@chayns-components/core 5.0.0-beta.1322 → 5.0.0-beta.1324
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/lib/cjs/components/color-scheme-provider/hooks/useChaynsTheme.js +7 -2
- package/lib/cjs/components/color-scheme-provider/hooks/useChaynsTheme.js.map +1 -1
- package/lib/cjs/components/color-scheme-provider/hooks/useDesignSettings.js +12 -3
- package/lib/cjs/components/color-scheme-provider/hooks/useDesignSettings.js.map +1 -1
- package/lib/esm/components/color-scheme-provider/hooks/useChaynsTheme.js +7 -2
- package/lib/esm/components/color-scheme-provider/hooks/useChaynsTheme.js.map +1 -1
- package/lib/esm/components/color-scheme-provider/hooks/useDesignSettings.js +12 -3
- package/lib/esm/components/color-scheme-provider/hooks/useDesignSettings.js.map +1 -1
- package/lib/types/components/color-scheme-provider/hooks/useDesignSettings.d.ts +9 -1
- package/package.json +2 -2
|
@@ -95,7 +95,12 @@ const useChaynsTheme = ({
|
|
|
95
95
|
theme,
|
|
96
96
|
customVariables
|
|
97
97
|
}) => {
|
|
98
|
-
const designSettings = (0, _useDesignSettings.useDesignSettings)(
|
|
98
|
+
const designSettings = (0, _useDesignSettings.useDesignSettings)({
|
|
99
|
+
color,
|
|
100
|
+
colorMode,
|
|
101
|
+
designSettings: designSettingsProp,
|
|
102
|
+
siteId
|
|
103
|
+
});
|
|
99
104
|
const paragraphFormat = (0, _useParagraphFormat.useParagraphFormat)(siteId, paragraphFormatProp);
|
|
100
105
|
const isMountedRef = (0, _react.useRef)(false);
|
|
101
106
|
const [internalTheme, setInternalTheme] = (0, _react.useState)(() => createTheme({
|
|
@@ -125,7 +130,7 @@ const useChaynsTheme = ({
|
|
|
125
130
|
iconColor,
|
|
126
131
|
customVariables
|
|
127
132
|
}));
|
|
128
|
-
}, [color, colorMode, colors, designSettings, paragraphFormat, secondaryColor, theme, customVariables]);
|
|
133
|
+
}, [color, colorMode, colors, designSettings, paragraphFormat, secondaryColor, theme, customVariables, iconColor]);
|
|
129
134
|
return (0, _react.useMemo)(() => ({
|
|
130
135
|
theme: internalTheme,
|
|
131
136
|
designSettings,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChaynsTheme.js","names":["_colors","require","_chaynsApi","_react","_font","_useDesignSettings","_useParagraphFormat","createTheme","colors","colorMode","color","secondaryColor","designSettings","paragraphFormat","theme","iconColor","customVariables","result","Object","keys","forEach","key","availableColors","getAvailableColorList","colorName","hexColor","getColorFromPalette","rgbColor","hexToRgb255","r","g","b","convertIconStyle","iconStyle","themeResult","getHeadlineColorSelector","ColorMode","Light","Dark","fontSize","fontSizePx","useChaynsTheme","designSettingsProp","paragraphFormatProp","siteId","useDesignSettings","useParagraphFormat","isMountedRef","useRef","internalTheme","setInternalTheme","useState","useEffect","current","useMemo","exports"],"sources":["../../../../../src/components/color-scheme-provider/hooks/useChaynsTheme.ts"],"sourcesContent":["import { getAvailableColorList, getColorFromPalette, hexToRgb255 } from '@chayns/colors';\nimport { ChaynsDesignSettings, ChaynsParagraphFormat, ColorMode } from 'chayns-api';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { convertIconStyle, getHeadlineColorSelector } from '../../../utils/font';\nimport type { Theme } from '../ColorSchemeProvider';\nimport { useDesignSettings } from './useDesignSettings';\nimport { useParagraphFormat } from './useParagraphFormat';\n\nexport type ThemeOptions = {\n colors?: Theme;\n colorMode: ColorMode;\n iconColor?: string;\n color: string;\n secondaryColor?: string;\n designSettings?: ChaynsDesignSettings & { fontSizePx?: number };\n paragraphFormat?: ChaynsParagraphFormat[];\n siteId?: string;\n theme?: Theme;\n customVariables?: Record<string, string>;\n};\n\nconst createTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n}: Omit<ThemeOptions, 'siteId'>) => {\n if (theme) {\n return theme;\n }\n\n const result: Theme = {};\n\n if (customVariables) {\n Object.keys(customVariables).forEach((key) => {\n result[key] = customVariables[key] as string;\n });\n }\n\n const availableColors = getAvailableColorList();\n\n if (!colors) {\n availableColors.forEach((colorName: string) => {\n const hexColor = getColorFromPalette(colorName, {\n color,\n colorMode,\n secondaryColor,\n });\n\n if (hexColor) {\n const rgbColor = hexToRgb255(hexColor);\n\n result[colorName] = hexColor;\n\n if (rgbColor) {\n result[`${colorName}-rgb`] = `${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b}`;\n }\n }\n });\n }\n\n if (designSettings) {\n Object.keys(designSettings).forEach((key) => {\n if (key === 'iconStyle') {\n result[key] = convertIconStyle(designSettings.iconStyle);\n\n return;\n }\n result[key] = designSettings[key as keyof ChaynsDesignSettings] as string;\n });\n }\n\n if (paragraphFormat) {\n const { themeResult } = getHeadlineColorSelector(paragraphFormat);\n\n // Update Theme\n Object.keys(themeResult).forEach((key) => {\n result[key] = themeResult[key] as string;\n });\n }\n\n switch (colorMode) {\n case ColorMode.Light:\n result.colorMode = 'light';\n break;\n case ColorMode.Dark:\n result.colorMode = 'dark';\n break;\n default:\n result.colorMode = 'classic';\n break;\n }\n\n if (iconColor) {\n result.iconColor = iconColor;\n }\n\n result.fontSize = (designSettings?.fontSizePx || 15) as unknown as string;\n\n return result;\n};\n\nexport const useChaynsTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings: designSettingsProp,\n paragraphFormat: paragraphFormatProp,\n siteId,\n iconColor,\n theme,\n customVariables,\n}: ThemeOptions) => {\n const designSettings = useDesignSettings(
|
|
1
|
+
{"version":3,"file":"useChaynsTheme.js","names":["_colors","require","_chaynsApi","_react","_font","_useDesignSettings","_useParagraphFormat","createTheme","colors","colorMode","color","secondaryColor","designSettings","paragraphFormat","theme","iconColor","customVariables","result","Object","keys","forEach","key","availableColors","getAvailableColorList","colorName","hexColor","getColorFromPalette","rgbColor","hexToRgb255","r","g","b","convertIconStyle","iconStyle","themeResult","getHeadlineColorSelector","ColorMode","Light","Dark","fontSize","fontSizePx","useChaynsTheme","designSettingsProp","paragraphFormatProp","siteId","useDesignSettings","useParagraphFormat","isMountedRef","useRef","internalTheme","setInternalTheme","useState","useEffect","current","useMemo","exports"],"sources":["../../../../../src/components/color-scheme-provider/hooks/useChaynsTheme.ts"],"sourcesContent":["import { getAvailableColorList, getColorFromPalette, hexToRgb255 } from '@chayns/colors';\nimport { ChaynsDesignSettings, ChaynsParagraphFormat, ColorMode } from 'chayns-api';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { convertIconStyle, getHeadlineColorSelector } from '../../../utils/font';\nimport type { Theme } from '../ColorSchemeProvider';\nimport { useDesignSettings } from './useDesignSettings';\nimport { useParagraphFormat } from './useParagraphFormat';\n\nexport type ThemeOptions = {\n colors?: Theme;\n colorMode: ColorMode;\n iconColor?: string;\n color: string;\n secondaryColor?: string;\n designSettings?: ChaynsDesignSettings & { fontSizePx?: number };\n paragraphFormat?: ChaynsParagraphFormat[];\n siteId?: string;\n theme?: Theme;\n customVariables?: Record<string, string>;\n};\n\nconst createTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n}: Omit<ThemeOptions, 'siteId'>) => {\n if (theme) {\n return theme;\n }\n\n const result: Theme = {};\n\n if (customVariables) {\n Object.keys(customVariables).forEach((key) => {\n result[key] = customVariables[key] as string;\n });\n }\n\n const availableColors = getAvailableColorList();\n\n if (!colors) {\n availableColors.forEach((colorName: string) => {\n const hexColor = getColorFromPalette(colorName, {\n color,\n colorMode,\n secondaryColor,\n });\n\n if (hexColor) {\n const rgbColor = hexToRgb255(hexColor);\n\n result[colorName] = hexColor;\n\n if (rgbColor) {\n result[`${colorName}-rgb`] = `${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b}`;\n }\n }\n });\n }\n\n if (designSettings) {\n Object.keys(designSettings).forEach((key) => {\n if (key === 'iconStyle') {\n result[key] = convertIconStyle(designSettings.iconStyle);\n\n return;\n }\n result[key] = designSettings[key as keyof ChaynsDesignSettings] as string;\n });\n }\n\n if (paragraphFormat) {\n const { themeResult } = getHeadlineColorSelector(paragraphFormat);\n\n // Update Theme\n Object.keys(themeResult).forEach((key) => {\n result[key] = themeResult[key] as string;\n });\n }\n\n switch (colorMode) {\n case ColorMode.Light:\n result.colorMode = 'light';\n break;\n case ColorMode.Dark:\n result.colorMode = 'dark';\n break;\n default:\n result.colorMode = 'classic';\n break;\n }\n\n if (iconColor) {\n result.iconColor = iconColor;\n }\n\n result.fontSize = (designSettings?.fontSizePx || 15) as unknown as string;\n\n return result;\n};\n\nexport const useChaynsTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings: designSettingsProp,\n paragraphFormat: paragraphFormatProp,\n siteId,\n iconColor,\n theme,\n customVariables,\n}: ThemeOptions) => {\n const designSettings = useDesignSettings({\n color,\n colorMode,\n designSettings: designSettingsProp,\n siteId,\n });\n\n const paragraphFormat = useParagraphFormat(siteId, paragraphFormatProp);\n const isMountedRef = useRef<boolean>(false);\n\n const [internalTheme, setInternalTheme] = useState<Theme>(() =>\n createTheme({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n }),\n );\n\n useEffect(() => {\n if (!isMountedRef.current) {\n isMountedRef.current = true;\n return;\n }\n setInternalTheme(\n createTheme({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n }),\n );\n }, [\n color,\n colorMode,\n colors,\n designSettings,\n paragraphFormat,\n secondaryColor,\n theme,\n customVariables,\n iconColor,\n ]);\n\n return useMemo(\n () => ({\n theme: internalTheme,\n designSettings,\n paragraphFormat,\n }),\n [internalTheme, designSettings, paragraphFormat],\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI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,EAACF,MAAM,EAAED,mBAAmB,CAAC;EACvE,MAAMI,YAAY,GAAG,IAAAC,aAAM,EAAU,KAAK,CAAC;EAE3C,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAG,IAAAC,eAAQ,EAAQ,MACtD5C,WAAW,CAAC;IACRC,MAAM;IACNC,SAAS;IACTC,KAAK;IACLC,cAAc;IACdC,cAAc;IACdC,eAAe;IACfC,KAAK;IACLC,SAAS;IACTC;EACJ,CAAC,CACL,CAAC;EAED,IAAAoC,gBAAS,EAAC,MAAM;IACZ,IAAI,CAACL,YAAY,CAACM,OAAO,EAAE;MACvBN,YAAY,CAACM,OAAO,GAAG,IAAI;MAC3B;IACJ;IACAH,gBAAgB,CACZ3C,WAAW,CAAC;MACRC,MAAM;MACNC,SAAS;MACTC,KAAK;MACLC,cAAc;MACdC,cAAc;MACdC,eAAe;MACfC,KAAK;MACLC,SAAS;MACTC;IACJ,CAAC,CACL,CAAC;EACL,CAAC,EAAE,CACCN,KAAK,EACLD,SAAS,EACTD,MAAM,EACNI,cAAc,EACdC,eAAe,EACfF,cAAc,EACdG,KAAK,EACLE,eAAe,EACfD,SAAS,CACZ,CAAC;EAEF,OAAO,IAAAuC,cAAO,EACV,OAAO;IACHxC,KAAK,EAAEmC,aAAa;IACpBrC,cAAc;IACdC;EACJ,CAAC,CAAC,EACF,CAACoC,aAAa,EAAErC,cAAc,EAAEC,eAAe,CACnD,CAAC;AACL,CAAC;AAAC0C,OAAA,CAAAd,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
@@ -7,9 +7,14 @@ exports.useDesignSettings = void 0;
|
|
|
7
7
|
var _chaynsApi = require("chayns-api");
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _get = require("../../../api/theme/get");
|
|
10
|
-
const useDesignSettings = (
|
|
11
|
-
|
|
10
|
+
const useDesignSettings = ({
|
|
11
|
+
color,
|
|
12
|
+
colorMode,
|
|
13
|
+
designSettings,
|
|
14
|
+
siteId
|
|
15
|
+
}) => {
|
|
12
16
|
const [value, setValue] = (0, _react.useState)(undefined);
|
|
17
|
+
const styleSettings = (0, _chaynsApi.useStyleSettings)();
|
|
13
18
|
const shouldLoad = !designSettings && !(styleSettings !== null && styleSettings !== void 0 && styleSettings.designSettings);
|
|
14
19
|
(0, _react.useEffect)(() => {
|
|
15
20
|
if (shouldLoad) {
|
|
@@ -18,7 +23,11 @@ const useDesignSettings = (siteId, designSettings) => {
|
|
|
18
23
|
});
|
|
19
24
|
}
|
|
20
25
|
}, [shouldLoad, siteId]);
|
|
21
|
-
return
|
|
26
|
+
return {
|
|
27
|
+
...(designSettings ?? (styleSettings === null || styleSettings === void 0 ? void 0 : styleSettings.designSettings) ?? value),
|
|
28
|
+
color,
|
|
29
|
+
colorMode
|
|
30
|
+
};
|
|
22
31
|
};
|
|
23
32
|
exports.useDesignSettings = useDesignSettings;
|
|
24
33
|
//# sourceMappingURL=useDesignSettings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDesignSettings.js","names":["_chaynsApi","require","_react","_get","useDesignSettings","
|
|
1
|
+
{"version":3,"file":"useDesignSettings.js","names":["_chaynsApi","require","_react","_get","useDesignSettings","color","colorMode","designSettings","siteId","value","setValue","useState","undefined","styleSettings","useStyleSettings","shouldLoad","useEffect","getDesignSettings","then","result","exports"],"sources":["../../../../../src/components/color-scheme-provider/hooks/useDesignSettings.ts"],"sourcesContent":["import { ChaynsDesignSettings, useStyleSettings } from 'chayns-api';\nimport { useEffect, useState } from 'react';\nimport { getDesignSettings } from '../../../api/theme/get';\nimport { ThemeOptions } from './useChaynsTheme';\n\ninterface UseDesignSettingsOptions {\n color?: ThemeOptions['color'];\n colorMode?: ThemeOptions['colorMode'];\n designSettings?: ChaynsDesignSettings;\n siteId?: string;\n}\n\nexport const useDesignSettings = ({\n color,\n colorMode,\n designSettings,\n siteId,\n}: UseDesignSettingsOptions) => {\n const [value, setValue] = useState<ChaynsDesignSettings | undefined>(undefined);\n\n const styleSettings = useStyleSettings();\n\n const shouldLoad = !designSettings && !styleSettings?.designSettings;\n\n useEffect(() => {\n if (shouldLoad) {\n void getDesignSettings(siteId).then((result) => {\n setValue(result);\n });\n }\n }, [shouldLoad, siteId]);\n\n return {\n ...(designSettings ?? styleSettings?.designSettings ?? value),\n color,\n colorMode,\n } as ChaynsDesignSettings | undefined;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AAUO,MAAMG,iBAAiB,GAAGA,CAAC;EAC9BC,KAAK;EACLC,SAAS;EACTC,cAAc;EACdC;AACsB,CAAC,KAAK;EAC5B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAmCC,SAAS,CAAC;EAE/E,MAAMC,aAAa,GAAG,IAAAC,2BAAgB,EAAC,CAAC;EAExC,MAAMC,UAAU,GAAG,CAACR,cAAc,IAAI,EAACM,aAAa,aAAbA,aAAa,eAAbA,aAAa,CAAEN,cAAc;EAEpE,IAAAS,gBAAS,EAAC,MAAM;IACZ,IAAID,UAAU,EAAE;MACZ,KAAK,IAAAE,sBAAiB,EAACT,MAAM,CAAC,CAACU,IAAI,CAAEC,MAAM,IAAK;QAC5CT,QAAQ,CAACS,MAAM,CAAC;MACpB,CAAC,CAAC;IACN;EACJ,CAAC,EAAE,CAACJ,UAAU,EAAEP,MAAM,CAAC,CAAC;EAExB,OAAO;IACH,IAAID,cAAc,KAAIM,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEN,cAAc,KAAIE,KAAK,CAAC;IAC7DJ,KAAK;IACLC;EACJ,CAAC;AACL,CAAC;AAACc,OAAA,CAAAhB,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -89,7 +89,12 @@ export const useChaynsTheme = ({
|
|
|
89
89
|
theme,
|
|
90
90
|
customVariables
|
|
91
91
|
}) => {
|
|
92
|
-
const designSettings = useDesignSettings(
|
|
92
|
+
const designSettings = useDesignSettings({
|
|
93
|
+
color,
|
|
94
|
+
colorMode,
|
|
95
|
+
designSettings: designSettingsProp,
|
|
96
|
+
siteId
|
|
97
|
+
});
|
|
93
98
|
const paragraphFormat = useParagraphFormat(siteId, paragraphFormatProp);
|
|
94
99
|
const isMountedRef = useRef(false);
|
|
95
100
|
const [internalTheme, setInternalTheme] = useState(() => createTheme({
|
|
@@ -119,7 +124,7 @@ export const useChaynsTheme = ({
|
|
|
119
124
|
iconColor,
|
|
120
125
|
customVariables
|
|
121
126
|
}));
|
|
122
|
-
}, [color, colorMode, colors, designSettings, paragraphFormat, secondaryColor, theme, customVariables]);
|
|
127
|
+
}, [color, colorMode, colors, designSettings, paragraphFormat, secondaryColor, theme, customVariables, iconColor]);
|
|
123
128
|
return useMemo(() => ({
|
|
124
129
|
theme: internalTheme,
|
|
125
130
|
designSettings,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChaynsTheme.js","names":["getAvailableColorList","getColorFromPalette","hexToRgb255","ColorMode","useEffect","useMemo","useRef","useState","convertIconStyle","getHeadlineColorSelector","useDesignSettings","useParagraphFormat","createTheme","colors","colorMode","color","secondaryColor","designSettings","paragraphFormat","theme","iconColor","customVariables","result","Object","keys","forEach","key","availableColors","colorName","hexColor","rgbColor","r","g","b","iconStyle","themeResult","Light","Dark","fontSize","fontSizePx","useChaynsTheme","designSettingsProp","paragraphFormatProp","siteId","isMountedRef","internalTheme","setInternalTheme","current"],"sources":["../../../../../src/components/color-scheme-provider/hooks/useChaynsTheme.ts"],"sourcesContent":["import { getAvailableColorList, getColorFromPalette, hexToRgb255 } from '@chayns/colors';\nimport { ChaynsDesignSettings, ChaynsParagraphFormat, ColorMode } from 'chayns-api';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { convertIconStyle, getHeadlineColorSelector } from '../../../utils/font';\nimport type { Theme } from '../ColorSchemeProvider';\nimport { useDesignSettings } from './useDesignSettings';\nimport { useParagraphFormat } from './useParagraphFormat';\n\nexport type ThemeOptions = {\n colors?: Theme;\n colorMode: ColorMode;\n iconColor?: string;\n color: string;\n secondaryColor?: string;\n designSettings?: ChaynsDesignSettings & { fontSizePx?: number };\n paragraphFormat?: ChaynsParagraphFormat[];\n siteId?: string;\n theme?: Theme;\n customVariables?: Record<string, string>;\n};\n\nconst createTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n}: Omit<ThemeOptions, 'siteId'>) => {\n if (theme) {\n return theme;\n }\n\n const result: Theme = {};\n\n if (customVariables) {\n Object.keys(customVariables).forEach((key) => {\n result[key] = customVariables[key] as string;\n });\n }\n\n const availableColors = getAvailableColorList();\n\n if (!colors) {\n availableColors.forEach((colorName: string) => {\n const hexColor = getColorFromPalette(colorName, {\n color,\n colorMode,\n secondaryColor,\n });\n\n if (hexColor) {\n const rgbColor = hexToRgb255(hexColor);\n\n result[colorName] = hexColor;\n\n if (rgbColor) {\n result[`${colorName}-rgb`] = `${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b}`;\n }\n }\n });\n }\n\n if (designSettings) {\n Object.keys(designSettings).forEach((key) => {\n if (key === 'iconStyle') {\n result[key] = convertIconStyle(designSettings.iconStyle);\n\n return;\n }\n result[key] = designSettings[key as keyof ChaynsDesignSettings] as string;\n });\n }\n\n if (paragraphFormat) {\n const { themeResult } = getHeadlineColorSelector(paragraphFormat);\n\n // Update Theme\n Object.keys(themeResult).forEach((key) => {\n result[key] = themeResult[key] as string;\n });\n }\n\n switch (colorMode) {\n case ColorMode.Light:\n result.colorMode = 'light';\n break;\n case ColorMode.Dark:\n result.colorMode = 'dark';\n break;\n default:\n result.colorMode = 'classic';\n break;\n }\n\n if (iconColor) {\n result.iconColor = iconColor;\n }\n\n result.fontSize = (designSettings?.fontSizePx || 15) as unknown as string;\n\n return result;\n};\n\nexport const useChaynsTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings: designSettingsProp,\n paragraphFormat: paragraphFormatProp,\n siteId,\n iconColor,\n theme,\n customVariables,\n}: ThemeOptions) => {\n const designSettings = useDesignSettings(
|
|
1
|
+
{"version":3,"file":"useChaynsTheme.js","names":["getAvailableColorList","getColorFromPalette","hexToRgb255","ColorMode","useEffect","useMemo","useRef","useState","convertIconStyle","getHeadlineColorSelector","useDesignSettings","useParagraphFormat","createTheme","colors","colorMode","color","secondaryColor","designSettings","paragraphFormat","theme","iconColor","customVariables","result","Object","keys","forEach","key","availableColors","colorName","hexColor","rgbColor","r","g","b","iconStyle","themeResult","Light","Dark","fontSize","fontSizePx","useChaynsTheme","designSettingsProp","paragraphFormatProp","siteId","isMountedRef","internalTheme","setInternalTheme","current"],"sources":["../../../../../src/components/color-scheme-provider/hooks/useChaynsTheme.ts"],"sourcesContent":["import { getAvailableColorList, getColorFromPalette, hexToRgb255 } from '@chayns/colors';\nimport { ChaynsDesignSettings, ChaynsParagraphFormat, ColorMode } from 'chayns-api';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { convertIconStyle, getHeadlineColorSelector } from '../../../utils/font';\nimport type { Theme } from '../ColorSchemeProvider';\nimport { useDesignSettings } from './useDesignSettings';\nimport { useParagraphFormat } from './useParagraphFormat';\n\nexport type ThemeOptions = {\n colors?: Theme;\n colorMode: ColorMode;\n iconColor?: string;\n color: string;\n secondaryColor?: string;\n designSettings?: ChaynsDesignSettings & { fontSizePx?: number };\n paragraphFormat?: ChaynsParagraphFormat[];\n siteId?: string;\n theme?: Theme;\n customVariables?: Record<string, string>;\n};\n\nconst createTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n}: Omit<ThemeOptions, 'siteId'>) => {\n if (theme) {\n return theme;\n }\n\n const result: Theme = {};\n\n if (customVariables) {\n Object.keys(customVariables).forEach((key) => {\n result[key] = customVariables[key] as string;\n });\n }\n\n const availableColors = getAvailableColorList();\n\n if (!colors) {\n availableColors.forEach((colorName: string) => {\n const hexColor = getColorFromPalette(colorName, {\n color,\n colorMode,\n secondaryColor,\n });\n\n if (hexColor) {\n const rgbColor = hexToRgb255(hexColor);\n\n result[colorName] = hexColor;\n\n if (rgbColor) {\n result[`${colorName}-rgb`] = `${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b}`;\n }\n }\n });\n }\n\n if (designSettings) {\n Object.keys(designSettings).forEach((key) => {\n if (key === 'iconStyle') {\n result[key] = convertIconStyle(designSettings.iconStyle);\n\n return;\n }\n result[key] = designSettings[key as keyof ChaynsDesignSettings] as string;\n });\n }\n\n if (paragraphFormat) {\n const { themeResult } = getHeadlineColorSelector(paragraphFormat);\n\n // Update Theme\n Object.keys(themeResult).forEach((key) => {\n result[key] = themeResult[key] as string;\n });\n }\n\n switch (colorMode) {\n case ColorMode.Light:\n result.colorMode = 'light';\n break;\n case ColorMode.Dark:\n result.colorMode = 'dark';\n break;\n default:\n result.colorMode = 'classic';\n break;\n }\n\n if (iconColor) {\n result.iconColor = iconColor;\n }\n\n result.fontSize = (designSettings?.fontSizePx || 15) as unknown as string;\n\n return result;\n};\n\nexport const useChaynsTheme = ({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings: designSettingsProp,\n paragraphFormat: paragraphFormatProp,\n siteId,\n iconColor,\n theme,\n customVariables,\n}: ThemeOptions) => {\n const designSettings = useDesignSettings({\n color,\n colorMode,\n designSettings: designSettingsProp,\n siteId,\n });\n\n const paragraphFormat = useParagraphFormat(siteId, paragraphFormatProp);\n const isMountedRef = useRef<boolean>(false);\n\n const [internalTheme, setInternalTheme] = useState<Theme>(() =>\n createTheme({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n }),\n );\n\n useEffect(() => {\n if (!isMountedRef.current) {\n isMountedRef.current = true;\n return;\n }\n setInternalTheme(\n createTheme({\n colors,\n colorMode,\n color,\n secondaryColor,\n designSettings,\n paragraphFormat,\n theme,\n iconColor,\n customVariables,\n }),\n );\n }, [\n color,\n colorMode,\n colors,\n designSettings,\n paragraphFormat,\n secondaryColor,\n theme,\n customVariables,\n iconColor,\n ]);\n\n return useMemo(\n () => ({\n theme: internalTheme,\n designSettings,\n paragraphFormat,\n }),\n [internalTheme, designSettings, paragraphFormat],\n );\n};\n"],"mappings":"AAAA,SAASA,qBAAqB,EAAEC,mBAAmB,EAAEC,WAAW,QAAQ,gBAAgB;AACxF,SAAsDC,SAAS,QAAQ,YAAY;AACnF,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC5D,SAASC,gBAAgB,EAAEC,wBAAwB,QAAQ,qBAAqB;AAEhF,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,kBAAkB,QAAQ,sBAAsB;AAezD,MAAMC,WAAW,GAAGA,CAAC;EACjBC,MAAM;EACNC,SAAS;EACTC,KAAK;EACLC,cAAc;EACdC,cAAc;EACdC,eAAe;EACfC,KAAK;EACLC,SAAS;EACTC;AAC0B,CAAC,KAAK;EAChC,IAAIF,KAAK,EAAE;IACP,OAAOA,KAAK;EAChB;EAEA,MAAMG,MAAa,GAAG,CAAC,CAAC;EAExB,IAAID,eAAe,EAAE;IACjBE,MAAM,CAACC,IAAI,CAACH,eAAe,CAAC,CAACI,OAAO,CAAEC,GAAG,IAAK;MAC1CJ,MAAM,CAACI,GAAG,CAAC,GAAGL,eAAe,CAACK,GAAG,CAAW;IAChD,CAAC,CAAC;EACN;EAEA,MAAMC,eAAe,GAAG3B,qBAAqB,CAAC,CAAC;EAE/C,IAAI,CAACa,MAAM,EAAE;IACTc,eAAe,CAACF,OAAO,CAAEG,SAAiB,IAAK;MAC3C,MAAMC,QAAQ,GAAG5B,mBAAmB,CAAC2B,SAAS,EAAE;QAC5Cb,KAAK;QACLD,SAAS;QACTE;MACJ,CAAC,CAAC;MAEF,IAAIa,QAAQ,EAAE;QACV,MAAMC,QAAQ,G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5B,cAAc,EAAEC,eAAe,CACnD,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { useStyleSettings } from 'chayns-api';
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
3
|
import { getDesignSettings } from '../../../api/theme/get';
|
|
4
|
-
export const useDesignSettings = (
|
|
5
|
-
|
|
4
|
+
export const useDesignSettings = ({
|
|
5
|
+
color,
|
|
6
|
+
colorMode,
|
|
7
|
+
designSettings,
|
|
8
|
+
siteId
|
|
9
|
+
}) => {
|
|
6
10
|
const [value, setValue] = useState(undefined);
|
|
11
|
+
const styleSettings = useStyleSettings();
|
|
7
12
|
const shouldLoad = !designSettings && !styleSettings?.designSettings;
|
|
8
13
|
useEffect(() => {
|
|
9
14
|
if (shouldLoad) {
|
|
@@ -12,6 +17,10 @@ export const useDesignSettings = (siteId, designSettings) => {
|
|
|
12
17
|
});
|
|
13
18
|
}
|
|
14
19
|
}, [shouldLoad, siteId]);
|
|
15
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
...(designSettings ?? styleSettings?.designSettings ?? value),
|
|
22
|
+
color,
|
|
23
|
+
colorMode
|
|
24
|
+
};
|
|
16
25
|
};
|
|
17
26
|
//# sourceMappingURL=useDesignSettings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDesignSettings.js","names":["useStyleSettings","useEffect","useState","getDesignSettings","useDesignSettings","
|
|
1
|
+
{"version":3,"file":"useDesignSettings.js","names":["useStyleSettings","useEffect","useState","getDesignSettings","useDesignSettings","color","colorMode","designSettings","siteId","value","setValue","undefined","styleSettings","shouldLoad","then","result"],"sources":["../../../../../src/components/color-scheme-provider/hooks/useDesignSettings.ts"],"sourcesContent":["import { ChaynsDesignSettings, useStyleSettings } from 'chayns-api';\nimport { useEffect, useState } from 'react';\nimport { getDesignSettings } from '../../../api/theme/get';\nimport { ThemeOptions } from './useChaynsTheme';\n\ninterface UseDesignSettingsOptions {\n color?: ThemeOptions['color'];\n colorMode?: ThemeOptions['colorMode'];\n designSettings?: ChaynsDesignSettings;\n siteId?: string;\n}\n\nexport const useDesignSettings = ({\n color,\n colorMode,\n designSettings,\n siteId,\n}: UseDesignSettingsOptions) => {\n const [value, setValue] = useState<ChaynsDesignSettings | undefined>(undefined);\n\n const styleSettings = useStyleSettings();\n\n const shouldLoad = !designSettings && !styleSettings?.designSettings;\n\n useEffect(() => {\n if (shouldLoad) {\n void getDesignSettings(siteId).then((result) => {\n setValue(result);\n });\n }\n }, [shouldLoad, siteId]);\n\n return {\n ...(designSettings ?? styleSettings?.designSettings ?? value),\n color,\n colorMode,\n } as ChaynsDesignSettings | undefined;\n};\n"],"mappings":"AAAA,SAA+BA,gBAAgB,QAAQ,YAAY;AACnE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,iBAAiB,QAAQ,wBAAwB;AAU1D,OAAO,MAAMC,iBAAiB,GAAGA,CAAC;EAC9BC,KAAK;EACLC,SAAS;EACTC,cAAc;EACdC;AACsB,CAAC,KAAK;EAC5B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGR,QAAQ,CAAmCS,SAAS,CAAC;EAE/E,MAAMC,aAAa,GAAGZ,gBAAgB,CAAC,CAAC;EAExC,MAAMa,UAAU,GAAG,CAACN,cAAc,IAAI,CAACK,aAAa,EAAEL,cAAc;EAEpEN,SAAS,CAAC,MAAM;IACZ,IAAIY,UAAU,EAAE;MACZ,KAAKV,iBAAiB,CAACK,MAAM,CAAC,CAACM,IAAI,CAAEC,MAAM,IAAK;QAC5CL,QAAQ,CAACK,MAAM,CAAC;MACpB,CAAC,CAAC;IACN;EACJ,CAAC,EAAE,CAACF,UAAU,EAAEL,MAAM,CAAC,CAAC;EAExB,OAAO;IACH,IAAID,cAAc,IAAIK,aAAa,EAAEL,cAAc,IAAIE,KAAK,CAAC;IAC7DJ,KAAK;IACLC;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { ChaynsDesignSettings } from 'chayns-api';
|
|
2
|
-
|
|
2
|
+
import { ThemeOptions } from './useChaynsTheme';
|
|
3
|
+
interface UseDesignSettingsOptions {
|
|
4
|
+
color?: ThemeOptions['color'];
|
|
5
|
+
colorMode?: ThemeOptions['colorMode'];
|
|
6
|
+
designSettings?: ChaynsDesignSettings;
|
|
7
|
+
siteId?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const useDesignSettings: ({ color, colorMode, designSettings, siteId, }: UseDesignSettingsOptions) => ChaynsDesignSettings | undefined;
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.1324",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "13f36b0832d4d4da2375bb5c99029c7b28977fa6"
|
|
90
90
|
}
|