|
| 1 | +import {faExclamationCircle, faHandPointUp} from '@fortawesome/free-solid-svg-icons'; |
| 2 | +import * as React from 'react'; |
| 3 | +import Text from '../text/text'; |
| 4 | + |
| 5 | +import {ActionButton} from './action-button'; |
| 6 | + |
| 7 | +const IconOptions = {faHandPointUp, faExclamationCircle}; |
| 8 | + |
| 9 | +export default { |
| 10 | + title: 'Components/ActionButton', |
| 11 | + component: ActionButton, |
| 12 | + argTypes: { |
| 13 | + sampleAction: { |
| 14 | + name: 'Sample Action', |
| 15 | + description: 'A set of sample actions to demo the Action Button. Not available for real component', |
| 16 | + control: { |
| 17 | + type: 'radio', |
| 18 | + options: ['Say hello', 'Surprise'], |
| 19 | + }, |
| 20 | + }, |
| 21 | + action: {control: {disable: true}, description: 'Function that is called when button is clicked', action: 'clicked'}, |
| 22 | + style: {control: {disable: true}}, |
| 23 | + icon: { |
| 24 | + name: 'Sample Icon', |
| 25 | + description: 'A set of sample icons to choose from. For real component, use any FontAwesome icon', |
| 26 | + options: Object.keys(IconOptions), |
| 27 | + mapping: IconOptions, |
| 28 | + control: { |
| 29 | + type: 'select', |
| 30 | + labels: { |
| 31 | + faHandPointUp: 'Pointer', |
| 32 | + faExclamationCircle: 'Error', |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + theme: {description: 'Takes precidence over dark boolean switch'}, |
| 37 | + dark: {description: 'Convenience flag to make button appear dark without special Theme logic'}, |
| 38 | + tooltip: {control: {type: 'text'}}, |
| 39 | + short: {description: 'Displays only the icon (hides the label). Does nothing if icon is not specified'}, |
| 40 | + indicateLoading: {description: 'Displays a spinner for a brief period on click, but only if the icon prop is set'}, |
| 41 | + indicateSuccess: {description: 'Displays a checkmark after the specified action is complete, but only if the icon prop is set'}, |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +const Template = (args: any) => { |
| 46 | + const [message, setMessage] = React.useState(''); |
| 47 | + const clickAction = args.action; |
| 48 | + |
| 49 | + const tempSetMessage = (text: string) => { |
| 50 | + clickAction(); |
| 51 | + setMessage(text); |
| 52 | + setTimeout(() => { |
| 53 | + setMessage(''); |
| 54 | + }, 1000); |
| 55 | + }; |
| 56 | + |
| 57 | + const SampleActions: {[key: string]: () => void} = { |
| 58 | + 'Say hello': () => tempSetMessage('Hello!'), |
| 59 | + 'Surprise': () => tempSetMessage('Boo!'), |
| 60 | + }; |
| 61 | + args.action = SampleActions[args.sampleAction]; |
| 62 | + if (args.tooltip && args.tooltip !== '') { |
| 63 | + args.tooltip = <Text>{args.tooltip}</Text>; |
| 64 | + } |
| 65 | + |
| 66 | + return ( |
| 67 | + <React.Fragment> |
| 68 | + <div style={{display: 'flex'}}> |
| 69 | + <ActionButton {...args} /> |
| 70 | + </div> |
| 71 | + {message !== '' && ( |
| 72 | + <div style={{marginTop: '1em'}}> |
| 73 | + <Text dark={args.dark}>{message}</Text> |
| 74 | + </div> |
| 75 | + )} |
| 76 | + </React.Fragment> |
| 77 | + ); |
| 78 | +}; |
| 79 | + |
| 80 | +export const Primary = Template.bind({}); |
| 81 | + |
| 82 | +Primary.args = { |
| 83 | + label: 'Click me!', |
| 84 | + sampleAction: 'Say hello', |
| 85 | +}; |
0 commit comments