@pickle-ui/react 1.0.0-beta.12 → 1.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,14 @@
1
+ import { type RenderSeparator } from './_internal/separate.js';
1
2
  import { type FlexProps } from './Flex.js';
2
- type XStackProps = Omit<FlexProps, 'direction'>;
3
- declare function XStack({ className, ref, ...props }: XStackProps): import("react").JSX.Element;
3
+ type XStackProps = Omit<FlexProps, 'direction'> & {
4
+ /**
5
+ * Renders a separator between each two children: a decorative `Separator`
6
+ * for `true`, or what a function returns, given the separator's index and
7
+ * its orientation. Give a decorative node `aria-hidden`.
8
+ */
9
+ separator?: boolean | RenderSeparator;
10
+ };
11
+ declare function XStack({ children, className, ref, separator, ...props }: XStackProps): import("react").JSX.Element;
4
12
  export { XStack };
5
13
  export type { XStackProps };
6
14
  //# sourceMappingURL=XStack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XStack.d.ts","sourceRoot":"","sources":["../../src/components/XStack.tsx"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9C,KAAK,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAEhD,iBAAS,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,EAAE,WAAW,+BASxD;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"XStack.d.ts","sourceRoot":"","sources":["../../src/components/XStack.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAY,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9C,KAAK,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG;IAChD;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;CACvC,CAAC;AAEF,iBAAS,MAAM,CAAC,EACd,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,GAAG,KAAK,EACT,EAAE,WAAW,+BAWb;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cn } from '../lib/utils.js';
3
+ import { separate } from './_internal/separate.js';
3
4
  import { Flex } from './Flex.js';
4
- function XStack({ className, ref, ...props }) {
5
- return (_jsx(Flex, { className: cn('flex-row', className), "data-slot": "x-stack", ref: ref, ...props }));
5
+ function XStack({ children, className, ref, separator, ...props }) {
6
+ return (_jsx(Flex, { className: cn('flex-row', className), "data-slot": "x-stack", ref: ref, ...props, children: separate(children, 'vertical', separator) }));
6
7
  }
7
8
  export { XStack };
8
9
  //# sourceMappingURL=XStack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"XStack.js","sourceRoot":"","sources":["../../src/components/XStack.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,IAAI,EAAkB,MAAM,QAAQ,CAAC;AAI9C,SAAS,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,EAAe;IACvD,OAAO,CACL,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,eAC1B,SAAS,EACnB,GAAG,EAAE,GAAG,KACJ,KAAK,GACT,CACH,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"XStack.js","sourceRoot":"","sources":["../../src/components/XStack.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAwB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAkB,MAAM,QAAQ,CAAC;AAW9C,SAAS,MAAM,CAAC,EACd,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,GAAG,KAAK,EACI;IACZ,OAAO,CACL,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,eAC1B,SAAS,EACnB,GAAG,EAAE,GAAG,KACJ,KAAK,YAER,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,GACrC,CACR,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -1,6 +1,14 @@
1
+ import { type RenderSeparator } from './_internal/separate.js';
1
2
  import { type FlexProps } from './Flex.js';
2
- type YStackProps = Omit<FlexProps, 'direction'>;
3
- declare function YStack({ className, ref, ...props }: YStackProps): import("react").JSX.Element;
3
+ type YStackProps = Omit<FlexProps, 'direction'> & {
4
+ /**
5
+ * Renders a separator between each two children: a decorative `Separator`
6
+ * for `true`, or what a function returns, given the separator's index and
7
+ * its orientation. Give a decorative node `aria-hidden`.
8
+ */
9
+ separator?: boolean | RenderSeparator;
10
+ };
11
+ declare function YStack({ children, className, ref, separator, ...props }: YStackProps): import("react").JSX.Element;
4
12
  export { YStack };
5
13
  export type { YStackProps };
6
14
  //# sourceMappingURL=YStack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"YStack.d.ts","sourceRoot":"","sources":["../../src/components/YStack.tsx"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9C,KAAK,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAEhD,iBAAS,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,EAAE,WAAW,+BASxD;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"YStack.d.ts","sourceRoot":"","sources":["../../src/components/YStack.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAY,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9C,KAAK,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG;IAChD;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;CACvC,CAAC;AAEF,iBAAS,MAAM,CAAC,EACd,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,GAAG,KAAK,EACT,EAAE,WAAW,+BAWb;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cn } from '../lib/utils.js';
3
+ import { separate } from './_internal/separate.js';
3
4
  import { Flex } from './Flex.js';
4
- function YStack({ className, ref, ...props }) {
5
- return (_jsx(Flex, { className: cn('flex-col', className), "data-slot": "y-stack", ref: ref, ...props }));
5
+ function YStack({ children, className, ref, separator, ...props }) {
6
+ return (_jsx(Flex, { className: cn('flex-col', className), "data-slot": "y-stack", ref: ref, ...props, children: separate(children, 'horizontal', separator) }));
6
7
  }
7
8
  export { YStack };
8
9
  //# sourceMappingURL=YStack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"YStack.js","sourceRoot":"","sources":["../../src/components/YStack.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,IAAI,EAAkB,MAAM,QAAQ,CAAC;AAI9C,SAAS,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,EAAe;IACvD,OAAO,CACL,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,eAC1B,SAAS,EACnB,GAAG,EAAE,GAAG,KACJ,KAAK,GACT,CACH,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"YStack.js","sourceRoot":"","sources":["../../src/components/YStack.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAwB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAkB,MAAM,QAAQ,CAAC;AAW9C,SAAS,MAAM,CAAC,EACd,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,GAAG,KAAK,EACI;IACZ,OAAO,CACL,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,eAC1B,SAAS,EACnB,GAAG,EAAE,GAAG,KACJ,KAAK,YAER,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,SAAS,CAAC,GACvC,CACR,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ export type RenderSeparator = (details: {
3
+ index: number;
4
+ orientation: SeparatorOrientation;
5
+ }) => React.ReactNode;
6
+ type SeparatorOrientation = 'horizontal' | 'vertical';
7
+ /**
8
+ * Puts a separator between each two children: a decorative `Separator` for
9
+ * `true`, or what a function returns.
10
+ */
11
+ export declare function separate(children: React.ReactNode, orientation: SeparatorOrientation, separator: boolean | RenderSeparator | undefined): string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element[] | null | undefined;
12
+ export {};
13
+ //# sourceMappingURL=separate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"separate.d.ts","sourceRoot":"","sources":["../../../src/components/_internal/separate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,oBAAoB,CAAC;CACnC,KAAK,KAAK,CAAC,SAAS,CAAC;AAEtB,KAAK,oBAAoB,GAAG,YAAY,GAAG,UAAU,CAAC;AAMtD;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,WAAW,EAAE,oBAAoB,EACjC,SAAS,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,8WAejD"}
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { Separator } from '../Separator.js';
4
+ const renderSeparator = ({ orientation }) => (_jsx(Separator, { "aria-hidden": true, orientation: orientation }));
5
+ /**
6
+ * Puts a separator between each two children: a decorative `Separator` for
7
+ * `true`, or what a function returns.
8
+ */
9
+ export function separate(children, orientation, separator) {
10
+ if (!separator)
11
+ return children;
12
+ const render = separator === true ? renderSeparator : separator;
13
+ // `toArray` drops empty children; `map` then keys each fragment by its child.
14
+ return React.Children.map(React.Children.toArray(children), (child, index) => (_jsxs(React.Fragment, { children: [index > 0 && render({ index: index - 1, orientation }), child] })));
15
+ }
16
+ //# sourceMappingURL=separate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"separate.js","sourceRoot":"","sources":["../../../src/components/_internal/separate.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzC,MAAM,eAAe,GAAoB,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAC5D,KAAC,SAAS,yBAAa,WAAW,EAAE,WAAW,GAAI,CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAyB,EACzB,WAAiC,EACjC,SAAgD;IAEhD,IAAI,CAAC,SAAS;QAAE,OAAO,QAAQ,CAAC;IAChC,MAAM,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;IAEhE,8EAA8E;IAC9E,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CACvB,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,EAChC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAChB,MAAC,KAAK,CAAC,QAAQ,eACZ,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,EACtD,KAAK,IACS,CAClB,CACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickle-ui/react",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.13",
4
4
  "type": "module",
5
5
  "description": "React component library built with Base UI, shadcn/ui, Tailwind CSS, and reui.",
6
6
  "main": "dist/index.js",
@@ -53,6 +53,14 @@ export const All: StoryDefinition = {
53
53
  </XStack>
54
54
  </Story.Section>
55
55
 
56
+ <Story.Section title="Separators">
57
+ <XStack gap={3} separator>
58
+ <Item>Groceries</Item>
59
+ <Item>Chores</Item>
60
+ <Item>Calendar</Item>
61
+ </XStack>
62
+ </Story.Section>
63
+
56
64
  <Story.Section title="Responsive override">
57
65
  <XStack className="max-sm:flex-col" gap={3}>
58
66
  <Item>Horizontal by default</Item>
@@ -30,4 +30,117 @@ describe('XStack', () => {
30
30
  expect(element.tagName.toLowerCase()).toBe('nav');
31
31
  expect(element).toHaveClass('max-md:flex-col');
32
32
  });
33
+
34
+ describe('separator', () => {
35
+ const separators = (container: HTMLElement) =>
36
+ container.querySelectorAll('[data-slot="separator"]');
37
+
38
+ it('renders no separator by default', () => {
39
+ const { container } = render(
40
+ <XStack>
41
+ <span>A</span>
42
+ <span>B</span>
43
+ </XStack>,
44
+ );
45
+
46
+ expect(separators(container)).toHaveLength(0);
47
+ });
48
+
49
+ it('renders a separator between each two children', () => {
50
+ const { container } = render(
51
+ <XStack separator>
52
+ <span>A</span>
53
+ <span>B</span>
54
+ <span>C</span>
55
+ </XStack>,
56
+ );
57
+
58
+ const stack = container.firstElementChild!;
59
+ expect(
60
+ [...stack.children].map(
61
+ (child) => child.getAttribute('data-slot') ?? child.textContent,
62
+ ),
63
+ ).toEqual(['A', 'separator', 'B', 'separator', 'C']);
64
+ });
65
+
66
+ it('renders no separator around a single child', () => {
67
+ const { container } = render(
68
+ <XStack separator>
69
+ <span>A</span>
70
+ </XStack>,
71
+ );
72
+
73
+ expect(separators(container)).toHaveLength(0);
74
+ });
75
+
76
+ it('skips falsy children', () => {
77
+ const { container } = render(
78
+ <XStack separator>
79
+ {null}
80
+ <span>A</span>
81
+ {false}
82
+ {undefined}
83
+ <span>B</span>
84
+ {null}
85
+ </XStack>,
86
+ );
87
+
88
+ expect(separators(container)).toHaveLength(1);
89
+ });
90
+
91
+ it('hides the separators from assistive technology', () => {
92
+ render(
93
+ <XStack role="list" separator>
94
+ <span role="listitem">A</span>
95
+ <span role="listitem">B</span>
96
+ </XStack>,
97
+ );
98
+
99
+ expect(screen.queryAllByRole('separator')).toHaveLength(0);
100
+ expect(
101
+ screen.getAllByRole('separator', { hidden: true })[0],
102
+ ).toHaveAttribute('aria-hidden', 'true');
103
+ expect(screen.getByRole('list').children).toHaveLength(3);
104
+ });
105
+
106
+ it('renders vertical separators', () => {
107
+ const { container } = render(
108
+ <XStack separator>
109
+ <span>A</span>
110
+ <span>B</span>
111
+ </XStack>,
112
+ );
113
+
114
+ expect(separators(container)[0]).toHaveAttribute(
115
+ 'data-orientation',
116
+ 'vertical',
117
+ );
118
+ });
119
+
120
+ it('renders the node a separator function returns', () => {
121
+ const { container } = render(
122
+ <XStack
123
+ separator={({ index, orientation }) => (
124
+ <hr data-orientation={orientation} data-testid={`rule-${index}`} />
125
+ )}
126
+ >
127
+ <span>A</span>
128
+ <span>B</span>
129
+ <span>C</span>
130
+ </XStack>,
131
+ );
132
+
133
+ const stack = container.firstElementChild!;
134
+ expect(
135
+ [...stack.children].map(
136
+ (child) => child.getAttribute('data-testid') ?? child.textContent,
137
+ ),
138
+ ).toEqual(['A', 'rule-0', 'B', 'rule-1', 'C']);
139
+ expect(screen.getByTestId('rule-0')).toHaveAttribute(
140
+ 'data-orientation',
141
+ 'vertical',
142
+ );
143
+ expect(separators(container)).toHaveLength(0);
144
+ });
145
+ });
33
146
  });
@@ -1,16 +1,32 @@
1
1
  import { cn } from '../lib/utils';
2
+ import { type RenderSeparator, separate } from './_internal/separate';
2
3
  import { Flex, type FlexProps } from './Flex';
3
4
 
4
- type XStackProps = Omit<FlexProps, 'direction'>;
5
+ type XStackProps = Omit<FlexProps, 'direction'> & {
6
+ /**
7
+ * Renders a separator between each two children: a decorative `Separator`
8
+ * for `true`, or what a function returns, given the separator's index and
9
+ * its orientation. Give a decorative node `aria-hidden`.
10
+ */
11
+ separator?: boolean | RenderSeparator;
12
+ };
5
13
 
6
- function XStack({ className, ref, ...props }: XStackProps) {
14
+ function XStack({
15
+ children,
16
+ className,
17
+ ref,
18
+ separator,
19
+ ...props
20
+ }: XStackProps) {
7
21
  return (
8
22
  <Flex
9
23
  className={cn('flex-row', className)}
10
24
  data-slot="x-stack"
11
25
  ref={ref}
12
26
  {...props}
13
- />
27
+ >
28
+ {separate(children, 'vertical', separator)}
29
+ </Flex>
14
30
  );
15
31
  }
16
32
 
@@ -1,6 +1,7 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite';
2
2
 
3
3
  import { Story } from './_internal/Story';
4
+ import { Separator } from './Separator';
4
5
  import { Text } from './Text';
5
6
  import { YStack } from './YStack';
6
7
 
@@ -54,6 +55,31 @@ export const All: StoryDefinition = {
54
55
  </YStack>
55
56
  </Story.Section>
56
57
 
58
+ <Story.Section title="Separators">
59
+ <YStack gap={3} separator>
60
+ <Item>Groceries</Item>
61
+ <Item>Chores</Item>
62
+ <Item>Calendar</Item>
63
+ </YStack>
64
+ </Story.Section>
65
+
66
+ <Story.Section title="Custom separators">
67
+ <YStack
68
+ gap={3}
69
+ separator={({ orientation }) => (
70
+ <Separator
71
+ aria-hidden
72
+ className="bg-primary"
73
+ orientation={orientation}
74
+ />
75
+ )}
76
+ >
77
+ <Item>Groceries</Item>
78
+ <Item>Chores</Item>
79
+ <Item>Calendar</Item>
80
+ </YStack>
81
+ </Story.Section>
82
+
57
83
  <Story.Section title="Responsive override">
58
84
  <YStack className="md:flex-row" gap={3}>
59
85
  <Item>Vertical by default</Item>
@@ -28,4 +28,19 @@ describe('YStack', () => {
28
28
  expect(element).toHaveClass('flex-row', 'custom-class');
29
29
  expect(element).not.toHaveClass('flex-col');
30
30
  });
31
+
32
+ it('renders horizontal separators between its children', () => {
33
+ const { container } = render(
34
+ <YStack separator>
35
+ <span>A</span>
36
+ <span>B</span>
37
+ <span>C</span>
38
+ </YStack>,
39
+ );
40
+
41
+ const separators = container.querySelectorAll('[data-slot="separator"]');
42
+ expect(separators).toHaveLength(2);
43
+ expect(separators[0]).toHaveAttribute('data-orientation', 'horizontal');
44
+ expect(separators[0]).toHaveAttribute('aria-hidden', 'true');
45
+ });
31
46
  });
@@ -1,16 +1,32 @@
1
1
  import { cn } from '../lib/utils';
2
+ import { type RenderSeparator, separate } from './_internal/separate';
2
3
  import { Flex, type FlexProps } from './Flex';
3
4
 
4
- type YStackProps = Omit<FlexProps, 'direction'>;
5
+ type YStackProps = Omit<FlexProps, 'direction'> & {
6
+ /**
7
+ * Renders a separator between each two children: a decorative `Separator`
8
+ * for `true`, or what a function returns, given the separator's index and
9
+ * its orientation. Give a decorative node `aria-hidden`.
10
+ */
11
+ separator?: boolean | RenderSeparator;
12
+ };
5
13
 
6
- function YStack({ className, ref, ...props }: YStackProps) {
14
+ function YStack({
15
+ children,
16
+ className,
17
+ ref,
18
+ separator,
19
+ ...props
20
+ }: YStackProps) {
7
21
  return (
8
22
  <Flex
9
23
  className={cn('flex-col', className)}
10
24
  data-slot="y-stack"
11
25
  ref={ref}
12
26
  {...props}
13
- />
27
+ >
28
+ {separate(children, 'horizontal', separator)}
29
+ </Flex>
14
30
  );
15
31
  }
16
32
 
@@ -0,0 +1,38 @@
1
+ import * as React from 'react';
2
+
3
+ import { Separator } from '../Separator';
4
+
5
+ export type RenderSeparator = (details: {
6
+ index: number;
7
+ orientation: SeparatorOrientation;
8
+ }) => React.ReactNode;
9
+
10
+ type SeparatorOrientation = 'horizontal' | 'vertical';
11
+
12
+ const renderSeparator: RenderSeparator = ({ orientation }) => (
13
+ <Separator aria-hidden orientation={orientation} />
14
+ );
15
+
16
+ /**
17
+ * Puts a separator between each two children: a decorative `Separator` for
18
+ * `true`, or what a function returns.
19
+ */
20
+ export function separate(
21
+ children: React.ReactNode,
22
+ orientation: SeparatorOrientation,
23
+ separator: boolean | RenderSeparator | undefined,
24
+ ) {
25
+ if (!separator) return children;
26
+ const render = separator === true ? renderSeparator : separator;
27
+
28
+ // `toArray` drops empty children; `map` then keys each fragment by its child.
29
+ return React.Children.map(
30
+ React.Children.toArray(children),
31
+ (child, index) => (
32
+ <React.Fragment>
33
+ {index > 0 && render({ index: index - 1, orientation })}
34
+ {child}
35
+ </React.Fragment>
36
+ ),
37
+ );
38
+ }