-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DS-17 - Layer Item + Radio + Radio Group updates
- Loading branch information
1 parent
85c6491
commit 76e5e91
Showing
14 changed files
with
351 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import LayerItem from '.' | ||
|
||
const meta = { | ||
title: 'Layers/LayerItem', | ||
component: LayerItem, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
} satisfies Meta<typeof LayerItem> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Switch: Story = { | ||
args: { | ||
id: 'switch-layer', | ||
label: 'Layer name', | ||
caption: 'Caption', | ||
}, | ||
} | ||
|
||
export const Radio: Story = { | ||
args: { | ||
id: 'radio-layer', | ||
label: 'Layer name', | ||
caption: 'Caption', | ||
variant: 'radio', | ||
}, | ||
} | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
id: 'switch-layer-1', | ||
label: 'Layer name', | ||
caption: 'Caption', | ||
isDisabled: true, | ||
}, | ||
} | ||
|
||
export const RadioDisabeld: Story = { | ||
args: { | ||
id: 'radio-layer', | ||
label: 'Layer name', | ||
caption: 'Caption', | ||
variant: 'radio', | ||
isDisabled: true, | ||
}, | ||
} | ||
|
||
export const NoInfoButton: Story = { | ||
args: { | ||
id: 'switch-layer-2', | ||
label: 'Layer name', | ||
caption: 'Caption', | ||
showInfoButton: false, | ||
}, | ||
} | ||
|
||
export const CustomInfoButtonLabel: Story = { | ||
args: { | ||
id: 'switch-layer-3', | ||
label: 'Layer name', | ||
caption: 'Caption', | ||
infoButtonLabel: 'Another Label', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { InfoIcon } from '@chakra-ui/icons' | ||
import Button from '../Button' | ||
import Switch from '../Switch' | ||
import Radio from '../Radio' | ||
import { LayerItemProps } from './types' | ||
import { | ||
LayerCaption, | ||
SwitchContainer, | ||
SwitchContent, | ||
LayerName, | ||
LayerItemContainer, | ||
} from './styled' | ||
|
||
const LayerItem = ({ | ||
id, | ||
label, | ||
caption, | ||
showInfoButton = true, | ||
infoButtonLabel = 'About data', | ||
variant = 'switch', | ||
isDisabled, | ||
onInfoClick, | ||
isDefaultSelected, | ||
}: LayerItemProps) => { | ||
const isSwitch = variant === 'switch' | ||
|
||
return ( | ||
<LayerItemContainer> | ||
{isSwitch ? ( | ||
<SwitchContainer> | ||
<SwitchContent> | ||
<LayerName>{label}</LayerName> | ||
<LayerCaption>{caption}</LayerCaption> | ||
</SwitchContent> | ||
<Switch | ||
id={id} | ||
isDisabled={isDisabled} | ||
isChecked={isDefaultSelected} | ||
/> | ||
</SwitchContainer> | ||
) : ( | ||
<div> | ||
<Radio label={label} value={id} isDisabled={isDisabled} /> | ||
<LayerCaption style={{ marginLeft: '28px' }}>{caption}</LayerCaption> | ||
</div> | ||
)} | ||
{showInfoButton ? ( | ||
<div | ||
style={{ | ||
marginTop: '8px', | ||
marginLeft: !isSwitch ? '28px' : 0, | ||
}} | ||
> | ||
<Button | ||
variant='secondary' | ||
label={infoButtonLabel} | ||
rightIcon={<InfoIcon />} | ||
size='small' | ||
onClick={onInfoClick} | ||
isDisabled={isDisabled} | ||
/> | ||
</div> | ||
) : null} | ||
</LayerItemContainer> | ||
) | ||
} | ||
|
||
export default LayerItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import styled from '@emotion/styled' | ||
import { getThemedColor, ThemeProps } from '../../lib/theme' | ||
|
||
export const LayerItemContainer = styled.div<{ | ||
isDisabled?: boolean | ||
theme?: ThemeProps | ||
}>` | ||
width: 268px; | ||
padding-bottom: 16px; | ||
margin-bottom: 16px; | ||
border-bottom: 1px solid | ||
${({ theme }) => getThemedColor(theme.colors, 'neutral', 300)}; | ||
` | ||
export const SwitchContainer = styled.div` | ||
display: flex; | ||
align-items: flex-start; | ||
justify-content: space-between; | ||
` | ||
export const SwitchContent = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
export const LayerName = styled.p<{ theme?: ThemeProps }>` | ||
font-size: 14px; | ||
font-weight: 400; | ||
line-height: 20px; | ||
text-align: left; | ||
color: ${({ theme }) => getThemedColor(theme.colors, 'neutral', 800)}; | ||
` | ||
export const LayerCaption = styled.p<{ theme?: ThemeProps }>` | ||
font-size: 12px; | ||
font-weight: 400; | ||
line-height: 16px; | ||
text-align: left; | ||
color: ${({ theme }) => getThemedColor(theme.colors, 'neutral', 600)}; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type LayerItemProps = { | ||
id: string | ||
label: string | ||
caption?: string | ||
showInfoButton?: boolean | ||
infoButtonLabel?: string | ||
variant?: 'switch' | 'radio' | ||
isDisabled?: boolean | ||
onInfoClick?: () => void | ||
isDefaultSelected?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { fn } from '@storybook/test' | ||
import Radio from '.' | ||
|
||
const meta = { | ||
title: 'Controls/Radio Button/Radio', | ||
component: Radio, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
args: { onChange: fn() }, | ||
} satisfies Meta<typeof Radio> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const SingleRadio: Story = { | ||
args: { | ||
label: 'Single Radio', | ||
value: '1', | ||
}, | ||
} | ||
|
||
export const DefaultChecked: Story = { | ||
args: { | ||
label: 'Single Radio', | ||
value: '1', | ||
isChecked: true, | ||
}, | ||
} | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
label: 'Single Radio', | ||
value: '1', | ||
isDisabled: true, | ||
isChecked: true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { RadioProps } from './types' | ||
import { StyledRadio } from './styled' | ||
|
||
const Radio = ({ | ||
label, | ||
value, | ||
isChecked, | ||
isDisabled, | ||
...rest | ||
}: RadioProps) => ( | ||
<StyledRadio | ||
value={value} | ||
isChecked={isChecked} | ||
isDisabled={isDisabled} | ||
{...rest} | ||
> | ||
{label} | ||
</StyledRadio> | ||
) | ||
|
||
export default Radio |
Oops, something went wrong.