@webtides/element-library 0.4.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/custom-elements.json +1543 -199
  3. package/package.json +1 -1
  4. package/src/components/app-frame/app-frame.changelog.md +14 -0
  5. package/src/components/app-frame/app-frame.js +14 -2
  6. package/src/components/app-frame/app-frame.readme.md +12 -3
  7. package/src/components/app-frame/app-frame.style.js +7 -0
  8. package/src/components/button/button.changelog.md +6 -0
  9. package/src/components/button/button.style.js +6 -1
  10. package/src/components/button-group/button-group.changelog.md +10 -0
  11. package/src/components/button-group/button-group.readme.md +2 -0
  12. package/src/components/button-group/button-group.style.js +6 -2
  13. package/src/components/checkbox-group-field/checkbox-group-field.changelog.md +6 -0
  14. package/src/components/checkbox-group-field/checkbox-group-field.js +7 -2
  15. package/src/components/checkbox-group-field/checkbox-group-field.readme.md +23 -1
  16. package/src/components/combobox-field/combobox-field.changelog.md +6 -0
  17. package/src/components/combobox-field/combobox-field.readme.md +8 -0
  18. package/src/components/combobox-field/combobox-field.style.js +2 -0
  19. package/src/components/date-field/date-field.changelog.md +6 -0
  20. package/src/components/date-field/date-field.readme.md +10 -0
  21. package/src/components/date-field/date-field.style.js +8 -3
  22. package/src/components/description-list/description-list.changelog.md +17 -0
  23. package/src/components/description-list/description-list.js +7 -2
  24. package/src/components/description-list/description-list.readme.md +30 -4
  25. package/src/components/description-list/description-list.style.js +57 -28
  26. package/src/components/divider/divider.changelog.md +6 -0
  27. package/src/components/divider/divider.readme.md +1 -1
  28. package/src/components/divider/divider.style.js +6 -0
  29. package/src/components/file-field/file-field.changelog.md +8 -0
  30. package/src/components/file-field/file-field.js +135 -5
  31. package/src/components/file-field/file-field.readme.md +35 -6
  32. package/src/components/file-field/file-field.style.js +71 -0
  33. package/src/components/form-field/form-field.js +1 -1
  34. package/src/components/input-field/input-field.changelog.md +10 -0
  35. package/src/components/input-field/input-field.js +192 -14
  36. package/src/components/input-field/input-field.readme.md +88 -2
  37. package/src/components/input-field/input-field.style.js +2 -0
  38. package/src/components/list/list.changelog.md +6 -0
  39. package/src/components/list/list.js +2 -0
  40. package/src/components/list/list.readme.md +1 -0
  41. package/src/components/list-item/list-item.changelog.md +16 -0
  42. package/src/components/list-item/list-item.js +2 -0
  43. package/src/components/list-item/list-item.readme.md +19 -1
  44. package/src/components/list-item/list-item.style.js +23 -11
  45. package/src/components/menu/menu.changelog.md +17 -0
  46. package/src/components/menu/menu.js +293 -70
  47. package/src/components/menu/menu.readme.md +47 -6
  48. package/src/components/menu/menu.style.js +6 -2
  49. package/src/components/menu-item/menu-item.changelog.md +8 -0
  50. package/src/components/menu-item/menu-item.js +41 -3
  51. package/src/components/menu-item/menu-item.readme.md +45 -7
  52. package/src/components/menu-item/menu-item.style.js +30 -0
  53. package/src/components/otp-field/otp-field.changelog.md +6 -0
  54. package/src/components/otp-field/otp-field.readme.md +8 -0
  55. package/src/components/otp-field/otp-field.style.js +8 -3
  56. package/src/components/password-field/password-field.changelog.md +7 -0
  57. package/src/components/password-field/password-field.readme.md +11 -1
  58. package/src/components/password-field/password-field.style.js +2 -0
  59. package/src/components/popover/popover.changelog.md +6 -0
  60. package/src/components/popover/popover.style.js +1 -0
  61. package/src/components/radio-field/radio-field.changelog.md +6 -0
  62. package/src/components/radio-field/radio-field.js +7 -2
  63. package/src/components/radio-field/radio-field.readme.md +23 -1
  64. package/src/components/textarea-field/textarea-field.changelog.md +6 -0
  65. package/src/components/textarea-field/textarea-field.js +14 -1
  66. package/src/components/textarea-field/textarea-field.readme.md +23 -1
  67. package/src/styles/choice-group.style.js +26 -0
  68. package/src/styles/input-control.style.js +87 -0
  69. package/src/styles/native.css +100 -0
  70. package/src/utils/floating.js +15 -1
  71. package/src/utils/options.js +35 -0
  72. package/src/utils/text-entry-attributes.js +13 -0
  73. package/types/src/components/app-frame/app-frame.d.ts +7 -1
  74. package/types/src/components/checkbox-group-field/checkbox-group-field.d.ts +5 -2
  75. package/types/src/components/combobox-field/combobox-field.d.ts +10 -0
  76. package/types/src/components/date-field/date-field.d.ts +10 -0
  77. package/types/src/components/description-list/description-list.d.ts +7 -2
  78. package/types/src/components/file-field/file-field.d.ts +68 -3
  79. package/types/src/components/form-field/form-field.d.ts +1 -1
  80. package/types/src/components/input-field/input-field.d.ts +99 -0
  81. package/types/src/components/list/list.d.ts +2 -0
  82. package/types/src/components/list-item/list-item.d.ts +2 -0
  83. package/types/src/components/menu/menu.d.ts +105 -9
  84. package/types/src/components/menu-item/menu-item.d.ts +21 -0
  85. package/types/src/components/otp-field/otp-field.d.ts +10 -0
  86. package/types/src/components/password-field/password-field.d.ts +10 -0
  87. package/types/src/components/radio-field/radio-field.d.ts +5 -2
  88. package/types/src/components/textarea-field/textarea-field.d.ts +7 -0
  89. package/types/src/styles/input-control.style.d.ts +15 -0
  90. package/types/src/utils/floating.d.ts +11 -0
  91. package/types/src/utils/options.d.ts +17 -0
  92. package/types/src/utils/text-entry-attributes.d.ts +10 -0
  93. package/web-types.json +514 -24
@@ -0,0 +1,87 @@
1
+ import { hostSelector } from './host.style.js';
2
+
3
+ const css = String.raw;
4
+
5
+ /**
6
+ * The control of a text field that has more in it than its input: content of the page at its
7
+ * start and at its end (an icon, a unit, a button), and the button that clears it. `.control` is
8
+ * the row with the input in its middle. A field renders it only while there is such content.
9
+ *
10
+ * This is the layout of that row, and the button. That the row is the control to the eye, with
11
+ * the border, the surface and the focus ring around all of it and none on the input, is the part
12
+ * of `styles/native.css`, as the border of an input alone is. Without that file the input keeps
13
+ * the look of the browser, and the content stands beside it in the row.
14
+ *
15
+ * The row follows the reading direction: the start is at the right in a right-to-left page.
16
+ * @param {string} [host] - `':host'` (the default), or the tag of a field without a shadow root.
17
+ * @returns {string}
18
+ */
19
+ export default function inputControlStyle(host = ':host') {
20
+ const field = hostSelector(host);
21
+
22
+ return css`
23
+ ${field} .control {
24
+ display: flex;
25
+ flex: 1 1 auto;
26
+ align-items: center;
27
+ gap: var(--el-space-2, 8px);
28
+ min-inline-size: 0;
29
+ }
30
+
31
+ /* The input takes the room that is left, and gives way to the content beside it. */
32
+ ${field} .control input {
33
+ flex: 1 1 auto;
34
+ min-inline-size: 0;
35
+ }
36
+
37
+ /* What the page has put at the start or at the end: as wide as it is, in one line, in
38
+ the muted colour of the theme. A control in it has its own colours. */
39
+ ${field} .control-content {
40
+ display: inline-flex;
41
+ flex: none;
42
+ align-items: center;
43
+ gap: var(--el-space-1, 4px);
44
+ color: var(--el-color-fg-muted, inherit);
45
+ white-space: nowrap;
46
+ }
47
+
48
+ ${field} .control-content[hidden],
49
+ ${field} .control-clear[hidden] {
50
+ display: none;
51
+ }
52
+
53
+ ${field} .control-clear {
54
+ display: inline-flex;
55
+ flex: none;
56
+ align-items: center;
57
+ justify-content: center;
58
+ padding: 0;
59
+ border: none;
60
+ border-radius: var(--el-radius-sm, 0);
61
+ background: transparent;
62
+ color: var(--el-color-fg-muted, inherit);
63
+ font: inherit;
64
+ line-height: 0;
65
+ cursor: pointer;
66
+ }
67
+
68
+ ${field} .control-clear:focus-visible {
69
+ outline: var(--el-focus-ring-width, 2px) solid var(--el-color-focus-ring, currentColor);
70
+ outline-offset: 2px;
71
+ }
72
+
73
+ ${field} .control-clear svg {
74
+ width: 1em;
75
+ height: 1em;
76
+ }
77
+
78
+ /* On a touch screen the button is at least as large as a finger needs. Without the token
79
+ it stays as it is. */
80
+ @media (any-pointer: coarse) {
81
+ ${field} .control-clear {
82
+ min-inline-size: var(--el-touch-target, auto);
83
+ min-block-size: var(--el-touch-target, auto);
84
+ }
85
+ }
86
+ `;
87
+ }
@@ -133,6 +133,106 @@ el-select-field select:disabled ~ .dropdown-indicator {
133
133
  cursor: not-allowed;
134
134
  }
135
135
 
136
+ /*
137
+ * A text field with content of the page in its control: something at the start
138
+ * or at the end of it, or the button that clears it. The field renders a row
139
+ * around its input for that (.control), and the row is the control to the eye:
140
+ * it has the border, the surface and the focus ring, and the input inside of
141
+ * it has none of them. It is as high as an input of its size alone.
142
+ *
143
+ * The rules for the input in the row name the row, so they win over the rules
144
+ * for an input above whichever comes first.
145
+ */
146
+ el-input-field .control,
147
+ el-password-field .control,
148
+ el-otp-field .control,
149
+ el-combobox-field .control,
150
+ el-date-field .control {
151
+ box-sizing: border-box;
152
+ width: 100%;
153
+ min-height: calc(var(--el-control-height) * var(--_el-size-scale, 1));
154
+ border: var(--el-border-width) solid var(--el-color-border);
155
+ border-radius: var(--el-radius-md);
156
+ padding-inline: var(--el-space-3);
157
+ background: var(--el-color-bg);
158
+ color: var(--el-color-fg);
159
+ font-family: var(--el-font-family);
160
+ font-size: var(--_el-size-font-size, var(--el-font-size-md));
161
+ line-height: var(--el-line-height);
162
+ transition:
163
+ border-color var(--el-duration-md) var(--el-ease),
164
+ box-shadow var(--el-duration-md) var(--el-ease);
165
+ }
166
+
167
+ @media (any-pointer: coarse) {
168
+ el-input-field .control,
169
+ el-password-field .control,
170
+ el-otp-field .control,
171
+ el-combobox-field .control,
172
+ el-date-field .control {
173
+ min-height: max(calc(var(--el-control-height) * var(--_el-size-scale, 1)), var(--el-touch-target, 0px));
174
+ }
175
+ }
176
+
177
+ el-input-field .control input,
178
+ el-password-field .control input,
179
+ el-otp-field .control input,
180
+ el-combobox-field .control input,
181
+ el-date-field .control input {
182
+ min-height: 0;
183
+ border: 0;
184
+ border-radius: 0;
185
+ padding-inline: 0;
186
+ background: transparent;
187
+ font-size: inherit;
188
+ }
189
+
190
+ el-input-field .control input:focus,
191
+ el-password-field .control input:focus,
192
+ el-otp-field .control input:focus,
193
+ el-combobox-field .control input:focus,
194
+ el-date-field .control input:focus {
195
+ box-shadow: none;
196
+ }
197
+
198
+ /* The ring is for the input: a button in the row has its own. */
199
+ el-input-field .control:has(input:focus),
200
+ el-password-field .control:has(input:focus),
201
+ el-otp-field .control:has(input:focus),
202
+ el-combobox-field .control:has(input:focus),
203
+ el-date-field .control:has(input:focus) {
204
+ border-color: var(--el-color-focus-ring);
205
+ box-shadow:
206
+ 0 0 0 var(--el-focus-ring-offset) var(--el-color-bg),
207
+ 0 0 0 calc(var(--el-focus-ring-offset) + var(--el-focus-ring-width)) var(--el-color-focus-ring);
208
+ }
209
+
210
+ el-input-field:state(invalid) .control,
211
+ el-password-field:state(invalid) .control,
212
+ el-otp-field:state(invalid) .control,
213
+ el-combobox-field:state(invalid) .control,
214
+ el-date-field:state(invalid) .control {
215
+ border-color: var(--el-color-danger);
216
+ }
217
+
218
+ /* The row fades as a whole, and its input not a second time. */
219
+ el-input-field .control:has(input:disabled),
220
+ el-password-field .control:has(input:disabled),
221
+ el-otp-field .control:has(input:disabled),
222
+ el-combobox-field .control:has(input:disabled),
223
+ el-date-field .control:has(input:disabled) {
224
+ opacity: 0.55;
225
+ cursor: not-allowed;
226
+ }
227
+
228
+ el-input-field .control input:disabled,
229
+ el-password-field .control input:disabled,
230
+ el-otp-field .control input:disabled,
231
+ el-combobox-field .control input:disabled,
232
+ el-date-field .control input:disabled {
233
+ opacity: 1;
234
+ }
235
+
136
236
  /*
137
237
  * The parts of a date (day, month, year) stand in a wrapper that has a padding
138
238
  * of its own above and below. Without it the control is as high as an input
@@ -1,4 +1,4 @@
1
- import { arrow, autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom';
1
+ import { arrow, autoUpdate, computePosition, flip, getOverflowAncestors, offset, shift } from '@floating-ui/dom';
2
2
 
3
3
  /** How close to the edge of the viewport a floating element may come, and its arrow to one of its corners. */
4
4
  const EDGE_PADDING = 8;
@@ -69,3 +69,17 @@ export async function placeAtAnchor(anchor, floating, { placement, distance = 0,
69
69
  export function followAnchor(anchor, floating, update) {
70
70
  return autoUpdate(anchor, floating, update);
71
71
  }
72
+
73
+ /**
74
+ * What scrolls an element away: the regions around it that scroll, and the window for the page.
75
+ * The way up goes through slots and out of shadow roots, so the region of an `el-app-frame` is
76
+ * one of them for what is in its content.
77
+ *
78
+ * A `scroll` event does not bubble and does not leave a shadow root: who wants to know that an
79
+ * element has moved listens on each of these.
80
+ * @param {Element} element
81
+ * @returns {Array<Element | Window>}
82
+ */
83
+ export function scrollersOf(element) {
84
+ return getOverflowAncestors(element).filter((scroller) => scroller instanceof Element || scroller === window);
85
+ }
@@ -0,0 +1,35 @@
1
+ import { html } from '@webtides/element-js';
2
+
3
+ /**
4
+ * What an option of a group of choices shows in front of its label: a dot in the colour the option
5
+ * names (`color`), and an icon, the address of an SVG symbol (`icon`: `'#tag'`,
6
+ * `'/icons.svg#tag'`), as an option of `el-segmented-field` has it.
7
+ *
8
+ * Both are decorations. The label is the name of the option, so what is in front of it is hidden
9
+ * from assistive technology as a whole.
10
+ *
11
+ * Nothing for an option that has neither, a plain text among them: such an option has the markup
12
+ * it had.
13
+ * @param {string | { color?: string, icon?: string }} option
14
+ * @returns {import('@webtides/element-js').TemplateResult | null}
15
+ */
16
+ export function optionStartTemplate(option) {
17
+ const color = option?.color;
18
+ const icon = option?.icon;
19
+ if (!color && !icon) return null;
20
+
21
+ // Each drawing is a whole <svg>: a part of one that comes from another template would be no
22
+ // part of the drawing.
23
+ return html`
24
+ <span class="option-start" aria-hidden="true">
25
+ ${color ? html`<span class="option-color" style="--_el-option-color: ${color}"></span>` : null}
26
+ ${
27
+ icon
28
+ ? html`<svg class="option-icon" focusable="false">
29
+ <use href="${icon}"></use>
30
+ </svg>`
31
+ : null
32
+ }
33
+ </span>
34
+ `;
35
+ }
@@ -49,3 +49,16 @@ export function shadowNativeTextEntryProperties(element) {
49
49
  export function textEntryAttributes(element) {
50
50
  return Object.fromEntries(TEXT_ENTRY_ATTRIBUTES.map((name) => [name, element[name] ?? null]));
51
51
  }
52
+
53
+ /**
54
+ * `maxlength` or `minlength` for the control: the number of the field, or `null` for one that is
55
+ * not set, which a plain binding leaves out.
56
+ *
57
+ * Empty is not set as well. element-js keeps an attribute that was on the field when it started:
58
+ * taken off, or with its property set to `null`, it is written back empty.
59
+ * @param {number | string | null | undefined} value
60
+ * @returns {number | string | null}
61
+ */
62
+ export function lengthAttribute(value) {
63
+ return value === '' || value === undefined ? null : value;
64
+ }
@@ -9,7 +9,8 @@ import Events from './app-frame.events.js';
9
9
  * landmarks, and slots them: `<header slot="header">`, `<nav slot="navigation" aria-label="…">`,
10
10
  * `<main id="…">`, `<aside slot="aside">`, `<footer slot="footer">`. The frame adds the layout,
11
11
  * the room for the notch and the home indicator of a phone, and a link that skips to the content
12
- * as the first stop of the Tab key.
12
+ * as the first stop of the Tab key. That link lies in the one landmark the frame has of its own,
13
+ * a navigation the page names (`skip-landmark-label`): content of a page belongs into a landmark.
13
14
  *
14
15
  * From the width `wide-from` names, the navigation and the aside are columns beside the content,
15
16
  * and each scrolls on its own. Where the frame is narrow, the content and the aside are one
@@ -54,6 +55,7 @@ import Events from './app-frame.events.js';
54
55
  * @slot footer - The region at the lower edge. Left out while it is empty.
55
56
  *
56
57
  * @csspart base - The frame: the grid of the regions.
58
+ * @csspart skip-landmark - The landmark the skip link lies in: a `<nav>`.
57
59
  * @csspart skip-link - The link that skips to the content. It shows while it has the focus.
58
60
  * @csspart header - The region at the top. Its surface reaches under the status bar of a phone.
59
61
  * @csspart navigation - The region at the start side, where the frame is wide.
@@ -89,6 +91,9 @@ import Events from './app-frame.events.js';
89
91
  *
90
92
  * @property {string} skipLabel - The text of the link that skips to the content. Default
91
93
  * `'Skip to content'`.
94
+ * @property {string} skipLandmarkLabel - The name of the landmark that link lies in, a
95
+ * navigation, for assistive technology. It has to differ from the names of the other
96
+ * navigations of the page. Default `'Skip link'`.
92
97
  * @property {'30rem'|'40rem'|'48rem'|'64rem'|'80rem'} wideFrom - The width of the frame from
93
98
  * which the navigation and the aside are columns beside the content. One of the steps the
94
99
  * stylesheet knows, another value is the default. Default `'48rem'`.
@@ -204,6 +209,7 @@ export default class AppFrame extends TemplateElement {
204
209
  constructor();
205
210
  properties(): {
206
211
  skipLabel: string;
212
+ skipLandmarkLabel: string;
207
213
  wideFrom: string;
208
214
  narrowOnly: string;
209
215
  wideOnly: string;
@@ -18,9 +18,12 @@ import FormField from '../form-field/form-field.js';
18
18
  *
19
19
  * @property {string[]} value - The values of the checked options, in the order of the options. As
20
20
  * an attribute it is JSON: `value='["news", "offers"]'`.
21
- * @property {Array<string | { value: string, label?: string, disabled?: boolean }>} options -
21
+ * @property {Array<string | { value: string, label?: string, disabled?: boolean, color?: string, icon?: string }>} options -
22
22
  * Options to render. Accepts plain strings (`['News', 'Offers']`) or option objects
23
- * (`[{ value, label, disabled? }]`). Strings are used as both value and label.
23
+ * (`[{ value, label, disabled? }]`). Strings are used as both value and label. An object can
24
+ * name a `color`, which is drawn as a dot in front of the label, and an `icon`, the address of
25
+ * an SVG symbol (`'#tag'`, `'/icons.svg#tag'`), which is drawn there as well. Both are
26
+ * decorations: the label stays the name of the option.
24
27
  * @property {boolean} required - Whether at least one option has to be checked.
25
28
  */
26
29
  export default class CheckboxGroupField extends FormField {
@@ -35,6 +35,10 @@ export default class ComboboxField extends InputField {
35
35
  size: string;
36
36
  placeholder: string;
37
37
  pattern: boolean;
38
+ clearable: boolean;
39
+ clearLabel: string;
40
+ maxlength: any;
41
+ minlength: any;
38
42
  autocomplete: any;
39
43
  inputmode: any;
40
44
  enterkeyhint: any;
@@ -51,6 +55,12 @@ export default class ComboboxField extends InputField {
51
55
  click: () => void;
52
56
  touchstart: () => void;
53
57
  };
58
+ '.control': {
59
+ click: (event: any) => void;
60
+ };
61
+ '[data-clear]': {
62
+ click: () => void;
63
+ };
54
64
  '[ref=input]': {
55
65
  focus: () => void;
56
66
  blur: () => void;
@@ -43,6 +43,10 @@ export default class DateField extends InputField {
43
43
  size: string;
44
44
  placeholder: string;
45
45
  pattern: boolean;
46
+ clearable: boolean;
47
+ clearLabel: string;
48
+ maxlength: any;
49
+ minlength: any;
46
50
  autocomplete: any;
47
51
  inputmode: any;
48
52
  enterkeyhint: any;
@@ -68,6 +72,12 @@ export default class DateField extends InputField {
68
72
  click: () => void;
69
73
  touchstart: () => void;
70
74
  };
75
+ '.control': {
76
+ click: (event: any) => void;
77
+ };
78
+ '[data-clear]': {
79
+ click: () => void;
80
+ };
71
81
  '[ref=input]': {
72
82
  focus: () => void;
73
83
  blur: () => void;
@@ -19,8 +19,13 @@ import { TemplateElement } from '@webtides/element-js';
19
19
  * @csspart base - The `<dl>`.
20
20
  *
21
21
  * @cssproperty --el-description-list-term-width - The width of the column of the names while
22
- * names and values stand side by side. Unset, the column is as wide as the longest name, and
23
- * 40% of the list at most.
22
+ * names and values stand side by side. The gap to the values comes after it. Unset, the column
23
+ * is as wide as the longest name, and takes 40% of the list at most together with that gap.
24
+ * @cssproperty --el-description-list-padding-block - The room above and below a row. Unset, it is
25
+ * `--el-space-3`, and `0.75rem` without a theme.
26
+ * @cssproperty --el-description-list-gap - The gap between a name and its value while they stand
27
+ * side by side, and in front of an action. Unset, it is `--el-space-4`, and `1rem` without a
28
+ * theme.
24
29
  */
25
30
  export default class DescriptionList extends TemplateElement {
26
31
  constructor();
@@ -7,15 +7,21 @@ import FormField from '../form-field/form-field.js';
7
7
  * The files come from the user. A script cannot choose one, the browser does not allow that; it can
8
8
  * take the choice away with an empty `value`.
9
9
  *
10
+ * With `drop-message` the field shows an area around its control to drop a file onto, with that
11
+ * text in it. The area looks different while a dragged file is over it, a click on it opens the
12
+ * dialog, and a drop is a choice as one in the dialog is: the control has the files, and the same
13
+ * events are fired.
14
+ *
10
15
  * @element el-file-field
11
16
  *
12
- * @fires {CustomEvent<string[]>} input-change - Fired when the user has chosen files, and when the
13
- * choice was taken away. `detail` is the list of the names; the files are in `files` of the
14
- * element. Bubbles.
17
+ * @fires {CustomEvent<string[]>} input-change - Fired when the user has chosen files, in the
18
+ * dialog or with a drop, and when the choice was taken away. `detail` is the list of the names;
19
+ * the files are in `files` of the element. Bubbles.
15
20
  *
16
21
  * @cssstate touched - Set on the host once the user has left the control for another place of the
17
22
  * page, or the browser has refused a submit because of it. Inherits `valid` and `invalid` from
18
23
  * `FormField`.
24
+ * @cssstate dragover - Set on the host while a dragged file is over the area to drop onto.
19
25
  *
20
26
  * @property {string[]} value - The names of the chosen files. It follows the control: a script can
21
27
  * set it to an empty list, which takes the choice away, and to nothing else.
@@ -28,8 +34,16 @@ import FormField from '../form-field/form-field.js';
28
34
  * @property {'small'|'medium'|'large'} size - Size of the control: its height, its padding and its
29
35
  * font size. Default `'medium'`. Reflected to the `size` attribute. It shows once the control is
30
36
  * decorated (`styles/native.css`); a control with the look of the browser keeps its size.
37
+ * @property {string} dropMessage - The text of an area to drop a file onto: "Drop the list here,
38
+ * or choose it". With one the field shows the area, around its control. Default `''`.
31
39
  */
32
40
  export default class FileField extends FormField {
41
+ /**
42
+ * How many elements of the area a dragged file is over: the browser tells of every one it
43
+ * enters and leaves, the text and the control in the area as well.
44
+ * @private
45
+ */
46
+ private _dragDepth;
33
47
  /**
34
48
  * The names the control had when the field last looked. See `_matchControl()`.
35
49
  * @private
@@ -56,6 +70,7 @@ export default class FileField extends FormField {
56
70
  multiple: boolean;
57
71
  capture: any;
58
72
  size: string;
73
+ dropMessage: string;
59
74
  };
60
75
  /**
61
76
  * The chosen files, as the control has them.
@@ -75,7 +90,48 @@ export default class FileField extends FormField {
75
90
  blur: () => void;
76
91
  invalid: (event: any) => void;
77
92
  };
93
+ '.drop-area': {
94
+ click: (event: any) => void;
95
+ dragenter: (event: any) => void;
96
+ dragover: (event: any) => void;
97
+ dragleave: (event: any) => void;
98
+ drop: (event: any) => void;
99
+ };
78
100
  };
101
+ /**
102
+ * A click on the area beside its control opens the dialog, as a click on the control does.
103
+ * @private
104
+ * @param {MouseEvent} event
105
+ */
106
+ private _onAreaClick;
107
+ /**
108
+ * A file is dragged into the area, over it or out of it. The area says that it takes the file
109
+ * (the browser shows a drop that is allowed with the pointer), and the host has the state
110
+ * `dragover` for as long. Text or a link that is dragged is nothing for this field.
111
+ * @private
112
+ * @param {DragEvent} event
113
+ * @param {-1 | 0 | 1} step - Into an element of the area, over one, or out of one.
114
+ */
115
+ private _onDrag;
116
+ /**
117
+ * Files were dropped onto the area. They are a choice as one in the dialog is: the control
118
+ * gets them and tells of it with `input` and `change`, which the field follows as it does for
119
+ * the dialog.
120
+ *
121
+ * The dialog does not offer what `accept` leaves out, and one file alone without `multiple`.
122
+ * A drop can bring anything, so the field asks itself. A drop it cannot take as a whole is
123
+ * not taken at all: the control keeps what it had, and the field says that the choice was
124
+ * not valid, with its error message.
125
+ * @private
126
+ * @param {DragEvent} event
127
+ */
128
+ private _onDrop;
129
+ /**
130
+ * The description of the control: the text of the area first, then the messages of the field.
131
+ * @private
132
+ * @returns {string}
133
+ */
134
+ private _describedBy;
79
135
  /**
80
136
  * The user has chosen files, or has taken the choice away in the dialog.
81
137
  * @returns {void}
@@ -112,4 +168,13 @@ export default class FileField extends FormField {
112
168
  /** @private */
113
169
  private fieldTemplate;
114
170
  }
171
+ /**
172
+ * Whether a file is one of the kinds an `accept` attribute names: an ending (`.pdf`), a type
173
+ * (`application/pdf`) or a group of types (`image/*`), with commas between them. Without one
174
+ * every file is.
175
+ * @param {string} accept
176
+ * @param {File} file
177
+ * @returns {boolean}
178
+ */
179
+ export declare function accepts(accept: string, file: File): boolean;
115
180
  export declare function define(): void;
@@ -186,7 +186,7 @@ export default class FormField extends TemplateElement {
186
186
  * The id is another one on every page load. Server-rendered markup has the ids of the server
187
187
  * until the element starts, which writes its own to the same elements.
188
188
  * @private
189
- * @param {'input' | 'help-message' | 'error-message' | 'list'} part
189
+ * @param {'input' | 'help-message' | 'error-message' | 'list' | 'control-start' | 'control-end' | 'drop-message'} part
190
190
  * @returns {string}
191
191
  */
192
192
  private _idOf;
@@ -4,11 +4,21 @@ import FormField from '../form-field/form-field.js';
4
4
  * cross indicators) and ARIA wiring. Extends `FormField` and inherits its label / help /
5
5
  * error / required surface.
6
6
  *
7
+ * The page can put content at the start and at the end of the control: an element with
8
+ * `slot="start"` or `slot="end"` among the children of the field. The field has no shadow root,
9
+ * so these are no slots of the platform: the field takes the elements into its control when it
10
+ * renders. And `clearable` adds a button that empties the field.
11
+ *
7
12
  * @element el-input-field
8
13
  *
9
14
  * @fires {CustomEvent<string>} input-change - Fired when the input's value changes.
10
15
  * `detail` is the new value. Bubbles.
11
16
  *
17
+ * @slot start - Content at the start of the control, in front of the text: an icon, a text, a
18
+ * button. An element of the page with `slot="start"`.
19
+ * @slot end - Content at the end of the control, after the text: a unit, a button. An element of
20
+ * the page with `slot="end"`.
21
+ *
12
22
  * @property {string} type - Native `type` attribute of the underlying `<input>` (e.g.
13
23
  * `'text'`, `'email'`, `'password'`, `'tel'`, `'url'`).
14
24
  * @property {'small'|'medium'|'large'} size - Size of the control: its height, its padding and its
@@ -18,6 +28,15 @@ import FormField from '../form-field/form-field.js';
18
28
  * @property {string | false} pattern - Regular expression used as the input's `pattern`
19
29
  * attribute. When `false` (the default), the `pattern` attribute is omitted entirely, so
20
30
  * the field applies no pattern constraint.
31
+ * @property {boolean} clearable - Whether the control has a button that empties it. The button
32
+ * shows while the field has a value and is not disabled. Default `false`.
33
+ * @property {string} clearLabel - The name of that button for assistive technology. Default
34
+ * `'Clear'`.
35
+ * @property {number | null} maxlength - Passed on to the control as `maxlength`: the browser takes
36
+ * no more characters than this while the user types. `null` (the default) leaves the attribute
37
+ * out.
38
+ * @property {number | null} minlength - Passed on as `minlength`: a text the user has typed that is
39
+ * shorter makes the field invalid. `null` (the default) leaves the attribute out.
21
40
  * @property {string | null} autocomplete - Passed on to the control as its `autocomplete`
22
41
  * attribute (e.g. `'email'`, `'current-password'`, `'one-time-code'`). `null` (the default)
23
42
  * leaves the attribute out. The same holds for the five properties below.
@@ -31,6 +50,11 @@ import FormField from '../form-field/form-field.js';
31
50
  * @property {boolean | string | null} spellcheck - Passed on as `spellcheck` (`true` or `false`).
32
51
  */
33
52
  export default class InputField extends FormField {
53
+ _started: boolean;
54
+ _controlContent: {
55
+ start: Element[];
56
+ end: Element[];
57
+ };
34
58
  constructor(options: any);
35
59
  properties(): {
36
60
  name: string;
@@ -47,6 +71,10 @@ export default class InputField extends FormField {
47
71
  size: string;
48
72
  placeholder: string;
49
73
  pattern: boolean;
74
+ clearable: boolean;
75
+ clearLabel: string;
76
+ maxlength: any;
77
+ minlength: any;
50
78
  autocomplete: any;
51
79
  inputmode: any;
52
80
  enterkeyhint: any;
@@ -54,11 +82,82 @@ export default class InputField extends FormField {
54
82
  autocorrect: any;
55
83
  spellcheck: any;
56
84
  };
85
+ connectedCallback(): void;
57
86
  watch(): {
58
87
  valid: () => void;
59
88
  touched: () => void;
60
89
  value: (value: any, oldValue: any) => void;
61
90
  };
91
+ events(): {
92
+ '[ref=input]': {
93
+ focus: () => void;
94
+ blur: () => void;
95
+ keyup: (event: any) => void;
96
+ change: () => void;
97
+ invalid: (event: any) => void;
98
+ };
99
+ '.is-invalid': {
100
+ focus: () => void;
101
+ };
102
+ '[data-clear-input]': {
103
+ click: () => void;
104
+ touchstart: () => void;
105
+ };
106
+ '.control': {
107
+ click: (event: any) => void;
108
+ };
109
+ '[data-clear]': {
110
+ click: () => void;
111
+ };
112
+ };
113
+ /**
114
+ * The elements the page has put into the field for the start or the end of its control:
115
+ * `<span slot="end">€</span>`. They are children of the field until it renders, and in
116
+ * their place in the control from then on, also in server-rendered markup. An element that
117
+ * comes later is taken in with the next render.
118
+ * @private
119
+ * @param {'start'|'end'} name
120
+ * @returns {Element[]}
121
+ */
122
+ private _slotted;
123
+ /**
124
+ * The content for a place in the control. In a browser the elements of the page themselves:
125
+ * they are moved, not copied, and stay where they are with every render. On a server their
126
+ * markup, written as it is.
127
+ *
128
+ * That is what `unsafeHTML()` gives on a server. It is written out here because the directive
129
+ * gives nodes wherever there is a DOM, and a template that is turned into a string in a
130
+ * browser, as the tests of the server-rendered markup do, would lose them.
131
+ * @private
132
+ * @param {Element[]} elements
133
+ * @returns {Element[] | { __unsafeHTML: true, string: string }}
134
+ */
135
+ private _content;
136
+ /**
137
+ * Whether what the page has put at a place describes the value: a unit, a currency, the start
138
+ * of an address. A screen reader reads it with the input then. A control there, a button or
139
+ * a link, has a name and a stop of the Tab key itself, and is no description. An icon is none
140
+ * either: it has no text, and is hidden from assistive technology (`aria-hidden`).
141
+ * @private
142
+ * @param {Element[]} elements
143
+ * @returns {boolean}
144
+ */
145
+ private _describes;
146
+ /**
147
+ * The description of the control: what the page has put at its start and at its end, then the
148
+ * messages of the field.
149
+ * @private
150
+ * @returns {string}
151
+ */
152
+ private _describedBy;
153
+ /**
154
+ * A click on the control beside its input, on a text or an icon of the page, puts the focus
155
+ * into the input: to the eye all of it is the control. A control in the content, the button
156
+ * that clears the field and the input itself keep their click.
157
+ * @private
158
+ * @param {MouseEvent} event
159
+ */
160
+ private _onControlClick;
62
161
  /**
63
162
  * The pattern of the control. A field that extends this one can have a pattern of its own
64
163
  * where the page gives none (`OtpField`).
@@ -17,6 +17,8 @@ import { TemplateElement } from '@webtides/element-js';
17
17
  * @cssproperty --el-list-padding-inline - The padding of a row at its start and its end. Unset, it
18
18
  * is `--el-space-4`, and `1rem` without a theme. Read by the rows, so it can be set on the list
19
19
  * or for the page.
20
+ * @cssproperty --el-list-gap - The gap between the start, the texts, the end and the control of a
21
+ * row. Unset, it is `--el-space-3`, and `0.75rem` without a theme. Read by the rows as well.
20
22
  *
21
23
  * @property {string} label - The name of the list for assistive technology. Unset, the list has
22
24
  * none.
@@ -31,6 +31,8 @@ import { TemplateElement } from '@webtides/element-js';
31
31
  *
32
32
  * @cssproperty --el-list-padding-inline - The padding of the row at its start and its end. Unset,
33
33
  * it is `--el-space-4`, and `1rem` without a theme.
34
+ * @cssproperty --el-list-gap - The gap between the start, the texts, the end and the control of
35
+ * the row. Unset, it is `--el-space-3`, and `0.75rem` without a theme.
34
36
  *
35
37
  * @property {string} href - The address the row leads to. Unset, the row is no link.
36
38
  * @property {string} target - Where to open the address (only with `href`).