@webtides/element-library 0.1.0
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 +109 -0
- package/LICENSE +21 -0
- package/README.md +125 -0
- package/all.js +26 -0
- package/custom-elements.json +7683 -0
- package/index.js +3 -0
- package/package.json +132 -0
- package/patches/@glidejs+glide+3.6.2.patch +11 -0
- package/src/components/accordion/accordion.changelog.md +47 -0
- package/src/components/accordion/accordion.define.js +3 -0
- package/src/components/accordion/accordion.events.js +3 -0
- package/src/components/accordion/accordion.js +144 -0
- package/src/components/accordion/accordion.readme.md +71 -0
- package/src/components/accordion/accordion.style.js +64 -0
- package/src/components/accordion-group/accordion-group.changelog.md +35 -0
- package/src/components/accordion-group/accordion-group.define.js +3 -0
- package/src/components/accordion-group/accordion-group.js +63 -0
- package/src/components/accordion-group/accordion-group.readme.md +56 -0
- package/src/components/amount-field/amount-field.changelog.md +40 -0
- package/src/components/amount-field/amount-field.define.js +3 -0
- package/src/components/amount-field/amount-field.js +91 -0
- package/src/components/amount-field/amount-field.readme.md +65 -0
- package/src/components/amount-field/amount-field.style.js +58 -0
- package/src/components/button/button.changelog.md +19 -0
- package/src/components/button/button.define.js +3 -0
- package/src/components/button/button.js +174 -0
- package/src/components/button/button.readme.md +91 -0
- package/src/components/button/button.style.js +251 -0
- package/src/components/carousel/carousel.changelog.md +58 -0
- package/src/components/carousel/carousel.define.js +3 -0
- package/src/components/carousel/carousel.events.js +3 -0
- package/src/components/carousel/carousel.js +232 -0
- package/src/components/carousel/carousel.readme.md +78 -0
- package/src/components/carousel/carousel.style.js +142 -0
- package/src/components/carousel/glide/components/ShadowAnchors.js +12 -0
- package/src/components/carousel/glide/components/ShadowClones.js +41 -0
- package/src/components/carousel/glide/components/ShadowGaps.js +28 -0
- package/src/components/carousel/glide/components/ShadowHtml.js +32 -0
- package/src/components/checkbox-field/checkbox-field.changelog.md +47 -0
- package/src/components/checkbox-field/checkbox-field.define.js +3 -0
- package/src/components/checkbox-field/checkbox-field.js +102 -0
- package/src/components/checkbox-field/checkbox-field.readme.md +66 -0
- package/src/components/checkbox-field/checkbox-field.style.js +69 -0
- package/src/components/dialog/dialog.changelog.md +24 -0
- package/src/components/dialog/dialog.define.js +3 -0
- package/src/components/dialog/dialog.events.js +8 -0
- package/src/components/dialog/dialog.js +271 -0
- package/src/components/dialog/dialog.readme.md +122 -0
- package/src/components/dialog/dialog.style.js +124 -0
- package/src/components/dropdown/dropdown.changelog.md +39 -0
- package/src/components/dropdown/dropdown.define.js +3 -0
- package/src/components/dropdown/dropdown.js +98 -0
- package/src/components/dropdown/dropdown.readme.md +69 -0
- package/src/components/dropdown/dropdown.style.js +17 -0
- package/src/components/form-field/form-field.changelog.md +35 -0
- package/src/components/form-field/form-field.define.js +3 -0
- package/src/components/form-field/form-field.events.js +4 -0
- package/src/components/form-field/form-field.js +210 -0
- package/src/components/form-field/form-field.readme.md +80 -0
- package/src/components/form-field/form-field.style.js +25 -0
- package/src/components/input-field/input-field.changelog.md +39 -0
- package/src/components/input-field/input-field.define.js +3 -0
- package/src/components/input-field/input-field.js +71 -0
- package/src/components/input-field/input-field.readme.md +90 -0
- package/src/components/input-field/input-field.style.js +33 -0
- package/src/components/lazy-src/lazy-src.changelog.md +57 -0
- package/src/components/lazy-src/lazy-src.define.js +3 -0
- package/src/components/lazy-src/lazy-src.events.js +5 -0
- package/src/components/lazy-src/lazy-src.js +100 -0
- package/src/components/lazy-src/lazy-src.readme.md +63 -0
- package/src/components/notification/notification.changelog.md +22 -0
- package/src/components/notification/notification.define.js +3 -0
- package/src/components/notification/notification.events.js +6 -0
- package/src/components/notification/notification.js +280 -0
- package/src/components/notification/notification.readme.md +98 -0
- package/src/components/notification/notification.style.js +113 -0
- package/src/components/password-field/password-field.changelog.md +22 -0
- package/src/components/password-field/password-field.define.js +3 -0
- package/src/components/password-field/password-field.js +113 -0
- package/src/components/password-field/password-field.readme.md +60 -0
- package/src/components/password-field/password-field.style.js +62 -0
- package/src/components/radio-field/radio-field.changelog.md +21 -0
- package/src/components/radio-field/radio-field.define.js +3 -0
- package/src/components/radio-field/radio-field.js +140 -0
- package/src/components/radio-field/radio-field.readme.md +72 -0
- package/src/components/radio-field/radio-field.style.js +108 -0
- package/src/components/scroll-to/scroll-to.changelog.md +39 -0
- package/src/components/scroll-to/scroll-to.define.js +3 -0
- package/src/components/scroll-to/scroll-to.js +40 -0
- package/src/components/scroll-to/scroll-to.readme.md +50 -0
- package/src/components/scroll-to-top/scroll-to-top.changelog.md +39 -0
- package/src/components/scroll-to-top/scroll-to-top.define.js +3 -0
- package/src/components/scroll-to-top/scroll-to-top.js +78 -0
- package/src/components/scroll-to-top/scroll-to-top.readme.md +48 -0
- package/src/components/scroll-to-top/scroll-to-top.style.js +9 -0
- package/src/components/select-field/select-field.changelog.md +30 -0
- package/src/components/select-field/select-field.define.js +3 -0
- package/src/components/select-field/select-field.js +83 -0
- package/src/components/select-field/select-field.readme.md +131 -0
- package/src/components/select-field/select-field.style.js +24 -0
- package/src/components/slider/slider.changelog.md +177 -0
- package/src/components/slider/slider.define.js +3 -0
- package/src/components/slider/slider.events.js +4 -0
- package/src/components/slider/slider.js +338 -0
- package/src/components/slider/slider.readme.md +87 -0
- package/src/components/slider/slider.style.js +107 -0
- package/src/components/sticky/sticky.changelog.md +43 -0
- package/src/components/sticky/sticky.define.js +3 -0
- package/src/components/sticky/sticky.js +105 -0
- package/src/components/sticky/sticky.readme.md +63 -0
- package/src/components/sticky/sticky.style.js +21 -0
- package/src/components/svg-use/svg-use.changelog.md +41 -0
- package/src/components/svg-use/svg-use.define.js +3 -0
- package/src/components/svg-use/svg-use.js +39 -0
- package/src/components/svg-use/svg-use.readme.md +50 -0
- package/src/components/svg-use/svg-use.style.js +20 -0
- package/src/components/switch-field/switch-field.changelog.md +21 -0
- package/src/components/switch-field/switch-field.define.js +3 -0
- package/src/components/switch-field/switch-field.js +99 -0
- package/src/components/switch-field/switch-field.readme.md +58 -0
- package/src/components/switch-field/switch-field.style.js +98 -0
- package/src/components/tab-group/tab-group.changelog.md +35 -0
- package/src/components/tab-group/tab-group.define.js +3 -0
- package/src/components/tab-group/tab-group.js +109 -0
- package/src/components/tab-group/tab-group.readme.md +61 -0
- package/src/components/tab-group/tab-group.style.js +7 -0
- package/src/components/tab-link/tab-link.changelog.md +35 -0
- package/src/components/tab-link/tab-link.define.js +3 -0
- package/src/components/tab-link/tab-link.js +50 -0
- package/src/components/tab-link/tab-link.readme.md +66 -0
- package/src/components/tab-link/tab-link.style.js +32 -0
- package/src/components/tab-panel/tab-panel.changelog.md +39 -0
- package/src/components/tab-panel/tab-panel.define.js +3 -0
- package/src/components/tab-panel/tab-panel.js +30 -0
- package/src/components/tab-panel/tab-panel.readme.md +57 -0
- package/src/components/tab-panel/tab-panel.style.js +7 -0
- package/src/components/textarea-field/textarea-field.changelog.md +39 -0
- package/src/components/textarea-field/textarea-field.define.js +3 -0
- package/src/components/textarea-field/textarea-field.js +62 -0
- package/src/components/textarea-field/textarea-field.readme.md +102 -0
- package/src/components/textarea-field/textarea-field.style.js +7 -0
- package/src/components/transition-classes/transition-classes.changelog.md +39 -0
- package/src/components/transition-classes/transition-classes.define.js +3 -0
- package/src/components/transition-classes/transition-classes.js +154 -0
- package/src/components/transition-classes/transition-classes.readme.md +71 -0
- package/src/themes/default.css +165 -0
- package/src/themes/high-contrast.css +147 -0
- package/src/themes/sketchy.css +238 -0
- package/types/all.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/src/components/accordion/accordion.d.ts +60 -0
- package/types/src/components/accordion/accordion.define.d.ts +1 -0
- package/types/src/components/accordion/accordion.events.d.ts +4 -0
- package/types/src/components/accordion/accordion.style.d.ts +2 -0
- package/types/src/components/accordion-group/accordion-group.d.ts +28 -0
- package/types/src/components/accordion-group/accordion-group.define.d.ts +1 -0
- package/types/src/components/amount-field/amount-field.d.ts +53 -0
- package/types/src/components/amount-field/amount-field.define.d.ts +1 -0
- package/types/src/components/amount-field/amount-field.style.d.ts +2 -0
- package/types/src/components/button/button.d.ts +73 -0
- package/types/src/components/button/button.define.d.ts +1 -0
- package/types/src/components/button/button.style.d.ts +2 -0
- package/types/src/components/carousel/carousel.d.ts +79 -0
- package/types/src/components/carousel/carousel.define.d.ts +1 -0
- package/types/src/components/carousel/carousel.events.d.ts +4 -0
- package/types/src/components/carousel/carousel.style.d.ts +2 -0
- package/types/src/components/carousel/glide/components/ShadowAnchors.d.ts +1 -0
- package/types/src/components/carousel/glide/components/ShadowClones.d.ts +1 -0
- package/types/src/components/carousel/glide/components/ShadowGaps.d.ts +1 -0
- package/types/src/components/carousel/glide/components/ShadowHtml.d.ts +1 -0
- package/types/src/components/checkbox-field/checkbox-field.d.ts +69 -0
- package/types/src/components/checkbox-field/checkbox-field.define.d.ts +1 -0
- package/types/src/components/checkbox-field/checkbox-field.style.d.ts +2 -0
- package/types/src/components/dialog/dialog.d.ts +103 -0
- package/types/src/components/dialog/dialog.define.d.ts +1 -0
- package/types/src/components/dialog/dialog.events.d.ts +9 -0
- package/types/src/components/dialog/dialog.style.d.ts +2 -0
- package/types/src/components/dropdown/dropdown.d.ts +45 -0
- package/types/src/components/dropdown/dropdown.define.d.ts +1 -0
- package/types/src/components/dropdown/dropdown.style.d.ts +2 -0
- package/types/src/components/form-field/form-field.d.ts +110 -0
- package/types/src/components/form-field/form-field.define.d.ts +1 -0
- package/types/src/components/form-field/form-field.events.d.ts +5 -0
- package/types/src/components/form-field/form-field.style.d.ts +2 -0
- package/types/src/components/input-field/input-field.d.ts +38 -0
- package/types/src/components/input-field/input-field.define.d.ts +1 -0
- package/types/src/components/input-field/input-field.style.d.ts +2 -0
- package/types/src/components/lazy-src/lazy-src.d.ts +46 -0
- package/types/src/components/lazy-src/lazy-src.define.d.ts +1 -0
- package/types/src/components/lazy-src/lazy-src.events.d.ts +6 -0
- package/types/src/components/notification/notification.d.ts +92 -0
- package/types/src/components/notification/notification.define.d.ts +1 -0
- package/types/src/components/notification/notification.events.d.ts +7 -0
- package/types/src/components/notification/notification.style.d.ts +2 -0
- package/types/src/components/password-field/password-field.d.ts +66 -0
- package/types/src/components/password-field/password-field.define.d.ts +1 -0
- package/types/src/components/password-field/password-field.style.d.ts +2 -0
- package/types/src/components/radio-field/radio-field.d.ts +62 -0
- package/types/src/components/radio-field/radio-field.define.d.ts +1 -0
- package/types/src/components/radio-field/radio-field.style.d.ts +2 -0
- package/types/src/components/scroll-to/scroll-to.d.ts +24 -0
- package/types/src/components/scroll-to/scroll-to.define.d.ts +1 -0
- package/types/src/components/scroll-to-top/scroll-to-top.d.ts +32 -0
- package/types/src/components/scroll-to-top/scroll-to-top.define.d.ts +1 -0
- package/types/src/components/scroll-to-top/scroll-to-top.style.d.ts +2 -0
- package/types/src/components/select-field/select-field.d.ts +39 -0
- package/types/src/components/select-field/select-field.define.d.ts +1 -0
- package/types/src/components/select-field/select-field.style.d.ts +2 -0
- package/types/src/components/slider/slider.d.ts +129 -0
- package/types/src/components/slider/slider.define.d.ts +1 -0
- package/types/src/components/slider/slider.events.d.ts +5 -0
- package/types/src/components/slider/slider.style.d.ts +2 -0
- package/types/src/components/sticky/sticky.d.ts +47 -0
- package/types/src/components/sticky/sticky.define.d.ts +1 -0
- package/types/src/components/sticky/sticky.style.d.ts +2 -0
- package/types/src/components/svg-use/svg-use.d.ts +18 -0
- package/types/src/components/svg-use/svg-use.define.d.ts +1 -0
- package/types/src/components/svg-use/svg-use.style.d.ts +2 -0
- package/types/src/components/switch-field/switch-field.d.ts +67 -0
- package/types/src/components/switch-field/switch-field.define.d.ts +1 -0
- package/types/src/components/switch-field/switch-field.style.d.ts +2 -0
- package/types/src/components/tab-group/tab-group.d.ts +48 -0
- package/types/src/components/tab-group/tab-group.define.d.ts +1 -0
- package/types/src/components/tab-group/tab-group.style.d.ts +2 -0
- package/types/src/components/tab-link/tab-link.d.ts +30 -0
- package/types/src/components/tab-link/tab-link.define.d.ts +1 -0
- package/types/src/components/tab-link/tab-link.style.d.ts +2 -0
- package/types/src/components/tab-panel/tab-panel.d.ts +18 -0
- package/types/src/components/tab-panel/tab-panel.define.d.ts +1 -0
- package/types/src/components/tab-panel/tab-panel.style.d.ts +2 -0
- package/types/src/components/textarea-field/textarea-field.d.ts +34 -0
- package/types/src/components/textarea-field/textarea-field.define.d.ts +1 -0
- package/types/src/components/textarea-field/textarea-field.style.d.ts +2 -0
- package/types/src/components/transition-classes/transition-classes.d.ts +52 -0
- package/types/src/components/transition-classes/transition-classes.define.d.ts +1 -0
- package/types/src/utils/body-scroll.d.ts +4 -0
- package/types/src/utils/transitions.d.ts +9 -0
- package/web-types.json +3956 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const css = String.raw;
|
|
2
|
+
|
|
3
|
+
export default css`
|
|
4
|
+
el-select-field {
|
|
5
|
+
display: block;
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Hide the custom .dropdown-indicator by default — the unthemed native
|
|
9
|
+
* <select> already paints its own chevron, so showing both would
|
|
10
|
+
* duplicate. Themes (default.css, high-contrast.css) un-hide and
|
|
11
|
+
* position the custom indicator, AND suppress the native chevron via
|
|
12
|
+
* appearance: none, so the result is a single, theme-able glyph.
|
|
13
|
+
*/
|
|
14
|
+
.dropdown-indicator {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.dropdown-indicator svg {
|
|
19
|
+
display: block;
|
|
20
|
+
width: 1em;
|
|
21
|
+
height: 1em;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this component live here. Versions refer to the parent `@webtides/element-library` release (see root [`CHANGELOG.md`](../../../CHANGELOG.md)); components no longer version independently.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
6
|
+
|
|
7
|
+
<!--
|
|
8
|
+
When your PR touches this component, add an entry under Unreleased and
|
|
9
|
+
mirror it (prefixed with the component name) in root CHANGELOG.md.
|
|
10
|
+
Uncomment headings as needed.
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
## Unreleased
|
|
14
|
+
|
|
15
|
+
## [0.1.0] - 2026-06-03
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- BREAKING: renamed the component — tag `el-slider-element` → `el-slider`, import subpaths `@webtides/element-library/slider-element` → `/slider` (and `/slider-element/define` → `/slider/define`), and exported class `SliderElement` → `Slider`.
|
|
20
|
+
- Hardcoded values in the stylesheet now reference design tokens with the previous values as fallbacks: `--el-color-fg` (dot color, default `light-dark(#333, #e5e7eb)`), `--el-color-bg` (arrow button background, default `light-dark(white, #1a1a1a)`), `--el-space-1` / `--el-space-2` / `--el-space-4` for padding.
|
|
21
|
+
|
|
22
|
+
## Legacy (pre-merge)
|
|
23
|
+
|
|
24
|
+
The version numbers below predate the single-package merge and refer to the component's former standalone npm package, not the current `@webtides/element-library` version. Kept for historical reference.
|
|
25
|
+
|
|
26
|
+
## [0.4.15] - 2022-07-21
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- update element-js
|
|
31
|
+
|
|
32
|
+
## [0.4.14] - 2022-07-18
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- make private fields #items & #itemsCount public
|
|
37
|
+
|
|
38
|
+
## [0.4.13] - 2021-09-09
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
|
|
42
|
+
- canSlide getter was throwing error when called before first update
|
|
43
|
+
|
|
44
|
+
## [0.4.12] - 2021-09-08
|
|
45
|
+
|
|
46
|
+
### ADDED
|
|
47
|
+
|
|
48
|
+
- canSlide getter
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- next() could cause an infinite loop if auoselect was on and the slider had no overflow
|
|
53
|
+
|
|
54
|
+
## [0.4.11] - 2021-09-07
|
|
55
|
+
|
|
56
|
+
### ADDED
|
|
57
|
+
|
|
58
|
+
- Resize Event for better Observation
|
|
59
|
+
|
|
60
|
+
## [0.4.10] - 2021-09-03
|
|
61
|
+
|
|
62
|
+
### Fixed
|
|
63
|
+
|
|
64
|
+
- infintie loop on next & autoselect
|
|
65
|
+
|
|
66
|
+
## [0.4.9] - 2021-09-02
|
|
67
|
+
|
|
68
|
+
### ADDED
|
|
69
|
+
|
|
70
|
+
- ResizeObserver to correct scroll positions after resize for Browsers with Scroll Snap Bugs (enabled by default)
|
|
71
|
+
- setIndexAfterResize Option to disable the above
|
|
72
|
+
- manualScrollEndDelay Option
|
|
73
|
+
|
|
74
|
+
### CHANGED
|
|
75
|
+
|
|
76
|
+
- manualScrollEnd Default Delay from 100ms to 200ms to prevent races with smooth scrolling
|
|
77
|
+
|
|
78
|
+
### Fixed
|
|
79
|
+
|
|
80
|
+
- Firefox / Safari Browser BUG after Layout SHIFT
|
|
81
|
+
|
|
82
|
+
## [0.4.8] - 2021-08-27
|
|
83
|
+
|
|
84
|
+
### Fixed
|
|
85
|
+
|
|
86
|
+
- scrollToIndex flag was never reseted as there was an early return in scroll listener. This Bug broke manualScrollEnd callback which was never executed once a button was pressed.
|
|
87
|
+
|
|
88
|
+
## [0.4.7] - 2021-07-02
|
|
89
|
+
|
|
90
|
+
### Added
|
|
91
|
+
|
|
92
|
+
- constructor options to overwrite default
|
|
93
|
+
- public method to (re)index children as items
|
|
94
|
+
|
|
95
|
+
## [0.4.6] - 2021-07-02
|
|
96
|
+
|
|
97
|
+
### Added
|
|
98
|
+
|
|
99
|
+
- adds initial check if initial scrollto is actually needed
|
|
100
|
+
|
|
101
|
+
## [0.4.5] - 2021-07-01
|
|
102
|
+
|
|
103
|
+
### FIXED
|
|
104
|
+
|
|
105
|
+
- maximum call stack error on autoselect when using margins for spacing
|
|
106
|
+
|
|
107
|
+
### Added
|
|
108
|
+
|
|
109
|
+
- stories for rendering slide items that wil get random dimensions after a timeout as a challenging test
|
|
110
|
+
|
|
111
|
+
## [0.4.4] - 2020-10-05
|
|
112
|
+
|
|
113
|
+
### Added
|
|
114
|
+
|
|
115
|
+
- part for disabled arrow
|
|
116
|
+
|
|
117
|
+
## [0.4.3] - 2020-09-29
|
|
118
|
+
|
|
119
|
+
### Fixed
|
|
120
|
+
|
|
121
|
+
- js error when scrollTo were called before render (externally)
|
|
122
|
+
|
|
123
|
+
## [0.4.2] - 2020-09-29
|
|
124
|
+
|
|
125
|
+
### Fixed
|
|
126
|
+
|
|
127
|
+
- initial selected index
|
|
128
|
+
|
|
129
|
+
### Added
|
|
130
|
+
|
|
131
|
+
- smooth flag to goto and scrollTo Method
|
|
132
|
+
|
|
133
|
+
## [0.4.1] - 2020-09-29
|
|
134
|
+
|
|
135
|
+
### Added
|
|
136
|
+
|
|
137
|
+
- feature flags for `dots` and `arrows`
|
|
138
|
+
- simple RUN to update external UI
|
|
139
|
+
|
|
140
|
+
### Fixed / Removed
|
|
141
|
+
|
|
142
|
+
- z-index from slider and ::slotted(item) css as it was bleeding into global style scope
|
|
143
|
+
|
|
144
|
+
## [0.4.0] - 2020-09-15
|
|
145
|
+
|
|
146
|
+
### Added
|
|
147
|
+
|
|
148
|
+
- `autoSelect` property. When set to `true` the slider will scroll to the next partially visible item in the direction the user wanted to go instead of only increasing/decreasing the index by one.
|
|
149
|
+
|
|
150
|
+
## [0.3.0] - 2020-09-11
|
|
151
|
+
|
|
152
|
+
### Added
|
|
153
|
+
|
|
154
|
+
- `goTo(index)` public method to control the slider from outside
|
|
155
|
+
|
|
156
|
+
### Changed
|
|
157
|
+
|
|
158
|
+
- refactored all calculations inside the slider to be more resilient
|
|
159
|
+
- the slider now can handle items of different widths
|
|
160
|
+
|
|
161
|
+
## [0.2.0] - 2020-09-08
|
|
162
|
+
|
|
163
|
+
### Added
|
|
164
|
+
|
|
165
|
+
- `canSlideLeft` and `canSlideRight` getter to check if arrow buttons should be shown in template
|
|
166
|
+
|
|
167
|
+
## [0.1.1] - 2020-08-26
|
|
168
|
+
|
|
169
|
+
### Added
|
|
170
|
+
|
|
171
|
+
- `--snap-align` custom property for changing the scroll-snap-align value for the scroller
|
|
172
|
+
|
|
173
|
+
## [0.1.0] - 2020-07-30
|
|
174
|
+
|
|
175
|
+
### Added
|
|
176
|
+
|
|
177
|
+
- initial release
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html } from '@webtides/element-js';
|
|
2
|
+
import SliderEvents from './slider.events.js';
|
|
3
|
+
import style from './slider.style.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CSS-scroll-snap based carousel. Direct children matched by `itemSelector` are arranged
|
|
7
|
+
* horizontally and navigated via the rendered dot pager and arrow buttons, by setting
|
|
8
|
+
* `selectedIndex`, or by calling `next()` / `previous()` / `goTo()`.
|
|
9
|
+
*
|
|
10
|
+
* @element el-slider
|
|
11
|
+
*
|
|
12
|
+
* @fires {CustomEvent<number>} SliderRun - Fired when `selectedIndex` changes.
|
|
13
|
+
* `detail` is the new index.
|
|
14
|
+
* @fires {CustomEvent<number>} SliderResize - Fired after the host element resizes and
|
|
15
|
+
* the slider re-aligns to the current index. `detail` is the current index.
|
|
16
|
+
*
|
|
17
|
+
* @slot - Default slot. Place item nodes here; each must match `itemSelector`.
|
|
18
|
+
* @slot arrow-left - Content of the "previous" navigation button (defaults to `⟨`).
|
|
19
|
+
* @slot arrow-right - Content of the "next" navigation button (defaults to `⟩`).
|
|
20
|
+
*
|
|
21
|
+
* @csspart scroller - The horizontally scrolling track.
|
|
22
|
+
* @csspart controls - Applied to both the dots wrapper and the arrows wrapper.
|
|
23
|
+
* @csspart dots - The dot pager wrapper.
|
|
24
|
+
* @csspart dot - Applied to each pager dot.
|
|
25
|
+
* @csspart selected-dot - Added to the dot representing the active slide.
|
|
26
|
+
* @csspart arrows - The arrow buttons wrapper.
|
|
27
|
+
* @csspart arrow - Applied to both arrow buttons.
|
|
28
|
+
* @csspart arrow-left - Applied to the previous button (in addition to `arrow`).
|
|
29
|
+
* @csspart arrow-right - Applied to the next button (in addition to `arrow`).
|
|
30
|
+
* @csspart arrow-disabled - Added to an arrow button when it cannot navigate further.
|
|
31
|
+
*
|
|
32
|
+
* @property {string} itemSelector - CSS selector used to find item nodes among the slotted
|
|
33
|
+
* children.
|
|
34
|
+
* @property {number} itemsToShow - Number of items visible per slide step. Used to compute
|
|
35
|
+
* the per-item width.
|
|
36
|
+
* @property {number} itemsToScroll - Number of items advanced by each `next()` / `previous()`
|
|
37
|
+
* call.
|
|
38
|
+
* @property {boolean} rewind - When `true`, navigating past the last (or before the first)
|
|
39
|
+
* item wraps around.
|
|
40
|
+
* @property {number} selectedIndex - Currently focused item index.
|
|
41
|
+
* @property {boolean} autoSelect - When `true`, navigation skips items that are already fully
|
|
42
|
+
* visible.
|
|
43
|
+
* @property {boolean} dots - Whether to render the dot pager.
|
|
44
|
+
* @property {boolean} arrows - Whether to render the previous/next arrow buttons.
|
|
45
|
+
* @property {boolean} setIndexAfterResize - When `true`, the slider re-aligns to
|
|
46
|
+
* `selectedIndex` after the host resizes.
|
|
47
|
+
* @property {number} manualScrollEndDelay - Debounce window (ms) used to detect the end of a
|
|
48
|
+
* manual scroll.
|
|
49
|
+
*/
|
|
50
|
+
export default class Slider extends TemplateElement {
|
|
51
|
+
/** @private */
|
|
52
|
+
itemsCount = 0;
|
|
53
|
+
/** @private */
|
|
54
|
+
#scrollTimer = null;
|
|
55
|
+
/** @private */
|
|
56
|
+
items = null;
|
|
57
|
+
/** @private */
|
|
58
|
+
#scrollToIndex = false;
|
|
59
|
+
|
|
60
|
+
constructor(options) {
|
|
61
|
+
super({ shadowRender: true, deferUpdate: true, adoptGlobalStyles: false, styles: [style], ...options });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
properties() {
|
|
65
|
+
return {
|
|
66
|
+
itemSelector: '.item',
|
|
67
|
+
itemsToShow: 1,
|
|
68
|
+
itemsToScroll: 1,
|
|
69
|
+
rewind: false,
|
|
70
|
+
selectedIndex: 0,
|
|
71
|
+
autoSelect: false,
|
|
72
|
+
dots: true,
|
|
73
|
+
arrows: true,
|
|
74
|
+
setIndexAfterResize: true,
|
|
75
|
+
manualScrollEndDelay: 200,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* `true` when the slider's content overflows its viewport (i.e. there is anything
|
|
81
|
+
* to scroll through).
|
|
82
|
+
*/
|
|
83
|
+
get canSlide() {
|
|
84
|
+
if (!this.$refs.scroller) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return this.$refs.scroller.scrollWidth > this.$refs.scroller.offsetWidth;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** `true` when `selectedIndex` can be decremented. */
|
|
91
|
+
get canSlideLeft() {
|
|
92
|
+
return this.selectedIndex > 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** `true` when `selectedIndex` can be incremented. */
|
|
96
|
+
get canSlideRight() {
|
|
97
|
+
return this.selectedIndex < this.itemsCount;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
connected() {
|
|
101
|
+
this.indexItems();
|
|
102
|
+
this.requestUpdate().then(() => {
|
|
103
|
+
if (this.selectedIndex > 0) {
|
|
104
|
+
//scroll to initial slide if set
|
|
105
|
+
this.scrollToIndex(false);
|
|
106
|
+
}
|
|
107
|
+
if (this.setIndexAfterResize) {
|
|
108
|
+
this.addResizeListener();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @private */
|
|
114
|
+
indexItems() {
|
|
115
|
+
this.items = Array.from(this.querySelectorAll(this.itemSelector));
|
|
116
|
+
this.itemsCount = this.items.length > 1 ? this.items.length - 1 : 0;
|
|
117
|
+
this.style.setProperty('--item-width', `${100 / this.itemsToShow}%`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
events() {
|
|
121
|
+
return {
|
|
122
|
+
'.scroller': {
|
|
123
|
+
scroll: () => this.startScrollEndTimer(),
|
|
124
|
+
},
|
|
125
|
+
'.dot': {
|
|
126
|
+
click: (e) => {
|
|
127
|
+
const indicator = e.target.closest('.dot');
|
|
128
|
+
this.selectedIndex = Array.from(indicator.parentNode.children).indexOf(indicator);
|
|
129
|
+
this.scrollToIndex();
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
'.arrow-left': {
|
|
133
|
+
click: () => this.previous(),
|
|
134
|
+
},
|
|
135
|
+
'.arrow-right': {
|
|
136
|
+
click: () => this.next(),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
watch() {
|
|
142
|
+
return {
|
|
143
|
+
selectedIndex: () => {
|
|
144
|
+
this.dispatch(SliderEvents.SLIDER_RUN, this.selectedIndex);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Advance to the next item (by `itemsToScroll`).
|
|
151
|
+
* @returns {void}
|
|
152
|
+
*/
|
|
153
|
+
next() {
|
|
154
|
+
const newIndex = this.selectedIndex + this.itemsToScroll;
|
|
155
|
+
this.selectedIndex = this.rewind && newIndex > this.itemsCount ? 0 : Math.min(this.itemsCount, newIndex);
|
|
156
|
+
if (this.autoSelect && this.canSlide) {
|
|
157
|
+
//check if element is already visible
|
|
158
|
+
const target = this.items[this.selectedIndex];
|
|
159
|
+
if (target) {
|
|
160
|
+
const parent = this.$refs.scroller;
|
|
161
|
+
const { marginLeft, marginRight } = getComputedStyle(target);
|
|
162
|
+
const targetWidth = target.offsetWidth + parseInt(marginLeft) + parseInt(marginRight);
|
|
163
|
+
if (target.offsetLeft + targetWidth < parent.scrollLeft + parent.offsetWidth) {
|
|
164
|
+
// means is in bounds
|
|
165
|
+
this.next();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
this.scrollToIndex();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Move to the previous item (by `itemsToScroll`).
|
|
175
|
+
* @returns {void}
|
|
176
|
+
*/
|
|
177
|
+
previous() {
|
|
178
|
+
const newIndex = this.selectedIndex - this.itemsToScroll;
|
|
179
|
+
this.selectedIndex = this.rewind && newIndex < 0 ? this.itemsCount : Math.max(newIndex, 0);
|
|
180
|
+
|
|
181
|
+
if (this.autoSelect && this.canSlide) {
|
|
182
|
+
//check if element is already visible
|
|
183
|
+
const target = this.items[this.selectedIndex];
|
|
184
|
+
if (target) {
|
|
185
|
+
const { marginLeft } = getComputedStyle(target);
|
|
186
|
+
const parent = this.$refs.scroller;
|
|
187
|
+
if (target.offsetLeft - parseInt(marginLeft) > parent.scrollLeft) {
|
|
188
|
+
// means is still in viewport
|
|
189
|
+
this.previous();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.scrollToIndex();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Jump directly to `index`.
|
|
200
|
+
* @param {number} index - Target item index.
|
|
201
|
+
* @param {boolean} [smooth=true] - When `true` the scroll animates; otherwise it
|
|
202
|
+
* jumps instantly.
|
|
203
|
+
* @returns {void}
|
|
204
|
+
*/
|
|
205
|
+
goTo(index, smooth = true) {
|
|
206
|
+
if (index !== this.selectedIndex) {
|
|
207
|
+
this.selectedIndex = index;
|
|
208
|
+
this.scrollToIndex(smooth);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** @private */
|
|
213
|
+
startScrollEndTimer() {
|
|
214
|
+
clearTimeout(this.#scrollTimer);
|
|
215
|
+
this.#scrollTimer = setTimeout(() => this.onManualScrollEnd(), this.manualScrollEndDelay);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** @private */
|
|
219
|
+
scrollToIndex(smooth = true) {
|
|
220
|
+
if (!this.$refs.scroller) {
|
|
221
|
+
//external call before render
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (smooth) {
|
|
225
|
+
this.#scrollToIndex = true;
|
|
226
|
+
// start timer just in case the slider is not scrolling at all
|
|
227
|
+
this.startScrollEndTimer();
|
|
228
|
+
}
|
|
229
|
+
const target = this.items[this.selectedIndex];
|
|
230
|
+
if (!target) return;
|
|
231
|
+
const parent = this.$refs.scroller;
|
|
232
|
+
const parentWidth = parent.offsetWidth;
|
|
233
|
+
|
|
234
|
+
let targetLeft = target.offsetLeft - (parentWidth - target.offsetWidth) / 2;
|
|
235
|
+
|
|
236
|
+
const snapAlign = window.getComputedStyle(target).scrollSnapAlign;
|
|
237
|
+
if (snapAlign === 'start') {
|
|
238
|
+
targetLeft = target.offsetLeft;
|
|
239
|
+
} else if (snapAlign === 'end') {
|
|
240
|
+
targetLeft = target.offsetLeft - (parentWidth - target.offsetWidth);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
this.$refs.scroller.scrollTo({
|
|
244
|
+
left: targetLeft,
|
|
245
|
+
behavior: smooth ? 'smooth' : 'auto',
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** @private */
|
|
250
|
+
onManualScrollEnd() {
|
|
251
|
+
if (!this.#scrollToIndex) {
|
|
252
|
+
const scroller = this.$refs.scroller;
|
|
253
|
+
const scrollLeft = scroller.scrollLeft;
|
|
254
|
+
const scrollPercentage = scrollLeft / (scroller.scrollWidth - scroller.offsetWidth);
|
|
255
|
+
|
|
256
|
+
if (scrollPercentage === 0) {
|
|
257
|
+
this.selectedIndex = 0;
|
|
258
|
+
} else if (scrollPercentage === 1) {
|
|
259
|
+
this.selectedIndex = this.itemsCount;
|
|
260
|
+
} else {
|
|
261
|
+
//aprox or guess selectedIndex to fix UI state
|
|
262
|
+
this.selectedIndex = Math.ceil(this.itemsCount * scrollPercentage);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
this.#scrollToIndex = false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** @private */
|
|
269
|
+
addResizeListener() {
|
|
270
|
+
try {
|
|
271
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
272
|
+
/*
|
|
273
|
+
* https://web.dev/snap-after-layout/
|
|
274
|
+
* this codes attempts to fix scrollsnap Position after layout changes
|
|
275
|
+
* */
|
|
276
|
+
this.#scrollToIndex = true;
|
|
277
|
+
this.dispatch(SliderEvents.SLIDER_RESIZE, this.selectedIndex);
|
|
278
|
+
this.scrollToIndex(false);
|
|
279
|
+
this.startScrollEndTimer();
|
|
280
|
+
});
|
|
281
|
+
resizeObserver.observe(this);
|
|
282
|
+
} catch (e) {
|
|
283
|
+
/* no ResizeOberserver no fix */
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
template() {
|
|
288
|
+
return html`
|
|
289
|
+
<div ref="scroller" part="scroller" class="scroller">
|
|
290
|
+
<slot></slot>
|
|
291
|
+
</div>
|
|
292
|
+
${this.dots ? html` <div part="controls dots">${this.dotsTemplate()}</div> ` : null}
|
|
293
|
+
${this.arrows ? html` <div part="controls arrows">${this.arrowsTemplate()}</div> ` : null}
|
|
294
|
+
`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** @private */
|
|
298
|
+
dotsTemplate() {
|
|
299
|
+
return this.items.map((item, index) => {
|
|
300
|
+
return html`
|
|
301
|
+
<button
|
|
302
|
+
part="dot ${this.selectedIndex === index ? 'selected-dot' : ''}"
|
|
303
|
+
class="dot"
|
|
304
|
+
aria-pressed="${this.selectedIndex === index ? 'true' : 'false'}"
|
|
305
|
+
></button>
|
|
306
|
+
`;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** @private */
|
|
311
|
+
arrowsTemplate() {
|
|
312
|
+
const disabledLeft = !this.rewind && !this.canSlideLeft;
|
|
313
|
+
const disabledRight = !this.rewind && !this.canSlideRight;
|
|
314
|
+
|
|
315
|
+
return html`
|
|
316
|
+
<button
|
|
317
|
+
part="arrow arrow-left ${disabledLeft ? 'arrow-disabled' : ''}"
|
|
318
|
+
class="arrow-left"
|
|
319
|
+
?disabled=${disabledLeft}
|
|
320
|
+
>
|
|
321
|
+
<slot name="arrow-left">⟨</slot>
|
|
322
|
+
</button>
|
|
323
|
+
<button
|
|
324
|
+
part="arrow arrow-right ${disabledRight ? 'arrow-disabled' : ''}"
|
|
325
|
+
class="arrow-right"
|
|
326
|
+
?disabled=${disabledRight}
|
|
327
|
+
>
|
|
328
|
+
<slot name="arrow-right">⟩</slot>
|
|
329
|
+
</button>
|
|
330
|
+
`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function define() {
|
|
335
|
+
defineElement('el-slider', Slider);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export { html, defineElement, SliderEvents };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Slider
|
|
2
|
+
|
|
3
|
+
`slider` is a CSS-scroll-snap based carousel. Direct children matched by `itemSelector` are arranged horizontally and navigated via the rendered dot pager and arrow buttons, by setting `selectedIndex`, or by calling `next()` / `previous()` / `goTo()`.
|
|
4
|
+
|
|
5
|
+
## How to use
|
|
6
|
+
|
|
7
|
+
#### Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i --save @webtides/element-library
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
#### Use
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import '@webtides/element-library/slider/define';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<el-slider>
|
|
21
|
+
<li class="item">1</li>
|
|
22
|
+
<li class="item">2</li>
|
|
23
|
+
<li class="item">3</li>
|
|
24
|
+
</el-slider>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API
|
|
28
|
+
|
|
29
|
+
#### Properties/Attributes
|
|
30
|
+
|
|
31
|
+
| Name | Type | Default | Description |
|
|
32
|
+
| --- | --- | --- | --- |
|
|
33
|
+
| `itemSelector` | `string` | `'.item'` | CSS selector used to find item nodes among the slotted children. |
|
|
34
|
+
| `itemsToShow` | `number` | `1` | Number of items visible per slide step. Used to compute the per-item width. |
|
|
35
|
+
| `itemsToScroll` | `number` | `1` | Number of items advanced by each `next()` / `previous()` call. |
|
|
36
|
+
| `rewind` | `boolean` | `false` | When `true`, navigating past the last (or before the first) item wraps around. |
|
|
37
|
+
| `selectedIndex` | `number` | `0` | Currently focused item index. |
|
|
38
|
+
| `autoSelect` | `boolean` | `false` | When `true`, navigation skips items that are already fully visible. |
|
|
39
|
+
| `dots` | `boolean` | `true` | Whether to render the dot pager. |
|
|
40
|
+
| `arrows` | `boolean` | `true` | Whether to render the previous/next arrow buttons. |
|
|
41
|
+
| `setIndexAfterResize` | `boolean` | `true` | When `true`, the slider re-aligns to `selectedIndex` after the host resizes. |
|
|
42
|
+
| `manualScrollEndDelay` | `number` | `200` | Debounce window (ms) used to detect the end of a manual scroll. |
|
|
43
|
+
|
|
44
|
+
#### Methods
|
|
45
|
+
|
|
46
|
+
| Name | Parameters | Description |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `next()` | None | Advance to the next item (by `itemsToScroll`). |
|
|
49
|
+
| `previous()` | None | Move to the previous item (by `itemsToScroll`). |
|
|
50
|
+
| `goTo(index, smooth?)` | `index: number`, `smooth: boolean = true` | Jump to a specific item index, optionally with smooth scrolling. |
|
|
51
|
+
| `canSlide` _(getter)_ | None | `true` when the slider's content overflows its viewport (i.e. there is anything to scroll through). |
|
|
52
|
+
| `canSlideLeft` _(getter)_ | None | `true` when `selectedIndex` can be decremented. |
|
|
53
|
+
| `canSlideRight` _(getter)_ | None | `true` when `selectedIndex` can be incremented. |
|
|
54
|
+
|
|
55
|
+
#### Events
|
|
56
|
+
|
|
57
|
+
| Name | Detail | Description |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `SliderRun` | `number` | Fired when `selectedIndex` changes. The detail is the new index. |
|
|
60
|
+
| `SliderResize` | `number` | Fired after the host element resizes and the slider re-aligns to the current index. The detail is the current index. |
|
|
61
|
+
|
|
62
|
+
#### Slots
|
|
63
|
+
|
|
64
|
+
| Name | Description |
|
|
65
|
+
| ------------- | -------------------------------------------------------------- |
|
|
66
|
+
| _(default)_ | Place item nodes here; each must match `itemSelector`. |
|
|
67
|
+
| `arrow-left` | Content of the "previous" navigation button (defaults to `⟨`). |
|
|
68
|
+
| `arrow-right` | Content of the "next" navigation button (defaults to `⟩`). |
|
|
69
|
+
|
|
70
|
+
#### CSS Parts
|
|
71
|
+
|
|
72
|
+
| Name | Description |
|
|
73
|
+
| ---------------- | --------------------------------------------------------- |
|
|
74
|
+
| `scroller` | The horizontally scrolling track. |
|
|
75
|
+
| `controls` | Applied to both the dots wrapper and the arrows wrapper. |
|
|
76
|
+
| `dots` | The dot pager wrapper. |
|
|
77
|
+
| `dot` | Applied to each pager dot. |
|
|
78
|
+
| `selected-dot` | Added to the dot representing the active slide. |
|
|
79
|
+
| `arrows` | The arrow buttons wrapper. |
|
|
80
|
+
| `arrow` | Applied to both arrow buttons. |
|
|
81
|
+
| `arrow-left` | Applied to the previous button (in addition to `arrow`). |
|
|
82
|
+
| `arrow-right` | Applied to the next button (in addition to `arrow`). |
|
|
83
|
+
| `arrow-disabled` | Added to an arrow button when it cannot navigate further. |
|
|
84
|
+
|
|
85
|
+
#### CSS Custom Properties
|
|
86
|
+
|
|
87
|
+
This component is headless by default and reads the library's `--el-*` design tokens (e.g. `--el-color-accent`, `--el-color-border`, `--el-radius-md`). Skin it by setting these via a theme — see the Storybook _Docs / Theming_ page.
|