@hitachivantara/uikit-react-core 5.18.5 → 5.19.1
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/dist/cjs/components/Button/Button.cjs +32 -56
- package/dist/cjs/components/Button/Button.cjs.map +1 -1
- package/dist/cjs/components/Button/Button.styles.cjs +122 -240
- package/dist/cjs/components/Button/Button.styles.cjs.map +1 -1
- package/dist/cjs/components/Carousel/Carousel.cjs +95 -110
- package/dist/cjs/components/Carousel/Carousel.cjs.map +1 -1
- package/dist/cjs/components/Carousel/Carousel.styles.cjs +4 -8
- package/dist/cjs/components/Carousel/Carousel.styles.cjs.map +1 -1
- package/dist/cjs/components/Carousel/CarouselControls.cjs +62 -0
- package/dist/cjs/components/Carousel/CarouselControls.cjs.map +1 -0
- package/dist/cjs/components/Carousel/CarouselSlide/CarouselSlide.cjs +2 -1
- package/dist/cjs/components/Carousel/CarouselSlide/CarouselSlide.cjs.map +1 -1
- package/dist/cjs/components/Carousel/CarouselThumbnail.cjs +30 -0
- package/dist/cjs/components/Carousel/CarouselThumbnail.cjs.map +1 -0
- package/dist/cjs/components/Carousel/CarouselThumbnails.cjs +44 -0
- package/dist/cjs/components/Carousel/CarouselThumbnails.cjs.map +1 -0
- package/dist/cjs/components/Dialog/Actions/Actions.cjs +14 -7
- package/dist/cjs/components/Dialog/Actions/Actions.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Actions/Actions.styles.cjs +18 -38
- package/dist/cjs/components/Dialog/Actions/Actions.styles.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Content/Content.cjs +11 -6
- package/dist/cjs/components/Dialog/Content/Content.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Content/Content.styles.cjs +13 -32
- package/dist/cjs/components/Dialog/Content/Content.styles.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Dialog.cjs +20 -21
- package/dist/cjs/components/Dialog/Dialog.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Dialog.styles.cjs +0 -31
- package/dist/cjs/components/Dialog/Dialog.styles.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Title/Title.cjs +22 -11
- package/dist/cjs/components/Dialog/Title/Title.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Title/Title.styles.cjs +18 -64
- package/dist/cjs/components/Dialog/Title/Title.styles.cjs.map +1 -1
- package/dist/cjs/components/Drawer/Drawer.cjs +4 -5
- package/dist/cjs/components/Drawer/Drawer.cjs.map +1 -1
- package/dist/cjs/components/Header/Actions/Actions.styles.cjs +3 -2
- package/dist/cjs/components/Header/Actions/Actions.styles.cjs.map +1 -1
- package/dist/cjs/components/Header/Navigation/MenuItem/MenuItem.cjs +6 -1
- package/dist/cjs/components/Header/Navigation/MenuItem/MenuItem.cjs.map +1 -1
- package/dist/cjs/components/InlineEditor/InlineEditor.cjs +15 -19
- package/dist/cjs/components/InlineEditor/InlineEditor.cjs.map +1 -1
- package/dist/cjs/components/MultiButton/MultiButton.styles.cjs +3 -2
- package/dist/cjs/components/MultiButton/MultiButton.styles.cjs.map +1 -1
- package/dist/cjs/components/Pagination/Pagination.cjs.map +1 -1
- package/dist/cjs/components/QueryBuilder/QueryBuilder.cjs.map +1 -1
- package/dist/cjs/components/Snackbar/SnackbarContentWrapper/SnackbarContentWrapper.cjs.map +1 -1
- package/dist/cjs/components/Snackbar/SnackbarProvider/SnackbarProvider.cjs +1 -1
- package/dist/cjs/components/Snackbar/SnackbarProvider/SnackbarProvider.cjs.map +1 -1
- package/dist/cjs/components/Table/TableCell/TableCell.cjs +6 -6
- package/dist/cjs/components/Table/TableCell/TableCell.cjs.map +1 -1
- package/dist/cjs/components/Table/TableRow/TableRow.cjs +6 -5
- package/dist/cjs/components/Table/TableRow/TableRow.cjs.map +1 -1
- package/dist/cjs/index.cjs +12 -12
- package/dist/cjs/utils/classes.cjs +2 -2
- package/dist/cjs/utils/classes.cjs.map +1 -1
- package/dist/cjs/utils/theme.cjs +6 -7
- package/dist/cjs/utils/theme.cjs.map +1 -1
- package/dist/esm/components/Button/Button.js +37 -60
- package/dist/esm/components/Button/Button.js.map +1 -1
- package/dist/esm/components/Button/Button.styles.js +122 -238
- package/dist/esm/components/Button/Button.styles.js.map +1 -1
- package/dist/esm/components/Carousel/Carousel.js +96 -111
- package/dist/esm/components/Carousel/Carousel.js.map +1 -1
- package/dist/esm/components/Carousel/Carousel.styles.js +4 -8
- package/dist/esm/components/Carousel/Carousel.styles.js.map +1 -1
- package/dist/esm/components/Carousel/CarouselControls.js +62 -0
- package/dist/esm/components/Carousel/CarouselControls.js.map +1 -0
- package/dist/esm/components/Carousel/CarouselSlide/CarouselSlide.js +2 -1
- package/dist/esm/components/Carousel/CarouselSlide/CarouselSlide.js.map +1 -1
- package/dist/esm/components/Carousel/CarouselThumbnail.js +30 -0
- package/dist/esm/components/Carousel/CarouselThumbnail.js.map +1 -0
- package/dist/esm/components/Carousel/CarouselThumbnails.js +44 -0
- package/dist/esm/components/Carousel/CarouselThumbnails.js.map +1 -0
- package/dist/esm/components/Dialog/Actions/Actions.js +15 -9
- package/dist/esm/components/Dialog/Actions/Actions.js.map +1 -1
- package/dist/esm/components/Dialog/Actions/Actions.styles.js +18 -35
- package/dist/esm/components/Dialog/Actions/Actions.styles.js.map +1 -1
- package/dist/esm/components/Dialog/Content/Content.js +14 -8
- package/dist/esm/components/Dialog/Content/Content.js.map +1 -1
- package/dist/esm/components/Dialog/Content/Content.styles.js +13 -30
- package/dist/esm/components/Dialog/Content/Content.styles.js.map +1 -1
- package/dist/esm/components/Dialog/Dialog.js +20 -22
- package/dist/esm/components/Dialog/Dialog.js.map +1 -1
- package/dist/esm/components/Dialog/Dialog.styles.js +0 -29
- package/dist/esm/components/Dialog/Dialog.styles.js.map +1 -1
- package/dist/esm/components/Dialog/Title/Title.js +23 -13
- package/dist/esm/components/Dialog/Title/Title.js.map +1 -1
- package/dist/esm/components/Dialog/Title/Title.styles.js +18 -61
- package/dist/esm/components/Dialog/Title/Title.styles.js.map +1 -1
- package/dist/esm/components/Drawer/Drawer.js +4 -5
- package/dist/esm/components/Drawer/Drawer.js.map +1 -1
- package/dist/esm/components/Header/Actions/Actions.styles.js +3 -2
- package/dist/esm/components/Header/Actions/Actions.styles.js.map +1 -1
- package/dist/esm/components/Header/Navigation/MenuItem/MenuItem.js +6 -1
- package/dist/esm/components/Header/Navigation/MenuItem/MenuItem.js.map +1 -1
- package/dist/esm/components/InlineEditor/InlineEditor.js +16 -20
- package/dist/esm/components/InlineEditor/InlineEditor.js.map +1 -1
- package/dist/esm/components/MultiButton/MultiButton.styles.js +3 -2
- package/dist/esm/components/MultiButton/MultiButton.styles.js.map +1 -1
- package/dist/esm/components/Pagination/Pagination.js.map +1 -1
- package/dist/esm/components/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/esm/components/Snackbar/SnackbarContentWrapper/SnackbarContentWrapper.js.map +1 -1
- package/dist/esm/components/Snackbar/SnackbarProvider/SnackbarProvider.js +1 -1
- package/dist/esm/components/Snackbar/SnackbarProvider/SnackbarProvider.js.map +1 -1
- package/dist/esm/components/Table/TableCell/TableCell.js +6 -6
- package/dist/esm/components/Table/TableCell/TableCell.js.map +1 -1
- package/dist/esm/components/Table/TableRow/TableRow.js +6 -5
- package/dist/esm/components/Table/TableRow/TableRow.js.map +1 -1
- package/dist/esm/index.js +230 -230
- package/dist/esm/utils/classes.js +2 -2
- package/dist/esm/utils/classes.js.map +1 -1
- package/dist/esm/utils/theme.js +6 -7
- package/dist/esm/utils/theme.js.map +1 -1
- package/dist/types/index.d.ts +193 -154
- package/package.json +5 -5
- package/dist/cjs/components/Button/buttonClasses.cjs +0 -8
- package/dist/cjs/components/Button/buttonClasses.cjs.map +0 -1
- package/dist/cjs/components/Dialog/Actions/actionsClasses.cjs +0 -8
- package/dist/cjs/components/Dialog/Actions/actionsClasses.cjs.map +0 -1
- package/dist/cjs/components/Dialog/Content/contentClasses.cjs +0 -8
- package/dist/cjs/components/Dialog/Content/contentClasses.cjs.map +0 -1
- package/dist/cjs/components/Dialog/Title/titleClasses.cjs +0 -8
- package/dist/cjs/components/Dialog/Title/titleClasses.cjs.map +0 -1
- package/dist/esm/components/Button/buttonClasses.js +0 -8
- package/dist/esm/components/Button/buttonClasses.js.map +0 -1
- package/dist/esm/components/Dialog/Actions/actionsClasses.js +0 -8
- package/dist/esm/components/Dialog/Actions/actionsClasses.js.map +0 -1
- package/dist/esm/components/Dialog/Content/contentClasses.js +0 -8
- package/dist/esm/components/Dialog/Content/contentClasses.js.map +0 -1
- package/dist/esm/components/Dialog/Title/titleClasses.js +0 -8
- package/dist/esm/components/Dialog/Title/titleClasses.js.map +0 -1
|
@@ -29,12 +29,12 @@ const replace$ = (stylesObj, name) => {
|
|
|
29
29
|
function createClasses(name, stylesObject) {
|
|
30
30
|
const styles = replace$(stylesObject, name);
|
|
31
31
|
const staticClasses = getClasses(Object.keys(styles), name);
|
|
32
|
-
function useClasses(classesProp = {}) {
|
|
32
|
+
function useClasses(classesProp = {}, addStatic = true) {
|
|
33
33
|
const {
|
|
34
34
|
cx,
|
|
35
35
|
css
|
|
36
36
|
} = useCss();
|
|
37
|
-
const mergeClasses = (key) => cx(`${name}-${key}`, css(styles[key]), classesProp == null ? void 0 : classesProp[key]);
|
|
37
|
+
const mergeClasses = (key) => cx(addStatic && `${name}-${key}`, css(styles[key]), classesProp == null ? void 0 : classesProp[key]);
|
|
38
38
|
const classes = Object.fromEntries(Object.keys(styles).map((key) => [key, mergeClasses(key)]));
|
|
39
39
|
return {
|
|
40
40
|
classes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classes.js","sources":["../../../src/utils/classes.ts"],"sourcesContent":["import { CSSInterpolation } from \"@emotion/css\";\nimport { useCss } from \"@core/hooks/useCss\";\n\nexport type ExtractNames<\n T extends (...args: any) => { classes: Record<string, any>; cx: any }\n> = Partial<ReturnType<T>[\"classes\"]>;\n\nexport const getClasses = <T extends string, N extends string>(\n keys: T[],\n name: N\n) => {\n const classesObj: Record<string, string> = {};\n keys.forEach((key: string) => {\n classesObj[key] = `${name}-${key}`;\n });\n return classesObj as { [P in T]: `${N}-${P}` };\n};\n\nconst deepRenameKeys = <T extends object>(\n obj: T,\n mapFn: (key: string) => string\n): T => {\n const result: any = {};\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const newKey = mapFn(key);\n const value = obj[key];\n result[newKey] =\n typeof value === \"object\" ? deepRenameKeys(value as any, mapFn) : value;\n }\n }\n return result;\n};\n\n/** Given a `stylesObj`, replaces its keys' `$myClass` with `.{name}-myClass`. */\nexport const replace$ = <T extends object>(stylesObj: T, name: string): T => {\n return deepRenameKeys(stylesObj, (key) => {\n const matches = key.match(/\\$\\w+/g);\n if (!matches?.length) return key;\n const newKey = matches.reduce(\n (acc, match) => acc.replace(match, `.${name}-${match.slice(1)}`),\n key\n );\n return newKey ?? key;\n });\n};\n\n/** Utility function to create classes for a component. */\nexport function createClasses<Name extends string, ClassName extends string>(\n /** Component name in PascalCase (ie. `HvTableCell`). */\n name: Name,\n stylesObject: Record<ClassName, CSSInterpolation>\n) {\n const styles = replace$(stylesObject, name);\n\n const staticClasses = getClasses(Object.keys(styles) as ClassName[], name);\n\n function useClasses(classesProp: Partial<Record<ClassName, string>> = {}) {\n const { cx, css } = useCss();\n\n const mergeClasses = (key: string) =>\n cx(`${name}-${key}`, css(styles[key]), classesProp?.[key]);\n\n const classes = Object.fromEntries(\n Object.keys(styles).map((key) => [key, mergeClasses(key)])\n ) as { [P in ClassName]: string };\n\n return { classes, css, cx };\n }\n\n return { useClasses, staticClasses };\n}\n"],"names":["getClasses","keys","name","classesObj","forEach","key","deepRenameKeys","obj","mapFn","result","Object","hasOwn","newKey","value","replace$","stylesObj","matches","match","length","reduce","acc","replace","slice","createClasses","stylesObject","styles","staticClasses","useClasses","classesProp","cx","css","useCss","mergeClasses","classes","fromEntries","map"],"mappings":";AAOaA,MAAAA,aAAa,CACxBC,MACAC,SACG;AACH,QAAMC,aAAqC,CAAA;AACtCC,OAAAA,QAAQ,CAACC,QAAgB;AACjBA,eAAAA,GAAG,IAAK,GAAEH,QAAQG;AAAAA,EAAAA,CAC9B;AACMF,SAAAA;AACT;AAEA,MAAMG,iBAAiB,CACrBC,KACAC,UACM;AACN,QAAMC,SAAc,CAAA;AACpB,aAAWJ,OAAOE,KAAK;AACrB,QAAIG,OAAOC,OAAOJ,KAAKF,GAAG,GAAG;AACrBO,YAAAA,SAASJ,MAAMH,GAAG;AAClBQ,YAAAA,QAAQN,IAAIF,GAAG;AACdO,aAAAA,MAAM,IACX,OAAOC,UAAU,WAAWP,eAAeO,OAAcL,KAAK,IAAIK;AAAAA,IACtE;AAAA,EACF;AACOJ,SAAAA;AACT;AAGaK,MAAAA,WAAW,CAAmBC,WAAcb,SAAoB;AACpEI,SAAAA,eAAeS,WAAYV,CAAQ,QAAA;AAClCW,UAAAA,UAAUX,IAAIY,MAAM,QAAQ;AAClC,QAAI,EAACD,mCAASE;AAAeb,aAAAA;AAC7B,UAAMO,SAASI,QAAQG,OACrB,CAACC,KAAKH,UAAUG,IAAIC,QAAQJ,OAAQ,IAAGf,QAAQe,MAAMK,MAAM,CAAC,GAAG,GAC/DjB,GACF;AACA,WAAOO,UAAUP;AAAAA,EAAAA,CAClB;AACH;AAGgBkB,SAAAA,cAEdrB,MACAsB,cACA;AACMC,QAAAA,SAASX,SAASU,cAActB,IAAI;AAE1C,QAAMwB,gBAAgB1B,WAAWU,OAAOT,KAAKwB,MAAM,GAAkBvB,IAAI;
|
|
1
|
+
{"version":3,"file":"classes.js","sources":["../../../src/utils/classes.ts"],"sourcesContent":["import { CSSInterpolation } from \"@emotion/css\";\nimport { useCss } from \"@core/hooks/useCss\";\n\nexport type ExtractNames<\n T extends (...args: any) => { classes: Record<string, any>; cx: any }\n> = Partial<ReturnType<T>[\"classes\"]>;\n\nexport const getClasses = <T extends string, N extends string>(\n keys: T[],\n name: N\n) => {\n const classesObj: Record<string, string> = {};\n keys.forEach((key: string) => {\n classesObj[key] = `${name}-${key}`;\n });\n return classesObj as { [P in T]: `${N}-${P}` };\n};\n\nconst deepRenameKeys = <T extends object>(\n obj: T,\n mapFn: (key: string) => string\n): T => {\n const result: any = {};\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const newKey = mapFn(key);\n const value = obj[key];\n result[newKey] =\n typeof value === \"object\" ? deepRenameKeys(value as any, mapFn) : value;\n }\n }\n return result;\n};\n\n/** Given a `stylesObj`, replaces its keys' `$myClass` with `.{name}-myClass`. */\nexport const replace$ = <T extends object>(stylesObj: T, name: string): T => {\n return deepRenameKeys(stylesObj, (key) => {\n const matches = key.match(/\\$\\w+/g);\n if (!matches?.length) return key;\n const newKey = matches.reduce(\n (acc, match) => acc.replace(match, `.${name}-${match.slice(1)}`),\n key\n );\n return newKey ?? key;\n });\n};\n\n/** Utility function to create classes for a component. */\nexport function createClasses<Name extends string, ClassName extends string>(\n /** Component name in PascalCase (ie. `HvTableCell`). */\n name: Name,\n stylesObject: Record<ClassName, CSSInterpolation>\n) {\n const styles = replace$(stylesObject, name);\n\n const staticClasses = getClasses(Object.keys(styles) as ClassName[], name);\n\n /**\n * Hook that takes in a component's `classesProp` overrides, and returns the\n * concatenated static/internal/override `classes`, and the cached `cx` and `css` utilities.\n */\n function useClasses(\n classesProp: Partial<Record<ClassName, string>> = {},\n /** Whether to add the static classes. Disable when included by `classesProp` */\n addStatic = true\n ) {\n const { cx, css } = useCss();\n\n const mergeClasses = (key: string) =>\n cx(addStatic && `${name}-${key}`, css(styles[key]), classesProp?.[key]);\n\n const classes = Object.fromEntries(\n Object.keys(styles).map((key) => [key, mergeClasses(key)])\n ) as { [P in ClassName]: string };\n\n return { classes, css, cx };\n }\n\n return { useClasses, staticClasses };\n}\n"],"names":["getClasses","keys","name","classesObj","forEach","key","deepRenameKeys","obj","mapFn","result","Object","hasOwn","newKey","value","replace$","stylesObj","matches","match","length","reduce","acc","replace","slice","createClasses","stylesObject","styles","staticClasses","useClasses","classesProp","addStatic","cx","css","useCss","mergeClas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B,2CAAcvB,IAAI;AAExE,UAAM6B,UAAUxB,OAAOyB,YACrBzB,OAAOT,KAAKwB,MAAM,EAAEW,IAAK/B,CAAAA,QAAQ,CAACA,KAAK4B,aAAa5B,GAAG,CAAC,CAAC,CAC3D;AAEO,WAAA;AAAA,MAAE6B;AAAAA,MAASH;AAAAA,MAAKD;AAAAA,IAAAA;AAAAA,EACzB;AAEO,SAAA;AAAA,IAAEH;AAAAA,IAAYD;AAAAA,EAAAA;AACvB;"}
|
package/dist/esm/utils/theme.js
CHANGED
|
@@ -89,13 +89,12 @@ const processThemes = (themesList) => {
|
|
|
89
89
|
}
|
|
90
90
|
return [themes.ds5];
|
|
91
91
|
};
|
|
92
|
-
const getVarValue = (cssVar) => {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return computedValue;
|
|
92
|
+
const getVarValue = (cssVar, rootElementId) => {
|
|
93
|
+
const root = document.getElementById(rootElementId || "hv-root");
|
|
94
|
+
if (root) {
|
|
95
|
+
const computedValue = getComputedStyle(root).getPropertyValue(cssVar.replace("var(", "").replace(")", "")).trim();
|
|
96
|
+
return computedValue;
|
|
97
|
+
}
|
|
99
98
|
};
|
|
100
99
|
export {
|
|
101
100
|
createTheme,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","sources":["../../../src/utils/theme.ts"],"sourcesContent":["/* eslint import/namespace: [2, { allowComputed: true }] */\nimport { CSSProperties } from \"react\";\nimport {\n themes,\n HvThemeColorModeStructure,\n HvThemeStructure,\n theme,\n} from \"@hitachivantara/uikit-styles\";\nimport { HvTheme, HvCreateThemeProps } from \"@core/types\";\n\n/**\n * Sets the element style properties.\n */\nconst setElementStyle = (element: HTMLElement, style: CSSProperties) => {\n Object.entries(style).forEach(([property, value]) => {\n element.style[property] = value;\n });\n};\n\n/**\n * Sets the element attributes and style for a theme and color mode.\n */\nexport const setElementAttrs = (\n themeName: string,\n modeName: string,\n colorScheme: string,\n themeRootId?: string\n) => {\n const element = themeRootId\n ? document.getElementById(themeRootId)\n : document.body;\n\n if (element) {\n element.setAttribute(`data-theme`, themeName);\n element.setAttribute(`data-color-mode`, modeName);\n\n // Set default properties for all components to inherit\n setElementStyle(element, {\n colorScheme,\n backgroundColor: theme.colors.backgroundColor,\n accentColor: theme.colors.secondary,\n color: theme.colors.secondary,\n fontSize: theme.typography.body.fontSize,\n fontWeight: theme.typography.body.fontWeight,\n lineHeight: theme.typography.body.lineHeight,\n letterSpacing: theme.typography.body.letterSpacing,\n fontFamily: theme.fontFamily.body,\n });\n }\n};\n\n/**\n * Applies customizations to a theme.\n */\nconst applyThemeCustomizations = (obj: object, customizations: object) => {\n const isObject = (val: any) =>\n val && typeof val === \"object\" && !Array.isArray(val);\n\n // Customized theme\n const customizedTheme = { ...obj };\n\n // Add new values to the theme or replace values\n Object.keys(customizations).forEach((key) => {\n if (customizedTheme[key]) {\n if (isObject(customizedTheme[key]) && isObject(customizations[key])) {\n customizedTheme[key] = applyThemeCustomizations(\n customizedTheme[key],\n customizations[key]\n );\n } else if (typeof customizedTheme[key] === typeof customizations[key]) {\n customizedTheme[key] = customizations[key];\n }\n } else {\n customizedTheme[key] = customizations[key];\n }\n });\n\n return customizedTheme;\n};\n\n/**\n * Creates a customized theme based on the base theme and customizations given.\n * For the color modes, the colors that are not defined will be replaced by the values from the dawn mode of the base theme.\n */\nexport const createTheme = (\n props: HvCreateThemeProps\n): HvTheme | HvThemeStructure => {\n const {\n name,\n base = \"ds5\",\n inheritColorModes = true,\n ...customizations\n } = props;\n\n // Apply customizations to the base theme\n const customizedTheme: HvTheme | HvThemeStructure = customizations\n ? (applyThemeCustomizations(themes[base], customizations) as HvTheme)\n : { ...themes[base] };\n\n // Set theme name\n customizedTheme.name = name.trim();\n // Set theme base\n customizedTheme.base = base;\n\n // Fill new color modes with missing colors\n if (customizations) {\n Object.keys(customizedTheme.colors.modes).forEach((mode) => {\n if (!themes[base].colors.modes[mode]) {\n customizedTheme.colors.modes[mode] = {\n ...themes[base].colors.modes.dawn,\n ...(customizedTheme.colors.modes[mode] as Partial<\n HvThemeColorModeStructure & { [key: string]: string }\n >),\n };\n }\n });\n }\n\n // If the flag `inheritColorModes` is false and customizations were given for the color modes,\n // we're removing any color modes that might have been inherited\n if (!inheritColorModes && customizations.colors?.modes) {\n Object.keys(customizedTheme.colors.modes).forEach((mode) => {\n if (!Object.keys(customizations.colors?.modes || {}).includes(mode)) {\n delete customizedTheme.colors.modes[mode];\n }\n });\n }\n\n // Created theme\n return customizedTheme;\n};\n\n/**\n * Process the themes provided to the HvProvider:\n * - Cleans themes with the same name\n * - Returns the default if the list is empty (ds5)\n */\nexport const processThemes = (\n themesList?: (HvTheme | HvThemeStructure)[]\n): (HvTheme | HvThemeStructure)[] => {\n if (themesList && Array.isArray(themesList) && themesList.length > 0) {\n const list: (HvTheme | HvThemeStructure)[] = [];\n\n themesList.forEach((thm) => {\n const i: number = list.findIndex(\n (t) => t.name.trim() === thm.name.trim()\n );\n\n if (i !== -1) {\n list.splice(i, 1);\n list.push(thm);\n } else {\n list.push(thm);\n }\n });\n\n // Cleaned themes\n return list;\n }\n // DS5\n return [themes.ds5];\n};\n\
|
|
1
|
+
{"version":3,"file":"theme.js","sources":["../../../src/utils/theme.ts"],"sourcesContent":["/* eslint import/namespace: [2, { allowComputed: true }] */\nimport { CSSProperties } from \"react\";\nimport {\n themes,\n HvThemeColorModeStructure,\n HvThemeStructure,\n theme,\n} from \"@hitachivantara/uikit-styles\";\nimport { HvTheme, HvCreateThemeProps } from \"@core/types\";\n\n/**\n * Sets the element style properties.\n */\nconst setElementStyle = (element: HTMLElement, style: CSSProperties) => {\n Object.entries(style).forEach(([property, value]) => {\n element.style[property] = value;\n });\n};\n\n/**\n * Sets the element attributes and style for a theme and color mode.\n */\nexport const setElementAttrs = (\n themeName: string,\n modeName: string,\n colorScheme: string,\n themeRootId?: string\n) => {\n const element = themeRootId\n ? document.getElementById(themeRootId)\n : document.body;\n\n if (element) {\n element.setAttribute(`data-theme`, themeName);\n element.setAttribute(`data-color-mode`, modeName);\n\n // Set default properties for all components to inherit\n setElementStyle(element, {\n colorScheme,\n backgroundColor: theme.colors.backgroundColor,\n accentColor: theme.colors.secondary,\n color: theme.colors.secondary,\n fontSize: theme.typography.body.fontSize,\n fontWeight: theme.typography.body.fontWeight,\n lineHeight: theme.typography.body.lineHeight,\n letterSpacing: theme.typography.body.letterSpacing,\n fontFamily: theme.fontFamily.body,\n });\n }\n};\n\n/**\n * Applies customizations to a theme.\n */\nconst applyThemeCustomizations = (obj: object, customizations: object) => {\n const isObject = (val: any) =>\n val && typeof val === \"object\" && !Array.isArray(val);\n\n // Customized theme\n const customizedTheme = { ...obj };\n\n // Add new values to the theme or replace values\n Object.keys(customizations).forEach((key) => {\n if (customizedTheme[key]) {\n if (isObject(customizedTheme[key]) && isObject(customizations[key])) {\n customizedTheme[key] = applyThemeCustomizations(\n customizedTheme[key],\n customizations[key]\n );\n } else if (typeof customizedTheme[key] === typeof customizations[key]) {\n customizedTheme[key] = customizations[key];\n }\n } else {\n customizedTheme[key] = customizations[key];\n }\n });\n\n return customizedTheme;\n};\n\n/**\n * Creates a customized theme based on the base theme and customizations given.\n * For the color modes, the colors that are not defined will be replaced by the values from the dawn mode of the base theme.\n */\nexport const createTheme = (\n props: HvCreateThemeProps\n): HvTheme | HvThemeStructure => {\n const {\n name,\n base = \"ds5\",\n inheritColorModes = true,\n ...customizations\n } = props;\n\n // Apply customizations to the base theme\n const customizedTheme: HvTheme | HvThemeStructure = customizations\n ? (applyThemeCustomizations(themes[base], customizations) as HvTheme)\n : { ...themes[base] };\n\n // Set theme name\n customizedTheme.name = name.trim();\n // Set theme base\n customizedTheme.base = base;\n\n // Fill new color modes with missing colors\n if (customizations) {\n Object.keys(customizedTheme.colors.modes).forEach((mode) => {\n if (!themes[base].colors.modes[mode]) {\n customizedTheme.colors.modes[mode] = {\n ...themes[base].colors.modes.dawn,\n ...(customizedTheme.colors.modes[mode] as Partial<\n HvThemeColorModeStructure & { [key: string]: string }\n >),\n };\n }\n });\n }\n\n // If the flag `inheritColorModes` is false and customizations were given for the color modes,\n // we're removing any color modes that might have been inherited\n if (!inheritColorModes && customizations.colors?.modes) {\n Object.keys(customizedTheme.colors.modes).forEach((mode) => {\n if (!Object.keys(customizations.colors?.modes || {}).includes(mode)) {\n delete customizedTheme.colors.modes[mode];\n }\n });\n }\n\n // Created theme\n return customizedTheme;\n};\n\n/**\n * Process the themes provided to the HvProvider:\n * - Cleans themes with the same name\n * - Returns the default if the list is empty (ds5)\n */\nexport const processThemes = (\n themesList?: (HvTheme | HvThemeStructure)[]\n): (HvTheme | HvThemeStructure)[] => {\n if (themesList && Array.isArray(themesList) && themesList.length > 0) {\n const list: (HvTheme | HvThemeStructure)[] = [];\n\n themesList.forEach((thm) => {\n const i: number = list.findIndex(\n (t) => t.name.trim() === thm.name.trim()\n );\n\n if (i !== -1) {\n list.splice(i, 1);\n list.push(thm);\n } else {\n list.push(thm);\n }\n });\n\n // Cleaned themes\n return list;\n }\n // DS5\n return [themes.ds5];\n};\n\nexport const getVarValue = (cssVar: string, rootElementId?: string) => {\n const root = document.getElementById(rootElementId || \"hv-root\");\n if (root) {\n const computedValue = getComputedStyle(root)\n .getPropertyValue(cssVar.replace(\"var(\", \"\").replace(\")\", \"\"))\n .trim();\n\n return computedValue;\n }\n};\n"],"names":["setElementStyle","element","style","entries","forEach","property","value","setElementAttrs","themeName","modeName","colorScheme","themeRootId","document","getElementById","body","setAttribute","backgroundColor","theme","colors","accentColor","secondary","color","fontSize","typography","fontWeight","lineHeight","letterSpacing","fontFamily","applyThemeCustomizations","obj","customizations","isObject","val","Array","isArray","customizedTheme","Object","keys","key","createTheme","props","name","base","inheritColorModes","themes","trim","modes","mode","dawn","includes","processThemes","themesList","length","list","thm","i","findIndex","t","splice","push","ds5","getVarValue","cssVar","rootElementId","root","computedValue","getComputedStyle","getPropertyValue","replace"],"mappings":";AAaA,MAAMA,kB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