@webtides/element-library 0.3.1 → 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.
Files changed (252) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/README.md +72 -56
  3. package/all.js +16 -0
  4. package/catalog.js +17 -1
  5. package/custom-elements.json +15912 -10065
  6. package/package.json +1 -1
  7. package/src/components/accordion/accordion.changelog.md +11 -0
  8. package/src/components/accordion/accordion.js +15 -3
  9. package/src/components/accordion/accordion.readme.md +27 -1
  10. package/src/components/accordion/accordion.style.js +19 -0
  11. package/src/components/app-bar/app-bar.changelog.md +24 -0
  12. package/src/components/app-bar/app-bar.define.js +3 -0
  13. package/src/components/app-bar/app-bar.js +91 -0
  14. package/src/components/app-bar/app-bar.readme.md +130 -0
  15. package/src/components/app-bar/app-bar.style.js +103 -0
  16. package/src/components/app-frame/app-frame.changelog.md +59 -0
  17. package/src/components/app-frame/app-frame.define.js +3 -0
  18. package/src/components/app-frame/app-frame.events.js +6 -0
  19. package/src/components/app-frame/app-frame.js +1085 -0
  20. package/src/components/app-frame/app-frame.readme.md +425 -0
  21. package/src/components/app-frame/app-frame.style.js +534 -0
  22. package/src/components/button/button.changelog.md +21 -0
  23. package/src/components/button/button.events.js +3 -0
  24. package/src/components/button/button.js +145 -3
  25. package/src/components/button/button.readme.md +72 -4
  26. package/src/components/button/button.style.js +167 -8
  27. package/src/components/button-group/button-group.changelog.md +10 -0
  28. package/src/components/button-group/button-group.readme.md +2 -0
  29. package/src/components/button-group/button-group.style.js +6 -2
  30. package/src/components/checkbox-group-field/checkbox-group-field.changelog.md +6 -0
  31. package/src/components/checkbox-group-field/checkbox-group-field.js +7 -2
  32. package/src/components/checkbox-group-field/checkbox-group-field.readme.md +23 -1
  33. package/src/components/combobox-field/combobox-field.changelog.md +6 -0
  34. package/src/components/combobox-field/combobox-field.readme.md +8 -0
  35. package/src/components/combobox-field/combobox-field.style.js +2 -0
  36. package/src/components/date-field/date-field.changelog.md +6 -0
  37. package/src/components/date-field/date-field.readme.md +10 -0
  38. package/src/components/date-field/date-field.style.js +8 -3
  39. package/src/components/description-list/description-list.changelog.md +42 -0
  40. package/src/components/description-list/description-list.define.js +3 -0
  41. package/src/components/description-list/description-list.js +49 -0
  42. package/src/components/description-list/description-list.readme.md +161 -0
  43. package/src/components/description-list/description-list.style.js +169 -0
  44. package/src/components/dialog/dialog.changelog.md +7 -0
  45. package/src/components/dialog/dialog.readme.md +5 -0
  46. package/src/components/dialog/dialog.style.js +17 -2
  47. package/src/components/divider/divider.changelog.md +6 -0
  48. package/src/components/divider/divider.readme.md +1 -1
  49. package/src/components/divider/divider.style.js +6 -0
  50. package/src/components/drawer/drawer.changelog.md +7 -0
  51. package/src/components/drawer/drawer.readme.md +7 -6
  52. package/src/components/drawer/drawer.style.js +35 -2
  53. package/src/components/dropdown/dropdown.readme.md +6 -1
  54. package/src/components/file-field/file-field.changelog.md +8 -0
  55. package/src/components/file-field/file-field.js +135 -5
  56. package/src/components/file-field/file-field.readme.md +35 -6
  57. package/src/components/file-field/file-field.style.js +71 -0
  58. package/src/components/form-field/form-field.js +1 -1
  59. package/src/components/input-field/input-field.changelog.md +10 -0
  60. package/src/components/input-field/input-field.js +192 -14
  61. package/src/components/input-field/input-field.readme.md +88 -2
  62. package/src/components/input-field/input-field.style.js +2 -0
  63. package/src/components/list/list.changelog.md +30 -0
  64. package/src/components/list/list.define.js +3 -0
  65. package/src/components/list/list.js +68 -0
  66. package/src/components/list/list.readme.md +123 -0
  67. package/src/components/list/list.style.js +56 -0
  68. package/src/components/list-item/list-item.changelog.md +40 -0
  69. package/src/components/list-item/list-item.define.js +3 -0
  70. package/src/components/list-item/list-item.js +130 -0
  71. package/src/components/list-item/list-item.readme.md +144 -0
  72. package/src/components/list-item/list-item.style.js +246 -0
  73. package/src/components/menu/menu.changelog.md +44 -0
  74. package/src/components/menu/menu.define.js +3 -0
  75. package/src/components/menu/menu.events.js +5 -0
  76. package/src/components/menu/menu.js +793 -0
  77. package/src/components/menu/menu.readme.md +313 -0
  78. package/src/components/menu/menu.style.js +59 -0
  79. package/src/components/menu-group/menu-group.changelog.md +20 -0
  80. package/src/components/menu-group/menu-group.define.js +3 -0
  81. package/src/components/menu-group/menu-group.js +44 -0
  82. package/src/components/menu-group/menu-group.readme.md +74 -0
  83. package/src/components/menu-group/menu-group.style.js +38 -0
  84. package/src/components/menu-item/menu-item.changelog.md +32 -0
  85. package/src/components/menu-item/menu-item.define.js +3 -0
  86. package/src/components/menu-item/menu-item.js +168 -0
  87. package/src/components/menu-item/menu-item.readme.md +132 -0
  88. package/src/components/menu-item/menu-item.style.js +117 -0
  89. package/src/components/nav/nav.changelog.md +35 -0
  90. package/src/components/nav/nav.define.js +3 -0
  91. package/src/components/nav/nav.js +212 -0
  92. package/src/components/nav/nav.readme.md +248 -0
  93. package/src/components/nav/nav.style.js +269 -0
  94. package/src/components/nav-item/nav-item.changelog.md +25 -0
  95. package/src/components/nav-item/nav-item.define.js +3 -0
  96. package/src/components/nav-item/nav-item.js +75 -0
  97. package/src/components/nav-item/nav-item.readme.md +111 -0
  98. package/src/components/nav-item/nav-item.style.js +159 -0
  99. package/src/components/otp-field/otp-field.changelog.md +6 -0
  100. package/src/components/otp-field/otp-field.readme.md +8 -0
  101. package/src/components/otp-field/otp-field.style.js +8 -3
  102. package/src/components/pagination/pagination.changelog.md +8 -0
  103. package/src/components/pagination/pagination.js +123 -49
  104. package/src/components/pagination/pagination.readme.md +24 -6
  105. package/src/components/pagination/pagination.style.js +11 -1
  106. package/src/components/password-field/password-field.changelog.md +7 -0
  107. package/src/components/password-field/password-field.readme.md +11 -1
  108. package/src/components/password-field/password-field.style.js +2 -0
  109. package/src/components/popover/popover.changelog.md +6 -0
  110. package/src/components/popover/popover.style.js +1 -0
  111. package/src/components/radio-field/radio-field.changelog.md +6 -0
  112. package/src/components/radio-field/radio-field.js +7 -2
  113. package/src/components/radio-field/radio-field.readme.md +23 -1
  114. package/src/components/scroll-to-top/scroll-to-top.changelog.md +7 -5
  115. package/src/components/scroll-to-top/scroll-to-top.js +16 -12
  116. package/src/components/scroll-to-top/scroll-to-top.readme.md +2 -0
  117. package/src/components/segmented-field/segmented-field.changelog.md +27 -0
  118. package/src/components/segmented-field/segmented-field.define.js +3 -0
  119. package/src/components/segmented-field/segmented-field.js +175 -0
  120. package/src/components/segmented-field/segmented-field.readme.md +140 -0
  121. package/src/components/segmented-field/segmented-field.style.js +193 -0
  122. package/src/components/splitter/splitter.changelog.md +24 -0
  123. package/src/components/splitter/splitter.define.js +3 -0
  124. package/src/components/splitter/splitter.events.js +4 -0
  125. package/src/components/splitter/splitter.js +237 -0
  126. package/src/components/splitter/splitter.readme.md +164 -0
  127. package/src/components/splitter/splitter.style.js +100 -0
  128. package/src/components/status-bar/status-bar.changelog.md +25 -0
  129. package/src/components/status-bar/status-bar.define.js +3 -0
  130. package/src/components/status-bar/status-bar.js +74 -0
  131. package/src/components/status-bar/status-bar.readme.md +139 -0
  132. package/src/components/status-bar/status-bar.style.js +122 -0
  133. package/src/components/tab-group/tab-group.changelog.md +7 -0
  134. package/src/components/tab-group/tab-group.js +30 -9
  135. package/src/components/tab-group/tab-group.readme.md +14 -0
  136. package/src/components/textarea-field/textarea-field.changelog.md +6 -0
  137. package/src/components/textarea-field/textarea-field.js +14 -1
  138. package/src/components/textarea-field/textarea-field.readme.md +23 -1
  139. package/src/components/toast/toast.changelog.md +6 -0
  140. package/src/components/toast/toast.readme.md +5 -3
  141. package/src/components/toast/toast.style.js +22 -6
  142. package/src/components/toolbar/toolbar.changelog.md +24 -0
  143. package/src/components/toolbar/toolbar.define.js +3 -0
  144. package/src/components/toolbar/toolbar.js +233 -0
  145. package/src/components/toolbar/toolbar.readme.md +156 -0
  146. package/src/components/toolbar/toolbar.style.js +49 -0
  147. package/src/components/tooltip/tooltip.changelog.md +11 -0
  148. package/src/components/tooltip/tooltip.js +51 -4
  149. package/src/components/tooltip/tooltip.readme.md +26 -1
  150. package/src/components/tree/tree.changelog.md +23 -0
  151. package/src/components/tree/tree.define.js +3 -0
  152. package/src/components/tree/tree.js +138 -0
  153. package/src/components/tree/tree.readme.md +119 -0
  154. package/src/components/tree/tree.style.js +16 -0
  155. package/src/components/tree-item/tree-item.changelog.md +23 -0
  156. package/src/components/tree-item/tree-item.define.js +3 -0
  157. package/src/components/tree-item/tree-item.events.js +3 -0
  158. package/src/components/tree-item/tree-item.js +246 -0
  159. package/src/components/tree-item/tree-item.readme.md +128 -0
  160. package/src/components/tree-item/tree-item.style.js +226 -0
  161. package/src/styles/appearance.style.js +47 -0
  162. package/src/styles/choice-group.style.js +27 -1
  163. package/src/styles/input-control.style.js +87 -0
  164. package/src/styles/modal.style.js +14 -1
  165. package/src/styles/native.css +100 -0
  166. package/src/styles/size.style.js +41 -0
  167. package/src/utils/floating.js +15 -1
  168. package/src/utils/focus.js +69 -0
  169. package/src/utils/options.js +35 -0
  170. package/src/utils/scroll.js +24 -0
  171. package/src/utils/text-entry-attributes.js +13 -0
  172. package/types/all.d.ts +16 -0
  173. package/types/src/components/accordion/accordion.d.ts +3 -1
  174. package/types/src/components/app-bar/app-bar.d.ts +43 -0
  175. package/types/src/components/app-bar/app-bar.define.d.ts +1 -0
  176. package/types/src/components/app-bar/app-bar.style.d.ts +2 -0
  177. package/types/src/components/app-frame/app-frame.d.ts +497 -0
  178. package/types/src/components/app-frame/app-frame.define.d.ts +1 -0
  179. package/types/src/components/app-frame/app-frame.events.d.ts +7 -0
  180. package/types/src/components/app-frame/app-frame.style.d.ts +8 -0
  181. package/types/src/components/button/button.d.ts +61 -0
  182. package/types/src/components/button/button.events.d.ts +4 -0
  183. package/types/src/components/checkbox-group-field/checkbox-group-field.d.ts +5 -2
  184. package/types/src/components/combobox-field/combobox-field.d.ts +10 -0
  185. package/types/src/components/date-field/date-field.d.ts +10 -0
  186. package/types/src/components/description-list/description-list.d.ts +34 -0
  187. package/types/src/components/description-list/description-list.define.d.ts +1 -0
  188. package/types/src/components/description-list/description-list.style.d.ts +2 -0
  189. package/types/src/components/file-field/file-field.d.ts +68 -3
  190. package/types/src/components/form-field/form-field.d.ts +1 -1
  191. package/types/src/components/input-field/input-field.d.ts +99 -0
  192. package/types/src/components/list/list.d.ts +41 -0
  193. package/types/src/components/list/list.define.d.ts +1 -0
  194. package/types/src/components/list/list.style.d.ts +2 -0
  195. package/types/src/components/list-item/list-item.d.ts +64 -0
  196. package/types/src/components/list-item/list-item.define.d.ts +1 -0
  197. package/types/src/components/list-item/list-item.style.d.ts +2 -0
  198. package/types/src/components/menu/menu.d.ts +362 -0
  199. package/types/src/components/menu/menu.define.d.ts +1 -0
  200. package/types/src/components/menu/menu.events.d.ts +6 -0
  201. package/types/src/components/menu/menu.style.d.ts +2 -0
  202. package/types/src/components/menu-group/menu-group.d.ts +24 -0
  203. package/types/src/components/menu-group/menu-group.define.d.ts +1 -0
  204. package/types/src/components/menu-group/menu-group.style.d.ts +2 -0
  205. package/types/src/components/menu-item/menu-item.d.ts +80 -0
  206. package/types/src/components/menu-item/menu-item.define.d.ts +1 -0
  207. package/types/src/components/menu-item/menu-item.style.d.ts +2 -0
  208. package/types/src/components/nav/nav.d.ts +103 -0
  209. package/types/src/components/nav/nav.define.d.ts +1 -0
  210. package/types/src/components/nav/nav.style.d.ts +2 -0
  211. package/types/src/components/nav-item/nav-item.d.ts +39 -0
  212. package/types/src/components/nav-item/nav-item.define.d.ts +1 -0
  213. package/types/src/components/nav-item/nav-item.style.d.ts +2 -0
  214. package/types/src/components/otp-field/otp-field.d.ts +10 -0
  215. package/types/src/components/pagination/pagination.d.ts +31 -2
  216. package/types/src/components/password-field/password-field.d.ts +10 -0
  217. package/types/src/components/radio-field/radio-field.d.ts +5 -2
  218. package/types/src/components/scroll-to-top/scroll-to-top.d.ts +6 -5
  219. package/types/src/components/segmented-field/segmented-field.d.ts +85 -0
  220. package/types/src/components/segmented-field/segmented-field.define.d.ts +1 -0
  221. package/types/src/components/segmented-field/segmented-field.style.d.ts +2 -0
  222. package/types/src/components/splitter/splitter.d.ts +127 -0
  223. package/types/src/components/splitter/splitter.define.d.ts +1 -0
  224. package/types/src/components/splitter/splitter.events.d.ts +5 -0
  225. package/types/src/components/splitter/splitter.style.d.ts +2 -0
  226. package/types/src/components/status-bar/status-bar.d.ts +44 -0
  227. package/types/src/components/status-bar/status-bar.define.d.ts +1 -0
  228. package/types/src/components/status-bar/status-bar.style.d.ts +2 -0
  229. package/types/src/components/tab-group/tab-group.d.ts +17 -0
  230. package/types/src/components/textarea-field/textarea-field.d.ts +7 -0
  231. package/types/src/components/toolbar/toolbar.d.ts +96 -0
  232. package/types/src/components/toolbar/toolbar.define.d.ts +1 -0
  233. package/types/src/components/toolbar/toolbar.style.d.ts +2 -0
  234. package/types/src/components/tooltip/tooltip.d.ts +26 -0
  235. package/types/src/components/tree/tree.d.ts +62 -0
  236. package/types/src/components/tree/tree.define.d.ts +1 -0
  237. package/types/src/components/tree/tree.style.d.ts +2 -0
  238. package/types/src/components/tree-item/tree-item.d.ts +106 -0
  239. package/types/src/components/tree-item/tree-item.define.d.ts +1 -0
  240. package/types/src/components/tree-item/tree-item.events.d.ts +4 -0
  241. package/types/src/components/tree-item/tree-item.style.d.ts +2 -0
  242. package/types/src/styles/appearance.style.d.ts +31 -0
  243. package/types/src/styles/choice-group.style.d.ts +1 -1
  244. package/types/src/styles/input-control.style.d.ts +15 -0
  245. package/types/src/styles/modal.style.d.ts +5 -0
  246. package/types/src/styles/size.style.d.ts +24 -0
  247. package/types/src/utils/floating.d.ts +11 -0
  248. package/types/src/utils/focus.d.ts +25 -0
  249. package/types/src/utils/options.d.ts +17 -0
  250. package/types/src/utils/scroll.d.ts +11 -0
  251. package/types/src/utils/text-entry-attributes.d.ts +10 -0
  252. package/web-types.json +2935 -308
@@ -0,0 +1,168 @@
1
+ import { TemplateElement, defineElement, html, classMap } from '@webtides/element-js';
2
+ import { hasSlotted } from '../../utils/slots.js';
3
+ import style from './menu-item.style.js';
4
+
5
+ /**
6
+ * One entry of an `el-menu`: an action, or a link with an address. A menu item to assistive
7
+ * technology (`role="menuitem"`). The menu moves the focus of the keyboard to it, so it is no stop
8
+ * of the Tab key itself.
9
+ *
10
+ * Choosing an entry is a click on it: listen for `click` on the entry, or for `menu-select` on the
11
+ * menu, which names the entry and its `value`.
12
+ *
13
+ * An entry can set something instead of doing something. With `type="checkbox"` it is on or off
14
+ * (`role="menuitemcheckbox"`), with `type="radio"` it is one of several of which one is chosen
15
+ * (`role="menuitemradio"`), and `checked` is its state, which it says (`aria-checked`) and shows
16
+ * with a mark in front of its text. The page sets `checked`: the entry does not change it when
17
+ * it is chosen.
18
+ *
19
+ * @element el-menu-item
20
+ *
21
+ * @slot - The text of the entry.
22
+ * @slot icon - An icon in front of the text: a decoration, the text is the name.
23
+ *
24
+ * @csspart base - The entry: a `<button>`, or an `<a>` with `href`.
25
+ * @csspart mark - The place of the mark of an entry with a `type`: a check, or a dot. It is
26
+ * there while the entry is not checked as well.
27
+ * @csspart icon - The place of the icon.
28
+ * @csspart label - The text of the entry.
29
+ *
30
+ * @property {string} href - The address the entry leads to. With one it is a link.
31
+ * @property {string} target - Where to open the address.
32
+ * @property {string} rel - `rel` attribute for the link, written when `target` is set. Default
33
+ * `'noreferrer noopener'`.
34
+ * @property {string} value - What the entry stands for, for the listener of `menu-select`:
35
+ * `'delete'`. Default `''`.
36
+ * @property {boolean} disabled - Whether the entry cannot be chosen. The keyboard still gets to
37
+ * it. Default `false`.
38
+ * @property {'normal'|'checkbox'|'radio'} type - What the entry is: an action or a link
39
+ * (`'normal'`), an entry that is on or off (`'checkbox'`), or one of several of which one is
40
+ * chosen (`'radio'`). Default `'normal'`.
41
+ * @property {boolean} checked - Whether an entry with the `type` `checkbox` is on, or one with
42
+ * the `type` `radio` is the chosen one. The page sets it. Default `false`.
43
+ * @property {'neutral'|'brand'|'success'|'warning'|'danger'} variant - The variant of the entry:
44
+ * `danger` for something that cannot be undone. Default `'neutral'`. Reflected to the `variant`
45
+ * attribute.
46
+ */
47
+ export default class MenuItem extends TemplateElement {
48
+ constructor() {
49
+ super({
50
+ styles: [style],
51
+ shadowRender: true,
52
+ // The shared variants module selects the host by this attribute.
53
+ propertyOptions: { variant: { reflect: true } },
54
+ });
55
+ }
56
+
57
+ properties() {
58
+ return {
59
+ href: '',
60
+ target: '',
61
+ rel: 'noreferrer noopener',
62
+ value: '',
63
+ disabled: false,
64
+ type: 'normal',
65
+ checked: false,
66
+ variant: 'neutral',
67
+ };
68
+ }
69
+
70
+ events() {
71
+ return {
72
+ "[part~='base']": {
73
+ // A template element does not render again when a child comes, goes or changes
74
+ // its `slot` attribute. The slot tells of all three.
75
+ slotchange: () => this.requestUpdate(),
76
+ // An entry that is disabled keeps its click to itself: the page hears nothing.
77
+ click: (event) => {
78
+ if (!this._disabled()) return;
79
+ event.preventDefault();
80
+ event.stopPropagation();
81
+ },
82
+ },
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Puts the focus on the entry: on the control inside of it.
88
+ * @param {FocusOptions} [options]
89
+ */
90
+ focus(options) {
91
+ this.shadowRoot?.querySelector("[part~='base']")?.focus(options);
92
+ }
93
+
94
+ /**
95
+ * @private
96
+ * @returns {boolean}
97
+ */
98
+ _disabled() {
99
+ return this.disabled === true || this.disabled === 'true' || this.disabled === '';
100
+ }
101
+
102
+ /**
103
+ * Whether the entry is checked: `checked` is there as an attribute without a value, or true.
104
+ * @private
105
+ * @returns {boolean}
106
+ */
107
+ _checked() {
108
+ return this.checked === true || this.checked === 'true' || this.checked === '';
109
+ }
110
+
111
+ template() {
112
+ const disabled = this._disabled();
113
+ // An entry with a type says its state, also while it is off and while it is disabled.
114
+ const checkable = this.type === 'checkbox' || this.type === 'radio';
115
+ const role = checkable ? `menuitem${this.type}` : 'menuitem';
116
+ const checked = checkable ? String(this._checked()) : null;
117
+ const classes = classMap({
118
+ item: true,
119
+ 'item--disabled': disabled,
120
+ 'item--checkbox': this.type === 'checkbox',
121
+ 'item--radio': this.type === 'radio',
122
+ });
123
+ // The mark is drawn by the stylesheet, from the state the control says. Its place is
124
+ // there for every entry with a type, so a text does not move when its entry is checked.
125
+ const content = html`
126
+ <span part="mark" class="mark" aria-hidden="true" ?hidden="${!checkable}"></span>
127
+ <span part="icon" class="icon" ?hidden="${!hasSlotted(this, 'icon')}"><slot name="icon"></slot></span>
128
+ <span part="label" class="label"><slot></slot></span>
129
+ `;
130
+
131
+ // The role and the place in the order of the Tab key are inside of the shadow root: they
132
+ // are part of the server-rendered markup that way. A link that is disabled has no address
133
+ // to follow, so it is the button.
134
+ if (this.href && !disabled) {
135
+ return html`
136
+ <a
137
+ part="base"
138
+ class="${classes}"
139
+ role="${role}"
140
+ aria-checked="${checked}"
141
+ tabindex="-1"
142
+ href="${this.href}"
143
+ target="${this.target || null}"
144
+ rel="${this.target ? this.rel : null}"
145
+ >${content}</a
146
+ >
147
+ `;
148
+ }
149
+
150
+ return html`
151
+ <button
152
+ part="base"
153
+ class="${classes}"
154
+ type="button"
155
+ role="${role}"
156
+ aria-checked="${checked}"
157
+ tabindex="-1"
158
+ aria-disabled="${disabled ? 'true' : null}"
159
+ >
160
+ ${content}
161
+ </button>
162
+ `;
163
+ }
164
+ }
165
+
166
+ export function define() {
167
+ defineElement('el-menu-item', MenuItem);
168
+ }
@@ -0,0 +1,132 @@
1
+ # Menu Item
2
+
3
+ `menu-item` is one entry of an [`el-menu`](../menu/menu.readme.md): an action, or a link with an address. Or an entry that sets something: one that is on or off, or the chosen one of several.
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/menu/define';
17
+ import '@webtides/element-library/menu-item/define';
18
+ ```
19
+
20
+ ```html
21
+ <el-menu>
22
+ <el-button slot="trigger">More</el-button>
23
+ <el-menu-item value="edit"><svg slot="icon" aria-hidden="true">…</svg>Edit</el-menu-item>
24
+ <el-menu-item href="/invoices/12/print">Print</el-menu-item>
25
+ <el-menu-item value="move" disabled="true">Move</el-menu-item>
26
+ <el-menu-item value="delete" variant="danger">Delete</el-menu-item>
27
+ </el-menu>
28
+ ```
29
+
30
+ > Boolean attributes are passed as strings (`disabled="true"`), matching the rest of the library.
31
+
32
+ ## API
33
+
34
+ #### Properties/Attributes
35
+
36
+ | Name | Type | Default | Description |
37
+ | --- | --- | --- | --- |
38
+ | `href` | `string` | `''` | The address the entry leads to. With one it is a link. |
39
+ | `target` | `string` | `''` | Where to open the address. |
40
+ | `rel` | `string` | `'noreferrer noopener'` | `rel` attribute for the link, written when `target` is set. |
41
+ | `value` | `string` | `''` | What the entry stands for, for the listener of `menu-select`. |
42
+ | `disabled` | `boolean` | `false` | Whether the entry cannot be chosen. The keyboard still gets to it. |
43
+ | `type` | `string` | `'normal'` | `normal`, an action or a link; `checkbox`, an entry that is on or off; `radio`, one of several of which one is chosen. |
44
+ | `checked` | `boolean` | `false` | Whether an entry with the `type` `checkbox` is on, or one with the `type` `radio` is the chosen one. The page sets it. |
45
+ | `variant` | `string` | `'neutral'` | `neutral`, `brand`, `success`, `warning` or `danger`: `danger` for something that cannot be undone. Reflected. |
46
+
47
+ #### Methods
48
+
49
+ | Name | Description |
50
+ | --------- | --------------------------------------------------------- |
51
+ | `focus()` | Puts the focus on the entry: on the control inside of it. |
52
+
53
+ #### Events
54
+
55
+ _None of its own._ A choice is a `click` on the entry, and `menu-select` on its menu.
56
+
57
+ #### Slots
58
+
59
+ | Name | Description |
60
+ | --------- | ----------------------------------------------------------------- |
61
+ | (default) | The text of the entry. |
62
+ | `icon` | An icon in front of the text: a decoration, the text is the name. |
63
+
64
+ #### CSS Parts
65
+
66
+ | Name | Description |
67
+ | --- | --- |
68
+ | `base` | The entry: a `<button>`, or an `<a>` with `href`. |
69
+ | `mark` | The place of the mark of an entry with a `type`: a check, or a dot. It is there while the entry is not checked as well. |
70
+ | `icon` | The place of the icon. |
71
+ | `label` | The text of the entry. |
72
+
73
+ #### CSS Custom Properties
74
+
75
+ Reads `--el-control-height` for its height (an entry is a little lower than a control), `--el-space-1`, `--el-space-2` and `--el-space-3` for its padding and the gap to its icon, `--el-radius-md`, `--el-focus-ring-width` and `--el-color-focus-ring` for the focus, `--el-touch-target` on a touch screen, and the colour of its variant: `--el-color-fg`, or `--el-color-danger` for `variant="danger"`.
76
+
77
+ ## An action or a link
78
+
79
+ Without `href` the entry is a button, and choosing it is a click the page acts on. With `href` it is a link, which the browser follows. Both have the role of a menu item, and both close the menu.
80
+
81
+ ## Disabled
82
+
83
+ `disabled="true"` takes the entry out of what can be chosen. It says so to assistive technology (`aria-disabled="true"`), fires no click, and a link has no address while it is disabled. The arrow keys still stop at it: a screen reader user learns that the action is there and not available now.
84
+
85
+ ## An entry that is checked
86
+
87
+ An entry can set something instead of doing something: the view a list is shown in, whether the archived rows are in it. `type` says which kind it is, and `checked` its state.
88
+
89
+ ```html
90
+ <el-menu>
91
+ <el-button slot="trigger">View</el-button>
92
+ <el-menu-group label="Layout">
93
+ <el-menu-item type="radio" value="list" checked="true">List</el-menu-item>
94
+ <el-menu-item type="radio" value="grid">Grid</el-menu-item>
95
+ </el-menu-group>
96
+ <el-menu-group>
97
+ <el-menu-item type="checkbox" value="archived">Show archived</el-menu-item>
98
+ </el-menu-group>
99
+ </el-menu>
100
+ ```
101
+
102
+ - **`type="checkbox"`** is an entry that is on or off (`role="menuitemcheckbox"`). **`type="radio"`** is one of several of which one is chosen (`role="menuitemradio"`): put the ones that belong together into an [`el-menu-group`](../menu-group/menu-group.readme.md).
103
+ - **`checked`** is the state. The entry says it to assistive technology (`aria-checked`), also while it is off and while it is disabled.
104
+ - **The page sets the state.** The entry does not change `checked` when it is chosen: the menu can be the answer of a server, and the server says what is chosen. Set it in the listener of `menu-select`, for the entry and, among radios, for the others:
105
+
106
+ ```js
107
+ menu.addEventListener('menu-select', ({ detail: { item } }) => {
108
+ if (item.type === 'radio') {
109
+ for (const other of item.parentElement.querySelectorAll('el-menu-item')) other.checked = other === item;
110
+ } else if (item.type === 'checkbox') {
111
+ item.checked = !item.checked;
112
+ }
113
+ });
114
+ ```
115
+
116
+ - **The mark** is in front of the text, and in front of the icon: a check for an entry that is on, a dot for the chosen one. Its place is there while the entry is not checked as well, so the text does not move when the state changes, and the texts of the entries of a group begin on one line. An entry without a `type` has no such place: in a menu that has both kinds, keep the checked ones in a group of their own.
117
+ - **Where the user forces colours** the mark has the colour of the text: the check is text, the dot is drawn with a border.
118
+ - **Choosing** such an entry is the same as for every entry: a click, `menu-select`, and the menu closes.
119
+
120
+ ## A danger
121
+
122
+ `variant="danger"` shows the entry in the colour of a danger, for an action that cannot be undone. The colour alone does not say so to everyone: name the action for what it does ("Delete"), and ask before it is done where it matters.
123
+
124
+ ## The icon
125
+
126
+ What is in the `icon` slot stands in front of the text. It is a decoration: give it `aria-hidden="true"`, the text is the name of the entry. Without an icon the text starts where the entry starts.
127
+
128
+ ## Accessibility
129
+
130
+ - A menu item (`role="menuitem"`), which is no stop of the Tab key: its menu moves the focus to it. With a `type` it is a `menuitemcheckbox` or a `menuitemradio`, which says its state (`aria-checked`). The mark is hidden from assistive technology: the state is said, not drawn.
131
+ - The focus of the keyboard shows as a ring inside of the entry and a tint, the pointer as a tint.
132
+ - On a touch screen the entry is at least `--el-touch-target` high. Without the token nothing changes.
@@ -0,0 +1,117 @@
1
+ import hostStyle from '../../styles/host.style.js';
2
+ import variantsStyle from '../../styles/variants.style.js';
3
+
4
+ const css = String.raw;
5
+
6
+ const style = css`
7
+ :host {
8
+ display: block;
9
+ }
10
+
11
+ /* The whole entry is the control: an icon, and the text beside it. A little lower than a
12
+ control of a form, so a menu of a few entries is no tower. */
13
+ .item {
14
+ display: flex;
15
+ align-items: center;
16
+ gap: var(--el-space-2, 0.5rem);
17
+ box-sizing: border-box;
18
+ inline-size: 100%;
19
+ min-block-size: calc(var(--el-control-height, 2.5rem) * 0.85);
20
+ margin: 0;
21
+ padding: var(--el-space-1, 0.25rem) var(--el-space-3, 0.75rem);
22
+ border: 0;
23
+ border-radius: var(--el-radius-md, 0);
24
+ background: transparent;
25
+ /* The colour of the variant: the text colour of the menu, or the colour of a danger. */
26
+ color: var(--_el-variant-text);
27
+ font: inherit;
28
+ text-align: start;
29
+ text-decoration: none;
30
+ cursor: pointer;
31
+ user-select: none;
32
+ }
33
+
34
+ .icon {
35
+ display: inline-flex;
36
+ flex: none;
37
+ align-items: center;
38
+ justify-content: center;
39
+ }
40
+
41
+ /* The place of the mark of an entry that is on or off, or one of several. It is as wide
42
+ while the entry is not checked, so the text of an entry does not move when it is, and the
43
+ texts of the entries of a group begin on one line. */
44
+ .mark {
45
+ display: inline-grid;
46
+ flex: none;
47
+ place-items: center;
48
+ inline-size: 1em;
49
+ block-size: 1em;
50
+ line-height: 1;
51
+ }
52
+
53
+ .mark[hidden] {
54
+ display: none;
55
+ }
56
+
57
+ /* On: a check, the sign in the box of a checkbox field. It is text, which shows where the
58
+ user forces colours. */
59
+ .item--checkbox[aria-checked='true'] .mark::before {
60
+ content: '\2713';
61
+ }
62
+
63
+ /* The chosen one of several: a dot. It is drawn with a border and has no size of its own: a
64
+ background is taken away where the user forces colours, a border stays. */
65
+ .item--radio[aria-checked='true'] .mark::before {
66
+ content: '';
67
+ border: 0.2em solid currentColor;
68
+ border-radius: 50%;
69
+ }
70
+
71
+ /* One line as a rule. A text that is longer than the menu is wide wraps: an action that is
72
+ cut off cannot be read. */
73
+ .label {
74
+ flex: 1 1 auto;
75
+ min-inline-size: 0;
76
+ }
77
+
78
+ /* Under the pointer, and with the focus of the keyboard: a tint of the text colour, which
79
+ shows on every background. Hover only where a pointer can hover: a touch screen leaves the
80
+ state on what was tapped last. */
81
+ @media (hover: hover) {
82
+ .item:hover {
83
+ background: color-mix(in srgb, currentColor 10%, transparent);
84
+ }
85
+ }
86
+
87
+ .item:focus-visible {
88
+ background: color-mix(in srgb, currentColor 10%, transparent);
89
+ /* The ring is inside of the entry: the edge of the menu is around it. It is what shows
90
+ where the user forces colours. */
91
+ outline: var(--el-focus-ring-width, 2px) solid var(--el-color-focus-ring, currentColor);
92
+ outline-offset: calc(-1 * var(--el-focus-ring-width, 2px));
93
+ }
94
+
95
+ .item:active {
96
+ background: color-mix(in srgb, currentColor 18%, transparent);
97
+ }
98
+
99
+ /* An entry that cannot be chosen. The keyboard still gets to it, so it has its ring. */
100
+ .item--disabled,
101
+ .item--disabled:hover,
102
+ .item--disabled:active {
103
+ background: transparent;
104
+ opacity: 0.55;
105
+ cursor: not-allowed;
106
+ }
107
+
108
+ /* On a touch screen an entry is at least as high as a finger needs. Without the token the
109
+ sizes stay as they are. */
110
+ @media (any-pointer: coarse) {
111
+ .item {
112
+ min-block-size: max(calc(var(--el-control-height, 2.5rem) * 0.85), var(--el-touch-target, 0px));
113
+ }
114
+ }
115
+ `;
116
+
117
+ export default [hostStyle(), variantsStyle(), style].join('\n');
@@ -0,0 +1,35 @@
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.4.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - Initial `el-nav`: the destinations of an application as a bar for the lower edge of a phone. A navigation landmark (`<nav>`, named by `label`) with a list of `el-nav-item` links. ([#179](https://github.com/webtides/element-library/issues/179))
20
+ - Three to five destinations share the width in equal parts, however long their texts are. The bar is as high as an `el-app-bar`, and keeps that height: a text that does not fit is cut.
21
+ - In the footer of an `el-app-frame` the surface of the bar reaches the lower edge of the screen and its sides, and the destinations stay above the home indicator of a phone. The line to the content is the one of the region there. Alone, the bar keeps its destinations clear of the home indicator and of the sides itself (`env(safe-area-inset-*)`).
22
+ - A surface from `--el-color-bg` and a line to the content from `--el-color-border` and `--el-border-width`. The line is a border, which stays where the user forces colours and is there without a theme then.
23
+ - `layout="rail"`: the destinations below each other in a narrow column for the side of a wider screen, `--el-nav-rail-size` wide (`5rem`), with a line to the content at the side that faces it. The rail is as high as its place, and scrolls where it has more destinations than height. ([#181](https://github.com/webtides/element-library/issues/181))
24
+ - The `end` slot: a second group at the lower end of a rail, for the settings and the account. It is a list of its own, stays in view while the group at the top scrolls, and is not shown in a bar.
25
+ - `labels="false"`: the destinations show an icon alone. Their texts are off the screen and stay the names of their links, and show as tooltips for the pointer and for the focus of the keyboard, beside a rail and above a bar. The tooltips are `el-tooltip` elements in the shadow root (`::part(tooltip)`); the element imports the tooltip, and with it `@floating-ui/dom`.
26
+ - `layout="auto"`, the new default: a bar, and a rail where an `el-app-frame` has the element in the column at its side. The frame says so in a CSS property that is inherited, so the page writes the destinations once and the stylesheets decide, before any script has run. Alone, and in the footer of a frame, `auto` is the bar that was the default.
27
+ - Alone, a rail keeps its destinations clear of the top, its side and the lower edge of the screen (`env(safe-area-inset-*)`).
28
+ - `layout="list"`: the destinations below each other, each a row with its icon and its text beside it, for a sidebar. A list is as wide as its place and as high as it, scrolls where it has more destinations than height, and keeps the `end` slot at its lower end in view. Where its place is as wide as what is in it, it is `--el-nav-list-size` wide (`16rem`). ([#199](https://github.com/webtides/element-library/issues/199))
29
+ - `column`: what `layout="auto"` is in the column at the side of an `el-app-frame`, `rail` (the default) or `list`. The class of the landmark says it and the stylesheet decides, so a server-rendered page has a list on one view and a rail on another before any script has run.
30
+ - The `secondary` slot: a second group of destinations below the first, for the pages that have no room in a bar, with `secondary-label` as its heading. A list shows the heading, a rail shows the group below a line, and a bar leaves the group out. The group is a list of its own with the heading as its name (`::part(secondary)`, `::part(secondary-label)`, `::part(secondary-list)`).
31
+ - In an element of the page that is in the `navigation` slot of a frame, the element takes its layout from the frame as one that is in the slot itself. In a flex column of that element it takes the height that is left: its destinations scroll, and what the page puts above and below it stays in view.
32
+
33
+ ### Changed
34
+
35
+ - The groups at the top of a rail scroll together in a new part, `groups`. `::part(list)` is the first group as before and no longer the element that scrolls. ([#199](https://github.com/webtides/element-library/issues/199))
@@ -0,0 +1,3 @@
1
+ import { define } from './nav.js';
2
+
3
+ define();
@@ -0,0 +1,212 @@
1
+ import { TemplateElement, defineElement, html } from '@webtides/element-js';
2
+ import { define as defineTooltip } from '../tooltip/tooltip.js';
3
+ import { hasSlotted } from '../../utils/slots.js';
4
+ import style from './nav.style.js';
5
+
6
+ const LAYOUTS = ['auto', 'bar', 'rail', 'list'];
7
+
8
+ /**
9
+ * The destinations of an application: the places the user goes to all the time. Each destination
10
+ * is an `el-nav-item`: a link with an icon and a short text, and the one of the current view is
11
+ * marked. The element is a navigation landmark, named by `label`.
12
+ *
13
+ * Three layouts. A **bar** for the lower edge of a phone, in which three to five destinations share
14
+ * the width in equal parts. A **rail** for the side of a wider screen: a narrow column of icons
15
+ * with a word under each. A **list** for a sidebar: an icon and its text in one row, as wide as
16
+ * its place. A rail and a list have a group at their top and one at their lower end, and scroll
17
+ * where they have more destinations than height.
18
+ *
19
+ * `layout="auto"`, the default, is a bar, and where an `el-app-frame` has the element in the
20
+ * column at its side it is what `column` names, a rail or a list: the page writes the
21
+ * destinations once.
22
+ *
23
+ * A second group takes the destinations that have no room among the five of a bar (the
24
+ * `secondary` slot, with `secondary-label` as its heading). A bar leaves it out.
25
+ *
26
+ * In a region of an `el-app-frame` the surface reaches the edge of the screen, and the
27
+ * destinations stay clear of the home indicator and the notch. Alone it keeps them clear itself.
28
+ *
29
+ * The look is the stylesheet alone, so server-rendered destinations do not change when the
30
+ * element takes over. The script adds the tooltips of destinations that show an icon alone.
31
+ *
32
+ * @element el-nav
33
+ *
34
+ * @slot - The destinations: `el-nav-item` elements.
35
+ * @slot secondary - A second group of destinations, below the first: the pages that have no room
36
+ * in a bar, which leaves them out.
37
+ * @slot end - The destinations at the lower end of a rail or a list: the settings, the account. A
38
+ * bar has no room for them, and leaves them out.
39
+ *
40
+ * @csspart base - The navigation landmark (`<nav>`): the surface and its line to the content.
41
+ * @csspart groups - The two groups at the top, which scroll where a rail or a list has more
42
+ * destinations than height.
43
+ * @csspart list - The list of the destinations.
44
+ * @csspart secondary - The second group: its heading and its list.
45
+ * @csspart secondary-label - The heading of the second group, which a list shows.
46
+ * @csspart secondary-list - The list of the destinations of the second group.
47
+ * @csspart end - The list of the destinations at the lower end of a rail or a list.
48
+ * @csspart tooltip - The tooltip of a destination that shows an icon alone: an `el-tooltip`.
49
+ *
50
+ * @cssproperty --el-nav-rail-size - The width of a rail. Default `5rem`.
51
+ * @cssproperty --el-nav-list-size - The width of a list where its place is as wide as what is in
52
+ * it. Default `16rem`.
53
+ *
54
+ * @property {string} label - The name of the navigation for assistive technology, "Main". A page
55
+ * with more than one navigation needs it to tell them apart.
56
+ * @property {'auto'|'bar'|'rail'|'list'} layout - How the destinations lie: `bar`, a row in which
57
+ * they share the width in equal parts; `rail`, a narrow column; `list`, rows of an icon and its
58
+ * text; `auto`, a bar, and in the column at the side of an `el-app-frame` what `column` names.
59
+ * Default `'auto'`.
60
+ * @property {'rail'|'list'} column - What the destinations are in the column at the side of an
61
+ * `el-app-frame`, with `layout="auto"`. Default `'rail'`.
62
+ * @property {string} secondaryLabel - The heading of the second group, and its name for assistive
63
+ * technology: "More". Default `''`.
64
+ * @property {boolean} labels - Whether the destinations show their texts. With `false` they show
65
+ * an icon alone: the text stays the name of the link, and shows as a tooltip. Default `true`.
66
+ */
67
+ export default class Nav extends TemplateElement {
68
+ /**
69
+ * Whether the element has started in a browser, see `connected()`.
70
+ * @private
71
+ */
72
+ _started = false;
73
+
74
+ constructor() {
75
+ super({
76
+ styles: [style],
77
+ shadowRender: true,
78
+ // The tooltips have the texts of the destinations: a destination that comes or goes,
79
+ // and a text that changes, ask for a new render. The filter names the attributes of
80
+ // the element itself as well: element-js hears of them through the same observer.
81
+ mutationObserverOptions: {
82
+ childList: true,
83
+ subtree: true,
84
+ characterData: true,
85
+ attributeFilter: ['label', 'layout', 'column', 'secondary-label', 'labels'],
86
+ },
87
+ });
88
+ }
89
+
90
+ properties() {
91
+ return {
92
+ label: '',
93
+ layout: 'auto',
94
+ column: 'rail',
95
+ secondaryLabel: '',
96
+ labels: true,
97
+ };
98
+ }
99
+
100
+ connected() {
101
+ // The tooltips come with the script: a server renders none, and the first render in the
102
+ // browser is the markup of the server.
103
+ this._started = true;
104
+ if (!this._showsLabels()) this.requestUpdate();
105
+ }
106
+
107
+ events() {
108
+ return {
109
+ // A template element does not render again when a child comes, goes or changes its
110
+ // `slot` attribute. The slot tells of all three, and the event bubbles to the base.
111
+ "[part~='base']": {
112
+ slotchange: () => this.requestUpdate(),
113
+ },
114
+ };
115
+ }
116
+
117
+ /**
118
+ * @private
119
+ * @returns {boolean}
120
+ */
121
+ _showsLabels() {
122
+ return this.labels !== false && this.labels !== 'false';
123
+ }
124
+
125
+ /**
126
+ * The destinations with their texts: what is in a destination and in none of its named slots.
127
+ * None before the element has started, and none while the texts show: a tooltip is for an
128
+ * icon alone, and on a server there is no pointer to show one to.
129
+ * @private
130
+ * @returns {Array<[Element, string]>}
131
+ */
132
+ _named() {
133
+ if (!this._started || this._showsLabels()) return [];
134
+ return [...this.querySelectorAll('el-nav-item')]
135
+ .map((item) => [
136
+ item,
137
+ [...item.childNodes]
138
+ .filter((node) => node.nodeType === Node.TEXT_NODE || !node.getAttribute?.('slot'))
139
+ .map((node) => node.textContent)
140
+ .join(' ')
141
+ .replace(/\s+/g, ' ')
142
+ .trim(),
143
+ ])
144
+ .filter(([, text]) => text);
145
+ }
146
+
147
+ /**
148
+ * Where the tooltip of a destination goes: beside a rail, on the side of the content, and
149
+ * above a bar. The stylesheet decides what the destinations are; this reads what it decided.
150
+ * @private
151
+ * @returns {string}
152
+ */
153
+ _tooltipPlacement() {
154
+ const base = this.shadowRoot.querySelector("[part~='base']");
155
+ if (!base) return 'top';
156
+ const style = getComputedStyle(base);
157
+ if (style.getPropertyValue('--_el-nav-direction').trim() !== 'column') return 'top';
158
+ return style.direction === 'rtl' ? 'left' : 'right';
159
+ }
160
+
161
+ template() {
162
+ const layout = LAYOUTS.includes(this.layout) ? this.layout : 'auto';
163
+ const named = this._named();
164
+ const placement = named.length ? this._tooltipPlacement() : 'top';
165
+
166
+ // The layout is a class of the landmark, not an attribute of the element: a server writes
167
+ // it, and the default has to be on no element for the stylesheet. So is what the column
168
+ // of a frame makes of the destinations.
169
+ // A plain binding leaves a name out while there is none.
170
+ return html`
171
+ <nav
172
+ part="base"
173
+ class="nav nav--${layout} ${this.column === 'list' ? 'nav--column-list' : ''} ${
174
+ this._showsLabels() ? '' : 'nav--icons'
175
+ }"
176
+ aria-label="${this.label || null}"
177
+ >
178
+ <div part="groups" class="groups">
179
+ <div part="list" class="list" role="list"><slot></slot></div>
180
+ <div part="secondary" class="secondary" ?hidden="${!hasSlotted(this, 'secondary')}">
181
+ <div
182
+ part="secondary-label"
183
+ class="heading"
184
+ aria-hidden="true"
185
+ ?hidden="${!this.secondaryLabel}"
186
+ >
187
+ ${this.secondaryLabel}
188
+ </div>
189
+ <div part="secondary-list" class="list" role="list" aria-label="${this.secondaryLabel || null}">
190
+ <slot name="secondary"></slot>
191
+ </div>
192
+ </div>
193
+ </div>
194
+ <div part="end" class="end" role="list" ?hidden="${!hasSlotted(this, 'end')}">
195
+ <slot name="end"></slot>
196
+ </div>
197
+ </nav>
198
+ ${named.map(
199
+ ([item, text]) =>
200
+ html`<el-tooltip part="tooltip" type="label" placement="${placement}" .anchor="${item}"
201
+ >${text}</el-tooltip
202
+ >`,
203
+ )}
204
+ `;
205
+ }
206
+ }
207
+
208
+ export function define() {
209
+ // The tooltips of the destinations that show an icon alone.
210
+ defineTooltip();
211
+ defineElement('el-nav', Nav);
212
+ }