@lion/ui 0.0.1 → 0.0.3
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/components/core/test/SlotMixin.test.js +28 -21
- package/components/drawer/src/LionDrawer.js +217 -0
- package/components/drawer/src/drawerStyle.js +59 -0
- package/components/drawer/test/lion-drawer.test.js +109 -0
- package/components/localize/src/number/parseNumber.js +15 -36
- package/components/localize/test/number/parseNumber.test.js +3 -12
- package/custom-elements.json +743 -0
- package/dist-types/components/drawer/src/LionDrawer.d.ts +67 -0
- package/dist-types/components/drawer/src/LionDrawer.d.ts.map +1 -0
- package/dist-types/components/drawer/src/drawerStyle.d.ts +2 -0
- package/dist-types/components/drawer/src/drawerStyle.d.ts.map +1 -0
- package/dist-types/components/drawer/test/lion-drawer.test.d.ts +3 -0
- package/dist-types/components/drawer/test/lion-drawer.test.d.ts.map +1 -0
- package/dist-types/components/localize/src/number/parseNumber.d.ts.map +1 -1
- package/dist-types/exports/define/lion-drawer.d.ts +2 -0
- package/dist-types/exports/define/lion-drawer.d.ts.map +1 -0
- package/dist-types/exports/drawer.d.ts +2 -0
- package/dist-types/exports/drawer.d.ts.map +1 -0
- package/dist-types/tsconfig.tsbuildinfo +1 -1
- package/docs/components/accordion/index.md +3 -0
- package/docs/components/accordion/overview.md +129 -0
- package/docs/components/accordion/reference.md +47 -0
- package/docs/components/accordion/use-cases.md +252 -0
- package/docs/components/button/examples.md +30 -0
- package/docs/components/button/index.md +3 -0
- package/docs/components/button/overview.md +30 -0
- package/docs/components/button/src/icon.svg.js +5 -0
- package/docs/components/button/use-cases.md +106 -0
- package/docs/components/calendar/index.md +3 -0
- package/docs/components/calendar/overview.md +49 -0
- package/docs/components/calendar/use-cases.md +192 -0
- package/docs/components/checkbox-group/index.md +3 -0
- package/docs/components/checkbox-group/overview.md +40 -0
- package/docs/components/checkbox-group/use-cases.md +256 -0
- package/docs/components/collapsible/assets/CustomCollapsible.js +113 -0
- package/docs/components/collapsible/assets/applyDemoCollapsibleStyles.js +37 -0
- package/docs/components/collapsible/examples.md +83 -0
- package/docs/components/collapsible/index.md +3 -0
- package/docs/components/collapsible/overview.md +39 -0
- package/docs/components/collapsible/use-cases.md +79 -0
- package/docs/components/combobox/examples.md +153 -0
- package/docs/components/combobox/index.md +3 -0
- package/docs/components/combobox/overview.md +51 -0
- package/docs/components/combobox/src/LinkMixin.js +60 -0
- package/docs/components/combobox/src/demo-selection-display.js +191 -0
- package/docs/components/combobox/src/gh-combobox/gh-button.js +69 -0
- package/docs/components/combobox/src/gh-combobox/gh-combobox.js +508 -0
- package/docs/components/combobox/src/google-combobox/assets/google-clear-icon.js +9 -0
- package/docs/components/combobox/src/google-combobox/assets/google-search-icon.js +9 -0
- package/docs/components/combobox/src/google-combobox/assets/google-voice-search-icon.js +19 -0
- package/docs/components/combobox/src/google-combobox/assets/googlelogo_color_272x92dp.png +0 -0
- package/docs/components/combobox/src/google-combobox/google-combobox.js +460 -0
- package/docs/components/combobox/src/lazyRender.js +29 -0
- package/docs/components/combobox/src/levenshtein.js +95 -0
- package/docs/components/combobox/src/md-combobox/MdFieldMixin.js +341 -0
- package/docs/components/combobox/src/md-combobox/md-combobox.js +89 -0
- package/docs/components/combobox/src/md-combobox/md-input.js +5 -0
- package/docs/components/combobox/src/md-combobox/style/load-roboto.js +6 -0
- package/docs/components/combobox/src/md-combobox/style/md-ripple.js +81 -0
- package/docs/components/combobox/src/wa-combobox/wa-combobox.js +368 -0
- package/docs/components/combobox/use-cases.md +377 -0
- package/docs/components/dialog/index.md +3 -0
- package/docs/components/dialog/overview.md +63 -0
- package/docs/components/dialog/src/demo-dialog-style.js +3 -0
- package/docs/components/dialog/src/demoStyle.js +39 -0
- package/docs/components/dialog/src/slots-dialog-content.js +32 -0
- package/docs/components/dialog/src/styled-dialog-content.js +38 -0
- package/docs/components/dialog/use-cases.md +154 -0
- package/docs/components/drawer/index.md +3 -0
- package/docs/components/drawer/overview.md +68 -0
- package/docs/components/drawer/src/demoStyle.js +71 -0
- package/docs/components/drawer/use-cases.md +194 -0
- package/docs/components/fieldset/index.md +3 -0
- package/docs/components/fieldset/overview.md +49 -0
- package/docs/components/fieldset/use-cases.md +185 -0
- package/docs/components/form/index.md +3 -0
- package/docs/components/form/overview.md +43 -0
- package/docs/components/form/use-cases.md +72 -0
- package/docs/components/icon/assets/bugs/bug01.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug02.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug05.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug06.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug08.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug12.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug19.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug23.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug24.svg.js +2 -0
- package/docs/components/icon/assets/iconset-bugs.js +11 -0
- package/docs/components/icon/assets/iconset-misc.js +3 -0
- package/docs/components/icon/assets/iconset-space.js +31 -0
- package/docs/components/icon/assets/misc/arrowLeft.svg.js +6 -0
- package/docs/components/icon/assets/space/aliens-spaceship.svg.js +2 -0
- package/docs/components/icon/assets/space/meteor.svg.js +2 -0
- package/docs/components/icon/assets/space/moon-flag.svg.js +2 -0
- package/docs/components/icon/assets/space/moon.svg.js +2 -0
- package/docs/components/icon/assets/space/night.svg.js +2 -0
- package/docs/components/icon/assets/space/orbit.svg.js +2 -0
- package/docs/components/icon/assets/space/planet.svg.js +2 -0
- package/docs/components/icon/assets/space/robot.svg.js +2 -0
- package/docs/components/icon/assets/space/rocket.svg.js +2 -0
- package/docs/components/icon/assets/space/satellite.svg.js +2 -0
- package/docs/components/icon/assets/space/signal.svg.js +2 -0
- package/docs/components/icon/assets/space/space-helmet.svg.js +2 -0
- package/docs/components/icon/assets/space/sun.svg.js +2 -0
- package/docs/components/icon/assets/space/telescope.svg.js +2 -0
- package/docs/components/icon/index.md +3 -0
- package/docs/components/icon/overview.md +40 -0
- package/docs/components/icon/use-cases.md +93 -0
- package/docs/components/index.md +7 -0
- package/docs/components/input/index.md +3 -0
- package/docs/components/input/overview.md +36 -0
- package/docs/components/input/use-cases.md +77 -0
- package/docs/components/input-amount/index.md +3 -0
- package/docs/components/input-amount/overview.md +49 -0
- package/docs/components/input-amount/use-cases.md +122 -0
- package/docs/components/input-date/index.md +3 -0
- package/docs/components/input-date/overview.md +39 -0
- package/docs/components/input-date/use-cases.md +83 -0
- package/docs/components/input-datepicker/index.md +3 -0
- package/docs/components/input-datepicker/overview.md +42 -0
- package/docs/components/input-datepicker/use-cases.md +78 -0
- package/docs/components/input-email/index.md +3 -0
- package/docs/components/input-email/overview.md +32 -0
- package/docs/components/input-email/use-cases.md +48 -0
- package/docs/components/input-iban/index.md +3 -0
- package/docs/components/input-iban/overview.md +37 -0
- package/docs/components/input-iban/use-cases.md +102 -0
- package/docs/components/input-range/index.md +3 -0
- package/docs/components/input-range/overview.md +34 -0
- package/docs/components/input-range/use-cases.md +108 -0
- package/docs/components/input-stepper/index.md +3 -0
- package/docs/components/input-stepper/overview.md +36 -0
- package/docs/components/input-stepper/use-cases.md +41 -0
- package/docs/components/input-tel/index.md +3 -0
- package/docs/components/input-tel/overview.md +62 -0
- package/docs/components/input-tel/src/h-region-code-table.js +109 -0
- package/docs/components/input-tel/use-cases.md +307 -0
- package/docs/components/input-tel-dropdown/examples.md +32 -0
- package/docs/components/input-tel-dropdown/index.md +3 -0
- package/docs/components/input-tel-dropdown/overview.md +38 -0
- package/docs/components/input-tel-dropdown/src/intl-input-tel-dropdown.js +127 -0
- package/docs/components/input-tel-dropdown/use-cases.md +159 -0
- package/docs/components/listbox/index.md +3 -0
- package/docs/components/listbox/overview.md +42 -0
- package/docs/components/listbox/src/listboxData.js +65 -0
- package/docs/components/listbox/use-cases.md +147 -0
- package/docs/components/pagination/index.md +3 -0
- package/docs/components/pagination/overview.md +29 -0
- package/docs/components/pagination/use-cases.md +99 -0
- package/docs/components/progress-indicator/assets/my-determinate-progress-bar.js +30 -0
- package/docs/components/progress-indicator/assets/my-indeterminate-progress-spinner.js +55 -0
- package/docs/components/progress-indicator/examples.md +125 -0
- package/docs/components/progress-indicator/index.md +3 -0
- package/docs/components/progress-indicator/overview.md +36 -0
- package/docs/components/radio-group/index.md +3 -0
- package/docs/components/radio-group/overview.md +46 -0
- package/docs/components/radio-group/use-cases.md +140 -0
- package/docs/components/select/index.md +3 -0
- package/docs/components/select/overview.md +44 -0
- package/docs/components/select/use-cases.md +55 -0
- package/docs/components/select-rich/examples.md +31 -0
- package/docs/components/select-rich/index.md +3 -0
- package/docs/components/select-rich/overview.md +46 -0
- package/docs/components/select-rich/src/flagStyles.js +1250 -0
- package/docs/components/select-rich/src/flags.png +0 -0
- package/docs/components/select-rich/src/flags@2x.png +0 -0
- package/docs/components/select-rich/src/intl-select-rich.js +194 -0
- package/docs/components/select-rich/src/regionMetaList.js +1717 -0
- package/docs/components/select-rich/use-cases.md +370 -0
- package/docs/components/steps/index.md +3 -0
- package/docs/components/steps/overview.md +63 -0
- package/docs/components/steps/use-cases.md +163 -0
- package/docs/components/switch/index.md +3 -0
- package/docs/components/switch/overview.md +75 -0
- package/docs/components/switch/reference.md +39 -0
- package/docs/components/switch/use-cases.md +76 -0
- package/docs/components/tabs/examples.md +23 -0
- package/docs/components/tabs/index.md +3 -0
- package/docs/components/tabs/overview.md +48 -0
- package/docs/components/tabs/src/lea-tab-panel.js +24 -0
- package/docs/components/tabs/src/lea-tab.js +45 -0
- package/docs/components/tabs/src/lea-tabs.js +28 -0
- package/docs/components/tabs/use-cases.md +219 -0
- package/docs/components/textarea/index.md +3 -0
- package/docs/components/textarea/overview.md +35 -0
- package/docs/components/textarea/use-cases.md +95 -0
- package/docs/components/tooltip/examples.md +39 -0
- package/docs/components/tooltip/index.md +3 -0
- package/docs/components/tooltip/overview.md +44 -0
- package/docs/components/tooltip/use-cases.md +208 -0
- package/docs/fundamentals/index.md +19 -0
- package/docs/fundamentals/node-tools/babel-plugin-extend-docs/index.md +1 -0
- package/docs/fundamentals/node-tools/babel-plugin-extend-docs/overview.md +233 -0
- package/docs/fundamentals/node-tools/index.md +1 -0
- package/docs/fundamentals/node-tools/providence-analytics/LocalConfiguration.md +68 -0
- package/docs/fundamentals/node-tools/providence-analytics/QueryResult.md +111 -0
- package/docs/fundamentals/node-tools/providence-analytics/analyzer.md +69 -0
- package/docs/fundamentals/node-tools/providence-analytics/assets/_mermaid.svg.js +1202 -0
- package/docs/fundamentals/node-tools/providence-analytics/dashboard.md +22 -0
- package/docs/fundamentals/node-tools/providence-analytics/index.md +1 -0
- package/docs/fundamentals/node-tools/providence-analytics/overview.md +192 -0
- package/docs/fundamentals/node-tools/publish-docs/index.md +1 -0
- package/docs/fundamentals/node-tools/publish-docs/overview.md +136 -0
- package/docs/fundamentals/node-tools/remark-extend/index.md +1 -0
- package/docs/fundamentals/node-tools/remark-extend/overview.md +274 -0
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/index.md +1 -0
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/overview.md +285 -0
- package/docs/fundamentals/rationales/TypeScript.md +18 -0
- package/docs/fundamentals/rationales/index.md +1 -0
- package/docs/fundamentals/rationales/side-effects.md +203 -0
- package/docs/fundamentals/rationales/versioning.md +35 -0
- package/docs/fundamentals/systems/core/index.md +3 -0
- package/docs/fundamentals/systems/core/overview.md +85 -0
- package/docs/fundamentals/systems/form/assets/FormatMixinDiagram-1.svg +1 -0
- package/docs/fundamentals/systems/form/assets/FormatMixinDiagram-2.svg +1 -0
- package/docs/fundamentals/systems/form/assets/FormatMixinDiagram-3.svg +84 -0
- package/docs/fundamentals/systems/form/assets/h-output.js +155 -0
- package/docs/fundamentals/systems/form/formatting-and-parsing.md +245 -0
- package/docs/fundamentals/systems/form/index.md +3 -0
- package/docs/fundamentals/systems/form/interaction-states.md +177 -0
- package/docs/fundamentals/systems/form/model-value.md +35 -0
- package/docs/fundamentals/systems/form/overview.md +82 -0
- package/docs/fundamentals/systems/form/styling.md +101 -0
- package/docs/fundamentals/systems/form/use-cases.md +156 -0
- package/docs/fundamentals/systems/form/validate.md +929 -0
- package/docs/fundamentals/systems/icon/index.md +3 -0
- package/docs/fundamentals/systems/icon/overview.md +124 -0
- package/docs/fundamentals/systems/index.md +1 -0
- package/docs/fundamentals/systems/localize/assets/all-locales.js +437 -0
- package/docs/fundamentals/systems/localize/assets/en-AU.js +6 -0
- package/docs/fundamentals/systems/localize/assets/en-GB.js +6 -0
- package/docs/fundamentals/systems/localize/assets/en-US.js +6 -0
- package/docs/fundamentals/systems/localize/assets/en.js +4 -0
- package/docs/fundamentals/systems/localize/assets/nl-BE.js +6 -0
- package/docs/fundamentals/systems/localize/assets/nl-NL.js +6 -0
- package/docs/fundamentals/systems/localize/assets/nl.js +4 -0
- package/docs/fundamentals/systems/localize/dates.md +195 -0
- package/docs/fundamentals/systems/localize/index.md +3 -0
- package/docs/fundamentals/systems/localize/numbers.md +217 -0
- package/docs/fundamentals/systems/localize/overview.md +48 -0
- package/docs/fundamentals/systems/localize/rationale.md +62 -0
- package/docs/fundamentals/systems/localize/text.md +125 -0
- package/docs/fundamentals/systems/localize/use-cases.md +319 -0
- package/docs/fundamentals/systems/overlays/assets/applyDemoOverlayStyles.js +22 -0
- package/docs/fundamentals/systems/overlays/assets/demo-overlay-backdrop.js +48 -0
- package/docs/fundamentals/systems/overlays/assets/demo-overlay-system.js +42 -0
- package/docs/fundamentals/systems/overlays/assets/umbrella-form.js +133 -0
- package/docs/fundamentals/systems/overlays/configuration.md +453 -0
- package/docs/fundamentals/systems/overlays/form-integration.md +65 -0
- package/docs/fundamentals/systems/overlays/index.md +3 -0
- package/docs/fundamentals/systems/overlays/overview.md +118 -0
- package/docs/fundamentals/systems/overlays/rationale.md +232 -0
- package/docs/fundamentals/systems/overlays/scope.md +176 -0
- package/docs/fundamentals/systems/overlays/use-cases.md +699 -0
- package/docs/fundamentals/tools/ajax/assets/naga.json +9 -0
- package/docs/fundamentals/tools/ajax/assets/pabu.json +9 -0
- package/docs/fundamentals/tools/ajax/index.md +3 -0
- package/docs/fundamentals/tools/ajax/overview.md +128 -0
- package/docs/fundamentals/tools/ajax/use-cases.md +456 -0
- package/docs/fundamentals/tools/helpers/action-logger.md +165 -0
- package/docs/fundamentals/tools/helpers/index.md +3 -0
- package/docs/fundamentals/tools/helpers/overview.md +30 -0
- package/docs/fundamentals/tools/index.md +1 -0
- package/docs/fundamentals/tools/singleton-manager/index.md +3 -0
- package/docs/fundamentals/tools/singleton-manager/overview.md +304 -0
- package/docs/guides/how-to/create-a-custom-field.md +200 -0
- package/docs/guides/how-to/extend-a-native-input.md +66 -0
- package/docs/guides/how-to/get-started.md +77 -0
- package/docs/guides/how-to/index.md +1 -0
- package/docs/guides/index.md +34 -0
- package/docs/guides/principles/definitions-and-terms.md +41 -0
- package/docs/guides/principles/index.md +26 -0
- package/docs/guides/principles/scoped-elements.md +103 -0
- package/docs/guides/principles/styling.md +32 -0
- package/docs/guides/principles/subclasser-apis.md +28 -0
- package/docs/override.js +15 -0
- package/exports/define/lion-drawer.js +3 -0
- package/exports/drawer.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Collapsible >> Examples ||30
|
|
2
|
+
|
|
3
|
+
```js script
|
|
4
|
+
import { html } from '@mdjs/mdjs-preview';
|
|
5
|
+
import '@lion/ui/define/lion-collapsible.js';
|
|
6
|
+
import '@lion/ui/define/lion-button.js';
|
|
7
|
+
import './assets/CustomCollapsible.js';
|
|
8
|
+
import './assets/applyDemoCollapsibleStyles.js';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Custom Invoker Template
|
|
12
|
+
|
|
13
|
+
A custom template can be specified to the `invoker` slot. It can be any button or custom component which mimics the button behavior for better accessibility support. In the below example, `lion-button` and native `button` with styling is used as a collapsible invoker.
|
|
14
|
+
|
|
15
|
+
```js preview-story
|
|
16
|
+
export const customInvokerTemplate = () => html`
|
|
17
|
+
<lion-collapsible style="margin-top:16px;">
|
|
18
|
+
<lion-button slot="invoker">More about cars</lion-button>
|
|
19
|
+
<div slot="content">
|
|
20
|
+
Most definitions of cars say that they run primarily on roads, seat one to eight people, have
|
|
21
|
+
four tires, and mainly transport people rather than goods.
|
|
22
|
+
</div>
|
|
23
|
+
</lion-collapsible>
|
|
24
|
+
`;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Extended collapsible with animation
|
|
28
|
+
|
|
29
|
+
`LionCollapsible` can easily be extended to add more features in the component, like animation for example.
|
|
30
|
+
|
|
31
|
+
```js preview-story
|
|
32
|
+
export const customAnimation = () => html`
|
|
33
|
+
<div class="demo-custom-collapsible-container">
|
|
34
|
+
<div class="demo-custom-collapsible-body">
|
|
35
|
+
A motorcycle, often called a motorbike, bike, or cycle, is a two- or three-wheeled motor
|
|
36
|
+
vehicle.
|
|
37
|
+
</div>
|
|
38
|
+
<custom-collapsible>
|
|
39
|
+
<button class="demo-custom-collapsible-invoker" slot="invoker">MORE ABOUT MOTORCYCLES</button>
|
|
40
|
+
<div slot="content">
|
|
41
|
+
Motorcycle design varies greatly to suit a range of different purposes: long distance
|
|
42
|
+
travel, commuting, cruising, sport including racing, and off-road riding. Motorcycling is
|
|
43
|
+
riding a motorcycle and related social activity such as joining a motorcycle club and
|
|
44
|
+
attending motorcycle rallies.
|
|
45
|
+
</div>
|
|
46
|
+
</custom-collapsible>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="demo-custom-collapsible-container">
|
|
49
|
+
<div class="demo-custom-collapsible-body">
|
|
50
|
+
A car (or automobile) is a wheeled motor vehicle used for transportation.
|
|
51
|
+
</div>
|
|
52
|
+
<custom-collapsible opened>
|
|
53
|
+
<button class="demo-custom-collapsible-invoker" slot="invoker">MORE ABOUT CARS</button>
|
|
54
|
+
<div slot="content">
|
|
55
|
+
Most definitions of cars say that they run primarily on roads, seat one to eight people,
|
|
56
|
+
have four tires, and mainly transport people rather than goods.
|
|
57
|
+
</div>
|
|
58
|
+
</custom-collapsible>
|
|
59
|
+
</div>
|
|
60
|
+
`;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Use `_showAnimation()` and `_hideAnimation()` methods to customize open and close behavior. Check the code for a full example of a `custom-collapsible`.
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
_showAnimation({ contentNode }) {
|
|
67
|
+
const expectedHeight = await this.__calculateHeight(contentNode);
|
|
68
|
+
contentNode.style.setProperty('opacity', '1');
|
|
69
|
+
contentNode.style.setProperty('padding', '12px 0');
|
|
70
|
+
contentNode.style.setProperty('max-height', '0px');
|
|
71
|
+
await new Promise(resolve => requestAnimationFrame(() => resolve()));
|
|
72
|
+
contentNode.style.setProperty('max-height', expectedHeight);
|
|
73
|
+
await this._waitForTransition({ contentNode });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_hideAnimation({ contentNode }) {
|
|
77
|
+
if (this._contentHeight === '0px') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
['opacity', 'padding', 'max-height'].map(prop => contentNode.style.setProperty(prop, 0));
|
|
81
|
+
await this._waitForTransition({ contentNode });
|
|
82
|
+
}
|
|
83
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Collapsible >> Overview ||10
|
|
2
|
+
|
|
3
|
+
A combination of a button (the invoker) and a chunk of 'extra content'. This web component can be extended with an animation to disclose the extra content. There are two slots available respectively; `invoker` to specify the collapsible's invoker and `content` for the extra content of the collapsible.
|
|
4
|
+
|
|
5
|
+
```js script
|
|
6
|
+
import { html } from '@mdjs/mdjs-preview';
|
|
7
|
+
import '@lion/ui/define/lion-collapsible.js';
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```js preview-story
|
|
11
|
+
export const main = () => html`
|
|
12
|
+
<lion-collapsible>
|
|
13
|
+
<button slot="invoker">More about cars</button>
|
|
14
|
+
<div slot="content">
|
|
15
|
+
Most definitions of cars say that they run primarily on roads, seat one to eight people, have
|
|
16
|
+
four tires, and mainly transport people rather than goods.
|
|
17
|
+
</div>
|
|
18
|
+
</lion-collapsible>
|
|
19
|
+
`;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Use `opened` attribute or `toggle()` method to render default open.
|
|
25
|
+
- `invoker` slot can be custom template e.g. our [button](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/components/button/overview.md) or native `button` with custom styling.
|
|
26
|
+
- Observe the state with the help of `@opened-changed` event.
|
|
27
|
+
- `show()` and `hide()` are helper methods to hide or show the content from outside.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm i --save @lion/ui
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { LionCollapsible } from '@lion/ui/collapsible.js';
|
|
37
|
+
// or
|
|
38
|
+
import '@lion/ui/define/lion-collapsible.js';
|
|
39
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Collapsible >> Use Cases ||20
|
|
2
|
+
|
|
3
|
+
```js script
|
|
4
|
+
import { html } from '@mdjs/mdjs-preview';
|
|
5
|
+
import '@lion/ui/define/lion-collapsible.js';
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
## Default open
|
|
9
|
+
|
|
10
|
+
Add the `opened` attribute to keep the component default open.
|
|
11
|
+
|
|
12
|
+
```js preview-story
|
|
13
|
+
export const defaultOpen = () => html`
|
|
14
|
+
<lion-collapsible opened>
|
|
15
|
+
<button slot="invoker">More about cars</button>
|
|
16
|
+
<div slot="content">
|
|
17
|
+
Most definitions of cars say that they run primarily on roads, seat one to eight people, have
|
|
18
|
+
four tires, and mainly transport people rather than goods.
|
|
19
|
+
</div>
|
|
20
|
+
</lion-collapsible>
|
|
21
|
+
`;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Methods
|
|
25
|
+
|
|
26
|
+
There are the following methods available to control the extra content for the collapsible.
|
|
27
|
+
|
|
28
|
+
- `toggle()`: toggle the extra content
|
|
29
|
+
- `show()`: show the extra content
|
|
30
|
+
- `hide()`: hide the extra content
|
|
31
|
+
|
|
32
|
+
```js preview-story
|
|
33
|
+
export const methods = ({ shadowRoot }) => html`
|
|
34
|
+
<lion-collapsible id="car-collapsible">
|
|
35
|
+
<button slot="invoker">More about cars</button>
|
|
36
|
+
<div slot="content">
|
|
37
|
+
Most definitions of cars say that they run primarily on roads, seat one to eight people, have
|
|
38
|
+
four tires, and mainly transport people rather than goods.
|
|
39
|
+
</div>
|
|
40
|
+
</lion-collapsible>
|
|
41
|
+
<section style="margin-top:16px">
|
|
42
|
+
<button @click=${() => shadowRoot.querySelector('#car-collapsible').toggle()}>
|
|
43
|
+
Toggle content
|
|
44
|
+
</button>
|
|
45
|
+
<button @click=${() => shadowRoot.querySelector('#car-collapsible').show()}>
|
|
46
|
+
Show content
|
|
47
|
+
</button>
|
|
48
|
+
<button @click=${() => shadowRoot.querySelector('#car-collapsible').hide()}>
|
|
49
|
+
Hide content
|
|
50
|
+
</button>
|
|
51
|
+
</section>
|
|
52
|
+
`;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Events
|
|
56
|
+
|
|
57
|
+
`lion-collapsible` fires an event on `invoker` click to notify the component's current state. It is useful for analytics purposes or to perform some actions while expanding and collapsing the component.
|
|
58
|
+
|
|
59
|
+
- `@opened-changed`: triggers when collapsible either gets opened or closed
|
|
60
|
+
|
|
61
|
+
```js preview-story
|
|
62
|
+
export const events = ({ shadowRoot }) => html`
|
|
63
|
+
<div class="demo-custom-collapsible-state-container">
|
|
64
|
+
<strong id="collapsible-state"></strong>
|
|
65
|
+
</div>
|
|
66
|
+
<lion-collapsible
|
|
67
|
+
@opened-changed=${ev => {
|
|
68
|
+
const collapsibleState = shadowRoot.getElementById('collapsible-state');
|
|
69
|
+
collapsibleState.innerText = `Opened: ${ev.target.opened}`;
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<button slot="invoker">More about cars</button>
|
|
73
|
+
<div slot="content">
|
|
74
|
+
Most definitions of cars say that they run primarily on roads, seat one to eight people, have
|
|
75
|
+
four tires, and mainly transport people rather than goods.
|
|
76
|
+
</div>
|
|
77
|
+
</lion-collapsible>
|
|
78
|
+
`;
|
|
79
|
+
```
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Combobox >> Examples ||30
|
|
2
|
+
|
|
3
|
+
```js script
|
|
4
|
+
import { html } from '@mdjs/mdjs-preview';
|
|
5
|
+
import './src/md-combobox/md-combobox.js';
|
|
6
|
+
import './src/gh-combobox/gh-combobox.js';
|
|
7
|
+
import './src/wa-combobox/wa-combobox.js';
|
|
8
|
+
import './src/google-combobox/google-combobox.js';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Below several extensions can be found. They illustrate that complex UI components can be created
|
|
12
|
+
easily from an extended Lion component, just by:
|
|
13
|
+
|
|
14
|
+
- **configuring**: setting properties or providing conditions via methods
|
|
15
|
+
- **enhancing**: adding extra html/styles/logic without changing behavior of the extended element
|
|
16
|
+
- **overriding**: replace html/styles/logic of the extended element with your own
|
|
17
|
+
|
|
18
|
+
## Material Design
|
|
19
|
+
|
|
20
|
+
```js preview-story
|
|
21
|
+
export const MaterialDesign = () => html`
|
|
22
|
+
<md-combobox name="combo" label="Default">
|
|
23
|
+
<md-option .choiceValue=${'Apple'}>Apple</md-option>
|
|
24
|
+
<md-option .choiceValue=${'Artichoke'}>Artichoke</md-option>
|
|
25
|
+
<md-option .choiceValue=${'Asparagus'}>Asparagus</md-option>
|
|
26
|
+
<md-option .choiceValue=${'Banana'}>Banana</md-option>
|
|
27
|
+
<md-option .choiceValue=${'Beets'}>Beets</md-option>
|
|
28
|
+
</md-combobox>
|
|
29
|
+
`;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Github
|
|
33
|
+
|
|
34
|
+
```js preview-story
|
|
35
|
+
export const Github = () => html`
|
|
36
|
+
<gh-combobox name="combo" label="Switch branches/tags">
|
|
37
|
+
<gh-option href="https://www.github.com" .choiceValue=${'master'} default>master</gh-option>
|
|
38
|
+
<gh-option .choiceValue=${'develop'}>develop</gh-option>
|
|
39
|
+
<gh-option .choiceValue=${'release'}>release</gh-option>
|
|
40
|
+
<gh-option .choiceValue=${'feat/abc'}>feat/abc</gh-option>
|
|
41
|
+
<gh-option .choiceValue=${'feat/xyz123'}>feat/xyz123</gh-option>
|
|
42
|
+
</gh-combobox>
|
|
43
|
+
`;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Whatsapp
|
|
47
|
+
|
|
48
|
+
```js preview-story
|
|
49
|
+
export const Whatsapp = () => html`
|
|
50
|
+
<wa-combobox name="combo" label="Filter chats">
|
|
51
|
+
<wa-option
|
|
52
|
+
title="Barack Obama"
|
|
53
|
+
text="Yup, let's try that for now👍"
|
|
54
|
+
time="15:02"
|
|
55
|
+
is-user-text
|
|
56
|
+
is-user-text-read
|
|
57
|
+
image="https://pbs.twimg.com/profile_images/822547732376207360/5g0FC8XX_400x400.jpg"
|
|
58
|
+
.choiceValue=${'Barack Obama'}
|
|
59
|
+
></wa-option>
|
|
60
|
+
<wa-option
|
|
61
|
+
title="Donald Trump"
|
|
62
|
+
text="Take care!"
|
|
63
|
+
time="14:59"
|
|
64
|
+
is-user-text
|
|
65
|
+
image="https://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_400x400.jpg"
|
|
66
|
+
.choiceValue=${'Donald Trump'}
|
|
67
|
+
></wa-option>
|
|
68
|
+
<wa-option
|
|
69
|
+
title="Joe Biden"
|
|
70
|
+
text="Hehe😅. You too, man, you too..."
|
|
71
|
+
time="yesterday"
|
|
72
|
+
image="https://pbs.twimg.com/profile_images/1308769664240160770/AfgzWVE7_400x400.jpg"
|
|
73
|
+
.choiceValue=${'Joe Biden'}
|
|
74
|
+
></wa-option>
|
|
75
|
+
<wa-option
|
|
76
|
+
title="George W. Bush"
|
|
77
|
+
time="friday"
|
|
78
|
+
text="You bet I will. Let's catch up soon!"
|
|
79
|
+
image="https://pbs.twimg.com/profile_images/828483922266877954/ljYUWUCu_400x400.jpg"
|
|
80
|
+
.choiceValue=${'George W. Bush'}
|
|
81
|
+
></wa-option>
|
|
82
|
+
<wa-option
|
|
83
|
+
title="Bill Clinton"
|
|
84
|
+
time="thursday"
|
|
85
|
+
text="Dude...😂 😂 😂"
|
|
86
|
+
image="https://pbs.twimg.com/profile_images/1239440892664086529/iY0Z83Dr_400x400.jpg"
|
|
87
|
+
.choiceValue=${'Bill Clinton'}
|
|
88
|
+
></wa-option>
|
|
89
|
+
</wa-combobox>
|
|
90
|
+
`;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Whatsapp example shows:**
|
|
94
|
+
|
|
95
|
+
- advanced styling
|
|
96
|
+
- how to match/highlight text on multiple rows of the option (not just choiceValue)
|
|
97
|
+
- how to animate options
|
|
98
|
+
|
|
99
|
+
## Google Search
|
|
100
|
+
|
|
101
|
+
```js preview-story
|
|
102
|
+
export const GoogleSearch = () => {
|
|
103
|
+
return html`
|
|
104
|
+
<google-combobox name="combo" label="Google Search">
|
|
105
|
+
<google-option
|
|
106
|
+
href="https://www.google.com/search?query=apple"
|
|
107
|
+
target="_blank"
|
|
108
|
+
rel="noopener noreferrer"
|
|
109
|
+
.choiceValue=${'Apple'}
|
|
110
|
+
>Apple</google-option
|
|
111
|
+
>
|
|
112
|
+
<google-option
|
|
113
|
+
href="https://www.google.com/search?query=Artichoke"
|
|
114
|
+
target="_blank"
|
|
115
|
+
rel="noopener noreferrer"
|
|
116
|
+
.choiceValue=${'Artichoke'}
|
|
117
|
+
>Artichoke</google-option
|
|
118
|
+
>
|
|
119
|
+
<google-option
|
|
120
|
+
href="https://www.google.com/search?query=Asparagus"
|
|
121
|
+
target="_blank"
|
|
122
|
+
rel="noopener noreferrer"
|
|
123
|
+
.choiceValue=${'Asparagus'}
|
|
124
|
+
>Asparagus</google-option
|
|
125
|
+
>
|
|
126
|
+
<google-option
|
|
127
|
+
href="https://www.google.com/search?query=Banana"
|
|
128
|
+
target="_blank"
|
|
129
|
+
rel="noopener noreferrer"
|
|
130
|
+
.choiceValue=${'Banana'}
|
|
131
|
+
>Banana</google-option
|
|
132
|
+
>
|
|
133
|
+
<google-option
|
|
134
|
+
href="https://www.google.com/search?query=Beets"
|
|
135
|
+
target="_blank"
|
|
136
|
+
rel="noopener noreferrer"
|
|
137
|
+
.choiceValue=${'Beets'}
|
|
138
|
+
>Beets</google-option
|
|
139
|
+
>
|
|
140
|
+
</google-combobox>
|
|
141
|
+
<div style="height:200px;"></div>
|
|
142
|
+
`;
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Google Search example shows:**
|
|
147
|
+
|
|
148
|
+
- advanced styling
|
|
149
|
+
- how to use options that are links
|
|
150
|
+
- create exact user experience of Google Search, by:
|
|
151
|
+
- using autocomplete 'list' as a fundament (we don't want inline completion in textbox)
|
|
152
|
+
- enhancing `_showOverlayCondition`: open on focus
|
|
153
|
+
- enhancing `_syncToTextboxCondition`: always sync to textbox when navigating by keyboard (this needs to be enabled, since it's not provided in the "autocomplete=list" preset)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Combobox >> Overview ||10
|
|
2
|
+
|
|
3
|
+
A combobox is a widget made up of the combination of two distinct elements:
|
|
4
|
+
|
|
5
|
+
- a single-line textbox
|
|
6
|
+
- an associated listbox overlay
|
|
7
|
+
|
|
8
|
+
Based on the combobox configuration and entered textbox value, options in the listbox will be
|
|
9
|
+
filtered, checked, focused and the textbox value may be autocompleted.
|
|
10
|
+
Optionally, the combobox contains a graphical button adjacent to the textbox, indicating the
|
|
11
|
+
availability of the pop-up.
|
|
12
|
+
|
|
13
|
+
> Fore more information, consult [Combobox wai-aria design pattern](https://www.w3.org/TR/wai-aria-practices/#combobox)
|
|
14
|
+
|
|
15
|
+
```js script
|
|
16
|
+
import { html } from '@mdjs/mdjs-preview';
|
|
17
|
+
import { listboxData } from '../listbox/src/listboxData.js';
|
|
18
|
+
import '@lion/ui/define/lion-combobox.js';
|
|
19
|
+
import '@lion/ui/define/lion-option.js';
|
|
20
|
+
import { lazyRender } from './src/lazyRender.js';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```js preview-story
|
|
24
|
+
export const main = () => html`
|
|
25
|
+
<lion-combobox name="combo" label="Default">
|
|
26
|
+
${lazyRender(
|
|
27
|
+
listboxData.map(
|
|
28
|
+
(entry, i) =>
|
|
29
|
+
html` <lion-option .checked="${i === 0}" .choiceValue="${entry}">${entry}</lion-option> `,
|
|
30
|
+
),
|
|
31
|
+
)}
|
|
32
|
+
</lion-combobox>
|
|
33
|
+
`;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
[...show more](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/components/combobox/examples.md)
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
> tbd
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm i --save @lion/ui
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import '@lion/ui/define/lion-combobox.js';
|
|
50
|
+
import '@lion/ui/define/lion-option.js';
|
|
51
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { dedupeMixin } from '@open-wc/dedupe-mixin';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('lit-element').PropertyValues } changedProperties
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Designed for webcomponents that need to behave like a link.
|
|
9
|
+
* For instance, comboboxes that have search result options opening a webpage on click.
|
|
10
|
+
* Using an <a> is not a viable alternative, because:
|
|
11
|
+
* - no shadow dom (and thus no style encapsulation possibilities)
|
|
12
|
+
* - we need to extend from LionOption (and we cannot put the anchor inside
|
|
13
|
+
* the focusable element (LionOption which has [role=option]))
|
|
14
|
+
*/
|
|
15
|
+
const LinkMixinImplementation = superclass =>
|
|
16
|
+
class extends superclass {
|
|
17
|
+
static get properties() {
|
|
18
|
+
return {
|
|
19
|
+
href: String,
|
|
20
|
+
target: String,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this._nativeAnchor = document.createElement('a');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
super.connectedCallback();
|
|
31
|
+
if (!this.hasAttribute('role')) {
|
|
32
|
+
this.setAttribute('role', 'link');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
firstUpdated(changedProperties) {
|
|
37
|
+
super.firstUpdated(changedProperties);
|
|
38
|
+
this.addEventListener('click', this.__navigate);
|
|
39
|
+
this.addEventListener('keydown', ({ key }) => {
|
|
40
|
+
if (key === ' ' || key === 'Enter') {
|
|
41
|
+
this.__navigate();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
updated(changedProperties) {
|
|
47
|
+
super.updated(changedProperties);
|
|
48
|
+
if (changedProperties.has('href')) {
|
|
49
|
+
this._nativeAnchor.href = this.href;
|
|
50
|
+
}
|
|
51
|
+
if (changedProperties.has('target')) {
|
|
52
|
+
this._nativeAnchor.target = this.target;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
__navigate() {
|
|
57
|
+
this._nativeAnchor.click();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export const LinkMixin = dedupeMixin(LinkMixinImplementation);
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// eslint-disable-next-line max-classes-per-file
|
|
2
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Disclaimer: this is just an example component demoing the selection display of LionCombobox
|
|
6
|
+
* It needs an 'a11y plan' and tests before it could be released
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {import('./LionCombobox.js.js.js.js').LionCombobox} LionCombobox
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Renders the wrapper containing the textbox that triggers the listbox with filtered options.
|
|
15
|
+
* Optionally, shows 'chips' that indicate the selection.
|
|
16
|
+
* Should be considered an internal/protected web component to be used in conjunction with
|
|
17
|
+
* LionCombobox
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export class DemoSelectionDisplay extends LitElement {
|
|
21
|
+
static get properties() {
|
|
22
|
+
return {
|
|
23
|
+
comboboxElement: Object,
|
|
24
|
+
/**
|
|
25
|
+
* Can be used to visually indicate the next
|
|
26
|
+
*/
|
|
27
|
+
removeChipOnNextBackspace: Boolean,
|
|
28
|
+
selectedElements: Array,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static get styles() {
|
|
33
|
+
return css`
|
|
34
|
+
:host {
|
|
35
|
+
display: flex;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.combobox__selection {
|
|
39
|
+
flex: none;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.combobox__input {
|
|
43
|
+
display: block;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.selection-chip {
|
|
47
|
+
border-radius: 4px;
|
|
48
|
+
background-color: #eee;
|
|
49
|
+
padding: 4px;
|
|
50
|
+
font-size: 10px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.selection-chip--highlighted {
|
|
54
|
+
background-color: #ccc;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
* > ::slotted([slot='_textbox']) {
|
|
58
|
+
outline: none;
|
|
59
|
+
width: 100%;
|
|
60
|
+
height: 100%;
|
|
61
|
+
box-sizing: border-box;
|
|
62
|
+
border: none;
|
|
63
|
+
border-bottom: 1px solid;
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @configure FocusMixin
|
|
70
|
+
*/
|
|
71
|
+
get _inputNode() {
|
|
72
|
+
return this.comboboxElement._inputNode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_computeSelectedElements() {
|
|
76
|
+
const { formElements, checkedIndex } = /** @type {LionCombobox} */ (this.comboboxElement);
|
|
77
|
+
const checkedIndexes = Array.isArray(checkedIndex) ? checkedIndex : [checkedIndex];
|
|
78
|
+
return formElements.filter((_, i) => checkedIndexes.includes(i));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get multipleChoice() {
|
|
82
|
+
return this.comboboxElement?.multipleChoice;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
constructor() {
|
|
86
|
+
super();
|
|
87
|
+
|
|
88
|
+
this.selectedElements = [];
|
|
89
|
+
|
|
90
|
+
/** @type {EventListener} */
|
|
91
|
+
this.__textboxOnKeyup = this.__textboxOnKeyup.bind(this);
|
|
92
|
+
/** @type {EventListener} */
|
|
93
|
+
this.__restoreBackspace = this.__restoreBackspace.bind(this);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {import('lit-element').PropertyValues } changedProperties
|
|
98
|
+
*/
|
|
99
|
+
firstUpdated(changedProperties) {
|
|
100
|
+
super.firstUpdated(changedProperties);
|
|
101
|
+
|
|
102
|
+
if (this.multipleChoice) {
|
|
103
|
+
this._inputNode.addEventListener('keyup', this.__textboxOnKeyup);
|
|
104
|
+
this._inputNode.addEventListener('focusout', this.__restoreBackspace);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {import('lit-element').PropertyValues } changedProperties
|
|
110
|
+
*/
|
|
111
|
+
onComboboxElementUpdated(changedProperties) {
|
|
112
|
+
if (changedProperties.has('modelValue')) {
|
|
113
|
+
this.selectedElements = this._computeSelectedElements();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Whenever selectedElements are updated, makes sure that latest added elements
|
|
119
|
+
* are shown latest, and deleted elements respect existing order of chips.
|
|
120
|
+
*/
|
|
121
|
+
__reorderChips() {
|
|
122
|
+
const { selectedElements } = this;
|
|
123
|
+
if (this.__prevSelectedEls) {
|
|
124
|
+
const addedEls = selectedElements.filter(e => !this.__prevSelectedEls.includes(e));
|
|
125
|
+
const deletedEls = this.__prevSelectedEls.filter(e => !selectedElements.includes(e));
|
|
126
|
+
if (addedEls.length) {
|
|
127
|
+
this.selectedElements = [...this.__prevSelectedEls, ...addedEls];
|
|
128
|
+
} else if (deletedEls.length) {
|
|
129
|
+
deletedEls.forEach(delEl => {
|
|
130
|
+
this.__prevSelectedEls.splice(this.__prevSelectedEls.indexOf(delEl), 1);
|
|
131
|
+
});
|
|
132
|
+
this.selectedElements = this.__prevSelectedEls;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.__prevSelectedEls = this.selectedElements;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {import("@lion/listbox").LionOption} option
|
|
140
|
+
* @param {boolean} highlight
|
|
141
|
+
*/
|
|
142
|
+
// eslint-disable-next-line class-methods-use-this
|
|
143
|
+
_selectedElementTemplate(option, highlight) {
|
|
144
|
+
return html`
|
|
145
|
+
<span class="selection-chip ${highlight ? 'selection-chip--highlighted' : ''}">
|
|
146
|
+
${option.value}
|
|
147
|
+
</span>
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_selectedElementsTemplate() {
|
|
152
|
+
if (!this.multipleChoice) {
|
|
153
|
+
return nothing;
|
|
154
|
+
}
|
|
155
|
+
return html`
|
|
156
|
+
<div class="combobox__selection">
|
|
157
|
+
${this.selectedElements.map((option, i) => {
|
|
158
|
+
const highlight = Boolean(
|
|
159
|
+
this.removeChipOnNextBackspace && i === this.selectedElements.length - 1,
|
|
160
|
+
);
|
|
161
|
+
return this._selectedElementTemplate(option, highlight);
|
|
162
|
+
})}
|
|
163
|
+
</div>
|
|
164
|
+
`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
render() {
|
|
168
|
+
return html` ${this._selectedElementsTemplate()} `;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {{ key: string; }} ev
|
|
173
|
+
*/
|
|
174
|
+
__textboxOnKeyup(ev) {
|
|
175
|
+
if (ev.key === 'Backspace') {
|
|
176
|
+
if (!this._inputNode.value) {
|
|
177
|
+
if (this.removeChipOnNextBackspace && this.selectedElements.length) {
|
|
178
|
+
this.selectedElements[this.selectedElements.length - 1].checked = false;
|
|
179
|
+
}
|
|
180
|
+
this.removeChipOnNextBackspace = true;
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
this.removeChipOnNextBackspace = false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
__restoreBackspace() {
|
|
188
|
+
this.removeChipOnNextBackspace = false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
customElements.define('demo-selection-display', DemoSelectionDisplay);
|