Skip to content
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
46 changes: 46 additions & 0 deletions docs/data/material/customization/shape/shape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Shape

<p class="description">The shape is a design token that helps control the border radius of components.</p>

The `shape` contains a single property, `borderRadius`, with the default value of `4px`.
Several components use this value to set consistent border radii across the library.

## Custom shape

To add custom shapes, create a theme with the `shape` key:

```js
import { createTheme } from '@mui/material/styles';

const theme = createTheme({
shape: {
borderRadius: 8,
borderRadiusSm: 4, // new property
borderRadiusMd: 8, // new property
borderRadiusLg: 16, // new property
borderRadiusXl: 24, // new property
},
});
```

### Typescript

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.

```ts
declare module '@mui/material/styles' {
interface Shape {
borderRadiusSm: number;
borderRadiusMd: number;
borderRadiusLg: number;
borderRadiusXl: number;
}

interface ShapeOptions {
borderRadiusSm?: number;
borderRadiusMd?: number;
borderRadiusLg?: number;
borderRadiusXl?: number;
}
}
```
1 change: 1 addition & 0 deletions docs/data/material/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const pages: MuiPage[] = [
{ pathname: '/material-ui/customization/palette' },
{ pathname: '/material-ui/customization/typography' },
{ pathname: '/material-ui/customization/spacing' },
{ pathname: '/material-ui/customization/shape' },
{ pathname: '/material-ui/customization/breakpoints' },
{
pathname: '/material-ui/customization/container-queries',
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/material-ui/customization/shape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from 'docs/data/material/customization/shape/shape.md?muiMarkdown';

export default function Page() {
return <MarkdownDocs {...pageProps} />;
}
1 change: 1 addition & 0 deletions docs/translations/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"/material-ui/customization/palette": "Palette",
"/material-ui/customization/typography": "Typography",
"/material-ui/customization/spacing": "Spacing",
"/material-ui/customization/shape": "Shape",
"/material-ui/customization/breakpoints": "Breakpoints",
"/material-ui/customization/container-queries": "Container queries",
"/material-ui/customization/density": "Density",
Expand Down
18 changes: 15 additions & 3 deletions packages/mui-material/src/styles/createThemeFoundation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { OverridableStringUnion } from '@mui/types';
import { SxConfig, SxProps, CSSObject, ApplyStyles, Theme as SystemTheme } from '@mui/system';
import {
SxConfig,
SxProps,
CSSObject,
ApplyStyles,
Theme as SystemTheme,
Shape as SystemShape,
ShapeOptions as SystemShapeOptions,
} from '@mui/system';
import { ExtractTypographyTokens } from '@mui/system/cssVars';
import { Palette, PaletteOptions } from './createPalette';
import { Shadows } from './shadows';
Expand Down Expand Up @@ -205,6 +213,10 @@ export interface PaletteTooltip {
bg: string;
}

export interface Shape extends SystemShape {}

export interface ShapeOptions extends SystemShapeOptions {}

// The Palette should be sync with `../themeCssVarsAugmentation/index.d.ts`
export interface ColorSystemOptions {
palette?: PaletteOptions & {
Expand Down Expand Up @@ -290,7 +302,7 @@ export interface ThemeVars {
opacity: Opacity;
overlays: Overlays;
shadows: Shadows;
shape: SystemTheme['shape'];
shape: Shape;
spacing: string;
zIndex: ZIndex;
}
Expand Down Expand Up @@ -397,7 +409,7 @@ export interface CssVarsTheme extends ColorSystem {
// Default theme tokens
spacing: SystemTheme['spacing'];
breakpoints: SystemTheme['breakpoints'];
shape: SystemTheme['shape'];
shape: Shape;
typography: TypographyVariants;
transitions: Transitions;
shadows: Shadows;
Expand Down
10 changes: 9 additions & 1 deletion packages/mui-material/src/styles/createThemeNoVars.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { Shadows } from './shadows';
import { Transitions, TransitionsOptions } from './createTransitions';
import { ZIndex, ZIndexOptions } from './zIndex';
import { Components } from './components';
import { CssVarsTheme, CssVarsPalette, ColorSystemOptions } from './createThemeFoundation';
import {
CssVarsTheme,
CssVarsPalette,
ColorSystemOptions,
Shape,
ShapeOptions,
} from './createThemeFoundation';

/**
* To disable custom properties, use module augmentation
Expand All @@ -37,6 +43,7 @@ export interface ThemeOptions extends Omit<SystemThemeOptions, 'zIndex'>, CssVar
components?: Components<Omit<Theme, 'components'>>;
palette?: PaletteOptions;
shadows?: Shadows;
shape?: ShapeOptions;
transitions?: TransitionsOptions;
typography?: TypographyVariantsOptions | ((palette: Palette) => TypographyVariantsOptions);
zIndex?: ZIndexOptions;
Expand All @@ -49,6 +56,7 @@ export interface BaseTheme extends SystemTheme {
mixins: Mixins;
palette: Palette & (CssThemeVariables extends { enabled: true } ? CssVarsPalette : {});
shadows: Shadows;
shape: Shape;
transitions: Transitions;
typography: TypographyVariants;
zIndex: ZIndex;
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-material/src/styles/createThemeWithVars.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
ThemeCssVarOverrides,
ThemeCssVar,
CssVarsTheme,
Shape,
ShapeOptions,
} from './createThemeFoundation';

// Re-export all types from foundation to maintain backward compatibility
Expand Down Expand Up @@ -73,6 +75,8 @@ export type {
ThemeCssVarOverrides,
ThemeCssVar,
CssVarsTheme,
Shape,
ShapeOptions,
};

export interface CssVarsThemeOptions extends Omit<ThemeOptions, 'palette' | 'components'> {
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-material/src/styles/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export type {
ThemeCssVar,
ThemeCssVarOverrides,
ColorSystemOptions,
Shape,
ShapeOptions,
} from './createThemeWithVars';
export { default as getOverlayAlpha } from './getOverlayAlpha';
export { default as shouldSkipGeneratingVar } from './shouldSkipGeneratingVar';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createTheme } from '@mui/material/styles';

declare module '@mui/material/styles' {
interface Shape {
borderRadiusSecondary: number;
}

interface ShapeOptions {
borderRadiusSecondary: number;
}
}

createTheme({
shape: {
borderRadiusSecondary: 12,
},
components: {
MuiButton: {
styleOverrides: {
root: ({ theme }) => ({
borderRadius: theme.shape.borderRadiusSecondary,
'&:hover': {
borderRadius: theme.vars.shape.borderRadiusSecondary,
},
}),
},
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../../../../tsconfig.json",
"files": ["shape.spec.ts"]
}
Loading