@codecademy/styleguide 79.0.1-alpha.2b3284.0 → 79.0.1-alpha.d8b528.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/components/Elements/Markdown.tsx +0 -1
- 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/About.mdx +1 -1
- package/src/lib/Foundations/System/Props/About.mdx +81 -0
- package/src/lib/Foundations/System/Props/Background.mdx +30 -0
- package/src/lib/Foundations/System/Props/Border.mdx +33 -0
- package/src/lib/Foundations/System/Props/Color.mdx +28 -0
- package/src/lib/Foundations/System/Props/Flex.mdx +28 -0
- package/src/lib/Foundations/System/Props/Grid.mdx +31 -0
- package/src/lib/Foundations/System/Props/Layout.mdx +34 -0
- package/src/lib/Foundations/System/Props/List.mdx +38 -0
- package/src/lib/Foundations/System/Props/Positioning.mdx +29 -0
- package/src/lib/Foundations/System/Props/Shadow.mdx +31 -0
- package/src/lib/Foundations/System/Props/Space.mdx +44 -0
- package/src/lib/Foundations/System/Props/Space.stories.tsx +48 -0
- package/src/lib/Foundations/System/Props/Typography.mdx +28 -0
- package/src/lib/Foundations/System/ResponsiveProperties/ResponsiveProperties.mdx +3 -3
- package/src/lib/Foundations/System/ResponsiveProperties/ResponsiveProperties.stories.tsx +1 -0
- package/src/lib/Foundations/shared/elements.tsx +69 -19
- 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/lib/Molecules/Popover/Popover.stories.tsx +4 -127
- package/src/static/meta/toolbar.png +0 -0
- package/src/lib/Foundations/System/Props.mdx +0 -230
|
@@ -2,22 +2,32 @@ import { Anchor, Box } from '@codecademy/gamut';
|
|
|
2
2
|
import {
|
|
3
3
|
Background,
|
|
4
4
|
coreSwatches,
|
|
5
|
+
css,
|
|
5
6
|
lxStudioColors,
|
|
6
7
|
theme,
|
|
7
8
|
trueColors,
|
|
8
9
|
} from '@codecademy/gamut-styles';
|
|
9
10
|
// eslint-disable-next-line gamut/import-paths
|
|
10
11
|
import * as ALL_PROPS from '@codecademy/gamut-styles/src/variance/config';
|
|
12
|
+
import { useTheme } from '@emotion/react';
|
|
13
|
+
import styled from '@emotion/styled';
|
|
11
14
|
import kebabCase from 'lodash/kebabCase';
|
|
12
15
|
|
|
13
16
|
import { Code, ColorScale, LinkTo, TokenTable } from '~styleguide/blocks';
|
|
14
17
|
|
|
15
18
|
import { applyCorrectNotation } from './applyCorrectNotation';
|
|
16
19
|
|
|
20
|
+
const AnchorCode = styled(Code)(
|
|
21
|
+
css({
|
|
22
|
+
textDecoration: 'underline',
|
|
23
|
+
mx: 4,
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
|
|
17
27
|
export const PROP_COLUMN = {
|
|
18
28
|
key: 'key',
|
|
19
29
|
name: 'Prop',
|
|
20
|
-
size: '
|
|
30
|
+
size: 'lg',
|
|
21
31
|
render: ({ id }: any) => <Code>{id}</Code>,
|
|
22
32
|
};
|
|
23
33
|
|
|
@@ -403,26 +413,61 @@ export const DarkModeTable = () => (
|
|
|
403
413
|
);
|
|
404
414
|
/* eslint-disable gamut/import-paths */
|
|
405
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
|
+
|
|
406
462
|
const PROPERTIES_COLUMN = {
|
|
407
463
|
key: 'properties',
|
|
408
464
|
name: 'Properties',
|
|
409
465
|
size: 'xl',
|
|
410
|
-
render: ({
|
|
411
|
-
property
|
|
412
|
-
properties
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
properties: string[];
|
|
416
|
-
}) =>
|
|
417
|
-
properties.map((property) => (
|
|
418
|
-
<Anchor
|
|
419
|
-
href={`https://developer.mozilla.org/en-US/docs/Web/CSS/${property}`}
|
|
420
|
-
rel=""
|
|
421
|
-
target="_blank"
|
|
422
|
-
>
|
|
423
|
-
<Code key={property}>{kebabCase(property)}</Code>
|
|
424
|
-
</Anchor>
|
|
425
|
-
)),
|
|
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} />,
|
|
426
471
|
};
|
|
427
472
|
|
|
428
473
|
const SCALE_COLUMN = {
|
|
@@ -430,7 +475,7 @@ const SCALE_COLUMN = {
|
|
|
430
475
|
name: 'Scale',
|
|
431
476
|
size: 'lg',
|
|
432
477
|
render: ({ scale }: { scale: string }) => (
|
|
433
|
-
<LinkTo id=
|
|
478
|
+
<LinkTo id="Foundations/Theme/Core Theme">{scale}</LinkTo>
|
|
434
479
|
),
|
|
435
480
|
};
|
|
436
481
|
|
|
@@ -438,7 +483,12 @@ const TRANSFORM_COLUMN = {
|
|
|
438
483
|
key: 'transform',
|
|
439
484
|
name: 'Transform',
|
|
440
485
|
size: 'fill',
|
|
441
|
-
render: ({ transform }: any) =>
|
|
486
|
+
render: ({ transform, resolveProperty }: any) => (
|
|
487
|
+
<>
|
|
488
|
+
{transform && <Code>{transform?.name}</Code>}
|
|
489
|
+
{resolveProperty && <Code>{resolveProperty?.name}</Code>}
|
|
490
|
+
</>
|
|
491
|
+
),
|
|
442
492
|
};
|
|
443
493
|
|
|
444
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:
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '@codecademy/gamut';
|
|
9
9
|
import * as patterns from '@codecademy/gamut-patterns';
|
|
10
10
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
11
|
-
import {
|
|
11
|
+
import { useRef, useState } from 'react';
|
|
12
12
|
|
|
13
13
|
const meta: Meta<typeof Popover> = {
|
|
14
14
|
component: Popover,
|
|
@@ -27,91 +27,10 @@ type Story = StoryObj<typeof Popover>;
|
|
|
27
27
|
|
|
28
28
|
type PopoverExampleProps = PopoverProps & Pick<FlexBoxProps, 'p'>;
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
const VIEWPORT_PADDING = 16; // Padding from viewport edge
|
|
32
|
-
|
|
33
|
-
const PopoverExample = ({
|
|
34
|
-
p = 16,
|
|
35
|
-
position: preferredPosition = 'below',
|
|
36
|
-
...rest
|
|
37
|
-
}: PopoverExampleProps) => {
|
|
30
|
+
const PopoverExample = ({ p = 16, ...rest }: PopoverExampleProps) => {
|
|
38
31
|
const [open, setOpen] = useState(false);
|
|
39
|
-
const [computedPosition, setComputedPosition] = useState<
|
|
40
|
-
'above' | 'below' | 'center'
|
|
41
|
-
>(preferredPosition === 'center' ? 'center' : preferredPosition);
|
|
42
|
-
const [availableHeight, setAvailableHeight] = useState<number | undefined>(
|
|
43
|
-
undefined
|
|
44
|
-
);
|
|
45
32
|
const activeElRef = useRef<HTMLDivElement>(null);
|
|
46
|
-
const popoverRef = useRef<HTMLDivElement>(null);
|
|
47
|
-
const [popoverHeight, setPopoverHeight] = useState(POPOVER_HEIGHT_ESTIMATE);
|
|
48
|
-
|
|
49
|
-
const calculatePosition = useCallback(() => {
|
|
50
|
-
const target = activeElRef.current;
|
|
51
|
-
if (!target || preferredPosition === 'center') return;
|
|
52
|
-
|
|
53
|
-
const targetRect = target.getBoundingClientRect();
|
|
54
|
-
const viewportHeight = window.innerHeight;
|
|
55
|
-
|
|
56
|
-
const spaceBelow = viewportHeight - targetRect.bottom - VIEWPORT_PADDING;
|
|
57
|
-
const spaceAbove = targetRect.top - VIEWPORT_PADDING;
|
|
58
|
-
|
|
59
|
-
// Use measured height if available, otherwise estimate
|
|
60
|
-
const heightToFit = popoverHeight;
|
|
61
|
-
|
|
62
|
-
let newPosition: 'above' | 'below' =
|
|
63
|
-
preferredPosition === 'above' ? 'above' : 'below';
|
|
64
|
-
|
|
65
|
-
if (preferredPosition === 'below') {
|
|
66
|
-
// Prefer below, but flip to above if not enough space below and more space above
|
|
67
|
-
if (spaceBelow < heightToFit && spaceAbove > spaceBelow) {
|
|
68
|
-
newPosition = 'above';
|
|
69
|
-
} else {
|
|
70
|
-
newPosition = 'below';
|
|
71
|
-
}
|
|
72
|
-
} else if (preferredPosition === 'above') {
|
|
73
|
-
// Prefer above, but flip to below if not enough space above and more space below
|
|
74
|
-
if (spaceAbove < heightToFit && spaceBelow > spaceAbove) {
|
|
75
|
-
newPosition = 'below';
|
|
76
|
-
} else {
|
|
77
|
-
newPosition = 'above';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setComputedPosition(newPosition);
|
|
82
|
-
|
|
83
|
-
// Set max height based on the available space in the computed direction
|
|
84
|
-
const maxAvailableHeight = newPosition === 'below' ? spaceBelow : spaceAbove;
|
|
85
|
-
setAvailableHeight(Math.max(maxAvailableHeight, 100)); // Minimum 100px
|
|
86
|
-
}, [preferredPosition, popoverHeight]);
|
|
87
|
-
|
|
88
|
-
// Measure popover height when it opens
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
if (open && popoverRef.current) {
|
|
91
|
-
const { height } = popoverRef.current.getBoundingClientRect();
|
|
92
|
-
if (height > 0) {
|
|
93
|
-
setPopoverHeight(height);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, [open]);
|
|
97
|
-
|
|
98
|
-
// Recalculate position on open, scroll, or resize
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
if (!open) return;
|
|
101
|
-
|
|
102
|
-
calculatePosition();
|
|
103
|
-
|
|
104
|
-
window.addEventListener('scroll', calculatePosition, true);
|
|
105
|
-
window.addEventListener('resize', calculatePosition);
|
|
106
|
-
|
|
107
|
-
return () => {
|
|
108
|
-
window.removeEventListener('scroll', calculatePosition, true);
|
|
109
|
-
window.removeEventListener('resize', calculatePosition);
|
|
110
|
-
};
|
|
111
|
-
}, [open, calculatePosition]);
|
|
112
|
-
|
|
113
33
|
const toggleOpen = () => setOpen(!open);
|
|
114
|
-
|
|
115
34
|
return (
|
|
116
35
|
<>
|
|
117
36
|
<Box ref={activeElRef} width="fit-content">
|
|
@@ -121,53 +40,11 @@ const PopoverExample = ({
|
|
|
121
40
|
<Popover
|
|
122
41
|
{...(rest as any)}
|
|
123
42
|
isOpen={open}
|
|
124
|
-
popoverContainerRef={popoverRef}
|
|
125
|
-
position={computedPosition}
|
|
126
43
|
targetRef={activeElRef}
|
|
127
44
|
onRequestClose={() => setOpen(false)}
|
|
128
45
|
>
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
This makes the popover contents scrollable when they exceed
|
|
132
|
-
the available viewport space.
|
|
133
|
-
*/}
|
|
134
|
-
<FlexBox
|
|
135
|
-
alignItems="flex-start"
|
|
136
|
-
flexDirection="column"
|
|
137
|
-
p={p}
|
|
138
|
-
maxHeight={availableHeight ? `${availableHeight}px` as any : undefined}
|
|
139
|
-
overflowY="auto"
|
|
140
|
-
>
|
|
141
|
-
<Box mb={8}>
|
|
142
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
143
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
144
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
145
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
146
|
-
</Box>
|
|
147
|
-
<Box mb={8}>
|
|
148
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
149
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
150
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
151
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
152
|
-
</Box>
|
|
153
|
-
<Box mb={8}>
|
|
154
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
155
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
156
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
157
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
158
|
-
</Box>
|
|
159
|
-
<Box mb={8}>
|
|
160
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
161
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
162
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
163
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
164
|
-
</Box>
|
|
165
|
-
<Box mb={8} opacity={0.7}>
|
|
166
|
-
Position: {computedPosition}
|
|
167
|
-
{computedPosition !== preferredPosition && ' (flipped!)'}
|
|
168
|
-
{' | '}
|
|
169
|
-
Max height: {availableHeight ? `${Math.round(availableHeight)}px` : 'auto'}
|
|
170
|
-
</Box>
|
|
46
|
+
<FlexBox alignItems="flex-start" flexDirection="column" p={p}>
|
|
47
|
+
<Box mb={8}>Hooray!</Box>
|
|
171
48
|
<FillButton size="small" onClick={() => setOpen(false)}>
|
|
172
49
|
Close Popover
|
|
173
50
|
</FillButton>
|
|
Binary file
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks';
|
|
2
|
-
|
|
3
|
-
import { AboutHeader, TokenTable } from '~styleguide/blocks';
|
|
4
|
-
|
|
5
|
-
import { defaultColumns, getPropRows } from '../shared/elements';
|
|
6
|
-
|
|
7
|
-
export const parameters = {
|
|
8
|
-
title: 'Props',
|
|
9
|
-
subtitle:
|
|
10
|
-
'Reusable CSS-in-JS props with predictable behaviors and a consistent API for responsive CSS.',
|
|
11
|
-
source: {
|
|
12
|
-
repo: 'gamut-styles',
|
|
13
|
-
githubLink:
|
|
14
|
-
'https://github.com/Codecademy/gamut/blob/af5be6e39cccca5d5d8a1f811c77a7a0b618c914/packages/gamut-styles/src/variance/config.ts#L11',
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
<Meta title="Foundations/System/Props" />
|
|
19
|
-
|
|
20
|
-
<AboutHeader {...parameters} />
|
|
21
|
-
|
|
22
|
-
We provide a set of out of style functions out of the box through `@codecademy/gamut-styles` that are standardized throughout all of our components. These props are strongly typed and can be included as necessary on any styled component.
|
|
23
|
-
|
|
24
|
-
System props have a few facets that are important to note:
|
|
25
|
-
|
|
26
|
-
- They can some times represent multiple properties.
|
|
27
|
-
- They may be restricted to specific token scales but will always have access to global css values like `initial` and `none`.
|
|
28
|
-
- They may have a function that transforms the given value into a standardized value (e.g. `width={.5}` => `width: 50%`)
|
|
29
|
-
|
|
30
|
-
We've grouped these into a few main groups that affect simliar behaviors: `layout`, `space`, `color`, `border`, `background`, `typography`, `positioning`, `grid`, `flex`, `shadow`.
|
|
31
|
-
|
|
32
|
-
You may import these groups directly from `gamut-styles`.
|
|
33
|
-
|
|
34
|
-
```tsx
|
|
35
|
-
import { variance } from '@codecademy/variance';
|
|
36
|
-
import { system } from '@codecademy/gamut-styles';
|
|
37
|
-
|
|
38
|
-
const Box = styled.div(variance.compose(system.layout, system.positioning));
|
|
39
|
-
|
|
40
|
-
<Box position="absolute" width="50px" height="50px" />;
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Each system prop has 3 important features:
|
|
44
|
-
|
|
45
|
-
- `properties`: Any number of CSS Properties this prop is responsible for.
|
|
46
|
-
- `scale`: A set of values that determines valid inputs for each prop (e.g. a scale of `colors` will restrict to only theme colors). These are generally aliases for more verbose or opaque css properties allowing you to specify a human readable name in your props. If a prop doesn't have a scale that means it accepts all valid CSSType values as props, however if it does have a scale it will only accept global values and keys of the provided scale.
|
|
47
|
-
- `transform`: A function that changes the prop / scale value prior to adding it to the stylehseet. This allows us to add / change units for properties like `width` and `height`. Or ensure extra defaults or fallbacks are added dynamically.
|
|
48
|
-
|
|
49
|
-
<br />
|
|
50
|
-
|
|
51
|
-
## Layout
|
|
52
|
-
|
|
53
|
-
Props for handling dimensions and other layout specific properties.
|
|
54
|
-
|
|
55
|
-
```tsx
|
|
56
|
-
import styled from '@emotion/styled';
|
|
57
|
-
import { system } from '@codecademy/gamut-styles';
|
|
58
|
-
|
|
59
|
-
const Box = styled.div(system.layout);
|
|
60
|
-
|
|
61
|
-
<Box display="flex" width="50%" height="300px" verticalAlign="middle" />;
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
<TokenTable rows={getPropRows('layout')} columns={defaultColumns} />
|
|
65
|
-
|
|
66
|
-
## Space
|
|
67
|
-
|
|
68
|
-
Props for maintaining specific vertical and horizontal rhythms
|
|
69
|
-
|
|
70
|
-
```tsx
|
|
71
|
-
import styled from '@emotion/styled';
|
|
72
|
-
import { system } from '@codecademy/gamut-styles';
|
|
73
|
-
|
|
74
|
-
const Spacer = styled.div(system.space);
|
|
75
|
-
|
|
76
|
-
<Spacer p={8} my={[16, 24, 32]} />;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
<TokenTable rows={getPropRows('space')} columns={defaultColumns} />
|
|
80
|
-
|
|
81
|
-
## Typography
|
|
82
|
-
|
|
83
|
-
Props for text manipulation
|
|
84
|
-
|
|
85
|
-
```tsx
|
|
86
|
-
import styled from '@emotion/styled';
|
|
87
|
-
import { system } from '@codecademy/gamut-styles';
|
|
88
|
-
|
|
89
|
-
const Text = styled.p(system.typography);
|
|
90
|
-
|
|
91
|
-
<Text fontSize={16} fontFamily="accent" textTransform="uppercase" />;
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
<TokenTable rows={getPropRows('typography')} columns={defaultColumns} />
|
|
95
|
-
|
|
96
|
-
## Color
|
|
97
|
-
|
|
98
|
-
Specific color properties
|
|
99
|
-
|
|
100
|
-
```tsx
|
|
101
|
-
import styled from '@emotion/styled';
|
|
102
|
-
import { system } from '@codecademy/gamut-styles';
|
|
103
|
-
|
|
104
|
-
const Background = styled.div(system.color);
|
|
105
|
-
|
|
106
|
-
<Background bg="navy" textColor="gray-100" borderColor="blue" />;
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
<TokenTable rows={getPropRows('color')} columns={defaultColumns} />
|
|
110
|
-
|
|
111
|
-
## Border
|
|
112
|
-
|
|
113
|
-
Border styles
|
|
114
|
-
|
|
115
|
-
```tsx
|
|
116
|
-
import styled from '@emotion/styled';
|
|
117
|
-
import { system } from '@codecademy/gamut-styles';
|
|
118
|
-
|
|
119
|
-
const Box = styled.div(system.border);
|
|
120
|
-
|
|
121
|
-
<Box
|
|
122
|
-
border={1}
|
|
123
|
-
borderLeft="none"
|
|
124
|
-
borderRightStyle="dotted"
|
|
125
|
-
borderRadius="md"
|
|
126
|
-
/>;
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
<TokenTable rows={getPropRows('border')} columns={defaultColumns} />
|
|
130
|
-
|
|
131
|
-
## Flex
|
|
132
|
-
|
|
133
|
-
Flex specific properties
|
|
134
|
-
|
|
135
|
-
```tsx
|
|
136
|
-
import styled from '@emotion/styled';
|
|
137
|
-
import { system } from '@codecademy/gamut-styles';
|
|
138
|
-
|
|
139
|
-
const FlexBox = styled.div(system.flex);
|
|
140
|
-
|
|
141
|
-
<FlexBox flex={1} justifyContent="center" alignItems="flex-start" />;
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
<TokenTable rows={getPropRows('flex')} columns={defaultColumns} />
|
|
145
|
-
|
|
146
|
-
## Grid
|
|
147
|
-
|
|
148
|
-
Grid specific properties
|
|
149
|
-
|
|
150
|
-
```tsx
|
|
151
|
-
import styled from '@emotion/styled';
|
|
152
|
-
import { system } from '@codecademy/gamut-styles';
|
|
153
|
-
|
|
154
|
-
const GridBox = styled.div(system.grid);
|
|
155
|
-
|
|
156
|
-
<GridBox gridTemplateColumns="max-content 1fr max-content" columnGap={32} />;
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
<TokenTable rows={getPropRows('grid')} columns={defaultColumns} />
|
|
160
|
-
|
|
161
|
-
## Background
|
|
162
|
-
|
|
163
|
-
Props for background manipulation (sizing / repitition / images), for background color see `colors`.
|
|
164
|
-
|
|
165
|
-
```tsx
|
|
166
|
-
import styled from '@emotion/styled';
|
|
167
|
-
import { system } from '@codecademy/gamut-styles';
|
|
168
|
-
import myBg from './myBg.png';
|
|
169
|
-
|
|
170
|
-
const Box = styled.div(system.background);
|
|
171
|
-
|
|
172
|
-
<Box background={`url(${myBg}`} backgroundSize="cover" />;
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
<TokenTable rows={getPropRows('background')} columns={defaultColumns} />
|
|
176
|
-
|
|
177
|
-
## Positioning
|
|
178
|
-
|
|
179
|
-
Props that affect stacking and position contexts. Like `top`, `position` and `opacity`.
|
|
180
|
-
|
|
181
|
-
```tsx
|
|
182
|
-
import styled from '@emotion/styled';
|
|
183
|
-
import { system } from '@codecademy/gamut-styles';
|
|
184
|
-
|
|
185
|
-
const Box = styled.div(system.positioning);
|
|
186
|
-
|
|
187
|
-
<Box position="absolute" zIndex={2} top="0" left="0" />;
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
<TokenTable rows={getPropRows('positioning')} columns={defaultColumns} />
|
|
191
|
-
|
|
192
|
-
## Shadow
|
|
193
|
-
|
|
194
|
-
Props for box and text shadows.
|
|
195
|
-
|
|
196
|
-
```tsx
|
|
197
|
-
import styled from '@emotion/styled';
|
|
198
|
-
import { system } from '@codecademy/gamut-styles';
|
|
199
|
-
|
|
200
|
-
const Box = styled.div(system.shadow);
|
|
201
|
-
|
|
202
|
-
<Box
|
|
203
|
-
boxShadow="0 0 4px rgba(0, 0, 0, .15)"
|
|
204
|
-
textShadow="0 0 4px rgba(0, 0, 0, .15)"
|
|
205
|
-
/>;
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
<TokenTable rows={getPropRows('shadows')} columns={defaultColumns} />
|
|
209
|
-
|
|
210
|
-
## List
|
|
211
|
-
|
|
212
|
-
Props for adjusting list styles when rendering a component as a `ul` or `ol`
|
|
213
|
-
|
|
214
|
-
```tsx
|
|
215
|
-
import styled from '@emotion/styled';
|
|
216
|
-
import { system } from '@codecademy/gamut-styles';
|
|
217
|
-
|
|
218
|
-
const Box = styled.div(system.list);
|
|
219
|
-
|
|
220
|
-
<Box
|
|
221
|
-
as="ul"
|
|
222
|
-
listStyleType="square"
|
|
223
|
-
listStylePosition="inside"
|
|
224
|
-
listStyleImage="none"
|
|
225
|
-
>
|
|
226
|
-
<Box as="li">a list item</Box>
|
|
227
|
-
</Box>;
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
<TokenTable rows={getPropRows('list')} columns={defaultColumns} />
|