Skip to content

Commit 8a4fd23

Browse files
committed
fix borders in firefox, update readme
1 parent 519bca8 commit 8a4fd23

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const App = () => {
2828

2929
export default App;
3030
```
31-
`react-round-div` will clip the `border-radius` of it is too large to prevent artifacts from appearing. You can turn this off by passing `clip={false}`.
3231

3332

3433
## Caveats
35-
This package is still in the starting blocks, so for now only single colored backgrounds and solid, uniform borders are supported.
36-
There is support to come for gradients and image backgrounds, gradient borders, and perhaps proper `backdrop-filter` support.
34+
This package is still in the starting blocks, so for now borders are only supported in the `solid` style and some transitions on the div may not work properly.
35+
36+
Moreover, children inside `RoundDiv` get cut off when are placed (partly) outside the div due to `clip-path` being used to make the smooth corners. There will probably an option in later versions to use a pseudo-element for the shape, so that children can be rendered outside.

src/generator.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
export default function generateSvgSquircle(height, width, radius) {
99
/* from right to left top left corner upper (right half) */
1010
const ratios = [1.528665037, 1.0884928889, 0.8684068148, 0.07491140741, 0.6314939259, 0.1690595556, 0.3728238519];
11+
const roundToNthPlace = 1;
1112

1213
if (typeof radius === 'number')
1314
radius = Array(4).fill(radius)
@@ -101,5 +102,10 @@ export default function generateSvgSquircle(height, width, radius) {
101102
C0,${a1x[0]},0,${a2x[0]},${a3y[0]},${a3x[0]}
102103
C${b1y[0]},${b1x[0]},${b1x[0]},${b1y[0]},${b0x[0]},${b0y[0]}
103104
C${a2x[0]},0,${a1x[0]},0,${startPoint}
104-
Z`.replace(/\n */g, '').replace(/NaN/g, '0');
105+
Z`
106+
.replace(/[\n ]/g, '')
107+
.replace(/NaN/g, '0')
108+
.replace(/\d+\.\d+/g, match =>
109+
Math.round(Number(match) * (10 ** roundToNthPlace)) / (10 ** roundToNthPlace)
110+
)
105111
}

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function RoundDiv({style, children, ...props}) {
9898
}} xmlnsXlink="http://www.w3.org/1999/xlink" preserveAspectRatio={'xMidYMid slice'}>
9999
<defs>
100100
<clipPath id="inner">
101-
<path d={`M0,0V${height}H${width}V0H0Z` + innerPath} fillRule={'evenodd'}/>
101+
<path d={`M0,0V${height}H${width}V0Z` + innerPath} fillRule={'evenodd'}/>
102102
</clipPath>
103103
</defs>
104104
{Object.keys(maskPaths).map((key, i) => {

src/mask-generator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default function getMaskPaths(borderWidth, height, width, radius) {
2+
// console.log(borderWidth, height, width, radius)
23
const allSides = ['top', 'right', 'bottom', 'left']
34
const max = allSides.length - 1
45
const next = i => i === max ? 0 : i + 1

src/styleSheetWatcher.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
const CSSChangeEvent = new CustomEvent('css-change');
22

33
export default function attachCSSWatcher(callback) {
4-
// attach later, after loading is done
5-
setTimeout(() =>
6-
CSSWatcher.addEventListener('css-change', () => callback())
7-
, 20)
4+
CSSWatcher.addEventListener('css-change', () => callback())
85
}
96

107
const CSSWatcher = new EventTarget()

src/updateStates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function updateStates(args) {
3939
const getNthStyle = (key, n) => {
4040
const returnNthOverwrittenOrCurrent = r =>
4141
!r ? false :
42-
r?.overwritten.length > 1
42+
r?.overwritten.length > 0
4343
? r.overwritten[n ?? 0].value
4444
: r.current?.value
4545

0 commit comments

Comments
 (0)