Skip to content

Commit 89bfb5d

Browse files
Component: List (codesandbox#3312)
* add List with 2 items * more stories * fix lint Co-authored-by: Sara Vieira <[email protected]>
1 parent 593d01b commit 89bfb5d

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

packages/components/src/components/Element/element.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
decorators: [LayoutDecorator],
99
};
1010

11-
export const Basic = () => <Element>content</Element>;
11+
export const Basic = () => <Element css={{ color: 'pink' }}>content</Element>;
1212

1313
export const AsProp = () => <Element as="span">content</Element>;
1414

packages/components/src/components/Element/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export const Element = styled.div<{
77
marginY?: number;
88
marginBottom?: number;
99
marginTop?: number; // prefer margin bottom to top
10+
css?: Object;
1011
}>(props =>
1112
css({
1213
margin: props.margin || null,
1314
marginX: props.marginX || null,
1415
marginY: props.marginY || null,
1516
marginBottom: props.marginBottom || null,
1617
marginTop: props.marginTop || null,
18+
...(props.css || {}),
1719
})
1820
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import styled from 'styled-components';
2+
import css from '@styled-system/css';
3+
import { Element } from '../Element';
4+
import { Stack } from '../Stack';
5+
6+
export const List = styled(Element).attrs({ as: 'ul' })(
7+
css({
8+
listStyle: 'none',
9+
paddingLeft: 0,
10+
})
11+
);
12+
13+
export const ListItem = styled(Stack).attrs({
14+
as: 'li',
15+
align: 'center',
16+
})(
17+
css({
18+
height: 8,
19+
paddingX: 2,
20+
})
21+
);
22+
23+
export const ListAction = styled(ListItem)(
24+
css({
25+
':hover': {
26+
cursor: 'pointer',
27+
backgroundColor: 'sideBar.hoverBackground',
28+
},
29+
':focus-within': {
30+
backgroundColor: 'sideBar.hoverBackground',
31+
},
32+
})
33+
);
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import React from 'react';
2+
import { action } from '@storybook/addon-actions';
3+
import { List, ListItem, ListAction } from '.';
4+
5+
export default {
6+
title: 'components/List',
7+
component: List,
8+
};
9+
10+
// replace the text inside with Text variants when available
11+
export const ListItems = () => (
12+
<List>
13+
<ListItem>IBM Plex</ListItem>
14+
<ListItem>Inter</ListItem>
15+
<ListItem>Roboto</ListItem>
16+
</List>
17+
);
18+
19+
export const withJustify = () => (
20+
<List style={{ width: 300, border: '1px solid white' }}>
21+
<ListItem justify="space-between">
22+
{/* eslint-disable-next-line */}
23+
<label htmlFor="frozen">Frozen</label>
24+
<input type="checkbox" id="frozen" />
25+
</ListItem>
26+
<ListItem justify="space-between">
27+
<span>Template</span>
28+
<a
29+
href="https://codesandbox.io/s/react-new"
30+
target="_blank"
31+
rel="noopener noreferrer"
32+
>
33+
React
34+
</a>
35+
</ListItem>
36+
<ListItem justify="space-between">
37+
<span>Environment</span>
38+
<a
39+
href="https://github.com/facebookincubator/create-react-app"
40+
target="_blank"
41+
rel="noopener noreferrer"
42+
>
43+
create-react-app
44+
</a>
45+
</ListItem>
46+
</List>
47+
);
48+
49+
const gitIcon = (
50+
<svg
51+
width="16"
52+
height="16"
53+
viewBox="0 0 16 16"
54+
fill="none"
55+
xmlns="http://www.w3.org/2000/svg"
56+
>
57+
<path
58+
fillRule="evenodd"
59+
clipRule="evenodd"
60+
d="M2 1H14C14.5523 1 15 1.44772 15 2V14C15 14.5523 14.5523 15 14 15H2C1.44772 15 1 14.5523 1 14V2C1 1.44772 1.44772 1 2 1ZM0 2C0 0.895431 0.895431 0 2 0H14C15.1046 0 16 0.895431 16 2V14C16 15.1046 15.1046 16 14 16H2C0.895431 16 0 15.1046 0 14V2ZM9 12H7V9H4V7H7V4H9V7H12V9H9V12Z"
61+
fill="#30D158"
62+
/>
63+
</svg>
64+
);
65+
66+
export const ListActions = () => (
67+
<List style={{ width: 300, border: '1px solid white' }}>
68+
<ListAction onClick={action('row clicked')} gap={2}>
69+
{gitIcon} <span>src/index.js</span>
70+
</ListAction>
71+
<ListAction onClick={action('row clicked')} gap={2}>
72+
{gitIcon} <span>src/style.css</span>
73+
</ListAction>
74+
<ListAction onClick={action('row clicked')} gap={2}>
75+
{gitIcon} <span>package.json</span>
76+
</ListAction>
77+
</List>
78+
);
79+
80+
// TODO: Replace a tags with Link component when ready
81+
export const ListActionWithMultipleActions = () => (
82+
<List style={{ width: 300, border: '1px solid white' }}>
83+
<ListAction justify="space-between">
84+
<a
85+
href="https://rsms.me/inter/inter.css"
86+
target="_blank"
87+
rel="noopener noreferrer"
88+
>
89+
IBM Plex
90+
</a>
91+
<button type="button">×</button>
92+
</ListAction>
93+
<ListAction justify="space-between">
94+
<a
95+
href="https://rsms.me/inter/inter.css"
96+
target="_blank"
97+
rel="noopener noreferrer"
98+
>
99+
Inter
100+
</a>
101+
<button type="button">×</button>
102+
</ListAction>
103+
<ListAction justify="space-between">
104+
<a
105+
href="https://rsms.me/inter/inter.css"
106+
target="_blank"
107+
rel="noopener noreferrer"
108+
>
109+
Roboto
110+
</a>
111+
<button type="button">×</button>
112+
</ListAction>
113+
</List>
114+
);

0 commit comments

Comments
 (0)