@shortfuse/materialdesignweb 0.2.0 → 0.5.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 +2 -1
- package/.eslintrc.json +188 -30
- package/.stylelintrc.json +643 -2
- package/.vscode/launch.json +20 -5
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +36 -0
- package/README.md +82 -2
- package/adapters/datatable/column.js +176 -0
- package/adapters/datatable/index.js +253 -437
- package/adapters/dom/index.js +586 -0
- package/adapters/list/index.js +36 -113
- package/adapters/search/index.js +153 -180
- package/components/appbar/_spec.scss +165 -0
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +2 -0
- package/components/banner/_spec.scss +83 -0
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +2 -0
- package/components/bottomnav/README.md +4 -4
- package/components/bottomnav/_spec.scss +149 -0
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +100 -120
- package/components/bottomnav/index.scss +2 -0
- package/components/bottomnav/item.js +88 -0
- package/components/button/README.md +16 -22
- package/components/button/_spec.scss +162 -0
- package/components/button/_theme.scss +42 -0
- package/components/button/index.eta +32 -0
- package/components/button/index.js +37 -48
- package/components/button/index.pug +18 -0
- package/components/button/index.scss +2 -0
- package/components/card/_spec.scss +241 -0
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +2 -0
- package/components/chip/_spec.scss +111 -0
- package/components/chip/_theme.scss +105 -0
- package/components/chip/index.js +23 -0
- package/components/chip/index.scss +2 -0
- package/components/chip/item.js +20 -0
- package/components/datatable/_spec.scss +225 -0
- package/components/datatable/_theme.scss +128 -0
- package/components/datatable/cell.js +44 -0
- package/components/datatable/columnheader.js +46 -0
- package/components/datatable/index.js +339 -443
- package/components/datatable/index.scss +2 -0
- package/components/datatable/row.js +48 -0
- package/components/datatable/rowheader.js +18 -0
- package/components/dialog/_spec.scss +203 -0
- package/components/dialog/_theme.scss +7 -0
- package/components/dialog/index.js +512 -437
- package/components/dialog/index.scss +2 -0
- package/components/divider/_spec.scss +11 -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/{style.scss → _spec.scss} +104 -79
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +85 -79
- package/components/fab/index.scss +2 -0
- package/components/grid/_spec.scss +169 -0
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +2 -0
- package/components/layout/_mixins.scss +11 -0
- package/components/layout/_spec.scss +916 -0
- package/components/layout/_theme.scss +19 -0
- package/components/layout/index.js +454 -0
- package/components/layout/index.scss +2 -0
- package/components/list/_spec.scss +363 -0
- package/components/list/_theme.scss +102 -0
- package/components/list/content.js +106 -0
- package/components/list/index.js +234 -79
- package/components/list/index.scss +2 -0
- package/components/list/item.js +167 -0
- package/components/list/secondary.js +45 -0
- package/components/menu/_spec.scss +329 -0
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +636 -651
- package/components/menu/index.scss +2 -0
- package/components/menu/item.js +231 -0
- package/components/progress/_spec.scss +156 -0
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +29 -13
- package/components/progress/index.scss +2 -0
- package/components/selection/_spec.scss +376 -0
- package/components/selection/_theme.scss +134 -0
- package/components/selection/index.eta +60 -0
- package/components/selection/index.js +70 -0
- package/components/selection/index.pug +30 -0
- package/components/selection/index.scss +2 -0
- package/components/selection/input.js +54 -0
- package/components/selection/radiogroup.js +40 -0
- package/components/slider/{style.scss → _spec.scss} +31 -34
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +2 -0
- package/components/snackbar/_spec.scss +150 -0
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +293 -206
- package/components/snackbar/index.scss +2 -0
- package/components/tab/_spec.scss +220 -0
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +210 -0
- package/components/tab/index.js +229 -213
- package/components/tab/index.scss +2 -0
- package/components/tab/item.js +88 -0
- package/components/tab/list.js +196 -0
- package/components/tab/panel.js +54 -0
- package/components/textfield/README.md +4 -4
- package/components/textfield/_spec.scss +763 -0
- package/components/textfield/_theme.scss +264 -0
- package/components/textfield/index.eta +74 -0
- package/components/textfield/index.js +132 -138
- package/components/textfield/index.pug +30 -0
- package/components/textfield/index.scss +2 -0
- package/components/tooltip/_spec.scss +185 -0
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +2 -0
- package/components/type/_spec.scss +227 -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 +78 -0
- package/core/_length.scss +8 -0
- package/core/_motion.scss +31 -0
- package/core/_platform.scss +12 -0
- package/core/_type.scss +128 -0
- package/core/aria/attributes.js +141 -0
- package/core/aria/button.js +49 -0
- package/core/aria/keyboard.js +92 -0
- package/core/aria/rovingtabindex.js +175 -0
- package/core/aria/tab.js +59 -0
- package/core/document/index.js +39 -0
- package/core/dom.js +180 -0
- package/core/overlay/_spec.scss +28 -0
- package/core/overlay/_theme.scss +147 -0
- package/core/overlay/index.js +95 -0
- package/core/overlay/index.scss +2 -0
- package/core/ripple/_spec.scss +196 -0
- package/core/ripple/_theme.scss +20 -0
- package/core/ripple/index.js +286 -0
- package/core/ripple/index.scss +2 -0
- package/core/theme/_aliases.scss +15 -0
- package/core/theme/_config.scss +8 -0
- package/core/theme/_functions.scss +22 -0
- package/{components/theming/palettes.scss → core/theme/_palettes.scss} +173 -151
- package/core/theme/_spec.scss +0 -0
- package/core/theme/_theme.scss +268 -0
- package/core/theme/index.js +50 -0
- package/core/theme/index.scss +4 -0
- package/core/throttler.js +42 -0
- package/core/transition/index.js +465 -0
- package/docs/_flex.scss +28 -0
- package/docs/_menuoptions.js +183 -0
- package/docs/_partials/_androidnavbar.eta +5 -0
- package/docs/_partials/_androidstatusbar.eta +13 -0
- package/docs/_partials/_appbar.eta +27 -0
- package/docs/_partials/_buttontest.eta +31 -0
- package/docs/_partials/_header.eta +146 -0
- package/docs/_partials/_navlistitem.eta +16 -0
- package/docs/_partials/_target.eta +1 -0
- package/docs/_sample-utils.js +88 -0
- package/docs/{src/storage.js → _storage.js} +0 -0
- package/docs/docs.scss +331 -0
- package/docs/framework.scss +26 -0
- package/docs/index.eta +12 -0
- package/docs/index.js +7 -0
- package/docs/pages/appbar.eta +108 -0
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/bottomnav.eta +188 -0
- package/docs/pages/bottomnav.js +118 -0
- package/docs/pages/button.eta +124 -0
- package/docs/pages/button.js +224 -0
- package/docs/pages/card.eta +90 -0
- package/docs/pages/card.js +175 -0
- package/docs/pages/chip.eta +122 -0
- package/docs/pages/chip.js +80 -0
- package/docs/pages/color.eta +143 -0
- package/docs/pages/color.js +261 -0
- package/docs/pages/datatable.eta +323 -0
- package/docs/pages/datatable.js +160 -0
- package/docs/pages/dialog.eta +184 -0
- package/docs/{src/components → pages}/dialog.js +35 -48
- package/docs/pages/dom.eta +26 -0
- package/docs/pages/dom.js +140 -0
- package/docs/pages/elevation.eta +35 -0
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/fab.eta +99 -0
- package/docs/{src/components → pages}/fab.js +6 -13
- package/docs/pages/grid.eta +135 -0
- package/docs/pages/grid.js +128 -0
- package/docs/pages/layout.eta +8 -0
- package/docs/pages/layout.js +0 -0
- package/docs/pages/list.eta +465 -0
- package/docs/pages/list.js +8 -0
- package/docs/pages/menu.eta +274 -0
- package/docs/{src/components → pages}/menu.js +26 -42
- package/docs/pages/overlay.eta +69 -0
- package/docs/pages/overlay.js +3 -0
- package/docs/pages/progress.eta +23 -0
- package/docs/{src/components → pages}/progress.js +2 -4
- package/docs/pages/ripple.eta +27 -0
- package/docs/pages/ripple.js +3 -0
- package/docs/pages/search.eta +242 -0
- package/docs/pages/search.js +226 -0
- package/docs/pages/selection.eta +107 -0
- package/docs/pages/selection.js +12 -0
- package/docs/pages/slider.eta +23 -0
- package/docs/pages/slider.js +0 -0
- package/docs/pages/snackbar.eta +83 -0
- package/docs/{src/components → pages}/snackbar.js +31 -36
- package/docs/pages/tab.eta +407 -0
- package/docs/pages/tab.js +152 -0
- package/docs/pages/textfield.eta +487 -0
- package/docs/{src/components → pages}/textfield.js +41 -45
- package/docs/pages/tooltip.eta +92 -0
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/transition.eta +117 -0
- package/docs/pages/transition.js +52 -0
- package/docs/pages/type.eta +31 -0
- package/docs/pages/type.js +0 -0
- package/docs/postrender.js +41 -0
- package/docs/prerender.js +16 -0
- package/docs/pwa/_dialogs.eta +143 -0
- package/docs/pwa/_menus.eta +16 -0
- package/docs/pwa/pwa-prerender.js +3 -0
- package/docs/pwa/pwa.eta +478 -0
- package/docs/pwa/pwa.js +298 -0
- package/docs/pwa/pwa.scss +31 -0
- package/docs/themes/theme-colored.scss +15 -0
- package/docs/themes/theme-default.scss +3 -0
- package/index.scss +27 -0
- package/jsconfig.json +8 -2
- package/package.json +54 -27
- package/scripts/deploy-docs.sh +9 -0
- package/templates/index.eta +2 -0
- package/templates/index.pug +3 -0
- package/tsconfig.json +16 -0
- package/utils/function.js +3 -0
- package/webpack.config.js +224 -68
- package/_index.scss +0 -4
- package/components/all-components.scss +0 -21
- package/components/bottomnav/style.scss +0 -190
- package/components/bottomnav/theming.scss +0 -76
- package/components/button/style.scss +0 -315
- package/components/button/theming.scss +0 -134
- package/components/card/style.scss +0 -175
- package/components/card/theming.scss +0 -43
- package/components/common/dom.js +0 -51
- package/components/common/functions.scss +0 -174
- package/components/common/mixins.scss +0 -122
- package/components/common/motion.scss +0 -36
- package/components/common/type.scss +0 -104
- package/components/common/variables.scss +0 -46
- package/components/datatable/style.scss +0 -257
- package/components/datatable/theming.scss +0 -119
- package/components/dialog/style.scss +0 -159
- package/components/dialog/theming.scss +0 -29
- package/components/divider/style.scss +0 -7
- package/components/divider/theming.scss +0 -20
- package/components/elevation/style.scss +0 -32
- package/components/layout/style.scss +0 -223
- package/components/list/style.scss +0 -358
- package/components/list/theming.scss +0 -83
- package/components/menu/style.scss +0 -280
- package/components/menu/theming.scss +0 -80
- package/components/navdrawer/index.js +0 -200
- package/components/navdrawer/style.scss +0 -595
- package/components/navdrawer/theming.scss +0 -62
- package/components/progress/style.scss +0 -136
- package/components/ripple/index.js +0 -63
- package/components/ripple/ripple.scss +0 -122
- package/components/selection/style.scss +0 -320
- package/components/selection/theming.scss +0 -98
- package/components/snackbar/style.scss +0 -212
- package/components/switch/style.scss +0 -3
- package/components/tab/style.scss +0 -275
- package/components/tab/theming.scss +0 -34
- package/components/template/theming.scss +0 -31
- package/components/textfield/style.scss +0 -795
- package/components/textfield/theming.scss +0 -256
- package/components/theming/globals.scss +0 -25
- package/components/theming/theming.scss +0 -559
- package/components/toolbar/style.scss +0 -190
- package/components/toolbar/theming.scss +0 -32
- package/components/tooltip/style.scss +0 -135
- package/components/type/style.scss +0 -167
- package/components/type/theming.scss +0 -25
- package/docs/bottomnav.html +0 -1
- package/docs/bottomnav.min.js +0 -2
- package/docs/bottomnav.min.js.map +0 -1
- package/docs/button.html +0 -1
- package/docs/button.min.js +0 -2
- package/docs/button.min.js.map +0 -1
- package/docs/card.html +0 -1
- package/docs/card.min.js +0 -2
- package/docs/card.min.js.map +0 -1
- package/docs/components.min.css +0 -1
- package/docs/components.min.js +0 -2
- package/docs/components.min.js.map +0 -1
- package/docs/datatable.html +0 -1
- package/docs/datatable.min.js +0 -2
- package/docs/datatable.min.js.map +0 -1
- package/docs/dialog.html +0 -1
- package/docs/dialog.min.js +0 -2
- package/docs/dialog.min.js.map +0 -1
- package/docs/docs.min.css +0 -1
- package/docs/docs.min.js +0 -2
- package/docs/docs.min.js.map +0 -1
- package/docs/elevation.html +0 -1
- package/docs/elevation.min.js +0 -2
- package/docs/elevation.min.js.map +0 -1
- package/docs/fab.html +0 -1
- package/docs/fab.min.js +0 -2
- package/docs/fab.min.js.map +0 -1
- package/docs/index.html +0 -1
- package/docs/index.min.js +0 -2
- package/docs/index.min.js.map +0 -1
- package/docs/layout.html +0 -1
- package/docs/layout.min.js +0 -2
- package/docs/layout.min.js.map +0 -1
- package/docs/list.html +0 -1
- package/docs/list.min.js +0 -2
- package/docs/list.min.js.map +0 -1
- package/docs/menu.html +0 -1
- package/docs/menu.min.js +0 -2
- package/docs/menu.min.js.map +0 -1
- package/docs/navdrawer.html +0 -1
- package/docs/navdrawer.min.js +0 -2
- package/docs/navdrawer.min.js.map +0 -1
- package/docs/prerender.min.js +0 -2
- package/docs/prerender.min.js.map +0 -1
- package/docs/progress.html +0 -1
- package/docs/progress.min.js +0 -2
- package/docs/progress.min.js.map +0 -1
- package/docs/search.html +0 -1
- package/docs/search.min.js +0 -2
- package/docs/search.min.js.map +0 -1
- package/docs/selection.html +0 -1
- package/docs/selection.min.js +0 -2
- package/docs/selection.min.js.map +0 -1
- package/docs/slider.html +0 -1
- package/docs/slider.min.js +0 -2
- package/docs/slider.min.js.map +0 -1
- package/docs/snackbar.html +0 -1
- package/docs/snackbar.min.js +0 -2
- package/docs/snackbar.min.js.map +0 -1
- package/docs/src/components/bottomnav.js +0 -16
- package/docs/src/components/bottomnav.pug +0 -112
- package/docs/src/components/button.js +0 -156
- package/docs/src/components/button.pug +0 -194
- package/docs/src/components/card.js +0 -136
- package/docs/src/components/card.pug +0 -133
- package/docs/src/components/datatable.js +0 -183
- package/docs/src/components/datatable.pug +0 -324
- package/docs/src/components/dialog.pug +0 -138
- package/docs/src/components/elevation.js +0 -3
- package/docs/src/components/elevation.pug +0 -17
- package/docs/src/components/fab.pug +0 -84
- package/docs/src/components/layout.js +0 -116
- package/docs/src/components/layout.pug +0 -104
- package/docs/src/components/list.js +0 -15
- package/docs/src/components/list.pug +0 -293
- package/docs/src/components/menu.pug +0 -292
- package/docs/src/components/navdrawer.js +0 -112
- package/docs/src/components/navdrawer.pug +0 -113
- package/docs/src/components/progress.pug +0 -17
- package/docs/src/components/search.js +0 -206
- package/docs/src/components/search.pug +0 -149
- package/docs/src/components/selection.js +0 -6
- package/docs/src/components/selection.pug +0 -116
- package/docs/src/components/slider.js +0 -3
- package/docs/src/components/slider.pug +0 -19
- package/docs/src/components/snackbar.pug +0 -145
- package/docs/src/components/tab.js +0 -137
- package/docs/src/components/tab.pug +0 -329
- package/docs/src/components/textfield.pug +0 -416
- package/docs/src/components/toolbar.js +0 -6
- package/docs/src/components/toolbar.pug +0 -86
- package/docs/src/components/tooltip.js +0 -6
- package/docs/src/components/tooltip.pug +0 -76
- package/docs/src/components/type.js +0 -6
- package/docs/src/components/type.pug +0 -34
- package/docs/src/components.scss +0 -1
- package/docs/src/docs.scss +0 -284
- package/docs/src/index.js +0 -3
- package/docs/src/index.pug +0 -6
- package/docs/src/menuoptions.js +0 -136
- package/docs/src/mixins.pug +0 -139
- package/docs/src/prerender.js +0 -26
- package/docs/src/sample-utils.js +0 -108
- package/docs/src/targetHandler.js +0 -50
- package/docs/src/theming.ie11.scss +0 -18
- package/docs/src/theming.scss +0 -18
- package/docs/tab.html +0 -1
- package/docs/tab.min.js +0 -2
- package/docs/tab.min.js.map +0 -1
- package/docs/textfield.html +0 -2
- package/docs/textfield.min.js +0 -2
- package/docs/textfield.min.js.map +0 -1
- package/docs/theming.ie11.min.css +0 -1
- package/docs/theming.ie11.min.js +0 -2
- package/docs/theming.ie11.min.js.map +0 -1
- package/docs/theming.min.css +0 -1
- package/docs/theming.min.js +0 -2
- package/docs/theming.min.js.map +0 -1
- package/docs/toolbar.html +0 -1
- package/docs/toolbar.min.js +0 -2
- package/docs/toolbar.min.js.map +0 -1
- package/docs/tooltip.html +0 -1
- package/docs/tooltip.min.js +0 -2
- package/docs/tooltip.min.js.map +0 -1
- package/docs/type.html +0 -1
- package/docs/type.min.js +0 -2
- package/docs/type.min.js.map +0 -1
- package/index.js +0 -16
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// https://www.w3.org/TR/wai-aria-practices/#menu
|
|
2
|
+
|
|
3
|
+
import * as Attributes from '../../core/aria/attributes.js';
|
|
4
|
+
import {
|
|
5
|
+
dispatchDomEvent,
|
|
6
|
+
iterateElementSiblings,
|
|
7
|
+
} from '../../core/dom.js';
|
|
8
|
+
import * as Overlay from '../../core/overlay/index.js';
|
|
9
|
+
import * as Ripple from '../../core/ripple/index.js';
|
|
10
|
+
|
|
11
|
+
export const ACTIVATE_EVENT = 'mdw:menuitem-activate';
|
|
12
|
+
export const CHECK_EVENT = 'mdw:menuitem-check';
|
|
13
|
+
export const UNCHECK_EVENT = 'mdw:menuitem-uncheck';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {Element} element
|
|
17
|
+
* @return {void}
|
|
18
|
+
*/
|
|
19
|
+
export function setupARIA(element) {
|
|
20
|
+
if (element.hasAttribute('mdw-no-aria')) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const role = element.getAttribute('role');
|
|
24
|
+
let useAriaChecked = false;
|
|
25
|
+
if (role === 'menuitemcheckbox' || role === 'menuitemradio') {
|
|
26
|
+
useAriaChecked = true;
|
|
27
|
+
} else if (role !== 'menuitem') {
|
|
28
|
+
if (element.getElementsByClassName('mdw-menu__check').length) {
|
|
29
|
+
useAriaChecked = true;
|
|
30
|
+
element.setAttribute('role', 'menuitemcheckbox');
|
|
31
|
+
} else if (element.getElementsByClassName('mdw-menu__radio').length) {
|
|
32
|
+
useAriaChecked = true;
|
|
33
|
+
element.setAttribute('role', 'menuitemradio');
|
|
34
|
+
} else {
|
|
35
|
+
element.setAttribute('role', 'menuitem');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (useAriaChecked && !element.hasAttribute('aria-checked')) {
|
|
39
|
+
element.setAttribute('aria-checked', 'false');
|
|
40
|
+
}
|
|
41
|
+
for (const el of element.getElementsByClassName('mdw-menu__icon')) el.setAttribute('aria-hidden', 'true');
|
|
42
|
+
for (const el of element.getElementsByClassName('mdw-menu__text')) el.setAttribute('role', 'text');
|
|
43
|
+
for (const el of element.getElementsByClassName('mdw-menu__check')) el.setAttribute('aria-hidden', 'true');
|
|
44
|
+
for (const el of element.getElementsByClassName('mdw-menu__info')) el.setAttribute('role', 'note');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {MouseEvent} event
|
|
49
|
+
* @return {void}
|
|
50
|
+
*/
|
|
51
|
+
export function onMouseMove(event) {
|
|
52
|
+
const el = /** @type {HTMLElement} */ (event.currentTarget);
|
|
53
|
+
if (!el) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const previousFocus = document.activeElement;
|
|
57
|
+
if (previousFocus === el) {
|
|
58
|
+
// Already focused
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (el.getAttribute('aria-disabled') === 'true') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
el.focus();
|
|
65
|
+
if (document.activeElement !== el
|
|
66
|
+
&& document.activeElement !== previousFocus
|
|
67
|
+
&& previousFocus instanceof HTMLElement) {
|
|
68
|
+
previousFocus.focus();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {Element} element
|
|
74
|
+
* @param {boolean} checked
|
|
75
|
+
* @return {boolean} uiChanged
|
|
76
|
+
*/
|
|
77
|
+
export function setChecked(element, checked) {
|
|
78
|
+
const role = element.getAttribute('role');
|
|
79
|
+
let isCheckable = false;
|
|
80
|
+
if (role === 'menuitemcheckbox') {
|
|
81
|
+
isCheckable = true;
|
|
82
|
+
if (!dispatchDomEvent(element, checked ? CHECK_EVENT : UNCHECK_EVENT)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (role === 'menuitemradio') {
|
|
87
|
+
isCheckable = true;
|
|
88
|
+
if (checked) {
|
|
89
|
+
if (!dispatchDomEvent(element, CHECK_EVENT)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
iterateElementSiblings(element, (sibling) => {
|
|
93
|
+
if (sibling.getAttribute('role') === 'menuitemradio') {
|
|
94
|
+
sibling.setAttribute('aria-checked', 'false');
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!isCheckable) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
element.setAttribute('aria-checked', checked ? 'true' : 'false');
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {Element} element
|
|
108
|
+
* @return {boolean}
|
|
109
|
+
*/
|
|
110
|
+
export function toggleChecked(element) {
|
|
111
|
+
const checked = !Attributes.isChecked(element);
|
|
112
|
+
return setChecked(element, checked);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {Element} element
|
|
117
|
+
* @return {boolean} handled
|
|
118
|
+
*/
|
|
119
|
+
export function openSubMenu(element) {
|
|
120
|
+
const hasPopup = element.getAttribute('aria-haspopup');
|
|
121
|
+
if (hasPopup !== 'menu' && hasPopup !== 'true') {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// TODO: Open new menu
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {MouseEvent|KeyboardEvent|PointerEvent} event
|
|
131
|
+
* @return {void}
|
|
132
|
+
*/
|
|
133
|
+
export function onClick(event) {
|
|
134
|
+
event.stopPropagation();
|
|
135
|
+
|
|
136
|
+
const menuItemElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
137
|
+
if (Attributes.isDisabled(menuItemElement)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const role = menuItemElement.getAttribute('role');
|
|
141
|
+
if (role === 'menuitemcheckbox') {
|
|
142
|
+
toggleChecked(menuItemElement);
|
|
143
|
+
} else if (role === 'menuitemradio') {
|
|
144
|
+
setChecked(menuItemElement, true);
|
|
145
|
+
}
|
|
146
|
+
dispatchDomEvent(menuItemElement, ACTIVATE_EVENT);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @param {KeyboardEvent} event
|
|
151
|
+
* @return {void}
|
|
152
|
+
*/
|
|
153
|
+
export function onKeyDown(event) {
|
|
154
|
+
const menuItemElement = /** @type {HTMLElement} */ (event.currentTarget);
|
|
155
|
+
|
|
156
|
+
if (event.key === 'Enter') {
|
|
157
|
+
event.stopPropagation();
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
if (Attributes.isDisabled(menuItemElement)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
onClick(event);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (event.key === 'Spacebar' || (event.key === ' ')) {
|
|
167
|
+
event.stopPropagation();
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
if (Attributes.isDisabled(menuItemElement)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const role = menuItemElement.getAttribute('role');
|
|
173
|
+
if (role === 'menuitemcheckbox') {
|
|
174
|
+
toggleChecked(menuItemElement);
|
|
175
|
+
} else if (role === 'menuitemradio') {
|
|
176
|
+
setChecked(menuItemElement, true);
|
|
177
|
+
} else {
|
|
178
|
+
dispatchDomEvent(menuItemElement, ACTIVATE_EVENT);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {Element} element
|
|
185
|
+
* @return {void}
|
|
186
|
+
*/
|
|
187
|
+
export function attachCore(element) {
|
|
188
|
+
// If mouseover is used, an item can still lose focus via keyboard navigation.
|
|
189
|
+
// An extra event listener would need to be created to catch blur but the cursor
|
|
190
|
+
// would still remain over the element, thus needing another mousemove event.
|
|
191
|
+
// Prioritization is given to less event listeners rather than operations per second.
|
|
192
|
+
element.addEventListener('mousemove', onMouseMove);
|
|
193
|
+
element.addEventListener('click', onClick);
|
|
194
|
+
element.addEventListener('keydown', onKeyDown);
|
|
195
|
+
setupARIA(element);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @param {Element} element
|
|
200
|
+
* @return {void}
|
|
201
|
+
*/
|
|
202
|
+
export function attach(element) {
|
|
203
|
+
element.classList.add('mdw-overlay');
|
|
204
|
+
Overlay.attach(element);
|
|
205
|
+
|
|
206
|
+
element.classList.add('mdw-ripple');
|
|
207
|
+
Ripple.attach(element);
|
|
208
|
+
|
|
209
|
+
attachCore(element);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @param {Element} element
|
|
214
|
+
* @return {void}
|
|
215
|
+
*/
|
|
216
|
+
export function detachCore(element) {
|
|
217
|
+
element.removeEventListener('click', onClick);
|
|
218
|
+
element.removeEventListener('mousemove', onMouseMove);
|
|
219
|
+
element.removeEventListener('keydown', onKeyDown);
|
|
220
|
+
element.removeAttribute('mdw-js');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @param {Element} element
|
|
225
|
+
* @return {void}
|
|
226
|
+
*/
|
|
227
|
+
export function detach(element) {
|
|
228
|
+
detachCore(element);
|
|
229
|
+
Ripple.detach(element);
|
|
230
|
+
Overlay.detach(element);
|
|
231
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// https://material.io/guidelines/components/progress-activity.html#
|
|
2
|
+
|
|
3
|
+
// https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/anim/progress_indeterminate_rotation_material.xml
|
|
4
|
+
// https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/anim/progress_indeterminate_material.xml
|
|
5
|
+
// https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/drawable/vector_drawable_progress_bar_medium.xml
|
|
6
|
+
|
|
7
|
+
@use "sass:math";
|
|
8
|
+
|
|
9
|
+
@use '../../core/_motion.scss' as motion;
|
|
10
|
+
@use '../../core/_platform.scss' as platform;
|
|
11
|
+
@use '../../core/_length.scss' as *;
|
|
12
|
+
|
|
13
|
+
:root {
|
|
14
|
+
--mdw-progress__circle-duration: 1333ms;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* SVG Animated Material Spin Animation
|
|
19
|
+
* radius = 8.75
|
|
20
|
+
* pi = 3.14159
|
|
21
|
+
* circumference = 2 * pi * r = (54.977825)
|
|
22
|
+
* dash-length = circumference * (100-x)/100
|
|
23
|
+
*
|
|
24
|
+
* Every cycle rotates entire shape an additional -90deg (CCW)
|
|
25
|
+
*
|
|
26
|
+
* Entire animation rotates 4x speed (CW)
|
|
27
|
+
*
|
|
28
|
+
* 1. Start head at: 0.5%
|
|
29
|
+
* 2. Ease in head: to 75%
|
|
30
|
+
* 3. Ease out tail: to 74.5%
|
|
31
|
+
* 4. Rotate -90 deg
|
|
32
|
+
*
|
|
33
|
+
* Animate with ease-in-out
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
@function circlePercentage($percent, $limit: 100) {
|
|
37
|
+
$radius: 8.75;
|
|
38
|
+
$pi: 3.14159265359;
|
|
39
|
+
$circumference: 2 * $pi * $radius;
|
|
40
|
+
@return $circumference * (math.div($limit,100) - math.div($percent,100));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@keyframes rotate-clockwise {
|
|
44
|
+
from {
|
|
45
|
+
transform: rotate(0deg);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
to {
|
|
49
|
+
transform: rotate(360deg);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@keyframes rotate-counterclockwise {
|
|
54
|
+
0% {
|
|
55
|
+
transform: rotate(0deg);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
100% {
|
|
59
|
+
transform: rotate(-360deg);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@keyframes mdw-progress-dash {
|
|
64
|
+
0% {
|
|
65
|
+
stroke-dashoffset: circlePercentage(0.5, 75);
|
|
66
|
+
}
|
|
67
|
+
#{motion.$standardPeakVelocity * 100%} {
|
|
68
|
+
stroke-dashoffset: circlePercentage(75, 75);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
100% {
|
|
72
|
+
stroke-dashoffset: circlePercentage(149.5, 75);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.mdw-progress__circle {
|
|
77
|
+
block-size: 48px;
|
|
78
|
+
inline-size: 48px;
|
|
79
|
+
margin: 8px;
|
|
80
|
+
|
|
81
|
+
stroke-width: 2.5;
|
|
82
|
+
|
|
83
|
+
svg {
|
|
84
|
+
block-size: 100%;
|
|
85
|
+
inline-size: 100%;
|
|
86
|
+
|
|
87
|
+
animation-name: rotate-clockwise;
|
|
88
|
+
animation-duration: var(--mdw-progress__circle-duration);
|
|
89
|
+
animation-timing-function: linear;
|
|
90
|
+
animation-iteration-count: infinite;
|
|
91
|
+
will-change: transform;
|
|
92
|
+
|
|
93
|
+
transform: rotate(0deg);
|
|
94
|
+
|
|
95
|
+
& > path {
|
|
96
|
+
transform-origin: center center;
|
|
97
|
+
|
|
98
|
+
fill: none;
|
|
99
|
+
stroke: currentColor;
|
|
100
|
+
stroke-width: inherit;
|
|
101
|
+
|
|
102
|
+
&:nth-child(1) {
|
|
103
|
+
animation-name: mdw-progress-dash, rotate-counterclockwise;
|
|
104
|
+
animation-duration: var(--mdw-progress__circle-duration), calc(var(--mdw-progress__circle-duration) * 4);
|
|
105
|
+
animation-timing-function: motion.$standardEasing, steps(4, end);
|
|
106
|
+
animation-iteration-count: infinite;
|
|
107
|
+
|
|
108
|
+
stroke-dasharray: circlePercentage(25, 100);
|
|
109
|
+
stroke-dashoffset: circlePercentage(math.div(100, 3), 75); // Fallback 33% length for IE
|
|
110
|
+
stroke-linecap: round;
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
&:nth-child(2) {
|
|
115
|
+
display: none;
|
|
116
|
+
|
|
117
|
+
transition-duration: motion.$shapeChangeDuration;
|
|
118
|
+
|
|
119
|
+
transition-property: stroke-dashoffset;
|
|
120
|
+
transition-timing-function: motion.$standardEasing;
|
|
121
|
+
|
|
122
|
+
stroke-dasharray: circlePercentage(0, 100);
|
|
123
|
+
stroke-dashoffset: circlePercentage(0, 100);
|
|
124
|
+
stroke-linecap: square;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.mdw-progress__circle[mdw-determinate] {
|
|
132
|
+
svg {
|
|
133
|
+
animation: none;
|
|
134
|
+
will-change: none;
|
|
135
|
+
|
|
136
|
+
& > path {
|
|
137
|
+
&:nth-child(1) {
|
|
138
|
+
display: none;
|
|
139
|
+
|
|
140
|
+
animation: none;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
&:nth-child(2) {
|
|
144
|
+
display: inline;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.mdw-progress__circle[value='100'] {
|
|
151
|
+
svg {
|
|
152
|
+
& > path:nth-child(2) {
|
|
153
|
+
stroke-dashoffset: circlePercentage(100);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
File without changes
|
|
@@ -2,19 +2,35 @@ const radius = 8.75;
|
|
|
2
2
|
const circumference = 2 * Math.PI * radius;
|
|
3
3
|
|
|
4
4
|
// TODO: Upgrade IE/Edge browsers to animate with rAF
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Element} progressCircleElement
|
|
8
|
+
* @return {void}
|
|
9
|
+
*/
|
|
10
|
+
export function attach(progressCircleElement) {
|
|
11
|
+
/** @type {Element} */
|
|
12
|
+
let svg = (progressCircleElement.getElementsByTagName('svg')[0]);
|
|
13
|
+
if (!svg) {
|
|
14
|
+
svg = (document.createElement('svg'));
|
|
15
|
+
svg.setAttribute('viewbox', '0 0 24 24');
|
|
16
|
+
progressCircleElement.appendChild(svg);
|
|
17
|
+
}
|
|
18
|
+
const paths = svg.getElementsByTagName('path');
|
|
19
|
+
if (paths.length !== 2) {
|
|
20
|
+
svg.innerHTML = /* html */ `
|
|
21
|
+
<path d="M12 3.25A8.75 8.75 0 1 1 3.25 12"/>
|
|
22
|
+
<path d="M12 3.25A8.75 8.75 0 1 1 3.25 12 A 8.75 8.75 0 0 1 12 3.25"/>
|
|
23
|
+
`;
|
|
15
24
|
}
|
|
16
25
|
}
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
27
|
+
/**
|
|
28
|
+
* @param {Element} progressCircleElement
|
|
29
|
+
* @param {number} value Percentage value (0-100);
|
|
30
|
+
* @return {void}
|
|
31
|
+
*/
|
|
32
|
+
export function setValue(progressCircleElement, value) {
|
|
33
|
+
const dashOffset = circumference * (3 - (value / 100));
|
|
34
|
+
const pathElements = progressCircleElement.getElementsByTagName('path');
|
|
35
|
+
pathElements[pathElements.length - 1].style.setProperty('stroke-dashoffset', dashOffset.toString());
|
|
36
|
+
}
|