55 * found at http://www.apache.org/licenses/LICENSE-2.0.
66 */
77
8- import React from 'react' ;
9- import { Story } from '@storybook/react' ;
10- import { IInputGroupProps , Input , InputGroup } from '@zendeskgarden/react-forms' ;
8+ import React , { PropsWithChildren , useState } from 'react' ;
9+ import { StoryFn } from '@storybook/react' ;
10+ import { IInputGroupProps , IInputProps , Input , InputGroup } from '@zendeskgarden/react-forms' ;
1111import { FieldStory , IFieldArgs } from './FieldStory' ;
1212import { IInputGroupItem } from './types' ;
13- import { Button } from '@zendeskgarden/react-buttons' ;
13+ import { Button , IButtonProps , ToggleButton } from '@zendeskgarden/react-buttons' ;
14+
15+ interface IGroupButtonProps extends PropsWithChildren {
16+ disabled ?: boolean ;
17+ isNeutral : boolean ;
18+ isPrimary ?: boolean ;
19+ isDanger ?: boolean ;
20+ isToggle ?: boolean ;
21+ size ?: IButtonProps [ 'size' ] ;
22+ }
23+
24+ const GroupButton = ( { isToggle, ...props } : IGroupButtonProps ) => {
25+ const [ isPressed , setIsPressed ] = useState ( false ) ;
26+
27+ return isToggle ? (
28+ < ToggleButton
29+ focusInset
30+ { ...props }
31+ isPressed = { isPressed }
32+ onClick = { ( ) => setIsPressed ( ! isPressed ) }
33+ />
34+ ) : (
35+ < Button focusInset { ...props } />
36+ ) ;
37+ } ;
1438
1539interface IArgs extends IInputGroupProps , IFieldArgs {
1640 items : IInputGroupItem [ ] ;
1741 disabled ?: boolean ;
1842 isNeutral : boolean ;
1943 isPrimary ?: boolean ;
2044 isDanger ?: boolean ;
45+ isToggle ?: boolean ;
2146 readOnly ?: boolean ;
47+ inputValidation ?: IInputProps [ 'validation' ] ;
2248}
2349
24- export const InputGroupStory : Story < IArgs > = ( {
50+ export const InputGroupStory : StoryFn < IArgs > = ( {
2551 label,
2652 isLabelRegular,
2753 isLabelHidden,
@@ -35,7 +61,9 @@ export const InputGroupStory: Story<IArgs> = ({
3561 isNeutral,
3662 isPrimary,
3763 isDanger,
64+ isToggle,
3865 readOnly,
66+ inputValidation,
3967 ...args
4068} ) => (
4169 < FieldStory
@@ -52,24 +80,25 @@ export const InputGroupStory: Story<IArgs> = ({
5280 < InputGroup { ...args } >
5381 { items . map ( ( item , index ) =>
5482 item . isButton ? (
55- < Button
83+ < GroupButton
5684 key = { index }
57- focusInset
5885 disabled = { disabled }
5986 isNeutral = { isNeutral }
6087 isPrimary = { isPrimary }
6188 isDanger = { isDanger }
89+ isToggle = { isToggle }
6290 size = { args . isCompact ? 'small' : undefined }
6391 >
6492 { item . text }
65- </ Button >
93+ </ GroupButton >
6694 ) : (
6795 < Input
6896 key = { index }
6997 placeholder = { item . text }
7098 readOnly = { readOnly }
7199 disabled = { disabled }
72100 isCompact = { args . isCompact }
101+ validation = { inputValidation }
73102 />
74103 )
75104 ) }
0 commit comments