@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,246 @@
1
+ import { TemplateElement, defineElement, html, classMap, spreadAttributes } from '@webtides/element-js';
2
+ import { hasSlotted } from '../../utils/slots.js';
3
+ import style from './tree-item.style.js';
4
+ import Events from './tree-item.events.js';
5
+
6
+ /**
7
+ * One entry of an `el-tree`, and the entries below it. It has the parts of a row of a list: an
8
+ * icon at the start, its name, a count at the end. With `href` the name is a link, and the whole
9
+ * row is its target. An entry with entries below it has a button that opens and closes them; its
10
+ * state is the `open` attribute, which the page can render.
11
+ *
12
+ * The entries below it are the `el-tree-item` elements the page writes into it.
13
+ *
14
+ * @element el-tree-item
15
+ *
16
+ * @fires {CustomEvent<{ open: boolean }>} tree-item-toggle - Fired when the user has opened or
17
+ * closed the entry, with its button or with the arrow keys. `detail.open` is the new state. Not
18
+ * fired when `open` is set from a script. It bubbles: an entry further up hears it as well, so
19
+ * look at `event.target`.
20
+ *
21
+ * @slot - The entries below this one: `el-tree-item` elements.
22
+ * @slot label - The name of the entry. Takes precedence over the `label` attribute.
23
+ * @slot start - What stands in front of the name: an icon.
24
+ * @slot end - What stands at the end of the row: a count. In an entry that is a link it is part
25
+ * of the target of the link.
26
+ *
27
+ * @csspart base - The entry: an item of the list it is in.
28
+ * @csspart row - The row of the entry: its button, its start, its name and its end.
29
+ * @csspart toggle - The button that opens and closes the entries below, present only with such
30
+ * entries.
31
+ * @csspart start - The region of the `start` slot.
32
+ * @csspart label - The name: an `<a>` with `href`; without, a `<button>` that opens and closes
33
+ * the entry when it has entries below it, and a `<span>` when it has none.
34
+ * @csspart end - The region of the `end` slot.
35
+ * @csspart children - The list of the entries below (`role="list"`).
36
+ *
37
+ * @cssproperty --el-tree-indent - How far the entries below stand in from this one. Unset, it is
38
+ * `--el-space-4`, and `1rem` without a theme.
39
+ *
40
+ * @property {string} label - The name of the entry.
41
+ * @property {string} href - The address the entry leads to. Unset, the entry is no link.
42
+ * @property {string} target - Where to open the address (only with `href`).
43
+ * @property {string} rel - `rel` attribute for the link, written when `target` is set. Default
44
+ * `'noreferrer noopener'`.
45
+ * @property {boolean} current - The entry is the one of the page the user is on: it gets
46
+ * `aria-current="page"` (`"true"` without `href`), a bar at its start and a heavier name.
47
+ * Default `false`.
48
+ * @property {boolean} open - Whether the entries below this one are shown. Reflected to the
49
+ * `open` attribute, which the stylesheet reads: an entry without `open="true"` is closed, before
50
+ * the element starts as well. Default `false`.
51
+ */
52
+ export default class TreeItem extends TemplateElement {
53
+ constructor() {
54
+ super({
55
+ styles: [style],
56
+ shadowRender: true,
57
+ // The stylesheet selects the host by this attribute.
58
+ propertyOptions: { open: { reflect: true } },
59
+ });
60
+ }
61
+
62
+ properties() {
63
+ return {
64
+ label: '',
65
+ href: '',
66
+ target: '',
67
+ rel: 'noreferrer noopener',
68
+ current: false,
69
+ open: false,
70
+ };
71
+ }
72
+
73
+ events() {
74
+ return {
75
+ '[data-toggle]': {
76
+ click: () => this.toggle(),
77
+ },
78
+ // A template element does not render again when a child comes, goes or changes its
79
+ // `slot` attribute. The slot tells of all three, and the event bubbles to the base.
80
+ "[part~='base']": {
81
+ slotchange: () => this.requestUpdate(),
82
+ },
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Whether the entry has entries below it. The children of the host are asked, not the slot:
88
+ * a template is rendered on a server too, where there are no slots to ask.
89
+ * @returns {boolean}
90
+ */
91
+ get hasItems() {
92
+ return [...(this.children ?? [])].some((child) => !child.getAttribute('slot'));
93
+ }
94
+
95
+ /**
96
+ * The control of the entry that the focus goes to: its link, or the button its name is when it
97
+ * has entries below it and no address. `null` for a name alone.
98
+ * @returns {HTMLElement | null}
99
+ */
100
+ get focusTarget() {
101
+ return this.shadowRoot?.querySelector('a[part~="label"], button[part~="label"]') ?? null;
102
+ }
103
+
104
+ /**
105
+ * Opens or closes the entry, as its button does, and says so with `tree-item-toggle`. An entry
106
+ * without entries below it stays as it is.
107
+ * @param {boolean} [open] - The state to go to. Left out, the entry goes to the other one.
108
+ * @returns {void}
109
+ */
110
+ toggle(open = !this.open) {
111
+ if (!this.hasItems || !!open === !!this.open) return;
112
+ this.open = !!open;
113
+ this.dispatch(Events.TOGGLE, { open: this.open });
114
+ }
115
+
116
+ /** @private */
117
+ labelContent() {
118
+ return html`<slot name="label">${this.label}</slot>`;
119
+ }
120
+
121
+ /**
122
+ * The name of the entry, and what it is: a link, the button of a branch that leads nowhere, or
123
+ * a text.
124
+ * @private
125
+ */
126
+ labelTemplate(hasItems) {
127
+ if (this.href) {
128
+ return html`
129
+ <a
130
+ part="label"
131
+ id="label"
132
+ class="label"
133
+ href="${this.href}"
134
+ ${spreadAttributes({
135
+ target: this.target || undefined,
136
+ rel: this.target ? this.rel : undefined,
137
+ 'aria-current': this.current ? 'page' : undefined,
138
+ })}
139
+ >${this.labelContent()}</a
140
+ >
141
+ `;
142
+ }
143
+
144
+ const current = { 'aria-current': this.current ? 'true' : undefined };
145
+ if (hasItems) {
146
+ return html`
147
+ <button
148
+ part="label"
149
+ id="label"
150
+ class="label"
151
+ type="button"
152
+ aria-expanded="${this.open ? 'true' : 'false'}"
153
+ aria-controls="children"
154
+ data-toggle
155
+ ${spreadAttributes(current)}
156
+ >
157
+ ${this.labelContent()}
158
+ </button>
159
+ `;
160
+ }
161
+
162
+ return html`<span part="label" id="label" class="label" ${spreadAttributes(current)}
163
+ >${this.labelContent()}</span
164
+ >`;
165
+ }
166
+
167
+ /**
168
+ * The button that opens and closes the entries below: for an entry that is a link, which
169
+ * cannot do both. It is named by the name of the entry, and says whether the entry is open.
170
+ * @private
171
+ */
172
+ toggleTemplate() {
173
+ return html`
174
+ <button
175
+ part="toggle"
176
+ class="toggle"
177
+ type="button"
178
+ aria-labelledby="label"
179
+ aria-expanded="${this.open ? 'true' : 'false'}"
180
+ aria-controls="children"
181
+ data-toggle
182
+ >
183
+ ${this.chevronTemplate()}
184
+ </button>
185
+ `;
186
+ }
187
+
188
+ /** @private */
189
+ chevronTemplate() {
190
+ return html`
191
+ <svg
192
+ class="chevron"
193
+ viewBox="0 0 24 24"
194
+ fill="none"
195
+ stroke="currentColor"
196
+ stroke-width="2"
197
+ stroke-linecap="round"
198
+ stroke-linejoin="round"
199
+ aria-hidden="true"
200
+ >
201
+ <path d="m9 6 6 6-6 6"></path>
202
+ </svg>
203
+ `;
204
+ }
205
+
206
+ template() {
207
+ const hasItems = this.hasItems;
208
+ const isLink = !!this.href;
209
+ const classes = {
210
+ row: true,
211
+ 'row--link': isLink,
212
+ 'row--branch': hasItems,
213
+ 'row--current': !!this.current,
214
+ };
215
+
216
+ // The roles are inside of the shadow root, not on the element: they are part of the
217
+ // server-rendered markup that way, and need no script.
218
+ return html`
219
+ <div part="base" class="item" role="listitem">
220
+ <div part="row" class="${classMap(classes)}">
221
+ ${
222
+ hasItems && isLink
223
+ ? this.toggleTemplate()
224
+ : html`<span class="toggle-place" aria-hidden="true"
225
+ >${hasItems ? this.chevronTemplate() : ''}</span
226
+ >`
227
+ }
228
+ <span part="start" class="start" ?hidden="${!hasSlotted(this, 'start')}"
229
+ ><slot name="start"></slot
230
+ ></span>
231
+ ${this.labelTemplate(hasItems)}
232
+ <span part="end" class="end" ?hidden="${!hasSlotted(this, 'end')}"><slot name="end"></slot></span>
233
+ </div>
234
+ <div part="children" id="children" class="children" role="list" ?hidden="${!hasItems}">
235
+ <slot></slot>
236
+ </div>
237
+ </div>
238
+ `;
239
+ }
240
+ }
241
+
242
+ export function define() {
243
+ defineElement('el-tree-item', TreeItem);
244
+ }
245
+
246
+ export { Events };
@@ -0,0 +1,128 @@
1
+ # TreeItem
2
+
3
+ `tree-item` is one entry of an [`el-tree`](../tree/tree.readme.md), and the entries below it. It has the parts of a row of a list: an icon at the start, its name, a count at the end. With `href` the name is a link. An entry with entries below it opens and closes.
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/tree/define';
17
+ import '@webtides/element-library/tree-item/define';
18
+ ```
19
+
20
+ ```html
21
+ <el-tree label="Folders">
22
+ <el-tree-item label="Inbox" href="/inbox" open="true">
23
+ <el-svg-use slot="start" name="folder" aria-hidden="true"></el-svg-use>
24
+ <span slot="end">12</span>
25
+
26
+ <el-tree-item label="Work" href="/inbox/work" current="true"></el-tree-item>
27
+ <el-tree-item label="Private" href="/inbox/private"></el-tree-item>
28
+ </el-tree-item>
29
+ </el-tree>
30
+ ```
31
+
32
+ The entries below an entry are the `el-tree-item` elements the page writes into it, to any depth.
33
+
34
+ > Boolean attributes are passed as strings (`open="true"`), matching the rest of the library.
35
+
36
+ ## API
37
+
38
+ #### Properties/Attributes
39
+
40
+ | Name | Type | Default | Description |
41
+ | --- | --- | --- | --- |
42
+ | `label` | `string` | `''` | The name of the entry. |
43
+ | `href` | `string` | `''` | The address the entry leads to. Unset, the entry is no link. |
44
+ | `target` | `string` | `''` | Where to open the address (only with `href`). |
45
+ | `rel` | `string` | `'noreferrer noopener'` | `rel` attribute for the link, written when `target` is set. |
46
+ | `current` | `boolean` | `false` | The entry is the one of the page the user is on. |
47
+ | `open` | `boolean` | `false` | Whether the entries below this one are shown. Reflected to the `open` attribute, which the stylesheet reads. |
48
+
49
+ `hasItems` (read only) says whether the entry has entries below it.
50
+
51
+ #### Methods
52
+
53
+ | Name | Description |
54
+ | --- | --- |
55
+ | `toggle(open?)` | Opens or closes the entry, as its button does, and fires `tree-item-toggle`. Without an argument it goes to the other state. An entry without entries below it stays as it is. |
56
+
57
+ #### Events
58
+
59
+ | Name | Detail | Description |
60
+ | --- | --- | --- |
61
+ | `tree-item-toggle` | `{ open: boolean }` | Fired when the user has opened or closed the entry, with its button or with the arrow keys. Not fired when `open` is set from a script. It bubbles, through the entries above and the tree: look at `event.target`. |
62
+
63
+ #### Slots
64
+
65
+ | Name | Description |
66
+ | --- | --- |
67
+ | (default) | The entries below this one: `el-tree-item` elements. |
68
+ | `label` | The name of the entry. Takes precedence over the `label` attribute. |
69
+ | `start` | What stands in front of the name: an icon. |
70
+ | `end` | What stands at the end of the row: a count. In an entry that is a link it is part of the target of the link. |
71
+
72
+ #### CSS Parts
73
+
74
+ | Name | Description |
75
+ | --- | --- |
76
+ | `base` | The entry: an item of the list it is in. |
77
+ | `row` | The row of the entry: its button, its start, its name and its end. |
78
+ | `toggle` | The button that opens and closes the entries below, on an entry that is a link and has such entries. |
79
+ | `start` | The region of the `start` slot. |
80
+ | `label` | The name: an `<a>` with `href`; without, a `<button>` when the entry has entries below it, and a `<span>` when it has none. |
81
+ | `end` | The region of the `end` slot. |
82
+ | `children` | The list of the entries below (`role="list"`). |
83
+
84
+ #### CSS Custom Properties
85
+
86
+ | Name | Default | Description |
87
+ | --- | --- | --- |
88
+ | `--el-tree-indent` | `--el-space-4` | How far the entries below stand in from this one. Set on the tree, or for the page. Without a theme it is `1rem`. |
89
+
90
+ Reads the design tokens of the library: `--el-space-1` and `--el-space-2` for the room in a row, `--el-color-fg` and `--el-color-fg-muted` for the name and the count, `--el-color-accent` for the bar of the current entry, `--el-radius-md` for the corners of a row, `--el-focus-ring-*` for the focus ring.
91
+
92
+ ## The row
93
+
94
+ A row is as wide as the tree on every level: the fill of the row under the pointer, and of the current entry, reaches from edge to edge, and what stands in the row is moved in by the level. Every row has the place of the button of a branch, with or without entries below, so the names of a level begin on one line.
95
+
96
+ A name that is longer than the tree breaks into more lines, inside of a word where it has to.
97
+
98
+ ## A link, a branch, a name
99
+
100
+ - **With `href`** the name is a native link, and its target is the whole row: the start, the name, the end and the room around them. An entry that also has entries below it gets a button in front of the name, which opens and closes them. The button lies on top of the link and is a target of its own.
101
+ - **Without `href`, with entries below**, the entry is a button as a whole: a click anywhere on its row opens and closes it. That is a category that leads nowhere itself.
102
+ - **Without `href` and without entries below**, the entry is a text.
103
+
104
+ ## Opening and closing
105
+
106
+ `open="true"` shows the entries below. The stylesheet of the entry reads that attribute, so a server-rendered entry is open or closed from the first paint. The button of a branch, the arrow keys of the tree and `toggle()` change it and fire `tree-item-toggle`; setting `open` from a script changes it and fires nothing.
107
+
108
+ An entry without entries below it has no button and no state: `open` does nothing there. When entries come later, the button comes with them.
109
+
110
+ ## The current entry
111
+
112
+ `current` marks the entry of the page the user is on. With `href` its link gets `aria-current="page"`, without it the name gets `aria-current="true"`.
113
+
114
+ It is told apart by a tint of the text colour, by a bar at its start in the accent colour and by a heavier name. The bar and the weight do not depend on a colour: where the user forces colours, the bar is drawn in a colour of the system.
115
+
116
+ The tree does not open the branches above the current entry. Render them open.
117
+
118
+ ## Accessibility
119
+
120
+ - The entry has `role="listitem"`, and the entries below it are in a list of their own (`role="list"`).
121
+ - The button of a branch is named by the name of its entry (`aria-labelledby`), says whether the branch is open (`aria-expanded`) and which list it opens (`aria-controls`).
122
+ - An icon in `start` that only repeats the name should be hidden from assistive technology (`aria-hidden="true"`).
123
+ - For the keyboard, see [`el-tree`](../tree/tree.readme.md#keyboard).
124
+ - On a touch screen (`@media (any-pointer: coarse)`) a row that is a target is at least `--el-touch-target` high, and the button of a branch is that wide and high.
125
+
126
+ ## Server-side rendering
127
+
128
+ The entry, its link, its button and the list below it are part of the server-rendered markup (Declarative Shadow DOM). Whether the entry has entries below it is asked of its children, which a server knows as well. Its links work before the script has run; opening and closing needs the script.
@@ -0,0 +1,226 @@
1
+ import hostStyle from '../../styles/host.style.js';
2
+
3
+ const css = String.raw;
4
+
5
+ const style = css`
6
+ /*
7
+ * How far in the entry stands. An entry takes what the list it is in hands down, and hands
8
+ * down one step more to the list below it. The two have different names: a property cannot be
9
+ * counted up from its own inherited value.
10
+ */
11
+ :host {
12
+ display: block;
13
+ --_el-tree-indent: var(--_el-tree-indent-below, 0px);
14
+ }
15
+
16
+ .children {
17
+ --_el-tree-indent-below: calc(var(--_el-tree-indent) + var(--el-tree-indent, var(--el-space-4, 1rem)));
18
+ }
19
+
20
+ /* Closed unless the host is open. The rule reads the attribute of the host, which is all there
21
+ is before the element starts: a server-rendered tree shows its open branches, and no other,
22
+ from the first paint. */
23
+ :host(:not([open='true'])) .children {
24
+ display: none;
25
+ }
26
+
27
+ /* ── Row ──────────────────────────────────────────────────────────────── */
28
+
29
+ /* As wide as the tree, on every level: the fill of a row under the pointer and of the current
30
+ row reaches from edge to edge, and what stands in the row is moved in. */
31
+ .row {
32
+ --_el-tree-row-padding: var(--el-space-2, 0.5rem);
33
+ --_el-tree-toggle-size: 1.5rem;
34
+
35
+ display: flex;
36
+ align-items: center;
37
+ gap: var(--el-space-1, 0.25rem);
38
+ /* The link of an entry is as large as this box, and the button that opens the entry lies
39
+ on top of it. Both stay inside of the row. */
40
+ position: relative;
41
+ isolation: isolate;
42
+ min-width: 0;
43
+ padding-block: var(--el-space-1, 0.25rem);
44
+ padding-inline: calc(var(--_el-tree-row-padding) + var(--_el-tree-indent)) var(--_el-tree-row-padding);
45
+ border-radius: var(--el-radius-md, 0);
46
+ color: var(--el-color-fg, inherit);
47
+ font-family: var(--el-font-family, inherit);
48
+ font-size: var(--el-font-size-md, inherit);
49
+ line-height: var(--el-line-height, inherit);
50
+ transition: background var(--el-duration-md, 0s) var(--el-ease, linear);
51
+ }
52
+
53
+ /* ── Button of a branch ───────────────────────────────────────────────── */
54
+
55
+ /* Every row has the place of the button, with or without entries below: the names of a level
56
+ begin on one line. */
57
+ .toggle,
58
+ .toggle-place {
59
+ display: inline-flex;
60
+ flex: none;
61
+ align-items: center;
62
+ justify-content: center;
63
+ width: var(--_el-tree-toggle-size);
64
+ height: var(--_el-tree-toggle-size);
65
+ color: var(--el-color-fg-muted, inherit);
66
+ }
67
+
68
+ .toggle {
69
+ /* On top of the link of the row: a target of its own. */
70
+ position: relative;
71
+ z-index: 1;
72
+ margin: 0;
73
+ padding: 0;
74
+ border: none;
75
+ border-radius: var(--el-radius-sm, 2px);
76
+ background: transparent;
77
+ font: inherit;
78
+ cursor: pointer;
79
+ }
80
+
81
+ @media (hover: hover) {
82
+ .toggle:hover {
83
+ background: color-mix(in srgb, currentColor 16%, transparent);
84
+ }
85
+ }
86
+
87
+ .toggle:focus-visible {
88
+ outline: var(--el-focus-ring-width, 2px) solid var(--el-color-focus-ring, currentColor);
89
+ outline-offset: calc(-1 * var(--el-focus-ring-width, 2px));
90
+ }
91
+
92
+ /* It points along the reading direction while the entry is closed, and down while it is open. */
93
+ .chevron {
94
+ width: 1em;
95
+ height: 1em;
96
+ transition: rotate var(--el-duration-md, 0s) var(--el-ease, linear);
97
+ }
98
+
99
+ :host(:dir(rtl)) .chevron {
100
+ scale: -1 1;
101
+ }
102
+
103
+ :host([open='true']) .chevron {
104
+ rotate: 90deg;
105
+ }
106
+
107
+ :host([open='true']:dir(rtl)) .chevron {
108
+ rotate: -90deg;
109
+ }
110
+
111
+ /* ── Start, name, end ─────────────────────────────────────────────────── */
112
+
113
+ .start {
114
+ display: inline-flex;
115
+ flex: none;
116
+ align-items: center;
117
+ }
118
+
119
+ /* A name a user typed cannot widen the tree: it breaks, inside of a word where it has to. */
120
+ .label {
121
+ flex: 1 1 auto;
122
+ min-width: 0;
123
+ margin: 0;
124
+ padding: 0;
125
+ border: none;
126
+ background: none;
127
+ color: inherit;
128
+ font: inherit;
129
+ text-align: start;
130
+ text-decoration: none;
131
+ overflow-wrap: anywhere;
132
+ }
133
+
134
+ button.label {
135
+ cursor: pointer;
136
+ }
137
+
138
+ /* A count: quieter than the name. */
139
+ .end {
140
+ display: inline-flex;
141
+ flex: none;
142
+ align-items: center;
143
+ color: var(--el-color-fg-muted, inherit);
144
+ font-size: var(--el-font-size-sm, 0.875em);
145
+ }
146
+
147
+ /* ── A row that leads somewhere, or opens ─────────────────────────────── */
148
+
149
+ /* The target of the link, and of a name that is a button, is the whole row: the box of the
150
+ row, drawn by the name. It lies on the start and the end, and under the button of a branch
151
+ that is a link. */
152
+ a.label::after,
153
+ button.label::after {
154
+ content: '';
155
+ position: absolute;
156
+ inset: 0;
157
+ border-radius: inherit;
158
+ }
159
+
160
+ .row:has(a.label, button.label) {
161
+ cursor: pointer;
162
+ }
163
+
164
+ /* A tint of the text colour, which shows on every background. Hover only where the pointer
165
+ can hover: a touch screen leaves :hover on the row that was tapped last. */
166
+ @media (hover: hover) {
167
+ .row:has(.label:is(a, button):hover) {
168
+ background: color-mix(in srgb, currentColor 8%, transparent);
169
+ }
170
+ }
171
+
172
+ .row:has(.label:is(a, button):active) {
173
+ background: color-mix(in srgb, currentColor 16%, transparent);
174
+ }
175
+
176
+ /* The ring of a theme, and without one a ring in the colour of the text. It is drawn around
177
+ the row and inside of it. */
178
+ .label:focus-visible {
179
+ outline: none;
180
+ }
181
+
182
+ .label:focus-visible::after {
183
+ outline: var(--el-focus-ring-width, 2px) solid var(--el-color-focus-ring, currentColor);
184
+ outline-offset: calc(-1 * var(--el-focus-ring-width, 2px));
185
+ }
186
+
187
+ /* ── The current entry ────────────────────────────────────────────────── */
188
+
189
+ /* A fill, a bar at the start and a heavier name. The bar and the weight tell the entry apart
190
+ without a colour; the bar is a border, which forced colours keep. */
191
+ .row--current {
192
+ background: color-mix(in srgb, currentColor 8%, transparent);
193
+ }
194
+
195
+ .row--current::before {
196
+ content: '';
197
+ position: absolute;
198
+ inset-block: 0;
199
+ inset-inline-start: 0;
200
+ border-inline-start: 0.1875rem solid var(--el-color-accent, currentColor);
201
+ border-start-start-radius: inherit;
202
+ border-end-start-radius: inherit;
203
+ pointer-events: none;
204
+ }
205
+
206
+ .row--current .label {
207
+ font-weight: var(--el-font-weight-semibold, 600);
208
+ }
209
+
210
+ /* ── Touch screens ────────────────────────────────────────────────────── */
211
+
212
+ /* On a coarse pointer a row that is a target is at least --el-touch-target high, and so is the
213
+ button of a branch, in both directions. Without the token the sizes stay as they are. */
214
+ @media (any-pointer: coarse) {
215
+ .row:has(a.label, button.label) {
216
+ min-height: var(--el-touch-target, auto);
217
+ }
218
+
219
+ .toggle {
220
+ min-width: var(--el-touch-target, var(--_el-tree-toggle-size));
221
+ min-height: var(--el-touch-target, var(--_el-tree-toggle-size));
222
+ }
223
+ }
224
+ `;
225
+
226
+ export default [hostStyle(), style].join('\n');
@@ -40,3 +40,50 @@ export default function appearanceStyle(surface, host = ':host') {
40
40
  }
41
41
  `;
42
42
  }
43
+
44
+ /**
45
+ * The appearance a container gives to the controls inside of it: a toolbar with
46
+ * `appearance="plain"` has plain buttons. The container declares `appearance` as a reflected
47
+ * property and composes this module; it sets one of two properties on the host, which are
48
+ * inherited at any depth and into shadow roots:
49
+ *
50
+ * - `--_el-context-appearance-outlined`
51
+ * - `--_el-context-appearance-plain`
52
+ *
53
+ * Each is a switch: it is set to nothing, or it is not set. A stylesheet cannot ask for the value
54
+ * of a property, so the control puts the switch in front of a value in a property of its own,
55
+ * which is valid only where the switch is set, and falls back from one to the next:
56
+ *
57
+ * --_el-button-if-plain: var(--_el-context-appearance-plain) transparent;
58
+ * background: var(--_el-button-if-plain, var(--_el-variant-fill));
59
+ *
60
+ * Outside of a container none of the switches is set, and the control paints what it painted
61
+ * before, with the same values. As with the size, the control only does so while the page has not
62
+ * given it an appearance of its own, and marks that from its template.
63
+ *
64
+ * `filled` sets nothing: it is the appearance a control has anyway.
65
+ *
66
+ * The appearance a container has without the attribute is given as `byDefault`. The rule for it
67
+ * selects a host that has no `appearance` attribute as well: element-js writes the default onto
68
+ * the element when it starts, and in server-rendered markup it is not there yet.
69
+ * @param {string} [host] - `':host'` (the default), or the tag of a component without a shadow root.
70
+ * @param {'filled'|'outlined'|'plain'} [byDefault] - The appearance of a container without the
71
+ * attribute. Default `'filled'`.
72
+ * @returns {string}
73
+ */
74
+ export function appearanceContextStyle(host = ':host', byDefault = 'filled') {
75
+ const selectorOf = (appearance) =>
76
+ [`[appearance='${appearance}']`, ...(appearance === byDefault ? [':not([appearance])'] : [])]
77
+ .map((condition) => hostSelector(host, condition))
78
+ .join(',\n ');
79
+
80
+ return css`
81
+ ${selectorOf('outlined')} {
82
+ --_el-context-appearance-outlined: ;
83
+ }
84
+
85
+ ${selectorOf('plain')} {
86
+ --_el-context-appearance-plain: ;
87
+ }
88
+ `;
89
+ }