diff --git a/apps/theme/app/page.module.css b/apps/theme/app/page.module.css index 170361601f..797fd5ac44 100644 --- a/apps/theme/app/page.module.css +++ b/apps/theme/app/page.module.css @@ -8,12 +8,6 @@ font-size: 18px; } -.preview.dark, -.preview.contrast { - --back: var(--grey1); - --fore: var(--grey2); -} - .container { max-width: 1600px; margin: 0 auto; diff --git a/apps/theme/app/page.tsx b/apps/theme/app/page.tsx index cdd934e056..f2da3ed0d9 100644 --- a/apps/theme/app/page.tsx +++ b/apps/theme/app/page.tsx @@ -231,8 +231,7 @@ export default function Home() {
diff --git a/apps/theme/components/Color/Color.tsx b/apps/theme/components/Color/Color.tsx index b968ff85ed..865227ef6c 100644 --- a/apps/theme/components/Color/Color.tsx +++ b/apps/theme/components/Color/Color.tsx @@ -1,6 +1,6 @@ import cl from 'clsx/lite'; import { SunIcon } from '@navikt/aksel-icons'; -import type { ColorInfo } from '@digdir/designsystemet/color'; +import type { ColorInfo, ColorType } from '@digdir/designsystemet/color'; import { useThemeStore } from '../../store'; @@ -14,6 +14,7 @@ type ColorProps = { featured?: boolean; hex?: string; showColorMeta?: boolean; + type: ColorType; }; const Color = ({ @@ -23,17 +24,21 @@ const Color = ({ lightness, hex, showColorMeta = true, + type, }: ColorProps) => { const setSelectedColor = useThemeStore((state) => state.setSelectedColor); return (
diff --git a/apps/theme/components/Scales/Scales.tsx b/apps/theme/components/Scales/Scales.tsx index 8b93a9b8fa..c65c1e4723 100644 --- a/apps/theme/components/Scales/Scales.tsx +++ b/apps/theme/components/Scales/Scales.tsx @@ -34,7 +34,7 @@ export const Scales = ({ themeMode }: ScalesProps) => { colorScale={neutralTheme.theme[themeMode]} showColorMeta={false} themeMode={themeMode} - type='grey' + type='neutral' /> @@ -44,7 +44,7 @@ export const Scales = ({ themeMode }: ScalesProps) => { colorScale={brandOneTheme.theme[themeMode]} showColorMeta={false} themeMode={themeMode} - type='brandOne' + type='brand1' />
@@ -53,7 +53,7 @@ export const Scales = ({ themeMode }: ScalesProps) => { colorScale={brandTwoTheme.theme[themeMode]} showColorMeta={false} themeMode={themeMode} - type='brandTwo' + type='brand2' />
@@ -63,7 +63,7 @@ export const Scales = ({ themeMode }: ScalesProps) => { colorScale={brandThreeTheme.theme[themeMode]} showColorMeta={false} themeMode={themeMode} - type='brandThree' + type='brand3' /> diff --git a/apps/theme/store.ts b/apps/theme/store.ts index 59011bbadb..3036e0cac9 100644 --- a/apps/theme/store.ts +++ b/apps/theme/store.ts @@ -1,7 +1,11 @@ import { create } from 'zustand'; import { subscribeWithSelector } from 'zustand/middleware'; import type { CssColor } from '@adobe/leonardo-contrast-colors'; -import type { ColorInfo, ThemeInfo } from '@digdir/designsystemet/color'; +import type { + ColorInfo, + ColorType, + ThemeInfo, +} from '@digdir/designsystemet/color'; import { Settings } from './settings'; @@ -21,8 +25,8 @@ type ColorStore = { setBrandOneTheme: (theme: ThemeInfo, color: CssColor) => void; setBrandTwoTheme: (theme: ThemeInfo, color: CssColor) => void; setBrandThreeTheme: (theme: ThemeInfo, color: CssColor) => void; - selectedColor: ColorInfo; - setSelectedColor: (color: ColorInfo) => void; + selectedColor: { color: ColorInfo; type: string }; + setSelectedColor: (color: ColorInfo, type: ColorType) => void; }; const defaultTheme = () => { @@ -56,11 +60,15 @@ export const useThemeStore = create( color: Settings.brand3BaseColor, }, selectedColor: { - hex: '#ffffff', - number: 1, - name: 'Default', + color: { + hex: '#ffffff', + number: 1, + name: 'Default', + }, + type: '', }, - setSelectedColor: (color) => set({ selectedColor: color }), + setSelectedColor: (color, type) => + set({ selectedColor: { color: color, type: type } }), setAccentTheme: (theme, color) => set({ accentTheme: { theme, color } }), setNeutralTheme: (theme, color) => set({ neutralTheme: { theme, color } }), setBrandOneTheme: (theme, color) => diff --git a/apps/theme/utils/tokenMapping.ts b/apps/theme/utils/tokenMapping.ts index a4d72ab384..55f3b9934b 100644 --- a/apps/theme/utils/tokenMapping.ts +++ b/apps/theme/utils/tokenMapping.ts @@ -1,91 +1,91 @@ export const mapTokens = () => { // accent - setToken('--ds-color-accent-background-default', 'var(--accent1)'); - setToken('--ds-color-accent-background-subtle', 'var(--accent2)'); - setToken('--ds-color-accent-surface-default', 'var(--accent3)'); - setToken('--ds-color-accent-surface-hover', 'var(--accent4)'); - setToken('--ds-color-accent-surface-active', 'var(--accent5)'); - setToken('--ds-color-accent-border-subtle', 'var(--accent6)'); - setToken('--ds-color-accent-border-default', 'var(--accent7)'); - setToken('--ds-color-accent-border-strong', 'var(--accent8)'); - setToken('--ds-color-accent-base-default', 'var(--accent9)'); - setToken('--ds-color-accent-base-hover', 'var(--accent10)'); - setToken('--ds-color-accent-base-active', 'var(--accent11)'); - setToken('--ds-color-accent-text-subtle', 'var(--accent12)'); - setToken('--ds-color-accent-text-default', 'var(--accent13)'); - setToken('--ds-color-accent-contrast-default', 'var(--accent14)'); - setToken('--ds-color-accent-contrast-sublte', 'var(--accent15)'); + setToken('--ds-color-accent-background-default', 'var(--accent-1)'); + setToken('--ds-color-accent-background-subtle', 'var(--accent-2)'); + setToken('--ds-color-accent-surface-default', 'var(--accent-3)'); + setToken('--ds-color-accent-surface-hover', 'var(--accent-4)'); + setToken('--ds-color-accent-surface-active', 'var(--accent-5)'); + setToken('--ds-color-accent-border-subtle', 'var(--accent-6)'); + setToken('--ds-color-accent-border-default', 'var(--accent-7)'); + setToken('--ds-color-accent-border-strong', 'var(--accent-8)'); + setToken('--ds-color-accent-base-default', 'var(--accent-9)'); + setToken('--ds-color-accent-base-hover', 'var(--accent-10)'); + setToken('--ds-color-accent-base-active', 'var(--accent-11)'); + setToken('--ds-color-accent-text-subtle', 'var(--accent-12)'); + setToken('--ds-color-accent-text-default', 'var(--accent-13)'); + setToken('--ds-color-accent-contrast-default', 'var(--accent-14)'); + setToken('--ds-color-accent-contrast-sublte', 'var(--accent-15)'); // neutral - setToken('--ds-color-neutral-background-default', 'var(--grey1)'); - setToken('--ds-color-neutral-background-subtle', 'var(--grey2)'); - setToken('--ds-color-neutral-surface-default', 'var(--grey3)'); - setToken('--ds-color-neutral-surface-hover', 'var(--grey4)'); - setToken('--ds-color-neutral-surface-active', 'var(--grey5)'); - setToken('--ds-color-neutral-border-subtle', 'var(--grey6)'); - setToken('--ds-color-neutral-border-default', 'var(--grey7)'); - setToken('--ds-color-neutral-border-strong', 'var(--grey8)'); - setToken('--ds-color-neutral-base-default', 'var(--grey9)'); - setToken('--ds-color-neutral-base-hover', 'var(--grey10)'); - setToken('--ds-color-neutral-base-active', 'var(--grey11)'); - setToken('--ds-color-neutral-text-subtle', 'var(--grey12)'); - setToken('--ds-color-neutral-text-default', 'var(--grey13)'); - setToken('--ds-color-neutral-contrast-default', 'var(--grey14)'); - setToken('--ds-color-neutral-contrast-sublte', 'var(--grey15)'); + setToken('--ds-color-neutral-background-default', 'var(--neutral-1)'); + setToken('--ds-color-neutral-background-subtle', 'var(--neutral-2)'); + setToken('--ds-color-neutral-surface-default', 'var(--neutral-3)'); + setToken('--ds-color-neutral-surface-hover', 'var(--neutral-4)'); + setToken('--ds-color-neutral-surface-active', 'var(--neutral-5)'); + setToken('--ds-color-neutral-border-subtle', 'var(--neutral-6)'); + setToken('--ds-color-neutral-border-default', 'var(--neutral-7)'); + setToken('--ds-color-neutral-border-strong', 'var(--neutral-8)'); + setToken('--ds-color-neutral-base-default', 'var(--neutral-9)'); + setToken('--ds-color-neutral-base-hover', 'var(--neutral-10)'); + setToken('--ds-color-neutral-base-active', 'var(--neutral-11)'); + setToken('--ds-color-neutral-text-subtle', 'var(--neutral-12)'); + setToken('--ds-color-neutral-text-default', 'var(--neutral-13)'); + setToken('--ds-color-neutral-contrast-default', 'var(--neutral-14)'); + setToken('--ds-color-neutral-contrast-sublte', 'var(--neutral-15)'); // brand 1 - setToken('--ds-color-brand1-background-default', 'var(--brandOne1)'); - setToken('--ds-color-brand1-background-subtle', 'var(--brandOne2)'); - setToken('--ds-color-brand1-surface-default', 'var(--brandOne3)'); - setToken('--ds-color-brand1-surface-hover', 'var(--brandOne4)'); - setToken('--ds-color-brand1-surface-active', 'var(--brandOne5)'); - setToken('--ds-color-brand1-border-subtle', 'var(--brandOne6)'); - setToken('--ds-color-brand1-border-default', 'var(--brandOne7)'); - setToken('--ds-color-brand1-border-strong', 'var(--brandOne8)'); - setToken('--ds-color-brand1-base-default', 'var(--brandOne9)'); - setToken('--ds-color-brand1-base-hover', 'var(--brandOne10)'); - setToken('--ds-color-brand1-base-active', 'var(--brandOne11)'); - setToken('--ds-color-brand1-text-subtle', 'var(--brandOne12)'); - setToken('--ds-color-brand1-text-default', 'var(--brandOne13)'); - setToken('--ds-color-brand1-contrast-default', 'var(--brandOne14)'); - setToken('--ds-color-brand1-contrast-sublte', 'var(--brandOne15)'); + setToken('--ds-color-brand1-background-default', 'var(--brand1-1)'); + setToken('--ds-color-brand1-background-subtle', 'var(--brand1-2)'); + setToken('--ds-color-brand1-surface-default', 'var(--brand1-3)'); + setToken('--ds-color-brand1-surface-hover', 'var(--brand1-4)'); + setToken('--ds-color-brand1-surface-active', 'var(--brand1-5)'); + setToken('--ds-color-brand1-border-subtle', 'var(--brand1-6)'); + setToken('--ds-color-brand1-border-default', 'var(--brand1-7)'); + setToken('--ds-color-brand1-border-strong', 'var(--brand1-8)'); + setToken('--ds-color-brand1-base-default', 'var(--brand1-9)'); + setToken('--ds-color-brand1-base-hover', 'var(--brand1-10)'); + setToken('--ds-color-brand1-base-active', 'var(--brand1-11)'); + setToken('--ds-color-brand1-text-subtle', 'var(--brand1-12)'); + setToken('--ds-color-brand1-text-default', 'var(--brand1-13)'); + setToken('--ds-color-brand1-contrast-default', 'var(--brand1-14)'); + setToken('--ds-color-brand1-contrast-sublte', 'var(--brand1-15)'); // brand 2 - setToken('--ds-color-brand2-background-default', 'var(--brandTwo1)'); - setToken('--ds-color-brand2-background-subtle', 'var(--brandTwo2)'); - setToken('--ds-color-brand2-surface-default', 'var(--brandTwo3)'); - setToken('--ds-color-brand2-surface-hover', 'var(--brandTwo4)'); - setToken('--ds-color-brand2-surface-active', 'var(--brandTwo5)'); - setToken('--ds-color-brand2-border-subtle', 'var(--brandTwo6)'); - setToken('--ds-color-brand2-border-default', 'var(--brandTwo7)'); - setToken('--ds-color-brand2-border-strong', 'var(--brandTwo8)'); - setToken('--ds-color-brand2-base-default', 'var(--brandTwo9)'); - setToken('--ds-color-brand2-base-hover', 'var(--brandTwo10)'); - setToken('--ds-color-brand2-base-active', 'var(--brandTwo11)'); - setToken('--ds-color-brand2-text-subtle', 'var(--brandTwo12)'); - setToken('--ds-color-brand2-text-default', 'var(--brandTwo13)'); - setToken('--ds-color-brand2-contrast-default', 'var(--brandTwo14)'); - setToken('--ds-color-brand2-contrast-sublte', 'var(--brandTwo15)'); + setToken('--ds-color-brand2-background-default', 'var(--brand2-1)'); + setToken('--ds-color-brand2-background-subtle', 'var(--brand2-2)'); + setToken('--ds-color-brand2-surface-default', 'var(--brand2-3)'); + setToken('--ds-color-brand2-surface-hover', 'var(--brand2-4)'); + setToken('--ds-color-brand2-surface-active', 'var(--brand2-5)'); + setToken('--ds-color-brand2-border-subtle', 'var(--brand2-6)'); + setToken('--ds-color-brand2-border-default', 'var(--brand2-7)'); + setToken('--ds-color-brand2-border-strong', 'var(--brand2-8)'); + setToken('--ds-color-brand2-base-default', 'var(--brand2-9)'); + setToken('--ds-color-brand2-base-hover', 'var(--brand2-10)'); + setToken('--ds-color-brand2-base-active', 'var(--brand2-11)'); + setToken('--ds-color-brand2-text-subtle', 'var(--brand2-12)'); + setToken('--ds-color-brand2-text-default', 'var(--brand2-13)'); + setToken('--ds-color-brand2-contrast-default', 'var(--brand2-14)'); + setToken('--ds-color-brand2-contrast-sublte', 'var(--brand2-15)'); // brand 3 - setToken('--ds-color-brand3-background-default', 'var(--brandThree1)'); - setToken('--ds-color-brand3-background-subtle', 'var(--brandThree2)'); - setToken('--ds-color-brand3-surface-default', 'var(--brandThree3)'); - setToken('--ds-color-brand3-surface-hover', 'var(--brandThree4)'); - setToken('--ds-color-brand3-surface-active', 'var(--brandThree5)'); - setToken('--ds-color-brand3-border-subtle', 'var(--brandThree6)'); - setToken('--ds-color-brand3-border-default', 'var(--brandThree7)'); - setToken('--ds-color-brand3-border-strong', 'var(--brandThree8)'); - setToken('--ds-color-brand3-base-default', 'var(--brandThree9)'); - setToken('--ds-color-brand3-base-hover', 'var(--brandThree10)'); - setToken('--ds-color-brand3-base-active', 'var(--brandThree11)'); - setToken('--ds-color-brand3-text-subtle', 'var(--brandThree12)'); - setToken('--ds-color-brand3-text-default', 'var(--brandThree13)'); - setToken('--ds-color-brand3-contrast-default', 'var(--brandThree14)'); - setToken('--ds-color-brand3-contrast-sublte', 'var(--brandThree15)'); + setToken('--ds-color-brand3-background-default', 'var(--brand3-1)'); + setToken('--ds-color-brand3-background-subtle', 'var(--brand3-2)'); + setToken('--ds-color-brand3-surface-default', 'var(--brand3-3)'); + setToken('--ds-color-brand3-surface-hover', 'var(--brand3-4)'); + setToken('--ds-color-brand3-surface-active', 'var(--brand3-5)'); + setToken('--ds-color-brand3-border-subtle', 'var(--brand3-6)'); + setToken('--ds-color-brand3-border-default', 'var(--brand3-7)'); + setToken('--ds-color-brand3-border-strong', 'var(--brand3-8)'); + setToken('--ds-color-brand3-base-default', 'var(--brand3-9)'); + setToken('--ds-color-brand3-base-hover', 'var(--brand3-10)'); + setToken('--ds-color-brand3-base-active', 'var(--brand3-11)'); + setToken('--ds-color-brand3-text-subtle', 'var(--brand3-12)'); + setToken('--ds-color-brand3-text-default', 'var(--brand3-13)'); + setToken('--ds-color-brand3-contrast-default', 'var(--brand3-14)'); + setToken('--ds-color-brand3-contrast-sublte', 'var(--brand3-15)'); - setToken('--ds-color-focus-outer', 'var(--grey13)'); - setToken('--ds-color-focus-inner', 'var(--grey1)'); + setToken('--ds-color-focus-outer', 'var(--neutral13)'); + setToken('--ds-color-focus-inner', 'var(--neutral1)'); }; const setToken = (token: string, color: string) => { diff --git a/packages/cli/src/colors/themeUtils.ts b/packages/cli/src/colors/themeUtils.ts index 78397cce8b..20c0898ecc 100644 --- a/packages/cli/src/colors/themeUtils.ts +++ b/packages/cli/src/colors/themeUtils.ts @@ -2,7 +2,7 @@ import type { CssColor } from '@adobe/leonardo-contrast-colors'; import { BackgroundColor, Color, Theme } from '@adobe/leonardo-contrast-colors'; import { Hsluv } from 'hsluv'; -import type { ContrastMode, Mode, ColorInfo, ColorNumber, ThemeInfo } from './types.ts'; +import type { ContrastMode, Mode, ColorInfo, ColorNumber, ThemeInfo, ColorType } from './types.ts'; import { getContrastFromHex, getContrastFromLightness, getLightnessFromHex } from './colorUtils'; const blueBaseColor = '#0A71C0'; @@ -351,3 +351,7 @@ export const getBaseColor = (color: CssColor) => { return conv.hex as CssColor; }; + +export const getCssVariable = (colorType: ColorType, colorNumber: ColorNumber) => { + return `--ds-${colorType}-${getColorNameFromNumber(colorNumber).toLowerCase().replace(/\s/g, '-')}`; +};