|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import Search from '.'; |
| 3 | +import '../../styles/stories.scss'; |
| 4 | +import Button from '../Button'; |
| 5 | + |
| 6 | +export default { |
| 7 | + title: 'Search', |
| 8 | + component: Search |
| 9 | +}; |
| 10 | + |
| 11 | +export const BasicUsage = () => ( |
| 12 | + <div className='container column grey'> |
| 13 | + <Search /> |
| 14 | + <Search shape='round' /> |
| 15 | + </div> |
| 16 | +); |
| 17 | + |
| 18 | +export const CustomLabel = () => ( |
| 19 | + <div className='container column grey'> |
| 20 | + <Search |
| 21 | + placeholder='Label width of 65px' |
| 22 | + label='Address' |
| 23 | + labelWidth='65px' |
| 24 | + /> |
| 25 | + <Search label='Address' labelAlign='center' /> |
| 26 | + <Search label='Address' labelAlign='right' /> |
| 27 | + </div> |
| 28 | +); |
| 29 | + |
| 30 | +export const BackgroundColor = () => ( |
| 31 | + <div className='container grey'> |
| 32 | + <Search background='rgb(79, 192, 141)' /> |
| 33 | + </div> |
| 34 | +); |
| 35 | + |
| 36 | +export const MaxLength = () => ( |
| 37 | + <div className='container grey'> |
| 38 | + <Search maxLength={5} /> |
| 39 | + </div> |
| 40 | +); |
| 41 | + |
| 42 | +export const PlaceholderAutoFocus = () => ( |
| 43 | + <div className='container grey column'> |
| 44 | + <Search placeholder='This is a placeholder' /> |
| 45 | + <Search placeholder='This is a auto focus' autofocus /> |
| 46 | + </div> |
| 47 | +); |
| 48 | + |
| 49 | +export const SearchActions = () => { |
| 50 | + const handleClick = (e) => { |
| 51 | + e.preventDefault(); |
| 52 | + alert('Action clicked'); |
| 53 | + }; |
| 54 | + const [value, setValue] = useState(''); |
| 55 | + const [focus, setFocus] = useState(false); |
| 56 | + return ( |
| 57 | + <div className='container column grey'> |
| 58 | + <h1>Value: {value}</h1> |
| 59 | + <Search cancel={handleClick} showAction /> |
| 60 | + <Search cancel={handleClick} showAction actionText='Clear' /> |
| 61 | + <Search |
| 62 | + showAction |
| 63 | + action={ |
| 64 | + <Button |
| 65 | + click={handleClick} |
| 66 | + text='Action' |
| 67 | + type='primary' |
| 68 | + size='small' |
| 69 | + block |
| 70 | + /> |
| 71 | + } |
| 72 | + /> |
| 73 | + <Search |
| 74 | + placeholder='Search Action, press Enter to search' |
| 75 | + search={() => alert('Searched')} |
| 76 | + /> |
| 77 | + |
| 78 | + <Search |
| 79 | + rightIcon={focus ? 'success' : 'cross'} |
| 80 | + clearable={false} |
| 81 | + placeholder='Focus blur and input actions' |
| 82 | + input={(e) => setValue(e.target.value)} |
| 83 | + focus={() => setFocus(true)} |
| 84 | + blur={() => setFocus(false)} |
| 85 | + /> |
| 86 | + </div> |
| 87 | + ); |
| 88 | +}; |
| 89 | + |
| 90 | +export const DisabledReadonlyError = () => ( |
| 91 | + <div className='container column grey'> |
| 92 | + <Search disabled /> |
| 93 | + <Search readonly /> |
| 94 | + <Search error errorMessage='Something is up' /> |
| 95 | + </div> |
| 96 | +); |
| 97 | + |
| 98 | +export const AlignmentAndIcon = () => ( |
| 99 | + <div className='container column grey'> |
| 100 | + <Search inputAlign='center' placeholder='This is a placeholder' /> |
| 101 | + <Search inputAlign='right' placeholder='This is a placeholder' /> |
| 102 | + <Search leftIcon='smile-o' /> |
| 103 | + <Search leftIcon='' rightIcon='search' clearable={false} /> |
| 104 | + </div> |
| 105 | +); |
0 commit comments