1
+ /* eslint-disable react/prop-types, react/display-name */
1
2
import React from 'react' ;
3
+ import { Value } from 'react-value' ;
2
4
import { storiesOf } from '@storybook/react' ;
3
5
import { withKnobs , boolean , text } from '@storybook/addon-knobs/react' ;
4
6
import { action } from '@storybook/addon-actions' ;
@@ -7,52 +9,70 @@ import Spacings from '../../spacings';
7
9
import Section from '../../../../.storybook/decorators/section' ;
8
10
import RichTextInput from './rich-text-input' ;
9
11
import Readme from './README.md' ;
10
- import TextInput from '../text-input' ;
11
12
12
13
// Create our initial value...
13
14
14
15
const initialValue = RichTextInput . deserialize ( '' ) ;
16
+
17
+ const Input = props => {
18
+ return (
19
+ < Value
20
+ defaultValue = { initialValue }
21
+ render = { ( value , onChange ) => (
22
+ < RichTextInput
23
+ id = { props . id }
24
+ name = { props . name }
25
+ key = { `rich-text-input-${ props . defaultExpandMultilineText } ` }
26
+ onChange = { event => onChange ( event . target . value ) }
27
+ value = { value }
28
+ onBlur = { props . onBlur }
29
+ onFocus = { props . onFocus }
30
+ defaultExpandMultilineText = { props . defaultExpandMultilineText }
31
+ placeholder = { props . placeholder }
32
+ onClickExpand = { props . onClickExpand }
33
+ showExpandIcon = { props . showExpandIcon }
34
+ hasError = { props . hasError }
35
+ hasWarning = { props . hasWarning }
36
+ isDisabled = { props . isDisabled }
37
+ isReadOnly = { props . isReadOnly }
38
+ />
39
+ ) }
40
+ />
41
+ ) ;
42
+ } ;
43
+
15
44
storiesOf ( 'Components|Inputs' , module )
16
45
. addDecorator ( withKnobs )
17
46
. addDecorator ( withReadme ( Readme ) )
18
47
. add ( 'RichTextInput' , ( ) => {
19
- const [ value , setValue ] = React . useState ( initialValue ) ;
20
-
21
- const onChange = React . useCallback ( event => setValue ( event . target . value ) , [
22
- setValue ,
23
- ] ) ;
24
-
25
- const [ textValue , setTextValue ] = React . useState ( '' ) ;
48
+ const onClickExpand = React . useCallback ( ( ) => {
49
+ // eslint-disable-next-line no-alert
50
+ alert ( 'Expand' ) ;
51
+ } , [ ] ) ;
26
52
27
53
const onBlur = React . useCallback ( action ( 'onBlur' ) , [ ] ) ;
28
54
const onFocus = React . useCallback ( action ( 'onFocus' ) , [ ] ) ;
29
55
30
56
return (
31
57
< Section >
32
58
< Spacings . Stack scale = "l" >
33
- < RichTextInput
59
+ < Input
34
60
id = { text ( 'id' , 'test-id' ) }
35
61
name = { text ( 'name' , 'test-name' ) }
36
- onChange = { onChange }
62
+ onBlur = { onBlur }
63
+ onFocus = { onFocus }
37
64
defaultExpandMultilineText = { boolean (
38
65
'defaultExpandMultilineText' ,
39
66
false
40
67
) }
41
- value = { value }
42
- onBlur = { onBlur }
43
- onFocus = { onFocus }
44
68
placeholder = { text ( 'placeholder' , 'Placeholder' ) }
69
+ showExpandIcon = { boolean ( 'showExpandIcon' , false ) }
70
+ onClickExpand = { onClickExpand }
45
71
hasError = { boolean ( 'hasError' , false ) }
46
72
hasWarning = { boolean ( 'hasWarning' , false ) }
47
73
isDisabled = { boolean ( 'isDisabled' , false ) }
48
74
isReadOnly = { boolean ( 'isReadOnly' , false ) }
49
75
/>
50
- < TextInput
51
- id = "text-input"
52
- name = "text-input"
53
- onChange = { evt => setTextValue ( evt . target . value ) }
54
- value = { textValue }
55
- />
56
76
</ Spacings . Stack >
57
77
</ Section >
58
78
) ;
0 commit comments