@shortfuse/materialdesignweb 0.0.9 → 0.4.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/.browserslistrc +3 -0
- package/.eslintrc.json +146 -27
- package/.stylelintrc.json +598 -2
- package/.vscode/launch.json +20 -5
- package/.vscode/settings.json +3 -0
- package/.vscode/tasks.json +19 -10
- package/CHANGELOG.md +24 -0
- package/README.md +84 -2
- package/adapters/datatable/column.js +203 -0
- package/adapters/datatable/index.js +972 -0
- package/adapters/dom/index.js +601 -0
- package/adapters/list/index.js +69 -0
- package/adapters/search/index.js +521 -0
- package/components/appbar/_spec.scss +225 -0
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +2 -0
- package/components/banner/_spec.scss +118 -0
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +2 -0
- package/components/bottomnav/README.md +85 -0
- package/components/bottomnav/_spec.scss +157 -0
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +122 -0
- package/components/bottomnav/index.scss +2 -0
- package/components/bottomnav/item.js +89 -0
- package/components/{core/button → button}/README.md +16 -22
- package/components/button/_spec.scss +161 -0
- package/components/button/_theme.scss +65 -0
- package/components/button/index.eta +32 -0
- package/components/button/index.js +43 -0
- package/components/button/index.pug +18 -0
- package/components/button/index.scss +2 -0
- package/components/card/_spec.scss +249 -0
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +2 -0
- package/components/chip/_spec.scss +134 -0
- package/components/chip/_theme.scss +177 -0
- package/components/chip/index.js +21 -0
- package/components/chip/index.scss +2 -0
- package/components/chip/item.js +20 -0
- package/components/datatable/_spec.scss +288 -0
- package/components/datatable/_theme.scss +154 -0
- package/components/datatable/cell.js +45 -0
- package/components/datatable/columnheader.js +47 -0
- package/components/datatable/index.js +388 -0
- package/components/datatable/index.scss +2 -0
- package/components/datatable/row.js +49 -0
- package/components/datatable/rowheader.js +18 -0
- package/components/dialog/_spec.scss +213 -0
- package/components/dialog/_theme.scss +0 -0
- package/components/dialog/index.js +627 -0
- package/components/dialog/index.scss +2 -0
- package/components/divider/_spec.scss +13 -0
- package/components/divider/_theme.scss +0 -0
- package/components/divider/index.scss +2 -0
- package/components/elevation/_spec.scss +9 -0
- package/components/elevation/_theme.scss +0 -0
- package/components/elevation/index.scss +2 -0
- package/components/fab/_spec.scss +222 -0
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +103 -0
- package/components/fab/index.scss +2 -0
- package/components/grid/_spec.scss +312 -0
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +2 -0
- package/components/layout/_mixins.scss +33 -0
- package/components/layout/_spec.scss +1012 -0
- package/components/layout/_theme.scss +44 -0
- package/components/layout/index.js +464 -0
- package/components/layout/index.scss +2 -0
- package/components/list/_spec.scss +397 -0
- package/components/list/_theme.scss +111 -0
- package/components/list/content.js +110 -0
- package/components/list/index.js +260 -0
- package/components/list/index.scss +2 -0
- package/components/list/item.js +170 -0
- package/components/list/secondary.js +46 -0
- package/components/menu/_spec.scss +362 -0
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +721 -0
- package/components/menu/index.scss +2 -0
- package/components/menu/item.js +239 -0
- package/components/{core/progress/style.scss → progress/_spec.scss} +36 -25
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +36 -0
- package/components/progress/index.scss +2 -0
- package/components/selection/_spec.scss +386 -0
- package/components/selection/_theme.scss +166 -0
- package/components/selection/index.eta +60 -0
- package/components/selection/index.js +76 -0
- package/components/selection/index.pug +30 -0
- package/components/selection/index.scss +2 -0
- package/components/selection/input.js +56 -0
- package/components/selection/radiogroup.js +47 -0
- package/components/slider/_spec.scss +64 -0
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +2 -0
- package/components/snackbar/_spec.scss +195 -0
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +344 -0
- package/components/snackbar/index.scss +2 -0
- package/components/tab/_spec.scss +235 -0
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +205 -0
- package/components/tab/index.js +260 -0
- package/components/tab/index.scss +2 -0
- package/components/tab/item.js +89 -0
- package/components/tab/list.js +210 -0
- package/components/tab/panel.js +54 -0
- package/components/template/_theme.scss +27 -0
- package/components/{core/textfield → textfield}/README.md +70 -50
- package/components/textfield/_mixins.scss +52 -0
- package/components/textfield/_spec.scss +809 -0
- package/components/textfield/_theme.scss +299 -0
- package/components/textfield/index.eta +74 -0
- package/components/textfield/index.js +168 -0
- package/components/textfield/index.pug +30 -0
- package/components/textfield/index.scss +2 -0
- package/components/tooltip/_spec.scss +188 -0
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +2 -0
- package/components/type/_spec.scss +224 -0
- package/components/type/_theme.scss +0 -0
- package/components/type/index.scss +2 -0
- package/core/_breakpoint.scss +189 -0
- package/core/_elevation.scss +38 -0
- package/core/_length.scss +9 -0
- package/core/_motion.scss +31 -0
- package/core/_platform.scss +34 -0
- package/core/_type.scss +127 -0
- package/core/aria/attributes.js +141 -0
- package/core/aria/button.js +50 -0
- package/core/aria/keyboard.js +93 -0
- package/core/aria/rovingtabindex.js +178 -0
- package/core/aria/tab.js +60 -0
- package/core/color/_spec.scss +0 -0
- package/core/color/_theme.scss +390 -0
- package/core/color/index.scss +2 -0
- package/core/document/index.js +39 -0
- package/core/dom.js +271 -0
- package/core/overlay/_spec.scss +31 -0
- package/core/overlay/_theme.scss +171 -0
- package/core/overlay/index.js +108 -0
- package/core/overlay/index.scss +2 -0
- package/core/ripple/_spec.scss +197 -0
- package/core/ripple/_theme.scss +40 -0
- package/core/ripple/index.js +294 -0
- package/core/ripple/index.scss +2 -0
- package/core/theme/_config.scss +2 -0
- package/core/theme/_mixins.scss +172 -0
- package/{components/theming/palettes.scss → core/theme/_palettes.scss} +173 -150
- package/core/theme/_variables.scss +24 -0
- package/core/theme/index.js +50 -0
- package/core/throttler.js +42 -0
- package/core/transition/index.js +468 -0
- package/docs/_flex.scss +22 -0
- package/docs/_menuoptions.js +183 -0
- package/docs/_mixins.pug +155 -0
- package/docs/_partials/_androidnavbar.eta +5 -0
- package/docs/_partials/_androidstatusbar.eta +13 -0
- package/docs/_partials/_appbar.eta +29 -0
- package/docs/_partials/_buttontest.eta +31 -0
- package/docs/_partials/_header.eta +149 -0
- package/docs/_partials/_navlistitem.eta +16 -0
- package/docs/_partials/_target.eta +1 -0
- package/docs/_sample-utils.js +93 -0
- package/docs/_storage.js +33 -0
- package/docs/docs.scss +295 -0
- package/docs/index.eta +16 -0
- package/docs/index.js +0 -0
- package/docs/pages/appbar.eta +114 -0
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/appbar.pug +78 -0
- package/docs/pages/bottomnav.eta +188 -0
- package/docs/pages/bottomnav.js +115 -0
- package/docs/pages/bottomnav.pug +137 -0
- package/docs/pages/button.eta +124 -0
- package/docs/pages/button.js +224 -0
- package/docs/pages/button.pug +121 -0
- package/docs/pages/card.eta +90 -0
- package/docs/pages/card.js +177 -0
- package/docs/pages/card.pug +74 -0
- package/docs/pages/chip.eta +122 -0
- package/docs/pages/chip.js +82 -0
- package/docs/pages/chip.pug +91 -0
- package/docs/pages/color.eta +143 -0
- package/docs/pages/color.js +262 -0
- package/docs/pages/color.pug +121 -0
- package/docs/pages/datatable.eta +323 -0
- package/docs/pages/datatable.js +164 -0
- package/docs/pages/datatable.pug +283 -0
- package/docs/pages/dialog.eta +186 -0
- package/docs/pages/dialog.js +177 -0
- package/docs/pages/dialog.pug +132 -0
- package/docs/pages/dom.eta +26 -0
- package/docs/pages/dom.js +143 -0
- package/docs/pages/dom.pug +22 -0
- package/docs/pages/elevation.eta +35 -0
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/elevation.pug +25 -0
- package/docs/pages/fab.eta +99 -0
- package/docs/pages/fab.js +44 -0
- package/docs/pages/fab.pug +66 -0
- package/docs/pages/grid.eta +135 -0
- package/docs/pages/grid.js +128 -0
- package/docs/pages/grid.pug +95 -0
- package/docs/pages/layout.eta +8 -0
- package/docs/pages/layout.js +0 -0
- package/docs/pages/layout.pug +7 -0
- package/docs/pages/list.eta +465 -0
- package/docs/pages/list.js +9 -0
- package/docs/pages/list.pug +326 -0
- package/docs/pages/menu.eta +276 -0
- package/docs/pages/menu.js +217 -0
- package/docs/pages/menu.pug +205 -0
- package/docs/pages/overlay.eta +69 -0
- package/docs/pages/overlay.js +4 -0
- package/docs/pages/overlay.pug +55 -0
- package/docs/pages/progress.eta +23 -0
- package/docs/pages/progress.js +12 -0
- package/docs/pages/progress.pug +16 -0
- package/docs/pages/ripple.eta +27 -0
- package/docs/pages/ripple.js +4 -0
- package/docs/pages/ripple.pug +21 -0
- package/docs/pages/search.eta +246 -0
- package/docs/pages/search.js +243 -0
- package/docs/pages/search.pug +165 -0
- package/docs/pages/selection.eta +111 -0
- package/docs/pages/selection.js +13 -0
- package/docs/pages/selection.pug +74 -0
- package/docs/pages/slider.eta +23 -0
- package/docs/pages/slider.js +0 -0
- package/docs/pages/slider.pug +17 -0
- package/docs/pages/snackbar.eta +83 -0
- package/docs/pages/snackbar.js +158 -0
- package/docs/pages/snackbar.pug +60 -0
- package/docs/pages/tab.eta +421 -0
- package/docs/pages/tab.js +151 -0
- package/docs/pages/tab.pug +304 -0
- package/docs/pages/textfield.eta +486 -0
- package/docs/pages/textfield.js +254 -0
- package/docs/pages/textfield.pug +360 -0
- package/docs/pages/tooltip.eta +94 -0
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/tooltip.pug +78 -0
- package/docs/pages/transition.eta +117 -0
- package/docs/pages/transition.js +54 -0
- package/docs/pages/transition.pug +76 -0
- package/docs/pages/type.eta +31 -0
- package/docs/pages/type.js +0 -0
- package/docs/pages/type.pug +29 -0
- package/docs/postrender.js +39 -0
- package/docs/prerender.js +16 -0
- package/docs/pwa/_dialogs.eta +143 -0
- package/docs/pwa/_dialogs.pug +96 -0
- package/docs/pwa/_menus.eta +16 -0
- package/docs/pwa/_menus.pug +11 -0
- package/docs/pwa/pwa-prerender.js +3 -0
- package/docs/pwa/pwa.eta +480 -0
- package/docs/pwa/pwa.js +306 -0
- package/docs/pwa/pwa.pug +325 -0
- package/docs/pwa/pwa.scss +26 -0
- package/docs/spec.scss +26 -0
- package/docs/themes/_component-themes.scss +26 -0
- package/docs/themes/theme-colored-fallbacks.scss +17 -0
- package/docs/themes/theme-colored.scss +17 -0
- package/docs/themes/theme-default-fallbacks.scss +17 -0
- package/docs/themes/theme-default.scss +17 -0
- package/jsconfig.json +4 -2
- package/package.json +43 -28
- package/scripts/deploy-docs.sh +9 -0
- package/templates/index.eta +2 -0
- package/templates/index.pug +3 -0
- package/utils/function.js +3 -0
- package/webpack.config.cjs +257 -0
- package/components/_index.scss +0 -4
- package/components/all-components.scss +0 -14
- package/components/common/functions.scss +0 -173
- package/components/common/mixins.scss +0 -107
- package/components/common/motion.scss +0 -36
- package/components/common/ripple.scss +0 -92
- package/components/common/variables.scss +0 -48
- package/components/complex/dialog/style.scss +0 -159
- package/components/complex/dialog/theming.scss +0 -29
- package/components/complex/navdrawer/style.scss +0 -477
- package/components/complex/navdrawer/theming.scss +0 -58
- package/components/complex/search/index.js +0 -492
- package/components/core/bottomnav/README.md +0 -85
- package/components/core/bottomnav/index.js +0 -140
- package/components/core/bottomnav/style.scss +0 -173
- package/components/core/bottomnav/theming.scss +0 -42
- package/components/core/button/index.js +0 -52
- package/components/core/button/style.scss +0 -283
- package/components/core/button/theming.scss +0 -131
- package/components/core/list/index.js +0 -94
- package/components/core/list/style.scss +0 -269
- package/components/core/list/theming.scss +0 -74
- package/components/core/menu/index.js +0 -127
- package/components/core/menu/style.scss +0 -239
- package/components/core/menu/theming.scss +0 -55
- package/components/core/progress/index.js +0 -33
- package/components/core/selection/style.scss +0 -249
- package/components/core/selection/theming.scss +0 -49
- package/components/core/switch/style.scss +0 -3
- package/components/core/tab/index.js +0 -174
- package/components/core/tab/style.scss +0 -202
- package/components/core/tab/theming.scss +0 -43
- package/components/core/textfield/index.js +0 -169
- package/components/core/textfield/style.scss +0 -672
- package/components/core/textfield/theming.scss +0 -262
- package/components/core/toolbar/style.scss +0 -109
- package/components/core/toolbar/theming.scss +0 -28
- package/components/core/tooltip/style.scss +0 -127
- package/components/core/type/style.scss +0 -133
- package/components/core/type/theming.scss +0 -25
- package/components/index.js +0 -24
- package/components/template/theming.scss +0 -31
- package/components/theming/theming.scss +0 -504
- package/docs/bottomnav.html +0 -171
- package/docs/bottomnav.min.js +0 -383
- package/docs/button.html +0 -322
- package/docs/button.min.js +0 -251
- package/docs/components.min.css +0 -1
- package/docs/components.min.js +0 -83
- package/docs/dialog.html +0 -103
- package/docs/dialog.min.js +0 -160
- package/docs/docs.min.css +0 -1
- package/docs/docs.min.js +0 -83
- package/docs/index.html +0 -55
- package/docs/index.min.js +0 -83
- package/docs/list.html +0 -442
- package/docs/list.min.js +0 -312
- package/docs/menu.html +0 -185
- package/docs/menu.min.js +0 -370
- package/docs/navdrawer.html +0 -199
- package/docs/navdrawer.min.js +0 -244
- package/docs/progress.html +0 -75
- package/docs/progress.min.js +0 -162
- package/docs/search.html +0 -230
- package/docs/search.min.js +0 -1202
- package/docs/selection.html +0 -188
- package/docs/selection.min.js +0 -160
- package/docs/src/complex/dialog.js +0 -3
- package/docs/src/complex/dialog.pug +0 -44
- package/docs/src/complex/navdrawer.js +0 -82
- package/docs/src/complex/navdrawer.pug +0 -109
- package/docs/src/complex/search.js +0 -207
- package/docs/src/complex/search.pug +0 -143
- package/docs/src/components.scss +0 -1
- package/docs/src/core/bottomnav.js +0 -22
- package/docs/src/core/bottomnav.pug +0 -93
- package/docs/src/core/button.js +0 -16
- package/docs/src/core/button.pug +0 -73
- package/docs/src/core/list.js +0 -21
- package/docs/src/core/list.pug +0 -246
- package/docs/src/core/menu.js +0 -33
- package/docs/src/core/menu.pug +0 -108
- package/docs/src/core/progress.js +0 -11
- package/docs/src/core/progress.pug +0 -17
- package/docs/src/core/selection.js +0 -4
- package/docs/src/core/selection.pug +0 -92
- package/docs/src/core/tab.js +0 -21
- package/docs/src/core/tab.pug +0 -180
- package/docs/src/core/textfield.js +0 -15
- package/docs/src/core/textfield.pug +0 -274
- package/docs/src/core/toolbar.js +0 -4
- package/docs/src/core/toolbar.pug +0 -79
- package/docs/src/core/tooltip.js +0 -4
- package/docs/src/core/tooltip.pug +0 -76
- package/docs/src/core/type.js +0 -4
- package/docs/src/core/type.pug +0 -36
- package/docs/src/docs.scss +0 -200
- package/docs/src/index.pug +0 -5
- package/docs/src/mixins.pug +0 -72
- package/docs/src/targetHandler.js +0 -50
- package/docs/src/theming.ie11.scss +0 -35
- package/docs/src/theming.scss +0 -36
- package/docs/tab.html +0 -301
- package/docs/tab.min.js +0 -397
- package/docs/textfield.html +0 -476
- package/docs/textfield.min.js +0 -381
- package/docs/theming.ie11.min.css +0 -1
- package/docs/theming.ie11.min.js +0 -83
- package/docs/theming.min.css +0 -1
- package/docs/theming.min.js +0 -83
- package/docs/toolbar.html +0 -213
- package/docs/toolbar.min.js +0 -160
- package/docs/tooltip.html +0 -138
- package/docs/tooltip.min.js +0 -160
- package/docs/type.html +0 -94
- package/docs/type.min.js +0 -160
- package/webpack.config.js +0 -176
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
import { TextField } from '../../core/textfield/index';
|
|
2
|
-
import { List } from '../../core/list/index';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {Object} options
|
|
7
|
-
* @param {string} options.input
|
|
8
|
-
* @param {string} options.content
|
|
9
|
-
* @return {boolean}
|
|
10
|
-
*/
|
|
11
|
-
function containsTextFilter(options) {
|
|
12
|
-
return options.content.trim().toLocaleLowerCase()
|
|
13
|
-
.indexOf(options.input.trim().toLocaleLowerCase()) !== -1;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {Object} options
|
|
18
|
-
* @param {string} options.input
|
|
19
|
-
* @param {string} options.content
|
|
20
|
-
* @return {boolean}
|
|
21
|
-
*/
|
|
22
|
-
function startsWithTextFilter(options) {
|
|
23
|
-
return options.content.trim().toLocaleLowerCase()
|
|
24
|
-
.indexOf(options.input.trim().toLocaleLowerCase()) === 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {HTMLElement} item
|
|
29
|
-
* @return {string}
|
|
30
|
-
*/
|
|
31
|
-
function defaultItemTextParser(item) {
|
|
32
|
-
/**
|
|
33
|
-
* @param {Node} node
|
|
34
|
-
* @return {string}
|
|
35
|
-
*/
|
|
36
|
-
function getTextNodeOnly(node) {
|
|
37
|
-
let text = '';
|
|
38
|
-
for (let i = 0; i < node.childNodes.length; i += 1) {
|
|
39
|
-
const childNode = node.childNodes[i];
|
|
40
|
-
if (childNode.nodeType === Node.TEXT_NODE) {
|
|
41
|
-
text += childNode.textContent;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return text;
|
|
45
|
-
}
|
|
46
|
-
if (item.hasAttribute('data-mdw-search-text')) {
|
|
47
|
-
return item.getAttribute('data-mdw-search-text');
|
|
48
|
-
}
|
|
49
|
-
let textElement = item.querySelector('.mdw-list__text .mdw-list__text-line');
|
|
50
|
-
if (!textElement) {
|
|
51
|
-
textElement = item.querySelector('.mdw-list__text');
|
|
52
|
-
}
|
|
53
|
-
if (!textElement) {
|
|
54
|
-
textElement = item.querySelector('.mdw-list__text');
|
|
55
|
-
}
|
|
56
|
-
if (textElement) {
|
|
57
|
-
return getTextNodeOnly(textElement);
|
|
58
|
-
}
|
|
59
|
-
return getTextNodeOnly(item);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @param {Element} list
|
|
64
|
-
* @param {boolean=} backwards
|
|
65
|
-
* @return {Element} sibling
|
|
66
|
-
*/
|
|
67
|
-
function selectSibling(list, backwards) {
|
|
68
|
-
const current = list.querySelector('.mdw-list__item[selected]');
|
|
69
|
-
const items = list.querySelectorAll('.mdw-list__item:not([hidden]):not([disabled])');
|
|
70
|
-
let sibling;
|
|
71
|
-
if (current && !current.hasAttribute('hidden')) {
|
|
72
|
-
for (let i = 0; i < items.length; i += 1) {
|
|
73
|
-
const item = items[i];
|
|
74
|
-
if (item === current) {
|
|
75
|
-
if (backwards) {
|
|
76
|
-
sibling = items[i - 1];
|
|
77
|
-
} else {
|
|
78
|
-
sibling = items[i + 1];
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
} else if (backwards) {
|
|
84
|
-
sibling = items[items.length - 1];
|
|
85
|
-
} else {
|
|
86
|
-
sibling = items[0];
|
|
87
|
-
}
|
|
88
|
-
if (sibling && sibling !== current) {
|
|
89
|
-
if (current) {
|
|
90
|
-
current.removeAttribute('selected');
|
|
91
|
-
}
|
|
92
|
-
sibling.setAttribute('selected', '');
|
|
93
|
-
return sibling;
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @param {HTMLElement} listItem
|
|
100
|
-
* @return {void}
|
|
101
|
-
*/
|
|
102
|
-
function scrollItemIntoView(listItem) {
|
|
103
|
-
/**
|
|
104
|
-
* @param {HTMLElement} el
|
|
105
|
-
* @return {number}
|
|
106
|
-
*/
|
|
107
|
-
function getElementVisibility(el) {
|
|
108
|
-
let rect = el.getBoundingClientRect();
|
|
109
|
-
const { top, height } = rect;
|
|
110
|
-
let next = el.parentElement;
|
|
111
|
-
do {
|
|
112
|
-
rect = next.getBoundingClientRect();
|
|
113
|
-
if ((top + height) > rect.bottom) {
|
|
114
|
-
// bottom clipped
|
|
115
|
-
return 1;
|
|
116
|
-
}
|
|
117
|
-
if (top < rect.top) {
|
|
118
|
-
// top clipped
|
|
119
|
-
return -1;
|
|
120
|
-
}
|
|
121
|
-
next = next.parentElement;
|
|
122
|
-
} while (next !== document.body);
|
|
123
|
-
if (top < 0) {
|
|
124
|
-
return -1;
|
|
125
|
-
} else if ((top + height) > document.documentElement.clientHeight) {
|
|
126
|
-
return 1;
|
|
127
|
-
}
|
|
128
|
-
return 0;
|
|
129
|
-
}
|
|
130
|
-
const visibility = getElementVisibility(listItem);
|
|
131
|
-
if (visibility < 0) {
|
|
132
|
-
listItem.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
|
|
133
|
-
} else if (visibility > 0) {
|
|
134
|
-
listItem.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class Search {
|
|
139
|
-
/**
|
|
140
|
-
* @param {Object} options
|
|
141
|
-
* @param {TextField} options.textfield
|
|
142
|
-
* @param {List} options.list
|
|
143
|
-
* @param {('contains'|'startsWith'|function({input:string, content:string}):boolean)=} [options.textFilter='contains']
|
|
144
|
-
* @param {(function(HTMLElement):string)=} options.itemTextParser
|
|
145
|
-
* @param {boolean=} [options.dropdown=false]
|
|
146
|
-
* @param {boolean=} [options.filterItems=true]
|
|
147
|
-
* @param {('replace'|'append'|'none')} [options.suggestionMethod='replace']
|
|
148
|
-
* @param {(function(HTMLElement))=} options.onItemActivated
|
|
149
|
-
* @param {(function(string):Promise)=} options.performSearch
|
|
150
|
-
* @param {(function(any):Promise)=} options.updateList
|
|
151
|
-
* @param {boolean=} [options.searchOnFocus=true]
|
|
152
|
-
* @param {number=} options.debounce Debounce time in milliseconds
|
|
153
|
-
*/
|
|
154
|
-
constructor(options) {
|
|
155
|
-
this.textfield = options.textfield;
|
|
156
|
-
this.list = options.list;
|
|
157
|
-
if (typeof options.textFilter === 'function') {
|
|
158
|
-
this.filter = options.textFilter;
|
|
159
|
-
} else if (options.textFilter === 'startsWith') {
|
|
160
|
-
this.filter = startsWithTextFilter;
|
|
161
|
-
} else {
|
|
162
|
-
this.filter = containsTextFilter;
|
|
163
|
-
}
|
|
164
|
-
this.itemTextParser = defaultItemTextParser || options.itemTextParser;
|
|
165
|
-
|
|
166
|
-
this.list.element.addEventListener('click', (event) => {
|
|
167
|
-
this.handleClickEvent(event);
|
|
168
|
-
});
|
|
169
|
-
this.textfield.input.addEventListener('keydown', (event) => {
|
|
170
|
-
this.onTextFieldKeydownEvent(event);
|
|
171
|
-
});
|
|
172
|
-
this.textfield.input.addEventListener('input', (event) => {
|
|
173
|
-
if (this.handleInputEvent) {
|
|
174
|
-
this.handleInputEvent(event);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
this.textfield.input.addEventListener('blur', (event) => {
|
|
178
|
-
if (this.handleBlurEvent) {
|
|
179
|
-
this.handleBlurEvent(event);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
this.textfield.input.addEventListener('focus', (event) => {
|
|
183
|
-
if (this.searchOnFocus) {
|
|
184
|
-
this.handleInputEvent(event);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
this.dropdown = options.dropdown;
|
|
189
|
-
if (options.filterItems !== false) {
|
|
190
|
-
this.filterItems = true;
|
|
191
|
-
}
|
|
192
|
-
if (options.searchOnFocus !== false) {
|
|
193
|
-
this.searchOnFocus = true;
|
|
194
|
-
}
|
|
195
|
-
this.debounce = options.debounce;
|
|
196
|
-
this.suggestionMethod = options.suggestionMethod || 'replace';
|
|
197
|
-
this.currentSearchTerm = this.textfield.input.value || '';
|
|
198
|
-
/** @type {string} */
|
|
199
|
-
this.suggestedInput = null;
|
|
200
|
-
/** @type {string} */
|
|
201
|
-
this.previousValue = null;
|
|
202
|
-
if (options.onItemActivated) {
|
|
203
|
-
this.onItemActivated = options.onItemActivated;
|
|
204
|
-
}
|
|
205
|
-
this.performSearch = options.performSearch || (() => Promise.resolve());
|
|
206
|
-
this.updateList = options.updateList || (() => Promise.resolve());
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @param {MouseEvent} event
|
|
211
|
-
* @return {void}
|
|
212
|
-
*/
|
|
213
|
-
handleClickEvent(event) {
|
|
214
|
-
if (!event.target) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if (!event.target.classList) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (!event.target.classList.contains('mdw-list__item')) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
this.onItemActivated(event.target);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Default input handler
|
|
229
|
-
* @param {Event|InputEvent} event
|
|
230
|
-
* @return {void}
|
|
231
|
-
*/
|
|
232
|
-
handleInputEvent(event) {
|
|
233
|
-
if (document.activeElement !== this.textfield.input) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
this.showDropDown();
|
|
237
|
-
const inputValue = this.textfield.input.value || '';
|
|
238
|
-
if (inputValue === this.suggestedInput) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (inputValue === this.previousValue) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
this.previousValue = inputValue;
|
|
245
|
-
this.currentSearchTerm = inputValue;
|
|
246
|
-
let results = null;
|
|
247
|
-
Promise.resolve()
|
|
248
|
-
.then(() => this.performDebounce(inputValue))
|
|
249
|
-
.then(() => this.checkExpired(inputValue))
|
|
250
|
-
.then(() => this.performSearch(inputValue))
|
|
251
|
-
.then((searchResults) => {
|
|
252
|
-
results = searchResults;
|
|
253
|
-
})
|
|
254
|
-
.then(() => this.checkExpired(inputValue))
|
|
255
|
-
.then(() => this.updateList(results))
|
|
256
|
-
.then(() => this.filterListItems())
|
|
257
|
-
.catch((error) => {
|
|
258
|
-
if (error.message === 'debounced') {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
if (error.message === 'expired') {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
throw error;
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
checkExpired(inputValue) {
|
|
269
|
-
return new Promise((resolve, reject) => {
|
|
270
|
-
if (inputValue === this.currentSearchTerm) {
|
|
271
|
-
resolve();
|
|
272
|
-
} else {
|
|
273
|
-
reject(new Error('expired'));
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @param {string} searchTerm
|
|
280
|
-
* @return {Promise}
|
|
281
|
-
*/
|
|
282
|
-
performDebounce(searchTerm) {
|
|
283
|
-
if (!this.debounce) {
|
|
284
|
-
return Promise.resolve();
|
|
285
|
-
}
|
|
286
|
-
return new Promise((resolve, reject) => {
|
|
287
|
-
setTimeout(() => {
|
|
288
|
-
if (searchTerm !== this.currentSearchTerm) {
|
|
289
|
-
reject(new Error('debounced'));
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
resolve();
|
|
293
|
-
}, this.debounce);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/** @return {boolean} handled */
|
|
298
|
-
showDropDown() {
|
|
299
|
-
if (!this.dropdown) {
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
const dropDownElement = this.textfield.element.querySelector('.mdw-textfield__dropdown');
|
|
303
|
-
let changed = false;
|
|
304
|
-
if (dropDownElement.hasAttribute('mdw-hide')) {
|
|
305
|
-
dropDownElement.removeAttribute('mdw-hide');
|
|
306
|
-
changed = true;
|
|
307
|
-
}
|
|
308
|
-
if (!dropDownElement.hasAttribute('mdw-show')) {
|
|
309
|
-
dropDownElement.setAttribute('mdw-show', '');
|
|
310
|
-
changed = true;
|
|
311
|
-
}
|
|
312
|
-
return changed;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/** @return {boolean} handled */
|
|
316
|
-
isDropDownShown() {
|
|
317
|
-
if (!this.dropdown) {
|
|
318
|
-
return true;
|
|
319
|
-
}
|
|
320
|
-
const dropDownElement = this.textfield.element.querySelector('.mdw-textfield__dropdown');
|
|
321
|
-
if (dropDownElement.hasAttribute('mdw-hide')) {
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
if (this.textfield.input === document.activeElement) {
|
|
325
|
-
return true;
|
|
326
|
-
}
|
|
327
|
-
if (dropDownElement.hasAttribute('mdw-show')) {
|
|
328
|
-
return true;
|
|
329
|
-
}
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/** @return {boolean} handled */
|
|
334
|
-
hideDropDown() {
|
|
335
|
-
if (!this.dropdown) {
|
|
336
|
-
return true;
|
|
337
|
-
}
|
|
338
|
-
const dropDownElement = this.textfield.element.querySelector('.mdw-textfield__dropdown');
|
|
339
|
-
if (!dropDownElement.hasAttribute('mdw-hide')) {
|
|
340
|
-
dropDownElement.setAttribute('mdw-hide', '');
|
|
341
|
-
return true;
|
|
342
|
-
}
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* @param {Event|FocusEvent} event
|
|
348
|
-
* @return {void}
|
|
349
|
-
*/
|
|
350
|
-
handleBlurEvent(event) {
|
|
351
|
-
if (this.dropdown) {
|
|
352
|
-
const dropDownElement = this.textfield.element.querySelector('.mdw-textfield__dropdown');
|
|
353
|
-
if (dropDownElement.hasAttribute('mdw-show')) {
|
|
354
|
-
dropDownElement.removeAttribute('mdw-show');
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* @param {HTMLElement} item
|
|
361
|
-
* @return {void}
|
|
362
|
-
*/
|
|
363
|
-
onItemSelected(item) {
|
|
364
|
-
if (this.suggestionMethod === 'none') {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
let suggestion = this.itemTextParser(item);
|
|
368
|
-
if (suggestion) {
|
|
369
|
-
suggestion = suggestion.trim();
|
|
370
|
-
}
|
|
371
|
-
if (!suggestion) {
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
this.suggestedInput = suggestion;
|
|
375
|
-
if (this.suggestionMethod === 'replace') {
|
|
376
|
-
this.textfield.input.value = suggestion;
|
|
377
|
-
} else if (this.suggestionMethod === 'append') {
|
|
378
|
-
const selectionStart = (this.previousValue || '').length;
|
|
379
|
-
const selectionEnd = suggestion.length;
|
|
380
|
-
this.textfield.input.value = suggestion;
|
|
381
|
-
this.textfield.input.setSelectionRange(selectionStart, selectionEnd);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* @param {HTMLElement} item
|
|
387
|
-
* @return {void}
|
|
388
|
-
*/
|
|
389
|
-
onItemActivated(item) {
|
|
390
|
-
// Override me
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* @param {(function({input:string, content:string}):boolean)=} fnFilter
|
|
395
|
-
* @return {void}
|
|
396
|
-
*/
|
|
397
|
-
filterListItems(fnFilter) {
|
|
398
|
-
if (!this.filterItems) {
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
const input = this.textfield.input.value;
|
|
402
|
-
const current = this.list.element.querySelector('.mdw-list__item[selected]');
|
|
403
|
-
const items = this.list.element.querySelectorAll('.mdw-list__item');
|
|
404
|
-
let hasItem = false;
|
|
405
|
-
for (let i = 0; i < items.length; i += 1) {
|
|
406
|
-
const item = items[i];
|
|
407
|
-
const content = this.itemTextParser(item);
|
|
408
|
-
const fn = fnFilter || this.filter;
|
|
409
|
-
if (fn({ input, content })) {
|
|
410
|
-
hasItem = true;
|
|
411
|
-
item.removeAttribute('hidden');
|
|
412
|
-
} else {
|
|
413
|
-
item.setAttribute('hidden', '');
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
if (current && current.hasAttribute('hidden')) {
|
|
417
|
-
const newSelection = selectSibling(this.list.element);
|
|
418
|
-
if (newSelection) {
|
|
419
|
-
this.onItemSelected(newSelection);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
if (!hasItem) {
|
|
423
|
-
this.hideDropDown();
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* @param {KeyboardEvent} event
|
|
429
|
-
* @return {void}
|
|
430
|
-
*/
|
|
431
|
-
onTextFieldKeydownEvent(event) {
|
|
432
|
-
if (event.defaultPrevented) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
if (event.ctrlKey || event.altKey || event.shiftKey) {
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
switch (event.key) {
|
|
439
|
-
case 'ArrowUp': {
|
|
440
|
-
if (this.isDropDownShown()) {
|
|
441
|
-
const sibling = selectSibling(this.list.element, true);
|
|
442
|
-
if (sibling) {
|
|
443
|
-
scrollItemIntoView(sibling);
|
|
444
|
-
this.onItemSelected(sibling);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
event.stopPropagation();
|
|
448
|
-
event.preventDefault();
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
case 'ArrowDown': {
|
|
452
|
-
if (this.isDropDownShown()) {
|
|
453
|
-
const sibling = selectSibling(this.list.element, false);
|
|
454
|
-
if (sibling) {
|
|
455
|
-
scrollItemIntoView(sibling);
|
|
456
|
-
this.onItemSelected(sibling);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
event.stopPropagation();
|
|
460
|
-
event.preventDefault();
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
case 'Escape': {
|
|
464
|
-
if (this.hideDropDown()) {
|
|
465
|
-
this.suggestedInput = this.previousValue;
|
|
466
|
-
this.textfield.input.value = this.previousValue;
|
|
467
|
-
event.stopPropagation();
|
|
468
|
-
event.preventDefault();
|
|
469
|
-
}
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
case 'Enter': {
|
|
473
|
-
const current = this.list.element.querySelector('.mdw-list__item[selected]');
|
|
474
|
-
if (current) {
|
|
475
|
-
if (this.hideDropDown()) {
|
|
476
|
-
const inputValue = this.textfield.input.value || '';
|
|
477
|
-
this.textfield.input.setSelectionRange(inputValue.length, inputValue.length);
|
|
478
|
-
this.onItemActivated(current);
|
|
479
|
-
event.stopPropagation();
|
|
480
|
-
event.preventDefault();
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
default:
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
export {
|
|
491
|
-
Search,
|
|
492
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Syntax
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
## Fixed (Primary Color)
|
|
5
|
-
|
|
6
|
-
```
|
|
7
|
-
form.mdw-bottomnav(mdw-theme-color="primary")
|
|
8
|
-
label.mdw-button.mdw-bottomnav__item
|
|
9
|
-
input(type="radio" name="bottomnav" value="recents")
|
|
10
|
-
.mdw-bottomnav__icon.material-icons history
|
|
11
|
-
.mdw-bottomnav__label Recents
|
|
12
|
-
label.mdw-button.mdw-bottomnav__item
|
|
13
|
-
input(type="radio" name="bottomnav" value="favorites" checked)
|
|
14
|
-
.mdw-bottomnav__icon.material-icons favorite
|
|
15
|
-
.mdw-bottomnav__label Favorites
|
|
16
|
-
label.mdw-button.mdw-bottomnav__item
|
|
17
|
-
input(type="radio" name="bottomnav" value="nearby")
|
|
18
|
-
.mdw-bottomnav__icon.material-icons near_me
|
|
19
|
-
.mdw-bottomnav__label Nearby
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Fixed (Filled)
|
|
23
|
-
```
|
|
24
|
-
form.mdw-bottomnav(mdw-theme-fill="primary-700")
|
|
25
|
-
label.mdw-button.mdw-bottomnav__item
|
|
26
|
-
input(type="radio" name="bottomnav" value="recents")
|
|
27
|
-
.mdw-bottomnav__icon.material-icons history
|
|
28
|
-
.mdw-bottomnav__label Recents
|
|
29
|
-
label.mdw-button.mdw-bottomnav__item
|
|
30
|
-
input(type="radio" name="bottomnav" value="favorites" checked)
|
|
31
|
-
.mdw-bottomnav__icon.material-icons favorite
|
|
32
|
-
.mdw-bottomnav__label Favorites
|
|
33
|
-
label.mdw-button.mdw-bottomnav__item
|
|
34
|
-
input(type="radio" name="bottomnav" value="nearby")
|
|
35
|
-
.mdw-bottomnav__icon.material-icons near_me
|
|
36
|
-
.mdw-bottomnav__label Nearby
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Shifting (Primary Color)
|
|
40
|
-
```
|
|
41
|
-
form.mdw-bottomnav(mdw-theme-color="primary" mdw-shifting)
|
|
42
|
-
input(type="radio" name="shiftingbottomnav" value="movies" id='value1')
|
|
43
|
-
label.mdw-button.mdw-bottomnav__item(for='value1')
|
|
44
|
-
.mdw-bottomnav__icon.material-icons tv
|
|
45
|
-
.mdw-bottomnav__label Movies & TV
|
|
46
|
-
input(type="radio" name="shiftingbottomnav" value="music" id='value2' checked )
|
|
47
|
-
label.mdw-button.mdw-bottomnav__item(for='value2')
|
|
48
|
-
.mdw-bottomnav__icon.material-icons music_note
|
|
49
|
-
.mdw-bottomnav__label Music
|
|
50
|
-
input(type="radio" name="shiftingbottomnav" value="books" id='value3')
|
|
51
|
-
label.mdw-button.mdw-bottomnav__item(for='value3')
|
|
52
|
-
.mdw-bottomnav__icon.material-icons book
|
|
53
|
-
.mdw-bottomnav__label Books
|
|
54
|
-
input(type="radio" name="shiftingbottomnav" value="newsstand" id='value4')
|
|
55
|
-
label.mdw-button.mdw-bottomnav__item(for='value4')
|
|
56
|
-
.mdw-bottomnav__icon.material-icons assignment
|
|
57
|
-
.mdw-bottomnav__label Newsstand
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Shifting (Filled)
|
|
61
|
-
```
|
|
62
|
-
form.mdw-bottomnav(mdw-theme-fill="primary-700" mdw-shifting)
|
|
63
|
-
input(type="radio" name="shiftingbottomnav" value="movies" id='value1')
|
|
64
|
-
label.mdw-button.mdw-bottomnav__item(for='value1')
|
|
65
|
-
.mdw-bottomnav__icon.material-icons tv
|
|
66
|
-
.mdw-bottomnav__label Movies & TV
|
|
67
|
-
input(type="radio" name="shiftingbottomnav" value="music" id='value2' checked )
|
|
68
|
-
label.mdw-button.mdw-bottomnav__item(for='value2')
|
|
69
|
-
.mdw-bottomnav__icon.material-icons music_note
|
|
70
|
-
.mdw-bottomnav__label Music
|
|
71
|
-
input(type="radio" name="shiftingbottomnav" value="books" id='value3')
|
|
72
|
-
label.mdw-button.mdw-bottomnav__item(for='value3')
|
|
73
|
-
.mdw-bottomnav__icon.material-icons book
|
|
74
|
-
.mdw-bottomnav__label Books
|
|
75
|
-
input(type="radio" name="shiftingbottomnav" value="newsstand" id='value4')
|
|
76
|
-
label.mdw-button.mdw-bottomnav__item(for='value4')
|
|
77
|
-
.mdw-bottomnav__icon.material-icons assignment
|
|
78
|
-
.mdw-bottomnav__label Newsstand
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
# Notes
|
|
82
|
-
|
|
83
|
-
Shifting items requires use of `input` elements *immediately* preceeding its corresponding the `.mdw-bottomnav__item` element.
|
|
84
|
-
|
|
85
|
-
See `.mdw-button` documentation for more information regardling ripple origins.
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
class BottomnavItem {
|
|
2
|
-
/**
|
|
3
|
-
* @param {Element} element
|
|
4
|
-
*/
|
|
5
|
-
constructor(element) {
|
|
6
|
-
this.element = element;
|
|
7
|
-
const rippleElements = element.getElementsByClassName('mdw-ripple');
|
|
8
|
-
this.ripple = rippleElements && rippleElements[0];
|
|
9
|
-
if (!this.ripple) {
|
|
10
|
-
const ripple = document.createElement('div');
|
|
11
|
-
ripple.classList.add('mdw-ripple');
|
|
12
|
-
this.element.insertBefore(ripple, this.element.firstChild);
|
|
13
|
-
this.ripple = ripple;
|
|
14
|
-
}
|
|
15
|
-
const innerRippleElements = this.ripple.getElementsByClassName('mdw-ripple__inner');
|
|
16
|
-
this.rippleInner = innerRippleElements && innerRippleElements[0];
|
|
17
|
-
if (!this.rippleInner) {
|
|
18
|
-
const rippleInner = document.createElement('div');
|
|
19
|
-
rippleInner.classList.add('mdw-ripple__inner');
|
|
20
|
-
this.ripple.appendChild(rippleInner);
|
|
21
|
-
this.rippleInner = rippleInner;
|
|
22
|
-
}
|
|
23
|
-
this.element.setAttribute('mdw-ripple', '');
|
|
24
|
-
this.element.addEventListener('click', (event) => {
|
|
25
|
-
this.updateRipplePosition(event);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @param {MouseEvent|PointerEvent} event
|
|
31
|
-
* @return {void}
|
|
32
|
-
*/
|
|
33
|
-
updateRipplePosition(event) {
|
|
34
|
-
if (event.target !== this.element && event.target !== this.ripple) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (!event.pointerType && !event.detail) {
|
|
38
|
-
// Ripple from center
|
|
39
|
-
this.rippleInner.style.removeProperty('left');
|
|
40
|
-
this.rippleInner.style.removeProperty('top');
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const x = event.offsetX;
|
|
44
|
-
const y = event.offsetY;
|
|
45
|
-
this.rippleInner.style.setProperty('left', `${x}px`);
|
|
46
|
-
this.rippleInner.style.setProperty('top', `${y}px`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class Bottomnav {
|
|
51
|
-
/**
|
|
52
|
-
* @param {Element} element
|
|
53
|
-
*/
|
|
54
|
-
constructor(element) {
|
|
55
|
-
this.element = element;
|
|
56
|
-
this.items = this.element.getElementsByClassName('mdw-bottomnav__item');
|
|
57
|
-
this.inputs = this.element.getElementsByTagName('input');
|
|
58
|
-
|
|
59
|
-
for (let i = 0; i < this.items.length; i += 1) {
|
|
60
|
-
const item = this.items.item(i);
|
|
61
|
-
item.addEventListener('click', () => {
|
|
62
|
-
this.onItemClicked(item);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
66
|
-
const input = this.inputs.item(i);
|
|
67
|
-
input.addEventListener('change', () => {
|
|
68
|
-
this.onInputChanged(input);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @param {HTMLInputElement} inputElement
|
|
75
|
-
* @return {void}
|
|
76
|
-
*/
|
|
77
|
-
onInputChanged(inputElement) {
|
|
78
|
-
let itemElement;
|
|
79
|
-
if (inputElement.parentElement.classList.contains('mdw-bottomnav__item')) {
|
|
80
|
-
itemElement = inputElement.parentElement;
|
|
81
|
-
}
|
|
82
|
-
if (inputElement.id) {
|
|
83
|
-
itemElement = document.querySelector(`label.mdw-bottomnav__item[for="${inputElement.id}"]`);
|
|
84
|
-
}
|
|
85
|
-
if (itemElement.hasAttribute('selected') && inputElement.checked) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (!itemElement.hasAttribute('selected') && !inputElement.checked) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this.removeSelection();
|
|
92
|
-
itemElement.setAttribute('selected', '');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** @return {boolean} change */
|
|
96
|
-
removeSelection() {
|
|
97
|
-
for (let i = 0; i < this.items.length; i += 1) {
|
|
98
|
-
const item = this.items.item(i);
|
|
99
|
-
if (item.hasAttribute('selected')) {
|
|
100
|
-
item.removeAttribute('selected');
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @param {Element} itemElement
|
|
109
|
-
* @return {void}
|
|
110
|
-
*/
|
|
111
|
-
onItemClicked(itemElement) {
|
|
112
|
-
if (itemElement.hasAttribute('selected')) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (itemElement.hasAttribute('disabled')) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
this.removeSelection();
|
|
119
|
-
itemElement.setAttribute('selected', '');
|
|
120
|
-
let inputElement;
|
|
121
|
-
if (itemElement instanceof HTMLLabelElement && itemElement.hasAttribute('for')) {
|
|
122
|
-
const id = itemElement.getAttribute('for');
|
|
123
|
-
if (id) {
|
|
124
|
-
inputElement = document.getElementById(id);
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
[inputElement] = itemElement.getElementsByTagName('input');
|
|
128
|
-
}
|
|
129
|
-
if (inputElement instanceof HTMLInputElement) {
|
|
130
|
-
inputElement.checked = true;
|
|
131
|
-
} else if (inputElement) {
|
|
132
|
-
throw new Error('Unexpected inputElement type');
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export {
|
|
138
|
-
Bottomnav,
|
|
139
|
-
BottomnavItem,
|
|
140
|
-
};
|