@edgeandnode/eds-react 1.0.0 → 1.0.2

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.
Files changed (160) hide show
  1. package/README.md +21 -4
  2. package/dist/EDSContext.d.ts +3 -0
  3. package/dist/EDSContext.d.ts.map +1 -1
  4. package/dist/EDSContext.js +7 -0
  5. package/dist/EDSContext.js.map +1 -1
  6. package/dist/EDSProvider.d.ts +1 -1
  7. package/dist/EDSProvider.d.ts.map +1 -1
  8. package/dist/EDSProvider.js +15 -8
  9. package/dist/EDSProvider.js.map +1 -1
  10. package/dist/components/Avatar.d.ts.map +1 -1
  11. package/dist/components/Avatar.js +3 -2
  12. package/dist/components/Avatar.js.map +1 -1
  13. package/dist/components/Breadcrumbs.parts.d.ts +4 -3
  14. package/dist/components/Breadcrumbs.parts.d.ts.map +1 -1
  15. package/dist/components/Breadcrumbs.parts.js +15 -14
  16. package/dist/components/Breadcrumbs.parts.js.map +1 -1
  17. package/dist/components/Button.d.ts.map +1 -1
  18. package/dist/components/Button.js +3 -2
  19. package/dist/components/Button.js.map +1 -1
  20. package/dist/components/CodeBlock.parts.d.ts.map +1 -1
  21. package/dist/components/CodeBlock.parts.js +16 -20
  22. package/dist/components/CodeBlock.parts.js.map +1 -1
  23. package/dist/components/CopyButton.d.ts.map +1 -1
  24. package/dist/components/CopyButton.js +3 -2
  25. package/dist/components/CopyButton.js.map +1 -1
  26. package/dist/components/Icon.d.ts.map +1 -1
  27. package/dist/components/Icon.js +3 -3
  28. package/dist/components/Icon.js.map +1 -1
  29. package/dist/components/LocalTheme.d.ts +16 -0
  30. package/dist/components/LocalTheme.d.ts.map +1 -0
  31. package/dist/components/LocalTheme.js +22 -0
  32. package/dist/components/LocalTheme.js.map +1 -0
  33. package/dist/components/Menu.parts.d.ts.map +1 -1
  34. package/dist/components/Menu.parts.js +6 -4
  35. package/dist/components/Menu.parts.js.map +1 -1
  36. package/dist/components/Modal.parts.d.ts.map +1 -1
  37. package/dist/components/Modal.parts.js +21 -10
  38. package/dist/components/Modal.parts.js.map +1 -1
  39. package/dist/components/SegmentedControl.parts.d.ts.map +1 -1
  40. package/dist/components/SegmentedControl.parts.js +3 -2
  41. package/dist/components/SegmentedControl.parts.js.map +1 -1
  42. package/dist/components/Select.parts.d.ts +4 -4
  43. package/dist/components/Select.parts.d.ts.map +1 -1
  44. package/dist/components/Select.parts.js +2 -1
  45. package/dist/components/Select.parts.js.map +1 -1
  46. package/dist/components/TabSet.parts.d.ts.map +1 -1
  47. package/dist/components/TabSet.parts.js +3 -2
  48. package/dist/components/TabSet.parts.js.map +1 -1
  49. package/dist/components/Table.parts.d.ts.map +1 -1
  50. package/dist/components/Table.parts.js +3 -4
  51. package/dist/components/Table.parts.js.map +1 -1
  52. package/dist/components/ThemeSwitcher.js +2 -2
  53. package/dist/components/ThemeSwitcher.js.map +1 -1
  54. package/dist/components/Tooltip.parts.js +2 -2
  55. package/dist/components/Tooltip.parts.js.map +1 -1
  56. package/dist/components/base/Addon.d.ts.map +1 -1
  57. package/dist/components/base/Addon.js +2 -4
  58. package/dist/components/base/Addon.js.map +1 -1
  59. package/dist/components/base/ButtonOrLink.parts.d.ts.map +1 -1
  60. package/dist/components/base/ButtonOrLink.parts.js +2 -1
  61. package/dist/components/base/ButtonOrLink.parts.js.map +1 -1
  62. package/dist/components/index.d.ts +1 -0
  63. package/dist/components/index.d.ts.map +1 -1
  64. package/dist/components/index.js +1 -0
  65. package/dist/components/index.js.map +1 -1
  66. package/dist/hooks/useCSSProp.js +1 -1
  67. package/dist/hooks/useCSSProp.js.map +1 -1
  68. package/dist/hooks/useEDS.d.ts +16 -1
  69. package/dist/hooks/useEDS.d.ts.map +1 -1
  70. package/dist/hooks/useEDS.js +18 -2
  71. package/dist/hooks/useEDS.js.map +1 -1
  72. package/dist/hooks/useStyleObserver.d.ts.map +1 -1
  73. package/dist/hooks/useStyleObserver.js +2 -1
  74. package/dist/hooks/useStyleObserver.js.map +1 -1
  75. package/dist/icons/CalendarDynamicIcon.d.ts.map +1 -1
  76. package/dist/icons/CalendarDynamicIcon.js +3 -1
  77. package/dist/icons/CalendarDynamicIcon.js.map +1 -1
  78. package/dist/utils/getReactNodeKey.d.ts.map +1 -1
  79. package/dist/utils/getReactNodeKey.js +31 -13
  80. package/dist/utils/getReactNodeKey.js.map +1 -1
  81. package/dist/utils/index.d.ts +1 -1
  82. package/dist/utils/index.d.ts.map +1 -1
  83. package/dist/utils/index.js +1 -1
  84. package/dist/utils/index.js.map +1 -1
  85. package/dist/utils/internal/getTooltipProps.d.ts +9 -0
  86. package/dist/utils/internal/getTooltipProps.d.ts.map +1 -0
  87. package/dist/utils/internal/getTooltipProps.js +18 -0
  88. package/dist/utils/internal/getTooltipProps.js.map +1 -0
  89. package/dist/utils/internal/index.d.ts +4 -0
  90. package/dist/utils/internal/index.d.ts.map +1 -0
  91. package/dist/utils/internal/index.js +4 -0
  92. package/dist/utils/internal/index.js.map +1 -0
  93. package/dist/utils/internal/resolveLazy.d.ts +29 -0
  94. package/dist/utils/internal/resolveLazy.d.ts.map +1 -0
  95. package/dist/utils/internal/resolveLazy.js +40 -0
  96. package/dist/utils/internal/resolveLazy.js.map +1 -0
  97. package/dist/utils/internal/styleScheduler.d.ts.map +1 -0
  98. package/dist/utils/internal/styleScheduler.js.map +1 -0
  99. package/dist/utils/isComponentType.d.ts +9 -0
  100. package/dist/utils/isComponentType.d.ts.map +1 -0
  101. package/dist/utils/isComponentType.js +22 -0
  102. package/dist/utils/isComponentType.js.map +1 -0
  103. package/dist/utils/isReactNode.d.ts +7 -0
  104. package/dist/utils/isReactNode.d.ts.map +1 -1
  105. package/dist/utils/isReactNode.js +11 -0
  106. package/dist/utils/isReactNode.js.map +1 -1
  107. package/dist/utils/reactNodeToString.d.ts +3 -0
  108. package/dist/utils/reactNodeToString.d.ts.map +1 -1
  109. package/dist/utils/reactNodeToString.js +6 -0
  110. package/dist/utils/reactNodeToString.js.map +1 -1
  111. package/dist/utils/styleObserver.js +1 -1
  112. package/dist/utils/trimReactNode.d.ts +3 -0
  113. package/dist/utils/trimReactNode.d.ts.map +1 -1
  114. package/dist/utils/trimReactNode.js +6 -0
  115. package/dist/utils/trimReactNode.js.map +1 -1
  116. package/package.json +9 -8
  117. package/scripts/update-skill.cjs +18 -5
  118. package/skill/SKILL.md +17 -10
  119. package/skill/references/tokens.md +26 -20
  120. package/src/EDSContext.ts +9 -0
  121. package/src/EDSProvider.tsx +34 -9
  122. package/src/components/Avatar.tsx +3 -2
  123. package/src/components/Breadcrumbs.parts.tsx +31 -15
  124. package/src/components/Button.tsx +3 -2
  125. package/src/components/CodeBlock.parts.tsx +20 -24
  126. package/src/components/CopyButton.tsx +3 -2
  127. package/src/components/Icon.tsx +3 -9
  128. package/src/components/LocalTheme.tsx +39 -0
  129. package/src/components/Menu.parts.tsx +5 -3
  130. package/src/components/Modal.parts.tsx +20 -10
  131. package/src/components/SegmentedControl.parts.tsx +3 -8
  132. package/src/components/Select.parts.tsx +6 -5
  133. package/src/components/TabSet.parts.tsx +3 -5
  134. package/src/components/Table.parts.tsx +3 -3
  135. package/src/components/ThemeSwitcher.tsx +2 -2
  136. package/src/components/Tooltip.parts.tsx +2 -2
  137. package/src/components/base/Addon.tsx +3 -4
  138. package/src/components/base/ButtonOrLink.parts.tsx +2 -1
  139. package/src/components/index.ts +1 -0
  140. package/src/hooks/useCSSProp.ts +1 -1
  141. package/src/hooks/useEDS.ts +18 -2
  142. package/src/hooks/useStyleObserver.ts +2 -1
  143. package/src/icons/CalendarDynamicIcon.tsx +1 -0
  144. package/src/utils/getReactNodeKey.ts +30 -14
  145. package/src/utils/index.ts +1 -1
  146. package/src/utils/internal/getTooltipProps.ts +25 -0
  147. package/src/utils/internal/index.ts +3 -0
  148. package/src/utils/internal/resolveLazy.ts +44 -0
  149. package/src/utils/isComponentType.ts +27 -0
  150. package/src/utils/isReactNode.ts +11 -0
  151. package/src/utils/reactNodeToString.ts +7 -0
  152. package/src/utils/styleObserver.ts +1 -1
  153. package/src/utils/trimReactNode.tsx +7 -0
  154. package/dist/utils/styleScheduler.d.ts.map +0 -1
  155. package/dist/utils/styleScheduler.js.map +0 -1
  156. package/src/__snapshots__/compiled.css +0 -22525
  157. package/styles/tailwind.storybook.css +0 -19
  158. /package/dist/utils/{styleScheduler.d.ts → internal/styleScheduler.d.ts} +0 -0
  159. /package/dist/utils/{styleScheduler.js → internal/styleScheduler.js} +0 -0
  160. /package/src/utils/{styleScheduler.ts → internal/styleScheduler.ts} +0 -0
@@ -0,0 +1,44 @@
1
+ import { Lazy } from 'react-is'
2
+
3
+ /**
4
+ * Whether `value` is a lazy value, which is how the React Server Components payload can encode an
5
+ * element passed as a prop from a server component (e.g. when it's rendered by an async server
6
+ * component), or the `type` of an element created by a server component (so the client can suspend
7
+ * on that component's code). `React.lazy()` components are lazy values too.
8
+ *
9
+ * Not to be confused with `react-is`'s `isLazy`, which checks whether an element's type is lazy.
10
+ */
11
+ export function isLazy(
12
+ value: unknown,
13
+ ): value is { _payload: unknown; _init: (payload: unknown) => unknown } {
14
+ return (
15
+ typeof value === 'object' &&
16
+ value !== null &&
17
+ '$$typeof' in value &&
18
+ value.$$typeof === Lazy &&
19
+ '_payload' in value &&
20
+ '_init' in value &&
21
+ typeof value._init === 'function'
22
+ )
23
+ }
24
+
25
+ /**
26
+ * Resolves a lazy value (see `isLazy`) to what it stands for. React resolves lazy values when
27
+ * rendering them, but code that inspects nodes or element types (`isValidElement`, `cloneElement`,
28
+ * reading `props`, comparing `type`, etc.) must resolve them first. Suspends (throws) while the
29
+ * value's content or code is still loading, so it must be called during render.
30
+ *
31
+ * React has no public API for this. Its `Children` utilities resolve lazy values but only keep
32
+ * renderable results, so they drop a function component and throw on a `memo` or `forwardRef` one.
33
+ * This relies on the same internal `_init` and `_payload` fields they use, which is why it's kept
34
+ * internal rather than offered as public API. Returns other values as is, including lazy ones in an
35
+ * unexpected shape.
36
+ *
37
+ * The return type is the same as the argument's because TypeScript already types a lazy value as
38
+ * what it resolves to.
39
+ */
40
+ export function resolveLazy<Value>(value: Value): Value {
41
+ let resolvedValue: unknown = value
42
+ while (isLazy(resolvedValue)) resolvedValue = resolvedValue._init(resolvedValue._payload)
43
+ return resolvedValue as Value
44
+ }
@@ -0,0 +1,27 @@
1
+ import type { ComponentType, ReactNode } from 'react'
2
+ import { ForwardRef, Memo } from 'react-is'
3
+
4
+ import { isLazy, resolveLazy } from './internal/index.ts'
5
+
6
+ /**
7
+ * Whether `value` is a component (function, class, `forwardRef`, or `memo`) rather than a node.
8
+ *
9
+ * Like React's `Children` utilities, this resolves lazy values (e.g. elements from server
10
+ * components), which suspends while one is still loading, so call it during render.
11
+ */
12
+ export function isComponentType<Props>(
13
+ value: ReactNode | ComponentType<Props>,
14
+ ): value is ComponentType<Props> {
15
+ /**
16
+ * Unlike `react-is`'s `isValidElementType`, which returns `true` for any lazy value, resolving
17
+ * tells lazy components (e.g. `React.lazy()`) apart from lazy nodes.
18
+ */
19
+ if (isLazy(value)) return isComponentType(resolveLazy(value))
20
+ return (
21
+ typeof value === 'function' ||
22
+ (typeof value === 'object' &&
23
+ value !== null &&
24
+ '$$typeof' in value &&
25
+ (value.$$typeof === ForwardRef || value.$$typeof === Memo))
26
+ )
27
+ }
@@ -1,6 +1,17 @@
1
1
  import { isValidElement, type ReactNode } from 'react'
2
2
 
3
+ import { isLazy, resolveLazy } from './internal/index.ts'
4
+
5
+ /**
6
+ * Whether `value` is a React node: `null`, `undefined`, a string, number, or boolean, an element, a
7
+ * lazy node (e.g. an element from a server component), or an array of these.
8
+ *
9
+ * Like React's `Children` utilities, this resolves lazy values (e.g. elements from server
10
+ * components), which suspends while one is still loading, so call it during render.
11
+ */
3
12
  export function isReactNode(value: unknown): value is ReactNode {
13
+ // Resolving tells lazy nodes apart from lazy components (e.g. `React.lazy()`)
14
+ if (isLazy(value)) return isReactNode(resolveLazy(value))
4
15
  return (
5
16
  value === null ||
6
17
  value === undefined ||
@@ -1,15 +1,22 @@
1
1
  import { isValidElement, type ReactElement, type ReactNode } from 'react'
2
2
 
3
+ import { isLazy, resolveLazy } from './internal/index.ts'
4
+
3
5
  /**
4
6
  * Converts a `ReactNode` to a `string` representation. Extracts text content from React elements
5
7
  * recursively.
6
8
  *
7
9
  * Based on `https://github.com/sunknudsen/react-node-to-string`
8
10
  *
11
+ * Like React's `Children` utilities, this resolves lazy values (e.g. elements from server
12
+ * components), which suspends while one is still loading, so call it during render.
13
+ *
9
14
  * @param reactNode - The React node to convert to string.
10
15
  * @returns The string representation of the node, or empty string for null/undefined/boolean.
11
16
  */
12
17
  export function reactNodeToString(reactNode: ReactNode): string {
18
+ if (isLazy(reactNode)) return reactNodeToString(resolveLazy(reactNode))
19
+
13
20
  if (typeof reactNode === 'string') {
14
21
  return reactNode
15
22
  }
@@ -1,6 +1,6 @@
1
1
  import StyleObserver from 'style-observer'
2
2
 
3
- import { styleScheduler } from './styleScheduler.ts'
3
+ import { styleScheduler } from './internal/index.ts'
4
4
 
5
5
  export interface StyleObserverRecord<T extends string = string> {
6
6
  target: Element
@@ -1,5 +1,7 @@
1
1
  import { Children, isValidElement, type ReactElement, type ReactNode } from 'react'
2
2
 
3
+ import { isLazy, resolveLazy } from './internal/index.ts'
4
+
3
5
  type Side = 'start' | 'end' | 'both'
4
6
 
5
7
  /**
@@ -15,6 +17,9 @@ type Side = 'start' | 'end' | 'both'
15
17
  * When recursing into a non-string edge child (e.g. a nested fragment), only the corresponding side
16
18
  * is trimmed, so that whitespace which is internal to the outer node is preserved.
17
19
  *
20
+ * Like React's `Children` utilities, this resolves lazy values (e.g. elements from server
21
+ * components), which suspends while one is still loading, so call it during render.
22
+ *
18
23
  * @example
19
24
  * ````tsx
20
25
  * trimReactNode(' hello ') // 'hello'
@@ -30,6 +35,8 @@ type Side = 'start' | 'end' | 'both'
30
35
  * @returns A new `ReactNode` with the requested edge whitespace removed.
31
36
  */
32
37
  export function trimReactNode(reactNode: ReactNode, side: Side = 'both'): ReactNode {
38
+ if (isLazy(reactNode)) return trimReactNode(resolveLazy(reactNode), side)
39
+
33
40
  // Handle primitives
34
41
  if (typeof reactNode === 'string') {
35
42
  switch (side) {
@@ -1 +0,0 @@
1
- {"version":3,"file":"styleScheduler.d.ts","sourceRoot":"","sources":["../../src/utils/styleScheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,cAAM,cAAc;IAClB,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,OAAO,CAAqB;IAEpC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAiBzC;IAED;;;OAGG;IACH,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAM/D;CACF;AAGD,eAAO,MAAM,cAAc,gBAAuB,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"styleScheduler.js","sourceRoot":"","sources":["../../src/utils/styleScheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,cAAc;IACV,KAAK,GAAkB,IAAI,CAAA;IAC3B,OAAO,GAAmB,EAAE,CAAA;IAEpC;;;;OAIG;IACH,QAAQ,CAAC,QAAoB;QAC3B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAE3B,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,GAAG,qBAAqB,CAAC,GAAG,EAAE;gBACtC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAA;gBAC9B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;gBACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;gBAEjB,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;YACjC,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,GAAG,EAAE;YACV,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YAC5C,IAAI,KAAK,KAAK,CAAC,CAAC;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACjD,CAAC,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,gBAAgB,CAAC,OAAgB;QAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;gBACjB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAA;YAC3C,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAED,kDAAkD;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAA"}