Skip to content

Commit dc37d76

Browse files
committed
feat: add theme.shapes and cornersToStyle
Adds the 10 MD3 shape scale tokens to theme.shapes.*, ShapeCorners for directional variants, and cornersToStyle() for mapping to RN style props. Deprecates theme.roundness in favour of theme.shapes.
1 parent d68ecfc commit dc37d76

8 files changed

Lines changed: 97 additions & 0 deletions

File tree

src/components/__tests__/__snapshots__/ListSection.test.tsx.snap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ exports[`renders list section with custom title style 1`] = `
188188
},
189189
},
190190
"roundness": 4,
191+
"shapes": {
192+
"extraExtraLarge": 48,
193+
"extraLarge": 28,
194+
"extraLargeIncreased": 32,
195+
"extraSmall": 4,
196+
"full": 9999,
197+
"large": 16,
198+
"largeIncreased": 20,
199+
"medium": 12,
200+
"none": 0,
201+
"small": 8,
202+
},
191203
"state": {
192204
"opacity": {
193205
"dragged": 0.16,
@@ -738,6 +750,18 @@ exports[`renders list section with subheader 1`] = `
738750
},
739751
},
740752
"roundness": 4,
753+
"shapes": {
754+
"extraExtraLarge": 48,
755+
"extraLarge": 28,
756+
"extraLargeIncreased": 32,
757+
"extraSmall": 4,
758+
"full": 9999,
759+
"large": 16,
760+
"largeIncreased": 20,
761+
"medium": 12,
762+
"none": 0,
763+
"small": 8,
764+
},
741765
"state": {
742766
"opacity": {
743767
"dragged": 0.16,
@@ -1286,6 +1310,18 @@ exports[`renders list section without subheader 1`] = `
12861310
},
12871311
},
12881312
"roundness": 4,
1313+
"shapes": {
1314+
"extraExtraLarge": 48,
1315+
"extraLarge": 28,
1316+
"extraLargeIncreased": 32,
1317+
"extraSmall": 4,
1318+
"full": 9999,
1319+
"large": 16,
1320+
"largeIncreased": 20,
1321+
"medium": 12,
1322+
"none": 0,
1323+
"small": 8,
1324+
},
12891325
"state": {
12901326
"opacity": {
12911327
"dragged": 0.16,

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export { default as Provider } from './core/PaperProvider';
1414
export { default as PaperProvider } from './core/PaperProvider';
1515
export { default as shadow } from './theme/shadow';
1616
export { default as configureFonts } from './theme/fonts';
17+
export { cornersToStyle } from './theme/tokens/sys/shape';
1718

1819
import * as Avatar from './components/Avatar/Avatar';
1920
import * as Drawer from './components/Drawer/Drawer';

src/theme/schemes/DarkTheme.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { baseTheme } from './base';
22
import { tokens } from '../tokens';
33
import { buildScheme } from '../tokens/sys/color/roles';
4+
import { defaultShapes } from '../tokens/sys/shape';
45
import { defaultState } from '../tokens/sys/state';
56
import type { Theme } from '../types';
67

@@ -10,4 +11,5 @@ export const DarkTheme: Theme = {
1011
mode: 'adaptive',
1112
colors: buildScheme(tokens.md.ref.palette, tokens.md.ref, { mode: 'dark' }),
1213
state: defaultState,
14+
shapes: defaultShapes,
1315
};

src/theme/schemes/LightTheme.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { baseTheme } from './base';
22
import { tokens } from '../tokens';
33
import { buildScheme } from '../tokens/sys/color/roles';
4+
import { defaultShapes } from '../tokens/sys/shape';
45
import { defaultState } from '../tokens/sys/state';
56
import type { Theme } from '../types';
67

@@ -9,4 +10,5 @@ export const LightTheme: Theme = {
910
dark: false,
1011
colors: buildScheme(tokens.md.ref.palette, tokens.md.ref, { mode: 'light' }),
1112
state: defaultState,
13+
shapes: defaultShapes,
1214
};

src/theme/tokens/sys/shape.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { ViewStyle } from 'react-native';
2+
3+
import type { ShapeCorners, ThemeShapes } from '../../types';
4+
5+
export const defaultShapes: ThemeShapes = {
6+
none: 0,
7+
extraSmall: 4,
8+
small: 8,
9+
medium: 12,
10+
large: 16,
11+
largeIncreased: 20,
12+
extraLarge: 28,
13+
extraLargeIncreased: 32,
14+
extraExtraLarge: 48,
15+
full: 9999,
16+
};
17+
18+
type CornersStyle = Pick<
19+
ViewStyle,
20+
| 'borderTopStartRadius'
21+
| 'borderTopEndRadius'
22+
| 'borderBottomStartRadius'
23+
| 'borderBottomEndRadius'
24+
>;
25+
26+
export function cornersToStyle(corners: ShapeCorners): CornersStyle {
27+
return {
28+
borderTopStartRadius: corners.topStart,
29+
borderTopEndRadius: corners.topEnd,
30+
borderBottomStartRadius: corners.bottomStart,
31+
borderBottomEndRadius: corners.bottomEnd,
32+
};
33+
}

src/theme/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './color';
22
export * from './elevation';
33
export * from './navigation';
4+
export * from './shape';
45
export * from './state';
56
export * from './theme';
67
export * from './typography';

src/theme/types/shape.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type ShapeCorners = {
2+
topStart: number;
3+
topEnd: number;
4+
bottomStart: number;
5+
bottomEnd: number;
6+
};
7+
8+
export type ThemeShapes = {
9+
none: number;
10+
extraSmall: number;
11+
small: number;
12+
medium: number;
13+
large: number;
14+
largeIncreased: number;
15+
extraLarge: number;
16+
extraLargeIncreased: number;
17+
extraExtraLarge: number;
18+
full: number;
19+
};

src/theme/types/theme.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { $DeepPartial } from '@callstack/react-theme-provider';
22

33
import type { ThemeColors } from './color';
4+
import type { ThemeShapes } from './shape';
45
import type { ThemeState } from './state';
56
import type { Typescale } from './typography';
67

@@ -9,6 +10,7 @@ type Mode = 'adaptive' | 'exact';
910
export type ThemeBase = {
1011
dark: boolean;
1112
mode?: Mode;
13+
/** @deprecated Use `theme.shapes.*` instead. Will be removed in a future version. */
1214
roundness: number;
1315
animation: {
1416
scale: number;
@@ -20,6 +22,7 @@ export type Theme = ThemeBase & {
2022
colors: ThemeColors;
2123
fonts: Typescale;
2224
state: ThemeState;
25+
shapes: ThemeShapes;
2326
};
2427

2528
export type InternalTheme = Theme;

0 commit comments

Comments
 (0)