@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/CHANGELOG.md
CHANGED
@@ -3,6 +3,15 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [2.0.0-alpha.146](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.145...v2.0.0-alpha.146) (2024-05-29)
|
7
|
+
|
8
|
+
|
9
|
+
### :rocket: New Features
|
10
|
+
|
11
|
+
* ox-select.setOptions(..) method ([e026449](https://github.com/hatiolab/operato/commit/e0264494780fed696b95f16431f774c7a49e4cde))
|
12
|
+
|
13
|
+
|
14
|
+
|
6
15
|
## [2.0.0-alpha.145](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.144...v2.0.0-alpha.145) (2024-05-28)
|
7
16
|
|
8
17
|
**Note:** Version bump only for package @operato/input
|
package/dist/src/ox-select.d.ts
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
*/
|
4
4
|
import '@material/web/icon/icon.js';
|
5
5
|
import '@operato/popup/ox-popup-list.js';
|
6
|
+
import './ox-checkbox.js';
|
6
7
|
import { PropertyValues } from 'lit';
|
7
8
|
import { OxFormField } from './ox-form-field.js';
|
8
|
-
export declare class
|
9
|
+
export declare class OxSelect extends OxFormField {
|
9
10
|
static styles: import("lit").CSSResult[];
|
10
11
|
name: string;
|
11
12
|
placeholder: string;
|
@@ -13,5 +14,12 @@ export declare class Select extends OxFormField {
|
|
13
14
|
render(): import("lit-html").TemplateResult<1>;
|
14
15
|
connectedCallback(): void;
|
15
16
|
updated(changes: PropertyValues<this>): Promise<void>;
|
17
|
+
setOptions(options: string[] | {
|
18
|
+
display: string;
|
19
|
+
value: string;
|
20
|
+
}[], opt?: {
|
21
|
+
multiple?: boolean;
|
22
|
+
withSearch?: boolean;
|
23
|
+
}): void;
|
16
24
|
expand(): void;
|
17
25
|
}
|
package/dist/src/ox-select.js
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
import { __decorate } from "tslib";
|
5
5
|
import '@material/web/icon/icon.js';
|
6
6
|
import '@operato/popup/ox-popup-list.js';
|
7
|
-
import
|
7
|
+
import './ox-checkbox.js';
|
8
|
+
import { css, html, render } from 'lit';
|
8
9
|
import { customElement, property, state } from 'lit/decorators.js';
|
9
10
|
import { TooltipStyles } from '@operato/styles';
|
10
11
|
import { detectOverflow } from '@operato/utils';
|
@@ -19,7 +20,7 @@ function onmouseout(e) {
|
|
19
20
|
const element = e.target;
|
20
21
|
element.removeAttribute('data-tooltip');
|
21
22
|
}
|
22
|
-
let
|
23
|
+
let OxSelect = class OxSelect extends OxFormField {
|
23
24
|
constructor() {
|
24
25
|
super(...arguments);
|
25
26
|
this.name = '';
|
@@ -118,11 +119,44 @@ let Select = class Select extends OxFormField {
|
|
118
119
|
async updated(changes) {
|
119
120
|
if (changes.has('value')) {
|
120
121
|
const popupList = this.querySelector('ox-popup-list');
|
121
|
-
popupList
|
122
|
-
|
123
|
-
|
122
|
+
if (popupList) {
|
123
|
+
popupList.value = this.value;
|
124
|
+
await this.requestUpdate();
|
125
|
+
this.label = popupList.getSelectedLabels();
|
126
|
+
}
|
124
127
|
}
|
125
128
|
}
|
129
|
+
setOptions(options, opt = {}) {
|
130
|
+
const objOptions = options.map(option => {
|
131
|
+
return typeof option == 'string' ? { display: option, value: option } : option;
|
132
|
+
});
|
133
|
+
const { multiple, withSearch } = opt || {};
|
134
|
+
const template = html `
|
135
|
+
<ox-popup-list
|
136
|
+
align-left
|
137
|
+
nowrap
|
138
|
+
?multiple=${multiple}
|
139
|
+
attr-selected=${multiple ? 'checked' : ''}
|
140
|
+
?with-search=${withSearch}
|
141
|
+
>
|
142
|
+
${multiple
|
143
|
+
? html `<ox-checkbox
|
144
|
+
@change=${(e) => {
|
145
|
+
const target = e.target;
|
146
|
+
const options = Array.from(target.parentElement.querySelectorAll('[option]')).filter(option => !option.hasAttribute('hidden'));
|
147
|
+
options.forEach(option => (option.checked = target.checked));
|
148
|
+
this.value = options
|
149
|
+
.map(option => option.checked ? option.value : undefined)
|
150
|
+
.filter(Boolean);
|
151
|
+
}}
|
152
|
+
>set all</ox-checkbox
|
153
|
+
>
|
154
|
+
${objOptions.map(option => html ` <ox-checkbox option value=${option.value}>${option.display}</ox-checkbox> `)} `
|
155
|
+
: html `${objOptions.map(option => html ` <div option value=${option.value}>${option.display}</div> `)}`}
|
156
|
+
</ox-popup-list>
|
157
|
+
`;
|
158
|
+
render(template, this);
|
159
|
+
}
|
126
160
|
expand() {
|
127
161
|
if (this.disabled) {
|
128
162
|
return;
|
@@ -141,15 +175,15 @@ let Select = class Select extends OxFormField {
|
|
141
175
|
};
|
142
176
|
__decorate([
|
143
177
|
property({ type: String })
|
144
|
-
],
|
178
|
+
], OxSelect.prototype, "name", void 0);
|
145
179
|
__decorate([
|
146
180
|
property({ type: String })
|
147
|
-
],
|
181
|
+
], OxSelect.prototype, "placeholder", void 0);
|
148
182
|
__decorate([
|
149
183
|
state()
|
150
|
-
],
|
151
|
-
|
184
|
+
], OxSelect.prototype, "label", void 0);
|
185
|
+
OxSelect = __decorate([
|
152
186
|
customElement('ox-select')
|
153
|
-
],
|
154
|
-
export {
|
187
|
+
], OxSel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IlB","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport '@material/web/icon/icon.js'\nimport '@operato/popup/ox-popup-list.js'\n\nimport { css, html, PropertyValues } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { OxPopupList } from '@operato/popup'\nimport { TooltipStyles } from '@operato/styles'\nimport { detectOverflow } from '@operato/utils'\n\nimport { OxFormField } from './ox-form-field.js'\n\nfunction onmouseover(e: Event) {\n const element = e.target as HTMLSpanElement\n if (detectOverflow(element)) {\n element.setAttribute('data-tooltip', element.textContent!)\n }\n}\n\nfunction onmouseout(e: Event) {\n const element = e.target as HTMLSpanElement\n element.removeAttribute('data-tooltip')\n}\n\n@customElement('ox-select')\nexport class Select extends OxFormField {\n static styles = [\n TooltipStyles,\n css`\n :host {\n display: block;\n position: relative;\n border-bottom: var(--border-dark-color);\n\n --ox-select-padding: var(--input-padding);\n --ox-select-font: var(--input-font);\n --ox-select-color: var(--input-color);\n --ox-select-icon-color: var(--theme-primary-text-color, #3c3938);\n --ox-select-icon-hover-color: var(--primary-color, #3c3938);\n }\n\n div {\n width: 100%;\n box-sizing: border-box;\n\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n padding: var(--ox-select-padding);\n font: var(--ox-select-font);\n color: var(--ox-select-color);\n }\n\n span {\n flex: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n gap: 4px;\n }\n\n md-icon {\n --md-icon-size: 16px;\n display: block;\n text-align: right;\n color: var(--ox-select-icon-color);\n opacity: 0.7;\n }\n\n div:hover md-icon {\n color: var(--primary-color);\n }\n\n ::slotted(ox-popup-list) {\n width: 100%;\n }\n `\n ]\n\n @property({ type: String }) name: string = ''\n @property({ type: String }) placeholder: string = ''\n\n @state() label: string | string[] = ''\n\n render() {\n const label =\n (this.label instanceof Array ? this.label.join(', ') : this.label?.trim()) ||\n (this.value instanceof Array ? this.value.join(', ') : this.value?.trim()) ||\n this.placeholder ||\n ''\n\n return html`\n <div @click=${this.expand}>\n <span @mouseover=${onmouseover} @mouseout=${onmouseout}>${label}</span>\n <md-icon>expand_more</md-icon>\n </div>\n\n <slot></slot>\n `\n }\n\n connectedCallback() {\n super.connectedCallback()\n\n this.setAttribute('tabindex', '0')\n\n this.addEventListener('select', (e: Event) => {\n this.value = (e as CustomEvent).detail\n })\n\n this.addEventListener('close', e => {\n /* popup이 close될 때 change 이벤트를 발생시킨다. */\n this.dispatchEvent(\n new CustomEvent('change', {\n bubbles: true,\n composed: true,\n detail: this.value\n })\n )\n })\n\n this.addEventListener('keydown', (e: KeyboardEvent) => {\n e.preventDefault()\n\n if (e.key === ' ' || e.key === 'Spacebar' || e.key === 'ArrowDown') {\n this.expand()\n }\n })\n }\n\n async updated(changes: PropertyValues<this>) {\n if (changes.has('value')) {\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n popupList.value = this.value\n\n await this.requestUpdate()\n\n this.label = popupList.getSelectedLabels()\n }\n }\n\n expand() {\n if (this.disabled) {\n return\n }\n\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n\n if (popupList) {\n popupList.style.width = `${this.offsetWidth}px`\n const align = popupList.hasAttribute('align-left') ? 'left' : 'right'\n\n const props = {\n top: this.offsetHeight,\n [align]: 0\n }\n\n popupList.open(props)\n }\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"ox-select.js","sourceRoot":"","sources":["../../src/ox-select.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,4BAA4B,CAAA;AACnC,OAAO,iCAAiC,CAAA;AACxC,OAAO,kBAAkB,CAAA;AAEzB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAA2B,MAAM,KAAK,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGzE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,cAAc,EA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list.js'\nimport './ox-checkbox.js'\n\nimport { css, html, render, PropertyValues, nothing } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { OxPopupList } from '@operato/popup'\nimport { TooltipStyles } from '@operato/styles'\nimport { detectOverflow } from '@operato/utils'\n\nimport { OxFormField } from './ox-form-field.js'\n\nfunction onmouseover(e: Event) {\n const element = e.target as HTMLSpanElement\n if (detectOverflow(element)) {\n element.setAttribute('data-tooltip', element.textContent!)\n }\n}\n\nfunction onmouseout(e: Event) {\n const element = e.target as HTMLSpanElement\n element.removeAttribute('data-tooltip')\n}\n\n@customElement('ox-select')\nexport class OxSelect extends OxFormField {\n static styles = [\n TooltipStyles,\n css`\n :host {\n display: block;\n position: relative;\n border-bottom: var(--border-dark-color);\n\n --ox-select-padding: var(--input-padding);\n --ox-select-font: var(--input-font);\n --ox-select-color: var(--input-color);\n --ox-select-icon-color: var(--theme-primary-text-color, #3c3938);\n --ox-select-icon-hover-color: var(--primary-color, #3c3938);\n }\n\n div {\n width: 100%;\n box-sizing: border-box;\n\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n padding: var(--ox-select-padding);\n font: var(--ox-select-font);\n color: var(--ox-select-color);\n }\n\n span {\n flex: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n gap: 4px;\n }\n\n md-icon {\n --md-icon-size: 16px;\n display: block;\n text-align: right;\n color: var(--ox-select-icon-color);\n opacity: 0.7;\n }\n\n div:hover md-icon {\n color: var(--primary-color);\n }\n\n ::slotted(ox-popup-list) {\n width: 100%;\n }\n `\n ]\n\n @property({ type: String }) name: string = ''\n @property({ type: String }) placeholder: string = ''\n\n @state() label: string | string[] = ''\n\n render() {\n const label =\n (this.label instanceof Array ? this.label.join(', ') : this.label?.trim()) ||\n (this.value instanceof Array ? this.value.join(', ') : this.value?.trim()) ||\n this.placeholder ||\n ''\n\n return html`\n <div @click=${this.expand}>\n <span @mouseover=${onmouseover} @mouseout=${onmouseout}>${label}</span>\n <md-icon>expand_more</md-icon>\n </div>\n\n <slot></slot>\n `\n }\n\n connectedCallback() {\n super.connectedCallback()\n\n this.setAttribute('tabindex', '0')\n\n this.addEventListener('select', (e: Event) => {\n this.value = (e as CustomEvent).detail\n })\n\n this.addEventListener('close', e => {\n /* popup이 close될 때 change 이벤트를 발생시킨다. */\n this.dispatchEvent(\n new CustomEvent('change', {\n bubbles: true,\n composed: true,\n detail: this.value\n })\n )\n })\n\n this.addEventListener('keydown', (e: KeyboardEvent) => {\n e.preventDefault()\n\n if (e.key === ' ' || e.key === 'Spacebar' || e.key === 'ArrowDown') {\n this.expand()\n }\n })\n }\n\n async updated(changes: PropertyValues<this>) {\n if (changes.has('value')) {\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n if (popupList) {\n popupList.value = this.value\n await this.requestUpdate()\n\n this.label = popupList.getSelectedLabels()\n }\n }\n }\n\n setOptions(\n options: string[] | { display: string; value: string }[],\n opt: { multiple?: boolean; withSearch?: boolean } = {}\n ) {\n const objOptions = options.map(option => {\n return typeof option == 'string' ? { display: option, value: option } : option\n })\n\n const { multiple, withSearch } = opt || {}\n\n const template = html`\n <ox-popup-list\n align-left\n nowrap\n ?multiple=${multiple}\n attr-selected=${multiple ? 'checked' : ''}\n ?with-search=${withSearch}\n >\n ${multiple\n ? html`<ox-checkbox\n @change=${(e: Event) => {\n const target = e.target as HTMLInputElement\n const options = Array.from(target.parentElement!.querySelectorAll('[option]')).filter(\n option => !option.hasAttribute('hidden')\n )\n options.forEach(option => ((option as HTMLInputElement).checked = target.checked))\n\n this.value = options\n .map(option =>\n (option as HTMLInputElement).checked ? (option as HTMLInputElement).value : undefined\n )\n .filter(Boolean)\n }}\n >set all</ox-checkbox\n >\n ${objOptions.map(\n option => html` <ox-checkbox option value=${option.value}>${option.display}</ox-checkbox> `\n )} `\n : html`${objOptions.map(option => html` <div option value=${option.value}>${option.display}</div> `)}`}\n </ox-popup-list>\n `\n\n render(template, this)\n }\n\n expand() {\n if (this.disabled) {\n return\n }\n\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n\n if (popupList) {\n popupList.style.width = `${this.offsetWidth}px`\n const align = popupList.hasAttribute('align-left') ? 'left' : 'right'\n\n const props = {\n top: this.offsetHeight,\n [align]: 0\n }\n\n popupList.open(props)\n }\n }\n}\n"]}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import '../src/ox-select.js';
|
2
|
+
import '../src/ox-checkbox.js';
|
3
|
+
import { TemplateResult } from 'lit';
|
4
|
+
declare const _default: {
|
5
|
+
title: string;
|
6
|
+
component: string;
|
7
|
+
argTypes: {
|
8
|
+
placeholder: {
|
9
|
+
control: string;
|
10
|
+
};
|
11
|
+
name: {
|
12
|
+
control: string;
|
13
|
+
};
|
14
|
+
options: {
|
15
|
+
control: string;
|
16
|
+
};
|
17
|
+
multiple: {
|
18
|
+
control: string;
|
19
|
+
};
|
20
|
+
withSearch: {
|
21
|
+
control: string;
|
22
|
+
};
|
23
|
+
disabled: {
|
24
|
+
control: string;
|
25
|
+
};
|
26
|
+
};
|
27
|
+
};
|
28
|
+
export default _default;
|
29
|
+
interface Story<T> {
|
30
|
+
(args: T): TemplateResult;
|
31
|
+
args?: Partial<T>;
|
32
|
+
argTypes?: Record<string, unknown>;
|
33
|
+
}
|
34
|
+
interface ArgTypes {
|
35
|
+
placeholder?: string;
|
36
|
+
name?: string;
|
37
|
+
value?: object | string;
|
38
|
+
options?: string[] | {
|
39
|
+
display: string;
|
40
|
+
value: string;
|
41
|
+
}[];
|
42
|
+
multiple?: boolean;
|
43
|
+
withSearch?: boolean;
|
44
|
+
disabled?: boolean;
|
45
|
+
}
|
46
|
+
export declare const Regular: Story<ArgTypes>;
|
47
|
+
export declare const MultipleSelect: Story<ArgTypes>;
|
48
|
+
export declare const MultipleWithCheckbox: Story<ArgTypes>;
|
@@ -0,0 +1,158 @@
|
|
1
|
+
import '../src/ox-select.js';
|
2
|
+
import '../src/ox-checkbox.js';
|
3
|
+
import { html } from 'lit';
|
4
|
+
export default {
|
5
|
+
title: 'ox-select-set-options',
|
6
|
+
component: 'ox-select',
|
7
|
+
argTypes: {
|
8
|
+
placeholder: { control: 'text' },
|
9
|
+
name: { control: 'text' },
|
10
|
+
options: { control: 'object' },
|
11
|
+
multiple: { control: 'boolean' },
|
12
|
+
withSearch: { control: 'boolean' },
|
13
|
+
disabled: { control: 'boolean' }
|
14
|
+
}
|
15
|
+
};
|
16
|
+
const Template = ({ placeholder = 'Checkbox', name = 'hello', value = '', options = [], multiple, withSearch, disabled }) => html `
|
17
|
+
<link href="/themes/app-theme.css" rel="stylesheet" />
|
18
|
+
|
19
|
+
<link
|
20
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
|
21
|
+
rel="stylesheet"
|
22
|
+
/>
|
23
|
+
<link
|
24
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
|
25
|
+
rel="stylesheet"
|
26
|
+
/>
|
27
|
+
<link
|
28
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
|
29
|
+
rel="stylesheet"
|
30
|
+
/>
|
31
|
+
|
32
|
+
<div style="height: 300px">
|
33
|
+
<ox-select
|
34
|
+
name=${name}
|
35
|
+
@change=${(e) => {
|
36
|
+
console.log(e.target.value);
|
37
|
+
}}
|
38
|
+
placeholder=${placeholder}
|
39
|
+
.value=${value}
|
40
|
+
?disabled=${disabled}
|
41
|
+
>
|
42
|
+
</ox-select>
|
43
|
+
|
44
|
+
<input
|
45
|
+
type="button"
|
46
|
+
value="set options"
|
47
|
+
@click=${() => {
|
48
|
+
const select = document.querySelector('ox-select');
|
49
|
+
select.setOptions(options, { multiple, withSearch });
|
50
|
+
select.value = JSON.parse(JSON.stringify(value));
|
51
|
+
}}
|
52
|
+
/>
|
53
|
+
</div>
|
54
|
+
`;
|
55
|
+
export const Regular = Template.bind({});
|
56
|
+
Regular.args = {
|
57
|
+
placeholder: 'single select',
|
58
|
+
name: 'label',
|
59
|
+
value: '',
|
60
|
+
multiple: false,
|
61
|
+
options: [
|
62
|
+
{
|
63
|
+
value: 'A',
|
64
|
+
display: 'LABEL-A'
|
65
|
+
},
|
66
|
+
{
|
67
|
+
value: 'B',
|
68
|
+
display: 'LABEL-B'
|
69
|
+
},
|
70
|
+
{
|
71
|
+
value: 'C',
|
72
|
+
display: 'LABEL-C'
|
73
|
+
},
|
74
|
+
{
|
75
|
+
value: 'TOO LONG VALUE',
|
76
|
+
display: 'LABEL-TOO LONG VALUE'
|
77
|
+
}
|
78
|
+
]
|
79
|
+
};
|
80
|
+
export const MultipleSelect = Template.bind({});
|
81
|
+
MultipleSelect.args = {
|
82
|
+
placeholder: 'multiple select',
|
83
|
+
name: 'multiple',
|
84
|
+
multiple: true,
|
85
|
+
withSearch: true,
|
86
|
+
value: ['B', 'TOO LONG VALUE'],
|
87
|
+
options: [
|
88
|
+
'A',
|
89
|
+
'B',
|
90
|
+
'C',
|
91
|
+
'D',
|
92
|
+
'E',
|
93
|
+
'F',
|
94
|
+
'G',
|
95
|
+
'H',
|
96
|
+
'I',
|
97
|
+
'J',
|
98
|
+
'K',
|
99
|
+
'L',
|
100
|
+
'M',
|
101
|
+
'O',
|
102
|
+
'P',
|
103
|
+
'Q',
|
104
|
+
'R',
|
105
|
+
'S',
|
106
|
+
'T',
|
107
|
+
'U',
|
108
|
+
'V',
|
109
|
+
'W',
|
110
|
+
'X',
|
111
|
+
'Y',
|
112
|
+
'Z',
|
113
|
+
'TOO LONG VALUE'
|
114
|
+
]
|
115
|
+
};
|
116
|
+
export const MultipleWithCheckbox = Template.bind({});
|
117
|
+
MultipleWithCheckbox.args = {
|
118
|
+
placeholder: 'multiple with checkbox',
|
119
|
+
name: 'multiple',
|
120
|
+
multiple: true,
|
121
|
+
withSearch: true,
|
122
|
+
value: ['B', 'C', 'F'],
|
123
|
+
options: [
|
124
|
+
{
|
125
|
+
value: 'A',
|
126
|
+
display: 'A'
|
127
|
+
},
|
128
|
+
{
|
129
|
+
value: 'B',
|
130
|
+
display: 'B'
|
131
|
+
},
|
132
|
+
{
|
133
|
+
value: 'C',
|
134
|
+
display: 'C'
|
135
|
+
},
|
136
|
+
{
|
137
|
+
value: 'D',
|
138
|
+
display: 'D'
|
139
|
+
},
|
140
|
+
{
|
141
|
+
value: 'E',
|
142
|
+
display: 'E'
|
143
|
+
},
|
144
|
+
{
|
145
|
+
value: 'F',
|
146
|
+
display: 'F'
|
147
|
+
},
|
148
|
+
{
|
149
|
+
value: 'G',
|
150
|
+
display: 'G'
|
151
|
+
},
|
152
|
+
{
|
153
|
+
value: 'TOO LONG VALUE',
|
154
|
+
display: 'TOO LONG VALUE'
|
155
|
+
}
|
156
|
+
]
|
157
|
+
};
|
158
|
+
//# sourceMappingURL=ox-select-set-options.stories.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ox-select-set-options.stories.js","sourceRoot":"","sources":["../../stories/ox-select-set-options.stories.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAA;AAC5B,OAAO,uBAAuB,CAAA;AAG9B,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAE1C,eAAe;IACb,KAAK,EAAE,uBAAuB;IAC9B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE;QACR,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QAChC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QACzB,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;QAC9B,QAAQ,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;QAChC,UAAU,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;QAClC,QAAQ,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;KACjC;CACF,CAAA;AAkBD,MAAM,QAAQ,GAAoB,CAAC,EACjC,WAAW,GAA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src/ox-select.js'\nimport '../src/ox-checkbox.js'\n\nimport { OxSelect } from '../src/ox-select.js'\nimport { html, TemplateResult } from 'lit'\n\nexport default {\n title: 'ox-select-set-options',\n component: 'ox-select',\n argTypes: {\n placeholder: { control: 'text' },\n name: { control: 'text' },\n options: { control: 'object' },\n multiple: { control: 'boolean' },\n withSearch: { control: 'boolean' },\n disabled: { control: 'boolean' }\n }\n}\n\ninterface Story<T> {\n (args: T): TemplateResult\n args?: Partial<T>\n argTypes?: Record<string, unknown>\n}\n\ninterface ArgTypes {\n placeholder?: string\n name?: string\n value?: object | string\n options?: string[] | { display: string; value: string }[]\n multiple?: boolean\n withSearch?: boolean\n disabled?: boolean\n}\n\nconst Template: Story<ArgTypes> = ({\n placeholder = 'Checkbox',\n name = 'hello',\n value = '',\n options = [],\n multiple,\n withSearch,\n disabled\n}: ArgTypes) => html`\n <link href=\"/themes/app-theme.css\" rel=\"stylesheet\" />\n\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n\n <div style=\"height: 300px\">\n <ox-select\n name=${name}\n @change=${(e: Event) => {\n console.log((e.target as HTMLInputElement).value)\n }}\n placeholder=${placeholder}\n .value=${value}\n ?disabled=${disabled}\n >\n </ox-select>\n\n <input\n type=\"button\"\n value=\"set options\"\n @click=${() => {\n const select = document.querySelector('ox-select') as OxSelect\n select.setOptions(options, { multiple, withSearch })\n select.value = JSON.parse(JSON.stringify(value))\n }}\n />\n </div>\n`\n\nexport const Regular = Template.bind({})\nRegular.args = {\n placeholder: 'single select',\n name: 'label',\n value: '',\n multiple: false,\n options: [\n {\n value: 'A',\n display: 'LABEL-A'\n },\n {\n value: 'B',\n display: 'LABEL-B'\n },\n {\n value: 'C',\n display: 'LABEL-C'\n },\n {\n value: 'TOO LONG VALUE',\n display: 'LABEL-TOO LONG VALUE'\n }\n ]\n}\n\nexport const MultipleSelect = Template.bind({})\nMultipleSelect.args = {\n placeholder: 'multiple select',\n name: 'multiple',\n multiple: true,\n withSearch: true,\n value: ['B', 'TOO LONG VALUE'],\n options: [\n 'A',\n 'B',\n 'C',\n 'D',\n 'E',\n 'F',\n 'G',\n 'H',\n 'I',\n 'J',\n 'K',\n 'L',\n 'M',\n 'O',\n 'P',\n 'Q',\n 'R',\n 'S',\n 'T',\n 'U',\n 'V',\n 'W',\n 'X',\n 'Y',\n 'Z',\n 'TOO LONG VALUE'\n ]\n}\n\nexport const MultipleWithCheckbox = Template.bind({})\nMultipleWithCheckbox.args = {\n placeholder: 'multiple with checkbox',\n name: 'multiple',\n multiple: true,\n withSearch: true,\n value: ['B', 'C', 'F'],\n options: [\n {\n value: 'A',\n display: 'A'\n },\n {\n value: 'B',\n display: 'B'\n },\n {\n value: 'C',\n display: 'C'\n },\n {\n value: 'D',\n display: 'D'\n },\n {\n value: 'E',\n display: 'E'\n },\n {\n value: 'F',\n display: 'F'\n },\n {\n value: 'G',\n display: 'G'\n },\n {\n value: 'TOO LONG VALUE',\n display: 'TOO LONG VALUE'\n }\n ]\n}\n"]}
|
@@ -101,9 +101,11 @@ MultipleWithCheckbox.args = {
|
|
101
101
|
option
|
102
102
|
@change=${(e) => {
|
103
103
|
const target = e.target;
|
104
|
-
const options = target.parentElement.querySelectorAll('[option]');
|
105
|
-
console.log(options);
|
104
|
+
const options = Array.from(target.parentElement.querySelectorAll('[option]')).filter(option => !option.hasAttribute('hidden'));
|
106
105
|
options.forEach(option => (option.checked = target.checked));
|
106
|
+
target.closest('ox-select').value = options
|
107
|
+
.map(option => (option.checked ? option.value : undefined))
|
108
|
+
.filter(Boolean);
|
107
109
|
}}
|
108
110
|
>set all</ox-checkbox
|
109
111
|
>
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ox-select.stories.js","sourceRoot":"","sources":["../../stories/ox-select.stories.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAA;AAC5B,OAAO,uBAAuB,CAAA;AAE9B,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAE1C,eAAe;IACb,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE;QACR,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QAChC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QACzB,QAAQ,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;KACjC;CACF,CAAA;AAgBD,MAAM,QAAQ,GAAoB,CAAC,EACjC,WAAW,GAAG,UAAU,EACxB,IAAI,GAAG,OAAO,EACd,KAAK,GAAG,EAAE,EACV,IAAI,EACJ,QAAQ,EACC,EAAE,EAAE,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;;;aAkBP,IAAI;gBACD,CAAC,CAAQ,EAAE,EAAE;IACrB,OAAO,CAAC,GAAG,CAAE,CAAC,CAAC,MAA2B,CAAC,KAAK,CAAC,CAAA;AACnD,CAAC;oBACa,WAAW;eAChB,KAAK;kBACF,QAAQ;;QAElB,IAAI;;;CAGX,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACxC,OAAO,CAAC,IAAI,GAAG;IACb,WAAW,EAAE,eAAe;IAC5B,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,IAAI,CAAA;;;;;;;GAOT;CACF,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC/C,cAAc,CAAC,IAAI,GAAG;IACpB,WAAW,EAAE,iBAAiB;IAC9B,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CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAE,MAA2B,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CACjF;QAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAU,CAAC,KAAK,GAAG,OAAO;aACnD,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAE,MAA2B,CAAC,OAAO,CAAC,CAAC,CAAE,MAA2B,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;aACtG,MAAM,CAAC,OAAO,CAAC,CAAA;IACpB,CAAC;;;;;;;;;;;;GAYN;CACF,CAAA","sourcesContent":["import '../src/ox-select.js'\nimport '../src/ox-checkbox.js'\n\nimport { html, TemplateResult } from 'lit'\n\nexport default {\n title: 'ox-select',\n component: 'ox-select',\n argTypes: {\n placeholder: { control: 'text' },\n name: { control: 'text' },\n disabled: { control: 'boolean' }\n }\n}\n\ninterface Story<T> {\n (args: T): TemplateResult\n args?: Partial<T>\n argTypes?: Record<string, unknown>\n}\n\ninterface ArgTypes {\n placeholder?: string\n name?: string\n value?: object | string\n slot?: TemplateResult\n disabled?: boolean\n}\n\nconst Template: Story<ArgTypes> = ({\n placeholder = 'Checkbox',\n name = 'hello',\n value = '',\n slot,\n disabled\n}: ArgTypes) => html`\n <link href=\"/themes/app-theme.css\" rel=\"stylesheet\" />\n\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n\n <div style=\"height: 300px\">\n <ox-select\n name=${name}\n @change=${(e: Event) => {\n console.log((e.target as HTMLInputElement).value)\n }}\n placeholder=${placeholder}\n .value=${value}\n ?disabled=${disabled}\n >\n ${slot}\n </ox-select>\n </div>\n`\n\nexport const Regular = Template.bind({})\nRegular.args = {\n placeholder: 'single select',\n name: 'label',\n value: '',\n slot: html`\n <ox-popup-list align-left nowrap>\n <div option value=\"A\">LABEL-A</div>\n <div option value=\"B\">LABEL-B</div>\n <div option value=\"C\">LABEL-C</div>\n <div option value=\"TOO LONG VALUE\">LABEL-TOO LONG VALUE</div>\n </ox-popup-list>\n `\n}\n\nexport const MultipleSelect = Template.bind({})\nMultipleSelect.args = {\n placeholder: 'multiple select',\n name: 'multiple',\n value: ['B', 'TOO LONG VALUE'],\n slot: html`\n <ox-popup-list multiple with-search>\n <div option value=\"A\">A</div>\n <div option value=\"B\">B</div>\n <div option value=\"C\">C</div>\n <div option value=\"D\">D</div>\n <div option value=\"E\">E</div>\n <div option value=\"F\">F</div>\n <div option value=\"G\">G</div>\n <div option value=\"H\">H</div>\n <div option value=\"I\">I</div>\n <div option value=\"J\">J</div>\n <div option value=\"K\">K</div>\n <div option value=\"L\">L</div>\n <div option value=\"M\">M</div>\n <div option value=\"O\">O</div>\n <div option value=\"P\">P</div>\n <div option value=\"Q\">Q</div>\n <div option value=\"R\">R</div>\n <div option value=\"S\">S</div>\n <div option value=\"T\">T</div>\n <div option value=\"U\">U</div>\n <div option value=\"V\">V</div>\n <div option value=\"W\">W</div>\n <div option value=\"X\">X</div>\n <div option value=\"Y\">Y</div>\n <div option value=\"Z\">Z</div>\n <div option value=\"TOO LONG VALUE\" />TOO LONG VALUE</div>\n </ox-popup-list>\n `\n}\n\nexport const MultipleWithCheckbox = Template.bind({})\nMultipleWithCheckbox.args = {\n placeholder: 'multiple with checkbox',\n name: 'multiple',\n value: ['B', 'C', 'F'],\n slot: html`\n <ox-popup-list attr-selected=\"checked\" multiple with-search>\n <ox-checkbox\n option\n @change=${(e: Event) => {\n const target = e.target as HTMLInputElement\n const options = Array.from(target.parentElement!.querySelectorAll('[option]')).filter(\n option => !option.hasAttribute('hidden')\n )\n options.forEach(option => ((option as HTMLInputElement).checked = target.checked))\n ;(target.closest('ox-select') as any)!.value = options\n .map(option => ((option as HTMLInputElement).checked ? (option as HTMLInputElement).value : undefined))\n .filter(Boolean)\n }}\n >set all</ox-checkbox\n >\n <ox-checkbox option value=\"A\">LABEL-A</ox-checkbox>\n <ox-checkbox option value=\"B\">LABEL-B</ox-checkbox>\n <ox-checkbox option value=\"C\" checked>LABEL-C</ox-checkbox>\n <ox-checkbox option value=\"D\">LABEL-D</ox-checkbox>\n <ox-checkbox option value=\"E\">LABEL-E</ox-checkbox>\n <ox-checkbox option value=\"F\">LABEL-F</ox-checkbox>\n <ox-checkbox option value=\"G\">LABEL-G</ox-checkbox>\n <ox-checkbox option value=\"TOO LONG VALUE\">TOO LONG VALUE</ox-checkbox>\n </ox-popup-list>\n `\n}\n"]}
|