|
| 1 | +import type {ThemeColorCard_v2} from '../system' |
| 2 | + |
| 3 | +/** |
| 4 | + * Apply `neutral` and `suggest` if they're not already part of the color object, |
| 5 | + * as this was introduced in v2.9, but is not compatible with v2.0. |
| 6 | + * |
| 7 | + * @param color - The color object to upgrade |
| 8 | + * @returns The upgraded color object. Returns as-is if already upgraded. |
| 9 | + * @internal |
| 10 | + */ |
| 11 | +export function themeColor_v0_v2_9(color: ThemeColorCard_v2): ThemeColorCard_v2 { |
| 12 | + if ('neutral' in color.badge) { |
| 13 | + return color // Already at >= v2.9 |
| 14 | + } |
| 15 | + |
| 16 | + // TypeScript narrows to `never` because the above should always be true |
| 17 | + const colors = color as ThemeColorCard_v2 |
| 18 | + |
| 19 | + return { |
| 20 | + ...colors, |
| 21 | + badge: { |
| 22 | + ...colors.badge, |
| 23 | + neutral: colors.badge.default, |
| 24 | + suggest: colors.badge.primary, |
| 25 | + }, |
| 26 | + button: { |
| 27 | + bleed: { |
| 28 | + ...colors.button.bleed, |
| 29 | + neutral: colors.button.bleed.default, |
| 30 | + suggest: colors.button.bleed.primary, |
| 31 | + }, |
| 32 | + default: { |
| 33 | + ...colors.button.default, |
| 34 | + neutral: colors.button.default.default, |
| 35 | + suggest: colors.button.default.primary, |
| 36 | + }, |
| 37 | + ghost: { |
| 38 | + ...colors.button.ghost, |
| 39 | + neutral: colors.button.ghost.default, |
| 40 | + suggest: colors.button.ghost.primary, |
| 41 | + }, |
| 42 | + }, |
| 43 | + selectable: { |
| 44 | + ...colors.selectable, |
| 45 | + neutral: colors.selectable.default, |
| 46 | + suggest: colors.selectable.primary, |
| 47 | + }, |
| 48 | + } |
| 49 | +} |
0 commit comments