@operato/input 2.0.0-alpha.145 → 2.0.0-alpha.146
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 +9 -0
- package/dist/src/ox-select.d.ts +9 -1
- package/dist/src/ox-select.js +45 -11
- package/dist/src/ox-select.js.map +1 -1
- package/dist/stories/ox-select-set-options.stories.d.ts +48 -0
- package/dist/stories/ox-select-set-options.stories.js +158 -0
- package/dist/stories/ox-select-set-options.stories.js.map +1 -0
- package/dist/stories/ox-select.stories.js +4 -2
- package/dist/stories/ox-select.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/ox-select.ts +54 -7
- package/stories/ox-select-set-options.stories.ts +188 -0
- package/stories/ox-select.stories.ts +6 -2
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@operato/input",
|
3
3
|
"description": "Webcomponents for input following open-wc recommendations",
|
4
4
|
"author": "heartyoh@hatiolab.com",
|
5
|
-
"version": "2.0.0-alpha.
|
5
|
+
"version": "2.0.0-alpha.146",
|
6
6
|
"main": "dist/src/index.js",
|
7
7
|
"module": "dist/src/index.js",
|
8
8
|
"license": "MIT",
|
@@ -243,5 +243,5 @@
|
|
243
243
|
"prettier --write"
|
244
244
|
]
|
245
245
|
},
|
246
|
-
"gitHead": "
|
246
|
+
"gitHead": "12ce58704cf117ec80208e44b58e9ae68aebb3cc"
|
247
247
|
}
|
package/src/ox-select.ts
CHANGED
@@ -4,9 +4,10 @@
|
|
4
4
|
|
5
5
|
import '@material/web/icon/icon.js'
|
6
6
|
import '@operato/popup/ox-popup-list.js'
|
7
|
+
import './ox-checkbox.js'
|
7
8
|
|
8
|
-
import { css, html, PropertyValues } from 'lit'
|
9
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
9
|
+
import { css, html, render, PropertyValues, nothing } from 'lit'
|
10
|
+
import { customElement, property, query, state } from 'lit/decorators.js'
|
10
11
|
|
11
12
|
import { OxPopupList } from '@operato/popup'
|
12
13
|
import { TooltipStyles } from '@operato/styles'
|
@@ -27,7 +28,7 @@ function onmouseout(e: Event) {
|
|
27
28
|
}
|
28
29
|
|
29
30
|
@customElement('ox-select')
|
30
|
-
export class
|
31
|
+
export class OxSelect extends OxFormField {
|
31
32
|
static styles = [
|
32
33
|
TooltipStyles,
|
33
34
|
css`
|
@@ -137,14 +138,60 @@ export class Select extends OxFormField {
|
|
137
138
|
async updated(changes: PropertyValues<this>) {
|
138
139
|
if (changes.has('value')) {
|
139
140
|
const popupList = this.querySelector('ox-popup-list') as OxPopupList
|
140
|
-
popupList
|
141
|
+
if (popupList) {
|
142
|
+
popupList.value = this.value
|
143
|
+
await this.requestUpdate()
|
141
144
|
|
142
|
-
|
143
|
-
|
144
|
-
this.label = popupList.getSelectedLabels()
|
145
|
+
this.label = popupList.getSelectedLabels()
|
146
|
+
}
|
145
147
|
}
|
146
148
|
}
|
147
149
|
|
150
|
+
setOptions(
|
151
|
+
options: string[] | { display: string; value: string }[],
|
152
|
+
opt: { multiple?: boolean; withSearch?: boolean } = {}
|
153
|
+
) {
|
154
|
+
const objOptions = options.map(option => {
|
155
|
+
return typeof option == 'string' ? { display: option, value: option } : option
|
156
|
+
})
|
157
|
+
|
158
|
+
const { multiple, withSearch } = opt || {}
|
159
|
+
|
160
|
+
const template = html`
|
161
|
+
<ox-popup-list
|
162
|
+
align-left
|
163
|
+
nowrap
|
164
|
+
?multiple=${multiple}
|
165
|
+
attr-selected=${multiple ? 'checked' : ''}
|
166
|
+
?with-search=${withSearch}
|
167
|
+
>
|
168
|
+
${multiple
|
169
|
+
? html`<ox-checkbox
|
170
|
+
@change=${(e: Event) => {
|
171
|
+
const target = e.target as HTMLInputElement
|
172
|
+
const options = Array.from(target.parentElement!.querySelectorAll('[option]')).filter(
|
173
|
+
option => !option.hasAttribute('hidden')
|
174
|
+
)
|
175
|
+
options.forEach(option => ((option as HTMLInputElement).checked = target.checked))
|
176
|
+
|
177
|
+
this.value = options
|
178
|
+
.map(option =>
|
179
|
+
(option as HTMLInputElement).checked ? (option as HTMLInputElement).value : undefined
|
180
|
+
)
|
181
|
+
.filter(Boolean)
|
182
|
+
}}
|
183
|
+
>set all</ox-checkbox
|
184
|
+
>
|
185
|
+
${objOptions.map(
|
186
|
+
option => html` <ox-checkbox option value=${option.value}>${option.display}</ox-checkbox> `
|
187
|
+
)} `
|
188
|
+
: html`${objOptions.map(option => html` <div option value=${option.value}>${option.display}</div> `)}`}
|
189
|
+
</ox-popup-list>
|
190
|
+
`
|
191
|
+
|
192
|
+
render(template, this)
|
193
|
+
}
|
194
|
+
|
148
195
|
expand() {
|
149
196
|
if (this.disabled) {
|
150
197
|
return
|
@@ -0,0 +1,188 @@
|
|
1
|
+
import '../src/ox-select.js'
|
2
|
+
import '../src/ox-checkbox.js'
|
3
|
+
|
4
|
+
import { OxSelect } from '../src/ox-select.js'
|
5
|
+
import { html, TemplateResult } from 'lit'
|
6
|
+
|
7
|
+
export default {
|
8
|
+
title: 'ox-select-set-options',
|
9
|
+
component: 'ox-select',
|
10
|
+
argTypes: {
|
11
|
+
placeholder: { control: 'text' },
|
12
|
+
name: { control: 'text' },
|
13
|
+
options: { control: 'object' },
|
14
|
+
multiple: { control: 'boolean' },
|
15
|
+
withSearch: { control: 'boolean' },
|
16
|
+
disabled: { control: 'boolean' }
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
interface Story<T> {
|
21
|
+
(args: T): TemplateResult
|
22
|
+
args?: Partial<T>
|
23
|
+
argTypes?: Record<string, unknown>
|
24
|
+
}
|
25
|
+
|
26
|
+
interface ArgTypes {
|
27
|
+
placeholder?: string
|
28
|
+
name?: string
|
29
|
+
value?: object | string
|
30
|
+
options?: string[] | { display: string; value: string }[]
|
31
|
+
multiple?: boolean
|
32
|
+
withSearch?: boolean
|
33
|
+
disabled?: boolean
|
34
|
+
}
|
35
|
+
|
36
|
+
const Template: Story<ArgTypes> = ({
|
37
|
+
placeholder = 'Checkbox',
|
38
|
+
name = 'hello',
|
39
|
+
value = '',
|
40
|
+
options = [],
|
41
|
+
multiple,
|
42
|
+
withSearch,
|
43
|
+
disabled
|
44
|
+
}: ArgTypes) => html`
|
45
|
+
<link href="/themes/app-theme.css" rel="stylesheet" />
|
46
|
+
|
47
|
+
<link
|
48
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
|
49
|
+
rel="stylesheet"
|
50
|
+
/>
|
51
|
+
<link
|
52
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
|
53
|
+
rel="stylesheet"
|
54
|
+
/>
|
55
|
+
<link
|
56
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
|
57
|
+
rel="stylesheet"
|
58
|
+
/>
|
59
|
+
|
60
|
+
<div style="height: 300px">
|
61
|
+
<ox-select
|
62
|
+
name=${name}
|
63
|
+
@change=${(e: Event) => {
|
64
|
+
console.log((e.target as HTMLInputElement).value)
|
65
|
+
}}
|
66
|
+
placeholder=${placeholder}
|
67
|
+
.value=${value}
|
68
|
+
?disabled=${disabled}
|
69
|
+
>
|
70
|
+
</ox-select>
|
71
|
+
|
72
|
+
<input
|
73
|
+
type="button"
|
74
|
+
value="set options"
|
75
|
+
@click=${() => {
|
76
|
+
const select = document.querySelector('ox-select') as OxSelect
|
77
|
+
select.setOptions(options, { multiple, withSearch })
|
78
|
+
select.value = JSON.parse(JSON.stringify(value))
|
79
|
+
}}
|
80
|
+
/>
|
81
|
+
</div>
|
82
|
+
`
|
83
|
+
|
84
|
+
export const Regular = Template.bind({})
|
85
|
+
Regular.args = {
|
86
|
+
placeholder: 'single select',
|
87
|
+
name: 'label',
|
88
|
+
value: '',
|
89
|
+
multiple: false,
|
90
|
+
options: [
|
91
|
+
{
|
92
|
+
value: 'A',
|
93
|
+
display: 'LABEL-A'
|
94
|
+
},
|
95
|
+
{
|
96
|
+
value: 'B',
|
97
|
+
display: 'LABEL-B'
|
98
|
+
},
|
99
|
+
{
|
100
|
+
value: 'C',
|
101
|
+
display: 'LABEL-C'
|
102
|
+
},
|
103
|
+
{
|
104
|
+
value: 'TOO LONG VALUE',
|
105
|
+
display: 'LABEL-TOO LONG VALUE'
|
106
|
+
}
|
107
|
+
]
|
108
|
+
}
|
109
|
+
|
110
|
+
export const MultipleSelect = Template.bind({})
|
111
|
+
MultipleSelect.args = {
|
112
|
+
placeholder: 'multiple select',
|
113
|
+
name: 'multiple',
|
114
|
+
multiple: true,
|
115
|
+
withSearch: true,
|
116
|
+
value: ['B', 'TOO LONG VALUE'],
|
117
|
+
options: [
|
118
|
+
'A',
|
119
|
+
'B',
|
120
|
+
'C',
|
121
|
+
'D',
|
122
|
+
'E',
|
123
|
+
'F',
|
124
|
+
'G',
|
125
|
+
'H',
|
126
|
+
'I',
|
127
|
+
'J',
|
128
|
+
'K',
|
129
|
+
'L',
|
130
|
+
'M',
|
131
|
+
'O',
|
132
|
+
'P',
|
133
|
+
'Q',
|
134
|
+
'R',
|
135
|
+
'S',
|
136
|
+
'T',
|
137
|
+
'U',
|
138
|
+
'V',
|
139
|
+
'W',
|
140
|
+
'X',
|
141
|
+
'Y',
|
142
|
+
'Z',
|
143
|
+
'TOO LONG VALUE'
|
144
|
+
]
|
145
|
+
}
|
146
|
+
|
147
|
+
export const MultipleWithCheckbox = Template.bind({})
|
148
|
+
MultipleWithCheckbox.args = {
|
149
|
+
placeholder: 'multiple with checkbox',
|
150
|
+
name: 'multiple',
|
151
|
+
multiple: true,
|
152
|
+
withSearch: true,
|
153
|
+
value: ['B', 'C', 'F'],
|
154
|
+
options: [
|
155
|
+
{
|
156
|
+
value: 'A',
|
157
|
+
display: 'A'
|
158
|
+
},
|
159
|
+
{
|
160
|
+
value: 'B',
|
161
|
+
display: 'B'
|
162
|
+
},
|
163
|
+
{
|
164
|
+
value: 'C',
|
165
|
+
display: 'C'
|
166
|
+
},
|
167
|
+
{
|
168
|
+
value: 'D',
|
169
|
+
display: 'D'
|
170
|
+
},
|
171
|
+
{
|
172
|
+
value: 'E',
|
173
|
+
display: 'E'
|
174
|
+
},
|
175
|
+
{
|
176
|
+
value: 'F',
|
177
|
+
display: 'F'
|
178
|
+
},
|
179
|
+
{
|
180
|
+
value: 'G',
|
181
|
+
display: 'G'
|
182
|
+
},
|
183
|
+
{
|
184
|
+
value: 'TOO LONG VALUE',
|
185
|
+
display: 'TOO LONG VALUE'
|
186
|
+
}
|
187
|
+
]
|
188
|
+
}
|
@@ -127,9 +127,13 @@ MultipleWithCheckbox.args = {
|
|
127
127
|
option
|
128
128
|
@change=${(e: Event) => {
|
129
129
|
const target = e.target as HTMLInputElement
|
130
|
-
const options = target.parentElement!.querySelectorAll('[option]')
|
131
|
-
|
130
|
+
const options = Array.from(target.parentElement!.querySelectorAll('[option]')).filter(
|
131
|
+
option => !option.hasAttribute('hidden')
|
132
|
+
)
|
132
133
|
options.forEach(option => ((option as HTMLInputElement).checked = target.checked))
|
134
|
+
;(target.closest('ox-select') as any)!.value = options
|
135
|
+
.map(option => ((option as HTMLInputElement).checked ? (option as HTMLInputElement).value : undefined))
|
136
|
+
.filter(Boolean)
|
133
137
|
}}
|
134
138
|
>set all</ox-checkbox
|
135
139
|
>
|