@operato/form 2.0.0-alpha.122 → 2.0.0-alpha.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/src/components/ox-search-form.js +32 -6
- package/dist/src/components/ox-search-form.js.map +1 -1
- package/dist/src/types.d.ts +2 -0
- package/dist/src/types.js.map +1 -1
- package/dist/stories/ox-search-form-change-handler.stories.d.ts +34 -0
- package/dist/stories/ox-search-form-change-handler.stories.js +225 -0
- package/dist/stories/ox-search-form-change-handler.stories.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/ox-search-form.ts +43 -8
- package/src/types.ts +3 -0
- package/stories/ox-search-form-change-handler.stories.ts +250 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { CommonHeaderStyles } from '@operato/styles'
|
|
2
|
+
import { sleep } from '@operato/utils'
|
|
3
|
+
import '../src/components/ox-search-form.js'
|
|
4
|
+
|
|
5
|
+
import { html, TemplateResult } from 'lit'
|
|
6
|
+
import { OxSearchForm, SearchFormField } from '../src/index.js'
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: 'ox-search-form change handler',
|
|
10
|
+
component: 'ox-search-form',
|
|
11
|
+
argTypes: {
|
|
12
|
+
value: { control: 'object' },
|
|
13
|
+
fields: { control: 'object' },
|
|
14
|
+
hideSearchButton: { control: 'boolean' },
|
|
15
|
+
autofocus: { control: 'boolean' }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface Story<T> {
|
|
20
|
+
(args: T): TemplateResult
|
|
21
|
+
args?: Partial<T>
|
|
22
|
+
argTypes?: Record<string, unknown>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ArgTypes {
|
|
26
|
+
fields?: SearchFormField[]
|
|
27
|
+
hideSearchButton?: boolean
|
|
28
|
+
autofocus?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const Template: Story<ArgTypes> = ({ fields, hideSearchButton, autofocus }: ArgTypes) => html`
|
|
32
|
+
<link href="/themes/app-theme.css" rel="stylesheet" />
|
|
33
|
+
<link href="/themes/form-theme.css" rel="stylesheet" />
|
|
34
|
+
<link href="/themes/input-theme.css" rel="stylesheet" />
|
|
35
|
+
|
|
36
|
+
<link
|
|
37
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
|
|
38
|
+
rel="stylesheet"
|
|
39
|
+
/>
|
|
40
|
+
<link
|
|
41
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
|
|
42
|
+
rel="stylesheet"
|
|
43
|
+
/>
|
|
44
|
+
<link
|
|
45
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
|
|
46
|
+
rel="stylesheet"
|
|
47
|
+
/>
|
|
48
|
+
|
|
49
|
+
<style>
|
|
50
|
+
body {
|
|
51
|
+
height: 500px;
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
54
|
+
|
|
55
|
+
<style>
|
|
56
|
+
ox-search-form {
|
|
57
|
+
--input-gap-vertical: 8px;
|
|
58
|
+
--input-gap-horizontal: 16px;
|
|
59
|
+
|
|
60
|
+
--ox-filters-input-placeholder-color: var(--primary-color);
|
|
61
|
+
|
|
62
|
+
--ox-filters-input-border: 1px solid rgba(0, 0, 0, 0.2);
|
|
63
|
+
--ox-filters-input-focus-border: 1px solid var(--primary-color);
|
|
64
|
+
--ox-filters-input-font: normal 14px var(--theme-font);
|
|
65
|
+
--ox-filters-input-color: var(--primary-text-color);
|
|
66
|
+
--ox-filters-input-focus-color: var(--primary-color);
|
|
67
|
+
--ox-filters-label-font: normal 14px var(--theme-font);
|
|
68
|
+
--ox-filters-label-color: var(--primary-text-color);
|
|
69
|
+
|
|
70
|
+
--ox-filters-form-gap: var(--input-gap-vertical, 8px) var(--input-gap-horizontal, 16px);
|
|
71
|
+
--ox-filters-input-padding: 6px 2px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
${CommonHeaderStyles.cssText}
|
|
75
|
+
</style>
|
|
76
|
+
|
|
77
|
+
<div class="header">
|
|
78
|
+
<div class="filters">
|
|
79
|
+
<ox-search-form
|
|
80
|
+
.fields=${fields!}
|
|
81
|
+
?autofocus=${autofocus}
|
|
82
|
+
?hideSearchButton=${hideSearchButton}
|
|
83
|
+
@change=${(e: CustomEvent) => {
|
|
84
|
+
console.log('search form changed', e.detail)
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
</ox-search-form>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
`
|
|
91
|
+
|
|
92
|
+
const WAREHOUSE = [
|
|
93
|
+
{
|
|
94
|
+
id: '01',
|
|
95
|
+
name: '제 1 창고',
|
|
96
|
+
zones: [
|
|
97
|
+
{
|
|
98
|
+
id: 'Z001',
|
|
99
|
+
name: 'Zone 01-001',
|
|
100
|
+
locations: ['L01-001-01', 'L01-001-02', 'L01-001-03', 'L01-001-04', 'L01-001-05']
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'Z002',
|
|
104
|
+
name: 'Zone 01-002',
|
|
105
|
+
locations: ['L01-002-01', 'L01-002-02', 'L01-002-03', 'L01-002-04', 'L01-002-05']
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: '02',
|
|
111
|
+
name: '제 2 창고',
|
|
112
|
+
zones: [
|
|
113
|
+
{
|
|
114
|
+
id: 'Z001',
|
|
115
|
+
name: 'Zone 02-001',
|
|
116
|
+
locations: ['L02-001-01', 'L02-001-02', 'L02-001-03', 'L02-001-04', 'L02-001-05']
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: 'Z002',
|
|
120
|
+
name: 'Zone 02-002',
|
|
121
|
+
locations: ['L02-002-01', 'L02-002-02', 'L02-002-03', 'L02-002-04', 'L02-002-05']
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
export const Regular = Template.bind({})
|
|
128
|
+
Regular.args = {
|
|
129
|
+
fields: [
|
|
130
|
+
{
|
|
131
|
+
type: 'select',
|
|
132
|
+
name: 'warehouse',
|
|
133
|
+
label: 'warehouse',
|
|
134
|
+
options: async (form: OxSearchForm) => {
|
|
135
|
+
await sleep(1000) // 테스트를 위해서 강제로 1초 쉬기
|
|
136
|
+
return [
|
|
137
|
+
{
|
|
138
|
+
display: '',
|
|
139
|
+
value: ''
|
|
140
|
+
}
|
|
141
|
+
].concat(
|
|
142
|
+
WAREHOUSE.map(w => {
|
|
143
|
+
return {
|
|
144
|
+
display: w.name,
|
|
145
|
+
value: w.id
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
)
|
|
149
|
+
},
|
|
150
|
+
onchange: () => false
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: 'select',
|
|
154
|
+
name: 'zone',
|
|
155
|
+
label: 'zone',
|
|
156
|
+
boundTo: ['warehouse'],
|
|
157
|
+
options: async (form: OxSearchForm) => {
|
|
158
|
+
await sleep(1000) // 테스트를 위해서 강제로 1초 쉬기
|
|
159
|
+
const formData = new FormData(await form.form)
|
|
160
|
+
const warehouse = formData?.get('warehouse')
|
|
161
|
+
console.log('warehouse', warehouse)
|
|
162
|
+
|
|
163
|
+
const targetWH = warehouse && WAREHOUSE.find(w => w.id == warehouse)
|
|
164
|
+
const zones = targetWH
|
|
165
|
+
? targetWH.zones
|
|
166
|
+
: WAREHOUSE.reduce((sum, warehouse) => {
|
|
167
|
+
sum = sum.concat(warehouse.zones)
|
|
168
|
+
return sum
|
|
169
|
+
}, [] as any[])
|
|
170
|
+
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
display: '',
|
|
174
|
+
value: ''
|
|
175
|
+
}
|
|
176
|
+
].concat(
|
|
177
|
+
zones.map((z: any) => {
|
|
178
|
+
return {
|
|
179
|
+
display: z.name,
|
|
180
|
+
value: z.id
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
)
|
|
184
|
+
},
|
|
185
|
+
onchange: () => false
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: 'location',
|
|
189
|
+
type: 'select',
|
|
190
|
+
label: 'location',
|
|
191
|
+
boundTo: ['warehouse', 'zone'],
|
|
192
|
+
options: async (form: OxSearchForm) => {
|
|
193
|
+
await sleep(1000) // 테스트를 위해서 강제로 1초 쉬기
|
|
194
|
+
const formData = new FormData(await form.form)
|
|
195
|
+
const warehouse = formData?.get('warehouse')
|
|
196
|
+
const zone = formData?.get('zone')
|
|
197
|
+
console.log('warehouse, zone', warehouse, zone)
|
|
198
|
+
|
|
199
|
+
const targetWH = (warehouse && WAREHOUSE.find(w => w.id == warehouse)) || null
|
|
200
|
+
const targetZone = zone && targetWH?.zones.find(z => z.id == zone)
|
|
201
|
+
return targetZone ? ['', ...targetZone.locations] : []
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
hideSearchButton: true,
|
|
206
|
+
autofocus: true
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export const RegularContact = Template.bind({})
|
|
210
|
+
RegularContact.args = {
|
|
211
|
+
fields: [
|
|
212
|
+
{
|
|
213
|
+
label: 'name',
|
|
214
|
+
name: 'name',
|
|
215
|
+
type: 'text',
|
|
216
|
+
placeholder: 'type your name.',
|
|
217
|
+
props: { searchOper: 'i_like' },
|
|
218
|
+
onchange: value => {
|
|
219
|
+
console.log('changed', value)
|
|
220
|
+
return false
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
label: 'email',
|
|
225
|
+
name: 'email',
|
|
226
|
+
type: 'text',
|
|
227
|
+
props: { searchOper: 'i_like' }
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
label: 'fax',
|
|
231
|
+
name: 'fax',
|
|
232
|
+
type: 'text',
|
|
233
|
+
props: { searchOper: 'i_like' }
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
label: 'phone',
|
|
237
|
+
name: 'phone',
|
|
238
|
+
type: 'text',
|
|
239
|
+
props: { searchOper: 'i_like' }
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
label: 'description',
|
|
243
|
+
name: 'description',
|
|
244
|
+
type: 'text',
|
|
245
|
+
props: { searchOper: 'i_like' }
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
hideSearchButton: true,
|
|
249
|
+
autofocus: true
|
|
250
|
+
}
|