@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,140 @@
|
|
|
1
|
+
import { SafeHTMLElement, defineElement } from '../base.js';
|
|
2
|
+
import { fallbackPosition } from '../position.js';
|
|
3
|
+
import overlayCss from '../styles/overlay.js';
|
|
4
|
+
import popoverCss from '../styles/popover.js';
|
|
5
|
+
/**
|
|
6
|
+
* Non-modal popover panel. Trigger with native `popovertarget="id"` on any button.
|
|
7
|
+
*
|
|
8
|
+
* `trigger="hover"` turns it into a hover card: it opens when the element named by `for` is hovered or focused and
|
|
9
|
+
* stays open while the pointer is over the card, so its content can be read and clicked. Keep hover cards
|
|
10
|
+
* supplementary: touch users reach the same content by following the link. `class="pm-mega"` lays the panel out as
|
|
11
|
+
* a wide grid of link groups for a navigation (mega) menu.
|
|
12
|
+
* @tag pm-popover
|
|
13
|
+
* @attr {'auto' | 'manual'} popover - Light-dismiss behaviour (default auto).
|
|
14
|
+
* @attr {'click' | 'hover'} trigger - How it opens: by its `popovertarget` button (default), or on hover and focus of the `for` element.
|
|
15
|
+
* @attr {string} for - id of the element that opens a hover card.
|
|
16
|
+
* @attr {'bottom' | 'top' | 'start' | 'end'} placement - Side of the trigger it opens on (default bottom); flips when there is no room.
|
|
17
|
+
* @slot - Panel content.
|
|
18
|
+
* @example <button popovertarget="share">Share</button><pm-popover id="share">…</pm-popover>
|
|
19
|
+
*/
|
|
20
|
+
export class PmPopover extends SafeHTMLElement {
|
|
21
|
+
static get observedAttributes() { return ['trigger', 'for', 'placement']; }
|
|
22
|
+
#anchor = null;
|
|
23
|
+
#showTimer = 0;
|
|
24
|
+
#hideTimer = 0;
|
|
25
|
+
connectedCallback() {
|
|
26
|
+
this.classList.add('pm-popover');
|
|
27
|
+
if (!this.hasAttribute('popover'))
|
|
28
|
+
this.setAttribute('popover', 'auto');
|
|
29
|
+
this.addEventListener('toggle', this.#onToggle);
|
|
30
|
+
this.addEventListener('pointerenter', this.#keep);
|
|
31
|
+
this.addEventListener('pointerleave', this.#leave);
|
|
32
|
+
this.addEventListener('focusout', this.#leave);
|
|
33
|
+
this.#sync();
|
|
34
|
+
queueMicrotask(() => this.#wire());
|
|
35
|
+
}
|
|
36
|
+
disconnectedCallback() {
|
|
37
|
+
this.removeEventListener('toggle', this.#onToggle);
|
|
38
|
+
this.removeEventListener('pointerenter', this.#keep);
|
|
39
|
+
this.removeEventListener('pointerleave', this.#leave);
|
|
40
|
+
this.removeEventListener('focusout', this.#leave);
|
|
41
|
+
this.#unwire();
|
|
42
|
+
}
|
|
43
|
+
attributeChangedCallback() { if (this.isConnected) {
|
|
44
|
+
this.#sync();
|
|
45
|
+
this.#unwire();
|
|
46
|
+
this.#wire();
|
|
47
|
+
} }
|
|
48
|
+
get #hover() { return this.getAttribute('trigger') === 'hover'; }
|
|
49
|
+
get #placement() {
|
|
50
|
+
const p = this.getAttribute('placement');
|
|
51
|
+
return p === 'top' || p === 'start' || p === 'end' ? p : 'bottom';
|
|
52
|
+
}
|
|
53
|
+
#sync() {
|
|
54
|
+
if (this.#placement === 'bottom')
|
|
55
|
+
this.removeAttribute('data-placement');
|
|
56
|
+
else
|
|
57
|
+
this.setAttribute('data-placement', this.#placement);
|
|
58
|
+
}
|
|
59
|
+
#wire() {
|
|
60
|
+
if (!this.#hover)
|
|
61
|
+
return;
|
|
62
|
+
const id = this.getAttribute('for');
|
|
63
|
+
this.#anchor = id ? document.getElementById(id) : null;
|
|
64
|
+
const a = this.#anchor;
|
|
65
|
+
if (!a)
|
|
66
|
+
return;
|
|
67
|
+
a.addEventListener('pointerenter', this.#enter);
|
|
68
|
+
a.addEventListener('pointerleave', this.#leave);
|
|
69
|
+
a.addEventListener('focusin', this.#enter);
|
|
70
|
+
a.addEventListener('focusout', this.#leave);
|
|
71
|
+
a.addEventListener('keydown', this.#onKey);
|
|
72
|
+
}
|
|
73
|
+
#unwire() {
|
|
74
|
+
clearTimeout(this.#showTimer);
|
|
75
|
+
clearTimeout(this.#hideTimer);
|
|
76
|
+
const a = this.#anchor;
|
|
77
|
+
if (!a)
|
|
78
|
+
return;
|
|
79
|
+
a.removeEventListener('pointerenter', this.#enter);
|
|
80
|
+
a.removeEventListener('pointerleave', this.#leave);
|
|
81
|
+
a.removeEventListener('focusin', this.#enter);
|
|
82
|
+
a.removeEventListener('focusout', this.#leave);
|
|
83
|
+
a.removeEventListener('keydown', this.#onKey);
|
|
84
|
+
this.#anchor = null;
|
|
85
|
+
}
|
|
86
|
+
#enter = (e) => {
|
|
87
|
+
// Touch has no hover: the trigger keeps its own action (usually a link).
|
|
88
|
+
if (e instanceof PointerEvent && e.pointerType === 'touch')
|
|
89
|
+
return;
|
|
90
|
+
clearTimeout(this.#hideTimer);
|
|
91
|
+
this.#showTimer = window.setTimeout(() => {
|
|
92
|
+
if (this.matches(':popover-open') || !this.#anchor?.isConnected)
|
|
93
|
+
return;
|
|
94
|
+
// `source` makes the trigger the anchor for CSS anchor positioning.
|
|
95
|
+
try {
|
|
96
|
+
this.showPopover({ source: this.#anchor });
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
try {
|
|
100
|
+
this.showPopover();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
fallbackPosition(this, this.#anchor, this.#placement);
|
|
107
|
+
}, e.type === 'focusin' ? 0 : 300);
|
|
108
|
+
};
|
|
109
|
+
#keep = () => { if (this.#hover)
|
|
110
|
+
clearTimeout(this.#hideTimer); };
|
|
111
|
+
#leave = () => {
|
|
112
|
+
if (!this.#hover)
|
|
113
|
+
return;
|
|
114
|
+
clearTimeout(this.#showTimer);
|
|
115
|
+
this.#hideTimer = window.setTimeout(() => {
|
|
116
|
+
// Still in use: pointer over the card or the trigger, or focus inside the card.
|
|
117
|
+
if (this.matches(':hover') || this.#anchor?.matches(':hover') || this.contains(document.activeElement))
|
|
118
|
+
return;
|
|
119
|
+
try {
|
|
120
|
+
if (this.matches(':popover-open'))
|
|
121
|
+
this.hidePopover();
|
|
122
|
+
}
|
|
123
|
+
catch { /* already closed */ }
|
|
124
|
+
}, 200);
|
|
125
|
+
};
|
|
126
|
+
#onKey = (e) => {
|
|
127
|
+
if (e.key === 'Escape' && this.matches(':popover-open')) {
|
|
128
|
+
clearTimeout(this.#showTimer);
|
|
129
|
+
this.hidePopover();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
#onToggle = (e) => {
|
|
133
|
+
if (e.newState !== 'open' || this.#hover)
|
|
134
|
+
return;
|
|
135
|
+
const invoker = this.id ? document.querySelector(`[popovertarget="${CSS.escape(this.id)}"]`) : null;
|
|
136
|
+
if (invoker)
|
|
137
|
+
fallbackPosition(this, invoker, this.#placement);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
defineElement('pm-popover', PmPopover, [overlayCss, popoverCss]);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Progress bar or ring (`variant="circular"`); determinate when `value` is set, indeterminate otherwise.
|
|
5
|
+
* @tag pm-progress
|
|
6
|
+
* @example <pm-progress label="Uploading" value="40"></pm-progress>
|
|
7
|
+
*/
|
|
8
|
+
export declare class PmProgress extends PmElement {
|
|
9
|
+
#private;
|
|
10
|
+
static componentName: string;
|
|
11
|
+
static styles: import("lit").CSSResult[];
|
|
12
|
+
static properties: PropertyDeclarations;
|
|
13
|
+
value?: number;
|
|
14
|
+
max: number;
|
|
15
|
+
/** Visible label and accessible name. */
|
|
16
|
+
label?: string;
|
|
17
|
+
size?: 'sm' | 'md' | 'lg';
|
|
18
|
+
/** `linear` (default) or `circular`. */
|
|
19
|
+
variant?: 'linear' | 'circular';
|
|
20
|
+
/** Keep the label as accessible name only. */
|
|
21
|
+
hideLabel: boolean;
|
|
22
|
+
/** Show the percentage next to the label. */
|
|
23
|
+
showValue: boolean;
|
|
24
|
+
constructor();
|
|
25
|
+
render(): import("lit").TemplateResult<1>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { PmElement, nextId, defineElement } from '../base.js';
|
|
4
|
+
import progressCss from '../styles/progress.js';
|
|
5
|
+
/**
|
|
6
|
+
* Progress bar or ring (`variant="circular"`); determinate when `value` is set, indeterminate otherwise.
|
|
7
|
+
* @tag pm-progress
|
|
8
|
+
* @example <pm-progress label="Uploading" value="40"></pm-progress>
|
|
9
|
+
*/
|
|
10
|
+
export class PmProgress extends PmElement {
|
|
11
|
+
static { this.componentName = 'progress'; }
|
|
12
|
+
static { this.styles = [...PmElement.styles, progressCss,
|
|
13
|
+
css `
|
|
14
|
+
:host { display: block; }
|
|
15
|
+
.head { display: flex; justify-content: space-between; gap: var(--pm-space-2); margin-block-end: var(--pm-space-1-5, 0.375rem);
|
|
16
|
+
font-size: var(--pm-font-size-sm); font-weight: 500; color: var(--pm-color-fg); }
|
|
17
|
+
.value { color: var(--pm-color-fg-muted); font-variant-numeric: tabular-nums; }
|
|
18
|
+
:host([variant="circular"]) { display: inline-block; }
|
|
19
|
+
.ring { --_s: 2.75rem; position: relative; display: inline-grid; place-items: center; inline-size: var(--_s); block-size: var(--_s); color: var(--pm-tone-solid); }
|
|
20
|
+
.ring[data-size="sm"] { --_s: 1.75rem; } .ring[data-size="lg"] { --_s: 4.5rem; }
|
|
21
|
+
.ring svg { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; rotate: -90deg; }
|
|
22
|
+
.ring .track { stroke: var(--pm-color-bg-active); }
|
|
23
|
+
.ring .bar { stroke: currentColor; stroke-linecap: round; }
|
|
24
|
+
@media (prefers-reduced-motion: no-preference) { .ring .bar { transition: stroke-dashoffset var(--pm-duration-slow) var(--pm-ease-standard); } }
|
|
25
|
+
.ring[data-indeterminate] svg { animation: pm-ring-spin 1s linear infinite; }
|
|
26
|
+
@media (prefers-reduced-motion: reduce) { .ring[data-indeterminate] svg { animation-duration: 4s; } }
|
|
27
|
+
@keyframes pm-ring-spin { to { rotate: 270deg; } }
|
|
28
|
+
.ring .pct { font-size: calc(var(--_s) * 0.26); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--pm-color-fg); }
|
|
29
|
+
@media (forced-colors: active) { .ring .bar { stroke: Highlight; } .ring .track { stroke: GrayText; } }
|
|
30
|
+
`,
|
|
31
|
+
]; }
|
|
32
|
+
static { this.properties = {
|
|
33
|
+
value: { type: Number }, max: { type: Number }, label: {}, size: { reflect: true },
|
|
34
|
+
variant: { reflect: true },
|
|
35
|
+
hideLabel: { type: Boolean, attribute: 'hide-label' }, showValue: { type: Boolean, attribute: 'show-value' },
|
|
36
|
+
}; }
|
|
37
|
+
#id = nextId('progress');
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
this.max = 100;
|
|
41
|
+
this.hideLabel = false;
|
|
42
|
+
this.showValue = false;
|
|
43
|
+
}
|
|
44
|
+
render() {
|
|
45
|
+
const pct = this.value != null ? Math.round((this.value / (this.max || 100)) * 100) : null;
|
|
46
|
+
const head = this.label && !this.hideLabel;
|
|
47
|
+
if (this.variant === 'circular') {
|
|
48
|
+
const r = 20;
|
|
49
|
+
const c = 2 * Math.PI * r;
|
|
50
|
+
const off = pct == null ? c * 0.72 : c * (1 - Math.min(100, Math.max(0, pct)) / 100);
|
|
51
|
+
return html `<span class="ring" part="base" role="progressbar" data-size=${ifDefined(this.size)} ?data-indeterminate=${pct == null}
|
|
52
|
+
aria-label=${ifDefined(this.label)} aria-valuemin="0" aria-valuemax=${pct == null ? nothing : this.max}
|
|
53
|
+
aria-valuenow=${pct == null ? nothing : (this.value ?? 0)}>
|
|
54
|
+
<svg viewBox="0 0 48 48" aria-hidden="true"><circle class="track" cx="24" cy="24" r=${r} fill="none" stroke-width="4"></circle>
|
|
55
|
+
<circle class="bar" cx="24" cy="24" r=${r} fill="none" stroke-width="4" stroke-dasharray=${c} stroke-dashoffset=${off}></circle></svg>
|
|
56
|
+
${this.showValue && pct != null ? html `<span class="pct" aria-hidden="true">${pct}%</span>` : nothing}
|
|
57
|
+
</span>`;
|
|
58
|
+
}
|
|
59
|
+
return html `${head || (this.showValue && pct != null)
|
|
60
|
+
? html `<div class="head"><label for=${this.#id}>${head ? this.label : ''}</label>${this.showValue && pct != null ? html `<span class="value" aria-hidden="true">${pct}%</span>` : nothing}</div>`
|
|
61
|
+
: nothing}
|
|
62
|
+
<progress part="base" id=${this.#id} class="pm-progress" data-size=${ifDefined(this.size)} max=${this.max}
|
|
63
|
+
value=${ifDefined(this.value ?? undefined)} aria-label=${ifDefined(head ? undefined : this.label)}></progress>`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
defineElement('pm-progress', PmProgress);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/** `pm-refresh` detail: call `waitUntil(promise)` to keep the spinner until your data has loaded. */
|
|
4
|
+
export interface PullRefreshDetail {
|
|
5
|
+
waitUntil(work: Promise<unknown>): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Pull down from the top of a list or page to reload it on touch screens, with a spinner while it refreshes.
|
|
9
|
+
*
|
|
10
|
+
* Wrap the scrolling content: the element scrolls itself when it has a height (`style="block-size: 30rem"`),
|
|
11
|
+
* otherwise it follows the page scroll. Pulling past `threshold` and letting go fires `pm-refresh`; pass your
|
|
12
|
+
* reload to `event.detail.waitUntil(fetch(...))` and the spinner stays until it settles (or set `refreshing` yourself
|
|
13
|
+
* and clear it). It stops the browser's own pull-to-reload inside it. Pulling needs touch, so also offer another way
|
|
14
|
+
* to refresh for mouse and keyboard users: `<pm-button commandfor="feed" command="--refresh">` or `refresh()`.
|
|
15
|
+
* @tag pm-pull-refresh
|
|
16
|
+
* @slot - The scrolling content.
|
|
17
|
+
* @csspart indicator - The circle with the arrow or spinner.
|
|
18
|
+
* @fires pm-refresh - The user pulled to refresh. detail: { waitUntil(promise) }
|
|
19
|
+
* @example <pm-pull-refresh style="block-size: 20rem"><pm-list divided>…</pm-list></pm-pull-refresh>
|
|
20
|
+
*/
|
|
21
|
+
export declare class PmPullRefresh extends PmElement {
|
|
22
|
+
#private;
|
|
23
|
+
static componentName: string;
|
|
24
|
+
static styles: import("lit").CSSResult[];
|
|
25
|
+
static properties: PropertyDeclarations;
|
|
26
|
+
/** A refresh is running (spinner shown). */
|
|
27
|
+
refreshing: boolean;
|
|
28
|
+
/** Pixels to pull before letting go refreshes. */
|
|
29
|
+
threshold: number;
|
|
30
|
+
/** Turn pulling off. */
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
/** Announced while refreshing. */
|
|
33
|
+
label: string;
|
|
34
|
+
_pull: number;
|
|
35
|
+
constructor();
|
|
36
|
+
connectedCallback(): void;
|
|
37
|
+
protected firstUpdated(): void;
|
|
38
|
+
/** Refresh as if pulled: fires `pm-refresh` and shows the spinner until the work passed to `waitUntil` settles. */
|
|
39
|
+
refresh(): void;
|
|
40
|
+
render(): import("lit").TemplateResult<1>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { css, html } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import pullRefreshCss from '../styles/pull-refresh.js';
|
|
4
|
+
/**
|
|
5
|
+
* Pull down from the top of a list or page to reload it on touch screens, with a spinner while it refreshes.
|
|
6
|
+
*
|
|
7
|
+
* Wrap the scrolling content: the element scrolls itself when it has a height (`style="block-size: 30rem"`),
|
|
8
|
+
* otherwise it follows the page scroll. Pulling past `threshold` and letting go fires `pm-refresh`; pass your
|
|
9
|
+
* reload to `event.detail.waitUntil(fetch(...))` and the spinner stays until it settles (or set `refreshing` yourself
|
|
10
|
+
* and clear it). It stops the browser's own pull-to-reload inside it. Pulling needs touch, so also offer another way
|
|
11
|
+
* to refresh for mouse and keyboard users: `<pm-button commandfor="feed" command="--refresh">` or `refresh()`.
|
|
12
|
+
* @tag pm-pull-refresh
|
|
13
|
+
* @slot - The scrolling content.
|
|
14
|
+
* @csspart indicator - The circle with the arrow or spinner.
|
|
15
|
+
* @fires pm-refresh - The user pulled to refresh. detail: { waitUntil(promise) }
|
|
16
|
+
* @example <pm-pull-refresh style="block-size: 20rem"><pm-list divided>…</pm-list></pm-pull-refresh>
|
|
17
|
+
*/
|
|
18
|
+
export class PmPullRefresh extends PmElement {
|
|
19
|
+
static { this.componentName = 'pull-refresh'; }
|
|
20
|
+
static { this.styles = [...PmElement.styles, pullRefreshCss, css `:host { display: block; position: relative; overscroll-behavior-y: contain; } :host([style*="block-size"]), :host([style*="height"]) { overflow-y: auto; }`]; }
|
|
21
|
+
static { this.properties = {
|
|
22
|
+
refreshing: { type: Boolean, reflect: true }, threshold: { type: Number }, disabled: { type: Boolean, reflect: true }, label: {}, _pull: { state: true },
|
|
23
|
+
}; }
|
|
24
|
+
#from;
|
|
25
|
+
constructor() { super(); this.refreshing = false; this.threshold = 72; this.disabled = false; this.label = 'Refreshing…'; this._pull = 0; }
|
|
26
|
+
connectedCallback() {
|
|
27
|
+
super.connectedCallback();
|
|
28
|
+
this.addEventListener('touchstart', this.#onStart, { passive: true });
|
|
29
|
+
this.addEventListener('touchmove', this.#onMove, { passive: false });
|
|
30
|
+
this.addEventListener('touchend', this.#onEnd);
|
|
31
|
+
this.addEventListener('touchcancel', this.#onEnd);
|
|
32
|
+
// Invoker buttons: <pm-button commandfor="id" command="--refresh">.
|
|
33
|
+
this.addEventListener('command', (e) => { if (e.command === '--refresh')
|
|
34
|
+
this.refresh(); });
|
|
35
|
+
}
|
|
36
|
+
/** Scrolled to the very top (its own scroll, or the page's when it does not scroll itself). */
|
|
37
|
+
get #atTop() { return this.scrollHeight > this.clientHeight && getComputedStyle(this).overflowY !== 'visible' ? this.scrollTop <= 0 : (document.scrollingElement?.scrollTop ?? 0) <= 0; }
|
|
38
|
+
#onStart = (e) => {
|
|
39
|
+
if (this.disabled || this.refreshing || e.touches.length !== 1 || !this.#atTop) {
|
|
40
|
+
this.#from = undefined;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.#from = { y: e.touches[0].clientY, x: e.touches[0].clientX, pulling: false };
|
|
44
|
+
};
|
|
45
|
+
#onMove = (e) => {
|
|
46
|
+
const f = this.#from;
|
|
47
|
+
if (!f)
|
|
48
|
+
return;
|
|
49
|
+
const dy = e.touches[0].clientY - f.y, dx = e.touches[0].clientX - f.x;
|
|
50
|
+
if (!f.pulling) {
|
|
51
|
+
if (dy <= 0 || Math.abs(dx) > Math.abs(dy) || !this.#atTop) {
|
|
52
|
+
if (Math.abs(dy) > 6 || Math.abs(dx) > 6)
|
|
53
|
+
this.#from = undefined;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (dy < 6)
|
|
57
|
+
return;
|
|
58
|
+
f.pulling = true;
|
|
59
|
+
}
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
// Resistance: the indicator moves less the further you pull.
|
|
62
|
+
this._pull = Math.max(0, Math.min(this.threshold * 1.6, dy * 0.5));
|
|
63
|
+
};
|
|
64
|
+
#onEnd = () => {
|
|
65
|
+
const pulled = this.#from?.pulling && this._pull >= this.threshold;
|
|
66
|
+
this.#from = undefined;
|
|
67
|
+
this._pull = 0;
|
|
68
|
+
if (pulled)
|
|
69
|
+
this.refresh();
|
|
70
|
+
};
|
|
71
|
+
firstUpdated() {
|
|
72
|
+
// A region that scrolls itself must be reachable by keyboard to scroll it (WCAG 2.1.1).
|
|
73
|
+
if (!this.hasAttribute('tabindex') && /auto|scroll/.test(getComputedStyle(this).overflowY))
|
|
74
|
+
this.tabIndex = 0;
|
|
75
|
+
}
|
|
76
|
+
/** Refresh as if pulled: fires `pm-refresh` and shows the spinner until the work passed to `waitUntil` settles. */
|
|
77
|
+
refresh() {
|
|
78
|
+
if (this.refreshing)
|
|
79
|
+
return;
|
|
80
|
+
const work = [];
|
|
81
|
+
this.refreshing = true;
|
|
82
|
+
this.emit('pm-refresh', { waitUntil: (p) => void work.push(p) });
|
|
83
|
+
// Listeners that call waitUntil keep the spinner; without one it shows briefly as confirmation.
|
|
84
|
+
void Promise.allSettled(work.length ? work : [new Promise((r) => setTimeout(r, 600))]).then(() => { this.refreshing = false; });
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
const progress = Math.min(1, this._pull / this.threshold);
|
|
88
|
+
const shown = this.refreshing ? this.threshold * 0.75 : this._pull;
|
|
89
|
+
return html `<div class="pm-pull" part="base" ?data-pulling=${this._pull > 0} ?data-ready=${progress >= 1} ?data-refreshing=${this.refreshing}
|
|
90
|
+
style="--_pull: ${shown}px; --_progress: ${progress}">
|
|
91
|
+
<div class="pm-pull-indicator" part="indicator" aria-hidden="true">
|
|
92
|
+
${this.refreshing
|
|
93
|
+
? html `<svg class="pm-pull-spin" viewBox="0 0 24 24" width="1.25em" height="1.25em" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M21 12a9 9 0 1 1-6.2-8.56"/></svg>`
|
|
94
|
+
: html `<svg class="pm-pull-arrow" viewBox="0 0 24 24" width="1.25em" height="1.25em" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>`}
|
|
95
|
+
</div>
|
|
96
|
+
<div class="pm-pull-content"><slot></slot></div>
|
|
97
|
+
</div>
|
|
98
|
+
<span class="pm-visually-hidden" role="status">${this.refreshing ? this.label : ''}</span>`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
defineElement('pm-pull-refresh', PmPullRefresh);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
import { type QrLevel } from '../qr.js';
|
|
4
|
+
/**
|
|
5
|
+
* QR code for a link or short text, drawn as SVG without any dependency.
|
|
6
|
+
*
|
|
7
|
+
* It is always dark on light with a quiet zone, whatever the theme, because scanners need that contrast. Holds up
|
|
8
|
+
* to 213 bytes at the default error-correction level; show the same link as text nearby for people who cannot scan.
|
|
9
|
+
* @tag pm-qr-code
|
|
10
|
+
* @slot - Caption under the code.
|
|
11
|
+
* @example <pm-qr-code value="https://prismora.design" label="Open prismora.design"></pm-qr-code>
|
|
12
|
+
*/
|
|
13
|
+
export declare class PmQrCode extends PmElement {
|
|
14
|
+
static componentName: string;
|
|
15
|
+
static styles: import("lit").CSSResult[];
|
|
16
|
+
static properties: PropertyDeclarations;
|
|
17
|
+
/** The link or text to encode. */
|
|
18
|
+
value?: string;
|
|
19
|
+
/** Accessible name: say where the code leads ("Open the booking page"). */
|
|
20
|
+
label?: string;
|
|
21
|
+
/** Width and height in pixels (default 160). */
|
|
22
|
+
size: number;
|
|
23
|
+
/** How much damage the code survives: L (7%), M (15%, default), Q (25%) or H (30%). Higher levels hold less text. */
|
|
24
|
+
errorCorrection: QrLevel;
|
|
25
|
+
/** Quiet zone around the code, in modules (default 4, the standard's minimum). */
|
|
26
|
+
margin: number;
|
|
27
|
+
constructor();
|
|
28
|
+
/** The encoded modules (rows of booleans), or null when there is no value or it does not fit. */
|
|
29
|
+
get matrix(): boolean[][] | null;
|
|
30
|
+
/** The code as a standalone SVG document, for saving or printing. */
|
|
31
|
+
toSvg(): string;
|
|
32
|
+
render(): import("lit").TemplateResult<1>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { css, html, nothing, svg } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import { qrMatrix, qrPath } from '../qr.js';
|
|
4
|
+
import extrasCss from '../styles/extras.js';
|
|
5
|
+
/**
|
|
6
|
+
* QR code for a link or short text, drawn as SVG without any dependency.
|
|
7
|
+
*
|
|
8
|
+
* It is always dark on light with a quiet zone, whatever the theme, because scanners need that contrast. Holds up
|
|
9
|
+
* to 213 bytes at the default error-correction level; show the same link as text nearby for people who cannot scan.
|
|
10
|
+
* @tag pm-qr-code
|
|
11
|
+
* @slot - Caption under the code.
|
|
12
|
+
* @example <pm-qr-code value="https://prismora.design" label="Open prismora.design"></pm-qr-code>
|
|
13
|
+
*/
|
|
14
|
+
export class PmQrCode extends PmElement {
|
|
15
|
+
static { this.componentName = 'qr-code'; }
|
|
16
|
+
static { this.styles = [...PmElement.styles, extrasCss, css `:host { display: inline-block; } :host([hidden]) { display: none; }`]; }
|
|
17
|
+
static { this.properties = {
|
|
18
|
+
value: {}, label: {}, size: { type: Number }, errorCorrection: { attribute: 'error-correction' }, margin: { type: Number },
|
|
19
|
+
}; }
|
|
20
|
+
constructor() { super(); this.size = 160; this.errorCorrection = 'M'; this.margin = 4; }
|
|
21
|
+
/** The encoded modules (rows of booleans), or null when there is no value or it does not fit. */
|
|
22
|
+
get matrix() {
|
|
23
|
+
if (!this.value)
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
return qrMatrix(this.value, ['L', 'M', 'Q', 'H'].includes(this.errorCorrection) ? this.errorCorrection : 'M');
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The code as a standalone SVG document, for saving or printing. */
|
|
33
|
+
toSvg() {
|
|
34
|
+
const m = this.matrix;
|
|
35
|
+
if (!m)
|
|
36
|
+
return '';
|
|
37
|
+
const n = m.length + this.margin * 2;
|
|
38
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${n} ${n}" width="${this.size}" height="${this.size}" shape-rendering="crispEdges"><rect width="${n}" height="${n}" fill="#fff"/><path d="${qrPath(m, this.margin)}" fill="#000"/></svg>`;
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
const m = this.matrix;
|
|
42
|
+
const style = `--_size: ${this.size}px`;
|
|
43
|
+
if (!m) {
|
|
44
|
+
return html `<figure class="pm-qr" part="base" style=${style}><div class="pm-qr-error" role="img" aria-label=${this.value ? 'QR code unavailable: the text is too long' : 'No QR code'}>${this.value ? 'Too much text for a QR code' : 'Nothing to encode'}</div></figure>`;
|
|
45
|
+
}
|
|
46
|
+
const n = m.length + this.margin * 2;
|
|
47
|
+
const hasCaption = !!this.textContent?.trim() || this.childElementCount > 0;
|
|
48
|
+
return html `<figure class="pm-qr" part="base" style=${style}>
|
|
49
|
+
<svg part="svg" viewBox="0 0 ${n} ${n}" role="img" aria-label=${this.label ?? `QR code: ${this.value}`} shape-rendering="crispEdges">${svg `<path d=${qrPath(m, this.margin)} fill="currentColor"/>`}</svg>
|
|
50
|
+
${hasCaption ? html `<figcaption part="caption"><slot></slot></figcaption>` : nothing}
|
|
51
|
+
</figure>`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
defineElement('pm-qr-code', PmQrCode);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { SafeHTMLElement } from '../base.js';
|
|
3
|
+
import { PmFormControl } from './form-control.js';
|
|
4
|
+
/**
|
|
5
|
+
* Radio group: choose one option from a short list.
|
|
6
|
+
*
|
|
7
|
+
* Declare choices as `<pm-radio value="x">Label</pm-radio>` children; the group renders native radios in one shadow
|
|
8
|
+
* root so arrow-key navigation and `name` grouping work natively. `variant="card"` shows each choice as a selectable
|
|
9
|
+
* card; add `description` to a `<pm-radio>` for a second line.
|
|
10
|
+
* @tag pm-radio-group
|
|
11
|
+
* @example <pm-radio-group label="Plan" name="plan" value="pro"><pm-radio value="free">Free</pm-radio><pm-radio value="pro">Pro</pm-radio></pm-radio-group>
|
|
12
|
+
*/
|
|
13
|
+
export declare class PmRadioGroup extends PmFormControl {
|
|
14
|
+
#private;
|
|
15
|
+
static styles: import("lit").CSSResult[];
|
|
16
|
+
static componentName: string;
|
|
17
|
+
static properties: PropertyDeclarations;
|
|
18
|
+
orientation: 'vertical' | 'horizontal';
|
|
19
|
+
/** list (default) or card. */
|
|
20
|
+
variant?: 'list' | 'card';
|
|
21
|
+
constructor();
|
|
22
|
+
connectedCallback(): void;
|
|
23
|
+
disconnectedCallback(): void;
|
|
24
|
+
protected get control(): HTMLInputElement | null;
|
|
25
|
+
render(): import("lit").TemplateResult<1>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Choice declaration for `pm-radio-group` (renders nothing itself).
|
|
29
|
+
* @tag pm-radio
|
|
30
|
+
* @attr {string} value - Value submitted when chosen.
|
|
31
|
+
* @attr {string} description - Second line under the label (card variant).
|
|
32
|
+
* @attr {boolean} disabled - Disable this choice.
|
|
33
|
+
* @slot - Choice label (text).
|
|
34
|
+
*/
|
|
35
|
+
export declare class PmRadio extends SafeHTMLElement {
|
|
36
|
+
constructor();
|
|
37
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 { SafeHTMLElement, defineElement } from '../base.js';
|
|
5
|
+
import { PmFormControl } from './form-control.js';
|
|
6
|
+
import checkboxCss from '../styles/checkbox.js';
|
|
7
|
+
import helpersCss from '../styles/helpers.js';
|
|
8
|
+
/**
|
|
9
|
+
* Radio group: choose one option from a short list.
|
|
10
|
+
*
|
|
11
|
+
* Declare choices as `<pm-radio value="x">Label</pm-radio>` children; the group renders native radios in one shadow
|
|
12
|
+
* root so arrow-key navigation and `name` grouping work natively. `variant="card"` shows each choice as a selectable
|
|
13
|
+
* card; add `description` to a `<pm-radio>` for a second line.
|
|
14
|
+
* @tag pm-radio-group
|
|
15
|
+
* @example <pm-radio-group label="Plan" name="plan" value="pro"><pm-radio value="free">Free</pm-radio><pm-radio value="pro">Pro</pm-radio></pm-radio-group>
|
|
16
|
+
*/
|
|
17
|
+
export class PmRadioGroup extends PmFormControl {
|
|
18
|
+
static { this.styles = [...PmFormControl.styles, checkboxCss, helpersCss]; }
|
|
19
|
+
static { this.componentName = 'radio-group'; }
|
|
20
|
+
static { this.properties = { orientation: { reflect: true }, variant: { reflect: true } }; }
|
|
21
|
+
#items = [];
|
|
22
|
+
#observer;
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.orientation = 'vertical';
|
|
26
|
+
}
|
|
27
|
+
connectedCallback() {
|
|
28
|
+
super.connectedCallback();
|
|
29
|
+
this.#read();
|
|
30
|
+
this.#observer = new MutationObserver(() => { this.#read(); this.requestUpdate(); });
|
|
31
|
+
this.#observer.observe(this, { childList: true, subtree: true, characterData: true });
|
|
32
|
+
}
|
|
33
|
+
disconnectedCallback() {
|
|
34
|
+
super.disconnectedCallback();
|
|
35
|
+
this.#observer?.disconnect();
|
|
36
|
+
}
|
|
37
|
+
#read() {
|
|
38
|
+
this.#items = [...this.querySelectorAll('pm-radio')].map((r) => ({
|
|
39
|
+
value: r.getAttribute('value') ?? '',
|
|
40
|
+
label: r.textContent?.trim() ?? '',
|
|
41
|
+
description: r.getAttribute('description') ?? '',
|
|
42
|
+
disabled: r.hasAttribute('disabled'),
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
get control() {
|
|
46
|
+
return this.renderRoot?.querySelector('input') ?? null;
|
|
47
|
+
}
|
|
48
|
+
render() {
|
|
49
|
+
const name = this.controlId;
|
|
50
|
+
return html `<fieldset class="pm-field" part="field" style="border:0;margin:0;padding:0;min-inline-size:0"
|
|
51
|
+
aria-describedby=${ifDefined(this.describedBy())}>
|
|
52
|
+
${this.label ? html `<legend class=${this.hideLabel ? 'pm-visually-hidden' : 'pm-label'} part="label"
|
|
53
|
+
style="padding:0;margin-block-end:var(--pm-space-1-5);font-size:var(--pm-font-size-sm);font-weight:var(--pm-font-weight-medium)">${this.label}</legend>` : nothing}
|
|
54
|
+
<div class=${this.variant === 'card' ? 'pm-choice-grid' : this.orientation === 'horizontal' ? 'pm-cluster' : 'pm-stack'} style="--pm-gap:var(--pm-space-2)">
|
|
55
|
+
${this.#items.map((it, i) => html `<label class="pm-check-label" ?data-card=${this.variant === 'card'}>
|
|
56
|
+
<input type="radio" class="pm-radio" name=${name} value=${it.value}
|
|
57
|
+
.checked=${live(it.value === this.value)}
|
|
58
|
+
?disabled=${this.disabled || it.disabled}
|
|
59
|
+
?required=${this.required && i === 0}
|
|
60
|
+
@change=${() => { this.value = it.value; this.onChange(); }} />
|
|
61
|
+
<span class="pm-check-text"><span>${it.label}</span>${it.description ? html `<span class="pm-check-desc">${it.description}</span>` : nothing}</span></label>`)}
|
|
62
|
+
</div>
|
|
63
|
+
${this.hint ? html `<span class="pm-hint" id=${`${this.controlId}-hint`}>${this.hint}</span>` : nothing}
|
|
64
|
+
</fieldset>`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Choice declaration for `pm-radio-group` (renders nothing itself).
|
|
69
|
+
* @tag pm-radio
|
|
70
|
+
* @attr {string} value - Value submitted when chosen.
|
|
71
|
+
* @attr {string} description - Second line under the label (card variant).
|
|
72
|
+
* @attr {boolean} disabled - Disable this choice.
|
|
73
|
+
* @slot - Choice label (text).
|
|
74
|
+
*/
|
|
75
|
+
export class PmRadio extends SafeHTMLElement {
|
|
76
|
+
constructor() {
|
|
77
|
+
super();
|
|
78
|
+
this.hidden = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
defineElement('pm-radio-group', PmRadioGroup);
|
|
82
|
+
defineElement('pm-radio', PmRadio);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Two-thumb range slider (price filters, time windows).
|
|
5
|
+
*
|
|
6
|
+
* Value is "low,high"; with `name` both numbers are submitted under that name. Thumbs never cross and keep `min-gap`
|
|
7
|
+
* apart. Each thumb is a native range input (full keyboard support), labelled "Minimum …" / "Maximum …".
|
|
8
|
+
* @tag pm-range-slider
|
|
9
|
+
* @fires pm-input - While dragging. detail: { value, low, high }
|
|
10
|
+
* @fires pm-change - When committed. detail: { value, low, high }
|
|
11
|
+
* @example <pm-range-slider label="Price" min="0" max="500" value="100,350" step="10" show-value></pm-range-slider>
|
|
12
|
+
*/
|
|
13
|
+
export declare class PmRangeSlider extends PmElement {
|
|
14
|
+
#private;
|
|
15
|
+
static componentName: string;
|
|
16
|
+
static formAssociated: boolean;
|
|
17
|
+
static styles: import("lit").CSSResult[];
|
|
18
|
+
static properties: PropertyDeclarations;
|
|
19
|
+
/** "low,high". */
|
|
20
|
+
value: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
label?: string;
|
|
23
|
+
hint?: string;
|
|
24
|
+
min: number;
|
|
25
|
+
max: number;
|
|
26
|
+
step: number;
|
|
27
|
+
/** Smallest allowed distance between the thumbs. */
|
|
28
|
+
minGap: number;
|
|
29
|
+
showValue: boolean;
|
|
30
|
+
disabled: boolean;
|
|
31
|
+
/** Text after values in the output, e.g. "€" or " km". */
|
|
32
|
+
unit?: string;
|
|
33
|
+
/** Custom error message. Setting it marks the field invalid. */
|
|
34
|
+
error?: string;
|
|
35
|
+
/** Thumb and track size. */
|
|
36
|
+
size?: 'sm' | 'md' | 'lg';
|
|
37
|
+
constructor();
|
|
38
|
+
get low(): number;
|
|
39
|
+
get high(): number;
|
|
40
|
+
connectedCallback(): void;
|
|
41
|
+
formResetCallback(): void;
|
|
42
|
+
formStateRestoreCallback(v: string): void;
|
|
43
|
+
formDisabledCallback(d: boolean): void;
|
|
44
|
+
protected updated(): void;
|
|
45
|
+
render(): import("lit").TemplateResult<1>;
|
|
46
|
+
}
|