Skip to content

Commit 013df7f

Browse files
committed
add simple transitions
1 parent 106c525 commit 013df7f

5 files changed

Lines changed: 28 additions & 13 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Here is a very clear demonstration of these smooth corners:
1111

1212
- [Installation](#installation)
1313
- [Usage](#usage)
14-
- [Options](#options)
15-
- [`dontConvertShadow`](#dontconvertshadow)
14+
- [Options](#options)
15+
- [`dontConvertShadow`](#dontconvertshadow)
1616
- [Things to note & caveats](#things-to-note--caveats)
17-
- [webpack](#webpack)
17+
- [webpack](#webpack)
1818

1919
## Installation
2020

@@ -60,8 +60,8 @@ your `box-shadow`s, add the `dontConvertShadow` option:
6060

6161
## Things to note & caveats
6262

63-
This package is still in the starting blocks, so for now borders are only supported in the `solid` style and transitions
64-
and animations on the div may not work properly.
63+
This package is still in the starting blocks, so for now borders are only supported in the `solid` style and some
64+
transitions, and animations on the div may not work properly.
6565

6666
There are a couple of css properties, that you can't reliably set with `RoundDiv`:
6767

src/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
2222
const [width, setWidth] = useState(0)
2323
const [radius, setRadius] = useState(Array(4).fill(0))
2424

25+
const [transition, setTransition] = useState(Array(4).fill(0))
26+
2527
const [borderColor, setBorderColor] = useState(Array(4).fill('transparent'))
2628
const [borderOpacity, setBorderOpacity] = useState(Array(4).fill(0))
2729
const [borderWidth, setBorderWidth] = useState(Array(4).fill(0))
@@ -47,7 +49,8 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
4749
setBorderColor,
4850
setBorderWidth,
4951
setBorderOpacity,
50-
setShadows
52+
setShadows,
53+
setTransition,
5154
})
5255
}
5356

@@ -133,6 +136,7 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
133136
...(Object.fromEntries(Object.keys(background).map(key => {
134137
return [camelise(key === 'null' ? 'background' : ('background-' + key)), background[key]]
135138
}))),
139+
transition,
136140
}}/>
137141
<svg viewBox={`0 0 ${width} ${height}`} style={{
138142
...shapeComponentStyles,

src/styleSheetWatcher.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export function detachCSSWatcher(id) {
1515
}
1616

1717
function watchCSS(callback, element) {
18-
let CSS = getCSSText()
18+
let CSS = getCSSText(element)
1919
let style = {...element.style}
2020
const interval = setInterval(() => {
21-
const newCSS = getCSSText()
21+
const newCSS = getCSSText(element)
2222
const newStyle = {...element.style}
2323
if (CSS === newCSS && areEqualObjects(style, newStyle)) return
2424
CSS = newCSS
@@ -30,7 +30,7 @@ function watchCSS(callback, element) {
3030
const forceUpdate = () => {
3131
clearTimeout(timeout)
3232
timeout = setTimeout(() => {
33-
CSS = getCSSText()
33+
CSS = getCSSText(element)
3434
style = {...element.style}
3535
callback()
3636
}, 0)
@@ -46,10 +46,16 @@ function watchCSS(callback, element) {
4646
}
4747
}
4848

49-
function getCSSText() {
49+
function getCSSText(element) {
5050
let CSS = ''
51-
iterateAllCssRules(rule =>
51+
iterateAllCssRules(rule => {
52+
try {
53+
if (!rule.selectorText || !element.matches(rule.selectorText)) return
54+
} catch (e) {
55+
return
56+
}
57+
// console.log(rule.selectorText)
5258
CSS += rule.cssText
53-
)
59+
})
5460
return CSS
5561
}

src/updateStates.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export default function updateStates(args) {
7070
))
7171
)
7272

73+
states.setTransition(
74+
getNthStyle('transition', 0)
75+
)
76+
7377
lazySetBackground(
7478
Object.fromEntries([
7579
'attachment',

src/utils/styles-extractor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export default function getAllCssPropertyDeclarationsForElement(targetProperty,
4242
} catch (e) {
4343
return
4444
}
45-
rule.cssParsed = css.parse(rule.cssText)?.stylesheet?.rules[0]?.declarations
45+
if (!rule.cssParsed)
46+
rule.cssParsed = css.parse(rule.cssText)?.stylesheet?.rules[0]?.declarations
4647
if (!rule.cssParsed) return
4748
let foundDeclaration = rule.cssParsed.find(dec => dec.property === targetProperty)
4849
const foundShorthandDeclaration = rule.cssParsed.find(dec => dec.property === targetPropertyShorthand)

0 commit comments

Comments
 (0)