@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.
@@ -1,6 +1,6 @@
1
1
  "use client"
2
2
 
3
- import { type FC, useMemo } from "react"
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 id: string = useMemo(() => `masonry-${Math.random().toString(36).slice(2, 8)}`, [])
13
-
14
- if (!children) return null
15
-
16
- const mediaStyles = `
17
- .${id} { column-count: ${columns[0]}; column-gap: ${gap[0]}px; }
18
- .${id} > * { break-inside: avoid; margin-bottom: ${gap[0]}px; }
19
-
20
- @media (min-width: ${breakpoints[1]}px) {
21
- .${id} { column-count: ${columns[1]}; column-gap: ${gap[1]}px; }
22
- .${id} > * { margin-bottom: ${gap[1]}px; }
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
- @media (min-width: ${breakpoints[2]}px) {
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
- <style dangerouslySetInnerHTML={{ __html: mediaStyles }} />
34
- <div className={id} data-ui-component="Masonry">
35
- {children}
36
- </div>
37
- </>
43
+ <div className={id} data-ui-component="Masonry">
44
+ {children}
45
+ </div>
38
46
  )
39
47
  }
40
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliosgraphics/ui",
3
- "version": "2.0.0-alpha.97",
3
+ "version": "2.0.0-alpha.98",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "*.css",