Skip to content

Commit e808be4

Browse files
committed
feat(javascript): add button border radius overrides and update theme components
1 parent 19cf975 commit e808be4

File tree

5 files changed

+101
-9
lines changed

5 files changed

+101
-9
lines changed

packages/javascript/src/theme/createTheme.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,31 @@ const toCssVariables = (theme: ThemeConfig): Record<string, string> => {
449449
});
450450
}
451451

452+
/* |---------------------------------------------------------------| */
453+
/* | Components | */
454+
/* |---------------------------------------------------------------| */
455+
456+
// Button Overrides
457+
if (theme.components?.Button?.styleOverrides?.root?.borderRadius) {
458+
cssVars[`--${prefix}-component-button-root-borderRadius`] =
459+
theme.components.Button.styleOverrides.root.borderRadius;
460+
}
461+
452462
return cssVars;
453463
};
454464

455465
const toThemeVars = (theme: ThemeConfig): ThemeVars => {
456466
const prefix = theme.cssVarPrefix || VendorConstants.VENDOR_PREFIX;
457467

468+
const componentVars: ThemeVars['components'] = {};
469+
if (theme.components?.Button?.styleOverrides?.root?.borderRadius) {
470+
componentVars.Button = {
471+
root: {
472+
borderRadius: `var(--${prefix}-component-button-root-borderRadius)`,
473+
},
474+
};
475+
}
476+
458477
const themeVars: ThemeVars = {
459478
colors: {
460479
action: {
@@ -558,6 +577,10 @@ const toThemeVars = (theme: ThemeConfig): ThemeVars => {
558577
});
559578
}
560579

580+
if (Object.keys(componentVars).length > 0) {
581+
themeVars.components = componentVars;
582+
}
583+
561584
return themeVars;
562585
};
563586

packages/javascript/src/theme/types.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,36 @@ export interface ThemeColors {
101101
};
102102
}
103103

104+
export interface ThemeComponentStyleOverrides {
105+
/**
106+
* Style overrides for the root element or slots.
107+
* Example: { root: { borderRadius: '8px' } }
108+
*/
109+
root?: Record<string, any>;
110+
[slot: string]: Record<string, any> | undefined;
111+
}
112+
113+
export interface ThemeComponents {
114+
Button?: {
115+
styleOverrides?: {
116+
root?: {
117+
borderRadius?: string;
118+
[key: string]: any;
119+
};
120+
[slot: string]: Record<string, any> | undefined;
121+
};
122+
defaultProps?: Record<string, any>;
123+
variants?: Array<Record<string, any>>;
124+
};
125+
[componentName: string]:
126+
| {
127+
styleOverrides?: ThemeComponentStyleOverrides;
128+
defaultProps?: Record<string, any>;
129+
variants?: Array<Record<string, any>>;
130+
}
131+
| undefined;
132+
}
133+
104134
export interface ThemeConfig {
105135
borderRadius: {
106136
large: string;
@@ -148,6 +178,25 @@ export interface ThemeConfig {
148178
* @default 'asgardeo' (from VendorConstants.VENDOR_PREFIX)
149179
*/
150180
cssVarPrefix?: string;
181+
/**
182+
* Component style overrides
183+
*/
184+
components?: ThemeComponents;
185+
}
186+
187+
export interface ThemeComponentVars {
188+
Button?: {
189+
root?: {
190+
borderRadius?: string;
191+
[key: string]: any;
192+
};
193+
[slot: string]: Record<string, any> | undefined;
194+
};
195+
[componentName: string]:
196+
| {
197+
[slot: string]: Record<string, any> | undefined;
198+
}
199+
| undefined;
151200
}
152201

153202
export interface ThemeVars {
@@ -266,6 +315,10 @@ export interface ThemeVars {
266315
}
267316
| undefined;
268317
};
318+
/**
319+
* Component CSS variable references (e.g., for overrides)
320+
*/
321+
components?: ThemeComponentVars;
269322
}
270323

271324
export interface Theme extends ThemeConfig {

packages/javascript/src/utils/transformBrandingPreferenceToTheme.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const transformThemeVariant = (themeVariant: ThemeVariant, isDark = false): Part
4949
const inputs = themeVariant.inputs;
5050
const images = themeVariant.images;
5151

52-
return {
52+
const config: Partial<ThemeConfig> = {
5353
colors: {
5454
action: {
5555
active: isDark ? 'rgba(255, 255, 255, 0.70)' : 'rgba(0, 0, 0, 0.54)',
@@ -111,13 +111,6 @@ const transformThemeVariant = (themeVariant: ThemeVariant, isDark = false): Part
111111
dark: (colors?.alerts?.warning as ColorVariant)?.dark || (colors?.alerts?.warning as ColorVariant)?.main,
112112
},
113113
},
114-
// Extract border radius from buttons or inputs
115-
borderRadius: {
116-
small: buttons?.primary?.base?.border?.borderRadius || inputs?.base?.border?.borderRadius,
117-
medium: buttons?.secondary?.base?.border?.borderRadius,
118-
large: buttons?.externalConnection?.base?.border?.borderRadius,
119-
},
120-
// Extract and transform images
121114
images: {
122115
favicon: images?.favicon
123116
? {
@@ -135,6 +128,22 @@ const transformThemeVariant = (themeVariant: ThemeVariant, isDark = false): Part
135128
: undefined,
136129
},
137130
};
131+
132+
// --- COMPONENT OVERRIDES: Button borderRadius ---
133+
const buttonBorderRadius = buttons?.primary?.base?.border?.borderRadius;
134+
if (buttonBorderRadius) {
135+
config.components = {
136+
Button: {
137+
styleOverrides: {
138+
root: {
139+
borderRadius: buttonBorderRadius,
140+
},
141+
},
142+
},
143+
};
144+
}
145+
146+
return config;
138147
};
139148

140149
/**

packages/react/src/components/primitives/Button/Button.styles.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ const useStyles = (
5353
align-items: center;
5454
justify-content: center;
5555
gap: calc(${theme.vars.spacing.unit} * 1);
56-
border-radius: ${shape === 'round' ? '50%' : theme.vars.borderRadius.medium};
56+
border-radius: ${shape === 'round'
57+
? '50%'
58+
: theme.vars.components?.Button?.root?.borderRadius || theme.vars.borderRadius.medium};
5759
font-weight: 500;
5860
cursor: ${disabled || loading ? 'not-allowed' : 'pointer'};
5961
outline: none;

packages/react/src/contexts/Theme/ThemeProvider.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ const ThemeProvider: FC<PropsWithChildren<ThemeProviderProps>> = ({
175175
shadows: brandingTheme.shadows,
176176
spacing: brandingTheme.spacing,
177177
images: brandingTheme.images,
178+
components: brandingTheme.components,
178179
};
179180

180181
// Merge branding theme with user-provided theme config
@@ -202,6 +203,10 @@ const ThemeProvider: FC<PropsWithChildren<ThemeProviderProps>> = ({
202203
...brandingThemeConfig.images,
203204
...themeConfig?.images,
204205
},
206+
components: {
207+
...brandingThemeConfig.components,
208+
...themeConfig?.components,
209+
},
205210
};
206211
}, [inheritFromBranding, brandingTheme, themeConfig]);
207212

0 commit comments

Comments
 (0)