Skip to content

Commit 5c2da3c

Browse files
committed
refactor(POC): make changes requested in POC comments - tbs
1 parent 32053a1 commit 5c2da3c

File tree

9 files changed

+111
-286
lines changed

9 files changed

+111
-286
lines changed

docs/styled-system-replacement-poc.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ By creating custom style functions using just plain old JavaScript, we can tailo
1818

1919
## Implementation
2020

21-
The implementation involves creating utility functions that mimic the behavior of `styled-system` for common use cases, such as spacing, layout, and flexbox.
21+
The implementation involves creating utility functions that mimic the behaviour of `styled-system` for common use cases, such as spacing, layout, and flexbox.
2222
These functions will parse props and apply styles directly to components without the overhead of a full library.
2323

2424
For now, we have created utilities for spacing props (margin, padding), layout and flexbox as a starting point. These have been selected as

src/__spec_helper__/__internal__/test-utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,14 @@ const testStyledPadding = (
280280
'when a custom spacing is specified using the "%s" styled props',
281281
(styledProp, propName) => {
282282
it(`should set ${propName} styling correctly`, () => {
283-
const props = { [styledProp]: 3 };
283+
const props = { [styledProp]: 2 };
284284
render(component({ ...props }));
285285

286-
assertStyleMatch({ [propName]: "24px" }, elementQuery(), assertOpts);
286+
assertStyleMatch(
287+
{ [propName]: "var(--spacing200)" },
288+
elementQuery(),
289+
assertOpts,
290+
);
287291
});
288292
},
289293
);
@@ -299,10 +303,14 @@ const testStyledMargin = (
299303
'when a custom spacing is specified using the "%s" styled props',
300304
(styledProp, propName) => {
301305
it(`should set ${propName} styling correctly`, () => {
302-
const props = { [styledProp]: 3 };
306+
const props = { [styledProp]: 2 };
303307
render(component({ ...props }));
304308

305-
assertStyleMatch({ [propName]: "24px" }, elementQuery(), assertOpts);
309+
assertStyleMatch(
310+
{ [propName]: "var(--spacing200)" },
311+
elementQuery(),
312+
assertOpts,
313+
);
306314
});
307315
},
308316
);

src/components/dips-box/dips-box.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const Spacing: Story = () => {
3030
Margin Left and Padding Top String
3131
</DipsBox>
3232

33-
<DipsBox ml="XS" pt="L">
33+
<DipsBox ml="var(--spacing300)" pt="var(--spacing600)">
3434
Margin Left and Padding Top String
3535
</DipsBox>
3636
</>

src/components/dips-box/dips-box.test.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
testStyledPadding,
88
} from "../../__spec_helper__/__internal__/test-utils";
99
import DipsBox from "./dips-box.component";
10+
import CarbonProvider from "../carbon-provider";
1011

1112
describe("DipsBox", () => {
1213
it("renders without crashing", () => {
@@ -24,23 +25,39 @@ describe("DipsBox", () => {
2425
});
2526

2627
testStyledPadding(
27-
(props) => <DipsBox data-role="box" {...props} />,
28+
(props) => (
29+
<CarbonProvider>
30+
<DipsBox data-role="box" {...props} />
31+
</CarbonProvider>
32+
),
2833
() => screen.getByTestId("box"),
2934
);
3035

3136
testStyledMargin(
32-
(props) => <DipsBox data-role="box" {...props} />,
37+
(props) => (
38+
<CarbonProvider>
39+
<DipsBox data-role="box" {...props} />
40+
</CarbonProvider>
41+
),
3342
() => screen.getByTestId("box"),
3443
);
3544

3645
testStyledFlexBox(
37-
(props) => <DipsBox data-role="box" {...props} />,
46+
(props) => (
47+
<CarbonProvider>
48+
<DipsBox data-role="box" {...props} />
49+
</CarbonProvider>
50+
),
3851
() => screen.getByTestId("box"),
3952
);
4053

4154
// Layout props are not fully supported so only test those that are.
4255
testStyledLayout(
43-
(props) => <DipsBox data-role="box" {...props} />,
56+
(props) => (
57+
<CarbonProvider>
58+
<DipsBox data-role="box" {...props} />
59+
</CarbonProvider>
60+
),
4461
() => screen.getByTestId("box"),
4562
);
4663
});

src/components/dips-box/utils/spacing-types.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,6 @@ export interface MarginProps {
5252
marginLeft?: string | number;
5353
}
5454

55-
// Size range from 3XS to 4XL. "none" added to allow zero spacing.
56-
export type SpacingSize =
57-
| "none"
58-
| "3XS"
59-
| "2XS"
60-
| "XS"
61-
| "S"
62-
| "M"
63-
| "L"
64-
| "XL"
65-
| "2XL"
66-
| "3XL"
67-
| "4XL";
68-
69-
// Mapping of size to multiplier value for spacing calculations
70-
// 3XS would be 1 * base spacing unit, 2XS would be 2 * base spacing unit, etc.
71-
export const spacingSizeMap: Record<SpacingSize, number> = {
72-
none: 0,
73-
"3XS": 1,
74-
"2XS": 2,
75-
XS: 3,
76-
S: 4,
77-
M: 5,
78-
L: 6,
79-
XL: 7,
80-
"2XL": 8,
81-
"3XL": 9,
82-
"4XL": 10,
83-
};
84-
8555
export interface FlexboxProps {
8656
/** Short hand `align-content` property */
8757
alignContent?: string;
@@ -141,7 +111,3 @@ export interface LayoutProps {
141111
/** Short hand `aspect-ratio` property */
142112
aspectRatio?: string;
143113
}
144-
145-
export interface MaxWidthProps {
146-
maxWidth?: string;
147-
}

0 commit comments

Comments
 (0)