@backstage/ui 0.12.1-next.0 → 0.13.0-next.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 (209) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/dist/analytics/BUIProvider.esm.js +18 -0
  3. package/dist/analytics/BUIProvider.esm.js.map +1 -0
  4. package/dist/analytics/getNodeText.esm.js +21 -0
  5. package/dist/analytics/getNodeText.esm.js.map +1 -0
  6. package/dist/analytics/useAnalytics.esm.js +26 -0
  7. package/dist/analytics/useAnalytics.esm.js.map +1 -0
  8. package/dist/components/Accordion/Accordion.esm.js +1 -0
  9. package/dist/components/Accordion/Accordion.esm.js.map +1 -1
  10. package/dist/components/Accordion/definition.esm.js +3 -2
  11. package/dist/components/Accordion/definition.esm.js.map +1 -1
  12. package/dist/components/Alert/definition.esm.js +2 -1
  13. package/dist/components/Alert/definition.esm.js.map +1 -1
  14. package/dist/components/Avatar/Avatar.esm.js +8 -28
  15. package/dist/components/Avatar/Avatar.esm.js.map +1 -1
  16. package/dist/components/Avatar/definition.esm.js +18 -4
  17. package/dist/components/Avatar/definition.esm.js.map +1 -1
  18. package/dist/components/Box/definition.esm.js +2 -1
  19. package/dist/components/Box/definition.esm.js.map +1 -1
  20. package/dist/components/Button/definition.esm.js +3 -3
  21. package/dist/components/Button/definition.esm.js.map +1 -1
  22. package/dist/components/ButtonIcon/definition.esm.js +3 -3
  23. package/dist/components/ButtonIcon/definition.esm.js.map +1 -1
  24. package/dist/components/ButtonLink/ButtonLink.esm.js +10 -1
  25. package/dist/components/ButtonLink/ButtonLink.esm.js.map +1 -1
  26. package/dist/components/ButtonLink/definition.esm.js +5 -3
  27. package/dist/components/ButtonLink/definition.esm.js.map +1 -1
  28. package/dist/components/Card/Card.esm.js +67 -6
  29. package/dist/components/Card/Card.esm.js.map +1 -1
  30. package/dist/components/Card/Card.module.css.esm.js +2 -2
  31. package/dist/components/Card/definition.esm.js +11 -3
  32. package/dist/components/Card/definition.esm.js.map +1 -1
  33. package/dist/components/Checkbox/Checkbox.esm.js +10 -17
  34. package/dist/components/Checkbox/Checkbox.esm.js.map +1 -1
  35. package/dist/components/Checkbox/definition.esm.js +17 -5
  36. package/dist/components/Checkbox/definition.esm.js.map +1 -1
  37. package/dist/components/Container/Container.esm.js +8 -13
  38. package/dist/components/Container/Container.esm.js.map +1 -1
  39. package/dist/components/Container/Container.module.css.esm.js +2 -2
  40. package/dist/components/Container/definition.esm.js +17 -2
  41. package/dist/components/Container/definition.esm.js.map +1 -1
  42. package/dist/components/Dialog/Dialog.esm.js +26 -59
  43. package/dist/components/Dialog/Dialog.esm.js.map +1 -1
  44. package/dist/components/Dialog/Dialog.module.css.esm.js +2 -2
  45. package/dist/components/Dialog/definition.esm.js +53 -8
  46. package/dist/components/Dialog/definition.esm.js.map +1 -1
  47. package/dist/components/FieldError/FieldError.esm.js +4 -13
  48. package/dist/components/FieldError/FieldError.esm.js.map +1 -1
  49. package/dist/components/FieldError/definition.esm.js +15 -2
  50. package/dist/components/FieldError/definition.esm.js.map +1 -1
  51. package/dist/components/FieldLabel/FieldLabel.esm.js +14 -59
  52. package/dist/components/FieldLabel/FieldLabel.esm.js.map +1 -1
  53. package/dist/components/FieldLabel/definition.esm.js +20 -2
  54. package/dist/components/FieldLabel/definition.esm.js.map +1 -1
  55. package/dist/components/Flex/Flex.esm.js +12 -22
  56. package/dist/components/Flex/Flex.esm.js.map +1 -1
  57. package/dist/components/Flex/definition.esm.js +20 -13
  58. package/dist/components/Flex/definition.esm.js.map +1 -1
  59. package/dist/components/FullPage/FullPage.esm.js +4 -13
  60. package/dist/components/FullPage/FullPage.esm.js.map +1 -1
  61. package/dist/components/FullPage/definition.esm.js +15 -2
  62. package/dist/components/FullPage/definition.esm.js.map +1 -1
  63. package/dist/components/Grid/Grid.esm.js +21 -40
  64. package/dist/components/Grid/Grid.esm.js.map +1 -1
  65. package/dist/components/Grid/definition.esm.js +31 -26
  66. package/dist/components/Grid/definition.esm.js.map +1 -1
  67. package/dist/components/Header/Header.esm.js +55 -0
  68. package/dist/components/Header/Header.esm.js.map +1 -0
  69. package/dist/components/Header/Header.module.css.esm.js +8 -0
  70. package/dist/components/Header/Header.module.css.esm.js.map +1 -0
  71. package/dist/components/Header/definition.esm.js +30 -0
  72. package/dist/components/Header/definition.esm.js.map +1 -0
  73. package/dist/components/Link/Link.esm.js +15 -34
  74. package/dist/components/Link/Link.esm.js.map +1 -1
  75. package/dist/components/Link/definition.esm.js +23 -15
  76. package/dist/components/Link/definition.esm.js.map +1 -1
  77. package/dist/components/Menu/Menu.esm.js +180 -344
  78. package/dist/components/Menu/Menu.esm.js.map +1 -1
  79. package/dist/components/Menu/Menu.module.css.esm.js +2 -2
  80. package/dist/components/Menu/definition.esm.js +116 -17
  81. package/dist/components/Menu/definition.esm.js.map +1 -1
  82. package/dist/components/PasswordField/PasswordField.esm.js +17 -52
  83. package/dist/components/PasswordField/PasswordField.esm.js.map +1 -1
  84. package/dist/components/PasswordField/PasswordField.module.css.esm.js +2 -2
  85. package/dist/components/PasswordField/definition.esm.js +29 -11
  86. package/dist/components/PasswordField/definition.esm.js.map +1 -1
  87. package/dist/components/PluginHeader/PluginHeader.esm.js +35 -46
  88. package/dist/components/PluginHeader/PluginHeader.esm.js.map +1 -1
  89. package/dist/components/PluginHeader/PluginHeader.module.css.esm.js +2 -2
  90. package/dist/components/PluginHeader/definition.esm.js +22 -3
  91. package/dist/components/PluginHeader/definition.esm.js.map +1 -1
  92. package/dist/components/Popover/Popover.esm.js +24 -32
  93. package/dist/components/Popover/Popover.esm.js.map +1 -1
  94. package/dist/components/Popover/Popover.module.css.esm.js +2 -2
  95. package/dist/components/Popover/definition.esm.js +17 -2
  96. package/dist/components/Popover/definition.esm.js.map +1 -1
  97. package/dist/components/RadioGroup/RadioGroup.esm.js +25 -44
  98. package/dist/components/RadioGroup/RadioGroup.esm.js.map +1 -1
  99. package/dist/components/RadioGroup/definition.esm.js +31 -5
  100. package/dist/components/RadioGroup/definition.esm.js.map +1 -1
  101. package/dist/components/SearchField/SearchField.esm.js +25 -45
  102. package/dist/components/SearchField/SearchField.esm.js.map +1 -1
  103. package/dist/components/SearchField/SearchField.module.css.esm.js +2 -2
  104. package/dist/components/SearchField/definition.esm.js +22 -5
  105. package/dist/components/SearchField/definition.esm.js.map +1 -1
  106. package/dist/components/Select/Select.esm.js +14 -23
  107. package/dist/components/Select/Select.esm.js.map +1 -1
  108. package/dist/components/Select/Select.module.css.esm.js +2 -2
  109. package/dist/components/Select/SelectContent.esm.js +8 -31
  110. package/dist/components/Select/SelectContent.esm.js.map +1 -1
  111. package/dist/components/Select/SelectListBox.esm.js +21 -44
  112. package/dist/components/Select/SelectListBox.esm.js.map +1 -1
  113. package/dist/components/Select/SelectTrigger.esm.js +11 -14
  114. package/dist/components/Select/SelectTrigger.esm.js.map +1 -1
  115. package/dist/components/Select/definition.esm.js +69 -17
  116. package/dist/components/Select/definition.esm.js.map +1 -1
  117. package/dist/components/Skeleton/Skeleton.esm.js +9 -13
  118. package/dist/components/Skeleton/Skeleton.esm.js.map +1 -1
  119. package/dist/components/Skeleton/definition.esm.js +19 -2
  120. package/dist/components/Skeleton/definition.esm.js.map +1 -1
  121. package/dist/components/Switch/Switch.esm.js +7 -22
  122. package/dist/components/Switch/Switch.esm.js.map +1 -1
  123. package/dist/components/Switch/definition.esm.js +16 -2
  124. package/dist/components/Switch/definition.esm.js.map +1 -1
  125. package/dist/components/Table/Table.module.css.esm.js +2 -2
  126. package/dist/components/Table/components/Cell.esm.js +4 -17
  127. package/dist/components/Table/components/Cell.esm.js.map +1 -1
  128. package/dist/components/Table/components/CellProfile.esm.js +12 -41
  129. package/dist/components/Table/components/CellProfile.esm.js.map +1 -1
  130. package/dist/components/Table/components/CellText.esm.js +39 -73
  131. package/dist/components/Table/components/CellText.esm.js.map +1 -1
  132. package/dist/components/Table/components/Column.esm.js +8 -36
  133. package/dist/components/Table/components/Column.esm.js.map +1 -1
  134. package/dist/components/Table/components/Row.esm.js +22 -19
  135. package/dist/components/Table/components/Row.esm.js.map +1 -1
  136. package/dist/components/Table/components/Table.esm.js +8 -0
  137. package/dist/components/Table/components/Table.esm.js.map +1 -1
  138. package/dist/components/Table/components/TableBody.esm.js +4 -12
  139. package/dist/components/Table/components/TableBody.esm.js.map +1 -1
  140. package/dist/components/Table/components/TableHeader.esm.js +19 -29
  141. package/dist/components/Table/components/TableHeader.esm.js.map +1 -1
  142. package/dist/components/Table/components/TableRoot.esm.js +5 -7
  143. package/dist/components/Table/components/TableRoot.esm.js.map +1 -1
  144. package/dist/components/Table/definition.esm.js +101 -21
  145. package/dist/components/Table/definition.esm.js.map +1 -1
  146. package/dist/components/TablePagination/TablePagination.esm.js +24 -32
  147. package/dist/components/TablePagination/TablePagination.esm.js.map +1 -1
  148. package/dist/components/TablePagination/definition.esm.js +33 -2
  149. package/dist/components/TablePagination/definition.esm.js.map +1 -1
  150. package/dist/components/Tabs/Tabs.esm.js +57 -64
  151. package/dist/components/Tabs/Tabs.esm.js.map +1 -1
  152. package/dist/components/Tabs/TabsIndicators.esm.js +6 -18
  153. package/dist/components/Tabs/TabsIndicators.esm.js.map +1 -1
  154. package/dist/components/Tabs/definition.esm.js +65 -10
  155. package/dist/components/Tabs/definition.esm.js.map +1 -1
  156. package/dist/components/TagGroup/TagGroup.esm.js +49 -63
  157. package/dist/components/TagGroup/TagGroup.esm.js.map +1 -1
  158. package/dist/components/TagGroup/definition.esm.js +38 -8
  159. package/dist/components/TagGroup/definition.esm.js.map +1 -1
  160. package/dist/components/Text/Text.esm.js +6 -13
  161. package/dist/components/Text/Text.esm.js.map +1 -1
  162. package/dist/components/Text/definition.esm.js +19 -14
  163. package/dist/components/Text/definition.esm.js.map +1 -1
  164. package/dist/components/TextField/TextField.esm.js +16 -41
  165. package/dist/components/TextField/TextField.esm.js.map +1 -1
  166. package/dist/components/TextField/TextField.module.css.esm.js +2 -2
  167. package/dist/components/TextField/definition.esm.js +21 -6
  168. package/dist/components/TextField/definition.esm.js.map +1 -1
  169. package/dist/components/ToggleButton/ToggleButton.esm.js +11 -23
  170. package/dist/components/ToggleButton/ToggleButton.esm.js.map +1 -1
  171. package/dist/components/ToggleButton/definition.esm.js +18 -4
  172. package/dist/components/ToggleButton/definition.esm.js.map +1 -1
  173. package/dist/components/ToggleButtonGroup/ToggleButtonGroup.esm.js +5 -18
  174. package/dist/components/ToggleButtonGroup/ToggleButtonGroup.esm.js.map +1 -1
  175. package/dist/components/ToggleButtonGroup/definition.esm.js +15 -4
  176. package/dist/components/ToggleButtonGroup/definition.esm.js.map +1 -1
  177. package/dist/components/Tooltip/Tooltip.esm.js +24 -30
  178. package/dist/components/Tooltip/Tooltip.esm.js.map +1 -1
  179. package/dist/components/Tooltip/Tooltip.module.css.esm.js +2 -2
  180. package/dist/components/Tooltip/definition.esm.js +17 -2
  181. package/dist/components/Tooltip/definition.esm.js.map +1 -1
  182. package/dist/components/VisuallyHidden/VisuallyHidden.esm.js +4 -12
  183. package/dist/components/VisuallyHidden/VisuallyHidden.esm.js.map +1 -1
  184. package/dist/components/VisuallyHidden/definition.esm.js +15 -2
  185. package/dist/components/VisuallyHidden/definition.esm.js.map +1 -1
  186. package/dist/css/styles.css +2 -4
  187. package/dist/hooks/useBg.esm.js +11 -2
  188. package/dist/hooks/useBg.esm.js.map +1 -1
  189. package/dist/hooks/useBreakpoint.esm.js +67 -27
  190. package/dist/hooks/useBreakpoint.esm.js.map +1 -1
  191. package/dist/hooks/useDefinition/defineComponent.esm.js.map +1 -1
  192. package/dist/hooks/useDefinition/useDefinition.esm.js +10 -3
  193. package/dist/hooks/useDefinition/useDefinition.esm.js.map +1 -1
  194. package/dist/index.d.ts +1036 -282
  195. package/dist/index.esm.js +7 -4
  196. package/dist/index.esm.js.map +1 -1
  197. package/package.json +5 -3
  198. package/dist/components/HeaderPage/HeaderPage.esm.js +0 -76
  199. package/dist/components/HeaderPage/HeaderPage.esm.js.map +0 -1
  200. package/dist/components/HeaderPage/HeaderPage.module.css.esm.js +0 -8
  201. package/dist/components/HeaderPage/HeaderPage.module.css.esm.js.map +0 -1
  202. package/dist/components/HeaderPage/definition.esm.js +0 -12
  203. package/dist/components/HeaderPage/definition.esm.js.map +0 -1
  204. package/dist/components/PluginHeader/PluginHeaderToolbar.esm.js +0 -94
  205. package/dist/components/PluginHeader/PluginHeaderToolbar.esm.js.map +0 -1
  206. package/dist/hooks/useMediaQuery.esm.js +0 -47
  207. package/dist/hooks/useMediaQuery.esm.js.map +0 -1
  208. package/dist/hooks/useStyles.esm.js +0 -53
  209. package/dist/hooks/useStyles.esm.js.map +0 -1
@@ -15,6 +15,15 @@ function incrementNeutralBg(bg) {
15
15
  const BgProvider = ({ bg, children }) => {
16
16
  return /* @__PURE__ */ jsx(BgContext.Provider, { value: createVersionedValueMap({ 1: { bg } }), children });
17
17
  };
18
+ const BgReset = ({ children }) => {
19
+ return /* @__PURE__ */ jsx(
20
+ BgContext.Provider,
21
+ {
22
+ value: createVersionedValueMap({ 1: { bg: void 0 } }),
23
+ children
24
+ }
25
+ );
26
+ };
18
27
  function useBgConsumer() {
19
28
  const value = useContext(BgContext)?.atVersion(1);
20
29
  return value ?? { bg: void 0 };
@@ -26,11 +35,11 @@ function useBgProvider(bg) {
26
35
  return { bg: void 0 };
27
36
  }
28
37
  const resolved = resolveResponsiveValue(bg, breakpoint);
29
- if (resolved === "neutral-auto") {
38
+ if (resolved === "neutral") {
30
39
  return { bg: incrementNeutralBg(context.bg) };
31
40
  }
32
41
  return { bg: resolved };
33
42
  }
34
43
 
35
- export { BgProvider, useBgConsumer, useBgProvider };
44
+ export { BgProvider, BgReset, useBgConsumer, useBgProvider };
36
45
  //# sourceMappingURL=useBg.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useBg.esm.js","sources":["../../src/hooks/useBg.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useContext, ReactNode } from 'react';\nimport {\n createVersionedContext,\n createVersionedValueMap,\n} from '@backstage/version-bridge';\nimport { ContainerBg, ProviderBg, Responsive } from '../types';\nimport { useBreakpoint } from './useBreakpoint';\nimport { resolveResponsiveValue } from './useDefinition/helpers';\n\n/** @public */\nexport interface BgContextValue {\n bg: ContainerBg | undefined;\n}\n\n/** @public */\nexport interface BgProviderProps {\n bg: ContainerBg;\n children: ReactNode;\n}\n\nconst BgContext = createVersionedContext<{\n 1: BgContextValue;\n}>('bg-context');\n\n/**\n * Increments a neutral bg level by one, capping at 'neutral-3'.\n * Intent backgrounds (danger, warning, success) pass through unchanged.\n *\n * The 'neutral-4' level is reserved for consumer component CSS and is\n * never set on providers.\n *\n * @internal\n */\nfunction incrementNeutralBg(bg: ContainerBg | undefined): ContainerBg {\n if (!bg) return 'neutral-1';\n if (bg === 'neutral-1') return 'neutral-2';\n if (bg === 'neutral-2') return 'neutral-3';\n if (bg === 'neutral-3') return 'neutral-3'; // capped at neutral-3\n // Intent values pass through unchanged\n return bg;\n}\n\n/**\n * Provider component that establishes the bg context for child components.\n *\n * @public\n */\nexport const BgProvider = ({ bg, children }: BgProviderProps) => {\n return (\n <BgContext.Provider value={createVersionedValueMap({ 1: { bg } })}>\n {children}\n </BgContext.Provider>\n );\n};\n\n/**\n * Hook for consumer components (e.g. Button) to read the parent bg context.\n *\n * Returns the parent container's bg unchanged. The consumer component's CSS\n * handles the visual step-up (e.g. on a neutral-1 surface, the consumer\n * uses neutral-2 tokens via `data-on-bg`).\n *\n * @public\n */\nexport function useBgConsumer(): BgContextValue {\n const value = useContext(BgContext)?.atVersion(1);\n return value ?? { bg: undefined };\n}\n\n/**\n * Hook for provider components (e.g. Box, Card) to resolve and provide bg context.\n *\n * **Resolution rules:**\n *\n * - `bg` is `undefined` -- transparent, no context change, returns `{ bg: undefined }`.\n * This is the default for Box, Flex, and Grid (they do **not** auto-increment).\n * - `bg` is a `ContainerBg` value -- uses that value directly (e.g. `'neutral-1'`).\n * - `bg` is `'neutral-auto'` -- increments the neutral level from the parent context,\n * capping at `neutral-3`. Only components that explicitly pass `'neutral-auto'`\n * (e.g. Card) will auto-increment; it is never implicit.\n *\n * **Capping:**\n *\n * Provider components cap at `neutral-3`. The `neutral-4` level is **not** a valid\n * prop value -- it exists only in consumer component CSS (e.g. a Button on a\n * `neutral-3` surface renders with `neutral-4` tokens via `data-on-bg`).\n *\n * The caller is responsible for wrapping children with `BgProvider` when the\n * resolved bg is defined.\n *\n * @public\n */\nexport function useBgProvider(bg?: Responsive<ProviderBg>): BgContextValue {\n const { breakpoint } = useBreakpoint();\n const context = useBgConsumer();\n\n if (bg === undefined) {\n return { bg: undefined };\n }\n\n const resolved = resolveResponsiveValue(bg, breakpoint);\n\n if (resolved === 'neutral-auto') {\n return { bg: incrementNeutralBg(context.bg) };\n }\n\n return { bg: resolved };\n}\n"],"names":[],"mappings":";;;;;;AAoCA,MAAM,SAAA,GAAY,uBAEf,YAAY,CAAA;AAWf,SAAS,mBAAmB,EAAA,EAA0C;AACpE,EAAA,IAAI,CAAC,IAAI,OAAO,WAAA;AAChB,EAAA,IAAI,EAAA,KAAO,aAAa,OAAO,WAAA;AAC/B,EAAA,IAAI,EAAA,KAAO,aAAa,OAAO,WAAA;AAC/B,EAAA,IAAI,EAAA,KAAO,aAAa,OAAO,WAAA;AAE/B,EAAA,OAAO,EAAA;AACT;AAOO,MAAM,UAAA,GAAa,CAAC,EAAE,EAAA,EAAI,UAAS,KAAuB;AAC/D,EAAA,uBACE,GAAA,CAAC,SAAA,CAAU,QAAA,EAAV,EAAmB,KAAA,EAAO,uBAAA,CAAwB,EAAE,CAAA,EAAG,EAAE,EAAA,EAAG,EAAG,GAC7D,QAAA,EACH,CAAA;AAEJ;AAWO,SAAS,aAAA,GAAgC;AAC9C,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,SAAS,CAAA,EAAG,UAAU,CAAC,CAAA;AAChD,EAAA,OAAO,KAAA,IAAS,EAAE,EAAA,EAAI,MAAA,EAAU;AAClC;AAyBO,SAAS,cAAc,EAAA,EAA6C;AACzE,EAAA,MAAM,EAAE,UAAA,EAAW,GAAI,aAAA,EAAc;AACrC,EAAA,MAAM,UAAU,aAAA,EAAc;AAE9B,EAAA,IAAI,OAAO,MAAA,EAAW;AACpB,IAAA,OAAO,EAAE,IAAI,MAAA,EAAU;AAAA,EACzB;AAEA,EAAA,MAAM,QAAA,GAAW,sBAAA,CAAuB,EAAA,EAAI,UAAU,CAAA;AAEtD,EAAA,IAAI,aAAa,cAAA,EAAgB;AAC/B,IAAA,OAAO,EAAE,EAAA,EAAI,kBAAA,CAAmB,OAAA,CAAQ,EAAE,CAAA,EAAE;AAAA,EAC9C;AAEA,EAAA,OAAO,EAAE,IAAI,QAAA,EAAS;AACxB;;;;"}
1
+ {"version":3,"file":"useBg.esm.js","sources":["../../src/hooks/useBg.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useContext, ReactNode } from 'react';\nimport {\n createVersionedContext,\n createVersionedValueMap,\n} from '@backstage/version-bridge';\nimport { ContainerBg, ProviderBg, Responsive } from '../types';\nimport { useBreakpoint } from './useBreakpoint';\nimport { resolveResponsiveValue } from './useDefinition/helpers';\n\n/** @public */\nexport interface BgContextValue {\n bg: ContainerBg | undefined;\n}\n\n/** @public */\nexport interface BgProviderProps {\n bg: ContainerBg;\n children: ReactNode;\n}\n\nconst BgContext = createVersionedContext<{\n 1: BgContextValue;\n}>('bg-context');\n\n/**\n * Increments a neutral bg level by one, capping at 'neutral-3'.\n * Intent backgrounds (danger, warning, success) pass through unchanged.\n *\n * The 'neutral-4' level is reserved for consumer component CSS and is\n * never set on providers.\n *\n * @internal\n */\nfunction incrementNeutralBg(bg: ContainerBg | undefined): ContainerBg {\n if (!bg) return 'neutral-1';\n if (bg === 'neutral-1') return 'neutral-2';\n if (bg === 'neutral-2') return 'neutral-3';\n if (bg === 'neutral-3') return 'neutral-3'; // capped at neutral-3\n // Intent values pass through unchanged\n return bg;\n}\n\n/**\n * Provider component that establishes the bg context for child components.\n *\n * @public\n */\nexport const BgProvider = ({ bg, children }: BgProviderProps) => {\n return (\n <BgContext.Provider value={createVersionedValueMap({ 1: { bg } })}>\n {children}\n </BgContext.Provider>\n );\n};\n\n/**\n * Resets the bg context to undefined, cutting any inherited neutral chain.\n * Use this inside overlay components (Popover, Tooltip, Dialog, Menu) so\n * their content always starts from neutral-1 regardless of where the trigger\n * is placed in the tree.\n *\n * @internal\n */\nexport const BgReset = ({ children }: { children: ReactNode }) => {\n return (\n <BgContext.Provider\n value={createVersionedValueMap({ 1: { bg: undefined } })}\n >\n {children}\n </BgContext.Provider>\n );\n};\n\n/**\n * Hook for consumer components (e.g. Button) to read the parent bg context.\n *\n * Returns the parent container's bg unchanged. The consumer component's CSS\n * handles the visual step-up (e.g. on a neutral-1 surface, the consumer\n * uses neutral-2 tokens via `data-on-bg`).\n *\n * @public\n */\nexport function useBgConsumer(): BgContextValue {\n const value = useContext(BgContext)?.atVersion(1);\n return value ?? { bg: undefined };\n}\n\n/**\n * Hook for provider components (e.g. Box, Card) to resolve and provide bg context.\n *\n * **Resolution rules:**\n *\n * - `bg` is `undefined` -- transparent, no context change, returns `{ bg: undefined }`.\n * This is the default for Box, Flex, and Grid (they do **not** auto-increment).\n * - `bg` is `'neutral'` -- when the parent bg is neutral, increments the neutral\n * level from the parent context, capping at `neutral-3`. When the parent bg is\n * an intent (`'danger'` | `'warning'` | `'success'`), the intent passes through\n * unchanged (i.e. `bg: 'neutral'` does not override the parent intent). The\n * increment is always relative to the parent; it is not possible to pin a\n * container to an explicit neutral level.\n * - `bg` is `'danger'` | `'warning'` | `'success'` -- sets the bg to that intent\n * explicitly, regardless of the parent value.\n *\n * **Capping:**\n *\n * Provider components cap at `neutral-3`. The `neutral-4` level is **not** a valid\n * prop value -- it exists only in consumer component CSS (e.g. a Button on a\n * `neutral-3` surface renders with `neutral-4` tokens via `data-on-bg`).\n *\n * The caller is responsible for wrapping children with `BgProvider` when the\n * resolved bg is defined.\n *\n * @public\n */\nexport function useBgProvider(bg?: Responsive<ProviderBg>): BgContextValue {\n const { breakpoint } = useBreakpoint();\n const context = useBgConsumer();\n\n if (bg === undefined) {\n return { bg: undefined };\n }\n\n const resolved = resolveResponsiveValue(bg, breakpoint);\n\n if (resolved === 'neutral') {\n return { bg: incrementNeutralBg(context.bg) };\n }\n\n return { bg: resolved };\n}\n"],"names":[],"mappings":";;;;;;AAoCA,MAAM,SAAA,GAAY,uBAEf,YAAY,CAAA;AAWf,SAAS,mBAAmB,EAAA,EAA0C;AACpE,EAAA,IAAI,CAAC,IAAI,OAAO,WAAA;AAChB,EAAA,IAAI,EAAA,KAAO,aAAa,OAAO,WAAA;AAC/B,EAAA,IAAI,EAAA,KAAO,aAAa,OAAO,WAAA;AAC/B,EAAA,IAAI,EAAA,KAAO,aAAa,OAAO,WAAA;AAE/B,EAAA,OAAO,EAAA;AACT;AAOO,MAAM,UAAA,GAAa,CAAC,EAAE,EAAA,EAAI,UAAS,KAAuB;AAC/D,EAAA,uBACE,GAAA,CAAC,SAAA,CAAU,QAAA,EAAV,EAAmB,KAAA,EAAO,uBAAA,CAAwB,EAAE,CAAA,EAAG,EAAE,EAAA,EAAG,EAAG,GAC7D,QAAA,EACH,CAAA;AAEJ;AAUO,MAAM,OAAA,GAAU,CAAC,EAAE,QAAA,EAAS,KAA+B;AAChE,EAAA,uBACE,GAAA;AAAA,IAAC,SAAA,CAAU,QAAA;AAAA,IAAV;AAAA,MACC,KAAA,EAAO,wBAAwB,EAAE,CAAA,EAAG,EAAE,EAAA,EAAI,MAAA,IAAa,CAAA;AAAA,MAEtD;AAAA;AAAA,GACH;AAEJ;AAWO,SAAS,aAAA,GAAgC;AAC9C,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,SAAS,CAAA,EAAG,UAAU,CAAC,CAAA;AAChD,EAAA,OAAO,KAAA,IAAS,EAAE,EAAA,EAAI,MAAA,EAAU;AAClC;AA6BO,SAAS,cAAc,EAAA,EAA6C;AACzE,EAAA,MAAM,EAAE,UAAA,EAAW,GAAI,aAAA,EAAc;AACrC,EAAA,MAAM,UAAU,aAAA,EAAc;AAE9B,EAAA,IAAI,OAAO,MAAA,EAAW;AACpB,IAAA,OAAO,EAAE,IAAI,MAAA,EAAU;AAAA,EACzB;AAEA,EAAA,MAAM,QAAA,GAAW,sBAAA,CAAuB,EAAA,EAAI,UAAU,CAAA;AAEtD,EAAA,IAAI,aAAa,SAAA,EAAW;AAC1B,IAAA,OAAO,EAAE,EAAA,EAAI,kBAAA,CAAmB,OAAA,CAAQ,EAAE,CAAA,EAAE;AAAA,EAC9C;AAEA,EAAA,OAAO,EAAE,IAAI,QAAA,EAAS;AACxB;;;;"}
@@ -1,4 +1,5 @@
1
- import { useMediaQuery } from './useMediaQuery.esm.js';
1
+ import { useMemo } from 'react';
2
+ import { useSyncExternalStore } from 'use-sync-external-store/shim';
2
3
 
3
4
  const breakpoints = [
4
5
  { name: "Initial", id: "initial", value: 0 },
@@ -8,35 +9,74 @@ const breakpoints = [
8
9
  { name: "Large", id: "lg", value: 1280 },
9
10
  { name: "Extra Large", id: "xl", value: 1536 }
10
11
  ];
11
- const useBreakpoint = () => {
12
- const matches = breakpoints.map((breakpoint2) => {
13
- return useMediaQuery(`(min-width: ${breakpoint2.value}px)`);
14
- });
15
- const upMatches = new Map(
16
- breakpoints.map((bp) => [bp.id, useMediaQuery(`(min-width: ${bp.value}px)`)])
17
- );
18
- const downMatches = new Map(
19
- breakpoints.map((bp) => [
20
- bp.id,
21
- useMediaQuery(`(max-width: ${bp.value - 1}px)`)
22
- ])
23
- );
24
- let breakpoint = breakpoints[0].id;
25
- for (let i = matches.length - 1; i >= 0; i--) {
26
- if (matches[i]) {
27
- breakpoint = breakpoints[i].id;
28
- break;
29
- }
12
+ const breakpointIndex = new Map(
13
+ breakpoints.map((bp, i) => [bp.id, i])
14
+ );
15
+ function bpIndex(key) {
16
+ return breakpointIndex.get(key) ?? 0;
17
+ }
18
+ const IS_SERVER = typeof window === "undefined" || typeof window.matchMedia === "undefined";
19
+ function computeBreakpoint() {
20
+ if (IS_SERVER) {
21
+ return "initial";
30
22
  }
31
- return {
32
- breakpoint,
33
- up: (key) => {
34
- return upMatches.get(key) ?? false;
35
- },
36
- down: (key) => {
37
- return downMatches.get(key) ?? false;
23
+ for (let i = breakpoints.length - 1; i >= 0; i--) {
24
+ if (window.matchMedia(`(min-width: ${breakpoints[i].value}px)`).matches) {
25
+ return breakpoints[i].id;
38
26
  }
27
+ }
28
+ return "initial";
29
+ }
30
+ let current;
31
+ const listeners = /* @__PURE__ */ new Set();
32
+ let initialized = false;
33
+ function ensureInitialized() {
34
+ if (initialized || IS_SERVER) {
35
+ return;
36
+ }
37
+ initialized = true;
38
+ current = computeBreakpoint();
39
+ for (const bp of breakpoints) {
40
+ const mql = window.matchMedia(`(min-width: ${bp.value}px)`);
41
+ mql.addEventListener("change", () => {
42
+ const next = computeBreakpoint();
43
+ if (next !== current) {
44
+ current = next;
45
+ for (const cb of listeners) {
46
+ cb();
47
+ }
48
+ }
49
+ });
50
+ }
51
+ }
52
+ function subscribe(callback) {
53
+ ensureInitialized();
54
+ listeners.add(callback);
55
+ return () => {
56
+ listeners.delete(callback);
39
57
  };
58
+ }
59
+ function getSnapshot() {
60
+ ensureInitialized();
61
+ return current ?? "initial";
62
+ }
63
+ function getServerSnapshot() {
64
+ return "initial";
65
+ }
66
+ const useBreakpoint = () => {
67
+ const breakpoint = useSyncExternalStore(
68
+ subscribe,
69
+ getSnapshot,
70
+ getServerSnapshot
71
+ );
72
+ return useMemo(
73
+ () => ({
74
+ breakpoint,
75
+ up: (key) => bpIndex(breakpoint) >= bpIndex(key),
76
+ down: (key) => bpIndex(breakpoint) < bpIndex(key)
77
+ }),
78
+ [breakpoint]
79
+ );
40
80
  };
41
81
 
42
82
  export { breakpoints, useBreakpoint };
@@ -1 +1 @@
1
- {"version":3,"file":"useBreakpoint.esm.js","sources":["../../src/hooks/useBreakpoint.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useMediaQuery } from './useMediaQuery';\nimport type { Breakpoint } from '../types';\n\nexport const breakpoints: { name: string; id: Breakpoint; value: number }[] = [\n { name: 'Initial', id: 'initial', value: 0 },\n { name: 'Extra Small', id: 'xs', value: 640 },\n { name: 'Small', id: 'sm', value: 768 },\n { name: 'Medium', id: 'md', value: 1024 },\n { name: 'Large', id: 'lg', value: 1280 },\n { name: 'Extra Large', id: 'xl', value: 1536 },\n];\n\n/** @public */\nexport const useBreakpoint = () => {\n // Call all media queries at the top level\n const matches = breakpoints.map(breakpoint => {\n return useMediaQuery(`(min-width: ${breakpoint.value}px)`);\n });\n\n // Pre-calculate all the up/down values we need\n const upMatches = new Map(\n breakpoints.map(bp => [bp.id, useMediaQuery(`(min-width: ${bp.value}px)`)]),\n );\n\n const downMatches = new Map(\n breakpoints.map(bp => [\n bp.id,\n useMediaQuery(`(max-width: ${bp.value - 1}px)`),\n ]),\n );\n\n let breakpoint: Breakpoint = breakpoints[0].id;\n for (let i = matches.length - 1; i >= 0; i--) {\n if (matches[i]) {\n breakpoint = breakpoints[i].id;\n break;\n }\n }\n\n return {\n breakpoint,\n up: (key: Breakpoint): boolean => {\n return upMatches.get(key) ?? false;\n },\n down: (key: Breakpoint): boolean => {\n return downMatches.get(key) ?? false;\n },\n };\n};\n"],"names":["breakpoint"],"mappings":";;AAkBO,MAAM,WAAA,GAAiE;AAAA,EAC5E,EAAE,IAAA,EAAM,SAAA,EAAW,EAAA,EAAI,SAAA,EAAW,OAAO,CAAA,EAAE;AAAA,EAC3C,EAAE,IAAA,EAAM,aAAA,EAAe,EAAA,EAAI,IAAA,EAAM,OAAO,GAAA,EAAI;AAAA,EAC5C,EAAE,IAAA,EAAM,OAAA,EAAS,EAAA,EAAI,IAAA,EAAM,OAAO,GAAA,EAAI;AAAA,EACtC,EAAE,IAAA,EAAM,QAAA,EAAU,EAAA,EAAI,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,EACxC,EAAE,IAAA,EAAM,OAAA,EAAS,EAAA,EAAI,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,EACvC,EAAE,IAAA,EAAM,aAAA,EAAe,EAAA,EAAI,IAAA,EAAM,OAAO,IAAA;AAC1C;AAGO,MAAM,gBAAgB,MAAM;AAEjC,EAAA,MAAM,OAAA,GAAU,WAAA,CAAY,GAAA,CAAI,CAAAA,WAAAA,KAAc;AAC5C,IAAA,OAAO,aAAA,CAAc,CAAA,YAAA,EAAeA,WAAAA,CAAW,KAAK,CAAA,GAAA,CAAK,CAAA;AAAA,EAC3D,CAAC,CAAA;AAGD,EAAA,MAAM,YAAY,IAAI,GAAA;AAAA,IACpB,WAAA,CAAY,GAAA,CAAI,CAAA,EAAA,KAAM,CAAC,EAAA,CAAG,EAAA,EAAI,aAAA,CAAc,CAAA,YAAA,EAAe,EAAA,CAAG,KAAK,CAAA,GAAA,CAAK,CAAC,CAAC;AAAA,GAC5E;AAEA,EAAA,MAAM,cAAc,IAAI,GAAA;AAAA,IACtB,WAAA,CAAY,IAAI,CAAA,EAAA,KAAM;AAAA,MACpB,EAAA,CAAG,EAAA;AAAA,MACH,aAAA,CAAc,CAAA,YAAA,EAAe,EAAA,CAAG,KAAA,GAAQ,CAAC,CAAA,GAAA,CAAK;AAAA,KAC/C;AAAA,GACH;AAEA,EAAA,IAAI,UAAA,GAAyB,WAAA,CAAY,CAAC,CAAA,CAAE,EAAA;AAC5C,EAAA,KAAA,IAAS,IAAI,OAAA,CAAQ,MAAA,GAAS,CAAA,EAAG,CAAA,IAAK,GAAG,CAAA,EAAA,EAAK;AAC5C,IAAA,IAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACd,MAAA,UAAA,GAAa,WAAA,CAAY,CAAC,CAAA,CAAE,EAAA;AAC5B,MAAA;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,EAAA,EAAI,CAAC,GAAA,KAA6B;AAChC,MAAA,OAAO,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,IAAK,KAAA;AAAA,IAC/B,CAAA;AAAA,IACA,IAAA,EAAM,CAAC,GAAA,KAA6B;AAClC,MAAA,OAAO,WAAA,CAAY,GAAA,CAAI,GAAG,CAAA,IAAK,KAAA;AAAA,IACjC;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"useBreakpoint.esm.js","sources":["../../src/hooks/useBreakpoint.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useMemo } from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\nimport type { Breakpoint } from '../types';\n\nexport const breakpoints: { name: string; id: Breakpoint; value: number }[] = [\n { name: 'Initial', id: 'initial', value: 0 },\n { name: 'Extra Small', id: 'xs', value: 640 },\n { name: 'Small', id: 'sm', value: 768 },\n { name: 'Medium', id: 'md', value: 1024 },\n { name: 'Large', id: 'lg', value: 1280 },\n { name: 'Extra Large', id: 'xl', value: 1536 },\n];\n\nconst breakpointIndex = new Map<Breakpoint, number>(\n breakpoints.map((bp, i) => [bp.id, i]),\n);\n\nfunction bpIndex(key: Breakpoint): number {\n return breakpointIndex.get(key) ?? 0;\n}\n\nconst IS_SERVER =\n typeof window === 'undefined' || typeof window.matchMedia === 'undefined';\n\nfunction computeBreakpoint(): Breakpoint {\n if (IS_SERVER) {\n return 'initial';\n }\n for (let i = breakpoints.length - 1; i >= 0; i--) {\n if (window.matchMedia(`(min-width: ${breakpoints[i].value}px)`).matches) {\n return breakpoints[i].id;\n }\n }\n return 'initial';\n}\n\n// --- Module-scoped singleton store ---\n// This is intentionally not a global singleton. Multiple copies of this module\n// (e.g. different package versions or module federation remotes) each get their\n// own store. This avoids cross-version coupling at the cost of a few extra\n// listeners, which is a fine trade-off.\n// `current` is initialized lazily on first client-side access.\n\nlet current: Breakpoint | undefined;\nconst listeners = new Set<() => void>();\nlet initialized = false;\n\nfunction ensureInitialized(): void {\n if (initialized || IS_SERVER) {\n return;\n }\n initialized = true;\n current = computeBreakpoint();\n\n // Register one listener per breakpoint. When any query fires, re-evaluate\n // all breakpoints to find the new active one. Notify subscribers only if\n // the active breakpoint actually changed.\n for (const bp of breakpoints) {\n const mql = window.matchMedia(`(min-width: ${bp.value}px)`);\n mql.addEventListener('change', () => {\n const next = computeBreakpoint();\n if (next !== current) {\n current = next;\n for (const cb of listeners) {\n cb();\n }\n }\n });\n }\n}\n\nfunction subscribe(callback: () => void): () => void {\n ensureInitialized();\n listeners.add(callback);\n return () => {\n listeners.delete(callback);\n };\n}\n\nfunction getSnapshot(): Breakpoint {\n ensureInitialized();\n return current ?? 'initial';\n}\n\nfunction getServerSnapshot(): Breakpoint {\n return 'initial';\n}\n\n/** @public */\nexport const useBreakpoint = () => {\n const breakpoint = useSyncExternalStore(\n subscribe,\n getSnapshot,\n getServerSnapshot,\n );\n\n return useMemo(\n () => ({\n breakpoint,\n up: (key: Breakpoint): boolean => bpIndex(breakpoint) >= bpIndex(key),\n down: (key: Breakpoint): boolean => bpIndex(breakpoint) < bpIndex(key),\n }),\n [breakpoint],\n );\n};\n"],"names":[],"mappings":";;;AAmBO,MAAM,WAAA,GAAiE;AAAA,EAC5E,EAAE,IAAA,EAAM,SAAA,EAAW,EAAA,EAAI,SAAA,EAAW,OAAO,CAAA,EAAE;AAAA,EAC3C,EAAE,IAAA,EAAM,aAAA,EAAe,EAAA,EAAI,IAAA,EAAM,OAAO,GAAA,EAAI;AAAA,EAC5C,EAAE,IAAA,EAAM,OAAA,EAAS,EAAA,EAAI,IAAA,EAAM,OAAO,GAAA,EAAI;AAAA,EACtC,EAAE,IAAA,EAAM,QAAA,EAAU,EAAA,EAAI,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,EACxC,EAAE,IAAA,EAAM,OAAA,EAAS,EAAA,EAAI,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,EACvC,EAAE,IAAA,EAAM,aAAA,EAAe,EAAA,EAAI,IAAA,EAAM,OAAO,IAAA;AAC1C;AAEA,MAAM,kBAAkB,IAAI,GAAA;AAAA,EAC1B,WAAA,CAAY,IAAI,CAAC,EAAA,EAAI,MAAM,CAAC,EAAA,CAAG,EAAA,EAAI,CAAC,CAAC;AACvC,CAAA;AAEA,SAAS,QAAQ,GAAA,EAAyB;AACxC,EAAA,OAAO,eAAA,CAAgB,GAAA,CAAI,GAAG,CAAA,IAAK,CAAA;AACrC;A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,EAAkB;AAClB,EAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,EAAA,OAAO,MAAM;AACX,IAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,EAC3B,CAAA;AACF;AAEA,SAAS,WAAA,GAA0B;AACjC,EAAA,iBAAA,EAAkB;AAClB,EAAA,OAAO,OAAA,IAAW,SAAA;AACpB;AAEA,SAAS,iBAAA,GAAgC;AACvC,EAAA,OAAO,SAAA;AACT;AAGO,MAAM,gBAAgB,MAAM;AACjC,EAAA,MAAM,UAAA,GAAa,oBAAA;AAAA,IACjB,SAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,OAAO,OAAA;AAAA,IACL,OAAO;AAAA,MACL,UAAA;AAAA,MACA,IAAI,CAAC,GAAA,KAA6B,QAAQ,UAAU,CAAA,IAAK,QAAQ,GAAG,CAAA;AAAA,MACpE,MAAM,CAAC,GAAA,KAA6B,QAAQ,UAAU,CAAA,GAAI,QAAQ,GAAG;AAAA,KACvE,CAAA;AAAA,IACA,CAAC,UAAU;AAAA,GACb;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"defineComponent.esm.js","sources":["../../../src/hooks/useDefinition/defineComponent.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ComponentConfig, BgPropsConstraint } from './types';\n\nexport function defineComponent<P extends Record<string, any>>() {\n return <\n const S extends Record<string, string>,\n const C extends ComponentConfig<P, S>,\n >(\n config: C & BgPropsConstraint<P, C['bg']>,\n ): C => config;\n}\n"],"names":[],"mappings":"AAkBO,SAAS,eAAA,GAAiD;AAC/D,EAAA,OAAO,CAIL,MAAA,KACM,MAAA;AACV;;;;"}
1
+ {"version":3,"file":"defineComponent.esm.js","sources":["../../../src/hooks/useDefinition/defineComponent.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ComponentConfig,\n BgPropsConstraint,\n AnalyticsPropsConstraint,\n} from './types';\n\nexport function defineComponent<P extends Record<string, any>>() {\n return <\n const S extends Record<string, string>,\n const C extends ComponentConfig<P, S>,\n >(\n config: C &\n BgPropsConstraint<P, C['bg']> &\n AnalyticsPropsConstraint<P, C['analytics']>,\n ): C => config;\n}\n"],"names":[],"mappings":"AAsBO,SAAS,eAAA,GAAiD;AAC/D,EAAA,OAAO,CAIL,MAAA,KAGM,MAAA;AACV;;;;"}
@@ -3,6 +3,7 @@ import clsx from 'clsx';
3
3
  import { useBreakpoint } from '../useBreakpoint.esm.js';
4
4
  import { useBgProvider, useBgConsumer, BgProvider } from '../useBg.esm.js';
5
5
  import { resolveDefinitionProps, processUtilityProps } from './helpers.esm.js';
6
+ import { useAnalytics, noopTracker } from '../../analytics/useAnalytics.esm.js';
6
7
 
7
8
  function useDefinition(definition, props, options) {
8
9
  const { breakpoint } = useBreakpoint();
@@ -35,8 +36,13 @@ function useDefinition(definition, props, options) {
35
36
  props,
36
37
  definition.utilityProps ?? []
37
38
  );
38
- const utilityTarget = "root";
39
- const classNameTarget = "root";
39
+ let analytics = noopTracker;
40
+ if (definition.analytics) {
41
+ const tracker = useAnalytics();
42
+ analytics = ownPropsResolved.noTrack ? noopTracker : tracker;
43
+ }
44
+ const utilityTarget = options?.utilityTarget ?? "root";
45
+ const classNameTarget = options?.classNameTarget ?? "root";
40
46
  const classes = {};
41
47
  for (const [name, cssKey] of Object.entries(definition.classNames)) {
42
48
  classes[name] = clsx(
@@ -61,7 +67,8 @@ function useDefinition(definition, props, options) {
61
67
  },
62
68
  restProps,
63
69
  dataAttributes,
64
- utilityStyle
70
+ utilityStyle,
71
+ ...definition.analytics ? { analytics } : {}
65
72
  };
66
73
  }
67
74
 
@@ -1 +1 @@
1
- {"version":3,"file":"useDefinition.esm.js","sources":["../../../src/hooks/useDefinition/useDefinition.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode } from 'react';\nimport clsx from 'clsx';\nimport { useBreakpoint } from '../useBreakpoint';\nimport { useBgProvider, useBgConsumer, BgProvider } from '../useBg';\nimport { resolveDefinitionProps, processUtilityProps } from './helpers';\nimport type {\n ComponentConfig,\n UseDefinitionOptions,\n UseDefinitionResult,\n UtilityKeys,\n} from './types';\n\nexport function useDefinition<\n D extends ComponentConfig<any, any>,\n P extends Record<string, any>,\n>(\n definition: D,\n props: P,\n options?: UseDefinitionOptions<D>,\n): UseDefinitionResult<D, P> {\n const { breakpoint } = useBreakpoint();\n\n // Resolve all props centrally — applies responsive values and defaults\n const { ownPropsResolved, restProps } = resolveDefinitionProps(\n definition,\n props,\n breakpoint,\n );\n\n const dataAttributes: Record<string, string | undefined> = {};\n\n for (const [key, config] of Object.entries(definition.propDefs)) {\n const finalValue = ownPropsResolved[key];\n\n if (finalValue !== undefined) {\n // Skip data-bg for bg prop when the provider path handles it\n if (key === 'bg' && definition.bg === 'provider') continue;\n\n if ((config as any).dataAttribute) {\n // eslint-disable-next-line no-restricted-syntax\n dataAttributes[`data-${key.toLowerCase()}`] = String(finalValue);\n }\n }\n }\n\n // Provider: resolve bg and provide context for children\n const providerBg = useBgProvider(\n definition.bg === 'provider' ? ownPropsResolved.bg : undefined,\n );\n\n // Consumer: read parent context bg\n const consumerBg = useBgConsumer();\n\n // Provider: set data-bg from the resolved provider bg\n if (definition.bg === 'provider' && providerBg.bg !== undefined) {\n dataAttributes['data-bg'] = String(providerBg.bg);\n }\n\n // Consumer: set data-on-bg from the parent context\n if (definition.bg === 'consumer' && consumerBg.bg !== undefined) {\n dataAttributes['data-on-bg'] = String(consumerBg.bg);\n }\n\n const { utilityClasses, utilityStyle } = processUtilityProps<UtilityKeys<D>>(\n props,\n (definition.utilityProps ?? []) as readonly UtilityKeys<D>[],\n );\n\n const utilityTarget = options?.utilityTarget ?? 'root';\n const classNameTarget = options?.classNameTarget ?? 'root';\n\n const classes: Record<string, string> = {};\n\n for (const [name, cssKey] of Object.entries(definition.classNames)) {\n classes[name] = clsx(\n cssKey as string,\n definition.styles[cssKey as keyof typeof definition.styles],\n utilityTarget === name && utilityClasses,\n classNameTarget === name && ownPropsResolved.className,\n );\n }\n\n let children: ReactNode | undefined;\n let childrenWithBgProvider: ReactNode | undefined;\n\n if (definition.bg === 'provider') {\n childrenWithBgProvider = providerBg.bg ? (\n <BgProvider bg={providerBg.bg}>{props.children}</BgProvider>\n ) : (\n props.children\n );\n } else {\n children = props.children;\n }\n\n return {\n ownProps: {\n classes,\n ...ownPropsResolved,\n ...(definition.bg === 'provider'\n ? { childrenWithBgProvider }\n : { children }),\n },\n restProps,\n dataAttributes,\n utilityStyle,\n } as unknown as UseDefinitionResult<D, P>;\n}\n"],"names":[],"mappings":";;;;;;AA4BO,SAAS,aAAA,CAId,UAAA,EACA,KAAA,EACA,OAA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BAAA;AAAA,IACvC,KAAA;AAAA,IACC,UAAA,CAAW,gBAAgB;AAAC,GAC/B;AAEA,EAAA,MAAM,aAAA,GAA0C,MAAA;AAChD,EAAA,MAAM,eAAA,GAA8C,MAAA;AAEpD,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,KAAA,MAAW,CAAC,MAAM,MAAM,CAAA,IAAK,OAAO,OAAA,CAAQ,UAAA,CAAW,UAAU,CAAA,EAAG;AAClE,IAAA,OAAA,CAAQ,IAAI,CAAA,GAAI,IAAA;AAAA,MACd,MAAA;AAAA,MACA,UAAA,CAAW,OAAO,MAAwC,CAAA;AAAA,MAC1D,kBAAkB,IAAA,IAAQ,cAAA;AAAA,MAC1B,eAAA,KAAoB,QAAQ,gBAAA,CAAiB;AAAA,KAC/C;AAAA,EACF;AAEA,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI,sBAAA;AAEJ,EAAA,IAAI,UAAA,CAAW,OAAO,UAAA,EAAY;AAChC,IAAA,sBAAA,GAAyB,UAAA,CAAW,EAAA,mBAClC,GAAA,CAAC,UAAA,EAAA,EAAW,EAAA,EAAI,WAAW,EAAA,EAAK,QAAA,EAAA,KAAA,CAAM,QAAA,EAAS,CAAA,GAE/C,KAAA,CAAM,QAAA;AAAA,EAEV,CAAA,MAAO;AACL,IAAA,QAAA,GAAW,KAAA,CAAM,QAAA;AAAA,EACnB;AAEA,EAAA,OAAO;AAAA,IACL,QAAA,EAAU;AAAA,MACR,OAAA;AAAA,MACA,GAAG,gBAAA;AAAA,MACH,GAAI,WAAW,EAAA,KAAO,UAAA,GAClB,EAAE,sBAAA,EAAuB,GACzB,EAAE,QAAA;AAAS,KACjB;AAAA,IACA,SAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"useDefinition.esm.js","sources":["../../../src/hooks/useDefinition/useDefinition.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode } from 'react';\nimport clsx from 'clsx';\nimport { useBreakpoint } from '../useBreakpoint';\nimport { useBgProvider, useBgConsumer, BgProvider } from '../useBg';\nimport { resolveDefinitionProps, processUtilityProps } from './helpers';\nimport { useAnalytics } from '../../analytics/useAnalytics';\nimport { noopTracker } from '../../analytics/useAnalytics';\nimport type {\n ComponentConfig,\n UseDefinitionOptions,\n UseDefinitionResult,\n UtilityKeys,\n} from './types';\n\nexport function useDefinition<\n D extends ComponentConfig<any, any>,\n P extends Record<string, any>,\n>(\n definition: D,\n props: P,\n options?: UseDefinitionOptions<D>,\n): UseDefinitionResult<D, P> {\n const { breakpoint } = useBreakpoint();\n\n // Resolve all props centrally — applies responsive values and defaults\n const { ownPropsResolved, restProps } = resolveDefinitionProps(\n definition,\n props,\n breakpoint,\n );\n\n const dataAttributes: Record<string, string | undefined> = {};\n\n for (const [key, config] of Object.entries(definition.propDefs)) {\n const finalValue = ownPropsResolved[key];\n\n if (finalValue !== undefined) {\n // Skip data-bg for bg prop when the provider path handles it\n if (key === 'bg' && definition.bg === 'provider') continue;\n\n if ((config as any).dataAttribute) {\n // eslint-disable-next-line no-restricted-syntax\n dataAttributes[`data-${key.toLowerCase()}`] = String(finalValue);\n }\n }\n }\n\n // Provider: resolve bg and provide context for children\n const providerBg = useBgProvider(\n definition.bg === 'provider' ? ownPropsResolved.bg : undefined,\n );\n\n // Consumer: read parent context bg\n const consumerBg = useBgConsumer();\n\n // Provider: set data-bg from the resolved provider bg\n if (definition.bg === 'provider' && providerBg.bg !== undefined) {\n dataAttributes['data-bg'] = String(providerBg.bg);\n }\n\n // Consumer: set data-on-bg from the parent context\n if (definition.bg === 'consumer' && consumerBg.bg !== undefined) {\n dataAttributes['data-on-bg'] = String(consumerBg.bg);\n }\n\n const { utilityClasses, utilityStyle } = processUtilityProps<UtilityKeys<D>>(\n props,\n (definition.utilityProps ?? []) as readonly UtilityKeys<D>[],\n );\n\n // Analytics: conditionally call useAnalytics based on definition flag\n // Safe: definition is a module-level constant, condition never changes at runtime\n let analytics = noopTracker;\n if (definition.analytics) {\n const tracker = useAnalytics();\n analytics = ownPropsResolved.noTrack ? noopTracker : tracker;\n }\n\n const utilityTarget = options?.utilityTarget ?? 'root';\n const classNameTarget = options?.classNameTarget ?? 'root';\n\n const classes: Record<string, string> = {};\n\n for (const [name, cssKey] of Object.entries(definition.classNames)) {\n classes[name] = clsx(\n cssKey as string,\n definition.styles[cssKey as keyof typeof definition.styles],\n utilityTarget === name && utilityClasses,\n classNameTarget === name && ownPropsResolved.className,\n );\n }\n\n let children: ReactNode | undefined;\n let childrenWithBgProvider: ReactNode | undefined;\n\n if (definition.bg === 'provider') {\n childrenWithBgProvider = providerBg.bg ? (\n <BgProvider bg={providerBg.bg}>{props.children}</BgProvider>\n ) : (\n props.children\n );\n } else {\n children = props.children;\n }\n\n return {\n ownProps: {\n classes,\n ...ownPropsResolved,\n ...(definition.bg === 'provider'\n ? { childrenWithBgProvider }\n : { children }),\n },\n restProps,\n dataAttributes,\n utilityStyle,\n ...(definition.analytics ? { analytics } : {}),\n } as unknown as UseDefinitionResult<D, P>;\n}\n"],"names":[],"mappings":";;;;;;;AA8BO,SAAS,aAAA,CAId,UAAA,EACA,KAAA,EACA,OAAA,EAC2B;AAC3B,EAAA,MAAM,EAAE,UAAA,EAAW,GAAI,aAAA,EAAc;AAGrC,EAAA,MAAM,EAAE,gBAAA,EAAkB,SAAA,EAAU,GAAI,sBAAA;AAAA,IACtC,UAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,iBAAqD,EAAC;AAE5D,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