@lion/ui 0.0.2 → 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/localize/src/number/parseNumber.js +15 -36
- package/components/localize/test/number/parseNumber.test.js +3 -12
- package/dist-types/components/localize/src/number/parseNumber.d.ts.map +1 -1
- 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/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Calendar >> Use Cases ||20
|
|
2
|
+
|
|
3
|
+
```js script
|
|
4
|
+
import { html, css } from '@mdjs/mdjs-preview';
|
|
5
|
+
import '@lion/ui/define/lion-calendar.js';
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
## Selected date
|
|
9
|
+
|
|
10
|
+
The `selectedDate` is the date which is currently marked as selected.
|
|
11
|
+
You usually select a date by clicking on it with the mouse or hitting Enter on the keyboard.
|
|
12
|
+
|
|
13
|
+
The `selectedDate` might not be within the dates in the current month view.
|
|
14
|
+
|
|
15
|
+
```js preview-story
|
|
16
|
+
export const selectedDate = () => html`
|
|
17
|
+
<style>
|
|
18
|
+
.demo-calendar {
|
|
19
|
+
border: 1px solid #adadad;
|
|
20
|
+
box-shadow: 0 0 16px #ccc;
|
|
21
|
+
max-width: 500px;
|
|
22
|
+
}
|
|
23
|
+
</style>
|
|
24
|
+
<lion-calendar class="demo-calendar" .selectedDate=${new Date(1988, 2, 5)}></lion-calendar>
|
|
25
|
+
`;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Central Date
|
|
29
|
+
|
|
30
|
+
The `centralDate` defines which day will be focused when keyboard moves the focus to the current month grid.
|
|
31
|
+
By default it is set to today, or the enabled day of the current month view that is closest to today's date.
|
|
32
|
+
|
|
33
|
+
The next and previous months' buttons work by changing the `centralDate` with plus or minus one month.
|
|
34
|
+
Changing the `centralDate` may mean a different view will be displayed to your users if it is in a different month.
|
|
35
|
+
Usually if you change only the day, "nothing" happens as it's already currently in view.
|
|
36
|
+
|
|
37
|
+
The `centralDate` can be different from `selectedDate` as you can have today as actively selected but still look at date that is years ago.
|
|
38
|
+
When the `selectedDate` changes, it will sync its value to the `centralDate`.
|
|
39
|
+
|
|
40
|
+
```js preview-story
|
|
41
|
+
export const centralDate = () => {
|
|
42
|
+
const today = new Date();
|
|
43
|
+
const centralDate = new Date(today.getFullYear(), today.getMonth() + 1, today.getDate());
|
|
44
|
+
return html`
|
|
45
|
+
<style>
|
|
46
|
+
.demo-calendar {
|
|
47
|
+
border: 1px solid #adadad;
|
|
48
|
+
box-shadow: 0 0 16px #ccc;
|
|
49
|
+
max-width: 500px;
|
|
50
|
+
}
|
|
51
|
+
</style>
|
|
52
|
+
<lion-calendar class="demo-calendar" .centralDate="${centralDate}"></lion-calendar>
|
|
53
|
+
`;
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Controlling focus
|
|
58
|
+
|
|
59
|
+
You can control the focus by calling the following methods
|
|
60
|
+
|
|
61
|
+
- `focusCentralDate()`
|
|
62
|
+
- `focusSelectedDate()`
|
|
63
|
+
- `focusDate(dateInstanceToFocus)`
|
|
64
|
+
|
|
65
|
+
> Be aware that the central date changes when a new date is focused.
|
|
66
|
+
|
|
67
|
+
```js preview-story
|
|
68
|
+
export const controllingFocus = () => {
|
|
69
|
+
const today = new Date();
|
|
70
|
+
const selectedDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
|
|
71
|
+
const centralDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 5);
|
|
72
|
+
return html`
|
|
73
|
+
<style>
|
|
74
|
+
.demo-calendar {
|
|
75
|
+
border: 1px solid #adadad;
|
|
76
|
+
box-shadow: 0 0 16px #ccc;
|
|
77
|
+
max-width: 500px;
|
|
78
|
+
}
|
|
79
|
+
</style>
|
|
80
|
+
<lion-calendar
|
|
81
|
+
id="js-demo-calendar"
|
|
82
|
+
class="demo-calendar"
|
|
83
|
+
.selectedDate="${selectedDate}"
|
|
84
|
+
.centralDate="${centralDate}"
|
|
85
|
+
></lion-calendar>
|
|
86
|
+
<button
|
|
87
|
+
@click="${e => e.target.parentElement.querySelector('#js-demo-calendar').focusCentralDate()}"
|
|
88
|
+
>
|
|
89
|
+
Set focus on: Central date
|
|
90
|
+
</button>
|
|
91
|
+
<button
|
|
92
|
+
@click="${e => e.target.parentElement.querySelector('#js-demo-calendar').focusSelectedDate()}"
|
|
93
|
+
>
|
|
94
|
+
Set focus on: Selected date
|
|
95
|
+
</button>
|
|
96
|
+
<button
|
|
97
|
+
@click="${e => e.target.parentElement.querySelector('#js-demo-calendar').focusDate(today)}"
|
|
98
|
+
>
|
|
99
|
+
Set focus on: Today
|
|
100
|
+
</button>
|
|
101
|
+
`;
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Limiting selectable values
|
|
106
|
+
|
|
107
|
+
### Providing a lower limit
|
|
108
|
+
|
|
109
|
+
To give a lower limit you can bind a date to the `minDate` property.
|
|
110
|
+
|
|
111
|
+
```js preview-story
|
|
112
|
+
export const providingLowerLimit = () => {
|
|
113
|
+
const minDate = new Date();
|
|
114
|
+
return html`
|
|
115
|
+
<style>
|
|
116
|
+
.demo-calendar {
|
|
117
|
+
border: 1px solid #adadad;
|
|
118
|
+
box-shadow: 0 0 16px #ccc;
|
|
119
|
+
max-width: 500px;
|
|
120
|
+
}
|
|
121
|
+
</style>
|
|
122
|
+
<lion-calendar class="demo-calendar" .minDate="${minDate}"></lion-calendar>
|
|
123
|
+
`;
|
|
124
|
+
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Provide a higher limit
|
|
128
|
+
|
|
129
|
+
To give a higher limit you can bind a date to the `maxDate` property. In this example, we show how to create an offset of + 2 days.
|
|
130
|
+
|
|
131
|
+
```js preview-story
|
|
132
|
+
export const providingHigherLimit = () => {
|
|
133
|
+
const today = new Date();
|
|
134
|
+
const maxDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2);
|
|
135
|
+
return html`
|
|
136
|
+
<style>
|
|
137
|
+
.demo-calendar {
|
|
138
|
+
border: 1px solid #adadad;
|
|
139
|
+
box-shadow: 0 0 16px #ccc;
|
|
140
|
+
max-width: 500px;
|
|
141
|
+
}
|
|
142
|
+
</style>
|
|
143
|
+
<lion-calendar class="demo-calendar" .maxDate="${maxDate}"></lion-calendar>
|
|
144
|
+
`;
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Provide a list of disabled dates
|
|
149
|
+
|
|
150
|
+
In some cases a specific date or day of the week needs to be disabled, supply those days to the `disableDates` property.
|
|
151
|
+
|
|
152
|
+
```js preview-story
|
|
153
|
+
export const disabledDates = () => html`
|
|
154
|
+
<style>
|
|
155
|
+
.demo-calendar {
|
|
156
|
+
border: 1px solid #adadad;
|
|
157
|
+
box-shadow: 0 0 16px #ccc;
|
|
158
|
+
max-width: 500px;
|
|
159
|
+
}
|
|
160
|
+
</style>
|
|
161
|
+
<lion-calendar
|
|
162
|
+
class="demo-calendar"
|
|
163
|
+
.disableDates=${day => day.getDay() === 6 || day.getDay() === 0}
|
|
164
|
+
></lion-calendar>
|
|
165
|
+
`;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Combined disable dates
|
|
169
|
+
|
|
170
|
+
To limit the scope of possible dates further, combine the methods mentioned above.
|
|
171
|
+
|
|
172
|
+
```js preview-story
|
|
173
|
+
export const combinedDisabledDates = () => {
|
|
174
|
+
const today = new Date();
|
|
175
|
+
const maxDate = new Date(today.getFullYear(), today.getMonth() + 2, today.getDate());
|
|
176
|
+
return html`
|
|
177
|
+
<style>
|
|
178
|
+
.demo-calendar {
|
|
179
|
+
border: 1px solid #adadad;
|
|
180
|
+
box-shadow: 0 0 16px #ccc;
|
|
181
|
+
max-width: 500px;
|
|
182
|
+
}
|
|
183
|
+
</style>
|
|
184
|
+
<lion-calendar
|
|
185
|
+
class="demo-calendar"
|
|
186
|
+
.disableDates=${day => day.getDay() === 6 || day.getDay() === 0}
|
|
187
|
+
.minDate="${new Date()}"
|
|
188
|
+
.maxDate="${maxDate}"
|
|
189
|
+
></lion-calendar>
|
|
190
|
+
`;
|
|
191
|
+
};
|
|
192
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Checkbox Group >> Overview ||10
|
|
2
|
+
|
|
3
|
+
A checkbox group enhances the functionality of the native `<input type="checkbox">` element.
|
|
4
|
+
Its purpose is to provide a way for users to check **multiple** options amongst a set of choices, or to function as a single toggle.
|
|
5
|
+
|
|
6
|
+
> You should use our `checkbox` elements as children in checkbox group.
|
|
7
|
+
|
|
8
|
+
```js script
|
|
9
|
+
import { html } from '@mdjs/mdjs-preview';
|
|
10
|
+
import '@lion/ui/define/lion-checkbox-group.js';
|
|
11
|
+
import '@lion/ui/define/lion-checkbox.js';
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```js preview-story
|
|
15
|
+
export const main = () => html`
|
|
16
|
+
<lion-checkbox-group name="scientists[]" label="Favorite scientists">
|
|
17
|
+
<lion-checkbox label="Archimedes" .choiceValue=${'Archimedes'}></lion-checkbox>
|
|
18
|
+
<lion-checkbox label="Francis Bacon" .choiceValue=${'Francis Bacon'}></lion-checkbox>
|
|
19
|
+
<lion-checkbox label="Marie Curie" .choiceValue=${'Marie Curie'}></lion-checkbox>
|
|
20
|
+
</lion-checkbox-group>
|
|
21
|
+
`;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> Make sure that the checkbox-group also has a name attribute, this is necessary for our [form](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/components/form/overview.md)'s serialization result.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
Since it extends from our [fieldset](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/components/fieldset/overview.md),
|
|
29
|
+
it has all the features a fieldset has.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm i --save @lion/ui
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import '@lion/ui/define/lion-checkbox-group.js';
|
|
39
|
+
import '@lion/ui/define/lion-checkbox.js';
|
|
40
|
+
```
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Checkbox Group >> Use Cases ||20
|
|
2
|
+
|
|
3
|
+
```js script
|
|
4
|
+
import { html } from '@mdjs/mdjs-preview';
|
|
5
|
+
import '@lion/ui/define/lion-checkbox-group.js';
|
|
6
|
+
import '@lion/ui/define/lion-checkbox.js';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Model value
|
|
10
|
+
|
|
11
|
+
The `modelValue` of a `lion-checkbox-group` is an array containing the `choiceValues` of the `lion-checkbox` elements that have been checked.
|
|
12
|
+
|
|
13
|
+
Given the scientists example above, say that we were to select the first and last options
|
|
14
|
+
(Archimedes & Marie Curie).
|
|
15
|
+
|
|
16
|
+
Then the `modelValue` of the `lion-checkbox-group` will look as follows:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
const groupElement = [parent].querySelector('lion-checkbox-group');
|
|
20
|
+
groupElement.modelValue;
|
|
21
|
+
=> ["Archimedes", "Marie Curie"];
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## The `name` attribute
|
|
25
|
+
|
|
26
|
+
The `name` attribute of a `lion-checkbox-group` automatically gets assigned to its `lion-checkbox` children. You can also specify names for the `lion-checkbox` elements, but if this name is different from the name assigned to `lion-checkbox-group`, then an exception will be thrown.
|
|
27
|
+
|
|
28
|
+
Our recommendation would be to set the `name` attribute only on the `lion-checkbox-group` and not on the `lion-checkbox` elements.
|
|
29
|
+
|
|
30
|
+
## Example
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<lion-checkbox-group
|
|
34
|
+
name="scientists[]"
|
|
35
|
+
label="Favorite scientists"
|
|
36
|
+
>
|
|
37
|
+
<lion-checkbox label="Archimedes" .choiceValue=${'Archimedes'}></lion-checkbox>
|
|
38
|
+
<lion-checkbox label="Francis Bacon" .choiceValue=${'Francis Bacon'}></lion-checkbox>
|
|
39
|
+
<lion-checkbox label="Marie Curie" .choiceValue=${'Marie Curie'}></lion-checkbox>
|
|
40
|
+
</lion-checkbox-group>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Pre-select
|
|
44
|
+
|
|
45
|
+
You can pre-select options by targeting the `modelValue` object of the option and setting the `checked` property to `true`.
|
|
46
|
+
|
|
47
|
+
```js preview-story
|
|
48
|
+
export const preselect = () => html`
|
|
49
|
+
<lion-checkbox-group name="scientists" label="Favorite scientists">
|
|
50
|
+
<lion-checkbox label="Archimedes" .choiceValue=${'Archimedes'}></lion-checkbox>
|
|
51
|
+
<lion-checkbox label="Francis Bacon" .choiceValue=${'Francis Bacon'} checked></lion-checkbox>
|
|
52
|
+
<lion-checkbox
|
|
53
|
+
label="Marie Curie"
|
|
54
|
+
.modelValue=${{ value: 'Marie Curie', checked: true }}
|
|
55
|
+
></lion-checkbox>
|
|
56
|
+
</lion-checkbox-group>
|
|
57
|
+
`;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Disabled
|
|
61
|
+
|
|
62
|
+
You can disable the entire group by setting the `disabled` attribute on the `<lion-checkbox-group>`.
|
|
63
|
+
|
|
64
|
+
```js preview-story
|
|
65
|
+
export const disabled = () => html`
|
|
66
|
+
<lion-checkbox-group name="scientists[]" label="Favorite scientists" disabled>
|
|
67
|
+
<lion-checkbox label="Archimedes" .choiceValue=${'Archimedes'}></lion-checkbox>
|
|
68
|
+
<lion-checkbox label="Francis Bacon" .choiceValue=${'Francis Bacon'}></lion-checkbox>
|
|
69
|
+
<lion-checkbox
|
|
70
|
+
label="Marie Curie"
|
|
71
|
+
.modelValue=${{ value: 'Marie Curie', checked: true }}
|
|
72
|
+
></lion-checkbox>
|
|
73
|
+
</lion-checkbox-group>
|
|
74
|
+
`;
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Label
|
|
78
|
+
|
|
79
|
+
You can use `slot="label"` instead of the `label` attribute for defining more complex labels, such as containing screen reader only text or an anchor.
|
|
80
|
+
|
|
81
|
+
```js preview-story
|
|
82
|
+
export const label = () => html`
|
|
83
|
+
<lion-checkbox-group name="scientists[]" label="Favorite scientists">
|
|
84
|
+
<lion-checkbox .choiceValue=${'Archimedes'}>
|
|
85
|
+
<label slot="label"
|
|
86
|
+
><a href="https://wikipedia.org/wiki/Archimedes" target="_blank">Archimedes</a></label
|
|
87
|
+
>
|
|
88
|
+
</lion-checkbox>
|
|
89
|
+
<lion-checkbox .choiceValue=${'Francis Bacon'}>
|
|
90
|
+
<label slot="label"
|
|
91
|
+
><a href="https://wikipedia.org/wiki/Francis_Bacon" target="_blank">Francis Bacon</a></label
|
|
92
|
+
>
|
|
93
|
+
</lion-checkbox>
|
|
94
|
+
<lion-checkbox .choiceValue=${'Marie Curie'}>
|
|
95
|
+
<label slot="label"
|
|
96
|
+
><a href="https://wikipedia.org/wiki/Marie_Curie" target="_blank">Marie Curie</a></label
|
|
97
|
+
>
|
|
98
|
+
</lion-checkbox>
|
|
99
|
+
</lion-checkbox-group>
|
|
100
|
+
`;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Help text
|
|
104
|
+
|
|
105
|
+
You can add help text on each checkbox with `help-text` attribute on the `<lion-checkbox>`.
|
|
106
|
+
|
|
107
|
+
```js preview-story
|
|
108
|
+
export const helpText = () => html`
|
|
109
|
+
<lion-checkbox-group name="scientists[]" label="Favorite scientists">
|
|
110
|
+
<lion-checkbox
|
|
111
|
+
label="Archimedes"
|
|
112
|
+
.choiceValue=${'Archimedes'}
|
|
113
|
+
help-text="Archimedes of Syracuse was a Greek mathematician, physicist, engineer, inventor, and astronomer"
|
|
114
|
+
></lion-checkbox>
|
|
115
|
+
<lion-checkbox
|
|
116
|
+
label="Francis Bacon"
|
|
117
|
+
.choiceValue=${'Francis Bacon'}
|
|
118
|
+
help-text="Francis Bacon, 1st Viscount St Alban also known as Lord Verulam, was an English philosopher and statesman who served as Attorney General and as Lord Chancellor of England"
|
|
119
|
+
></lion-checkbox>
|
|
120
|
+
<lion-checkbox
|
|
121
|
+
label="Marie Curie"
|
|
122
|
+
.choiceValue=${'Marie Curie'}
|
|
123
|
+
help-text="Marie Skłodowska Curie born Maria Salomea Skłodowska, was a Polish and naturalized-French physicist and chemist who conducted pioneering research on radioactivity"
|
|
124
|
+
></lion-checkbox>
|
|
125
|
+
</lion-checkbox-group>
|
|
126
|
+
`;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Event
|
|
130
|
+
|
|
131
|
+
You can listen to the `model-value-changed` event whenever the value of the checkbox group is changed.
|
|
132
|
+
|
|
133
|
+
```js preview-story
|
|
134
|
+
export const event = ({ shadowRoot }) => html`
|
|
135
|
+
<lion-checkbox-group
|
|
136
|
+
name="scientists[]"
|
|
137
|
+
label="Favorite scientists"
|
|
138
|
+
@model-value-changed=${ev =>
|
|
139
|
+
(ev.target.parentElement.querySelector('#selectedDinosaur').innerText = JSON.stringify(
|
|
140
|
+
ev.target.modelValue,
|
|
141
|
+
null,
|
|
142
|
+
4,
|
|
143
|
+
))}
|
|
144
|
+
>
|
|
145
|
+
<lion-checkbox label="Archimedes" .choiceValue=${'Archimedes'}></lion-checkbox>
|
|
146
|
+
<lion-checkbox label="Francis Bacon" .choiceValue=${'Francis Bacon'}></lion-checkbox>
|
|
147
|
+
<lion-checkbox label="Marie Curie" .choiceValue=${'Marie Curie'}></lion-checkbox>
|
|
148
|
+
</lion-checkbox-group>
|
|
149
|
+
<br />
|
|
150
|
+
<span>Selected scientists: <strong id="selectedDinosaur">N/A</strong></span>
|
|
151
|
+
`;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Indeterminate
|
|
155
|
+
|
|
156
|
+
A `checkbox-indeterminate`'s value is neither true nor false, but is instead indeterminate, meaning that its state cannot be determined or stated in pure binary terms, based on it's `checkbox` children.
|
|
157
|
+
|
|
158
|
+
```js preview-story
|
|
159
|
+
export const indeterminateSiblings = () => html`
|
|
160
|
+
<lion-checkbox-group name="scientists[]" label="Favorite scientists">
|
|
161
|
+
<lion-checkbox-indeterminate label="Old Greek scientists">
|
|
162
|
+
<lion-checkbox
|
|
163
|
+
slot="checkbox"
|
|
164
|
+
label="Archimedes"
|
|
165
|
+
.choiceValue=${'Archimedes'}
|
|
166
|
+
></lion-checkbox>
|
|
167
|
+
<lion-checkbox slot="checkbox" label="Plato" .choiceValue=${'Plato'}></lion-checkbox>
|
|
168
|
+
<lion-checkbox
|
|
169
|
+
slot="checkbox"
|
|
170
|
+
label="Pythagoras"
|
|
171
|
+
.choiceValue=${'Pythagoras'}
|
|
172
|
+
></lion-checkbox>
|
|
173
|
+
</lion-checkbox-indeterminate>
|
|
174
|
+
<lion-checkbox-indeterminate label="17th Century scientists">
|
|
175
|
+
<lion-checkbox
|
|
176
|
+
slot="checkbox"
|
|
177
|
+
label="Isaac Newton"
|
|
178
|
+
.choiceValue=${'Isaac Newton'}
|
|
179
|
+
></lion-checkbox>
|
|
180
|
+
<lion-checkbox
|
|
181
|
+
slot="checkbox"
|
|
182
|
+
label="Galileo Galilei"
|
|
183
|
+
.choiceValue=${'Galileo Galilei'}
|
|
184
|
+
></lion-checkbox>
|
|
185
|
+
</lion-checkbox-indeterminate>
|
|
186
|
+
</lion-checkbox-group>
|
|
187
|
+
`;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The `checkbox-indeterminate` can have another `checkbox-indeterminate` as a child.
|
|
191
|
+
|
|
192
|
+
```js preview-story
|
|
193
|
+
export const indeterminateChildren = () => html`
|
|
194
|
+
<lion-checkbox-group name="scientists[]" label="Favorite scientists">
|
|
195
|
+
<lion-checkbox-indeterminate label="Scientists">
|
|
196
|
+
<lion-checkbox
|
|
197
|
+
slot="checkbox"
|
|
198
|
+
label="Isaac Newton"
|
|
199
|
+
.choiceValue=${'Isaac Newton'}
|
|
200
|
+
></lion-checkbox>
|
|
201
|
+
<lion-checkbox
|
|
202
|
+
slot="checkbox"
|
|
203
|
+
label="Galileo Galilei"
|
|
204
|
+
.choiceValue=${'Galileo Galilei'}
|
|
205
|
+
></lion-checkbox>
|
|
206
|
+
<lion-checkbox-indeterminate slot="checkbox" label="Old Greek scientists">
|
|
207
|
+
<lion-checkbox
|
|
208
|
+
slot="checkbox"
|
|
209
|
+
label="Archimedes"
|
|
210
|
+
.choiceValue=${'Archimedes'}
|
|
211
|
+
></lion-checkbox>
|
|
212
|
+
<lion-checkbox slot="checkbox" label="Plato" .choiceValue=${'Plato'}></lion-checkbox>
|
|
213
|
+
<lion-checkbox
|
|
214
|
+
slot="checkbox"
|
|
215
|
+
label="Pythagoras"
|
|
216
|
+
.choiceValue=${'Pythagoras'}
|
|
217
|
+
></lion-checkbox>
|
|
218
|
+
</lion-checkbox-indeterminate>
|
|
219
|
+
</lion-checkbox-indeterminate>
|
|
220
|
+
</lion-checkbox-group>
|
|
221
|
+
`;
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
You can also use `mixed-state` attribute so your indeterminate checkbox toggles through three states (indeterminate, checked, unchecked), where for indeterminate state the old children states are restored when you toggle back into this.
|
|
225
|
+
|
|
226
|
+
```js preview-story
|
|
227
|
+
export const mixedState = () => html`
|
|
228
|
+
<lion-checkbox-group name="scientists[]" label="Favorite scientists">
|
|
229
|
+
<lion-checkbox-indeterminate mixed-state label="Scientists">
|
|
230
|
+
<lion-checkbox
|
|
231
|
+
slot="checkbox"
|
|
232
|
+
label="Isaac Newton"
|
|
233
|
+
.choiceValue=${'Isaac Newton'}
|
|
234
|
+
></lion-checkbox>
|
|
235
|
+
<lion-checkbox
|
|
236
|
+
slot="checkbox"
|
|
237
|
+
label="Galileo Galilei"
|
|
238
|
+
.choiceValue=${'Galileo Galilei'}
|
|
239
|
+
></lion-checkbox>
|
|
240
|
+
<lion-checkbox-indeterminate mixed-state slot="checkbox" label="Old Greek scientists">
|
|
241
|
+
<lion-checkbox
|
|
242
|
+
slot="checkbox"
|
|
243
|
+
label="Archimedes"
|
|
244
|
+
.choiceValue=${'Archimedes'}
|
|
245
|
+
></lion-checkbox>
|
|
246
|
+
<lion-checkbox slot="checkbox" label="Plato" .choiceValue=${'Plato'}></lion-checkbox>
|
|
247
|
+
<lion-checkbox
|
|
248
|
+
slot="checkbox"
|
|
249
|
+
label="Pythagoras"
|
|
250
|
+
.choiceValue=${'Pythagoras'}
|
|
251
|
+
></lion-checkbox>
|
|
252
|
+
</lion-checkbox-indeterminate>
|
|
253
|
+
</lion-checkbox-indeterminate>
|
|
254
|
+
</lion-checkbox-group>
|
|
255
|
+
`;
|
|
256
|
+
```
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { LionCollapsible } from '@lion/ui/collapsible.js';
|
|
2
|
+
|
|
3
|
+
const EVENT = {
|
|
4
|
+
TRANSITION_END: 'transitionend',
|
|
5
|
+
TRANSITION_START: 'transitionstart',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* `CustomCollapsible` is a class for custom collapsible element (`<custom-collapsible>` web component).
|
|
9
|
+
* @customElement custom-collapsible
|
|
10
|
+
*/
|
|
11
|
+
// @ts-expect-error false positive for incompatible static get properties. Lit-element merges super properties already for you.
|
|
12
|
+
export class CustomCollapsible extends LionCollapsible {
|
|
13
|
+
static get properties() {
|
|
14
|
+
return {
|
|
15
|
+
transitioning: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
reflect: true,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.transitioning = false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
connectedCallback() {
|
|
28
|
+
super.connectedCallback();
|
|
29
|
+
this._contentNode?.style.setProperty(
|
|
30
|
+
'transition',
|
|
31
|
+
'max-height 0.35s, padding 0.35s, opacity 0.35s',
|
|
32
|
+
);
|
|
33
|
+
if (this.opened) {
|
|
34
|
+
this._contentNode?.style.setProperty('padding', '12px 0');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Wait until transition is finished.
|
|
40
|
+
* @override
|
|
41
|
+
*/
|
|
42
|
+
toggle() {
|
|
43
|
+
if (!this.transitioning) {
|
|
44
|
+
super.toggle();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Trigger show animation and wait for transition to be finished.
|
|
50
|
+
* @param {Object} options - element node and its options
|
|
51
|
+
* @param {HTMLElement} options.contentNode
|
|
52
|
+
* @override
|
|
53
|
+
*/
|
|
54
|
+
async _showAnimation({ contentNode }) {
|
|
55
|
+
const expectedHeight = await this.__calculateHeight(contentNode);
|
|
56
|
+
contentNode.style.setProperty('opacity', '1');
|
|
57
|
+
contentNode.style.setProperty('padding', '12px 0');
|
|
58
|
+
contentNode.style.setProperty('max-height', '0px');
|
|
59
|
+
await new Promise(resolve => requestAnimationFrame(() => resolve()));
|
|
60
|
+
contentNode.style.setProperty('max-height', expectedHeight);
|
|
61
|
+
await this._waitForTransition({ contentNode });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Trigger hide animation and wait for transition to be finished.
|
|
66
|
+
* @param {Object} options - element node and its options
|
|
67
|
+
* @param {HTMLElement} options.contentNode
|
|
68
|
+
* @override
|
|
69
|
+
*/
|
|
70
|
+
async _hideAnimation({ contentNode }) {
|
|
71
|
+
if (this._contentHeight === '0px') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
['opacity', 'padding', 'max-height'].map(prop => contentNode.style.setProperty(prop, '0'));
|
|
75
|
+
await this._waitForTransition({ contentNode });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Wait until the transition event is finished.
|
|
80
|
+
* @param {Object} options - element node and its options
|
|
81
|
+
* @param {HTMLElement} options.contentNode
|
|
82
|
+
* @returns {Promise<void>} transition event
|
|
83
|
+
*/
|
|
84
|
+
_waitForTransition({ contentNode }) {
|
|
85
|
+
return new Promise(resolve => {
|
|
86
|
+
const transitionStarted = () => {
|
|
87
|
+
contentNode.removeEventListener(EVENT.TRANSITION_START, transitionStarted);
|
|
88
|
+
this.transitioning = true;
|
|
89
|
+
};
|
|
90
|
+
contentNode.addEventListener(EVENT.TRANSITION_START, transitionStarted);
|
|
91
|
+
|
|
92
|
+
const transitionEnded = () => {
|
|
93
|
+
contentNode.removeEventListener(EVENT.TRANSITION_END, transitionEnded);
|
|
94
|
+
this.transitioning = false;
|
|
95
|
+
resolve();
|
|
96
|
+
};
|
|
97
|
+
contentNode.addEventListener(EVENT.TRANSITION_END, transitionEnded);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Calculate total content height after collapsible opens
|
|
103
|
+
* @param {HTMLElement} contentNode content node
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
async __calculateHeight(contentNode) {
|
|
107
|
+
contentNode.style.setProperty('max-height', '');
|
|
108
|
+
await new Promise(resolve => requestAnimationFrame(() => resolve()));
|
|
109
|
+
return this._contentHeight; // Expected height i.e. actual size once collapsed after animation
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
customElements.define('custom-collapsible', CustomCollapsible);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
|
|
3
|
+
const applyDemoCollapsibleStyles = () => {
|
|
4
|
+
const demoCollapsibleStyles = css`
|
|
5
|
+
.demo-custom-collapsible-container {
|
|
6
|
+
padding: 16px;
|
|
7
|
+
margin: 16px;
|
|
8
|
+
border-radius: 4px;
|
|
9
|
+
width: 400px;
|
|
10
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.demo-custom-collapsible-body {
|
|
14
|
+
padding: 12px 0px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.demo-custom-collapsible-invoker {
|
|
18
|
+
border-width: 0;
|
|
19
|
+
border-radius: 2px;
|
|
20
|
+
padding: 12px 24px;
|
|
21
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
|
|
22
|
+
font-weight: bold;
|
|
23
|
+
color: #3f51b5;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.demo-custom-collapsible-state-container {
|
|
27
|
+
padding: 12px 0;
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const styleTag = document.createElement('style');
|
|
32
|
+
styleTag.setAttribute('data-demo-collapsible', '');
|
|
33
|
+
styleTag.textContent = demoCollapsibleStyles.cssText;
|
|
34
|
+
document.head.appendChild(styleTag);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
applyDemoCollapsibleStyles();
|