Skip to content

Commit c18590a

Browse files
Merge pull request #292 from commitd/sh/layout
Layout components
2 parents 61a2a69 + f80a156 commit c18590a

38 files changed

+716
-185
lines changed

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
"@radix-ui/colors": "^0.1.8",
151151
"@radix-ui/react-accordion": "^1.0.0",
152152
"@radix-ui/react-alert-dialog": "^1.0.0",
153+
"@radix-ui/react-aspect-ratio": "^1.0.0",
153154
"@radix-ui/react-avatar": "^1.0.0",
154155
"@radix-ui/react-checkbox": "^1.0.0",
155156
"@radix-ui/react-context-menu": "^1.0.0",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Meta, Story } from '@storybook/react'
2+
import React, { ComponentProps, useState } from 'react'
3+
import { AspectRatio } from '.'
4+
import { Box } from '../Box'
5+
import { Card, CardBody, CardHeading, CardSubheading } from '../Card'
6+
import { Image } from '../Image'
7+
import { Inline } from '../Inline'
8+
import { Label } from '../Label'
9+
import { Slider } from '../Slider'
10+
import { Stack } from '../Stack'
11+
12+
export default {
13+
title: 'Components/AspectRatio',
14+
component: AspectRatio,
15+
} as Meta
16+
17+
export const Default: Story<ComponentProps<typeof AspectRatio>> = ({
18+
ratio = 9 / 16,
19+
...args
20+
}) => (
21+
<Card css={{ width: '50%' }}>
22+
<CardHeading>Photo by Damian Markutt</CardHeading>
23+
<CardSubheading>@wildandfree_photography</CardSubheading>
24+
<CardBody>
25+
{/* ratio={ 9 / 16} */}
26+
<AspectRatio ratio={ratio} {...args}>
27+
<Image
28+
src="https://images.unsplash.com/photo-1572302895496-a09d147fa902?w=300&dpr=2&q=80"
29+
alt="Photo by Damian Markutt @wildandfree_photography"
30+
/>
31+
</AspectRatio>
32+
</CardBody>
33+
</Card>
34+
)
35+
36+
/**
37+
* The ratio can be entered as a numerator and denominator to give comm0n values like `16 / 9`.
38+
*/
39+
export const Dynamic: Story = () => {
40+
const [numerator, setNumerator] = useState([9])
41+
const [denominator, setDenominator] = useState([16])
42+
43+
return (
44+
<Inline>
45+
<Box variant="wide">
46+
<Stack>
47+
<Label>
48+
Numerator
49+
<Slider value={numerator} onValueChange={setNumerator} />
50+
</Label>
51+
<Label>
52+
Denominator
53+
<Slider value={denominator} onValueChange={setDenominator} />
54+
</Label>
55+
</Stack>
56+
</Box>
57+
<Card css={{ width: '50%' }}>
58+
<CardHeading>Photo by Damian Markutt</CardHeading>
59+
<CardSubheading>@wildandfree_photography</CardSubheading>
60+
<CardBody>
61+
<AspectRatio ratio={numerator[0] / denominator[0]}>
62+
<Image
63+
src="https://images.unsplash.com/photo-1572302895496-a09d147fa902?w=300&dpr=2&q=80"
64+
alt="Photo by Damian Markutt @wildandfree_photography"
65+
/>
66+
</AspectRatio>
67+
</CardBody>
68+
</Card>
69+
</Inline>
70+
)
71+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { renderDark, renderLight } from 'test-utils'
3+
import { Default } from './AspectRatio.stories'
4+
5+
it('renders light without error', () => {
6+
const { asFragment } = renderLight(<Default />)
7+
expect(asFragment()).toBeDefined()
8+
})
9+
10+
it('renders dark without error', () => {
11+
const { asFragment } = renderDark(<Default />)
12+
expect(asFragment()).toBeDefined()
13+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Root } from '@radix-ui/react-aspect-ratio'
2+
3+
/**
4+
* AspectRatio can be used to display content with a fixed aspect ratio
5+
*/
6+
export const AspectRatio = Root
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './AspectRatio'

src/components/Button/Button.stories.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Meta, Story } from '@storybook/react'
22
import React, { ComponentProps } from 'react'
3-
import { Column, Grid, Row } from '../'
3+
import { Grid } from '../'
44
import { Variants } from '../../docs/util'
5+
import { Inline } from '../Inline'
6+
import { Stack } from '../Stack'
57
import { Button } from './Button'
68

79
export default {
@@ -61,16 +63,16 @@ export const Default: Story<ComponentProps<typeof Button>> = (args) => {
6163

6264
/* Three size options are available */
6365
export const Size: Story = () => (
64-
<Row css={{ gap: '$3', mb: '$3' }}>
66+
<Inline>
6567
<Button size="small">Small</Button>
6668
<Button size="default">Default</Button>
6769
<Button size="large">Large</Button>
68-
</Row>
70+
</Inline>
6971
)
7072

7173
/* Add `full-width` to make the button grow to take the full width */
7274
export const FullWidth: Story = () => (
73-
<Column css={{ gap: '$3' }}>
75+
<Stack>
7476
<Button full-width size="small">
7577
Small
7678
</Button>
@@ -80,7 +82,7 @@ export const FullWidth: Story = () => (
8082
<Button full-width size="large">
8183
Large
8284
</Button>
83-
</Column>
85+
</Stack>
8486
)
8587

8688
/* Three variants are supported,
@@ -90,16 +92,16 @@ export const FullWidth: Story = () => (
9092
* - `tertiary` use to pair with others as cancel or for icon buttons
9193
*/
9294
export const Variant: Story = () => (
93-
<Row css={{ gap: '$3' }}>
95+
<Inline>
9496
<Button variant="primary">Primary</Button>
9597
<Button variant="secondary">Secondary</Button>
9698
<Button variant="tertiary">Tertiary</Button>
97-
</Row>
99+
</Inline>
98100
)
99101

100102
/** If the action is destructive, say a delete or an action that cannot be undone, add the `destructive` flag */
101103
export const Destructive: Story = () => (
102-
<Row css={{ gap: '$3' }}>
104+
<Inline>
103105
<Button destructive variant="primary">
104106
Primary
105107
</Button>
@@ -109,12 +111,12 @@ export const Destructive: Story = () => (
109111
<Button destructive variant="tertiary">
110112
Tertiary
111113
</Button>
112-
</Row>
114+
</Inline>
113115
)
114116

115117
/** The `disabled` state is controlled in the standard way */
116118
export const Disabled: Story = () => (
117-
<Row css={{ gap: '$3' }}>
119+
<Inline>
118120
<Button disabled variant="primary">
119121
Primary
120122
</Button>
@@ -124,7 +126,7 @@ export const Disabled: Story = () => (
124126
<Button disabled variant="tertiary">
125127
Tertiary
126128
</Button>
127-
</Row>
129+
</Inline>
128130
)
129131

130132
/**

src/components/Card/Card.stories.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
CardLeadIn,
1111
CardSubheading,
1212
} from '.'
13-
import { Button, IconButton, Row, Svg, Text } from '../'
13+
import { Button, IconButton, Svg, Text } from '../'
14+
import { Inline } from '../Inline'
1415

1516
export default {
1617
title: 'Components/Card',
@@ -44,7 +45,7 @@ export const Default: Story = () => {
4445
*/
4546
export const Classic: Story = () => {
4647
return (
47-
<Row css={{ gap: '$3' }}>
48+
<Inline>
4849
<Card>
4950
<CardHeading>Default Card</CardHeading>
5051
<CardBody>
@@ -57,7 +58,7 @@ export const Classic: Story = () => {
5758
<Text>Lorem Ipsum is simply dummy text...</Text>
5859
</CardBody>
5960
</Card>
60-
</Row>
61+
</Inline>
6162
)
6263
}
6364

@@ -68,7 +69,7 @@ export const Classic: Story = () => {
6869
*/
6970
export const Outline: Story = () => {
7071
return (
71-
<Row css={{ gap: '$3' }}>
72+
<Inline>
7273
<Card variant="outline">
7374
<CardHeading>Outline</CardHeading>
7475
<CardBody>
@@ -81,7 +82,7 @@ export const Outline: Story = () => {
8182
<Text>Lorem Ipsum is simply dummy text...</Text>
8283
</CardBody>
8384
</Card>
84-
</Row>
85+
</Inline>
8586
)
8687
}
8788

@@ -92,7 +93,7 @@ export const Outline: Story = () => {
9293
*/
9394
export const Ghost: Story = () => {
9495
return (
95-
<Row css={{ gap: '$3' }}>
96+
<Inline>
9697
<Card variant="ghost">
9798
<CardHeading>Ghost</CardHeading>
9899
<CardBody>
@@ -105,7 +106,7 @@ export const Ghost: Story = () => {
105106
<Text>Lorem Ipsum is simply dummy text...</Text>
106107
</CardBody>
107108
</Card>
108-
</Row>
109+
</Inline>
109110
)
110111
}
111112

@@ -128,7 +129,7 @@ export const Body: Story = () => (
128129
* By default headings are just `div`s, use the `as` prop if the heading should be semantic.
129130
*/
130131
export const Headers: Story = () => (
131-
<Row css={{ flexWrap: 'wrap', gap: '$3' }}>
132+
<Inline wrap>
132133
<Card>
133134
<CardHeading>Heading</CardHeading>
134135
<CardBody>
@@ -149,7 +150,7 @@ export const Headers: Story = () => (
149150
<Text>Lorem Ipsum is simply dummy text...</Text>
150151
</CardBody>
151152
</Card>
152-
</Row>
153+
</Inline>
153154
)
154155

155156
/**
@@ -159,7 +160,7 @@ export const Headers: Story = () => (
159160
* If a more complex layout is required you can create your own.
160161
*/
161162
export const Actions: Story = () => (
162-
<Row css={{ flexWrap: 'wrap', gap: '$3' }}>
163+
<Inline wrap>
163164
<Card>
164165
<CardHeading>
165166
Heading
@@ -228,5 +229,5 @@ export const Actions: Story = () => (
228229
/>
229230
</CardActions>
230231
</Card>
231-
</Row>
232+
</Inline>
232233
)

src/components/Chip/Chip.stories.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { action } from '@storybook/addon-actions'
22
import { Meta, Story } from '@storybook/react'
33
import React from 'react'
44
import { Chip } from '.'
5-
import { Row } from '../'
65
import { Variants } from '../../docs/util'
6+
import { Inline } from '../Inline'
77

88
export default {
99
title: 'Components/Chip',
@@ -14,17 +14,17 @@ export const Default: Story = (args) => <Chip {...args}>Chip</Chip>
1414

1515
/** Chips are available in 2 sizes, `default` and `small` */
1616
export const Sizes: Story = () => (
17-
<>
17+
<Inline css={{ alignItems: 'center' }}>
1818
<Chip variant="info" size="small">
1919
New
2020
</Chip>
2121
<Chip variant="error">Error</Chip>
22-
</>
22+
</Inline>
2323
)
2424

2525
/** If an `onClose` prop is provided a close button is added and clicking calls the onClose` */
2626
export const Closable: Story = () => (
27-
<Row css={{ gap: '$3', alignItems: 'center' }}>
27+
<Inline css={{ alignItems: 'center' }}>
2828
<Chip variant="info" size="small" onClose={action('close')}>
2929
Close
3030
</Chip>
@@ -50,7 +50,7 @@ export const Closable: Story = () => (
5050
>
5151
Click
5252
</Chip>
53-
</Row>
53+
</Inline>
5454
)
5555

5656
export const All: Story = () => (
@@ -95,7 +95,7 @@ export const Interactive: Story = () => (
9595
)
9696

9797
export const Disabled: Story = () => (
98-
<Row css={{ gap: '$3', alignItems: 'center' }}>
98+
<Inline css={{ alignItems: 'center' }}>
9999
<Chip
100100
as="button"
101101
onClick={action('disabled')}
@@ -128,5 +128,5 @@ export const Disabled: Story = () => (
128128
>
129129
Disabled
130130
</Chip>
131-
</Row>
131+
</Inline>
132132
)

src/components/ComponentsProvider/ComponentsProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type ComponentsProviderProps = {
4242
*/
4343
viewport?: false | ToastViewportPropsWithoutChildren
4444
/**
45-
* By default the childre are put into their own stacking context to better separate the content from the portalled dialog elements. Set false to turn this off and controll it yourself.
45+
* By default the children are put into their own stacking context to better separate the content from the portalled dialog elements. Set false to turn this off and control it yourself.
4646
*/
4747
isolated?: boolean
4848
} & CSSProps

0 commit comments

Comments
 (0)