/
EditorSearchInput.story.js
108 lines (102 loc) · 2.65 KB
/
EditorSearchInput.story.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React from 'react'
import { storiesOf } from '@kadira/storybook'
import { action, decorateAction } from '@kadira/storybook-addon-actions'
import RealEditorSearchInput from '.'
// Simple wrapper component to handle text updates for the story
// Uses the component name so it shows accurately how to use it
class EditorSearchInput extends React.Component {
constructor(props) {
super(props)
this.state = {
search: props.search,
advanced: props.advanced
}
this.toggleAdvanced = ::this.toggleAdvanced
this.updateSearch = ::this.updateSearch
}
toggleAdvanced () {
// ensure the action is visible in the logger
this.props.toggleAdvanced()
this.setState({
advanced: !this.state.advanced
})
}
updateSearch (search) {
// ensure the action is visible in the logger
this.props.updateSearch(search)
this.setState({
search: {
...this.state.search,
...search
}
})
}
render () {
return (
<RealEditorSearchInput
advanced={this.state.advanced}
search={this.state.search}
updateSearch={this.updateSearch}
toggleAdvanced={this.toggleAdvanced}
/>
)
}
}
const blankSearch = {
text: '',
resourceId: '',
lastModifiedBy: '',
lastModifiedBefore: '',
lastModifiedAfter: '',
sourceComment: '',
translationComment: '',
msgctxt: ''
}
storiesOf('EditorSearchInput', module)
.add('empty', () => (
<EditorSearchInput
search={blankSearch}
updateSearch={action('updateSearch')}
advanced={false}
toggleAdvanced={action('toggleAdvanced')}
/>
))
.add('simple search', () => (
<EditorSearchInput
search={{
...blankSearch,
text: 'it was the'
}}
updateSearch={action('updateSearch')}
advanced={false}
toggleAdvanced={action('toggleAdvanced')}
/>
))
.add('advanced panel open', () => (
<EditorSearchInput
search={{
...blankSearch,
text: 'it was the worst'
}}
updateSearch={action('updateSearch')}
advanced={true}
toggleAdvanced={action('toggleAdvanced')}
/>
))
.add('advanced search', () => (
<EditorSearchInput
search={{
text: 'it was the worst of',
resourceId: 'para-0001',
lastModifiedBy: 'cdickens',
lastModifiedBefore: '1859-12-31',
lastModifiedAfter: '1859-01-01',
sourceComment: 'England and France',
translationComment: 'blurst of times?! You stupid monkey!',
msgctxt: 'chapter01.txt'
}}
updateSearch={action('updateSearch')}
advanced={true}
toggleAdvanced={action('toggleAdvanced')}
/>
))