-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add settings components [LW-10713] #47
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { ReactNode } from 'react'; | ||
|
||
import { Box } from '../box'; | ||
import { Flex } from '../flex'; | ||
import { Text } from '../text'; | ||
|
||
import * as styles from './setting.css'; | ||
|
||
interface SettingsItemProps { | ||
addon?: ReactNode; | ||
description: ReactNode; | ||
onClick?: () => void; | ||
testId?: string; | ||
title?: ReactNode | string; | ||
} | ||
|
||
export const Setting = ({ | ||
description, | ||
addon, | ||
onClick, | ||
testId = 'setting', | ||
title, | ||
}: SettingsItemProps): React.ReactElement => ( | ||
<Box mb="$32" className={styles.root}> | ||
<div className={styles.separator} /> | ||
<Box | ||
pt="$32" | ||
pb="$32" | ||
pl="$16" | ||
pr="$16" | ||
className={styles.content} | ||
onClick={onClick} | ||
data-testid={testId} | ||
> | ||
{title ? ( | ||
<Box> | ||
<Text.Body.Large weight="$semibold" data-testid={`${testId}-title`}> | ||
{title} | ||
</Text.Body.Large> | ||
</Box> | ||
) : null} | ||
<Flex justifyContent="space-between"> | ||
<Text.Body.Normal data-testid={`${testId}-description`}> | ||
{description} | ||
</Text.Body.Normal> | ||
<div data-testid={`${testId}-addon`}>{addon}</div> | ||
</Flex> | ||
</Box> | ||
</Box> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { style, vars } from '../../design-tokens'; | ||
|
||
export const root = style({}); | ||
|
||
export const separator = style({ | ||
width: '100%', | ||
height: 1, | ||
background: vars.colors.$settings_item_separator_color, | ||
selectors: { | ||
[`${root}:first-of-type &`]: { | ||
background: 'none', | ||
}, | ||
[`${root}:hover &`]: { | ||
background: 'none', | ||
}, | ||
}, | ||
}); | ||
|
||
Comment on lines
+5
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestions: Maybe you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah good point, i thought that it might be more work to make it react to these selectors then? |
||
export const content = style({ | ||
selectors: { | ||
'&:hover': { | ||
background: vars.colors.$settings_item_hover_bgColor, | ||
borderRadius: vars.spacing.$16, | ||
cursor: 'pointer', | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
|
||
import { Box } from '../box'; | ||
import { Text } from '../text'; | ||
|
||
import * as styles from './settings-section.css'; | ||
|
||
interface SettingsCardProps { | ||
title: string; | ||
testId?: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const SettingsSection = ({ | ||
children, | ||
title, | ||
testId = 'settings-section', | ||
}: SettingsCardProps): React.ReactElement => ( | ||
<div data-testid="settings-card" className={styles.root}> | ||
<Box pl="$16" mb="$16"> | ||
<Text.SubHeading data-testid={`${testId}-heading`}> | ||
{title} | ||
</Text.SubHeading> | ||
</Box> | ||
<div>{children}</div> | ||
</div> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { style, vars } from '../../design-tokens'; | ||
|
||
export const root = style([ | ||
{ | ||
width: vars.spacing.$fill, | ||
marginBottom: vars.spacing.$40, | ||
}, | ||
]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
|
||
import { action } from '@storybook/addon-actions'; | ||
import type { Meta } from '@storybook/react'; | ||
|
||
import * as Button from '../buttons/'; | ||
import { page, Section, Variants } from '../decorators'; | ||
import { Flex } from '../flex'; | ||
import { Grid, Cell } from '../grid'; | ||
|
||
import { Setting } from './setting.component'; | ||
import { SettingsSection } from './settings-section.component'; | ||
|
||
export default { | ||
title: 'Settings/Overview', | ||
|
||
decorators: [ | ||
page({ | ||
title: 'Settings Components', | ||
subtitle: | ||
'These components can be used to render the sections and items on a settings page.', | ||
}), | ||
], | ||
} as Meta; | ||
|
||
export const Overview = (): React.JSX.Element => ( | ||
<div id="storybook"> | ||
<Grid columns="$1"> | ||
<Cell> | ||
<Section title="Usage Example"> | ||
<Variants.Table> | ||
<Variants.Row> | ||
<Variants.Cell> | ||
<Flex justifyContent="center" w="$fill"> | ||
<SettingsSection title="Example Setting"> | ||
<Setting | ||
description="this is an example of a first setting" | ||
title="First Setting" | ||
onClick={action('first setting clicked')} | ||
/> | ||
<Setting | ||
description="this is an example of a second setting" | ||
title="Second Setting" | ||
onClick={action('second setting clicked')} | ||
addon={<Button.CallToAction label="test addon" />} | ||
/> | ||
</SettingsSection> | ||
</Flex> | ||
</Variants.Cell> | ||
</Variants.Row> | ||
</Variants.Table> | ||
</Section> | ||
</Cell> | ||
</Grid> | ||
</div> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: can we at least allow classname or something to override this ? Maybe it won't be applicable in all the places.
Or, remove a wrapper Box and control it from the parent if necessary?
Separator is an end-app choice.
Just thinking loudly... WDYT?