-
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.
- Loading branch information
1 parent
5c6e932
commit e6b5e54
Showing
16 changed files
with
335 additions
and
27 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,105 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import LayerGroupContainer from './LayerGroupContainer' | ||
import LayerGroup from '.' | ||
|
||
const meta = { | ||
title: 'Layers/LayerGroup', | ||
component: LayerGroupContainer, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
} satisfies Meta<typeof LayerGroupContainer> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const LayerGroupOpen: Story = { | ||
args: { | ||
defaultIndex: [0], | ||
allowMultiple: true, | ||
allowToggle: true, | ||
children: ( | ||
<> | ||
<LayerGroup | ||
label='Title 1' | ||
caption='Caption 1' | ||
layerItems={[ | ||
{ | ||
name: 'layer-1-item-1', | ||
label: 'Layer name 1', | ||
caption: 'Caption', | ||
}, | ||
{ | ||
name: 'layer-1-item-2', | ||
label: 'Layer name 2', | ||
caption: 'Caption', | ||
}, | ||
]} | ||
/> | ||
<LayerGroup | ||
label='Title 2' | ||
caption='Caption 2' | ||
layerItems={[ | ||
{ | ||
name: 'layer-2-item-1', | ||
label: 'Layer name 1', | ||
caption: 'Caption', | ||
}, | ||
{ | ||
name: 'layer-2-item-2', | ||
label: 'Layer name 2', | ||
caption: 'Caption', | ||
}, | ||
]} | ||
/> | ||
</> | ||
) | ||
}, | ||
} | ||
|
||
// export const Radio: Story = { | ||
// args: { | ||
// name: 'radio-layer', | ||
// label: 'Layer name', | ||
// caption: 'Caption', | ||
// variant: 'radio', | ||
// }, | ||
// } | ||
|
||
// export const Disabled: Story = { | ||
// args: { | ||
// name: 'switch-layer-1', | ||
// label: 'Layer name', | ||
// caption: 'Caption', | ||
// isDisabled: true, | ||
// }, | ||
// } | ||
|
||
// export const RadioDisabeld: Story = { | ||
// args: { | ||
// name: 'radio-layer', | ||
// label: 'Layer name', | ||
// caption: 'Caption', | ||
// variant: 'radio', | ||
// isDisabled: true, | ||
// }, | ||
// } | ||
|
||
// export const NoInfoButton: Story = { | ||
// args: { | ||
// name: 'switch-layer-2', | ||
// label: 'Layer name', | ||
// caption: 'Caption', | ||
// showInfoButton: false, | ||
// }, | ||
// } | ||
|
||
// export const CustomInfoButtonLabel: Story = { | ||
// args: { | ||
// name: '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,23 @@ | ||
import { Accordion } from '@chakra-ui/react' | ||
import { LayerGroupContainerProps } from './types' | ||
|
||
const LayerGroupContainer = ({ | ||
children, | ||
allowMultiple = true, | ||
allowToggle = true, | ||
defaultIndex = [0], | ||
...rest | ||
}: LayerGroupContainerProps) => ( | ||
<div style={{ width: '300px' }}> | ||
<Accordion | ||
allowMultiple={allowMultiple} | ||
allowToggle={allowToggle} | ||
defaultIndex={defaultIndex} | ||
{...rest} | ||
> | ||
{children} | ||
</Accordion> | ||
</div> | ||
) | ||
|
||
export default LayerGroupContainer |
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,80 @@ | ||
import { | ||
AccordionItem, | ||
AccordionButton, | ||
AccordionPanel, | ||
AccordionIcon, | ||
useTheme, | ||
RadioGroup, | ||
} from '@chakra-ui/react' | ||
import { useState } from 'react' | ||
import { LayerGroupProps } from './types' | ||
import { LayerGroupCaption, LayerGroupTitle } from './styled' | ||
import { getThemedColor } from '../../../lib/theme' | ||
import ActiveTag from '../../Tag/ActiveTag' | ||
import LayerItem from '../LayerItem' | ||
|
||
const LayerGroup = ({ | ||
label, | ||
caption, | ||
layerItems, | ||
}: LayerGroupProps) => { | ||
const [activeItems, setActiveItems] = useState<{ key?: string, value?: boolean }>({}) | ||
const theme = useTheme() | ||
|
||
const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>, onChange: ((e: React.ChangeEvent<HTMLInputElement>) => void) | undefined) => { | ||
const newActiveItems = { | ||
...activeItems, | ||
[e.target.name]: e.target.checked, | ||
} | ||
|
||
setActiveItems(newActiveItems) | ||
|
||
if (onChange) { | ||
onChange(e) | ||
} | ||
} | ||
|
||
const getActiveCount = Object.values(activeItems) | ||
.filter(item => item === true).length | ||
|
||
return ( | ||
<div style={{ width: '300px' }}> | ||
<AccordionItem> | ||
<h2> | ||
<AccordionButton | ||
style={{ alignItems: 'flex-start' }} | ||
_hover={{ backgroundColor: 'transparent' }} | ||
> | ||
<LayerGroupTitle | ||
as='span' | ||
flex='1' | ||
> | ||
{label} | ||
<ActiveTag count={getActiveCount} /> | ||
</LayerGroupTitle> | ||
<AccordionIcon | ||
width='30px' | ||
height='30px' | ||
color={getThemedColor(theme.colors, 'neutral', 700)} | ||
/> | ||
</AccordionButton> | ||
</h2> | ||
<LayerGroupCaption> | ||
{caption} | ||
</LayerGroupCaption> | ||
<AccordionPanel pb={0}> | ||
<RadioGroup name={label}> | ||
{layerItems.map(layerItem => ( | ||
<LayerItem | ||
{...layerItem} | ||
onChange={(e) => handleOnChange(e, layerItem.onChange)} | ||
/> | ||
))} | ||
</RadioGroup> | ||
</AccordionPanel> | ||
</AccordionItem> | ||
</div> | ||
) | ||
} | ||
|
||
export default LayerGroup |
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,29 @@ | ||
import styled from '@emotion/styled' | ||
import { Box } from '@chakra-ui/react' | ||
import { getThemedColor, ThemeProps } from '../../../lib/theme' | ||
|
||
export const LayerGroupTitle = styled(Box) <{ | ||
theme?: ThemeProps | ||
}>` | ||
font-size: 16px; | ||
font-weight: 700; | ||
line-height: 24px; | ||
text-align: left; | ||
color: ${({ theme }) => getThemedColor(theme.colors, 'neutral', 800)}; | ||
display: flex; | ||
align-items: center; | ||
text-align: left; | ||
gap: 10px; | ||
` | ||
|
||
export const LayerGroupCaption = styled(Box) <{ | ||
theme?: ThemeProps | ||
}>` | ||
font-size: 12px; | ||
font-weight: 400; | ||
line-height: 16px; | ||
text-align: left; | ||
color: ${({ theme }) => getThemedColor(theme.colors, 'neutral', 600)}; | ||
margin-left: 16px; | ||
margin-bottom: 24px; | ||
` |
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,17 @@ | ||
import { AccordionProps } from '@chakra-ui/react' | ||
import { LayerItemProps } from '../LayerItem/types' | ||
|
||
export type LayerGroupContainerProps = Omit< | ||
AccordionProps, | ||
'onChange' | ||
> & { | ||
allowMultiple?: boolean | ||
allowToggle?: boolean | ||
defaultIndex?: number[] | ||
} | ||
|
||
export type LayerGroupProps = { | ||
label: string | ||
caption: string | ||
layerItems: LayerItemProps[] | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/components/LayerItem/styled.ts → src/components/Layer/LayerItem/styled.ts
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
Oops, something went wrong.