-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Toggle Button with Story * Improve view of ToggleButton stories * Update FilterButton to new design * Making basic the default design in Toggle Button * Missing gap and indentation * Update ToggleButton story to have design basic as the story value --------- Co-authored-by: Leonard Burton <[email protected]>
- Loading branch information
Showing
6 changed files
with
201 additions
and
21 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
packages/storybook/src/stories/Filters/atoms/ToggleButton.stories.tsx
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,125 @@ | ||
import React, { useCallback, useState } from "react"; | ||
import { ToggleButton } from "scorer-ui-kit"; | ||
import { boolean, object, select, text } from "@storybook/addon-knobs"; | ||
import { action } from "@storybook/addon-actions"; | ||
import styled from "styled-components"; | ||
|
||
export default { | ||
title: 'Filters/atoms', | ||
component: ToggleButton, | ||
decorators: [] | ||
}; | ||
|
||
const layoutOptions = [ | ||
{ text: 'Grid', value: 'grid', icon: 'LayoutGrid' }, | ||
{ text: 'List', value: 'list', icon: 'LayoutList' } | ||
] | ||
|
||
const CameraData = styled.div``; | ||
const Camera = styled.li``; | ||
|
||
const Container = styled.div``; | ||
const DataGroup = styled.ol<{ layout: string }>` | ||
margin-top: 20px; | ||
display: grid; | ||
${({ layout }) => layout === 'grid' && | ||
` | ||
list-style-type: none; | ||
grid-template-columns: repeat(3, 300px); | ||
gap: 16px; | ||
${Camera} { | ||
padding: 100px 20px; | ||
border: 1px solid var(--grey-9); | ||
text-align: center; | ||
} | ||
` | ||
}; | ||
`; | ||
|
||
const StatusSpan = styled.span<{ isOnline?: boolean }>` | ||
${({ isOnline }) => isOnline ? | ||
` | ||
color: var(--success); | ||
` | ||
: | ||
` | ||
color: var(--warning); | ||
`} | ||
`; | ||
|
||
export const _ToggleButton = () => { | ||
const [selectedLayout, setSelectedLayout] = useState(0) | ||
|
||
const disabled = boolean('Disabled', false); | ||
const design = select('Design type', { Default: 'default', Basic: 'basic' }, 'basic'); | ||
const categoryLabel = text('Category Label', 'Layout:'); | ||
const options = object('Options', layoutOptions); | ||
const showToggleValue = action('Button Value: '); | ||
|
||
const onToggle = useCallback((index: number, value: string | number) => { | ||
setSelectedLayout(index); | ||
showToggleValue(value); | ||
}, [showToggleValue]) | ||
|
||
return ( | ||
<Container> | ||
<ToggleButton | ||
{...{ | ||
categoryLabel, | ||
options, | ||
onToggle, | ||
disabled, | ||
design, | ||
selectedIndex: selectedLayout | ||
}} /> | ||
|
||
<DataGroup layout={layoutOptions[selectedLayout].value}> | ||
<Camera> | ||
<CameraData> | ||
Camera01 - <StatusSpan isOnline>Online</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera02 - <StatusSpan isOnline>Online</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera03 - <StatusSpan>OffLine</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera04 - <StatusSpan>OffLine</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera05 - <StatusSpan>OffLine</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera06 - <StatusSpan>OffLine</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera07 - <StatusSpan isOnline>Online</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera08 - <StatusSpan isOnline>Online</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
<Camera> | ||
<CameraData> | ||
Camera09 - <StatusSpan>Online</StatusSpan> | ||
</CameraData> | ||
</Camera> | ||
</DataGroup> | ||
</Container> | ||
) | ||
} |
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,31 @@ | ||
import React, { useCallback } from 'react'; | ||
import { IToggleOption } from '../FilterTypes'; | ||
import FilterButton from './FilterButton'; | ||
import { FilterButtonDesign } from '..'; | ||
|
||
type IToggleButton = { | ||
options: IToggleOption[] | ||
categoryLabel: String | ||
selectedIndex: number | ||
design?: FilterButtonDesign | ||
onToggle: (index: number, value: string | number) => void | ||
} | ||
|
||
const ToggleButton: React.FC<IToggleButton> = ({ options, categoryLabel, selectedIndex, design = 'basic', onToggle, ...props }) => { | ||
|
||
const onToggleCallback = useCallback((currentIndex: number) => { | ||
const selected = currentIndex === 1 ? 0 : 1; | ||
onToggle(selected, options[selected].value); | ||
|
||
}, [onToggle, options]); | ||
|
||
if (selectedIndex !== 0 && selectedIndex !== 1) return null; | ||
|
||
return ( | ||
<FilterButton icon={options[selectedIndex].icon} onClick={() => onToggleCallback(selectedIndex)} {...{design}} {...props}> | ||
{`${categoryLabel} : ${options[selectedIndex].text}`} | ||
</FilterButton> | ||
); | ||
}; | ||
|
||
export default ToggleButton; |
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