Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards compatibility for V2 theme #622

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export const LifeSGTheme: ThemeSpec = {
radiusScheme: "lifesg",
breakpointScheme: "lifesg",
resourceScheme: "lifesg",
_v2: {
colorScheme: "base",
textStyleScheme: "base",
designTokenScheme: "base",
resourceScheme: "base",
},
};

export const BookingSGTheme: ThemeSpec = {
Expand All @@ -59,6 +65,12 @@ export const BookingSGTheme: ThemeSpec = {
radiusScheme: "lifesg",
breakpointScheme: "lifesg",
resourceScheme: "bookingsg",
_v2: {
colorScheme: "bookingsg",
textStyleScheme: "base",
designTokenScheme: "base",
resourceScheme: "bookingsg",
},
};

export const CCubeTheme: ThemeSpec = {
Expand All @@ -70,6 +82,12 @@ export const CCubeTheme: ThemeSpec = {
radiusScheme: "lifesg",
breakpointScheme: "lifesg",
resourceScheme: "ccube",
_v2: {
colorScheme: "ccube",
textStyleScheme: "base",
designTokenScheme: "base",
resourceScheme: "ccube",
},
};

export const MyLegacyTheme: ThemeSpec = {
Expand All @@ -81,6 +99,12 @@ export const MyLegacyTheme: ThemeSpec = {
radiusScheme: "lifesg",
breakpointScheme: "lifesg",
resourceScheme: "mylegacy",
_v2: {
colorScheme: "mylegacy",
textStyleScheme: "base",
designTokenScheme: "base",
resourceScheme: "mylegacy",
},
};

export const RBSTheme: ThemeSpec = {
Expand All @@ -92,4 +116,10 @@ export const RBSTheme: ThemeSpec = {
radiusScheme: "lifesg",
breakpointScheme: "lifesg",
resourceScheme: "rbs",
_v2: {
colorScheme: "rbs",
textStyleScheme: "base",
designTokenScheme: "rbs",
resourceScheme: "rbs",
},
};
11 changes: 7 additions & 4 deletions src/theme/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { V2_ThemeSpec } from "../v2_theme/types";
import { BorderSetOptions } from "./border/types";
import { BreakpointSetOptions } from "./breakpoint/types";
import { PrimitiveColourSetOptions } from "./colour-primitive/types";
import { SemanticColourSetOptions } from "./colour-semantic/types";
import { FontSetOptions } from "./font/types";
import { FontSpecSetOptions } from "./font-spec/types";
import { FontSetOptions } from "./font/types";
import { MotionSetOptions } from "./motion/types";
import { BorderSetOptions } from "./border/types";
import { SpacingSetOptions } from "./spacing/types";
import { RadiusSetOptions } from "./radius/types";
import { BreakpointSetOptions } from "./breakpoint/types";
import { SpacingSetOptions } from "./spacing/types";

export type {
PrimitiveColourSet,
Expand Down Expand Up @@ -76,6 +77,8 @@ export interface ThemeSpec {
overrides?: ThemeSpecOptions | undefined;

maxColumns?: any;
/** @deprecated For backwards compatibility with V2 theme */
_v2?: V2_ThemeSpec;
}

export interface ThemeCollectionSpec<T, V> {
Expand Down
4 changes: 2 additions & 2 deletions src/v2_theme/color-theme-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const ColorSpec: V2_ThemeCollectionSpec<
// =============================================================================
export const getThemeColors = (attributePath: string) => {
return (props: any): string => {
const theme = props.theme as V2_ThemeSpec;
const theme = (props.theme?._v2 || props.theme) as V2_ThemeSpec;
const colorSet: V2_ColorSet = getCollection(
ColorSpec,
theme[V2_ThemeContextKeys.colorScheme]
theme?.[V2_ThemeContextKeys.colorScheme]
);

return theme.options && theme.options.color
Expand Down
4 changes: 2 additions & 2 deletions src/v2_theme/design-token-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const DesignTokenSpec: V2_ThemeCollectionSpec<
// =============================================================================
export const getThemeDesignToken = (attributePath: string) => {
return (props: any): CssValue => {
const theme = props.theme as V2_ThemeSpec;
const theme = (props.theme?._v2 || props.theme) as V2_ThemeSpec;
const DesignTokenSet: V2_DesignTokenSet = getCollection(
DesignTokenSpec,
theme[V2_ThemeContextKeys.designTokenScheme]
theme?.[V2_ThemeContextKeys.designTokenScheme]
);

return theme.options?.designToken
Expand Down
4 changes: 2 additions & 2 deletions src/v2_theme/text-theme-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const TextStyleSpec: V2_ThemeCollectionSpec<
// =============================================================================
export const getThemeTextStyles = (attributePath: string) => {
return (props: any): string | number => {
const theme = props.theme as V2_ThemeSpec;
const theme = (props.theme?._v2 || props.theme) as V2_ThemeSpec;
const textStyleSet: V2_TextStyleSetType = getCollection(
TextStyleSpec,
theme[V2_ThemeContextKeys.textStyleScheme]
theme?.[V2_ThemeContextKeys.textStyleScheme]
);

return theme.options && theme.options.textStyle
Expand Down
Loading