-
Hey, One question: Is it possible to access the theme colors from JS? I.e. when integrating a third party gui-library, which uses a CSS in JS-styling pattern, it would be useful to access the daisyUI-theme-colors. Something like this: const customStyles = {
option: (provided, state) => ({
...provided,
color: theme("colors.base-content"),
borderBottom: '1px dotted pink'
})
}
const App = () => (
<Select
styles={customStyles}
options={...}
/>
); Or is it safe to just use the css variables? const customStyles = {
option: (provided, state) => ({
...provided,
color: var(--bc),
borderBottom: '1px dotted pink'
})
} Thanks and best regards |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 23 replies
-
You can import Example: https://svelte.dev/repl/dcb3fbf9915741fea2f6fce0a0f166ea?version=3.46.2 Edit : |
Beta Was this translation helpful? Give feedback.
-
Update: |
Beta Was this translation helpful? Give feedback.
-
Is there a way to get my custom theme from JS?
How can i read the primary color code from JS? |
Beta Was this translation helpful? Give feedback.
-
Since I got this page myself, here is what I ended up doing using typescript: export interface ThemeColors {
primary: string;
primaryFocus: string;
primaryContent: string;
secondary: string;
secondaryFocus: string;
secondaryContent: string;
accent: string;
accentFocus: string;
accentContent: string;
neutral: string;
neutralFocus: string;
neutralContent: string;
base100: string;
base200: string;
base300: string;
baseContent: string;
info: string;
infoContent: string;
success: string;
successContent: string;
warning: string;
warningContent: string;
error: string;
errorContent: string;
}
export function extractThemeColorsFromDOM(): ThemeColors {
const computedStyles = getComputedStyle(document.querySelector(':root')!);
return {
primary: `hsl(${computedStyles.getPropertyValue('--p')}`,
primaryFocus: `hsl(${computedStyles.getPropertyValue('--pf')}`,
primaryContent: `hsl(${computedStyles.getPropertyValue('--pc')}`,
secondary: `hsl(${computedStyles.getPropertyValue('--s')}`,
secondaryFocus: `hsl(${computedStyles.getPropertyValue('--sf')}`,
secondaryContent: `hsl(${computedStyles.getPropertyValue('--sc')}`,
accent: `hsl(${computedStyles.getPropertyValue('--a')}`,
accentFocus: `hsl(${computedStyles.getPropertyValue('--af')}`,
accentContent: `hsl(${computedStyles.getPropertyValue('--ac')}`,
neutral: `hsl(${computedStyles.getPropertyValue('--n')}`,
neutralFocus: `hsl(${computedStyles.getPropertyValue('--nf')}`,
neutralContent: `hsl(${computedStyles.getPropertyValue('--nc')}`,
base100: `hsl(${computedStyles.getPropertyValue('--b1')}`,
base200: `hsl(${computedStyles.getPropertyValue('--b2')}`,
base300: `hsl(${computedStyles.getPropertyValue('--b3')}`,
baseContent: `hsl(${computedStyles.getPropertyValue('--bc')}`,
info: `hsl(${computedStyles.getPropertyValue('--in')}`,
infoContent: `hsl(${computedStyles.getPropertyValue('--inc')}`,
success: `hsl(${computedStyles.getPropertyValue('--su')}`,
successContent: `hsl(${computedStyles.getPropertyValue('--suc')}`,
warning: `hsl(${computedStyles.getPropertyValue('--wa')}`,
warningContent: `hsl(${computedStyles.getPropertyValue('--wac')}`,
error: `hsl(${computedStyles.getPropertyValue('--er')}`,
errorContent: `hsl(${computedStyles.getPropertyValue('--erc')}`,
};
} This code extracts the color theme in its entirety from the DOM. To be able to extract this data, the DOM must actually be present - so be aware that in SSR situations this needs to be guarded against. |
Beta Was this translation helpful? Give feedback.
-
Tried following the suggestions here but wasn't able to retrieve my current theme colors programatically. Is it possible with DaisyUI 4+ ? |
Beta Was this translation helpful? Give feedback.
You can import
daisyui/src/theming/themes
file and get the color values of a theme.Or you can get the CSS variable value of the current theme.
Example: https://svelte.dev/repl/dcb3fbf9915741fea2f6fce0a0f166ea?version=3.46.2
Edit :
daisyui/src/colors/themes
path is now changed todaisyui/src/theming/themes
in daisyUI version 3.0