Skip to content

Commit 8ea8732

Browse files
committed
feat(stack): add alignment props to stack
This prop will allow the stack to align the children inline re #2207
1 parent e8f12c3 commit 8ea8732

File tree

10 files changed

+290
-31
lines changed

10 files changed

+290
-31
lines changed

Diff for: packages/css/src/components/stack.css

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@
1414
margin: 0;
1515
}
1616

17-
[data-bedrock-stack] > [data-bedrock-column] {
18-
grid-column: span 1 / auto;
17+
[data-bedrock-stack~="align:start"] {
18+
align-items: flex-start;
19+
}
20+
[data-bedrock-stack~="align:center"] {
21+
align-items: center;
22+
}
23+
[data-bedrock-stack~="align:end"] {
24+
align-items: flex-end;
25+
}
26+
[data-bedrock-stack~="align:stretch"] {
27+
align-items: stretch;
1928
}
2029

2130
/* Gutter Sizes */

Diff for: packages/solid-doc-site/src/pages/StackPage/StackPage.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { ArgsTable } from "../../components/ArgsTable";
55
import { Heading } from "../../components/Heading";
66
import { PageSection } from "../../components/PageSection";
77
import { Story } from "../../components/Story";
8+
import { Align } from "./align";
9+
import alignCode from "./align?raw";
810
import { argTypes } from "./argTypes";
911
import { Gutter } from "./gutters";
1012
import gutterCode from "./gutters?raw";
@@ -44,6 +46,17 @@ export function StackPage(): JSXElement {
4446
<Gutter />
4547
</Story>
4648
</PageSection>
49+
<PageSection title="align">
50+
<p>
51+
The `align` prop defines the inline alignment of the elements within
52+
the stack. It accepts the following values: `start`, `end`, `center`,
53+
`stretch`.
54+
</p>
55+
56+
<Story code={alignCode}>
57+
<Align />
58+
</Story>
59+
</PageSection>
4760
<PageSection title="Playground">
4861
<Story code={playgroundCode}>
4962
<Playground {...props()} />
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable react/style-prop-object */
2+
import { Stack } from "@bedrock-layout/solid";
3+
import { JSXElement } from "solid-js";
4+
5+
import { Box } from "../../components/Box";
6+
7+
export function Align(): JSXElement {
8+
return (
9+
<>
10+
<h3>start</h3>
11+
<Stack align="start" gutter="size7">
12+
<Box style="height:200px" widthLevel={5} />
13+
<Box widthLevel={0.5} />
14+
<Box />
15+
</Stack>
16+
<h3>end</h3>
17+
<Stack align="end" gutter="size7">
18+
<Box style="height:200px" widthLevel={5} />
19+
<Box widthLevel={0.5} />
20+
<Box />
21+
</Stack>
22+
<h3>center</h3>
23+
<Stack align="center" gutter="size7">
24+
<Box style="height:200px" widthLevel={5} />
25+
<Box widthLevel={0.5} />
26+
<Box />
27+
</Stack>
28+
<h3>stretch</h3>
29+
<Stack align="stretch" gutter="size7">
30+
<Box style="height:200px" widthLevel={5} />
31+
<Box widthLevel={0.5} />
32+
<Box />
33+
</Stack>
34+
</>
35+
);
36+
}

Diff for: packages/solid-doc-site/src/pages/StackPage/argTypes.ts

+8
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ export const argTypes: ArgType = {
1010
control: "select",
1111
options: Object.keys(spacing),
1212
},
13+
align: {
14+
description: "Sets the block alignment of the children",
15+
summary: "start | end | center | stretch",
16+
defaultValue: "stretch",
17+
initialValue: "stretch",
18+
control: "select",
19+
options: ["start", "end", "center", "stretch"],
20+
},
1321
};

Diff for: packages/solid/src/inline.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function Inline<T extends ValidConstructor = "div">(
9494
const style = () =>
9595
[propsStyle(), gutter(), switchAt(), minItemWidth()].join("; ");
9696

97-
const attrAssesor = () =>
97+
const attrAssessor = () =>
9898
[justify(), align(), stretch()].filter(Boolean).join(" ");
9999

100100
return createDynamic(
@@ -110,7 +110,7 @@ export function Inline<T extends ValidConstructor = "div">(
110110
]),
111111
createPropsFromAccessors({
112112
style,
113-
"data-bedrock-inline": attrAssesor,
113+
"data-bedrock-inline": attrAssessor,
114114
}),
115115
) as DynamicProps<T>,
116116
);

Diff for: packages/solid/src/stack.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ import createDynamic, {
1010
omitProps,
1111
} from "./typeUtils";
1212

13+
const alignMap = {
14+
start: "align:start",
15+
end: "align:end",
16+
center: "align:center",
17+
stretch: "align:stretch",
18+
} as const;
19+
1320
export interface StackPropsBase {
1421
gutter?: SpacingOptions;
22+
align?: keyof typeof alignMap;
1523
}
1624

1725
export type StackProps<T extends ValidConstructor = "div"> =
@@ -34,11 +42,16 @@ export function Stack<T extends ValidConstructor = "div">(
3442

3543
const style = () => [propsStyle(), gutter()].join("; ");
3644

45+
const align = () =>
46+
props.align !== undefined ? alignMap[props.align] : undefined;
47+
48+
const attrAssessor = () => [align()].filter(Boolean).join(" ");
49+
3750
return createDynamic(
3851
() => props.as ?? ("div" as T),
3952
mergeProps(
4053
omitProps(props, ["as", "gutter"]),
41-
createPropsFromAccessors({ style, "data-bedrock-stack": () => "" }),
54+
createPropsFromAccessors({ style, "data-bedrock-stack": attrAssessor }),
4255
) as DynamicProps<T>,
4356
);
4457
}

0 commit comments

Comments
 (0)