@prismora/elements 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +21 -2
- package/components.json +15600 -0
- package/custom-elements.json +56320 -0
- package/dist/base.d.ts +42 -0
- package/dist/base.js +62 -0
- package/dist/catalog.d.ts +33 -0
- package/dist/catalog.js +803 -0
- package/dist/components/accordion.d.ts +31 -0
- package/dist/components/accordion.js +63 -0
- package/dist/components/alert.d.ts +27 -0
- package/dist/components/alert.js +40 -0
- package/dist/components/avatar-group.d.ts +23 -0
- package/dist/components/avatar-group.js +43 -0
- package/dist/components/avatar.d.ts +24 -0
- package/dist/components/avatar.js +43 -0
- package/dist/components/back-to-top.d.ts +32 -0
- package/dist/components/back-to-top.js +50 -0
- package/dist/components/badge.d.ts +17 -0
- package/dist/components/badge.js +20 -0
- package/dist/components/banner.d.ts +34 -0
- package/dist/components/banner.js +54 -0
- package/dist/components/breadcrumb.d.ts +42 -0
- package/dist/components/breadcrumb.js +63 -0
- package/dist/components/button-group.d.ts +14 -0
- package/dist/components/button-group.js +28 -0
- package/dist/components/button.d.ts +59 -0
- package/dist/components/button.js +162 -0
- package/dist/components/calendar.d.ts +48 -0
- package/dist/components/calendar.js +296 -0
- package/dist/components/card.d.ts +23 -0
- package/dist/components/card.js +44 -0
- package/dist/components/carousel.d.ts +41 -0
- package/dist/components/carousel.js +156 -0
- package/dist/components/cascader.d.ts +70 -0
- package/dist/components/cascader.js +220 -0
- package/dist/components/chart.d.ts +59 -0
- package/dist/components/chart.js +267 -0
- package/dist/components/chat.d.ts +98 -0
- package/dist/components/chat.js +134 -0
- package/dist/components/checkbox-group.d.ts +48 -0
- package/dist/components/checkbox-group.js +111 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +70 -0
- package/dist/components/code-block.d.ts +46 -0
- package/dist/components/code-block.js +86 -0
- package/dist/components/color-picker.d.ts +46 -0
- package/dist/components/color-picker.js +292 -0
- package/dist/components/combobox.d.ts +89 -0
- package/dist/components/combobox.js +384 -0
- package/dist/components/command.d.ts +96 -0
- package/dist/components/command.js +289 -0
- package/dist/components/context-menu.d.ts +23 -0
- package/dist/components/context-menu.js +110 -0
- package/dist/components/copy-button.d.ts +33 -0
- package/dist/components/copy-button.js +62 -0
- package/dist/components/countdown.d.ts +36 -0
- package/dist/components/countdown.js +56 -0
- package/dist/components/data-table.d.ts +180 -0
- package/dist/components/data-table.js +1060 -0
- package/dist/components/date-picker.d.ts +47 -0
- package/dist/components/date-picker.js +267 -0
- package/dist/components/description-list.d.ts +38 -0
- package/dist/components/description-list.js +41 -0
- package/dist/components/dialog.d.ts +47 -0
- package/dist/components/dialog.js +189 -0
- package/dist/components/divider.d.ts +16 -0
- package/dist/components/divider.js +23 -0
- package/dist/components/drawer.d.ts +19 -0
- package/dist/components/drawer.js +27 -0
- package/dist/components/editor.d.ts +50 -0
- package/dist/components/editor.js +474 -0
- package/dist/components/empty-state.d.ts +24 -0
- package/dist/components/empty-state.js +27 -0
- package/dist/components/file-upload.d.ts +56 -0
- package/dist/components/file-upload.js +176 -0
- package/dist/components/form-control.d.ts +69 -0
- package/dist/components/form-control.js +134 -0
- package/dist/components/form.d.ts +38 -0
- package/dist/components/form.js +161 -0
- package/dist/components/format-number.d.ts +37 -0
- package/dist/components/format-number.js +86 -0
- package/dist/components/icon.d.ts +34 -0
- package/dist/components/icon.js +47 -0
- package/dist/components/image.d.ts +44 -0
- package/dist/components/image.js +53 -0
- package/dist/components/indicator.d.ts +41 -0
- package/dist/components/indicator.js +65 -0
- package/dist/components/inline-edit.d.ts +45 -0
- package/dist/components/inline-edit.js +129 -0
- package/dist/components/input.d.ts +55 -0
- package/dist/components/input.js +186 -0
- package/dist/components/kbd.d.ts +15 -0
- package/dist/components/kbd.js +18 -0
- package/dist/components/list.d.ts +68 -0
- package/dist/components/list.js +180 -0
- package/dist/components/menu.d.ts +22 -0
- package/dist/components/menu.js +182 -0
- package/dist/components/menubar.d.ts +20 -0
- package/dist/components/menubar.js +120 -0
- package/dist/components/meter.d.ts +38 -0
- package/dist/components/meter.js +48 -0
- package/dist/components/nav.d.ts +91 -0
- package/dist/components/nav.js +228 -0
- package/dist/components/number-input.d.ts +26 -0
- package/dist/components/number-input.js +70 -0
- package/dist/components/pagination.d.ts +44 -0
- package/dist/components/pagination.js +94 -0
- package/dist/components/pin-input.d.ts +25 -0
- package/dist/components/pin-input.js +128 -0
- package/dist/components/popover.d.ts +23 -0
- package/dist/components/popover.js +140 -0
- package/dist/components/progress.d.ts +26 -0
- package/dist/components/progress.js +66 -0
- package/dist/components/pull-refresh.d.ts +41 -0
- package/dist/components/pull-refresh.js +101 -0
- package/dist/components/qr-code.d.ts +33 -0
- package/dist/components/qr-code.js +54 -0
- package/dist/components/radio-group.d.ts +37 -0
- package/dist/components/radio-group.js +82 -0
- package/dist/components/range-slider.d.ts +46 -0
- package/dist/components/range-slider.js +95 -0
- package/dist/components/rating.d.ts +38 -0
- package/dist/components/rating.js +80 -0
- package/dist/components/relative-time.d.ts +31 -0
- package/dist/components/relative-time.js +51 -0
- package/dist/components/scheduler.d.ts +84 -0
- package/dist/components/scheduler.js +187 -0
- package/dist/components/segmented.d.ts +58 -0
- package/dist/components/segmented.js +129 -0
- package/dist/components/select.d.ts +62 -0
- package/dist/components/select.js +140 -0
- package/dist/components/share-button.d.ts +37 -0
- package/dist/components/share-button.js +60 -0
- package/dist/components/signature.d.ts +54 -0
- package/dist/components/signature.js +152 -0
- package/dist/components/skeleton.d.ts +21 -0
- package/dist/components/skeleton.js +26 -0
- package/dist/components/slider.d.ts +31 -0
- package/dist/components/slider.js +80 -0
- package/dist/components/sortable.d.ts +22 -0
- package/dist/components/sortable.js +196 -0
- package/dist/components/sparkline.d.ts +28 -0
- package/dist/components/sparkline.js +46 -0
- package/dist/components/spinner.d.ts +16 -0
- package/dist/components/spinner.js +22 -0
- package/dist/components/splitter.d.ts +28 -0
- package/dist/components/splitter.js +89 -0
- package/dist/components/stat.d.ts +28 -0
- package/dist/components/stat.js +33 -0
- package/dist/components/steps.d.ts +53 -0
- package/dist/components/steps.js +91 -0
- package/dist/components/switch.d.ts +12 -0
- package/dist/components/switch.js +18 -0
- package/dist/components/table.d.ts +58 -0
- package/dist/components/table.js +96 -0
- package/dist/components/tabs.d.ts +62 -0
- package/dist/components/tabs.js +310 -0
- package/dist/components/tag.d.ts +32 -0
- package/dist/components/tag.js +58 -0
- package/dist/components/textarea.d.ts +25 -0
- package/dist/components/textarea.js +56 -0
- package/dist/components/theme-switch.d.ts +51 -0
- package/dist/components/theme-switch.js +85 -0
- package/dist/components/time-picker.d.ts +39 -0
- package/dist/components/time-picker.js +257 -0
- package/dist/components/timeline.d.ts +38 -0
- package/dist/components/timeline.js +56 -0
- package/dist/components/toaster.d.ts +25 -0
- package/dist/components/toaster.js +44 -0
- package/dist/components/toggle-group.d.ts +70 -0
- package/dist/components/toggle-group.js +172 -0
- package/dist/components/toolbar.d.ts +23 -0
- package/dist/components/toolbar.js +81 -0
- package/dist/components/tooltip.d.ts +18 -0
- package/dist/components/tooltip.js +92 -0
- package/dist/components/tour.d.ts +41 -0
- package/dist/components/tour.js +197 -0
- package/dist/components/transfer.d.ts +57 -0
- package/dist/components/transfer.js +161 -0
- package/dist/components/tree-select.d.ts +66 -0
- package/dist/components/tree-select.js +282 -0
- package/dist/components/tree.d.ts +129 -0
- package/dist/components/tree.js +427 -0
- package/dist/components/virtual-list.d.ts +41 -0
- package/dist/components/virtual-list.js +77 -0
- package/dist/confirm.d.ts +21 -0
- package/dist/confirm.js +69 -0
- package/dist/count.d.ts +5 -0
- package/dist/count.js +12 -0
- package/dist/data-table/icons.d.ts +8 -0
- package/dist/data-table/icons.js +10 -0
- package/dist/data-table/logic.d.ts +33 -0
- package/dist/data-table/logic.js +141 -0
- package/dist/data-table/strings.d.ts +37 -0
- package/dist/data-table/strings.js +36 -0
- package/dist/data-table/types.d.ts +76 -0
- package/dist/data-table/types.js +1 -0
- package/dist/define.d.ts +2 -0
- package/dist/define.js +2 -0
- package/dist/field-validity.d.ts +42 -0
- package/dist/field-validity.js +58 -0
- package/dist/floating.d.ts +13 -0
- package/dist/floating.js +65 -0
- package/dist/highlight.d.ts +11 -0
- package/dist/highlight.js +103 -0
- package/dist/id.d.ts +2 -0
- package/dist/id.js +3 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.js +102 -0
- package/dist/manifest.d.ts +51 -0
- package/dist/manifest.js +11 -0
- package/dist/named-icon.d.ts +8 -0
- package/dist/named-icon.js +8 -0
- package/dist/patterns/account.d.ts +6 -0
- package/dist/patterns/account.js +137 -0
- package/dist/patterns/app.d.ts +7 -0
- package/dist/patterns/app.js +351 -0
- package/dist/patterns/commerce.d.ts +4 -0
- package/dist/patterns/commerce.js +200 -0
- package/dist/patterns/flows.d.ts +3 -0
- package/dist/patterns/flows.js +100 -0
- package/dist/patterns/index.d.ts +9 -0
- package/dist/patterns/index.js +29 -0
- package/dist/patterns/marketing.d.ts +4 -0
- package/dist/patterns/marketing.js +173 -0
- package/dist/patterns/more.d.ts +15 -0
- package/dist/patterns/more.js +581 -0
- package/dist/patterns/shell.d.ts +9 -0
- package/dist/patterns/shell.js +48 -0
- package/dist/patterns/types.d.ts +19 -0
- package/dist/patterns/types.js +1 -0
- package/dist/position.d.ts +2 -0
- package/dist/position.js +33 -0
- package/dist/prismora.standalone.js +5222 -0
- package/dist/prismora.standalone.js.map +199 -0
- package/dist/qr.d.ts +14 -0
- package/dist/qr.js +258 -0
- package/dist/register.d.ts +8 -0
- package/dist/register.js +21 -0
- package/dist/registry.d.ts +203 -0
- package/dist/registry.js +203 -0
- package/dist/remote.d.ts +58 -0
- package/dist/remote.js +130 -0
- package/dist/sheet.d.ts +34 -0
- package/dist/sheet.js +153 -0
- package/dist/styles/accordion.d.ts +2 -0
- package/dist/styles/accordion.js +3 -0
- package/dist/styles/alert.d.ts +2 -0
- package/dist/styles/alert.js +3 -0
- package/dist/styles/avatar.d.ts +2 -0
- package/dist/styles/avatar.js +3 -0
- package/dist/styles/badge.d.ts +2 -0
- package/dist/styles/badge.js +3 -0
- package/dist/styles/banner.d.ts +2 -0
- package/dist/styles/banner.js +3 -0
- package/dist/styles/breadcrumb.d.ts +2 -0
- package/dist/styles/breadcrumb.js +3 -0
- package/dist/styles/button.d.ts +2 -0
- package/dist/styles/button.js +3 -0
- package/dist/styles/calendar.d.ts +2 -0
- package/dist/styles/calendar.js +3 -0
- package/dist/styles/card.d.ts +2 -0
- package/dist/styles/card.js +3 -0
- package/dist/styles/carousel.d.ts +2 -0
- package/dist/styles/carousel.js +3 -0
- package/dist/styles/chart.d.ts +2 -0
- package/dist/styles/chart.js +3 -0
- package/dist/styles/chat.d.ts +2 -0
- package/dist/styles/chat.js +3 -0
- package/dist/styles/checkbox.d.ts +2 -0
- package/dist/styles/checkbox.js +3 -0
- package/dist/styles/color-picker.d.ts +2 -0
- package/dist/styles/color-picker.js +3 -0
- package/dist/styles/combobox.d.ts +2 -0
- package/dist/styles/combobox.js +3 -0
- package/dist/styles/command.d.ts +2 -0
- package/dist/styles/command.js +3 -0
- package/dist/styles/data-table.d.ts +2 -0
- package/dist/styles/data-table.js +3 -0
- package/dist/styles/description-list.d.ts +2 -0
- package/dist/styles/description-list.js +3 -0
- package/dist/styles/dialog.d.ts +2 -0
- package/dist/styles/dialog.js +3 -0
- package/dist/styles/drawer.d.ts +2 -0
- package/dist/styles/drawer.js +3 -0
- package/dist/styles/editor.d.ts +2 -0
- package/dist/styles/editor.js +3 -0
- package/dist/styles/empty-state.d.ts +2 -0
- package/dist/styles/empty-state.js +3 -0
- package/dist/styles/extras.d.ts +2 -0
- package/dist/styles/extras.js +3 -0
- package/dist/styles/field.d.ts +2 -0
- package/dist/styles/field.js +3 -0
- package/dist/styles/file-upload.d.ts +2 -0
- package/dist/styles/file-upload.js +3 -0
- package/dist/styles/foundation.d.ts +2 -0
- package/dist/styles/foundation.js +3 -0
- package/dist/styles/helpers.d.ts +2 -0
- package/dist/styles/helpers.js +3 -0
- package/dist/styles/icon.d.ts +2 -0
- package/dist/styles/icon.js +3 -0
- package/dist/styles/image.d.ts +2 -0
- package/dist/styles/image.js +3 -0
- package/dist/styles/indicator.d.ts +2 -0
- package/dist/styles/indicator.js +3 -0
- package/dist/styles/input.d.ts +2 -0
- package/dist/styles/input.js +3 -0
- package/dist/styles/kbd.d.ts +2 -0
- package/dist/styles/kbd.js +3 -0
- package/dist/styles/list.d.ts +2 -0
- package/dist/styles/list.js +3 -0
- package/dist/styles/listbox.d.ts +2 -0
- package/dist/styles/listbox.js +3 -0
- package/dist/styles/meter.d.ts +2 -0
- package/dist/styles/meter.js +3 -0
- package/dist/styles/nav.d.ts +2 -0
- package/dist/styles/nav.js +3 -0
- package/dist/styles/number-input.d.ts +2 -0
- package/dist/styles/number-input.js +3 -0
- package/dist/styles/overlay.d.ts +2 -0
- package/dist/styles/overlay.js +3 -0
- package/dist/styles/pagination.d.ts +2 -0
- package/dist/styles/pagination.js +3 -0
- package/dist/styles/pickers.d.ts +2 -0
- package/dist/styles/pickers.js +3 -0
- package/dist/styles/pin-input.d.ts +2 -0
- package/dist/styles/pin-input.js +3 -0
- package/dist/styles/popover.d.ts +2 -0
- package/dist/styles/popover.js +3 -0
- package/dist/styles/progress.d.ts +2 -0
- package/dist/styles/progress.js +3 -0
- package/dist/styles/pull-refresh.d.ts +2 -0
- package/dist/styles/pull-refresh.js +3 -0
- package/dist/styles/range-slider.d.ts +2 -0
- package/dist/styles/range-slider.js +3 -0
- package/dist/styles/rating.d.ts +2 -0
- package/dist/styles/rating.js +3 -0
- package/dist/styles/scheduler.d.ts +2 -0
- package/dist/styles/scheduler.js +3 -0
- package/dist/styles/segmented.d.ts +2 -0
- package/dist/styles/segmented.js +3 -0
- package/dist/styles/select.d.ts +2 -0
- package/dist/styles/select.js +3 -0
- package/dist/styles/separator.d.ts +2 -0
- package/dist/styles/separator.js +3 -0
- package/dist/styles/sheet.d.ts +2 -0
- package/dist/styles/sheet.js +3 -0
- package/dist/styles/skeleton.d.ts +2 -0
- package/dist/styles/skeleton.js +3 -0
- package/dist/styles/slider.d.ts +2 -0
- package/dist/styles/slider.js +3 -0
- package/dist/styles/sortable.d.ts +2 -0
- package/dist/styles/sortable.js +3 -0
- package/dist/styles/spinner.d.ts +2 -0
- package/dist/styles/spinner.js +3 -0
- package/dist/styles/splitter.d.ts +2 -0
- package/dist/styles/splitter.js +3 -0
- package/dist/styles/stat.d.ts +2 -0
- package/dist/styles/stat.js +3 -0
- package/dist/styles/steps.d.ts +2 -0
- package/dist/styles/steps.js +3 -0
- package/dist/styles/surface.d.ts +2 -0
- package/dist/styles/surface.js +3 -0
- package/dist/styles/switch.d.ts +2 -0
- package/dist/styles/switch.js +3 -0
- package/dist/styles/table.d.ts +2 -0
- package/dist/styles/table.js +3 -0
- package/dist/styles/tabs.d.ts +2 -0
- package/dist/styles/tabs.js +3 -0
- package/dist/styles/tag.d.ts +2 -0
- package/dist/styles/tag.js +3 -0
- package/dist/styles/time-picker.d.ts +2 -0
- package/dist/styles/time-picker.js +3 -0
- package/dist/styles/timeline.d.ts +2 -0
- package/dist/styles/timeline.js +3 -0
- package/dist/styles/toast.d.ts +2 -0
- package/dist/styles/toast.js +3 -0
- package/dist/styles/toggle.d.ts +2 -0
- package/dist/styles/toggle.js +3 -0
- package/dist/styles/toolbar.d.ts +2 -0
- package/dist/styles/toolbar.js +3 -0
- package/dist/styles/tooltip.d.ts +2 -0
- package/dist/styles/tooltip.js +3 -0
- package/dist/styles/tree.d.ts +2 -0
- package/dist/styles/tree.js +3 -0
- package/dist/table-core.d.ts +75 -0
- package/dist/table-core.js +205 -0
- package/dist/toast.d.ts +42 -0
- package/dist/toast.js +206 -0
- package/dist/top-layer.d.ts +4 -0
- package/dist/top-layer.js +33 -0
- package/package.json +101 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { html, nothing } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { live } from 'lit/directives/live.js';
|
|
4
|
+
import { defineElement } from '../base.js';
|
|
5
|
+
import { PmFormControl } from './form-control.js';
|
|
6
|
+
import inputCss from '../styles/input.js';
|
|
7
|
+
import { namedIcon } from '../named-icon.js';
|
|
8
|
+
/**
|
|
9
|
+
* Single-line text field for text, email, numbers, passwords, search and more.
|
|
10
|
+
* @tag pm-input
|
|
11
|
+
* @slot end - Trailing adornment.
|
|
12
|
+
* @slot start - Leading adornment (icon or text such as "https://").
|
|
13
|
+
* @csspart control - The native input.
|
|
14
|
+
* @csspart counter - Character counter (with `show-count`).
|
|
15
|
+
* @fires pm-clear - The clear button was pressed.
|
|
16
|
+
* @example <pm-input label="Email" type="email" name="email" required></pm-input>
|
|
17
|
+
*/
|
|
18
|
+
export class PmInput extends PmFormControl {
|
|
19
|
+
static { this.styles = [...PmFormControl.styles, inputCss]; }
|
|
20
|
+
static { this.componentName = 'input'; }
|
|
21
|
+
static { this.properties = { mask: {}, strength: { type: Boolean }, iconStart: { attribute: 'icon-start', reflect: true }, iconEnd: { attribute: 'icon-end', reflect: true },
|
|
22
|
+
type: {},
|
|
23
|
+
placeholder: {},
|
|
24
|
+
autocomplete: {},
|
|
25
|
+
inputmode: {},
|
|
26
|
+
pattern: {},
|
|
27
|
+
minlength: { type: Number },
|
|
28
|
+
maxlength: { type: Number },
|
|
29
|
+
min: {},
|
|
30
|
+
max: {},
|
|
31
|
+
step: {},
|
|
32
|
+
clearable: { type: Boolean },
|
|
33
|
+
passwordToggle: { type: Boolean, attribute: 'password-toggle' },
|
|
34
|
+
showCount: { type: Boolean, attribute: 'show-count' },
|
|
35
|
+
_revealed: { state: true },
|
|
36
|
+
}; }
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
this.type = 'text';
|
|
40
|
+
this.clearable = false;
|
|
41
|
+
this.passwordToggle = false;
|
|
42
|
+
this.showCount = false;
|
|
43
|
+
this._revealed = false;
|
|
44
|
+
this.strength = false;
|
|
45
|
+
}
|
|
46
|
+
onInput(e) {
|
|
47
|
+
const el = e.target;
|
|
48
|
+
if (this.mask)
|
|
49
|
+
el.value = applyMask(el.value, this.mask);
|
|
50
|
+
super.onInput(e);
|
|
51
|
+
}
|
|
52
|
+
#ro;
|
|
53
|
+
firstUpdated(changed) {
|
|
54
|
+
super.firstUpdated(changed);
|
|
55
|
+
if (typeof ResizeObserver === 'undefined')
|
|
56
|
+
return;
|
|
57
|
+
this.#ro = new ResizeObserver(() => this.#measure());
|
|
58
|
+
this.#ro.observe(this.renderRoot.querySelector('.pm-input-group'));
|
|
59
|
+
}
|
|
60
|
+
disconnectedCallback() { super.disconnectedCallback(); this.#ro?.disconnect(); }
|
|
61
|
+
updated(changed) {
|
|
62
|
+
super.updated(changed);
|
|
63
|
+
this.#measure();
|
|
64
|
+
}
|
|
65
|
+
/** Pad the input by the real width of adornments and action buttons. */
|
|
66
|
+
#measure() {
|
|
67
|
+
const g = this.renderRoot.querySelector('.pm-input-group');
|
|
68
|
+
if (!g)
|
|
69
|
+
return;
|
|
70
|
+
const w = (sel) => g.querySelector(sel)?.offsetWidth ?? 0;
|
|
71
|
+
const start = w('[data-slot="start"]');
|
|
72
|
+
const endSlot = w('[data-slot="end"]');
|
|
73
|
+
const actions = w('.pm-input-actions');
|
|
74
|
+
if (start)
|
|
75
|
+
g.style.setProperty('--_start', `${start}px`);
|
|
76
|
+
else
|
|
77
|
+
g.style.removeProperty('--_start');
|
|
78
|
+
g.style.setProperty('--_end-slot', `${endSlot}px`);
|
|
79
|
+
if (endSlot + actions)
|
|
80
|
+
g.style.setProperty('--_end', `${endSlot + actions + (actions && !endSlot ? 4 : 0)}px`);
|
|
81
|
+
else
|
|
82
|
+
g.style.removeProperty('--_end');
|
|
83
|
+
}
|
|
84
|
+
#clear() {
|
|
85
|
+
this.value = '';
|
|
86
|
+
this.emit('pm-input', { value: '' });
|
|
87
|
+
this.emit('pm-change', { value: '' });
|
|
88
|
+
this.emit('pm-clear');
|
|
89
|
+
this.control?.focus();
|
|
90
|
+
}
|
|
91
|
+
#strength() {
|
|
92
|
+
const score = this.value ? passwordStrength(this.value) : -1;
|
|
93
|
+
const tone = ['danger', 'danger', 'warning', 'success', 'success'][Math.max(score, 0)];
|
|
94
|
+
const text = score < 0 ? '' : ['Too short', 'Weak', 'Fair', 'Good', 'Strong'][score];
|
|
95
|
+
return html `<span part="strength" style="display:grid;grid-template-columns:repeat(4,1fr) auto;align-items:center;gap:3px;font-size:var(--pm-font-size-xs);color:var(--pm-color-fg-muted)">
|
|
96
|
+
${[1, 2, 3, 4].map((n) => html `<span style="block-size:4px;border-radius:2px;background:${score >= n ? `var(--pm-color-${tone}-solid)` : 'var(--pm-color-bg-muted)'}"></span>`)}
|
|
97
|
+
<span aria-live="polite" style="min-inline-size:5em;text-align:end">${text ? html `<span class="pm-visually-hidden">Password strength: </span>${text}` : nothing}</span>
|
|
98
|
+
</span>`;
|
|
99
|
+
}
|
|
100
|
+
render() {
|
|
101
|
+
const hasStart = !!this.iconStart || !!this.querySelector('[slot="start"]');
|
|
102
|
+
const hasEnd = !!this.iconEnd || !!this.querySelector('[slot="end"]');
|
|
103
|
+
const editable = !this.disabled && !this.readonly;
|
|
104
|
+
const showClear = this.clearable && editable && this.value.length > 0;
|
|
105
|
+
const showToggle = this.passwordToggle && this.type === 'password' && !this.disabled;
|
|
106
|
+
return this.field(html `<div class="pm-input-group">
|
|
107
|
+
${hasStart ? html `<span data-slot="start"><slot name="start">${namedIcon(this.iconStart)}</slot></span>` : nothing}
|
|
108
|
+
<input
|
|
109
|
+
data-control
|
|
110
|
+
part="control"
|
|
111
|
+
class="pm-input"
|
|
112
|
+
id=${this.controlId}
|
|
113
|
+
type=${this.type === 'password' && this._revealed ? 'text' : this.type}
|
|
114
|
+
name=${ifDefined(this.name)}
|
|
115
|
+
.value=${live(this.value)}
|
|
116
|
+
placeholder=${ifDefined(this.placeholder)}
|
|
117
|
+
autocomplete=${ifDefined(this.autocomplete)}
|
|
118
|
+
inputmode=${ifDefined(this.inputmode)}
|
|
119
|
+
pattern=${ifDefined(this.pattern)}
|
|
120
|
+
minlength=${ifDefined(this.minlength)}
|
|
121
|
+
maxlength=${ifDefined(this.maxlength)}
|
|
122
|
+
min=${ifDefined(this.min)}
|
|
123
|
+
max=${ifDefined(this.max)}
|
|
124
|
+
step=${ifDefined(this.step)}
|
|
125
|
+
data-size=${ifDefined(this.size)}
|
|
126
|
+
?required=${this.required}
|
|
127
|
+
?disabled=${this.disabled}
|
|
128
|
+
?readonly=${this.readonly}
|
|
129
|
+
aria-invalid=${this.showInvalid ? 'true' : nothing}
|
|
130
|
+
aria-describedby=${ifDefined([this.describedBy(), this.showCount ? `${this.controlId}-count` : ''].filter(Boolean).join(' ') || undefined)}
|
|
131
|
+
?data-custom-controls=${this.type === 'search' && this.clearable}
|
|
132
|
+
@input=${this.onInput}
|
|
133
|
+
@change=${this.onChange}
|
|
134
|
+
@blur=${this.onBlur}
|
|
135
|
+
/>
|
|
136
|
+
${showClear || showToggle ? html `<span class="pm-input-actions">
|
|
137
|
+
${showClear ? html `<button type="button" class="pm-input-action" part="clear" aria-label="Clear" @click=${this.#clear}>
|
|
138
|
+
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M7 7l10 10M17 7L7 17"/></svg></button>` : nothing}
|
|
139
|
+
${showToggle ? html `<button type="button" class="pm-input-action" part="password-toggle" aria-pressed=${this._revealed ? 'true' : 'false'}
|
|
140
|
+
aria-label=${this._revealed ? 'Hide password' : 'Show password'} @click=${() => { this._revealed = !this._revealed; }}>
|
|
141
|
+
${this._revealed
|
|
142
|
+
? html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 4l16 16M10.6 6A8.6 8.6 0 0 1 12 5.5c6 0 9.5 6.5 9.5 6.5a16 16 0 0 1-2.6 3.4M6.6 7.6A15.6 15.6 0 0 0 2.5 12S6 18.5 12 18.5a8.7 8.7 0 0 0 4.4-1.2M9.9 9.9a3 3 0 0 0 4.2 4.2"/></svg>`
|
|
143
|
+
: html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 12S6 5.5 12 5.5 21.5 12 21.5 12 18 18.5 12 18.5 2.5 12 2.5 12z"/><circle cx="12" cy="12" r="3"/></svg>`}
|
|
144
|
+
</button>` : nothing}
|
|
145
|
+
</span>` : nothing}
|
|
146
|
+
${hasEnd ? html `<span data-slot="end"><slot name="end">${namedIcon(this.iconEnd)}</slot></span>` : nothing}
|
|
147
|
+
</div>
|
|
148
|
+
${this.strength && this.type === 'password' ? this.#strength() : nothing}
|
|
149
|
+
${this.showCount ? html `<span class="pm-input-counter" part="counter" id=${`${this.controlId}-count`} ?data-over=${!!this.maxlength && this.value.length > this.maxlength}
|
|
150
|
+
>${this.value.length}${this.maxlength ? ` / ${this.maxlength}` : ''}<span class="pm-visually-hidden"> characters</span></span>` : nothing}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Fit `raw` to a mask: `9` digit, `a` letter, `*` letter or digit; literals are inserted. Stops at the first missing character. */
|
|
154
|
+
export function applyMask(raw, mask) {
|
|
155
|
+
const fits = (m, c) => (m === '9' ? /\d/.test(c) : m === 'a' ? /\p{L}/u.test(c) : /[\p{L}\d]/u.test(c));
|
|
156
|
+
let out = '';
|
|
157
|
+
let i = 0;
|
|
158
|
+
for (const m of mask) {
|
|
159
|
+
if (!'9a*'.includes(m)) {
|
|
160
|
+
if (i >= raw.length)
|
|
161
|
+
break;
|
|
162
|
+
out += m;
|
|
163
|
+
if (raw[i] === m)
|
|
164
|
+
i++;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
while (i < raw.length && !fits(m, raw[i]))
|
|
168
|
+
i++;
|
|
169
|
+
if (i >= raw.length)
|
|
170
|
+
break;
|
|
171
|
+
out += raw[i++];
|
|
172
|
+
}
|
|
173
|
+
// Drop literals left hanging at the end, so Backspace keeps working.
|
|
174
|
+
while (out && !/[\p{L}\d]/u.test(out.at(-1)))
|
|
175
|
+
out = out.slice(0, -1);
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/** Rough password strength, 0 (too short) to 4 (strong), from length and character variety. */
|
|
179
|
+
export function passwordStrength(value) {
|
|
180
|
+
if (value.length < 8)
|
|
181
|
+
return 0;
|
|
182
|
+
const kinds = [/[a-z]/, /[A-Z]/, /\d/, /[^A-Za-z0-9]/].filter((r) => r.test(value)).length;
|
|
183
|
+
const score = (value.length >= 12 ? 1 : 0) + (value.length >= 16 ? 1 : 0) + (kinds >= 2 ? 1 : 0) + (kinds >= 3 ? 1 : 0);
|
|
184
|
+
return Math.max(1, Math.min(4, score));
|
|
185
|
+
}
|
|
186
|
+
defineElement('pm-input', PmInput);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Keyboard key or shortcut.
|
|
5
|
+
* @tag pm-kbd
|
|
6
|
+
* @slot - Key label, e.g. ⌘ or Ctrl.
|
|
7
|
+
* @example <pm-kbd>⌘</pm-kbd> <pm-kbd>K</pm-kbd>
|
|
8
|
+
*/
|
|
9
|
+
export declare class PmKbd extends PmElement {
|
|
10
|
+
static componentName: string;
|
|
11
|
+
static styles: import("lit").CSSResult[];
|
|
12
|
+
static properties: PropertyDeclarations;
|
|
13
|
+
size?: 'sm' | 'md' | 'lg';
|
|
14
|
+
render(): import("lit").TemplateResult<1>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import kbdCss from '../styles/kbd.js';
|
|
4
|
+
/**
|
|
5
|
+
* Keyboard key or shortcut.
|
|
6
|
+
* @tag pm-kbd
|
|
7
|
+
* @slot - Key label, e.g. ⌘ or Ctrl.
|
|
8
|
+
* @example <pm-kbd>⌘</pm-kbd> <pm-kbd>K</pm-kbd>
|
|
9
|
+
*/
|
|
10
|
+
export class PmKbd extends PmElement {
|
|
11
|
+
static { this.componentName = 'kbd'; }
|
|
12
|
+
static { this.styles = [...PmElement.styles, kbdCss, css `:host { display: inline-flex; vertical-align: middle; }`]; }
|
|
13
|
+
static { this.properties = { size: { reflect: true } }; }
|
|
14
|
+
render() {
|
|
15
|
+
return html `<kbd class="pm-kbd" part="base" data-size=${this.size ?? nothing}><slot></slot></kbd>`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
defineElement('pm-kbd', PmKbd);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type PropertyDeclarations, type PropertyValues } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* List of rows (settings, inboxes, contacts, search results). Rows have leading media, a heading, a description and
|
|
5
|
+
* trailing meta or actions. `divided` adds separators, `bordered` a frame.
|
|
6
|
+
* @tag pm-list
|
|
7
|
+
* @slot - `pm-list-item` elements.
|
|
8
|
+
* @example <pm-list bordered divided><pm-list-item heading="Ada Lovelace" description="ada@example.com"></pm-list-item></pm-list>
|
|
9
|
+
*/
|
|
10
|
+
export declare class PmList extends PmElement {
|
|
11
|
+
static componentName: string;
|
|
12
|
+
static styles: import("lit").CSSResult[];
|
|
13
|
+
static properties: PropertyDeclarations;
|
|
14
|
+
/** Lines between rows. */
|
|
15
|
+
divided: boolean;
|
|
16
|
+
/** Border around the list. */
|
|
17
|
+
bordered: boolean;
|
|
18
|
+
/** Accessible name of the list. */
|
|
19
|
+
label?: string;
|
|
20
|
+
constructor();
|
|
21
|
+
render(): import("lit").TemplateResult<1>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* One list row. With `href` the row is a link; with `interactive` it is a button that fires `pm-select`.
|
|
25
|
+
*
|
|
26
|
+
* Swipe actions (mail, chat and task apps): put buttons in the `swipe-start` / `swipe-end` slots. On touch screens
|
|
27
|
+
* the row slides sideways to reveal them (one open row per list; a tap elsewhere closes it). They never depend on
|
|
28
|
+
* swiping: moving keyboard or screen reader focus onto an action opens the row to that side, and `open` /
|
|
29
|
+
* `close()` control it from code.
|
|
30
|
+
* @tag pm-list-item
|
|
31
|
+
* @slot swipe-start - Actions revealed by swiping toward the end (e.g. Archive, Mark read).
|
|
32
|
+
* @slot swipe-end - Actions revealed by swiping toward the start (e.g. Delete).
|
|
33
|
+
* @fires pm-swipe - The row opened to a side (or closed: side is null). detail: { side }
|
|
34
|
+
* @slot start - Leading avatar, icon or checkbox.
|
|
35
|
+
* @slot - Extra content under the description.
|
|
36
|
+
* @slot end - Trailing meta, badge or actions.
|
|
37
|
+
* @fires pm-select - An interactive row was activated. detail: { value }
|
|
38
|
+
* @example <pm-list-item heading="Notifications" description="Email and push"><pm-switch slot="end" label="Notifications" hide-label></pm-switch></pm-list-item>
|
|
39
|
+
*/
|
|
40
|
+
export declare class PmListItem extends PmElement {
|
|
41
|
+
#private;
|
|
42
|
+
static componentName: string;
|
|
43
|
+
static styles: import("lit").CSSResult[];
|
|
44
|
+
static properties: PropertyDeclarations;
|
|
45
|
+
/** Which swipe actions are showing: `start`, `end`, or none. */
|
|
46
|
+
open?: 'start' | 'end' | null;
|
|
47
|
+
_drag?: number;
|
|
48
|
+
/** Registered icon name shown before the content (see `registerIcons`); a `start` slot overrides it. */
|
|
49
|
+
iconStart?: string;
|
|
50
|
+
/** Registered icon name shown after the content (see `registerIcons`); an `end` slot overrides it. */
|
|
51
|
+
iconEnd?: string;
|
|
52
|
+
heading?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
/** Make the whole row a link. */
|
|
55
|
+
href?: string;
|
|
56
|
+
value?: string;
|
|
57
|
+
/** Make the whole row a button. */
|
|
58
|
+
interactive: boolean;
|
|
59
|
+
selected: boolean;
|
|
60
|
+
disabled: boolean;
|
|
61
|
+
constructor();
|
|
62
|
+
connectedCallback(): void;
|
|
63
|
+
disconnectedCallback(): void;
|
|
64
|
+
/** Hide the swipe actions. */
|
|
65
|
+
close(): void;
|
|
66
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
67
|
+
render(): import("lit").TemplateResult<1>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import listCss from '../styles/list.js';
|
|
4
|
+
import { namedIcon } from '../named-icon.js';
|
|
5
|
+
/**
|
|
6
|
+
* List of rows (settings, inboxes, contacts, search results). Rows have leading media, a heading, a description and
|
|
7
|
+
* trailing meta or actions. `divided` adds separators, `bordered` a frame.
|
|
8
|
+
* @tag pm-list
|
|
9
|
+
* @slot - `pm-list-item` elements.
|
|
10
|
+
* @example <pm-list bordered divided><pm-list-item heading="Ada Lovelace" description="ada@example.com"></pm-list-item></pm-list>
|
|
11
|
+
*/
|
|
12
|
+
export class PmList extends PmElement {
|
|
13
|
+
static { this.componentName = 'list'; }
|
|
14
|
+
static { this.styles = [...PmElement.styles, listCss, css `:host { display: block; }`]; }
|
|
15
|
+
static { this.properties = { divided: { type: Boolean, reflect: true }, bordered: { type: Boolean, reflect: true }, label: {} }; }
|
|
16
|
+
constructor() { super(); this.divided = false; this.bordered = false; }
|
|
17
|
+
render() {
|
|
18
|
+
return html `<div class="pm-list" part="base" role="list" aria-label=${this.label ?? nothing} ?data-divided=${this.divided} ?data-bordered=${this.bordered}><slot></slot></div>`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One list row. With `href` the row is a link; with `interactive` it is a button that fires `pm-select`.
|
|
23
|
+
*
|
|
24
|
+
* Swipe actions (mail, chat and task apps): put buttons in the `swipe-start` / `swipe-end` slots. On touch screens
|
|
25
|
+
* the row slides sideways to reveal them (one open row per list; a tap elsewhere closes it). They never depend on
|
|
26
|
+
* swiping: moving keyboard or screen reader focus onto an action opens the row to that side, and `open` /
|
|
27
|
+
* `close()` control it from code.
|
|
28
|
+
* @tag pm-list-item
|
|
29
|
+
* @slot swipe-start - Actions revealed by swiping toward the end (e.g. Archive, Mark read).
|
|
30
|
+
* @slot swipe-end - Actions revealed by swiping toward the start (e.g. Delete).
|
|
31
|
+
* @fires pm-swipe - The row opened to a side (or closed: side is null). detail: { side }
|
|
32
|
+
* @slot start - Leading avatar, icon or checkbox.
|
|
33
|
+
* @slot - Extra content under the description.
|
|
34
|
+
* @slot end - Trailing meta, badge or actions.
|
|
35
|
+
* @fires pm-select - An interactive row was activated. detail: { value }
|
|
36
|
+
* @example <pm-list-item heading="Notifications" description="Email and push"><pm-switch slot="end" label="Notifications" hide-label></pm-switch></pm-list-item>
|
|
37
|
+
*/
|
|
38
|
+
export class PmListItem extends PmElement {
|
|
39
|
+
static { this.componentName = 'list-item'; }
|
|
40
|
+
static { this.styles = [...PmElement.styles, listCss, css `:host { display: block; } :host(:not(:last-child)) :is(.pm-list-item[data-divided]:not(.pm-list-swipe > *), .pm-list-swipe[data-divided]) { border-block-end: 1px solid var(--pm-color-border); }`]; }
|
|
41
|
+
static { this.properties = { iconStart: { attribute: 'icon-start', reflect: true }, iconEnd: { attribute: 'icon-end', reflect: true },
|
|
42
|
+
heading: {}, description: {}, href: {}, value: {}, interactive: { type: Boolean }, selected: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true },
|
|
43
|
+
open: { reflect: true }, _drag: { state: true },
|
|
44
|
+
}; }
|
|
45
|
+
constructor() { super(); this.interactive = false; this.selected = false; this.disabled = false; }
|
|
46
|
+
connectedCallback() {
|
|
47
|
+
super.connectedCallback();
|
|
48
|
+
this.setAttribute('role', 'listitem');
|
|
49
|
+
this.addEventListener('focusin', this.#onFocus);
|
|
50
|
+
}
|
|
51
|
+
disconnectedCallback() { super.disconnectedCallback(); document.removeEventListener('pointerdown', this.#outside, true); }
|
|
52
|
+
/** Hide the swipe actions. */
|
|
53
|
+
close() { this.open = null; }
|
|
54
|
+
get #hasSwipe() { return !!this.querySelector(':scope > [slot="swipe-start"], :scope > [slot="swipe-end"]'); }
|
|
55
|
+
/** +1 in left-to-right text, -1 in right-to-left (swipe offsets are logical). */
|
|
56
|
+
get #dir() { return getComputedStyle(this).direction === 'rtl' ? -1 : 1; }
|
|
57
|
+
#width(side) { return this.renderRoot.querySelector(`.pm-list-actions[data-side="${side}"]`)?.offsetWidth ?? 0; }
|
|
58
|
+
#onFocus = (e) => {
|
|
59
|
+
const slot = e.target.closest?.('[slot^="swipe-"]')?.getAttribute('slot');
|
|
60
|
+
if (slot === 'swipe-start' || slot === 'swipe-end')
|
|
61
|
+
this.open = slot === 'swipe-start' ? 'start' : 'end';
|
|
62
|
+
};
|
|
63
|
+
#outside = (e) => { if (!e.composedPath().includes(this))
|
|
64
|
+
this.close(); };
|
|
65
|
+
#start;
|
|
66
|
+
#onDown = (e) => {
|
|
67
|
+
this.#swiped = false;
|
|
68
|
+
if (e.pointerType === 'mouse' || this.disabled || !e.isPrimary)
|
|
69
|
+
return;
|
|
70
|
+
const base = this.open === 'start' ? this.#width('start') : this.open === 'end' ? -this.#width('end') : 0;
|
|
71
|
+
this.#start = { x: e.clientX, y: e.clientY, base, id: e.pointerId, swiping: false };
|
|
72
|
+
};
|
|
73
|
+
#onMove = (e) => {
|
|
74
|
+
const s = this.#start;
|
|
75
|
+
if (!s || e.pointerId !== s.id)
|
|
76
|
+
return;
|
|
77
|
+
const dx = (e.clientX - s.x) * this.#dir, dy = e.clientY - s.y;
|
|
78
|
+
if (!s.swiping) {
|
|
79
|
+
if (Math.abs(dy) > 10 && Math.abs(dy) > Math.abs(dx)) {
|
|
80
|
+
this.#start = undefined;
|
|
81
|
+
return;
|
|
82
|
+
} // scrolling the page
|
|
83
|
+
if (Math.abs(dx) < 8)
|
|
84
|
+
return;
|
|
85
|
+
s.swiping = true;
|
|
86
|
+
try {
|
|
87
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
88
|
+
}
|
|
89
|
+
catch { /* pointer already released */ }
|
|
90
|
+
}
|
|
91
|
+
const max = this.#width('start'), min = -this.#width('end');
|
|
92
|
+
let x = s.base + dx;
|
|
93
|
+
// Rubber band past the actions.
|
|
94
|
+
if (x > max)
|
|
95
|
+
x = max + (x - max) / 4;
|
|
96
|
+
else if (x < min)
|
|
97
|
+
x = min + (x - min) / 4;
|
|
98
|
+
this._drag = x;
|
|
99
|
+
};
|
|
100
|
+
#onUp = (e) => {
|
|
101
|
+
const s = this.#start;
|
|
102
|
+
this.#start = undefined;
|
|
103
|
+
if (!s?.swiping || this._drag === undefined)
|
|
104
|
+
return;
|
|
105
|
+
const x = this._drag;
|
|
106
|
+
this._drag = undefined;
|
|
107
|
+
const next = x > this.#width('start') / 2 && this.#width('start') ? 'start' : -x > this.#width('end') / 2 && this.#width('end') ? 'end' : null;
|
|
108
|
+
this.open = next;
|
|
109
|
+
// A swipe is not a tap: keep the row's link or button from activating (cleared by the next press).
|
|
110
|
+
this.#swiped = e.type === 'pointerup';
|
|
111
|
+
};
|
|
112
|
+
#swiped = false;
|
|
113
|
+
#onClick = {
|
|
114
|
+
handleEvent: (e) => {
|
|
115
|
+
if (this.#swiped) {
|
|
116
|
+
this.#swiped = false;
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (e.target.closest?.('[slot^="swipe-"]'))
|
|
122
|
+
queueMicrotask(() => this.close());
|
|
123
|
+
// A tap on an open row closes it instead of activating it.
|
|
124
|
+
else if (this.open) {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
e.stopPropagation();
|
|
127
|
+
this.close();
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
capture: true,
|
|
131
|
+
};
|
|
132
|
+
updated(changed) {
|
|
133
|
+
super.updated(changed);
|
|
134
|
+
if (!changed.has('open'))
|
|
135
|
+
return;
|
|
136
|
+
if (this.open) {
|
|
137
|
+
// One open row per list.
|
|
138
|
+
for (const other of this.parentElement?.querySelectorAll(':scope > pm-list-item[open]') ?? [])
|
|
139
|
+
if (other !== this)
|
|
140
|
+
other.close();
|
|
141
|
+
document.addEventListener('pointerdown', this.#outside, true);
|
|
142
|
+
}
|
|
143
|
+
else
|
|
144
|
+
document.removeEventListener('pointerdown', this.#outside, true);
|
|
145
|
+
if (changed.get('open') !== undefined || this.open)
|
|
146
|
+
this.emit('pm-swipe', { side: this.open ?? null });
|
|
147
|
+
}
|
|
148
|
+
#activate() { if (!this.disabled)
|
|
149
|
+
this.emit('pm-select', { value: this.value ?? this.heading }); }
|
|
150
|
+
render() {
|
|
151
|
+
const divided = this.parentElement?.hasAttribute('divided');
|
|
152
|
+
const hasStart = !!this.iconStart || !!this.querySelector(':scope > [slot="start"]');
|
|
153
|
+
const body = html `<span class="pm-list-start" part="start" ?hidden=${!hasStart}><slot name="start" @slotchange=${() => this.requestUpdate()}>${namedIcon(this.iconStart)}</slot></span>
|
|
154
|
+
<span class="pm-list-body">
|
|
155
|
+
${this.heading ? html `<span class="pm-list-heading" part="heading">${this.heading}</span>` : nothing}
|
|
156
|
+
${this.description ? html `<span class="pm-list-desc" part="description">${this.description}</span>` : nothing}
|
|
157
|
+
<slot></slot>
|
|
158
|
+
</span>`;
|
|
159
|
+
const end = html `<span class="pm-list-end" part="end"><slot name="end">${namedIcon(this.iconEnd)}</slot></span>`;
|
|
160
|
+
const cls = 'pm-list-main';
|
|
161
|
+
const main = this.href && !this.disabled
|
|
162
|
+
? html `<a class=${cls} href=${this.href} aria-current=${this.selected ? 'page' : nothing}>${body}</a>`
|
|
163
|
+
: this.interactive
|
|
164
|
+
? html `<button type="button" class=${cls} ?disabled=${this.disabled} aria-pressed=${this.selected ? 'true' : nothing} @click=${this.#activate}>${body}</button>`
|
|
165
|
+
: html `<div class=${cls}>${body}</div>`;
|
|
166
|
+
const row = html `<div class="pm-list-item" part="base" ?data-divided=${divided} ?data-selected=${this.selected} ?data-disabled=${this.disabled}
|
|
167
|
+
?data-interactive=${!!this.href || this.interactive}>${main}${end}</div>`;
|
|
168
|
+
if (!this.#hasSwipe)
|
|
169
|
+
return html `${row}<slot name="swipe-start" hidden @slotchange=${() => this.requestUpdate()}></slot><slot name="swipe-end" hidden @slotchange=${() => this.requestUpdate()}></slot>`;
|
|
170
|
+
const offset = this._drag ?? (this.open === 'start' ? this.#width('start') : this.open === 'end' ? -this.#width('end') : 0);
|
|
171
|
+
return html `<div class="pm-list-swipe" part="swipe" ?data-divided=${divided} ?data-dragging=${this._drag !== undefined}
|
|
172
|
+
style="--_x: ${offset}px" @pointerdown=${this.#onDown} @pointermove=${this.#onMove} @pointerup=${this.#onUp} @pointercancel=${this.#onUp} @click=${this.#onClick}>
|
|
173
|
+
<div class="pm-list-actions" part="actions-start" data-side="start"><slot name="swipe-start" @slotchange=${() => this.requestUpdate()}></slot></div>
|
|
174
|
+
<div class="pm-list-actions" part="actions-end" data-side="end"><slot name="swipe-end" @slotchange=${() => this.requestUpdate()}></slot></div>
|
|
175
|
+
${row}
|
|
176
|
+
</div>`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
defineElement('pm-list', PmList);
|
|
180
|
+
defineElement('pm-list-item', PmListItem);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SafeHTMLElement } from '../base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Menu (role="menu") opened from a button with `popovertarget`. Arrow keys, Home/End and typeahead.
|
|
4
|
+
*
|
|
5
|
+
* Items: `<button role="menuitem">` or `<a role="menuitem">`. `role="menuitemcheckbox"` toggles and
|
|
6
|
+
* `role="menuitemradio"` picks one within its `role="group"` (or the menu); both show a tick from `aria-checked`.
|
|
7
|
+
* A submenu is a nested `<pm-menu id="x">` opened by an item with `popovertarget="x"`: it opens on hover, click and
|
|
8
|
+
* Arrow Right, and closes with Arrow Left or Escape.
|
|
9
|
+
* @attr {boolean} mobile - Native mobile pattern on phones: opens as a swipeable bottom sheet (inherits from ancestors such as `<html mobile>`; `mobile="false"` opts out).
|
|
10
|
+
* @tag pm-menu
|
|
11
|
+
* @slot - Menu items: `<button role="menuitem">`, `<a role="menuitem">`, `<hr>` separators, nested `<pm-menu>` submenus.
|
|
12
|
+
* @fires pm-select - detail: { item, checked? } (`checked` for checkbox and radio items)
|
|
13
|
+
* @example <button popovertarget="m" aria-haspopup="menu">Actions</button>
|
|
14
|
+
* <pm-menu id="m"><button role="menuitem">Rename</button><button role="menuitem" data-tone="danger">Delete</button></pm-menu>
|
|
15
|
+
*/
|
|
16
|
+
export declare class PmMenu extends SafeHTMLElement {
|
|
17
|
+
#private;
|
|
18
|
+
connectedCallback(): void;
|
|
19
|
+
disconnectedCallback(): void;
|
|
20
|
+
/** Own items only: a submenu's items belong to the submenu. */
|
|
21
|
+
get items(): HTMLElement[];
|
|
22
|
+
}
|