-
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
28a5dce
commit 2c59424
Showing
23 changed files
with
535 additions
and
10 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export type LayerParametersProps = { | ||
label: string | ||
children: React.ReactNode | ||
openedByDefault?: 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,79 @@ | ||
/* 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 LegendItemStory from '.' | ||
import ScaleLegend from '../ScaleLegend' | ||
import QualitativeLegend from '../QualitativeLegend' | ||
import Banner from '../../Banner' | ||
import LayerParameters from '../LayerParameters' | ||
|
||
const meta = { | ||
title: 'Legend/Legend Item', | ||
component: LegendItemStory, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
decorators: [ | ||
(Story: any) => ( | ||
<div style={{ width: '290px' }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
} satisfies Meta<typeof LegendItemStory> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const LegendItem: Story = { | ||
args: { | ||
layerName: 'Layer Name', | ||
dataUnit: 'Data Unit', | ||
onDrag: () => console.log('drag'), | ||
onUpClick: () => console.log('up'), | ||
onDownClick: () => console.log('down'), | ||
onRemoveClick: () => console.log('remove'), | ||
onInfoClick: () => console.log('info'), | ||
onOpacityChanged: (value) => console.log('opacity changed', value), | ||
children: null, | ||
}, | ||
render: function Render(args) { | ||
return ( | ||
<LegendItemStory {...args}> | ||
<ScaleLegend | ||
colors={['#EDF8FB', '#B2E2E2', '#66C2A4', '#2CA25F', '#006D2C']} | ||
values={['0%', '25%', '50%', '75%', '100%']} | ||
/> | ||
<QualitativeLegend | ||
type='raster' | ||
label='Attribute' | ||
caption='Caption' | ||
color='#238B45' | ||
onActionClick={() => console.log('click')} | ||
showActionButton | ||
/> | ||
<QualitativeLegend | ||
type='raster' | ||
label='Attribute' | ||
caption='Caption' | ||
color='#238B45' | ||
/> | ||
<Banner | ||
label='Label' | ||
caption='caption' | ||
variant='info-white' | ||
actionLabel='Label' | ||
size='small' | ||
/> | ||
<LayerParameters label='Adjust layer parameters'> | ||
<div>Component Placeholder</div> | ||
<div>Component Placeholder</div> | ||
<div>Component Placeholder</div> | ||
</LayerParameters> | ||
</LegendItemStory> | ||
) | ||
}, | ||
} |
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,56 @@ | ||
/* eslint-disable no-console */ | ||
import { | ||
Banner, | ||
LayerParameters, | ||
LegendItem, | ||
QualitativeLegend, | ||
ScaleLegend, | ||
} from '../..' | ||
|
||
const LegendItemDemo = () => ( | ||
<div style={{ width: '290px' }}> | ||
<LegendItem | ||
layerName='Layer Name' | ||
dataUnit='Data Unit' | ||
onDrag={() => console.log('drag')} | ||
onUpClick={() => console.log('up')} | ||
onDownClick={() => console.log('down')} | ||
onRemoveClick={() => console.log('remove')} | ||
onInfoClick={() => console.log('info')} | ||
onOpacityChanged={(value) => console.log('opacity changed', value)} | ||
> | ||
<ScaleLegend | ||
colors={['#EDF8FB', '#B2E2E2', '#66C2A4', '#2CA25F', '#006D2C']} | ||
values={['0%', '25%', '50%', '75%', '100%']} | ||
/> | ||
<QualitativeLegend | ||
type='raster' | ||
label='Attribute' | ||
caption='Caption' | ||
color='#238B45' | ||
onActionClick={() => console.log('click')} | ||
showActionButton | ||
/> | ||
<QualitativeLegend | ||
type='raster' | ||
label='Attribute' | ||
caption='Caption' | ||
color='#238B45' | ||
/> | ||
<Banner | ||
label='Label' | ||
caption='caption' | ||
variant='info-white' | ||
actionLabel='Label' | ||
size='small' | ||
/> | ||
<LayerParameters label='Adjust layer parameters'> | ||
<div>Component Placeholder</div> | ||
<div>Component Placeholder</div> | ||
<div>Component Placeholder</div> | ||
</LayerParameters> | ||
</LegendItem> | ||
</div> | ||
) | ||
|
||
export default LegendItemDemo |
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 @@ | ||
# LegendItem | ||
|
||
[Storybook Ref](https://wri.github.io/wri-design-systems/?path=/docs/legend-legend-item--docs) | ||
|
||
[LegendItemDemo](https://github.com/wri/wri-design-systems/blob/main/src/components/Legend/LegendItem/LegendItemDemo.tsx) | ||
|
||
## Import | ||
|
||
```js | ||
import { | ||
LegendItem, | ||
Banner, | ||
LayerParameters, | ||
LegendItem, | ||
QualitativeLegend, | ||
ScaleLegend, | ||
} from 'wri-design-systems' | ||
``` | ||
|
||
## Usage | ||
|
||
```html | ||
<LegendItem | ||
layerName='Layer Name' | ||
dataUnit='Data Unit' | ||
onDrag={() => console.log('drag')} | ||
onUpClick={() => console.log('up')} | ||
onDownClick={() => console.log('down')} | ||
onRemoveClick={() => console.log('remove')} | ||
onInfoClick={() => console.log('info')} | ||
onOpacityChanged={(value) => console.log('opacity changed', value)} | ||
> | ||
<ScaleLegend | ||
colors={['#EDF8FB', '#B2E2E2', '#66C2A4', '#2CA25F', '#006D2C']} | ||
values={['0%', '25%', '50%', '75%', '100%']} | ||
/> | ||
<QualitativeLegend | ||
type='raster' | ||
label='Attribute' | ||
caption='Caption' | ||
color='#238B45' | ||
onActionClick={() => console.log('click')} | ||
showActionButton | ||
/> | ||
<QualitativeLegend | ||
type='raster' | ||
label='Attribute' | ||
caption='Caption' | ||
color='#238B45' | ||
/> | ||
<Banner | ||
label='Label' | ||
caption='caption' | ||
variant='info-white' | ||
actionLabel='Label' | ||
size='small' | ||
/> | ||
<LayerParameters label='Adjust layer parameters'> | ||
<div>Component Placeholder</div> | ||
<div>Component Placeholder</div> | ||
<div>Component Placeholder</div> | ||
</LayerParameters> | ||
</LegendItem> | ||
``` | ||
|
||
## Props | ||
|
||
```ts | ||
type LegendItemProps = { | ||
layerName: string | ||
dataUnit: string | ||
onDrag: VoidFunction | ||
onUpClick: VoidFunction | ||
onDownClick: VoidFunction | ||
onRemoveClick: VoidFunction | ||
children: React.ReactNode | ||
onInfoClick: VoidFunction | ||
onOpacityChanged: (value: number) => 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,85 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import React from 'react' | ||
|
||
import { LegendItemProps } from './types' | ||
import { | ||
LegendItemDragAndDropActions, | ||
LegendItemContainer, | ||
LegendItemDataUnit, | ||
LegendItemHeaderContainer, | ||
LegendItemLayerName, | ||
LegendItemButtonsContainer, | ||
} from './styled' | ||
import Button from '../../Buttons/Button' | ||
import { ChevronDownIcon, CloseIcon, DotsIcon, InfoIcon } from '../../icons' | ||
import IconButton from '../../Buttons/IconButton' | ||
import OpacityControl from '../OpacityControl' | ||
|
||
const LegendItem = ({ | ||
layerName, | ||
dataUnit, | ||
onDrag, | ||
onUpClick, | ||
onDownClick, | ||
onRemoveClick, | ||
children, | ||
onInfoClick, | ||
onOpacityChanged, | ||
}: LegendItemProps) => ( | ||
<LegendItemContainer> | ||
<LegendItemDragAndDropActions> | ||
<IconButton | ||
icon={<DotsIcon />} | ||
aria-label='Drag and drop' | ||
onClick={onDrag} | ||
/> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
marginTop: '12px', | ||
gap: '12px', | ||
}} | ||
> | ||
<IconButton | ||
icon={<ChevronDownIcon rotate='180' />} | ||
aria-label='Up' | ||
onClick={onUpClick} | ||
/> | ||
<IconButton | ||
icon={<ChevronDownIcon />} | ||
aria-label='Down' | ||
onClick={onDownClick} | ||
/> | ||
</div> | ||
</LegendItemDragAndDropActions> | ||
<div> | ||
<LegendItemHeaderContainer> | ||
<div> | ||
<LegendItemLayerName>{layerName}</LegendItemLayerName> | ||
<LegendItemDataUnit>{dataUnit}</LegendItemDataUnit> | ||
</div> | ||
<Button | ||
label='Remove' | ||
size='small' | ||
variant='secondary' | ||
rightIcon={<CloseIcon />} | ||
onClick={onRemoveClick} | ||
/> | ||
</LegendItemHeaderContainer> | ||
{children} | ||
<LegendItemButtonsContainer> | ||
<Button | ||
label='About data' | ||
size='small' | ||
variant='secondary' | ||
leftIcon={<InfoIcon />} | ||
onClick={onInfoClick} | ||
/> | ||
<OpacityControl defaultValue={80} onOpacityChanged={onOpacityChanged} /> | ||
</LegendItemButtonsContainer> | ||
</div> | ||
</LegendItemContainer> | ||
) | ||
|
||
export default LegendItem |
Oops, something went wrong.