@heliosgraphics/ui 2.0.0-alpha.97 → 2.0.0-alpha.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Masonry/Masonry.tsx +31 -23
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { type FC,
|
|
3
|
+
import { type FC, useId, useInsertionEffect } from "react"
|
|
4
4
|
import type { MasonryProps } from "./Masonry.types"
|
|
5
5
|
|
|
6
6
|
export const Masonry: FC<MasonryProps> = ({
|
|
@@ -9,32 +9,40 @@ export const Masonry: FC<MasonryProps> = ({
|
|
|
9
9
|
gap = [2, 4, 6],
|
|
10
10
|
breakpoints = [0, 640, 960],
|
|
11
11
|
}) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.${id} {
|
|
22
|
-
|
|
12
|
+
const reactId = useId()
|
|
13
|
+
const id = `masonry${reactId.replace(/:/g, "")}`
|
|
14
|
+
|
|
15
|
+
useInsertionEffect(() => {
|
|
16
|
+
const style = document.createElement("style")
|
|
17
|
+
|
|
18
|
+
style.dataset["masonryId"] = id
|
|
19
|
+
style.textContent = `
|
|
20
|
+
.${id} { column-count: ${columns[0]}; column-gap: ${gap[0]}px; }
|
|
21
|
+
.${id} > * { break-inside: avoid; margin-bottom: ${gap[0]}px; }
|
|
22
|
+
|
|
23
|
+
@media (min-width: ${breakpoints[1]}px) {
|
|
24
|
+
.${id} { column-count: ${columns[1]}; column-gap: ${gap[1]}px; }
|
|
25
|
+
.${id} > * { margin-bottom: ${gap[1]}px; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@media (min-width: ${breakpoints[2]}px) {
|
|
29
|
+
.${id} { column-count: ${columns[2]}; column-gap: ${gap[2]}px; }
|
|
30
|
+
.${id} > * { margin-bottom: ${gap[2]}px; }
|
|
31
|
+
}
|
|
32
|
+
`
|
|
33
|
+
document.head.appendChild(style)
|
|
34
|
+
|
|
35
|
+
return (): void => {
|
|
36
|
+
style.remove()
|
|
23
37
|
}
|
|
38
|
+
}, [id, columns, gap, breakpoints])
|
|
24
39
|
|
|
25
|
-
|
|
26
|
-
.${id} { column-count: ${columns[2]}; column-gap: ${gap[2]}px; }
|
|
27
|
-
.${id} > * { margin-bottom: ${gap[2]}px; }
|
|
28
|
-
}
|
|
29
|
-
`
|
|
40
|
+
if (!children) return null
|
|
30
41
|
|
|
31
42
|
return (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{children}
|
|
36
|
-
</div>
|
|
37
|
-
</>
|
|
43
|
+
<div className={id} data-ui-component="Masonry">
|
|
44
|
+
{children}
|
|
45
|
+
</div>
|
|
38
46
|
)
|
|
39
47
|
}
|
|
40
48
|
|