-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.tsx
199 lines (166 loc) · 4.63 KB
/
Main.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import * as React from 'react';
import styled from 'styled-components';
import { Stack, Spacer, Divider } from '../../src';
import { media } from '../theme';
export default function Main() {
const items = [1, 2, 3, 4, 5, 6, 7, 8];
return (
<Wrapper>
<Stack spacing="medium">
<Title>Vertical Stack</Title>
{items.slice(0, 4).map(i => (
<Box key={i} bg="tomato">
{i}
</Box>
))}
<Stack spacing={{ _: 'small', sm: 'xxlarge' }}>
<Box bg="bisque">1</Box>
<Box bg="bisque">2</Box>
<Spacer size="medium" />
<Box bg="bisque">3</Box>
</Stack>
<Spacer size="xxlarge" />
<Title>Horizontal Stack</Title>
<Stack axis="x" spacing="normal" fluid={{ _: false, sm: true }}>
{items.map(i => (
<Box key={i} bg="gold">
{i}
</Box>
))}
</Stack>
<Stack axis="x">
<Box bg="aquamarine">1</Box>
<Spacer axis="x" size="large" />
<Box bg="aquamarine">2</Box>
<Box bg="aquamarine">3</Box>
<Spacer axis="x" size="xsmall" />
<Box bg="aquamarine">4</Box>
</Stack>
<ScrollingStack>
{items.map(i => (
<Box key={i} bg="seagreen">
{i}
</Box>
))}
</ScrollingStack>
<Spacer size="xxlarge" />
<Title>Fluid Stack</Title>
{/* Since fluid Stack uses negative margins we need a wrapper for padding/border etc. */}
<FluidStackWrapper>
<FluidStack>
{items.map(i => (
<Box key={i} bg="hotpink">
{i}
</Box>
))}
</FluidStack>
</FluidStackWrapper>
<Spacer size="xxlarge" />
<Title>Alignment inside Stack</Title>
<Stack axis={{ _: 'x', sm: 'y' }} spacing="large">
<Card>
<Stack align="center">
<Circle />
<PlaceholderText w="30%" />
<PlaceholderText w="80%" />
</Stack>
</Card>
<Card>
<Stack align="center">
<Circle />
<PlaceholderText w="60%" />
<PlaceholderText w="100%" />
</Stack>
</Card>
</Stack>
<Spacer size="xxlarge" />
<Title>Dividers</Title>
<Stack dividers>
<Box bg="turquoise">1</Box>
<Box bg="turquoise">2</Box>
<Divider size="large" />
<Box bg="turquoise">3</Box>
</Stack>
<Divider size="large" color="grey-90" />
<Stack
axis={{ _: 'x', sm: 'y', md: 'x', lgUp: 'y', xl: 'x' }}
align="center"
justify={{
_: 'space-between',
sm: 'flex-start',
lgDown: 'space-around',
xl: 'flex-end',
}}
spacing={{ _: 'large', mdDown: 'small' }}
>
<Box bg="powderblue">1 responsive</Box>
<Box bg="powderblue">2 responsive</Box>
<Box bg="powderblue">3 responsive</Box>
</Stack>
</Stack>
</Wrapper>
);
}
const BOX_SIZE = 40;
const ScrollingStack = styled(Stack).attrs({ axis: 'x' })`
max-width: 220px;
overflow: auto;
border: 1px solid #ccc;
border-radius: 5px;
padding: ${p => p.theme.spacing.small};
&:after {
content: '';
flex-shrink: 0;
width: 8px;
}
`;
const FluidStackWrapper = styled.div`
padding: ${p => p.theme.spacing.small};
border: 1px solid #ccc;
border-radius: 5px;
align-self: flex-start;
${media.sm`
padding: ${p => p.theme.spacing.medium};
`}
`;
const FluidStack = styled(Stack).attrs({ axis: 'x', fluid: true })`
max-width: calc(${BOX_SIZE}px * 3 + ${p => p.theme.spacing.normal} * 3);
`;
const Wrapper = styled.div`
padding: ${p => p.theme.spacing.large};
`;
const Title = styled.h1`
margin: 0;
font-size: 32px;
`;
const Box = styled.div<{ bg: string }>`
min-width: ${BOX_SIZE}px;
min-height: ${BOX_SIZE}px;
padding: 8px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
flex: none;
background-color: ${p => p.bg};
font-weight: 500;
`;
const Card = styled.div`
padding: ${p => p.theme.spacing.medium};
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f7f7f7;
min-width: 120px;
`;
const Circle = styled.div`
width: 72px;
height: 72px;
border-radius: 50%;
background: linear-gradient(to bottom, #ccc, #ddd);
`;
const PlaceholderText = styled.span<{ w: string }>`
width: ${p => p.w};
height: 8px;
border-radius: 99px;
background: linear-gradient(to right, #ccc, #ddd);
`;