@backstage/ui 0.9.0-next.3 → 0.9.0
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/CHANGELOG.md +174 -0
- package/README.md +23 -0
- package/dist/components/Accordion/Accordion.esm.js +5 -4
- package/dist/components/Accordion/Accordion.esm.js.map +1 -1
- package/dist/components/Accordion/definition.esm.js +15 -0
- package/dist/components/Accordion/definition.esm.js.map +1 -0
- package/dist/components/Avatar/Avatar.esm.js +9 -5
- package/dist/components/Avatar/Avatar.esm.js.map +1 -1
- package/dist/components/Avatar/definition.esm.js +13 -0
- package/dist/components/Avatar/definition.esm.js.map +1 -0
- package/dist/components/Box/Box.esm.js +2 -1
- package/dist/components/Box/Box.esm.js.map +1 -1
- package/dist/components/Box/definition.esm.js +32 -0
- package/dist/components/Box/definition.esm.js.map +1 -0
- package/dist/components/Button/Button.esm.js +9 -5
- package/dist/components/Button/Button.esm.js.map +1 -1
- package/dist/components/Button/definition.esm.js +15 -0
- package/dist/components/Button/definition.esm.js.map +1 -0
- package/dist/components/ButtonIcon/ButtonIcon.esm.js +11 -6
- package/dist/components/ButtonIcon/ButtonIcon.esm.js.map +1 -1
- package/dist/components/ButtonIcon/definition.esm.js +10 -0
- package/dist/components/ButtonIcon/definition.esm.js.map +1 -0
- package/dist/components/ButtonLink/ButtonLink.esm.js +11 -6
- package/dist/components/ButtonLink/ButtonLink.esm.js.map +1 -1
- package/dist/components/ButtonLink/definition.esm.js +8 -0
- package/dist/components/ButtonLink/definition.esm.js.map +1 -0
- package/dist/components/Card/Card.esm.js +5 -4
- package/dist/components/Card/Card.esm.js.map +1 -1
- package/dist/components/Card/definition.esm.js +11 -0
- package/dist/components/Card/definition.esm.js.map +1 -0
- package/dist/components/Checkbox/Checkbox.esm.js +2 -1
- package/dist/components/Checkbox/Checkbox.esm.js.map +1 -1
- package/dist/components/Checkbox/definition.esm.js +12 -0
- package/dist/components/Checkbox/definition.esm.js.map +1 -0
- package/dist/components/Container/Container.esm.js +2 -1
- package/dist/components/Container/Container.esm.js.map +1 -1
- package/dist/components/Container/definition.esm.js +9 -0
- package/dist/components/Container/definition.esm.js.map +1 -0
- package/dist/components/Dialog/Dialog.esm.js +5 -4
- package/dist/components/Dialog/Dialog.esm.js.map +1 -1
- package/dist/components/Dialog/definition.esm.js +13 -0
- package/dist/components/Dialog/definition.esm.js.map +1 -0
- package/dist/components/FieldError/FieldError.esm.js +2 -1
- package/dist/components/FieldError/FieldError.esm.js.map +1 -1
- package/dist/components/FieldError/definition.esm.js +8 -0
- package/dist/components/FieldError/definition.esm.js.map +1 -0
- package/dist/components/FieldLabel/FieldLabel.esm.js +2 -1
- package/dist/components/FieldLabel/FieldLabel.esm.js.map +1 -1
- package/dist/components/FieldLabel/definition.esm.js +11 -0
- package/dist/components/FieldLabel/definition.esm.js.map +1 -0
- package/dist/components/Flex/Flex.esm.js +2 -1
- package/dist/components/Flex/Flex.esm.js.map +1 -1
- package/dist/components/Flex/definition.esm.js +28 -0
- package/dist/components/Flex/definition.esm.js.map +1 -0
- package/dist/components/Grid/Grid.esm.js +3 -2
- package/dist/components/Grid/Grid.esm.js.map +1 -1
- package/dist/components/Grid/definition.esm.js +32 -0
- package/dist/components/Grid/definition.esm.js.map +1 -0
- package/dist/components/Header/Header.esm.js +2 -1
- package/dist/components/Header/Header.esm.js.map +1 -1
- package/dist/components/Header/HeaderToolbar.esm.js +2 -1
- package/dist/components/Header/HeaderToolbar.esm.js.map +1 -1
- package/dist/components/Header/definition.esm.js +14 -0
- package/dist/components/Header/definition.esm.js.map +1 -0
- package/dist/components/HeaderPage/HeaderPage.esm.js +2 -1
- package/dist/components/HeaderPage/HeaderPage.esm.js.map +1 -1
- package/dist/components/HeaderPage/definition.esm.js +12 -0
- package/dist/components/HeaderPage/definition.esm.js.map +1 -0
- package/dist/components/Link/Link.esm.js +10 -6
- package/dist/components/Link/Link.esm.js.map +1 -1
- package/dist/components/Link/definition.esm.js +14 -0
- package/dist/components/Link/definition.esm.js.map +1 -0
- package/dist/components/Menu/Menu.esm.js +10 -9
- package/dist/components/Menu/Menu.esm.js.map +1 -1
- package/dist/components/Menu/definition.esm.js +23 -0
- package/dist/components/Menu/definition.esm.js.map +1 -0
- package/dist/components/Popover/definition.esm.js +8 -0
- package/dist/components/Popover/definition.esm.js.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.esm.js +3 -2
- package/dist/components/RadioGroup/RadioGroup.esm.js.map +1 -1
- package/dist/components/RadioGroup/definition.esm.js +10 -0
- package/dist/components/RadioGroup/definition.esm.js.map +1 -0
- package/dist/components/SearchField/SearchField.esm.js +2 -1
- package/dist/components/SearchField/SearchField.esm.js.map +1 -1
- package/dist/components/SearchField/definition.esm.js +16 -0
- package/dist/components/SearchField/definition.esm.js.map +1 -0
- package/dist/components/Select/Select.esm.js +11 -6
- package/dist/components/Select/Select.esm.js.map +1 -1
- package/dist/components/Select/SelectContent.esm.js +2 -1
- package/dist/components/Select/SelectContent.esm.js.map +1 -1
- package/dist/components/Select/SelectListBox.esm.js +3 -2
- package/dist/components/Select/SelectListBox.esm.js.map +1 -1
- package/dist/components/Select/SelectTrigger.esm.js +2 -1
- package/dist/components/Select/SelectTrigger.esm.js.map +1 -1
- package/dist/components/Select/definition.esm.js +23 -0
- package/dist/components/Select/definition.esm.js.map +1 -0
- package/dist/components/Skeleton/Skeleton.esm.js +2 -1
- package/dist/components/Skeleton/Skeleton.esm.js.map +1 -1
- package/dist/components/Skeleton/definition.esm.js +8 -0
- package/dist/components/Skeleton/definition.esm.js.map +1 -0
- package/dist/components/Switch/Switch.esm.js +2 -1
- package/dist/components/Switch/Switch.esm.js.map +1 -1
- package/dist/components/Switch/definition.esm.js +9 -0
- package/dist/components/Switch/definition.esm.js.map +1 -0
- package/dist/components/Table/components/Cell.esm.js +2 -1
- package/dist/components/Table/components/Cell.esm.js.map +1 -1
- package/dist/components/Table/components/CellProfile.esm.js +5 -7
- package/dist/components/Table/components/CellProfile.esm.js.map +1 -1
- package/dist/components/Table/components/Column.esm.js +2 -4
- package/dist/components/Table/components/Column.esm.js.map +1 -1
- package/dist/components/Table/components/Row.esm.js +2 -4
- package/dist/components/Table/components/Row.esm.js.map +1 -1
- package/dist/components/Table/components/Table.esm.js +2 -4
- package/dist/components/Table/components/Table.esm.js.map +1 -1
- package/dist/components/Table/components/TableBody.esm.js +2 -4
- package/dist/components/Table/components/TableBody.esm.js.map +1 -1
- package/dist/components/Table/components/TableHeader.esm.js +2 -4
- package/dist/components/Table/components/TableHeader.esm.js.map +1 -1
- package/dist/components/Table/definition.esm.js +24 -0
- package/dist/components/Table/definition.esm.js.map +1 -0
- package/dist/components/TablePagination/TablePagination.esm.js +2 -1
- package/dist/components/TablePagination/TablePagination.esm.js.map +1 -1
- package/dist/components/TablePagination/definition.esm.js +11 -0
- package/dist/components/TablePagination/definition.esm.js.map +1 -0
- package/dist/components/Tabs/Tabs.esm.js +5 -4
- package/dist/components/Tabs/Tabs.esm.js.map +1 -1
- package/dist/components/Tabs/TabsIndicators.esm.js +2 -1
- package/dist/components/Tabs/TabsIndicators.esm.js.map +1 -1
- package/dist/components/Tabs/definition.esm.js +14 -0
- package/dist/components/Tabs/definition.esm.js.map +1 -0
- package/dist/components/TagGroup/TagGroup.esm.js +3 -2
- package/dist/components/TagGroup/TagGroup.esm.js.map +1 -1
- package/dist/components/TagGroup/definition.esm.js +12 -0
- package/dist/components/TagGroup/definition.esm.js.map +1 -0
- package/dist/components/Text/Text.esm.js +10 -6
- package/dist/components/Text/Text.esm.js.map +1 -1
- package/dist/components/Text/definition.esm.js +14 -0
- package/dist/components/Text/definition.esm.js.map +1 -0
- package/dist/components/TextField/TextField.esm.js +2 -1
- package/dist/components/TextField/TextField.esm.js.map +1 -1
- package/dist/components/TextField/definition.esm.js +17 -0
- package/dist/components/TextField/definition.esm.js.map +1 -0
- package/dist/components/Tooltip/Tooltip.esm.js +2 -1
- package/dist/components/Tooltip/Tooltip.esm.js.map +1 -1
- package/dist/components/Tooltip/definition.esm.js +9 -0
- package/dist/components/Tooltip/definition.esm.js.map +1 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.esm.js +5 -1
- package/dist/components/VisuallyHidden/VisuallyHidden.esm.js.map +1 -1
- package/dist/components/VisuallyHidden/definition.esm.js +8 -0
- package/dist/components/VisuallyHidden/definition.esm.js.map +1 -0
- package/dist/hooks/useStyles.esm.js +1 -3
- package/dist/hooks/useStyles.esm.js.map +1 -1
- package/dist/index.d.ts +455 -362
- package/dist/index.esm.js +30 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/dist/utils/componentDefinitions.esm.js +0 -406
- package/dist/utils/componentDefinitions.esm.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisuallyHidden.esm.js","sources":["../../../src/components/VisuallyHidden/VisuallyHidden.tsx"],"sourcesContent":["/*\n * Copyright 2024 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 { useStyles } from '../../hooks/useStyles';\nimport { VisuallyHiddenProps } from './types';\nimport styles from './VisuallyHidden.module.css';\nimport clsx from 'clsx';\n\n/**\n * Visually hides content while keeping it accessible to screen readers.\n * Useful for descriptive labels and other screen-reader-only content.\n *\n * Note: This component is for content that should ALWAYS remain visually hidden.\n * For skip links that become visible on focus, use a different approach.\n *\n * @public\n */\nexport const VisuallyHidden = (props: VisuallyHiddenProps) => {\n const { classNames, cleanedProps } = useStyles(
|
|
1
|
+
{"version":3,"file":"VisuallyHidden.esm.js","sources":["../../../src/components/VisuallyHidden/VisuallyHidden.tsx"],"sourcesContent":["/*\n * Copyright 2024 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 { useStyles } from '../../hooks/useStyles';\nimport { VisuallyHiddenDefinition } from './definition';\nimport { VisuallyHiddenProps } from './types';\nimport styles from './VisuallyHidden.module.css';\nimport clsx from 'clsx';\n\n/**\n * Visually hides content while keeping it accessible to screen readers.\n * Useful for descriptive labels and other screen-reader-only content.\n *\n * Note: This component is for content that should ALWAYS remain visually hidden.\n * For skip links that become visible on focus, use a different approach.\n *\n * @public\n */\nexport const VisuallyHidden = (props: VisuallyHiddenProps) => {\n const { classNames, cleanedProps } = useStyles(\n VisuallyHiddenDefinition,\n props,\n );\n const { className, ...rest } = cleanedProps;\n\n return (\n <div\n className={clsx(classNames.root, styles[classNames.root], className)}\n {...rest}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AA+BO,MAAM,cAAA,GAAiB,CAAC,KAAA,KAA+B;AAC5D,EAAA,MAAM,EAAE,UAAA,EAAY,YAAA,EAAa,GAAI,SAAA;AAAA,IACnC,wBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,MAAM,EAAE,SAAA,EAAW,GAAG,IAAA,EAAK,GAAI,YAAA;AAE/B,EAAA,uBACE,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,KAAK,UAAA,CAAW,IAAA,EAAM,OAAO,UAAA,CAAW,IAAI,GAAG,SAAS,CAAA;AAAA,MAClE,GAAG;AAAA;AAAA,GACN;AAEJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.esm.js","sources":["../../../src/components/VisuallyHidden/definition.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { ComponentDefinition } from '../../types';\n\n/**\n * Component definition for VisuallyHidden\n * @public\n */\nexport const VisuallyHiddenDefinition = {\n classNames: {\n root: 'bui-VisuallyHidden',\n },\n} as const satisfies ComponentDefinition;\n"],"names":[],"mappings":"AAsBO,MAAM,wBAAA,GAA2B;AAAA,EACtC,UAAA,EAAY;AAAA,IACV,IAAA,EAAM;AAAA;AAEV;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useBreakpoint, breakpoints } from './useBreakpoint.esm.js';
|
|
2
|
-
import { componentDefinitions } from '../utils/componentDefinitions.esm.js';
|
|
3
2
|
import { utilityClassMap } from '../utils/utilityClassMap.esm.js';
|
|
4
3
|
|
|
5
4
|
function resolveResponsiveValue(value, breakpoint) {
|
|
@@ -21,9 +20,8 @@ function resolveResponsiveValue(value, breakpoint) {
|
|
|
21
20
|
}
|
|
22
21
|
return void 0;
|
|
23
22
|
}
|
|
24
|
-
function useStyles(
|
|
23
|
+
function useStyles(componentDefinition, props = {}) {
|
|
25
24
|
const { breakpoint } = useBreakpoint();
|
|
26
|
-
const componentDefinition = componentDefinitions[componentName];
|
|
27
25
|
const classNames = componentDefinition.classNames;
|
|
28
26
|
const utilityPropNames = ("utilityProps" in componentDefinition ? componentDefinition.utilityProps : []) || [];
|
|
29
27
|
const dataAttributeNames = "dataAttributes" in componentDefinition ? Object.keys(componentDefinition.dataAttributes || {}) : [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStyles.esm.js","sources":["../../src/hooks/useStyles.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 { useBreakpoint, breakpoints } from './useBreakpoint';\nimport { componentDefinitions } from '../utils/componentDefinitions';\nimport type { ComponentDefinitionName, ComponentClassNames } from '../types';\nimport { utilityClassMap } from '../utils/utilityClassMap';\n\n/**\n * Resolve a responsive value based on the current breakpoint\n * @param value - The responsive value (string or object with breakpoint keys)\n * @param breakpoint - The current breakpoint\n * @returns The resolved value for the current breakpoint\n */\nfunction resolveResponsiveValue(\n value: string | Record<string, string>,\n breakpoint: string,\n): string | undefined {\n if (typeof value === 'string') {\n return value;\n }\n\n if (typeof value === 'object' && value !== null) {\n const index = breakpoints.findIndex(b => b.id === breakpoint);\n\n // Look for value at current breakpoint or smaller\n for (let i = index; i >= 0; i--) {\n if (value[breakpoints[i].id]) {\n return value[breakpoints[i].id];\n }\n }\n\n // If no value found, check from smallest breakpoint up\n for (let i = 0; i < breakpoints.length; i++) {\n if (value[breakpoints[i].id]) {\n return value[breakpoints[i].id];\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * React hook to get class names and data attributes for a component with responsive support\n * @param componentName - The name of the component\n * @param props - All component props\n * @returns Object with classNames, dataAttributes, utilityClasses, style, and cleanedProps\n */\nexport function useStyles<\n T extends ComponentDefinitionName,\n P extends Record<string, any> = Record<string, any>,\n>(\n componentName: T,\n props: P = {} as P,\n): {\n classNames: ComponentClassNames<T>;\n dataAttributes: Record<string, string>;\n utilityClasses: string;\n style: React.CSSProperties;\n cleanedProps: P;\n} {\n const { breakpoint } = useBreakpoint();\n const componentDefinition = componentDefinitions[componentName];\n const classNames = componentDefinition.classNames as ComponentClassNames<T>;\n const utilityPropNames =\n ('utilityProps' in componentDefinition\n ? componentDefinition.utilityProps\n : []) || [];\n\n // Extract data attribute names from component definition\n const dataAttributeNames =\n 'dataAttributes' in componentDefinition\n ? Object.keys(componentDefinition.dataAttributes || {})\n : [];\n\n // Extract existing style from props\n const incomingStyle = props.style || {};\n\n // Generate data attributes from component definition\n const dataAttributes: Record<string, string> = {};\n for (const key of dataAttributeNames) {\n const value = props[key];\n if (value !== undefined && value !== null) {\n // Handle boolean and number values directly\n if (typeof value === 'boolean' || typeof value === 'number') {\n dataAttributes[`data-${key}`] = String(value);\n } else {\n const resolvedValue = resolveResponsiveValue(value, breakpoint);\n if (resolvedValue !== undefined) {\n dataAttributes[`data-${key}`] = resolvedValue;\n }\n }\n }\n }\n\n // Generate utility classes and custom styles from component's allowed utility props\n const utilityClassList: string[] = [];\n const generatedStyle: React.CSSProperties = {};\n\n const handleUtilityValue = (\n key: string,\n val: unknown,\n prefix: string = '',\n ) => {\n // Get utility class configuration for this key\n const utilityConfig = utilityClassMap[key as keyof typeof utilityClassMap];\n\n if (!utilityConfig) {\n // Skip if no config found for this key\n return;\n }\n\n // Check if value is in the list of valid values for this utility\n if (\n utilityConfig.values.length > 0 &&\n utilityConfig.values.includes(val as string | number)\n ) {\n // Generate utility class with value suffix and optional breakpoint prefix\n const className = prefix\n ? `${prefix}${utilityConfig.class}-${val}`\n : `${utilityConfig.class}-${val}`;\n utilityClassList.push(className);\n } else if (utilityConfig.cssVar) {\n // Custom value - add CSS custom property AND utility class name\n // Only if cssVar is defined (properties with fixed values don't have cssVar)\n const cssVarKey = prefix\n ? `${utilityConfig.cssVar}-${prefix.slice(0, -1)}`\n : utilityConfig.cssVar;\n // CSS custom properties need to be set on the style object as strings\n (generatedStyle as Record<string, unknown>)[cssVarKey] = val;\n\n // Add utility class name (without value suffix) with optional breakpoint prefix\n const className = prefix\n ? `${prefix}${utilityConfig.class}`\n : utilityConfig.class;\n utilityClassList.push(className);\n }\n // If no cssVar and value is not in valid values, skip (invalid value for fixed-value property)\n };\n\n for (const key of utilityPropNames) {\n const value = props[key];\n if (value === undefined || value === null) {\n continue;\n }\n\n // Check if value is a responsive object\n if (typeof value === 'object' && value !== null) {\n const breakpointValues = value as { [key: string]: unknown };\n // Handle responsive object values\n for (const bp in breakpointValues) {\n const prefix = bp === 'initial' ? '' : `${bp}:`;\n handleUtilityValue(key, breakpointValues[bp], prefix);\n }\n } else {\n // Handle simple value\n handleUtilityValue(key, value);\n }\n }\n\n // Create cleaned props by excluding only utility props\n // All other props (including data attributes, style, children, etc.) remain\n const utilityPropsSet = new Set<string>(utilityPropNames);\n\n const cleanedPropsBase = Object.keys(props).reduce((acc, key) => {\n if (!utilityPropsSet.has(key)) {\n acc[key] = props[key];\n }\n return acc;\n }, {} as any);\n\n // Merge incoming style with generated styles (incoming styles take precedence)\n const mergedStyle = {\n ...generatedStyle,\n ...incomingStyle,\n };\n\n // Add merged style to cleanedProps\n const cleanedProps = {\n ...cleanedPropsBase,\n style: mergedStyle,\n } as P;\n\n return {\n classNames,\n dataAttributes,\n utilityClasses: utilityClassList.join(' '),\n style: mergedStyle,\n cleanedProps,\n };\n}\n"],"names":[],"mappings":";;;;AA0BA,SAAS,sBAAA,CACP,OACA,UAAA,EACoB;AACpB,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,EAAM;AAC/C,IAAA,MAAM,QAAQ,WAAA,CAAY,SAAA,CAAU,CAAA,CAAA,KAAK,CAAA,CAAE,OAAO,UAAU,CAAA;AAG5D,IAAA,KAAA,IAAS,CAAA,GAAI,KAAA,EAAO,CAAA,IAAK,CAAA,EAAG,CAAA,EAAA,EAAK;AAC/B,MAAA,IAAI,KAAA,CAAM,WAAA,C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AAe;AAAA,IACnB,GAAG,gBAAA;AAAA,IACH,KAAA,EAAO;AAAA,GACT;AAEA,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA,EAAgB,gBAAA,CAAiB,IAAA,CAAK,GAAG,CAAA;AAAA,IACzC,KAAA,EAAO,WAAA;AAAA,IACP;AAAA,GACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"useStyles.esm.js","sources":["../../src/hooks/useStyles.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 { useBreakpoint, breakpoints } from './useBreakpoint';\nimport type { ComponentDefinition } from '../types';\nimport { utilityClassMap } from '../utils/utilityClassMap';\n\n/**\n * Resolve a responsive value based on the current breakpoint\n * @param value - The responsive value (string or object with breakpoint keys)\n * @param breakpoint - The current breakpoint\n * @returns The resolved value for the current breakpoint\n */\nfunction resolveResponsiveValue(\n value: string | Record<string, string>,\n breakpoint: string,\n): string | undefined {\n if (typeof value === 'string') {\n return value;\n }\n\n if (typeof value === 'object' && value !== null) {\n const index = breakpoints.findIndex(b => b.id === breakpoint);\n\n // Look for value at current breakpoint or smaller\n for (let i = index; i >= 0; i--) {\n if (value[breakpoints[i].id]) {\n return value[breakpoints[i].id];\n }\n }\n\n // If no value found, check from smallest breakpoint up\n for (let i = 0; i < breakpoints.length; i++) {\n if (value[breakpoints[i].id]) {\n return value[breakpoints[i].id];\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * React hook to get class names and data attributes for a component with responsive support\n * @param componentDefinition - The component's definition object\n * @param props - All component props\n * @returns Object with classNames, dataAttributes, utilityClasses, style, and cleanedProps\n */\nexport function useStyles<\n T extends ComponentDefinition,\n P extends Record<string, any> = Record<string, any>,\n>(\n componentDefinition: T,\n props: P = {} as P,\n): {\n classNames: T['classNames'];\n dataAttributes: Record<string, string>;\n utilityClasses: string;\n style: React.CSSProperties;\n cleanedProps: P;\n} {\n const { breakpoint } = useBreakpoint();\n const classNames = componentDefinition.classNames;\n const utilityPropNames =\n ('utilityProps' in componentDefinition\n ? componentDefinition.utilityProps\n : []) || [];\n\n // Extract data attribute names from component definition\n const dataAttributeNames =\n 'dataAttributes' in componentDefinition\n ? Object.keys(componentDefinition.dataAttributes || {})\n : [];\n\n // Extract existing style from props\n const incomingStyle = props.style || {};\n\n // Generate data attributes from component definition\n const dataAttributes: Record<string, string> = {};\n for (const key of dataAttributeNames) {\n const value = props[key];\n if (value !== undefined && value !== null) {\n // Handle boolean and number values directly\n if (typeof value === 'boolean' || typeof value === 'number') {\n dataAttributes[`data-${key}`] = String(value);\n } else {\n const resolvedValue = resolveResponsiveValue(value, breakpoint);\n if (resolvedValue !== undefined) {\n dataAttributes[`data-${key}`] = resolvedValue;\n }\n }\n }\n }\n\n // Generate utility classes and custom styles from component's allowed utility props\n const utilityClassList: string[] = [];\n const generatedStyle: React.CSSProperties = {};\n\n const handleUtilityValue = (\n key: string,\n val: unknown,\n prefix: string = '',\n ) => {\n // Get utility class configuration for this key\n const utilityConfig = utilityClassMap[key as keyof typeof utilityClassMap];\n\n if (!utilityConfig) {\n // Skip if no config found for this key\n return;\n }\n\n // Check if value is in the list of valid values for this utility\n if (\n utilityConfig.values.length > 0 &&\n utilityConfig.values.includes(val as string | number)\n ) {\n // Generate utility class with value suffix and optional breakpoint prefix\n const className = prefix\n ? `${prefix}${utilityConfig.class}-${val}`\n : `${utilityConfig.class}-${val}`;\n utilityClassList.push(className);\n } else if (utilityConfig.cssVar) {\n // Custom value - add CSS custom property AND utility class name\n // Only if cssVar is defined (properties with fixed values don't have cssVar)\n const cssVarKey = prefix\n ? `${utilityConfig.cssVar}-${prefix.slice(0, -1)}`\n : utilityConfig.cssVar;\n // CSS custom properties need to be set on the style object as strings\n (generatedStyle as Record<string, unknown>)[cssVarKey] = val;\n\n // Add utility class name (without value suffix) with optional breakpoint prefix\n const className = prefix\n ? `${prefix}${utilityConfig.class}`\n : utilityConfig.class;\n utilityClassList.push(className);\n }\n // If no cssVar and value is not in valid values, skip (invalid value for fixed-value property)\n };\n\n for (const key of utilityPropNames) {\n const value = props[key];\n if (value === undefined || value === null) {\n continue;\n }\n\n // Check if value is a responsive object\n if (typeof value === 'object' && value !== null) {\n const breakpointValues = value as { [key: string]: unknown };\n // Handle responsive object values\n for (const bp in breakpointValues) {\n const prefix = bp === 'initial' ? '' : `${bp}:`;\n handleUtilityValue(key, breakpointValues[bp], prefix);\n }\n } else {\n // Handle simple value\n handleUtilityValue(key, value);\n }\n }\n\n // Create cleaned props by excluding only utility props\n // All other props (including data attributes, style, children, etc.) remain\n const utilityPropsSet = new Set<string>(utilityPropNames);\n\n const cleanedPropsBase = Object.keys(props).reduce((acc, key) => {\n if (!utilityPropsSet.has(key)) {\n acc[key] = props[key];\n }\n return acc;\n }, {} as any);\n\n // Merge incoming style with generated styles (incoming styles take precedence)\n const mergedStyle = {\n ...generatedStyle,\n ...incomingStyle,\n };\n\n // Add merged style to cleanedProps\n const cleanedProps = {\n ...cleanedPropsBase,\n style: mergedStyle,\n } as P;\n\n return {\n classNames,\n dataAttributes,\n utilityClasses: utilityClassList.join(' '),\n style: mergedStyle,\n cleanedProps,\n };\n}\n"],"names":[],"mappings":";;;AAyBA,SAAS,sBAAA,CACP,OACA,UAAA,EACoB;AACpB,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,EAAM;AAC/C,IAAA,MAAM,QAAQ,WAAA,CAAY,SAAA,CA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