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
894394d
commit 85c84f9
Showing
6 changed files
with
459 additions
and
9 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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import React from 'react'; | ||
import {addDecorator} from '@storybook/react'; | ||
import {addDecorator, addParameters} from '@storybook/react'; | ||
import {StoryStyle} from '../src/shared/global'; | ||
|
||
addDecorator(story => ( | ||
<> | ||
<StoryStyle>{story()}</StoryStyle> | ||
</> | ||
)); | ||
|
||
addParameters({ | ||
viewMode: 'docs' | ||
}) |
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
31 changes: 31 additions & 0 deletions
31
akeneo-design-system/src/components/Checkbox/Checkbox.stories.mdx
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 { useState } from 'react'; | ||
import { Meta, Story, Preview, Props, ArgsTable, Canvas } from '@storybook/addon-docs/blocks'; | ||
import { action } from "@storybook/addon-actions"; | ||
import { Checkbox } from "./Checkbox.tsx"; | ||
|
||
<Meta | ||
title="Components/Checkbox" | ||
component={Checkbox} | ||
argTypes={{ | ||
readOnly: {control: {type: 'boolean', default: 'false'}}, | ||
checked: {control: {type: 'boolean', default: 'false'}}, | ||
label: 'string', | ||
}} | ||
/> | ||
|
||
# Checkbox | ||
|
||
## Playground | ||
|
||
Use this playground to test the checkbox component | ||
|
||
<Preview> | ||
<Story name="Standard"> | ||
{(args) => { | ||
return <Checkbox {...args}/>; | ||
}} | ||
</Story> | ||
</Preview> | ||
|
||
<Props story="Standard" /> | ||
|
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,89 @@ | ||
import React, {FormEvent} from 'react'; | ||
import styled, {css} from 'styled-components'; | ||
import {CheckIcon} from '../../icons/CheckIcon'; | ||
|
||
/** | ||
* @TODO use blue20 instead of #dee9f4 | ||
* @TODO use blue40 instead of #bdd3e9 | ||
* @TODO use blue100 instead of #5992c7 | ||
* @TODO use grey60 instead of #f9f9fb | ||
* @TODO use grey100 instead of #a1a9b7 | ||
* @TODO use grey140 instead of #11324d | ||
*/ | ||
|
||
const CheckboxContainer = styled.div < {checked: boolean, readOnly: boolean } > ` | ||
background-color: transparent; | ||
height: 20px; | ||
width: 20px; | ||
border: 1px solid #5992c7; | ||
border-radius: 3px; | ||
display: inline-block; | ||
${props => | ||
props.checked && css` | ||
background-color: #5992c7 | ||
` | ||
} | ||
${props => | ||
props.checked && props.readOnly && css` | ||
background-color: #dee9f4 | ||
border-color: #bdd3e9 | ||
` | ||
} | ||
${props => | ||
!props.checked && props.readOnly && css` | ||
background-color: #f9f9fb | ||
border-color: #a1a9b7 | ||
` | ||
} | ||
`; | ||
|
||
const LabelContainer = styled.div < {readOnly: boolean} > ` | ||
font-color: "#11324d"; | ||
font-weight: 400; | ||
font-size: 15px; | ||
padding-left: 10px; | ||
display: inline-block; | ||
${props => | ||
props.readOnly && ` | ||
font-color: "#a1a9b7"; | ||
` | ||
} | ||
`; | ||
|
||
type CheckboxProps = { | ||
checked: boolean, | ||
readOnly: boolean, | ||
label?: string, | ||
onChange?: (value: boolean) => void, | ||
}; | ||
|
||
/** | ||
* The checkboxes are applied when users can select all, several, or none of the options from a given list. | ||
*/ | ||
const Checkbox = ({label, checked, onChange, readOnly = false}: CheckboxProps) => { | ||
const handleChange = (e: FormEvent<HTMLDivElement>) => onChange && !readOnly && onChange(!checked); | ||
|
||
console.log(checked); | ||
console.log(readOnly); | ||
|
||
return ( | ||
<label> | ||
<CheckboxContainer onClick={handleChange} checked={checked} readOnly={readOnly}> | ||
{checked ? ( | ||
<CheckIcon height={20} width={20}/> | ||
) : null} | ||
</CheckboxContainer> | ||
{label ? ( | ||
<LabelContainer readOnly={readOnly}> | ||
{label} | ||
</LabelContainer> | ||
) : null} | ||
</label> | ||
); | ||
}; | ||
|
||
export {Checkbox}; |
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,16 @@ | ||
import React from 'react'; | ||
|
||
const CheckIcon = ({number: width = 24, number: height = 24}) => ( | ||
<svg width={width} height={height} viewBox="0 0 24 24"> | ||
<path | ||
stroke="#A1A9B7" | ||
d="M2.5 12l7.5 6.5L21.5 6" | ||
fill="none" | ||
fillRule="evenodd" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
); | ||
|
||
export {CheckIcon}; |
Oops, something went wrong.