Skip to content

Commit 867397d

Browse files
authored
Merge pull request #78 from buildo/bleed
2 parents 63db8f8 + a2693c9 commit 867397d

11 files changed

+154
-16
lines changed

Diff for: src/Layout/createBleed.tsx

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { BoxProps, BoxType, Children } from "..";
2+
import { bentoSprinkles } from "../internal";
3+
4+
export function createBleed<AtomsFn extends typeof bentoSprinkles>(Box: BoxType<AtomsFn>) {
5+
type ResponsiveSpace = BoxProps<AtomsFn>["gap"];
6+
7+
type BleedProps = {
8+
children: Children;
9+
space?: ResponsiveSpace;
10+
spaceX?: ResponsiveSpace;
11+
spaceY?: ResponsiveSpace;
12+
spaceRight?: ResponsiveSpace;
13+
spaceLeft?: ResponsiveSpace;
14+
spaceTop?: ResponsiveSpace;
15+
spaceBottom?: ResponsiveSpace;
16+
};
17+
18+
type ResponsiveNegativeSpace = BoxProps<AtomsFn>["margin"];
19+
20+
function negateSpace(space: ResponsiveSpace | undefined): ResponsiveNegativeSpace | undefined {
21+
if (typeof space === "number") {
22+
return `negative${space}`;
23+
} else if (!!space) {
24+
return {
25+
desktop: space.desktop ? `negative${space.desktop}` : undefined,
26+
tablet: space.tablet ? `negative${space.tablet}` : undefined,
27+
mobile: space.mobile ? `negative${space.mobile}` : undefined,
28+
};
29+
} else {
30+
return undefined;
31+
}
32+
}
33+
34+
return function Bleed({
35+
space,
36+
spaceX,
37+
spaceY,
38+
spaceRight,
39+
spaceLeft,
40+
spaceTop,
41+
spaceBottom,
42+
children,
43+
}: BleedProps) {
44+
return (
45+
<Box
46+
margin={negateSpace(space)}
47+
marginX={negateSpace(spaceX)}
48+
marginY={negateSpace(spaceY)}
49+
marginRight={negateSpace(spaceRight)}
50+
marginLeft={negateSpace(spaceLeft)}
51+
marginTop={negateSpace(spaceTop)}
52+
marginBottom={negateSpace(spaceBottom)}
53+
>
54+
{children}
55+
</Box>
56+
);
57+
};
58+
}

Diff for: src/Layout/createLayoutComponents.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createInline } from "./createInline";
44
import { createStack } from "./createStack";
55
import { createColumns } from "./createColumns";
66
import { createInset } from "./createInset";
7+
import { createBleed } from "./createBleed";
78

89
export function createLayoutComponents<AtomsFn extends typeof bentoSprinkles>(
910
Box: BoxType<AtomsFn>
@@ -12,12 +13,14 @@ export function createLayoutComponents<AtomsFn extends typeof bentoSprinkles>(
1213
const Inset = createInset(Box);
1314
const Stack = createStack(Box);
1415
const { Column, Columns } = createColumns(Box);
16+
const Bleed = createBleed(Box);
1517

1618
return {
1719
Inline,
1820
Stack,
1921
Inset,
2022
Column,
2123
Columns,
24+
Bleed,
2225
};
2326
}

Diff for: src/Toast/createToast.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import { createToastContainer } from "./createToastContainer";
66
import { createToastProvider } from "./createToastProvider";
77

88
export type ToastConfig = {
9-
paddingX?: {
10-
withAction: BentoSprinkles["paddingX"];
11-
withoutAction: BentoSprinkles["paddingX"];
12-
};
9+
paddingX?: BentoSprinkles["paddingX"];
1310
paddingY?: BentoSprinkles["paddingY"];
1411
radius?: BentoSprinkles["borderRadius"];
1512
messageSize?: ComponentProps<typeof Body>["size"];
13+
mediumButtonPaddingX: BentoSprinkles["paddingY"];
1614
};
1715

1816
export type ToastProps = {
@@ -24,16 +22,20 @@ export type ToastProps = {
2422
export function createToast(
2523
Button: FunctionComponent<ButtonProps>,
2624
{
27-
paddingX = {
28-
withAction: 0,
29-
withoutAction: 16,
30-
},
25+
paddingX = 16,
3126
paddingY = 16,
3227
radius = 8,
3328
messageSize = "medium",
29+
mediumButtonPaddingX,
3430
}: ToastConfig
3531
) {
36-
const Toast = createToastInternal(Button, { paddingX, paddingY, radius, messageSize });
32+
const Toast = createToastInternal(Button, {
33+
paddingX,
34+
paddingY,
35+
mediumButtonPaddingX,
36+
radius,
37+
messageSize,
38+
});
3739
const ToastContainer = createToastContainer(Toast);
3840
const ToastProvider = createToastProvider(ToastContainer);
3941

Diff for: src/Toast/createToastInternal.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FunctionComponent } from "react";
2-
import { Box, Column, Columns } from "../internal";
2+
import { Box, Column, Columns, Bleed } from "../internal";
33
import { Body, ButtonProps, ToastProps } from "..";
44
import { toastRecipe } from "./Toast.css";
55
import { ToastConfig } from "./createToast";
@@ -20,16 +20,17 @@ export function createToastInternal(
2020
className={toastRecipe({ kind })}
2121
borderRadius={config.radius}
2222
paddingY={config.paddingY}
23-
paddingLeft={config.paddingX.withoutAction}
24-
paddingRight={!!action ? config.paddingX.withAction : config.paddingX.withoutAction}
23+
paddingX={config.paddingX}
2524
>
2625
<Columns space={16} alignY="center">
2726
<Body size={config.messageSize} color={kind === "secondary" ? "default" : kind}>
2827
{message}
2928
</Body>
3029
{action && (
3130
<Column width="content">
32-
<Button size="medium" kind="transparent" hierarchy="secondary" {...action} />
31+
<Bleed spaceRight={config.mediumButtonPaddingX}>
32+
<Button size="medium" kind="transparent" hierarchy="secondary" {...action} />
33+
</Bleed>
3334
</Column>
3435
)}
3536
</Columns>

Diff for: src/internal/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import { Box } from "./Box/Box";
66
export { bentoSprinkles } from "./sprinkles.css";
77
export type { BentoSprinkles } from "./sprinkles.css";
88
export * from "./Box/Box";
9-
export const { Column, Columns, Inline, Inset, Stack } = createLayoutComponents(Box);
9+
export const { Column, Columns, Inline, Inset, Stack, Bleed } = createLayoutComponents(Box);

Diff for: src/sprinkles.ts

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export function createDefineBentoSprinklesFn() {
3838
padding: ["paddingTop", "paddingBottom", "paddingLeft", "paddingRight"],
3939
paddingX: ["paddingLeft", "paddingRight"],
4040
paddingY: ["paddingTop", "paddingBottom"],
41+
margin: ["marginTop", "marginBottom", "marginLeft", "marginRight"],
42+
marginX: ["marginLeft", "marginRight"],
43+
marginY: ["marginTop", "marginBottom"],
4144
},
4245
});
4346

Diff for: src/util/atoms.ts

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export const responsiveProperties = {
7373
bottom: vars.space,
7474
left: vars.space,
7575
right: vars.space,
76+
marginTop: vars.negativeSpace,
77+
marginBottom: vars.negativeSpace,
78+
marginLeft: vars.negativeSpace,
79+
marginRight: vars.negativeSpace,
7680
} as const;
7781

7882
const color = {

Diff for: src/vars.css.ts

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ export const vars = createThemeContract({
5656
40: null,
5757
80: null,
5858
},
59+
negativeSpace: {
60+
"0": null,
61+
// NOTE(gabro): ideally we would use "-4" and so on here, but we can't due to
62+
// https://github.com/Swatinem/rollup-plugin-dts/issues/201
63+
negative4: null,
64+
negative8: null,
65+
negative16: null,
66+
negative24: null,
67+
negative32: null,
68+
negative40: null,
69+
negative80: null,
70+
},
5971
radius: {
6072
4: null,
6173
8: null,

Diff for: stories/Layout/Bleed.stories.tsx

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { JSXElementConstructor } from "react";
2+
import { Bleed, Box, Inset, Placeholder } from "..";
3+
import { createComponentStories, spaceArgType } from "../util";
4+
5+
const { defaultExport, createStory } = createComponentStories({
6+
component: Bleed,
7+
args: {
8+
children: <Placeholder height={100} width={100} />,
9+
},
10+
argTypes: {
11+
space: spaceArgType,
12+
spaceX: spaceArgType,
13+
spaceY: spaceArgType,
14+
},
15+
decorators: [
16+
(Story: JSXElementConstructor<unknown>) => (
17+
<Box background="softViolet" style={{ width: "fit-content" }}>
18+
<Inset space={24}>
19+
<Story />
20+
</Inset>
21+
</Box>
22+
),
23+
],
24+
});
25+
26+
export default defaultExport;
27+
28+
export const allAxis = createStory({
29+
space: 40,
30+
});
31+
32+
export const horizontal = createStory({
33+
spaceX: 40,
34+
});
35+
36+
export const vertical = createStory({
37+
spaceY: 40,
38+
});
39+
40+
export const horizontalAndVertical = createStory({
41+
spaceX: 40,
42+
spaceY: 16,
43+
});

Diff for: stories/index.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { sprinkles } from "./sprinkles.css";
3535

3636
export * from "../src";
3737
export const Box = createBentoBox(sprinkles);
38-
export const { Stack, Column, Columns, Inline, Inset } = createLayoutComponents(Box);
38+
export const { Stack, Column, Columns, Inline, Inset, Bleed } = createLayoutComponents(Box);
3939
export const Tooltip = createTooltip();
4040
export const {
4141
Field,
@@ -50,7 +50,9 @@ export const { Button, ButtonLink } = createButtons();
5050
export const Banner = createBanner(Button, {});
5151
export const Actions = createActions(Button, Banner);
5252
export const { Form, FormSection, FormRow } = createFormLayoutComponents(Actions);
53-
export const { Toast, ToastProvider } = createToast(Button, {});
53+
export const { Toast, ToastProvider } = createToast(Button, {
54+
mediumButtonPaddingX: 16,
55+
});
5456
export const BentoProvider = createBentoProvider(ToastProvider);
5557
export const Card = createCard<24 | 32 | 40>({});
5658
export const Link = createLink();

Diff for: stories/theme.css.ts

+10
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ const commonTheme = {
119119
"40": "40px",
120120
"80": "80px",
121121
},
122+
negativeSpace: {
123+
"0": "0",
124+
negative4: "-4px",
125+
negative8: "-8px",
126+
negative16: "-16px",
127+
negative24: "-24px",
128+
negative32: "-32px",
129+
negative40: "-40px",
130+
negative80: "-80px",
131+
},
122132
radius: {
123133
"4": "4px",
124134
"8": "8px",

0 commit comments

Comments
 (0)