|
| 1 | +import {useState} from 'react' |
| 2 | + |
| 3 | +import PropTypes from 'prop-types' |
| 4 | + |
| 5 | +import { |
| 6 | + AntDesignIcon, |
| 7 | + Article, |
| 8 | + Cell, |
| 9 | + Code, |
| 10 | + Grid, |
| 11 | + H2, |
| 12 | + Input, |
| 13 | + ListItem, |
| 14 | + Paragraph, |
| 15 | + RadioButton, |
| 16 | + RadioButtonGroup, |
| 17 | + UnorderedList |
| 18 | +} from '@s-ui/documentation-library' |
| 19 | +import AtomLabel from '@s-ui/react-atom-label/lib' |
| 20 | +import PrimitiveVisuallyHidden from '@s-ui/react-primitive-visually-hidden' |
| 21 | + |
| 22 | +import AtomInput from '../../src/index.js' |
| 23 | + |
| 24 | +const ArticleAddonAndIcon = ({className}) => { |
| 25 | + const [state, setState] = useState({}) |
| 26 | + const {icon, iconValue, rightAddon, leftAddon} = state |
| 27 | + const setStatus = (newState = {}) => setState({...state, ...newState}) |
| 28 | + const valueIcon = iconValue ? <AntDesignIcon icon={iconValue} style={{color: 'currentColor'}} /> : null |
| 29 | + return ( |
| 30 | + <Article className={className}> |
| 31 | + <H2>Addon and Icon</H2> |
| 32 | + <Paragraph>Input offers the possibility to add icons and contents on its left or right positions</Paragraph> |
| 33 | + <UnorderedList> |
| 34 | + <ListItem> |
| 35 | + <Code>leftAddon</Code> and <Code>rightAddon</Code>: use it as a label for the input field |
| 36 | + </ListItem> |
| 37 | + <ListItem> |
| 38 | + <Code>leftIcon</Code> and <Code>rightIcon</Code>: use it as a valid symbol for the field |
| 39 | + </ListItem> |
| 40 | + </UnorderedList> |
| 41 | + <Paragraph>This field props can be combined all together.</Paragraph> |
| 42 | + <Grid cols={2} gutter={[8, 8]}> |
| 43 | + <Cell span={2}> |
| 44 | + <PrimitiveVisuallyHidden> |
| 45 | + <AtomLabel htmlFor="input-icons-and-addons" text="icons and addons" /> |
| 46 | + </PrimitiveVisuallyHidden> |
| 47 | + <AtomInput |
| 48 | + id="input-icons-and-addons" |
| 49 | + placeholder="icons and addons" |
| 50 | + leftIcon={icon === 'leftIcon' ? valueIcon : undefined} |
| 51 | + rightIcon={icon === 'rightIcon' ? valueIcon : undefined} |
| 52 | + leftAddon={leftAddon} |
| 53 | + rightAddon={rightAddon} |
| 54 | + /> |
| 55 | + </Cell> |
| 56 | + <Cell> |
| 57 | + <RadioButtonGroup |
| 58 | + onChange={(event, value) => { |
| 59 | + setStatus({icon: value}) |
| 60 | + }} |
| 61 | + fullWidth |
| 62 | + > |
| 63 | + <RadioButton value="leftIcon" label="leftIcon" /> |
| 64 | + <RadioButton value="rightIcon" label="rightIcon" /> |
| 65 | + </RadioButtonGroup> |
| 66 | + </Cell> |
| 67 | + <Cell> |
| 68 | + <RadioButtonGroup |
| 69 | + onChange={(event, value) => |
| 70 | + setStatus({ |
| 71 | + iconValue: value |
| 72 | + }) |
| 73 | + } |
| 74 | + fullWidth |
| 75 | + > |
| 76 | + <RadioButton |
| 77 | + value="AiFillFire" |
| 78 | + aria-label="fire" |
| 79 | + label={<AntDesignIcon icon="AiFillFire" style={{color: 'currentColor'}} />} |
| 80 | + /> |
| 81 | + <RadioButton |
| 82 | + value="AiOutlineSketch" |
| 83 | + aria-label="sketch" |
| 84 | + label={<AntDesignIcon icon="AiOutlineSketch" style={{color: 'currentColor'}} />} |
| 85 | + /> |
| 86 | + <RadioButton |
| 87 | + value="AiOutlineInfoCircle" |
| 88 | + aria-label="info" |
| 89 | + label={<AntDesignIcon icon="AiOutlineInfoCircle" style={{color: 'currentColor'}} />} |
| 90 | + /> |
| 91 | + <RadioButton |
| 92 | + value="AiTwotoneSkin" |
| 93 | + aria-label="skin" |
| 94 | + label={<AntDesignIcon icon="AiTwotoneSkin" style={{color: 'currentColor'}} />} |
| 95 | + /> |
| 96 | + <RadioButton |
| 97 | + value="AiOutlineExclamationCircle" |
| 98 | + aria-label="exclamation" |
| 99 | + label={<AntDesignIcon icon="AiOutlineExclamationCircle" style={{color: 'currentColor'}} />} |
| 100 | + /> |
| 101 | + <RadioButton |
| 102 | + value="AiOutlineCar" |
| 103 | + aria-label="car" |
| 104 | + label={<AntDesignIcon icon="AiOutlineCar" style={{color: 'currentColor'}} />} |
| 105 | + /> |
| 106 | + <RadioButton |
| 107 | + value="AiOutlineAppstore" |
| 108 | + aria-label="appstore" |
| 109 | + label={<AntDesignIcon icon="AiOutlineAppstore" style={{color: 'currentColor'}} />} |
| 110 | + /> |
| 111 | + <RadioButton |
| 112 | + value="AiFillTrophy" |
| 113 | + aria-label="trophy" |
| 114 | + label={<AntDesignIcon icon="AiFillTrophy" style={{color: 'currentColor'}} />} |
| 115 | + /> |
| 116 | + </RadioButtonGroup> |
| 117 | + </Cell> |
| 118 | + <Cell> |
| 119 | + <Input |
| 120 | + fullWidth |
| 121 | + placeholder="leftAddon text" |
| 122 | + onChange={event => setStatus({leftAddon: event.target.value})} |
| 123 | + /> |
| 124 | + </Cell> |
| 125 | + <Cell> |
| 126 | + <Input |
| 127 | + fullWidth |
| 128 | + placeholder="rightAddon text" |
| 129 | + onChange={event => setStatus({rightAddon: event.target.value})} |
| 130 | + /> |
| 131 | + </Cell> |
| 132 | + </Grid> |
| 133 | + </Article> |
| 134 | + ) |
| 135 | +} |
| 136 | + |
| 137 | +ArticleAddonAndIcon.propTypes = { |
| 138 | + className: PropTypes.node |
| 139 | +} |
| 140 | + |
| 141 | +export default ArticleAddonAndIcon |
0 commit comments