@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,26 @@
|
|
|
1
|
+
import { css, html } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { PmElement, defineElement } from '../base.js';
|
|
4
|
+
import skeletonCss from '../styles/skeleton.js';
|
|
5
|
+
/**
|
|
6
|
+
* Loading placeholder.
|
|
7
|
+
* @tag pm-skeleton
|
|
8
|
+
* @example <pm-skeleton shape="text" lines="3"></pm-skeleton>
|
|
9
|
+
*/
|
|
10
|
+
export class PmSkeleton extends PmElement {
|
|
11
|
+
static { this.componentName = 'skeleton'; }
|
|
12
|
+
static { this.styles = [...PmElement.styles, skeletonCss, css `:host { display: block; } :host(:not([shape="circle"])) { flex: 1 1 8rem; min-inline-size: 4rem; } :host([shape="circle"]) { flex: none; }`]; }
|
|
13
|
+
static { this.properties = { shape: { reflect: true }, lines: { type: Number }, width: {}, height: {} }; }
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.lines = 1;
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
const style = `${this.width ? `inline-size:${this.width};` : ''}${this.height ? `block-size:${this.height};` : ''}`;
|
|
20
|
+
return html `<div aria-hidden="true">
|
|
21
|
+
${Array.from({ length: this.lines }, (_, i) => html `<span part="base" class="pm-skeleton" data-shape=${ifDefined(this.shape)}
|
|
22
|
+
style=${this.shape === 'text' && i === this.lines - 1 && this.lines > 1 ? 'inline-size:60%' : style}></span>`)}
|
|
23
|
+
</div>`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
defineElement('pm-skeleton', PmSkeleton);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type PropertyDeclarations, type PropertyValues } from 'lit';
|
|
2
|
+
import { PmFormControl } from './form-control.js';
|
|
3
|
+
/**
|
|
4
|
+
* Range slider. `marks` adds labelled ticks (clickable, and snapped to by the native control); `unit` and `locale`
|
|
5
|
+
* format the shown value and what screen readers hear (`aria-valuetext`).
|
|
6
|
+
* @tag pm-slider
|
|
7
|
+
* @example <pm-slider label="Volume" min="0" max="100" value="40" show-value unit="%"></pm-slider>
|
|
8
|
+
* <pm-slider label="Size" min="0" max="4" marks='[{"value":0,"label":"XS"},{"value":1,"label":"S"},{"value":2,"label":"M"},{"value":3,"label":"L"},{"value":4,"label":"XL"}]'></pm-slider>
|
|
9
|
+
*/
|
|
10
|
+
export declare class PmSlider extends PmFormControl {
|
|
11
|
+
#private;
|
|
12
|
+
static styles: import("lit").CSSResult[];
|
|
13
|
+
static componentName: string;
|
|
14
|
+
static properties: PropertyDeclarations;
|
|
15
|
+
/** Ticks: numbers or `{ value, label }`. */
|
|
16
|
+
marks?: (number | {
|
|
17
|
+
value: number;
|
|
18
|
+
label?: string;
|
|
19
|
+
})[];
|
|
20
|
+
/** Unit after the value, e.g. "%", "px", "kg". */
|
|
21
|
+
unit?: string;
|
|
22
|
+
/** Locale for number formatting. */
|
|
23
|
+
locale?: string;
|
|
24
|
+
min: number;
|
|
25
|
+
max: number;
|
|
26
|
+
step: number;
|
|
27
|
+
showValue: boolean;
|
|
28
|
+
constructor();
|
|
29
|
+
protected willUpdate(changed: PropertyValues<this>): void;
|
|
30
|
+
render(): import("lit").TemplateResult<1>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { css, 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 sliderCss from '../styles/slider.js';
|
|
7
|
+
/**
|
|
8
|
+
* Range slider. `marks` adds labelled ticks (clickable, and snapped to by the native control); `unit` and `locale`
|
|
9
|
+
* format the shown value and what screen readers hear (`aria-valuetext`).
|
|
10
|
+
* @tag pm-slider
|
|
11
|
+
* @example <pm-slider label="Volume" min="0" max="100" value="40" show-value unit="%"></pm-slider>
|
|
12
|
+
* <pm-slider label="Size" min="0" max="4" marks='[{"value":0,"label":"XS"},{"value":1,"label":"S"},{"value":2,"label":"M"},{"value":3,"label":"L"},{"value":4,"label":"XL"}]'></pm-slider>
|
|
13
|
+
*/
|
|
14
|
+
export class PmSlider extends PmFormControl {
|
|
15
|
+
static { this.styles = [...PmFormControl.styles, sliderCss, css `
|
|
16
|
+
.wrap { display: grid; gap: var(--pm-space-1); flex: 1; min-inline-size: 0; }
|
|
17
|
+
.marks { position: relative; block-size: 1.25rem; margin-inline: calc(var(--pm-slider-thumb, 1.1rem) / 2); font-size: var(--pm-font-size-xs); color: var(--pm-color-fg-muted); }
|
|
18
|
+
.mark { position: absolute; inset-inline-start: var(--_at); translate: -50% 0; padding: 0 2px; border: 0; background: none; color: inherit; font: inherit; white-space: nowrap; cursor: pointer; }
|
|
19
|
+
:host(:dir(rtl)) .mark { translate: 50% 0; }
|
|
20
|
+
.mark::before { content: ""; position: absolute; inset-block-start: -0.35rem; inset-inline-start: 50%; inline-size: 1px; block-size: 0.3rem; background: currentColor; opacity: 0.6; }
|
|
21
|
+
.mark[data-on] { color: var(--pm-color-fg); font-weight: var(--pm-font-weight-semibold); }
|
|
22
|
+
.mark:focus-visible { outline: 2px solid var(--pm-color-ring); border-radius: 2px; }
|
|
23
|
+
`]; }
|
|
24
|
+
static { this.componentName = 'slider'; }
|
|
25
|
+
static { this.properties = {
|
|
26
|
+
min: { type: Number }, max: { type: Number }, step: { type: Number }, showValue: { type: Boolean, attribute: 'show-value' },
|
|
27
|
+
marks: { type: Array }, unit: {}, locale: {},
|
|
28
|
+
}; }
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.min = 0;
|
|
32
|
+
this.max = 100;
|
|
33
|
+
this.step = 1;
|
|
34
|
+
this.showValue = false;
|
|
35
|
+
}
|
|
36
|
+
willUpdate(changed) {
|
|
37
|
+
super.willUpdate(changed);
|
|
38
|
+
if (typeof this.marks === 'string') {
|
|
39
|
+
try {
|
|
40
|
+
this.marks = JSON.parse(this.marks);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
this.marks = [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
#fmt(v) {
|
|
48
|
+
const n = new Intl.NumberFormat(this.locale).format(v);
|
|
49
|
+
return this.unit ? (this.unit === '%' ? `${n}%` : `${n} ${this.unit}`) : n;
|
|
50
|
+
}
|
|
51
|
+
#set(v) {
|
|
52
|
+
this.value = String(v);
|
|
53
|
+
this.onChange();
|
|
54
|
+
this.control?.focus();
|
|
55
|
+
}
|
|
56
|
+
render() {
|
|
57
|
+
const v = Number(this.value || this.min);
|
|
58
|
+
const span = this.max - this.min || 1;
|
|
59
|
+
const pct = ((v - this.min) / span) * 100;
|
|
60
|
+
const marks = (this.marks ?? []).map((m) => (typeof m === 'number' ? { value: m, label: undefined } : m));
|
|
61
|
+
const listId = marks.length ? `${this.controlId}-marks` : undefined;
|
|
62
|
+
const labelOf = (m) => m.label ?? this.#fmt(m.value);
|
|
63
|
+
const named = marks.find((m) => m.value === v && m.label);
|
|
64
|
+
return this.field(html `<div style="display:flex;align-items:center;gap:var(--pm-space-3)">
|
|
65
|
+
<div class="wrap">
|
|
66
|
+
<input data-control part="control" type="range" class="pm-slider" id=${this.controlId}
|
|
67
|
+
name=${ifDefined(this.name)} min=${this.min} max=${this.max} step=${this.step} list=${ifDefined(listId)}
|
|
68
|
+
.value=${live(String(v))} style=${`--pm-value:${pct}%`} data-size=${ifDefined(this.size)}
|
|
69
|
+
aria-valuetext=${named ? named.label : this.#fmt(v)}
|
|
70
|
+
?disabled=${this.disabled} aria-describedby=${ifDefined(this.describedBy())}
|
|
71
|
+
@input=${this.onInput} @change=${this.onChange} />
|
|
72
|
+
${marks.length ? html `<datalist id=${listId}>${marks.map((m) => html `<option value=${m.value} label=${labelOf(m)}></option>`)}</datalist>
|
|
73
|
+
<div class="marks" part="marks" aria-hidden="true">${marks.map((m) => html `<button type="button" tabindex="-1" class="mark" ?data-on=${m.value === v} ?disabled=${this.disabled}
|
|
74
|
+
style=${`--_at:${((m.value - this.min) / span) * 100}%`} @click=${() => this.#set(m.value)}>${labelOf(m)}</button>`)}</div>` : nothing}
|
|
75
|
+
</div>
|
|
76
|
+
${this.showValue ? html `<output for=${this.controlId} class="pm-text-sm" style="min-inline-size:3ch;text-align:end;font-variant-numeric:tabular-nums">${named ? named.label : this.#fmt(v)}</output>` : nothing}
|
|
77
|
+
</div>`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
defineElement('pm-slider', PmSlider);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SafeHTMLElement } from '../base.js';
|
|
2
|
+
/**
|
|
3
|
+
* List whose rows can be reordered by dragging or with the keyboard.
|
|
4
|
+
*
|
|
5
|
+
* Drag rows with a pointer (from a `[data-handle]` if present, else the whole row), or with the keyboard: focus a
|
|
6
|
+
* row, Space to pick it up, ↑/↓ to move, Space to drop, Esc to cancel. Moves are announced. Children keep their own
|
|
7
|
+
* markup; `value` lists their `data-value`s in order.
|
|
8
|
+
* @tag pm-sortable
|
|
9
|
+
* @attr {string} label - Accessible name of the list.
|
|
10
|
+
* @attr {boolean} disabled - Turn reordering off.
|
|
11
|
+
* @slot - Rows (any elements; give each a `data-value`).
|
|
12
|
+
* @fires pm-reorder - Order changed. detail: { order, from, to }
|
|
13
|
+
* @example <pm-sortable label="Priorities"><div data-value="a">Alpha</div><div data-value="b">Beta</div><div data-value="c">Gamma</div></pm-sortable>
|
|
14
|
+
*/
|
|
15
|
+
export declare class PmSortable extends SafeHTMLElement {
|
|
16
|
+
#private;
|
|
17
|
+
connectedCallback(): void;
|
|
18
|
+
disconnectedCallback(): void;
|
|
19
|
+
get items(): HTMLElement[];
|
|
20
|
+
/** `data-value`s (or text) of the rows in order. */
|
|
21
|
+
get value(): string[];
|
|
22
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { SafeHTMLElement, defineElement } from '../base.js';
|
|
2
|
+
import sortableCss from '../styles/sortable.js';
|
|
3
|
+
/**
|
|
4
|
+
* List whose rows can be reordered by dragging or with the keyboard.
|
|
5
|
+
*
|
|
6
|
+
* Drag rows with a pointer (from a `[data-handle]` if present, else the whole row), or with the keyboard: focus a
|
|
7
|
+
* row, Space to pick it up, ↑/↓ to move, Space to drop, Esc to cancel. Moves are announced. Children keep their own
|
|
8
|
+
* markup; `value` lists their `data-value`s in order.
|
|
9
|
+
* @tag pm-sortable
|
|
10
|
+
* @attr {string} label - Accessible name of the list.
|
|
11
|
+
* @attr {boolean} disabled - Turn reordering off.
|
|
12
|
+
* @slot - Rows (any elements; give each a `data-value`).
|
|
13
|
+
* @fires pm-reorder - Order changed. detail: { order, from, to }
|
|
14
|
+
* @example <pm-sortable label="Priorities"><div data-value="a">Alpha</div><div data-value="b">Beta</div><div data-value="c">Gamma</div></pm-sortable>
|
|
15
|
+
*/
|
|
16
|
+
export class PmSortable extends SafeHTMLElement {
|
|
17
|
+
#grabbed = null;
|
|
18
|
+
#start = -1;
|
|
19
|
+
#live;
|
|
20
|
+
#mo;
|
|
21
|
+
#moving = false;
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
this.classList.add('pm-sortable');
|
|
24
|
+
this.setAttribute('role', 'list');
|
|
25
|
+
const l = this.getAttribute('label');
|
|
26
|
+
if (l)
|
|
27
|
+
this.setAttribute('aria-label', l);
|
|
28
|
+
this.#live ??= Object.assign(document.createElement('span'), { className: 'pm-visually-hidden' });
|
|
29
|
+
this.#live.setAttribute('aria-live', 'assertive');
|
|
30
|
+
this.#live.setAttribute('data-sortable-live', '');
|
|
31
|
+
// Fixed at the top-left corner: an offset-less absolute box keeps its static position, which inside a horizontal
|
|
32
|
+
// scroller can sit far outside the viewport and widen the page.
|
|
33
|
+
this.#live.style.cssText = 'position:fixed;inset:0 auto auto 0;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap';
|
|
34
|
+
if (!this.#live.isConnected)
|
|
35
|
+
this.after(this.#live);
|
|
36
|
+
this.#prepare();
|
|
37
|
+
this.addEventListener('keydown', this.#onKey);
|
|
38
|
+
this.addEventListener('pointerdown', this.#onPointer);
|
|
39
|
+
this.addEventListener('focusout', this.#onBlur);
|
|
40
|
+
this.#mo ??= new MutationObserver(() => this.#prepare());
|
|
41
|
+
this.#mo.observe(this, { childList: true });
|
|
42
|
+
}
|
|
43
|
+
disconnectedCallback() {
|
|
44
|
+
this.removeEventListener('keydown', this.#onKey);
|
|
45
|
+
this.removeEventListener('pointerdown', this.#onPointer);
|
|
46
|
+
this.removeEventListener('focusout', this.#onBlur);
|
|
47
|
+
this.#live?.remove();
|
|
48
|
+
this.#mo?.disconnect();
|
|
49
|
+
}
|
|
50
|
+
get items() { return [...this.children].filter((c) => c instanceof HTMLElement && !c.hasAttribute('data-sortable-live')); }
|
|
51
|
+
/** `data-value`s (or text) of the rows in order. */
|
|
52
|
+
get value() { return this.items.map((i) => i.dataset.value ?? i.textContent?.trim() ?? ''); }
|
|
53
|
+
#name(el) { return el.getAttribute('aria-label') ?? el.textContent?.trim().replace(/\s+/g, ' ') ?? ''; }
|
|
54
|
+
#say(msg) { if (this.#live) {
|
|
55
|
+
this.#live.textContent = '';
|
|
56
|
+
setTimeout(() => { if (this.#live)
|
|
57
|
+
this.#live.textContent = msg; }, 30);
|
|
58
|
+
} }
|
|
59
|
+
#prepare() {
|
|
60
|
+
const items = this.items;
|
|
61
|
+
items.forEach((el, i) => {
|
|
62
|
+
el.setAttribute('role', 'listitem');
|
|
63
|
+
el.classList.add('pm-sortable-item');
|
|
64
|
+
if (!el.hasAttribute('tabindex'))
|
|
65
|
+
el.tabIndex = 0;
|
|
66
|
+
el.setAttribute('aria-roledescription', 'sortable item');
|
|
67
|
+
el.setAttribute('aria-posinset', String(i + 1));
|
|
68
|
+
el.setAttribute('aria-setsize', String(items.length));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
#emit(from, to) {
|
|
72
|
+
this.#prepare();
|
|
73
|
+
if (from !== to)
|
|
74
|
+
this.dispatchEvent(new CustomEvent('pm-reorder', { detail: { order: this.value, from, to }, bubbles: true, composed: true }));
|
|
75
|
+
}
|
|
76
|
+
#move(el, to) {
|
|
77
|
+
const items = this.items.filter((i) => i !== el);
|
|
78
|
+
const ref = items[to] ?? items.at(-1)?.nextSibling ?? null;
|
|
79
|
+
const hadFocus = el.contains(document.activeElement);
|
|
80
|
+
this.#moving = true;
|
|
81
|
+
// moveBefore keeps focus and element state where supported.
|
|
82
|
+
const host = this;
|
|
83
|
+
if (host.moveBefore)
|
|
84
|
+
host.moveBefore(el, ref);
|
|
85
|
+
else
|
|
86
|
+
this.insertBefore(el, ref);
|
|
87
|
+
if (hadFocus)
|
|
88
|
+
el.focus();
|
|
89
|
+
this.#moving = false;
|
|
90
|
+
}
|
|
91
|
+
#drop(cancel = false) {
|
|
92
|
+
const el = this.#grabbed;
|
|
93
|
+
if (!el)
|
|
94
|
+
return;
|
|
95
|
+
if (cancel)
|
|
96
|
+
this.#move(el, this.#start);
|
|
97
|
+
el.removeAttribute('data-grabbed');
|
|
98
|
+
this.#grabbed = null;
|
|
99
|
+
const to = this.items.indexOf(el);
|
|
100
|
+
this.#say(cancel ? `${this.#name(el)} returned to position ${this.#start + 1}.` : `${this.#name(el)} dropped at position ${to + 1} of ${this.items.length}.`);
|
|
101
|
+
if (!cancel)
|
|
102
|
+
this.#emit(this.#start, to);
|
|
103
|
+
}
|
|
104
|
+
#onBlur = (e) => { if (!this.#moving && this.#grabbed && !this.contains(e.relatedTarget))
|
|
105
|
+
this.#drop(); };
|
|
106
|
+
#onKey = (e) => {
|
|
107
|
+
const el = e.target.closest('.pm-sortable-item');
|
|
108
|
+
if (!el || el.parentElement !== this || this.hasAttribute('disabled'))
|
|
109
|
+
return;
|
|
110
|
+
if (e.target !== el && (e.key === ' ' || e.key === 'Enter'))
|
|
111
|
+
return; // controls inside the row
|
|
112
|
+
const items = this.items;
|
|
113
|
+
const i = items.indexOf(el);
|
|
114
|
+
if (e.key === ' ' || (e.key === 'Enter' && this.#grabbed)) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
if (this.#grabbed) {
|
|
117
|
+
this.#drop();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.#grabbed = el;
|
|
121
|
+
this.#start = i;
|
|
122
|
+
el.setAttribute('data-grabbed', '');
|
|
123
|
+
this.#say(`${this.#name(el)} grabbed, position ${i + 1} of ${items.length}. Use arrow keys to move, Space to drop, Escape to cancel.`);
|
|
124
|
+
}
|
|
125
|
+
else if (e.key === 'Escape' && this.#grabbed) {
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
this.#drop(true);
|
|
128
|
+
}
|
|
129
|
+
else if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Home' || e.key === 'End') {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
const j = e.key === 'Home' ? 0 : e.key === 'End' ? items.length - 1 : Math.max(0, Math.min(items.length - 1, i + (e.key === 'ArrowDown' ? 1 : -1)));
|
|
132
|
+
if (this.#grabbed === el) {
|
|
133
|
+
if (j !== i) {
|
|
134
|
+
this.#move(el, j);
|
|
135
|
+
this.#prepare();
|
|
136
|
+
this.#say(`Moved to position ${j + 1} of ${items.length}.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else
|
|
140
|
+
items[j]?.focus();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
#onPointer = (e) => {
|
|
144
|
+
if (e.button !== 0 || this.hasAttribute('disabled'))
|
|
145
|
+
return;
|
|
146
|
+
const el = e.target.closest('.pm-sortable-item');
|
|
147
|
+
if (!el || el.parentElement !== this)
|
|
148
|
+
return;
|
|
149
|
+
const handle = el.querySelector('[data-handle]');
|
|
150
|
+
if (handle ? !handle.contains(e.target) : e.target.closest('button, a, input, select, textarea, [contenteditable]'))
|
|
151
|
+
return;
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
const from = this.items.indexOf(el);
|
|
154
|
+
const startY = e.clientY;
|
|
155
|
+
let moved = false;
|
|
156
|
+
el.setPointerCapture(e.pointerId);
|
|
157
|
+
const move = (ev) => {
|
|
158
|
+
if (!moved && Math.abs(ev.clientY - startY) < 4)
|
|
159
|
+
return;
|
|
160
|
+
if (!moved) {
|
|
161
|
+
moved = true;
|
|
162
|
+
el.setAttribute('data-dragging', '');
|
|
163
|
+
}
|
|
164
|
+
const others = this.items.filter((x) => x !== el);
|
|
165
|
+
const idx = others.findIndex((o) => { const r = o.getBoundingClientRect(); return ev.clientY < r.top + r.height / 2; });
|
|
166
|
+
const to = idx < 0 ? others.length : idx;
|
|
167
|
+
if (to !== this.items.indexOf(el)) {
|
|
168
|
+
const before = new Map(this.items.map((x) => [x, x.getBoundingClientRect().top]));
|
|
169
|
+
this.#move(el, to);
|
|
170
|
+
// FLIP the rows that shifted.
|
|
171
|
+
if (matchMedia('(prefers-reduced-motion: no-preference)').matches)
|
|
172
|
+
for (const x of this.items) {
|
|
173
|
+
if (x === el)
|
|
174
|
+
continue;
|
|
175
|
+
const dy = before.get(x) - x.getBoundingClientRect().top;
|
|
176
|
+
if (dy)
|
|
177
|
+
x.animate([{ translate: `0 ${dy}px` }, { translate: '0 0' }], { duration: 160, easing: 'ease-out' });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const up = () => {
|
|
182
|
+
el.removeEventListener('pointermove', move);
|
|
183
|
+
el.removeEventListener('pointerup', up);
|
|
184
|
+
el.removeEventListener('pointercancel', up);
|
|
185
|
+
el.removeAttribute('data-dragging');
|
|
186
|
+
if (moved) {
|
|
187
|
+
this.#emit(from, this.items.indexOf(el));
|
|
188
|
+
this.#say(`${this.#name(el)} moved to position ${this.items.indexOf(el) + 1}.`);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
el.addEventListener('pointermove', move);
|
|
192
|
+
el.addEventListener('pointerup', up);
|
|
193
|
+
el.addEventListener('pointercancel', up);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
defineElement('pm-sortable', PmSortable, [sortableCss]);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/** "3, 5 8" or a JSON array → numbers. */
|
|
4
|
+
export declare const numberList: {
|
|
5
|
+
fromAttribute: (v: string | null) => number[];
|
|
6
|
+
toAttribute: (v: number[]) => string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Sparkline: a small trend chart without axes, for stat cards and table cells.
|
|
10
|
+
*
|
|
11
|
+
* Takes the colour of its `tone`. With a `label` it is announced with its first and last value; without one it is
|
|
12
|
+
* decorative. Size with `--pm-sparkline-width` / `--pm-sparkline-height`.
|
|
13
|
+
* @tag pm-sparkline
|
|
14
|
+
* @example <pm-sparkline values="4,6,5,8,7,11,12" label="Revenue, last 7 days" tone="success"></pm-sparkline>
|
|
15
|
+
*/
|
|
16
|
+
export declare class PmSparkline extends PmElement {
|
|
17
|
+
static componentName: string;
|
|
18
|
+
static styles: import("lit").CSSResult[];
|
|
19
|
+
static properties: PropertyDeclarations;
|
|
20
|
+
/** The numbers to plot, in order: `values="3,5,4,8"` or an array property. */
|
|
21
|
+
values: number[];
|
|
22
|
+
/** line (default), area or bar. */
|
|
23
|
+
type?: 'line' | 'area' | 'bar';
|
|
24
|
+
/** Accessible name, e.g. "Revenue, last 7 days". */
|
|
25
|
+
label?: string;
|
|
26
|
+
constructor();
|
|
27
|
+
render(): import("lit").TemplateResult<1>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { css, html, svg } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import chartCss from '../styles/chart.js';
|
|
4
|
+
/** "3, 5 8" or a JSON array → numbers. */
|
|
5
|
+
export const numberList = {
|
|
6
|
+
fromAttribute: (v) => (v ?? '').replace(/[[\]]/g, '').split(/[\s,]+/).filter(Boolean).map(Number).filter((n) => Number.isFinite(n)),
|
|
7
|
+
toAttribute: (v) => v.join(','),
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Sparkline: a small trend chart without axes, for stat cards and table cells.
|
|
11
|
+
*
|
|
12
|
+
* Takes the colour of its `tone`. With a `label` it is announced with its first and last value; without one it is
|
|
13
|
+
* decorative. Size with `--pm-sparkline-width` / `--pm-sparkline-height`.
|
|
14
|
+
* @tag pm-sparkline
|
|
15
|
+
* @example <pm-sparkline values="4,6,5,8,7,11,12" label="Revenue, last 7 days" tone="success"></pm-sparkline>
|
|
16
|
+
*/
|
|
17
|
+
export class PmSparkline extends PmElement {
|
|
18
|
+
static { this.componentName = 'sparkline'; }
|
|
19
|
+
static { this.styles = [...PmElement.styles, chartCss, css `:host { display: inline-block; vertical-align: middle; } :host([hidden]) { display: none; }`]; }
|
|
20
|
+
static { this.properties = { values: { converter: numberList }, type: { reflect: true }, label: {} }; }
|
|
21
|
+
constructor() { super(); this.values = []; }
|
|
22
|
+
render() {
|
|
23
|
+
const v = this.values ?? [];
|
|
24
|
+
const W = 100;
|
|
25
|
+
const H = 32;
|
|
26
|
+
const pad = 2;
|
|
27
|
+
const min = Math.min(...v);
|
|
28
|
+
const max = Math.max(...v);
|
|
29
|
+
const span = max - min || 1;
|
|
30
|
+
const x = (i) => (v.length < 2 ? W / 2 : (i / (v.length - 1)) * W);
|
|
31
|
+
const y = (n) => pad + (1 - (n - min) / span) * (H - pad * 2);
|
|
32
|
+
const name = this.label && v.length ? `${this.label}: ${v[0]} to ${v.at(-1)}` : this.label;
|
|
33
|
+
let marks;
|
|
34
|
+
if (this.type === 'bar') {
|
|
35
|
+
const bw = W / Math.max(v.length, 1);
|
|
36
|
+
marks = v.map((n, i) => svg `<rect class="pm-sparkline-bar" x=${i * bw + bw * 0.15} y=${y(n)} width=${bw * 0.7} height=${Math.max(H - y(n), 1)} rx="1"></rect>`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const line = v.map((n, i) => `${i ? 'L' : 'M'}${x(i).toFixed(2)},${y(n).toFixed(2)}`).join('');
|
|
40
|
+
marks = svg `${this.type === 'area' && v.length > 1 ? svg `<path class="pm-sparkline-area" d=${`${line}L${W},${H}L0,${H}Z`}></path>` : ''}<path class="pm-sparkline-line" d=${line}></path>`;
|
|
41
|
+
}
|
|
42
|
+
return html `<svg class="pm-sparkline" part="base" viewBox="0 0 ${W} ${H}" preserveAspectRatio="none"
|
|
43
|
+
role=${name ? 'img' : 'presentation'} aria-label=${name ?? ''} aria-hidden=${name ? 'false' : 'true'}>${v.length ? marks : ''}</svg>`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
defineElement('pm-sparkline', PmSparkline);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Loading spinner (announces as a status).
|
|
5
|
+
* @tag pm-spinner
|
|
6
|
+
* @example <pm-spinner label="Loading results"></pm-spinner>
|
|
7
|
+
*/
|
|
8
|
+
export declare class PmSpinner extends PmElement {
|
|
9
|
+
static componentName: string;
|
|
10
|
+
static styles: import("lit").CSSResult[];
|
|
11
|
+
static properties: PropertyDeclarations;
|
|
12
|
+
label: string;
|
|
13
|
+
size?: 'sm' | 'md' | 'lg';
|
|
14
|
+
constructor();
|
|
15
|
+
render(): import("lit").TemplateResult<1>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { css, html } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { PmElement, defineElement } from '../base.js';
|
|
4
|
+
import spinnerCss from '../styles/spinner.js';
|
|
5
|
+
/**
|
|
6
|
+
* Loading spinner (announces as a status).
|
|
7
|
+
* @tag pm-spinner
|
|
8
|
+
* @example <pm-spinner label="Loading results"></pm-spinner>
|
|
9
|
+
*/
|
|
10
|
+
export class PmSpinner extends PmElement {
|
|
11
|
+
static { this.componentName = 'spinner'; }
|
|
12
|
+
static { this.styles = [...PmElement.styles, spinnerCss, css `:host { display: inline-flex; vertical-align: middle; }`]; }
|
|
13
|
+
static { this.properties = { label: {}, size: { reflect: true } }; }
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.label = 'Loading';
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
return html `<span part="base" class="pm-spinner" role="status" aria-label=${this.label} data-size=${ifDefined(this.size)}></span>`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
defineElement('pm-spinner', PmSpinner);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Resizable split view (window splitter pattern). Two panes, a draggable separator with arrow-key support
|
|
5
|
+
* (±1%, Shift ±10%, Home/End to the limits, Enter to collapse/restore).
|
|
6
|
+
* @tag pm-splitter
|
|
7
|
+
* @slot start - First pane.
|
|
8
|
+
* @slot end - Second pane.
|
|
9
|
+
* @fires pm-resize - Position changed. detail: { position } (percent of the first pane)
|
|
10
|
+
* @example <pm-splitter position="30" label="Sidebar"><nav slot="start">…</nav><main slot="end">…</main></pm-splitter>
|
|
11
|
+
*/
|
|
12
|
+
export declare class PmSplitter extends PmElement {
|
|
13
|
+
#private;
|
|
14
|
+
static componentName: string;
|
|
15
|
+
static styles: import("lit").CSSResult[];
|
|
16
|
+
static properties: PropertyDeclarations;
|
|
17
|
+
/** Size of the first pane in percent. */
|
|
18
|
+
position: number;
|
|
19
|
+
min: number;
|
|
20
|
+
max: number;
|
|
21
|
+
/** horizontal = side by side (vertical bar); vertical = stacked. */
|
|
22
|
+
orientation: 'horizontal' | 'vertical';
|
|
23
|
+
/** Accessible name of the separator (names the first pane). */
|
|
24
|
+
label?: string;
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
constructor();
|
|
27
|
+
render(): import("lit").TemplateResult<1>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { css, html } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import splitterCss from '../styles/splitter.js';
|
|
4
|
+
/**
|
|
5
|
+
* Resizable split view (window splitter pattern). Two panes, a draggable separator with arrow-key support
|
|
6
|
+
* (±1%, Shift ±10%, Home/End to the limits, Enter to collapse/restore).
|
|
7
|
+
* @tag pm-splitter
|
|
8
|
+
* @slot start - First pane.
|
|
9
|
+
* @slot end - Second pane.
|
|
10
|
+
* @fires pm-resize - Position changed. detail: { position } (percent of the first pane)
|
|
11
|
+
* @example <pm-splitter position="30" label="Sidebar"><nav slot="start">…</nav><main slot="end">…</main></pm-splitter>
|
|
12
|
+
*/
|
|
13
|
+
export class PmSplitter extends PmElement {
|
|
14
|
+
static { this.componentName = 'splitter'; }
|
|
15
|
+
static { this.styles = [...PmElement.styles, splitterCss, css `:host { display: block; min-block-size: 12rem; } .pm-splitter { block-size: 100%; }`]; }
|
|
16
|
+
static { this.properties = {
|
|
17
|
+
position: { type: Number, reflect: true }, min: { type: Number }, max: { type: Number },
|
|
18
|
+
orientation: { reflect: true }, label: {}, disabled: { type: Boolean, reflect: true },
|
|
19
|
+
}; }
|
|
20
|
+
#restore = 50;
|
|
21
|
+
constructor() { super(); this.position = 50; this.min = 10; this.max = 90; this.orientation = 'horizontal'; this.disabled = false; }
|
|
22
|
+
#set(p) {
|
|
23
|
+
const v = Math.round(Math.min(this.max, Math.max(this.min, p)) * 10) / 10;
|
|
24
|
+
if (v === this.position)
|
|
25
|
+
return;
|
|
26
|
+
this.position = v;
|
|
27
|
+
this.emit('pm-resize', { position: v });
|
|
28
|
+
}
|
|
29
|
+
#onPointer(e) {
|
|
30
|
+
if (this.disabled || e.button !== 0)
|
|
31
|
+
return;
|
|
32
|
+
const bar = e.currentTarget;
|
|
33
|
+
const box = this.renderRoot.querySelector('.pm-splitter');
|
|
34
|
+
bar.setPointerCapture(e.pointerId);
|
|
35
|
+
const vert = this.orientation === 'vertical';
|
|
36
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
37
|
+
const move = (ev) => {
|
|
38
|
+
const r = box.getBoundingClientRect();
|
|
39
|
+
const p = vert ? (ev.clientY - r.top) / r.height : rtl ? (r.right - ev.clientX) / r.width : (ev.clientX - r.left) / r.width;
|
|
40
|
+
this.#set(p * 100);
|
|
41
|
+
};
|
|
42
|
+
const up = () => { bar.removeEventListener('pointermove', move); bar.removeEventListener('pointerup', up); bar.removeEventListener('pointercancel', up); box.removeAttribute('data-dragging'); };
|
|
43
|
+
box.setAttribute('data-dragging', '');
|
|
44
|
+
bar.addEventListener('pointermove', move);
|
|
45
|
+
bar.addEventListener('pointerup', up);
|
|
46
|
+
bar.addEventListener('pointercancel', up);
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
bar.focus();
|
|
49
|
+
}
|
|
50
|
+
#onKey(e) {
|
|
51
|
+
if (this.disabled)
|
|
52
|
+
return;
|
|
53
|
+
const step = e.shiftKey ? 10 : 1;
|
|
54
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
55
|
+
const vert = this.orientation === 'vertical';
|
|
56
|
+
const dec = vert ? 'ArrowUp' : rtl ? 'ArrowRight' : 'ArrowLeft';
|
|
57
|
+
const inc = vert ? 'ArrowDown' : rtl ? 'ArrowLeft' : 'ArrowRight';
|
|
58
|
+
if (e.key === dec)
|
|
59
|
+
this.#set(this.position - step);
|
|
60
|
+
else if (e.key === inc)
|
|
61
|
+
this.#set(this.position + step);
|
|
62
|
+
else if (e.key === 'Home')
|
|
63
|
+
this.#set(this.min);
|
|
64
|
+
else if (e.key === 'End')
|
|
65
|
+
this.#set(this.max);
|
|
66
|
+
else if (e.key === 'Enter') {
|
|
67
|
+
if (this.position > this.min) {
|
|
68
|
+
this.#restore = this.position;
|
|
69
|
+
this.#set(this.min);
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
this.#set(this.#restore);
|
|
73
|
+
}
|
|
74
|
+
else
|
|
75
|
+
return;
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
}
|
|
78
|
+
render() {
|
|
79
|
+
return html `<div class="pm-splitter" part="base" data-orientation=${this.orientation} style=${`--_pos: ${this.position}%`}>
|
|
80
|
+
<div class="pm-splitter-pane" part="start"><slot name="start"></slot></div>
|
|
81
|
+
<div class="pm-splitter-bar" part="separator" role="separator" tabindex=${this.disabled ? -1 : 0}
|
|
82
|
+
aria-orientation=${this.orientation === 'vertical' ? 'horizontal' : 'vertical'} aria-label=${this.label ?? 'Resize'}
|
|
83
|
+
aria-valuenow=${this.position} aria-valuemin=${this.min} aria-valuemax=${this.max} aria-disabled=${this.disabled ? 'true' : 'false'}
|
|
84
|
+
@pointerdown=${this.#onPointer} @keydown=${this.#onKey}></div>
|
|
85
|
+
<div class="pm-splitter-pane" part="end"><slot name="end"></slot></div>
|
|
86
|
+
</div>`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
defineElement('pm-splitter', PmSplitter);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Stat / KPI: a labelled number with an optional change indicator.
|
|
5
|
+
* Trend is inferred from the sign of `delta` unless set; `inverse` flips colours (e.g. costs, latency).
|
|
6
|
+
* @tag pm-stat
|
|
7
|
+
* @slot icon - Icon next to the label.
|
|
8
|
+
* @slot - Extra footer content (sparkline, link).
|
|
9
|
+
* @example <pm-stat label="Revenue" value="$48.2k" delta="+12%" description="vs last month"></pm-stat>
|
|
10
|
+
*/
|
|
11
|
+
export declare class PmStat extends PmElement {
|
|
12
|
+
static componentName: string;
|
|
13
|
+
static styles: import("lit").CSSResult[];
|
|
14
|
+
static properties: PropertyDeclarations;
|
|
15
|
+
/** Registered icon name (see `registerIcons`); an `icon` slot overrides it. */
|
|
16
|
+
icon?: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
value?: string;
|
|
19
|
+
/** Change, e.g. "+12%" or "-3". */
|
|
20
|
+
delta?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Direction of the change: up, down or flat (colours the delta). */
|
|
23
|
+
trend?: 'up' | 'down' | 'neutral';
|
|
24
|
+
/** A decrease is good (e.g. error rate). */
|
|
25
|
+
inverse?: boolean;
|
|
26
|
+
size?: 'sm' | 'md' | 'lg';
|
|
27
|
+
render(): import("lit").TemplateResult<1>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import statCss from '../styles/stat.js';
|
|
4
|
+
import { namedIcon } from '../named-icon.js';
|
|
5
|
+
/**
|
|
6
|
+
* Stat / KPI: a labelled number with an optional change indicator.
|
|
7
|
+
* Trend is inferred from the sign of `delta` unless set; `inverse` flips colours (e.g. costs, latency).
|
|
8
|
+
* @tag pm-stat
|
|
9
|
+
* @slot icon - Icon next to the label.
|
|
10
|
+
* @slot - Extra footer content (sparkline, link).
|
|
11
|
+
* @example <pm-stat label="Revenue" value="$48.2k" delta="+12%" description="vs last month"></pm-stat>
|
|
12
|
+
*/
|
|
13
|
+
export class PmStat extends PmElement {
|
|
14
|
+
static { this.componentName = 'stat'; }
|
|
15
|
+
static { this.styles = [...PmElement.styles, statCss, css `:host { display: block; }`]; }
|
|
16
|
+
static { this.properties = { icon: { reflect: true },
|
|
17
|
+
label: {}, value: {}, delta: {}, description: {}, trend: { reflect: true }, inverse: { type: Boolean }, size: { reflect: true },
|
|
18
|
+
}; }
|
|
19
|
+
render() {
|
|
20
|
+
const trend = this.trend ?? (this.delta?.trim().startsWith('-') || this.delta?.trim().startsWith('−') ? 'down' : this.delta ? 'up' : 'neutral');
|
|
21
|
+
const words = { up: 'increase', down: 'decrease', neutral: 'no change' };
|
|
22
|
+
return html `<div class="pm-stat" part="base" data-size=${this.size ?? nothing}>
|
|
23
|
+
<span class="pm-stat-label" part="label"><slot name="icon">${namedIcon(this.icon)}</slot>${this.label}</span>
|
|
24
|
+
<span class="pm-stat-value" part="value">${this.value}</span>
|
|
25
|
+
<span class="pm-stat-footer">
|
|
26
|
+
${this.delta ? html `<span class="pm-stat-delta" part="delta" data-trend=${trend} ?data-inverse=${!!this.inverse}><span class="pm-visually-hidden">${words[trend]} of </span>${this.delta}</span>` : nothing}
|
|
27
|
+
${this.description ? html `<span>${this.description}</span>` : nothing}
|
|
28
|
+
<slot></slot>
|
|
29
|
+
</span>
|
|
30
|
+
</div>`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
defineElement('pm-stat', PmStat);
|