Skip to content

Commit a19c466

Browse files
committed
Refactor(web-react): Refactor breakpoint types #DS-1701
1 parent 7409cee commit a19c466

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

packages/web-react/src/components/Modal/demo/ModalScrollingLongContent.tsx

+25-21
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,26 @@ import {
1313
ScrollView,
1414
Stack,
1515
} from '../..';
16-
import { BreakpointToken } from '../../../types';
16+
import { BreakpointToken, SpaceToken } from '../../../types';
1717

1818
const breakpointControls = {
19-
mobile: { marginBottom: { mobile: 'space-800' }, className: '' },
20-
tablet: { marginBottom: { tablet: 'space-800' }, className: 'd-none d-tablet-grid' },
21-
desktop: { marginBottom: {}, className: 'd-none d-desktop-grid' },
19+
mobile: { marginBottom: { mobile: 'space-800' }, className: 'border-0' },
20+
tablet: { marginBottom: { tablet: 'space-800' }, className: 'd-none d-tablet-grid border-0' },
21+
desktop: { marginBottom: {}, className: 'd-none d-desktop-grid border-0' },
2222
};
2323

2424
const setVerticalDimensionValueForProp = (
2525
prevState: { height: Record<BreakpointToken, number>; maxHeight: Record<BreakpointToken, number> },
2626
breakpoint: BreakpointToken,
2727
event: ChangeEvent<HTMLInputElement>,
2828
propName: 'height' | 'maxHeight',
29-
) => {
30-
return {
31-
...prevState,
32-
[propName]: {
33-
...prevState[propName],
34-
[breakpoint]: Number(event.target.value),
35-
},
36-
};
37-
};
29+
) => ({
30+
...prevState,
31+
[propName]: {
32+
...prevState[propName],
33+
[breakpoint]: Number(event.target.value),
34+
},
35+
});
3836

3937
const ModalScrollingLongContent = () => {
4038
const [isModalLongContentOpen, setModalLongContentOpen] = useState(false);
@@ -80,8 +78,8 @@ const ModalScrollingLongContent = () => {
8078
setHeightValue((prevState) => setVerticalDimensionValueForProp(prevState, breakpoint, event, 'height'));
8179
};
8280

83-
const generateHeightObject = (isMax = false) => {
84-
return (['mobile', 'tablet', 'desktop'] as BreakpointToken[]).reduce(
81+
const generateHeightObject = (isMax = false) =>
82+
(['mobile', 'tablet', 'desktop'] as BreakpointToken[]).reduce(
8583
(acc, breakpoint) => {
8684
acc[breakpoint] = isCustomHeightEnabled[breakpoint]
8785
? `${heightValue[isMax ? 'maxHeight' : 'height'][breakpoint]}px`
@@ -91,7 +89,6 @@ const ModalScrollingLongContent = () => {
9189
},
9290
{} as Record<BreakpointToken, string | null>,
9391
);
94-
};
9592

9693
return (
9794
<>
@@ -216,14 +213,21 @@ const ModalScrollingLongContent = () => {
216213
<ModalHeader>Modal with Custom Height</ModalHeader>
217214
<ModalBody>
218215
<form>
219-
{Object.entries(breakpointControls).map(([breakpoint, { marginBottom, className }]) => (
216+
{(
217+
Object.entries(breakpointControls) as [
218+
BreakpointToken,
219+
{
220+
marginBottom: Partial<Record<string, SpaceToken>>;
221+
className: string;
222+
},
223+
][]
224+
).map(([breakpoint, { marginBottom, className }]) => (
220225
<Stack
221226
elementType="fieldset"
222227
hasSpacing
223228
key={breakpoint}
224-
marginBottom={marginBottom as Partial<Record<string, `space-${number}`>>}
229+
marginBottom={marginBottom as Partial<Record<string, SpaceToken>>}
225230
UNSAFE_className={className}
226-
UNSAFE_style={{ border: 0 }}
227231
>
228232
<legend hidden>{breakpoint.charAt(0).toUpperCase() + breakpoint.slice(1)}</legend>
229233
<Checkbox
@@ -237,7 +241,7 @@ const ModalScrollingLongContent = () => {
237241
}))
238242
}
239243
/>
240-
<Grid UNSAFE_style={{ columnGap: 'var(--spirit-space-600)' }}>
244+
<Grid spacingX="space-600">
241245
<Label
242246
UNSAFE_className="GridItem"
243247
htmlFor={`custom-height-${breakpoint}`}
@@ -274,7 +278,7 @@ const ModalScrollingLongContent = () => {
274278
type="range"
275279
/>
276280
</Grid>
277-
<Grid UNSAFE_style={{ columnGap: 'var(--spirit-space-600)' }}>
281+
<Grid spacingX="space-600">
278282
<Label
279283
UNSAFE_className="GridItem"
280284
htmlFor={`custom-max-height-${breakpoint}`}

packages/web-react/src/components/Section/useSectionSizeProps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface UseSectionSizeProps {
88

99
const sizePaddingMapping: Record<
1010
SizeExtendedDictionaryType<never>,
11-
{ paddingY: Record<BreakpointToken, SpaceToken> }
11+
{ paddingY: Partial<Record<BreakpointToken, SpaceToken>> }
1212
> = {
1313
[SizesExtended.XSMALL]: { paddingY: { mobile: 'space-900', tablet: 'space-1000' } },
1414
[SizesExtended.SMALL]: { paddingY: { mobile: 'space-1000', tablet: 'space-1100' } },

packages/web-react/src/types/shared/tokens.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { breakpoints, spaces } from '@lmc-eu/spirit-design-tokens';
22

33
export const BREAKPOINT_MOBILE = 'mobile';
44

5-
export type BreakpointToken = keyof typeof breakpoints | string;
5+
export type BreakpointToken = keyof typeof breakpoints;
66
export type SpaceToken = `space-${keyof typeof spaces}` | `space-${number}`;

0 commit comments

Comments
 (0)