Skip to content

Commit 0c26c37

Browse files
authored
[material-ui] Fix regression on theme.vars.shape module augmentation (#47164)
1 parent 7bb780f commit 0c26c37

File tree

10 files changed

+117
-4
lines changed

10 files changed

+117
-4
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Shape
2+
3+
<p class="description">The shape is a design token that helps control the border radius of components.</p>
4+
5+
The `shape` contains a single property, `borderRadius`, with the default value of `4px`.
6+
Several components use this value to set consistent border radii across the library.
7+
8+
## Custom shape
9+
10+
To add custom shapes, create a theme with the `shape` key:
11+
12+
```js
13+
import { createTheme } from '@mui/material/styles';
14+
15+
const theme = createTheme({
16+
shape: {
17+
borderRadius: 8,
18+
borderRadiusSm: 4, // new property
19+
borderRadiusMd: 8, // new property
20+
borderRadiusLg: 16, // new property
21+
borderRadiusXl: 24, // new property
22+
},
23+
});
24+
```
25+
26+
### Typescript
27+
28+
If you're using TypeScript you need to use [module augmentation](/material-ui/guides/typescript/#customization-of-theme) to extend **new** shape properties to the theme.
29+
30+
```ts
31+
declare module '@mui/material/styles' {
32+
interface Shape {
33+
borderRadiusSm: number;
34+
borderRadiusMd: number;
35+
borderRadiusLg: number;
36+
borderRadiusXl: number;
37+
}
38+
39+
interface ShapeOptions {
40+
borderRadiusSm?: number;
41+
borderRadiusMd?: number;
42+
borderRadiusLg?: number;
43+
borderRadiusXl?: number;
44+
}
45+
}
46+
```

docs/data/material/pages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ const pages: MuiPage[] = [
195195
{ pathname: '/material-ui/customization/palette' },
196196
{ pathname: '/material-ui/customization/typography' },
197197
{ pathname: '/material-ui/customization/spacing' },
198+
{ pathname: '/material-ui/customization/shape' },
198199
{ pathname: '/material-ui/customization/breakpoints' },
199200
{
200201
pathname: '/material-ui/customization/container-queries',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
2+
import * as pageProps from 'docs/data/material/customization/shape/shape.md?muiMarkdown';
3+
4+
export default function Page() {
5+
return <MarkdownDocs {...pageProps} />;
6+
}

docs/translations/translations.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
"/material-ui/customization/palette": "Palette",
139139
"/material-ui/customization/typography": "Typography",
140140
"/material-ui/customization/spacing": "Spacing",
141+
"/material-ui/customization/shape": "Shape",
141142
"/material-ui/customization/breakpoints": "Breakpoints",
142143
"/material-ui/customization/container-queries": "Container queries",
143144
"/material-ui/customization/density": "Density",

packages/mui-material/src/styles/createThemeFoundation.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { OverridableStringUnion } from '@mui/types';
2-
import { SxConfig, SxProps, CSSObject, ApplyStyles, Theme as SystemTheme } from '@mui/system';
2+
import {
3+
SxConfig,
4+
SxProps,
5+
CSSObject,
6+
ApplyStyles,
7+
Theme as SystemTheme,
8+
Shape as SystemShape,
9+
ShapeOptions as SystemShapeOptions,
10+
} from '@mui/system';
311
import { ExtractTypographyTokens } from '@mui/system/cssVars';
412
import { Palette, PaletteOptions } from './createPalette';
513
import { Shadows } from './shadows';
@@ -205,6 +213,10 @@ export interface PaletteTooltip {
205213
bg: string;
206214
}
207215

216+
export interface Shape extends SystemShape {}
217+
218+
export interface ShapeOptions extends SystemShapeOptions {}
219+
208220
// The Palette should be sync with `../themeCssVarsAugmentation/index.d.ts`
209221
export interface ColorSystemOptions {
210222
palette?: PaletteOptions & {
@@ -290,7 +302,7 @@ export interface ThemeVars {
290302
opacity: Opacity;
291303
overlays: Overlays;
292304
shadows: Shadows;
293-
shape: SystemTheme['shape'];
305+
shape: Shape;
294306
spacing: string;
295307
zIndex: ZIndex;
296308
}
@@ -397,7 +409,7 @@ export interface CssVarsTheme extends ColorSystem {
397409
// Default theme tokens
398410
spacing: SystemTheme['spacing'];
399411
breakpoints: SystemTheme['breakpoints'];
400-
shape: SystemTheme['shape'];
412+
shape: Shape;
401413
typography: TypographyVariants;
402414
transitions: Transitions;
403415
shadows: Shadows;

packages/mui-material/src/styles/createThemeNoVars.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import { Shadows } from './shadows';
1212
import { Transitions, TransitionsOptions } from './createTransitions';
1313
import { ZIndex, ZIndexOptions } from './zIndex';
1414
import { Components } from './components';
15-
import { CssVarsTheme, CssVarsPalette, ColorSystemOptions } from './createThemeFoundation';
15+
import {
16+
CssVarsTheme,
17+
CssVarsPalette,
18+
ColorSystemOptions,
19+
Shape,
20+
ShapeOptions,
21+
} from './createThemeFoundation';
1622

1723
/**
1824
* To disable custom properties, use module augmentation
@@ -37,6 +43,7 @@ export interface ThemeOptions extends Omit<SystemThemeOptions, 'zIndex'>, CssVar
3743
components?: Components<Omit<Theme, 'components'>>;
3844
palette?: PaletteOptions;
3945
shadows?: Shadows;
46+
shape?: ShapeOptions;
4047
transitions?: TransitionsOptions;
4148
typography?: TypographyVariantsOptions | ((palette: Palette) => TypographyVariantsOptions);
4249
zIndex?: ZIndexOptions;
@@ -49,6 +56,7 @@ export interface BaseTheme extends SystemTheme {
4956
mixins: Mixins;
5057
palette: Palette & (CssThemeVariables extends { enabled: true } ? CssVarsPalette : {});
5158
shadows: Shadows;
59+
shape: Shape;
5260
transitions: Transitions;
5361
typography: TypographyVariants;
5462
zIndex: ZIndex;

packages/mui-material/src/styles/createThemeWithVars.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
ThemeCssVarOverrides,
3636
ThemeCssVar,
3737
CssVarsTheme,
38+
Shape,
39+
ShapeOptions,
3840
} from './createThemeFoundation';
3941

4042
// Re-export all types from foundation to maintain backward compatibility
@@ -73,6 +75,8 @@ export type {
7375
ThemeCssVarOverrides,
7476
ThemeCssVar,
7577
CssVarsTheme,
78+
Shape,
79+
ShapeOptions,
7680
};
7781

7882
export interface CssVarsThemeOptions extends Omit<ThemeOptions, 'palette' | 'components'> {

packages/mui-material/src/styles/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ export type {
158158
ThemeCssVar,
159159
ThemeCssVarOverrides,
160160
ColorSystemOptions,
161+
Shape,
162+
ShapeOptions,
161163
} from './createThemeWithVars';
162164
export { default as getOverlayAlpha } from './getOverlayAlpha';
163165
export { default as shouldSkipGeneratingVar } from './shouldSkipGeneratingVar';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createTheme } from '@mui/material/styles';
2+
3+
declare module '@mui/material/styles' {
4+
interface Shape {
5+
borderRadiusSecondary: number;
6+
}
7+
8+
interface ShapeOptions {
9+
borderRadiusSecondary: number;
10+
}
11+
}
12+
13+
createTheme({
14+
shape: {
15+
borderRadiusSecondary: 12,
16+
},
17+
components: {
18+
MuiButton: {
19+
styleOverrides: {
20+
root: ({ theme }) => ({
21+
borderRadius: theme.shape.borderRadiusSecondary,
22+
'&:hover': {
23+
borderRadius: theme.vars.shape.borderRadiusSecondary,
24+
},
25+
}),
26+
},
27+
},
28+
},
29+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../../../../tsconfig.json",
3+
"files": ["shape.spec.ts"]
4+
}

0 commit comments

Comments
 (0)