Skip to content

Commit ab7c414

Browse files
authored
Merge pull request #45 from outshift-open/new-breakpoints
feat(responsivity)!: Extend breakpoints' list
2 parents 730f033 + 683d537 commit ab7c414

File tree

9 files changed

+129
-82
lines changed

9 files changed

+129
-82
lines changed

packages/open-ui-kit/src/charts/bar-graph/bar-graph.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,20 @@ export const BarGraph = ({
6868

6969
const [header0, header1] = headers;
7070

71-
const updateYAxisWidth = () => {
72-
if (chartContainerRef.current) {
73-
const chartWidth =
74-
chartContainerRef.current.getBoundingClientRect().width;
71+
useEffect(() => {
72+
const el = chartContainerRef.current;
73+
if (!el) return;
74+
75+
const updateYAxisWidth = () => {
76+
const chartWidth = el.getBoundingClientRect().width;
7577
setYAxisWidth(chartWidth * 0.43);
76-
}
77-
};
78+
};
7879

79-
useEffect(() => {
8080
updateYAxisWidth();
81-
window.addEventListener("resize", updateYAxisWidth, false);
81+
82+
const ro = new ResizeObserver(updateYAxisWidth);
83+
ro.observe(el);
84+
return () => ro.disconnect();
8285
}, []);
8386

8487
return (
@@ -177,7 +180,6 @@ export const BarGraph = ({
177180
spacing={2}
178181
alignItems="center"
179182
overflow="hidden"
180-
position="absolute"
181183
bottom={0}
182184
sx={{
183185
backgroundColor: theme.palette.vars.interactiveSecondaryWeakDefault,

packages/open-ui-kit/src/components/modal/stories/modal.stories.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ const meta: Meta<typeof Modal> = {
3939
),
4040
},
4141
},
42+
argTypes: {
43+
maxWidth: {
44+
description:
45+
"Dialog **content width** preset (MUI). This string is **not** the same as layout viewport breakpoints (`theme.breakpoints`). See the **Dialog sizes** story and `docs/new-breakpoints-branch-changes.md`.",
46+
},
47+
},
4248
};
4349

4450
export default meta;
@@ -97,11 +103,32 @@ export const SimpleModal: Story = {
97103
};
98104

99105
export const DialogSizes: Story = {
106+
name: "Dialog sizes (content width)",
107+
parameters: {
108+
docs: {
109+
description: {
110+
story:
111+
"Labels use M / L / XL (content) to avoid confusing these with layout breakpoints. Engineers still set MUI maxWidth (md / lg / xl) as shown in each row. Mapping: theme/mui/dialog.tsx docblock and docs/new-breakpoints-branch-changes.md.",
112+
},
113+
},
114+
},
100115
render: () => (
101116
<Stack gap={2}>
102-
<ModalComponent maxWidth="md" fullWidth title="md" />
103-
<ModalComponent maxWidth="lg" fullWidth title="lg" />
104-
<ModalComponent maxWidth="xl" fullWidth title="xl" />
117+
<ModalComponent
118+
maxWidth="md"
119+
fullWidth
120+
title='M (content), maxWidth="md", 600px paper'
121+
/>
122+
<ModalComponent
123+
maxWidth="lg"
124+
fullWidth
125+
title='L (content), maxWidth="lg", 1024px paper'
126+
/>
127+
<ModalComponent
128+
maxWidth="xl"
129+
fullWidth
130+
title='XL (content), maxWidth="xl", 1440px paper'
131+
/>
105132
</Stack>
106133
),
107134
};

packages/open-ui-kit/src/components/overflow-tooltip/components/overflow-tooltip.tsx

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { useState, useRef, useEffect } from "react";
7+
import { useState, useRef, useEffect, useCallback } from "react";
88
import { rtlWrapperStyle, baseWrapperStyle, spanStyle } from "../styles";
99
import { Tooltip, TooltipProps } from "@/components";
1010

@@ -24,37 +24,27 @@ export const OverflowTooltip = ({
2424
styleText,
2525
...rest
2626
}: OverflowTooltipProps) => {
27-
// Create Ref
28-
const textElementRef = useRef() as React.MutableRefObject<HTMLDivElement>;
29-
30-
/**
31-
* Compares the size of the text element to its container and sets the hover state accordingly
32-
*/
33-
const compareSize = () => {
34-
const compare =
35-
textElementRef.current.scrollWidth > textElementRef.current.clientWidth;
36-
setHover(compare);
37-
};
27+
const textElementRef = useRef<HTMLDivElement | null>(null);
28+
const [hoverStatus, setHover] = useState(false);
3829

39-
// Add resize listener to compare size on component mount
40-
useEffect(() => {
41-
window.addEventListener("resize", compareSize);
30+
const compareSize = useCallback(() => {
31+
const el = textElementRef.current;
32+
if (!el) return;
33+
setHover(el.scrollWidth > el.clientWidth);
4234
}, []);
4335

4436
useEffect(() => {
45-
compareSize();
46-
}, [value]);
37+
const el = textElementRef.current;
38+
if (!el) return;
4739

48-
// Remove resize listener on component unmount
49-
useEffect(
50-
() => () => {
51-
window.removeEventListener("resize", compareSize);
52-
},
53-
[],
54-
);
40+
compareSize();
5541

56-
// Define state and function to update the value
57-
const [hoverStatus, setHover] = useState(false);
42+
const ro = new ResizeObserver(() => {
43+
compareSize();
44+
});
45+
ro.observe(el);
46+
return () => ro.disconnect();
47+
}, [value, someLongText, ellipsisDirection, compareSize]);
5848

5949
return (
6050
<Tooltip {...rest} disableHoverListener={!hoverStatus} title={value}>

packages/open-ui-kit/src/templates/layout/components/layout.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { useEffect, useState } from "react";
8-
import { Box, Drawer, Toolbar, Typography } from "@mui/material";
7+
import {
8+
Box,
9+
Drawer,
10+
Toolbar,
11+
Typography,
12+
useMediaQuery,
13+
useTheme,
14+
} from "@mui/material";
915
import { Header, HeaderProps } from "@/components";
1016

1117
export interface LayoutProps {
@@ -21,20 +27,12 @@ export const Layout = ({
2127
headerProps,
2228
content,
2329
}: LayoutProps) => {
30+
const theme = useTheme();
2431
const defaultLayoutWidth = 240;
2532
const collapsedLayoutWidth = 56;
26-
const [isCollapsed, setIsCollapsed] = useState(window.innerWidth < 768);
27-
28-
const handleResize = () => {
29-
setIsCollapsed(window.innerWidth < 768);
30-
};
31-
32-
useEffect(() => {
33-
window.addEventListener("resize", handleResize);
34-
return () => {
35-
window.removeEventListener("resize", handleResize);
36-
};
37-
}, []);
33+
const isCollapsed = useMediaQuery(theme.breakpoints.down("sm"), {
34+
noSsr: true,
35+
});
3836

3937
return (
4038
<Box sx={{ display: "flex" }}>

packages/open-ui-kit/src/theme/common.tsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { Components, Theme } from "@mui/material";
7+
import { BreakpointsOptions, Components, Theme } from "@mui/material";
88
import { TypographyVariantsOptions } from "@mui/material/styles/createTypography";
99
import { KeyboardArrowUp } from "../custom-icons";
1010
import { TOOLBAR_MINIMUM_HEIGHT } from "./constants";
@@ -385,13 +385,39 @@ export const listItemCommonStyles = (theme: Theme) => {
385385
};
386386
};
387387

388+
/** Pixel widths for each named breakpoint (required keys; aligns with `BreakpointOverrides` in `types/theme.ts`). */
389+
export type AppBreakpointValues = {
390+
xs: number;
391+
sm: number;
392+
md: number;
393+
lg: number;
394+
xl: number;
395+
xxl: number;
396+
};
397+
398+
/** Single source of truth for breakpoint widths (px). Use this instead of `breakpoints.values?.x ?? n`. */
399+
export const breakpointValues: AppBreakpointValues = {
400+
xs: 0,
401+
sm: 600,
402+
md: 1024,
403+
lg: 1440,
404+
xl: 1920,
405+
xxl: 2560,
406+
};
407+
408+
export const breakpoints: BreakpointsOptions = {
409+
keys: ["xs", "sm", "md", "lg", "xl", "xxl"],
410+
values: breakpointValues,
411+
};
412+
388413
export const commonMixins = {
389414
toolbar: {
390415
minHeight: TOOLBAR_MINIMUM_HEIGHT,
391-
"@media (min-width:0px) and (orientation: landscape)": {
392-
minHeight: TOOLBAR_MINIMUM_HEIGHT,
393-
},
394-
"@media (min-width:600px)": {
416+
[`@media (min-width:${breakpointValues.xs}px) and (orientation: landscape)`]:
417+
{
418+
minHeight: TOOLBAR_MINIMUM_HEIGHT,
419+
},
420+
[`@media (min-width:${breakpointValues.sm}px)`]: {
395421
minHeight: TOOLBAR_MINIMUM_HEIGHT,
396422
},
397423
},

packages/open-ui-kit/src/theme/dark/dark-theme.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
surfaceDark900,
1515
surfaceDarkPalette,
1616
} from "../color-palette";
17-
import { typography, commonMixins } from "../common";
17+
import { typography, breakpoints, commonMixins } from "../common";
1818
import {
1919
createTheme,
2020
PaletteOptions,
@@ -90,15 +90,7 @@ const palette: PaletteOptions = {
9090
};
9191

9292
const theme: Theme = createTheme({
93-
breakpoints: {
94-
keys: ["md", "lg", "xl", "xxl"],
95-
values: {
96-
md: 1024,
97-
lg: 1440,
98-
xl: 1920,
99-
xxl: 2560,
100-
},
101-
},
93+
breakpoints,
10294
palette,
10395
typography,
10496
mixins: commonMixins,

packages/open-ui-kit/src/theme/light/light-theme.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
Theme,
2828
Shadows,
2929
} from "@mui/material";
30-
import { commonMixins, typography } from "../common";
30+
import { commonMixins, typography, breakpoints } from "../common";
3131
import { lightVars } from "./light-vars";
3232
import {
3333
appBarComponent,
@@ -109,15 +109,7 @@ const palette: PaletteOptions = {
109109
// });
110110

111111
const theme: Theme = createTheme({
112-
breakpoints: {
113-
keys: ["md", "lg", "xl", "xxl"],
114-
values: {
115-
md: 1024,
116-
lg: 1440,
117-
xl: 1920,
118-
xxl: 2560,
119-
},
120-
},
112+
breakpoints,
121113
palette,
122114
typography,
123115
mixins: commonMixins,

packages/open-ui-kit/src/theme/mui/dialog.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,27 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
/**
8+
* Dialog paper `maxWidth` presets vs layout breakpoints
9+
* -------------------------------------------------------
10+
* MUI’s `maxWidth` string is a **dialog content-size preset**, not `theme.breakpoints.*`.
11+
* We map three presets to `breakpointValues` pixel widths so modals stay readable; the
12+
* **preset label** (md / lg / xl) does **not** match the **token key** (sm / md / lg).
13+
*
14+
* | MUI `maxWidth` | Paper `maxWidth` (px) | `breakpointValues` key | Same name as layout breakpoint? |
15+
* |----------------|----------------------:|------------------------|--------------------------------|
16+
* | `xs` | *(MUI default)* | — | — |
17+
* | `sm` | *(MUI default)* | — | — |
18+
* | `md` | 600 | `sm` | **No** |
19+
* | `lg` | 1024 | `md` | **No** |
20+
* | `xl` | 1440 | `lg` | **No** |
21+
*
22+
* In Storybook, prefer **S / M / L / XL (content)** in titles, not “layout md/lg”.
23+
* @see docs/new-breakpoints-branch-changes.md
24+
*/
25+
726
import { Components, Theme } from "@mui/material";
27+
import { breakpointValues } from "../common";
828

929
export const dialogComponent = (theme: Theme): Components => {
1030
return {
@@ -15,13 +35,13 @@ export const dialogComponent = (theme: Theme): Components => {
1535
background: theme.palette.vars.controlBackgroundDefault,
1636
padding: "24px",
1737
"&.MuiDialog-paperWidthMd": {
18-
maxWidth: "480px",
38+
maxWidth: breakpointValues.sm,
1939
},
2040
"&.MuiDialog-paperWidthLg": {
21-
maxWidth: "720px",
41+
maxWidth: breakpointValues.md,
2242
},
2343
"&.MuiDialog-paperWidthXl": {
24-
maxWidth: "1200px",
44+
maxWidth: breakpointValues.lg,
2545
},
2646
},
2747
},

packages/open-ui-kit/src/types/theme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ declare module "@mui/material/styles" {
3333
interface PaletteColor extends ColorPartial {}
3434

3535
interface BreakpointOverrides {
36-
xs: false;
37-
sm: false;
36+
xs: true;
37+
sm: true;
3838
md: true;
3939
lg: true;
4040
xl: true;

0 commit comments

Comments
 (0)