-
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
2c59424
commit 517f051
Showing
15 changed files
with
287 additions
and
4 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
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,32 @@ | ||
/* eslint-disable no-console */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import React from 'react' | ||
|
||
import type { Meta, StoryObj } from '@storybook/react' | ||
import LegendPanelStory from '.' | ||
import { LegendItemDemo, LegendItemDemo2, LegendItemDemo3 } from '../LegendItem/LegendItemDemo' | ||
|
||
const meta = { | ||
title: 'Legend/Legend Panel', | ||
component: LegendPanelStory, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
} satisfies Meta<typeof LegendPanelStory> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const LegendPanel: Story = { | ||
args: { | ||
legendContent: ( | ||
<> | ||
<LegendItemDemo /> | ||
<LegendItemDemo2 /> | ||
<LegendItemDemo3 /> | ||
</> | ||
), | ||
analysisContent: <div />, | ||
}, | ||
} |
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,20 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import React from 'react' | ||
|
||
import { LegendPanel } from '../..' | ||
import { LegendItemDemo, LegendItemDemo2, LegendItemDemo3 } from '../LegendItem/LegendItemDemo' | ||
|
||
const LegendPanelDemo = () => ( | ||
<LegendPanel | ||
legendContent={( | ||
<> | ||
<LegendItemDemo /> | ||
<LegendItemDemo2 /> | ||
<LegendItemDemo3 /> | ||
</> | ||
)} | ||
analysisContent={<div />} | ||
/> | ||
) | ||
|
||
export default LegendPanelDemo |
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,38 @@ | ||
# LegendPanel | ||
|
||
[Storybook Ref](https://wri.github.io/wri-design-systems/?path=/docs/legend-legend-panel--docs) | ||
|
||
[LegendPanelDemo](https://github.com/wri/wri-design-systems/blob/main/src/components/Legend/LegendPanel/LegendPanelDemo.tsx) | ||
|
||
## Import | ||
|
||
```js | ||
import { | ||
LegendPanel, | ||
} from 'wri-design-systems' | ||
``` | ||
|
||
## Usage | ||
|
||
```html | ||
<LegendPanel | ||
legendContent={( | ||
<> | ||
<LegendItemDemo /> | ||
<LegendItemDemo2 /> | ||
<LegendItemDemo3 /> | ||
</> | ||
)} | ||
analysisContent={<div />} | ||
/> | ||
``` | ||
|
||
## Props | ||
|
||
```ts | ||
type LegendPanelProps = { | ||
legendContent: React.ReactNode | ||
analysisContent: React.ReactNode | ||
onTabClick?: (tabValue: string) => void | ||
} | ||
``` |
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,50 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import React, { Children, useState } from 'react' | ||
|
||
import { LegendPanelProps } from './types' | ||
import { LegendPanelContainer } from './styled' | ||
import { AnalysisIcon, LegendIcon } from '../../icons' | ||
import TabBar from '../../TabBar' | ||
|
||
const defaultTabValue = 'legend-tab' | ||
|
||
const LegendPanel = ({ legendContent, analysisContent, onTabClick }: LegendPanelProps) => { | ||
const [selectedTabValue, setSelectedTabValue] = useState(defaultTabValue) | ||
const [legentItems] = useState(Children.map(legendContent, (child, index) => ({ | ||
id: index, | ||
child, | ||
sequence: index, | ||
})) || []) | ||
|
||
const handleOnTabClick = (tabValue: string) => { | ||
setSelectedTabValue(tabValue) | ||
|
||
if (onTabClick) { | ||
onTabClick(tabValue) | ||
} | ||
} | ||
|
||
return ( | ||
<LegendPanelContainer> | ||
<TabBar | ||
tabs={[ | ||
{ label: 'Legend', value: 'legend-tab', icon: <LegendIcon /> }, | ||
{ label: 'Analysis', value: 'analysis-tab', icon: <AnalysisIcon /> }, | ||
]} | ||
onTabClick={handleOnTabClick} | ||
/> | ||
{selectedTabValue === 'legend-tab' ? ( | ||
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}> | ||
{legentItems.map((item) => item.child)} | ||
</div> | ||
) : null} | ||
{selectedTabValue === 'analysis-tab' ? ( | ||
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}> | ||
{analysisContent} | ||
</div> | ||
) : null} | ||
</LegendPanelContainer> | ||
) | ||
} | ||
|
||
export default LegendPanel |
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,8 @@ | ||
import styled from '@emotion/styled' | ||
|
||
export const LegendPanelContainer = styled.div` | ||
width: 290px; | ||
box-shadow: 0px 2px 4px -2px #0000001A; | ||
box-shadow: 0px 4px 6px -1px #0000001A; | ||
` |
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,7 @@ | ||
import React from 'react' | ||
|
||
export type LegendPanelProps = { | ||
legendContent: React.ReactNode | ||
analysisContent: React.ReactNode | ||
onTabClick?: (tabValue: string) => void | ||
} |
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
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,12 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import React from 'react' | ||
|
||
import { Icon, IconProps } from '@chakra-ui/react' | ||
|
||
export const AnalysisIcon = (props: IconProps) => ( | ||
<Icon {...props}> | ||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M1.71286 12.5714V3.42857H5.14144V12.5714H1.71286ZM6.28429 12.5714V6.85714H9.71286V12.5714H6.28429ZM10.8557 12.5714V0H14.2843V12.5714H10.8557ZM0.570007 16V13.7143H15.4271V16H0.570007Z" fill="currentColor" /> | ||
</svg> | ||
</Icon> | ||
) |
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,19 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import React from 'react' | ||
|
||
import { Icon, IconProps } from '@chakra-ui/react' | ||
|
||
export const LegendIcon = (props: IconProps) => ( | ||
<Icon {...props}> | ||
<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<g clipPath="url(#clip0_5584_387)"> | ||
<path d="M8.49906 16L0.940002 10.1207L2.32583 9.07087L8.49906 13.8583L14.6723 9.07087L16.0581 10.1207L8.49906 16ZM8.49906 11.7585L0.940002 5.87926L8.49906 0L16.0581 5.87926L8.49906 11.7585Z" fill="currentColor" /> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_5584_387"> | ||
<rect width="16" height="16" fill="white" transform="translate(0.5)" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
</Icon> | ||
) |
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