Skip to content

Commit 51c71ab

Browse files
committed
feat: add settings components [LW-10713]
1 parent 102c3f0 commit 51c71ab

File tree

8 files changed

+177
-0
lines changed

8 files changed

+177
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, { ReactNode } from 'react';
2+
3+
import { Box } from '../box';
4+
import { Flex } from '../flex';
5+
import { Text } from '../text';
6+
7+
import * as styles from './setting.css';
8+
9+
interface SettingsItemProps {
10+
addon?: ReactNode;
11+
description: ReactNode;
12+
onClick?: () => void;
13+
testId?: string;
14+
title?: ReactNode | string;
15+
}
16+
17+
export const Setting = ({
18+
description,
19+
addon,
20+
onClick,
21+
testId = 'setting',
22+
title,
23+
}: SettingsItemProps): React.ReactElement => (
24+
<Box mb="$32" className={styles.root}>
25+
<div className={styles.separator} />
26+
<Box
27+
pt="$32"
28+
pb="$32"
29+
pl="$16"
30+
pr="$16"
31+
className={styles.content}
32+
onClick={onClick}
33+
data-testid={testId}
34+
>
35+
{title ? (
36+
<Box>
37+
<Text.Body.Large weight="$semibold" data-testid={`${testId}-title`}>
38+
{title}
39+
</Text.Body.Large>
40+
</Box>
41+
) : null}
42+
<Flex justifyContent="space-between">
43+
<Text.Body.Normal data-testid={`${testId}-description`}>
44+
{description}
45+
</Text.Body.Normal>
46+
<div data-testid={`${testId}-addon`}>{addon}</div>
47+
</Flex>
48+
</Box>
49+
</Box>
50+
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { style, vars } from '../../design-tokens';
2+
3+
export const root = style({});
4+
5+
export const separator = style({
6+
width: '100%',
7+
height: 1,
8+
background: vars.colors.$settings_item_separator_color,
9+
selectors: {
10+
[`${root}:first-of-type &`]: {
11+
background: 'none',
12+
},
13+
[`${root}:hover &`]: {
14+
background: 'none',
15+
},
16+
},
17+
});
18+
19+
export const content = style({
20+
selectors: {
21+
'&:hover': {
22+
background: vars.colors.$settings_item_hover_bgColor,
23+
borderRadius: vars.spacing.$16,
24+
cursor: 'pointer',
25+
},
26+
},
27+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
3+
import { Box } from '../box';
4+
import { Text } from '../text';
5+
6+
import * as styles from './settings-section.css';
7+
8+
interface SettingsCardProps {
9+
title: string;
10+
testId?: string;
11+
children: React.ReactNode;
12+
}
13+
14+
export const SettingsSection = ({
15+
children,
16+
title,
17+
testId = 'settings-section',
18+
}: SettingsCardProps): React.ReactElement => (
19+
<div data-testid="settings-card" className={styles.root}>
20+
<Box pl="$16" mb="$16">
21+
<Text.SubHeading data-testid={`${testId}-heading`}>
22+
{title}
23+
</Text.SubHeading>
24+
</Box>
25+
<div>{children}</div>
26+
</div>
27+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { style, vars } from '../../design-tokens';
2+
3+
export const root = style([
4+
{
5+
width: vars.spacing.$fill,
6+
marginBottom: vars.spacing.$40,
7+
},
8+
]);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
3+
import { action } from '@storybook/addon-actions';
4+
import type { Meta } from '@storybook/react';
5+
6+
import * as Button from '../buttons/';
7+
import { page, Section, Variants } from '../decorators';
8+
import { Flex } from '../flex';
9+
import { Grid, Cell } from '../grid';
10+
11+
import { Setting } from './setting.component';
12+
import { SettingsSection } from './settings-section.component';
13+
14+
export default {
15+
title: 'Settings/Overview',
16+
17+
decorators: [
18+
page({
19+
title: 'Settings Components',
20+
subtitle:
21+
'These components can be used to render the sections and items on a settings page.',
22+
}),
23+
],
24+
} as Meta;
25+
26+
export const Overview = (): React.JSX.Element => (
27+
<div id="storybook">
28+
<Grid columns="$1">
29+
<Cell>
30+
<Section title="Usage Example">
31+
<Variants.Table>
32+
<Variants.Row>
33+
<Variants.Cell>
34+
<Flex justifyContent="center" w="$fill">
35+
<SettingsSection title="Example Setting">
36+
<Setting
37+
description="this is an example of a first setting"
38+
title="First Setting"
39+
onClick={action('first setting clicked')}
40+
/>
41+
<Setting
42+
description="this is an example of a second setting"
43+
title="Second Setting"
44+
onClick={action('second setting clicked')}
45+
addon={<Button.CallToAction label="test addon" />}
46+
/>
47+
</SettingsSection>
48+
</Flex>
49+
</Variants.Cell>
50+
</Variants.Row>
51+
</Variants.Table>
52+
</Section>
53+
</Cell>
54+
</Grid>
55+
</div>
56+
);

src/design-tokens/colors.data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ export const colors = {
295295
$address_tag_own_bgColor: '',
296296
$address_tag_foreign_color: '',
297297
$address_tag_foreign_bgColor: '',
298+
299+
$settings_item_separator_color: '',
300+
$settings_item_hover_bgColor: '',
298301
};
299302

300303
export type Colors = typeof colors;

src/design-tokens/theme/dark-theme.css.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ const colors: Colors = {
394394
darkColorScheme.$primary_accent_purple,
395395
0.1,
396396
),
397+
398+
$settings_item_separator_color: darkColorScheme.$primary_mid_grey,
399+
$settings_item_hover_bgColor: darkColorScheme.$primary_mid_grey,
397400
};
398401

399402
const elevation: Elevation = {

src/design-tokens/theme/light-theme.css.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ const colors: Colors = {
422422
lightColorScheme.$primary_accent_purple,
423423
0.1,
424424
),
425+
426+
$settings_item_separator_color: lightColorScheme.$primary_light_grey_plus,
427+
$settings_item_hover_bgColor: lightColorScheme.$primary_light_grey,
425428
};
426429

427430
export const elevation: Elevation = {

0 commit comments

Comments
 (0)