@codecademy/styleguide 79.0.1-alpha.df213b.0 → 79.0.1-alpha.dfd5fd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/components/Elements/DocsContainer.tsx +4 -0
- package/.storybook/preview.ts +14 -0
- package/.storybook/theming/GamutThemeProvider.tsx +7 -1
- package/CHANGELOG.md +1 -1
- package/package.json +2 -2
- package/src/lib/Foundations/System/Props/Border.mdx +23 -3
- package/src/lib/Foundations/System/Props/Border.stories.tsx +138 -0
- package/src/lib/Foundations/System/Props/Color.mdx +17 -3
- package/src/lib/Foundations/System/Props/Color.stories.tsx +47 -0
- package/src/lib/Foundations/System/Props/Space.mdx +19 -3
- package/src/lib/Foundations/System/Props/Space.stories.tsx +48 -0
- package/src/lib/Foundations/shared/elements.tsx +58 -20
- package/src/lib/Meta/About.mdx +3 -1
- package/src/lib/Meta/Logical and physical CSS properties.mdx +123 -0
- package/src/lib/Meta/Usage Guide.mdx +6 -1
- package/src/static/meta/toolbar.png +0 -0
|
@@ -52,6 +52,9 @@ export const DocsContainer: React.FC<{
|
|
|
52
52
|
|
|
53
53
|
const globalTheme =
|
|
54
54
|
(context as any).store.userGlobals?.globals?.theme || 'core';
|
|
55
|
+
const globalLogicalProps = (context as any).store.userGlobals?.globals
|
|
56
|
+
?.logicalProps;
|
|
57
|
+
const useLogicalProperties = globalLogicalProps !== 'false';
|
|
55
58
|
|
|
56
59
|
const { currentTheme } = useMemo(() => {
|
|
57
60
|
const findThemeStory: keyof typeof themeSpecificStories | undefined =
|
|
@@ -77,6 +80,7 @@ export const DocsContainer: React.FC<{
|
|
|
77
80
|
cache={createEmotionCache({ speedy: false })}
|
|
78
81
|
// This is typed to the CoreTheme in theme.d.ts
|
|
79
82
|
theme={currentTheme as unknown as CoreTheme}
|
|
83
|
+
useLogicalProperties={useLogicalProperties}
|
|
80
84
|
>
|
|
81
85
|
<ColorMode mode="light">
|
|
82
86
|
<HelmetProvider>
|
package/.storybook/preview.ts
CHANGED
|
@@ -49,6 +49,7 @@ const preview: Preview = {
|
|
|
49
49
|
'ESLint rules',
|
|
50
50
|
'Contributing',
|
|
51
51
|
'FAQs',
|
|
52
|
+
'Logical and physical CSS properties',
|
|
52
53
|
'Stories',
|
|
53
54
|
],
|
|
54
55
|
'Foundations',
|
|
@@ -163,6 +164,19 @@ export const globalTypes = {
|
|
|
163
164
|
showName: true,
|
|
164
165
|
},
|
|
165
166
|
},
|
|
167
|
+
logicalProps: {
|
|
168
|
+
name: 'LogicalProps',
|
|
169
|
+
description: 'Toggle between logical and physical CSS properties',
|
|
170
|
+
defaultValue: 'true',
|
|
171
|
+
toolbar: {
|
|
172
|
+
icon: 'transfer',
|
|
173
|
+
items: [
|
|
174
|
+
{ value: 'true', title: 'Logical' },
|
|
175
|
+
{ value: 'false', title: 'Physical' },
|
|
176
|
+
],
|
|
177
|
+
showName: true,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
166
180
|
};
|
|
167
181
|
|
|
168
182
|
export const decorators = [withEmotion];
|
|
@@ -34,12 +34,14 @@ type GlobalsContext = {
|
|
|
34
34
|
globals: {
|
|
35
35
|
colorMode: 'light' | 'dark';
|
|
36
36
|
theme: keyof typeof themeMap;
|
|
37
|
+
logicalProps: 'true' | 'false';
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
export const withEmotion = (Story: any, context: GlobalsContext) => {
|
|
41
42
|
const colorMode = context.globals.colorMode ?? 'light';
|
|
42
43
|
const selectedTheme = context.globals.theme;
|
|
44
|
+
const useLogicalProperties = context.globals.logicalProps !== 'false';
|
|
43
45
|
const background = corePalette[themeBackground[colorMode]];
|
|
44
46
|
const storyRef = useRef<HTMLDivElement>(null);
|
|
45
47
|
const currentTheme = themeMap[selectedTheme];
|
|
@@ -57,6 +59,7 @@ export const withEmotion = (Story: any, context: GlobalsContext) => {
|
|
|
57
59
|
<GamutProvider
|
|
58
60
|
useCache={false}
|
|
59
61
|
useGlobals={false}
|
|
62
|
+
useLogicalProperties={useLogicalProperties}
|
|
60
63
|
theme={currentTheme as unknown as Theme}
|
|
61
64
|
>
|
|
62
65
|
<Background
|
|
@@ -72,7 +75,10 @@ export const withEmotion = (Story: any, context: GlobalsContext) => {
|
|
|
72
75
|
|
|
73
76
|
// Wrap all stories in minimal provider
|
|
74
77
|
return (
|
|
75
|
-
<GamutProvider
|
|
78
|
+
<GamutProvider
|
|
79
|
+
useLogicalProperties={useLogicalProperties}
|
|
80
|
+
theme={currentTheme as unknown as Theme}
|
|
81
|
+
>
|
|
76
82
|
<Background
|
|
77
83
|
alwaysSetVariables
|
|
78
84
|
bg={themeBackground[colorMode]}
|
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
### [79.0.1-alpha.
|
|
6
|
+
### [79.0.1-alpha.dfd5fd.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.0.0...@codecademy/styleguide@79.0.1-alpha.dfd5fd.0) (2026-02-11)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @codecademy/styleguide
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/styleguide",
|
|
3
3
|
"description": "Styleguide & Component library for codecademy.com",
|
|
4
|
-
"version": "79.0.1-alpha.
|
|
4
|
+
"version": "79.0.1-alpha.dfd5fd.0",
|
|
5
5
|
"author": "Codecademy Engineering",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"repository": "git@github.com:Codecademy/gamut.git",
|
|
11
|
-
"gitHead": "
|
|
11
|
+
"gitHead": "10ba188d41d93ccb3a07a9ab7569ac5f7341bd4d"
|
|
12
12
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks';
|
|
1
|
+
import { Canvas, Meta } from '@storybook/blocks';
|
|
2
2
|
|
|
3
|
-
import { AboutHeader, TokenTable } from '~styleguide/blocks';
|
|
3
|
+
import { AboutHeader, Callout, TokenTable } from '~styleguide/blocks';
|
|
4
4
|
|
|
5
5
|
import { defaultColumns, getPropRows } from '../../shared/elements';
|
|
6
|
+
import * as BorderStories from './Border.stories';
|
|
6
7
|
|
|
7
8
|
export const parameters = {
|
|
8
9
|
title: 'Border',
|
|
@@ -10,7 +11,7 @@ export const parameters = {
|
|
|
10
11
|
status: 'updating',
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
<Meta title="Foundations/System/Props/Border" />
|
|
14
|
+
<Meta of={BorderStories} title="Foundations/System/Props/Border" />
|
|
14
15
|
|
|
15
16
|
<AboutHeader {...parameters} />
|
|
16
17
|
|
|
@@ -30,4 +31,23 @@ const BorderExample = styled.div(system.border);
|
|
|
30
31
|
/>;
|
|
31
32
|
```
|
|
32
33
|
|
|
34
|
+
These border props support both physical and logical CSS properties and will render the appropriate properties based on `useLogicalProperties`'s value passed into the `<GamutProvider>` at the root of your application.
|
|
35
|
+
|
|
36
|
+
<Callout
|
|
37
|
+
text={
|
|
38
|
+
<>
|
|
39
|
+
You can use the <strong>LogicalProps</strong> button in the toolbar to
|
|
40
|
+
switch between modes.
|
|
41
|
+
</>
|
|
42
|
+
}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
<Canvas of={BorderStories.DirectionalBorderExample} />
|
|
46
|
+
|
|
47
|
+
<Canvas of={BorderStories.BorderWidthExample} />
|
|
48
|
+
|
|
49
|
+
<Canvas of={BorderStories.BorderRadiusExample} />
|
|
50
|
+
|
|
51
|
+
<Canvas of={BorderStories.BorderStyleExample} />
|
|
52
|
+
|
|
33
53
|
<TokenTable rows={getPropRows('border')} columns={defaultColumns} />
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Box, FlexBox, Markdown } from '@codecademy/gamut';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Box> = {
|
|
5
|
+
title: 'Foundations/System/Props/Border',
|
|
6
|
+
component: Box,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj<typeof Box>;
|
|
11
|
+
|
|
12
|
+
export const DirectionalBorderExample: Story = {
|
|
13
|
+
render: () => (
|
|
14
|
+
<FlexBox gap={16} row>
|
|
15
|
+
<Box
|
|
16
|
+
bg="background-selected"
|
|
17
|
+
borderX={2}
|
|
18
|
+
borderY={1}
|
|
19
|
+
p={16}
|
|
20
|
+
textAlign="center"
|
|
21
|
+
>
|
|
22
|
+
This box has <Markdown text="`borderX={2}`, `borderY={1}`." /> Inspect
|
|
23
|
+
the example to see what CSS properties are rendered based on the logical
|
|
24
|
+
properties mode.
|
|
25
|
+
</Box>
|
|
26
|
+
<Box
|
|
27
|
+
bg="background-selected"
|
|
28
|
+
borderLeft={2}
|
|
29
|
+
borderRight={1}
|
|
30
|
+
p={16}
|
|
31
|
+
textAlign="center"
|
|
32
|
+
>
|
|
33
|
+
This box has <Markdown text="`borderLeft={2}`, `borderRight={1}`." />{' '}
|
|
34
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
35
|
+
logical properties mode.
|
|
36
|
+
</Box>
|
|
37
|
+
</FlexBox>
|
|
38
|
+
),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const BorderWidthExample: Story = {
|
|
42
|
+
render: () => (
|
|
43
|
+
<FlexBox gap={16} row>
|
|
44
|
+
<Box
|
|
45
|
+
bg="background-selected"
|
|
46
|
+
border={1}
|
|
47
|
+
borderWidthX="4px"
|
|
48
|
+
borderWidthY="10px"
|
|
49
|
+
p={16}
|
|
50
|
+
textAlign="center"
|
|
51
|
+
>
|
|
52
|
+
This box has{' '}
|
|
53
|
+
<Markdown text="`borderWidthX='4px'` and `borderWidthY='10px'`." />{' '}
|
|
54
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
55
|
+
logical properties mode.
|
|
56
|
+
</Box>
|
|
57
|
+
<Box
|
|
58
|
+
bg="background-selected"
|
|
59
|
+
border={1}
|
|
60
|
+
borderWidthRight="10px"
|
|
61
|
+
borderWidthTop="4px"
|
|
62
|
+
p={16}
|
|
63
|
+
textAlign="center"
|
|
64
|
+
>
|
|
65
|
+
This box has{' '}
|
|
66
|
+
<Markdown text="`borderWidthTop='4px'` and `borderWidthRight='10px'`." />{' '}
|
|
67
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
68
|
+
logical properties mode.
|
|
69
|
+
</Box>
|
|
70
|
+
</FlexBox>
|
|
71
|
+
),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const BorderRadiusExample: Story = {
|
|
75
|
+
render: () => (
|
|
76
|
+
<FlexBox gap={16} row>
|
|
77
|
+
<Box
|
|
78
|
+
bg="background-selected"
|
|
79
|
+
border={1}
|
|
80
|
+
borderRadiusLeft="lg"
|
|
81
|
+
borderRadiusRight="none"
|
|
82
|
+
p={16}
|
|
83
|
+
textAlign="center"
|
|
84
|
+
>
|
|
85
|
+
This box has{' '}
|
|
86
|
+
<Markdown text="`borderRadiusLeft='lg'` and `borderRadiusRight='none'`." />{' '}
|
|
87
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
88
|
+
logical properties mode.
|
|
89
|
+
</Box>
|
|
90
|
+
<Box
|
|
91
|
+
bg="background-selected"
|
|
92
|
+
border={1}
|
|
93
|
+
borderRadiusBottomLeft="xl"
|
|
94
|
+
borderRadiusTopRight="xl"
|
|
95
|
+
p={16}
|
|
96
|
+
textAlign="center"
|
|
97
|
+
>
|
|
98
|
+
This box has{' '}
|
|
99
|
+
<Markdown text="`borderRadiusTopRight='xl'` and `borderRadiusBottomLeft='xl'`." />{' '}
|
|
100
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
101
|
+
logical properties mode.
|
|
102
|
+
</Box>
|
|
103
|
+
</FlexBox>
|
|
104
|
+
),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const BorderStyleExample: Story = {
|
|
108
|
+
render: () => (
|
|
109
|
+
<FlexBox gap={16} row>
|
|
110
|
+
<Box
|
|
111
|
+
bg="background-selected"
|
|
112
|
+
border={1}
|
|
113
|
+
borderStyleX="dashed"
|
|
114
|
+
borderStyleY="dotted"
|
|
115
|
+
p={16}
|
|
116
|
+
textAlign="center"
|
|
117
|
+
>
|
|
118
|
+
This box has{' '}
|
|
119
|
+
<Markdown text="`borderStyleX='dashed'` and `borderStyleY='dotted'`." />{' '}
|
|
120
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
121
|
+
logical properties mode.
|
|
122
|
+
</Box>
|
|
123
|
+
<Box
|
|
124
|
+
bg="background-selected"
|
|
125
|
+
border={1}
|
|
126
|
+
borderStyleBottom="dotted"
|
|
127
|
+
borderStyleLeft="dashed"
|
|
128
|
+
p={16}
|
|
129
|
+
textAlign="center"
|
|
130
|
+
>
|
|
131
|
+
This box has{' '}
|
|
132
|
+
<Markdown text="`borderStyleBottom='dotted'` and `borderStyleLeft='dashed'`." />{' '}
|
|
133
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
134
|
+
logical properties mode.
|
|
135
|
+
</Box>
|
|
136
|
+
</FlexBox>
|
|
137
|
+
),
|
|
138
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks';
|
|
1
|
+
import { Canvas, Meta } from '@storybook/blocks';
|
|
2
2
|
|
|
3
|
-
import { AboutHeader, TokenTable } from '~styleguide/blocks';
|
|
3
|
+
import { AboutHeader, Callout, TokenTable } from '~styleguide/blocks';
|
|
4
4
|
|
|
5
5
|
import { defaultColumns, getPropRows } from '../../shared/elements';
|
|
6
|
+
import * as ColorStories from './Color.stories';
|
|
6
7
|
|
|
7
8
|
export const parameters = {
|
|
8
9
|
title: 'Color',
|
|
@@ -10,7 +11,7 @@ export const parameters = {
|
|
|
10
11
|
status: 'current',
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
<Meta title="Foundations/System/Props/Color" />
|
|
14
|
+
<Meta of={ColorStories} title="Foundations/System/Props/Color" />
|
|
14
15
|
|
|
15
16
|
<AboutHeader {...parameters} />
|
|
16
17
|
|
|
@@ -25,4 +26,17 @@ const ColorExample = styled.div(system.color);
|
|
|
25
26
|
<ColorExample bg="navy" textColor="gray-100" borderColor="blue" />;
|
|
26
27
|
```
|
|
27
28
|
|
|
29
|
+
These color props support both physical and logical CSS properties and will render the appropriate properties based on `useLogicalProperties`'s value passed into the `<GamutProvider>` at the root of your application.
|
|
30
|
+
|
|
31
|
+
<Callout
|
|
32
|
+
text={
|
|
33
|
+
<>
|
|
34
|
+
You can use the <strong>LogicalProps</strong> button in the toolbar to
|
|
35
|
+
switch between modes.
|
|
36
|
+
</>
|
|
37
|
+
}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<Canvas of={ColorStories.BorderColorExample} />
|
|
41
|
+
|
|
28
42
|
<TokenTable rows={getPropRows('color')} columns={defaultColumns} />
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Box, FlexBox, Markdown } from '@codecademy/gamut';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Box> = {
|
|
5
|
+
title: 'Foundations/System/Props/Color',
|
|
6
|
+
component: Box,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj<typeof Box>;
|
|
11
|
+
|
|
12
|
+
export const BorderColorExample: Story = {
|
|
13
|
+
render: () => (
|
|
14
|
+
<FlexBox gap={16} row>
|
|
15
|
+
<Box
|
|
16
|
+
bg="background-selected"
|
|
17
|
+
border={1}
|
|
18
|
+
borderColorX="feedback-success"
|
|
19
|
+
borderColorY="feedback-error"
|
|
20
|
+
borderWidth="4px"
|
|
21
|
+
p={16}
|
|
22
|
+
textAlign="center"
|
|
23
|
+
>
|
|
24
|
+
This box has{' '}
|
|
25
|
+
<Markdown text="`borderColorX='feedback-success'` and `borderColorY='feedback-error'`." />{' '}
|
|
26
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
27
|
+
logical properties mode.
|
|
28
|
+
</Box>
|
|
29
|
+
<Box
|
|
30
|
+
bg="background-selected"
|
|
31
|
+
border={1}
|
|
32
|
+
borderColorBottom="feedback-warning"
|
|
33
|
+
borderColorLeft="feedback-success"
|
|
34
|
+
borderColorRight="feedback-error"
|
|
35
|
+
borderColorTop="interface"
|
|
36
|
+
borderWidth="4px"
|
|
37
|
+
p={16}
|
|
38
|
+
textAlign="center"
|
|
39
|
+
>
|
|
40
|
+
This box has{' '}
|
|
41
|
+
<Markdown text="`borderColorBottom='feedback-warning'`, `borderColorLeft='feedback-success'`, `borderColorRight='feedback-error'`, and `borderColorTop='interface'`." />{' '}
|
|
42
|
+
Inspect the example to see what CSS properties are rendered based on the
|
|
43
|
+
logical properties mode.
|
|
44
|
+
</Box>
|
|
45
|
+
</FlexBox>
|
|
46
|
+
),
|
|
47
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks';
|
|
1
|
+
import { Canvas, Meta } from '@storybook/blocks';
|
|
2
2
|
|
|
3
|
-
import { AboutHeader, TokenTable } from '~styleguide/blocks';
|
|
3
|
+
import { AboutHeader, Callout, TokenTable } from '~styleguide/blocks';
|
|
4
4
|
|
|
5
5
|
import { defaultColumns, getPropRows } from '../../shared/elements';
|
|
6
|
+
import * as SpaceStories from './Space.stories';
|
|
6
7
|
|
|
7
8
|
export const parameters = {
|
|
8
9
|
title: 'Space',
|
|
@@ -10,7 +11,7 @@ export const parameters = {
|
|
|
10
11
|
status: 'updating',
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
<Meta title="Foundations/System/Props/Space" />
|
|
14
|
+
<Meta of={SpaceStories} title="Foundations/System/Props/Space" />
|
|
14
15
|
|
|
15
16
|
<AboutHeader {...parameters} />
|
|
16
17
|
|
|
@@ -25,4 +26,19 @@ const SpaceExample = styled.div(system.space);
|
|
|
25
26
|
<SpaceExample p={8} my={[16, 24, 32]} />;
|
|
26
27
|
```
|
|
27
28
|
|
|
29
|
+
These space props support both physical and logical CSS properties and will render the appropriate properties based on `useLogicalProperties`'s value passed into the `<GamutProvider>` at the root of your application.
|
|
30
|
+
|
|
31
|
+
<Callout
|
|
32
|
+
text={
|
|
33
|
+
<>
|
|
34
|
+
You can use the <strong>LogicalProps</strong> button in the toolbar to
|
|
35
|
+
switch between modes.
|
|
36
|
+
</>
|
|
37
|
+
}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<Canvas of={SpaceStories.MarginExample} />
|
|
41
|
+
|
|
42
|
+
<Canvas of={SpaceStories.PaddingExample} />
|
|
43
|
+
|
|
28
44
|
<TokenTable rows={getPropRows('space')} columns={defaultColumns} />
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Box, Markdown } from '@codecademy/gamut';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Box> = {
|
|
5
|
+
title: 'Foundations/System/Props/Space',
|
|
6
|
+
component: Box,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj<typeof Box>;
|
|
11
|
+
|
|
12
|
+
export const MarginExample: Story = {
|
|
13
|
+
render: () => (
|
|
14
|
+
<Box
|
|
15
|
+
bg="primary"
|
|
16
|
+
color="background-contrast"
|
|
17
|
+
mb={64}
|
|
18
|
+
ml={16}
|
|
19
|
+
mr={32}
|
|
20
|
+
mt={4}
|
|
21
|
+
textAlign="center"
|
|
22
|
+
>
|
|
23
|
+
This box has{' '}
|
|
24
|
+
<Markdown text="`mt={4}`, `mr={32}`, `mb={64}`, and `ml={16}`." /> Inspect
|
|
25
|
+
the example to see what CSS properties are rendered.
|
|
26
|
+
</Box>
|
|
27
|
+
),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const PaddingExample: Story = {
|
|
31
|
+
render: () => (
|
|
32
|
+
<Box bg="background-selected">
|
|
33
|
+
<Box
|
|
34
|
+
bg="primary"
|
|
35
|
+
color="background-contrast"
|
|
36
|
+
pb={64}
|
|
37
|
+
pl={16}
|
|
38
|
+
pr={32}
|
|
39
|
+
pt={4}
|
|
40
|
+
textAlign="center"
|
|
41
|
+
>
|
|
42
|
+
This box has{' '}
|
|
43
|
+
<Markdown text="`pt={4}`, `pr={32}`, `pb={64}`, and `pl={16}`." />{' '}
|
|
44
|
+
Inspect the example to see what CSS properties are rendered.
|
|
45
|
+
</Box>
|
|
46
|
+
</Box>
|
|
47
|
+
),
|
|
48
|
+
};
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '@codecademy/gamut-styles';
|
|
10
10
|
// eslint-disable-next-line gamut/import-paths
|
|
11
11
|
import * as ALL_PROPS from '@codecademy/gamut-styles/src/variance/config';
|
|
12
|
+
import { useTheme } from '@emotion/react';
|
|
12
13
|
import styled from '@emotion/styled';
|
|
13
14
|
import kebabCase from 'lodash/kebabCase';
|
|
14
15
|
|
|
@@ -412,29 +413,61 @@ export const DarkModeTable = () => (
|
|
|
412
413
|
);
|
|
413
414
|
/* eslint-disable gamut/import-paths */
|
|
414
415
|
|
|
416
|
+
const PropertiesRenderer = ({
|
|
417
|
+
property,
|
|
418
|
+
properties,
|
|
419
|
+
resolveProperty,
|
|
420
|
+
}: {
|
|
421
|
+
property: string | { physical: string; logical: string };
|
|
422
|
+
properties?: string[] | { physical: string[]; logical: string[] };
|
|
423
|
+
resolveProperty?: (useLogicalProperties: boolean) => 'logical' | 'physical';
|
|
424
|
+
}) => {
|
|
425
|
+
const currentTheme = useTheme() as { useLogicalProperties?: boolean };
|
|
426
|
+
const useLogicalProperties = currentTheme?.useLogicalProperties ?? true;
|
|
427
|
+
|
|
428
|
+
const mode = resolveProperty
|
|
429
|
+
? resolveProperty(useLogicalProperties)
|
|
430
|
+
: 'physical';
|
|
431
|
+
|
|
432
|
+
const resolvedProperty =
|
|
433
|
+
typeof property === 'string' ? property : property[mode];
|
|
434
|
+
|
|
435
|
+
let resolvedProperties: string[];
|
|
436
|
+
if (!properties) {
|
|
437
|
+
resolvedProperties = [resolvedProperty];
|
|
438
|
+
} else if (Array.isArray(properties)) {
|
|
439
|
+
resolvedProperties = properties;
|
|
440
|
+
} else {
|
|
441
|
+
resolvedProperties = properties[mode];
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return (
|
|
445
|
+
<>
|
|
446
|
+
{resolvedProperties.map((prop) => (
|
|
447
|
+
<Anchor
|
|
448
|
+
href={`https://developer.mozilla.org/en-US/docs/Web/CSS/${kebabCase(
|
|
449
|
+
prop
|
|
450
|
+
)}`}
|
|
451
|
+
key={prop}
|
|
452
|
+
rel=""
|
|
453
|
+
target="_blank"
|
|
454
|
+
>
|
|
455
|
+
<AnchorCode>{kebabCase(prop)}</AnchorCode>
|
|
456
|
+
</Anchor>
|
|
457
|
+
))}
|
|
458
|
+
</>
|
|
459
|
+
);
|
|
460
|
+
};
|
|
461
|
+
|
|
415
462
|
const PROPERTIES_COLUMN = {
|
|
416
463
|
key: 'properties',
|
|
417
464
|
name: 'Properties',
|
|
418
465
|
size: 'xl',
|
|
419
|
-
render: ({
|
|
420
|
-
property
|
|
421
|
-
properties
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
properties: string[];
|
|
425
|
-
}) =>
|
|
426
|
-
properties.map((property) => (
|
|
427
|
-
<Anchor
|
|
428
|
-
href={`https://developer.mozilla.org/en-US/docs/Web/CSS/${kebabCase(
|
|
429
|
-
property
|
|
430
|
-
)}`}
|
|
431
|
-
key={property}
|
|
432
|
-
rel=""
|
|
433
|
-
target="_blank"
|
|
434
|
-
>
|
|
435
|
-
<AnchorCode>{kebabCase(property)}</AnchorCode>
|
|
436
|
-
</Anchor>
|
|
437
|
-
)),
|
|
466
|
+
render: (props: {
|
|
467
|
+
property: string | { physical: string; logical: string };
|
|
468
|
+
properties?: string[] | { physical: string[]; logical: string[] };
|
|
469
|
+
resolveProperty?: (useLogicalProperties: boolean) => 'logical' | 'physical';
|
|
470
|
+
}) => <PropertiesRenderer {...props} />,
|
|
438
471
|
};
|
|
439
472
|
|
|
440
473
|
const SCALE_COLUMN = {
|
|
@@ -450,7 +483,12 @@ const TRANSFORM_COLUMN = {
|
|
|
450
483
|
key: 'transform',
|
|
451
484
|
name: 'Transform',
|
|
452
485
|
size: 'fill',
|
|
453
|
-
render: ({ transform }: any) =>
|
|
486
|
+
render: ({ transform, resolveProperty }: any) => (
|
|
487
|
+
<>
|
|
488
|
+
{transform && <Code>{transform?.name}</Code>}
|
|
489
|
+
{resolveProperty && <Code>{resolveProperty?.name}</Code>}
|
|
490
|
+
</>
|
|
491
|
+
),
|
|
454
492
|
};
|
|
455
493
|
|
|
456
494
|
export const defaultColumns = [
|
package/src/lib/Meta/About.mdx
CHANGED
|
@@ -13,6 +13,7 @@ import { parameters as deepControlsParameters } from './Deep Controls Add-On.mdx
|
|
|
13
13
|
import { parameters as eslintRulesParameters } from './ESLint rules.mdx';
|
|
14
14
|
import { parameters as faqsParameters } from './FAQs.mdx';
|
|
15
15
|
import { parameters as installationParameters } from './Installation.mdx';
|
|
16
|
+
import { parameters as logicalPhysicalParameters } from './Logical and physical CSS properties.mdx';
|
|
16
17
|
import { parameters as storiesParameters } from './Stories.mdx';
|
|
17
18
|
import { parameters as usageGuideParameters } from './Usage Guide.mdx';
|
|
18
19
|
|
|
@@ -34,9 +35,10 @@ export const parameters = {
|
|
|
34
35
|
deepControlsParameters,
|
|
35
36
|
eslintRulesParameters,
|
|
36
37
|
faqsParameters,
|
|
38
|
+
installationParameters,
|
|
39
|
+
logicalPhysicalParameters,
|
|
37
40
|
storiesParameters,
|
|
38
41
|
brandParameters,
|
|
39
|
-
installationParameters,
|
|
40
42
|
usageGuideParameters,
|
|
41
43
|
])}
|
|
42
44
|
/>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AboutHeader,
|
|
5
|
+
Callout,
|
|
6
|
+
Code,
|
|
7
|
+
ImageWrapper,
|
|
8
|
+
TokenTable,
|
|
9
|
+
} from '~styleguide/blocks';
|
|
10
|
+
|
|
11
|
+
export const parameters = {
|
|
12
|
+
id: 'Meta/Logical and physical CSS properties',
|
|
13
|
+
title: 'Logical and physical CSS properties',
|
|
14
|
+
subtitle:
|
|
15
|
+
'Understanding CSS logical and physical properties and how Gamut supports both modes.',
|
|
16
|
+
status: 'static',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
<Meta title="Meta/Logical and physical CSS properties" />
|
|
20
|
+
|
|
21
|
+
<AboutHeader {...parameters} />
|
|
22
|
+
|
|
23
|
+
## What are CSS logical properties?
|
|
24
|
+
|
|
25
|
+
CSS logical properties are a modern approach to styling that adapts to the writing mode and text direction of your content, rather than being tied to physical screen directions. More information can be found on[MDN: CSS Logical Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
|
|
26
|
+
|
|
27
|
+
### Physical Properties (Traditional)
|
|
28
|
+
|
|
29
|
+
Physical properties reference the physical dimensions of the viewport. For example:
|
|
30
|
+
|
|
31
|
+
- `margin-left`, `margin-right`, `margin-top`, `margin-bottom`
|
|
32
|
+
- `padding-left`, `padding-right`, `padding-top`, `padding-bottom`
|
|
33
|
+
|
|
34
|
+
These work well for left-to-right (LTR) languages but require manual overrides for right-to-left (RTL) languages like Arabic or Hebrew.
|
|
35
|
+
|
|
36
|
+
### Logical Properties (Modern)
|
|
37
|
+
|
|
38
|
+
Logical properties reference the flow of content:
|
|
39
|
+
|
|
40
|
+
- **Inline axis** (text direction): `margin-inline-start`, `margin-inline-end`
|
|
41
|
+
- **Block axis** (reading direction): `margin-block-start`, `margin-block-end`
|
|
42
|
+
|
|
43
|
+
## Using `useLogicalProperties` in Gamut
|
|
44
|
+
|
|
45
|
+
Gamut supports both physical and logical CSS properties through the `useLogicalProperties` prop on `GamutProvider`. This allows you to choose which mode your application uses. By default, `useLogicalProperties` is set to `true`, meaning Gamut will use logical CSS properties. If you want to use physical CSS properties, you have to set `useLogicalProperties` to `false`.
|
|
46
|
+
|
|
47
|
+
### Affected Props
|
|
48
|
+
|
|
49
|
+
Here are some examples of how physical and logical properties are affected by the `useLogicalProperties` prop:
|
|
50
|
+
|
|
51
|
+
<TokenTable
|
|
52
|
+
idKey="prop"
|
|
53
|
+
columns={[
|
|
54
|
+
{
|
|
55
|
+
key: 'prop',
|
|
56
|
+
name: 'Prop',
|
|
57
|
+
size: 'sm',
|
|
58
|
+
render: ({ prop }) => <Code>{prop}</Code>,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: 'physical',
|
|
62
|
+
name: 'Physical',
|
|
63
|
+
size: 'xl',
|
|
64
|
+
render: ({ physical }) =>
|
|
65
|
+
physical.map((p) => (
|
|
66
|
+
<>
|
|
67
|
+
<Code key={p}>{p}</Code>{' '}
|
|
68
|
+
</>
|
|
69
|
+
)),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
key: 'logical',
|
|
73
|
+
name: 'Logical',
|
|
74
|
+
size: 'xl',
|
|
75
|
+
render: ({ logical }) =>
|
|
76
|
+
logical.map((l) => (
|
|
77
|
+
<>
|
|
78
|
+
<Code key={l}>{l}</Code>{' '}
|
|
79
|
+
</>
|
|
80
|
+
)),
|
|
81
|
+
},
|
|
82
|
+
]}
|
|
83
|
+
rows={[
|
|
84
|
+
{
|
|
85
|
+
prop: 'mx',
|
|
86
|
+
physical: ['margin-left', 'margin-right'],
|
|
87
|
+
logical: ['margin-inline-start', 'margin-inline-end'],
|
|
88
|
+
},
|
|
89
|
+
{ prop: 'mt', physical: ['margin-top'], logical: ['margin-block-start'] },
|
|
90
|
+
{
|
|
91
|
+
prop: 'py',
|
|
92
|
+
physical: ['padding-top', 'padding-bottom'],
|
|
93
|
+
logical: ['padding-block-start', 'padding-block-end'],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
prop: 'pb',
|
|
97
|
+
physical: ['padding-bottom'],
|
|
98
|
+
logical: ['padding-block-end'],
|
|
99
|
+
},
|
|
100
|
+
]}
|
|
101
|
+
/>
|
|
102
|
+
|
|
103
|
+
<Callout
|
|
104
|
+
text={
|
|
105
|
+
<>
|
|
106
|
+
Props like <code>m</code> and <code>p</code> (which set all four sides at
|
|
107
|
+
once) are not affected by this setting, as the CSS <code>margin</code> and{' '}
|
|
108
|
+
<code>padding</code> shorthands work identically in both modes.
|
|
109
|
+
</>
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
|
|
113
|
+
## Previewing in Storybook
|
|
114
|
+
|
|
115
|
+
You can toggle between logical and physical properties in Storybook using the **LogicalProps** toolbar button:
|
|
116
|
+
|
|
117
|
+
<ImageWrapper
|
|
118
|
+
src="./meta/toolbar.png"
|
|
119
|
+
alt="The Storybook toolbar with the LogicalProps toggle highlighted."
|
|
120
|
+
height="auto"
|
|
121
|
+
/>
|
|
122
|
+
|
|
123
|
+
This allows you to preview how components render with either property mode without changing any code.
|
|
@@ -39,7 +39,8 @@ On each page is a toolbar located on the top:
|
|
|
39
39
|
1. Grid (the 2x2 collection of squares) - applies a grid to the preview
|
|
40
40
|
2. Color mode selector (the circle icon) - toggles between light and dark mode for rendered code examples
|
|
41
41
|
3. Theme switcher (the paintbrush icon) - switches between different design system themes (Core, Admin, LX Studio, Percipio)
|
|
42
|
-
4.
|
|
42
|
+
4. LogicalProps (the two arrows icon) - toggles between physical and logical CSS properties
|
|
43
|
+
5. Outline (dotted square) - applies outlines to elements in the rendered code examples
|
|
43
44
|
|
|
44
45
|
### Theme Switcher
|
|
45
46
|
|
|
@@ -58,6 +59,10 @@ Available themes:
|
|
|
58
59
|
|
|
59
60
|
The theme switcher works in combination with the color mode selector, so you can test both light and dark variants of each theme.
|
|
60
61
|
|
|
62
|
+
### LogicalProps
|
|
63
|
+
|
|
64
|
+
The LogicalProps button (two arrows icon) provides a menu to select between Logical and Physical CSS properties.
|
|
65
|
+
|
|
61
66
|
### Showing code
|
|
62
67
|
|
|
63
68
|
On the bottom right of each canvas (a rendered code example) is a button to show its code:
|
|
Binary file
|