Skip to content

Commit 8b7afb1

Browse files
committed
chore!: change z-indexes on theme from array to dictionary
1 parent 063e574 commit 8b7afb1

File tree

12 files changed

+62
-11
lines changed

12 files changed

+62
-11
lines changed

.changeset/seven-cats-roll.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@strapi/design-system': major
3+
---
4+
5+
chore!: change z-indexes on theme from array to dictionary
6+
7+
`z-indices` on the theme object were an array of length 4. We've since changed this to a dictionary to help engineers understand how to correctly apply these values. See the `Elevation` documentation for more information.

docs/.storybook/preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const preview: Preview = {
135135
'Getting Started',
136136
['Welcome', 'Contributing', 'Changelog', 'Migration Guides', ['V1 to V2']],
137137
'Foundations',
138-
['Accessibility', 'Color', 'Grid', 'Icons', ['Overview', '*'], 'Typography'],
138+
['Accessibility', 'Color', 'Elevation', 'Grid', 'Icons', ['Overview', '*'], 'Typography'],
139139
'Primitives',
140140
['Overview', '*'],
141141
'Inputs',
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Meta } from '@storybook/blocks';
2+
3+
<Meta title="Foundations/Elevation" />
4+
5+
# Layers
6+
7+
Modern UI is composed of different layers, be that modals, popovers or tooltips.
8+
9+
## Shadows
10+
11+
Shadows are used to create a sense of depth and separation between elements. They might be used to indicate evelation of
12+
an element e.g. a Popover, or alternatively, they can indicate that UI can scroll below another element e.g. Tables.
13+
14+
## Z-Index
15+
16+
The z-index determines the stacking order of elements. Elements with a higher z-index always sit in front of elements
17+
with a lower z-index. Our current collection of z-index values are lised below with their alias, they're currently
18+
non-linear to support growing other common use-cases we may not have encountered yet. All are accessible via the theme
19+
object – `theme.zIndices.<alias>`.
20+
21+
- `navigation``100`
22+
- `overlay``300`
23+
- `modal``310`
24+
- `dialog``320`
25+
- `popover``500`
26+
- `notification``700`
27+
- `tooltip``1000`

packages/design-system/src/components/Box/Box.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ interface TransientBoxProps
2323
| 'pointerEvents'
2424
| 'display'
2525
| 'position'
26-
| 'zIndex'
2726
| 'overflow'
2827
| 'cursor'
2928
| 'transition'
@@ -120,6 +119,7 @@ interface TransientBoxProps
120119
borderRadius?: CSSProperties['borderRadius'];
121120
borderStyle?: CSSProperties['borderStyle'];
122121
borderWidth?: CSSProperties['borderWidth'];
122+
zIndex?: DefaultThemeOrCSSProp<'zIndicies', 'zIndex'>;
123123
}
124124

125125
interface BoxPropsImpl extends TransientBoxProps {
@@ -294,7 +294,7 @@ const StyledBox = styled.div<PropsToTransientProps<TransientBoxProps>>`
294294
right: ${({ $right, theme }) => extractStyleFromTheme(theme.spaces, $right, $right)};
295295
top: ${({ $top, theme }) => extractStyleFromTheme(theme.spaces, $top, $top)};
296296
bottom: ${({ $bottom, theme }) => extractStyleFromTheme(theme.spaces, $bottom, $bottom)};
297-
z-index: ${({ $zIndex }) => $zIndex};
297+
z-index: ${({ $zIndex, theme }) => extractStyleFromTheme(theme.zIndices, $zIndex, $zIndex)};
298298
overflow: ${({ $overflow }) => $overflow};
299299
300300
// Size

packages/design-system/src/components/Combobox/Combobox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ const Content = styled(ComboboxPrimitive.Content)`
366366
width: var(--radix-combobox-trigger-width);
367367
/* This is from the design-system figma file. */
368368
max-height: 15rem;
369-
z-index: ${({ theme }) => theme.zIndices[1]};
369+
z-index: ${({ theme }) => theme.zIndices.popover};
370370
`;
371371

372372
const Viewport = styled(ComboboxPrimitive.Viewport)`

packages/design-system/src/components/DatePicker/DatePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ const DatePickerContentImpl = React.forwardRef<DatePickerContentImplElement, Con
875875

876876
const ContentElement = styled<BoxComponent>(Box)`
877877
box-shadow: ${({ theme }) => theme.shadows.filterShadow};
878-
z-index: ${({ theme }) => theme.zIndices[0]};
878+
z-index: ${({ theme }) => theme.zIndices.popover};
879879
border: 1px solid ${({ theme }) => theme.colors.neutral150};
880880
`;
881881

packages/design-system/src/components/Dialog/Dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface DialogProps extends BoxProps {
3535
as?: TypographyProps<any>['tag'];
3636
}
3737

38-
export const Dialog = ({ onClose, title, as = 'h2', isOpen, id, zIndex = 4, ...props }: DialogProps) => {
38+
export const Dialog = ({ onClose, title, as = 'h2', isOpen, id, zIndex = 'dialog', ...props }: DialogProps) => {
3939
const generatedId = useId(id);
4040

4141
useLockScroll(isOpen);

packages/design-system/src/components/ModalLayout/ModalLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const ModalLayout = ({ onClose, labelledBy, ...props }: ModalLayoutProps)
2525
return (
2626
<Portal>
2727
<ModalContext.Provider value={onClose}>
28-
<ModalWrapper justifyContent="center" paddingLeft={8} paddingRight={8} position="fixed" zIndex={4}>
28+
<ModalWrapper justifyContent="center" paddingLeft={8} paddingRight={8} position="fixed" zIndex="modal">
2929
<FocusTrap>
3030
<DismissibleLayer onEscapeKeyDown={onClose} onPointerDownOutside={onClose}>
3131
<Box

packages/design-system/src/components/Popover/Popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const POPOVER_PLACEMENTS = [
3232

3333
const PopoverWrapper = styled<BoxComponent>(Box)`
3434
box-shadow: ${({ theme }) => theme.shadows.filterShadow};
35-
z-index: ${({ theme }) => theme.zIndices[0]};
35+
z-index: ${({ theme }) => theme.zIndices.popover};
3636
border: 1px solid ${({ theme }) => theme.colors.neutral150};
3737
`;
3838
export interface ContentProps

packages/design-system/src/components/Select/SelectParts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const SelectContent = styled(Select.Content)`
174174
min-width: var(--radix-select-trigger-width);
175175
/* This is from the design-system figma file. */
176176
max-height: 15rem;
177-
z-index: ${({ theme }) => theme.zIndices[1]};
177+
z-index: ${({ theme }) => theme.zIndices.popover};
178178
`;
179179

180180
/* -------------------------------------------------------------------------------------------------

packages/design-system/src/components/Tooltip/Tooltip.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const TooltipContent = styled(Tooltip.Content)`
8181
padding-inline: ${(props) => props.theme.spaces[2]};
8282
padding-block: ${(props) => props.theme.spaces[2]};
8383
border-radius: ${(props) => props.theme.borderRadius};
84+
z-index: ${(props) => props.theme.zIndices.tooltip};
8485
will-change: opacity;
8586
transform-origin: var(--radix-tooltip-content-transform-origin);
8687

packages/design-system/src/themes/common-theme.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import { Sizes, sizes } from './sizes';
44

55
export interface CommonTheme {
66
sizes: Sizes;
7-
zIndices: [5, 10, 15, 20];
7+
zIndices: {
8+
navigation: 100;
9+
overlay: 300;
10+
modal: 310;
11+
dialog: 320;
12+
popover: 500;
13+
notification: 700;
14+
tooltip: 1000;
15+
};
816
spaces: ['0px', '4px', '8px', '12px', '16px', '20px', '24px', '32px', '40px', '48px', '56px', '64px'];
917
borderRadius: '4px';
1018
mediaQueries: {
@@ -23,7 +31,15 @@ export interface CommonTheme {
2331

2432
export const commonTheme: CommonTheme = {
2533
sizes,
26-
zIndices: [5, 10, 15, 20], // TBD
34+
zIndices: {
35+
navigation: 100,
36+
overlay: 300,
37+
modal: 310,
38+
dialog: 320,
39+
popover: 500,
40+
notification: 700,
41+
tooltip: 1000,
42+
},
2743
spaces: ['0px', '4px', '8px', '12px', '16px', '20px', '24px', '32px', '40px', '48px', '56px', '64px'],
2844
borderRadius: '4px',
2945
mediaQueries: {

0 commit comments

Comments
 (0)