@prismora/elements 0.0.0-stage → 0.1.1
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,111 @@
|
|
|
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
|
+
* Checkbox group: choose any number of options under one label.
|
|
10
|
+
*
|
|
11
|
+
* Declare options as `<pm-choice value="x">` children. `value` is the chosen values joined with commas; the form
|
|
12
|
+
* receives one entry per chosen value under `name`. `required` needs at least one choice; `min` / `max` limit how
|
|
13
|
+
* many. `variant="card"` shows options as cards with an optional description.
|
|
14
|
+
* @tag pm-checkbox-group
|
|
15
|
+
* @fires pm-change - The selection changed. detail: { value, values }
|
|
16
|
+
* @example <pm-checkbox-group label="Notify me about" name="topics" value="mentions"><pm-choice value="mentions">Mentions</pm-choice><pm-choice value="replies">Replies</pm-choice></pm-checkbox-group>
|
|
17
|
+
*/
|
|
18
|
+
export class PmCheckboxGroup extends PmFormControl {
|
|
19
|
+
static { this.styles = [...PmFormControl.styles, checkboxCss, helpersCss]; }
|
|
20
|
+
static { this.componentName = 'checkbox-group'; }
|
|
21
|
+
static { this.properties = { orientation: { reflect: true }, variant: { reflect: true }, min: { type: Number }, max: { type: Number } }; }
|
|
22
|
+
#items = [];
|
|
23
|
+
#observer;
|
|
24
|
+
constructor() { super(); this.orientation = 'vertical'; }
|
|
25
|
+
/** The chosen values. */
|
|
26
|
+
get values() { return this.value ? this.value.split(',').filter(Boolean) : []; }
|
|
27
|
+
set values(v) { this.value = v.join(','); }
|
|
28
|
+
connectedCallback() {
|
|
29
|
+
super.connectedCallback();
|
|
30
|
+
this.#read();
|
|
31
|
+
this.#observer = new MutationObserver(() => { this.#read(); this.requestUpdate(); });
|
|
32
|
+
this.#observer.observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['value', 'description', 'disabled'] });
|
|
33
|
+
}
|
|
34
|
+
disconnectedCallback() { super.disconnectedCallback(); this.#observer?.disconnect(); }
|
|
35
|
+
#read() {
|
|
36
|
+
this.#items = [...this.querySelectorAll('pm-choice')].map((r) => ({
|
|
37
|
+
value: r.getAttribute('value') ?? '', label: r.textContent?.trim() ?? '', description: r.getAttribute('description') ?? '', disabled: r.hasAttribute('disabled'),
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
get control() { return this.renderRoot?.querySelector('input') ?? null; }
|
|
41
|
+
syncFormValue() {
|
|
42
|
+
const data = new FormData();
|
|
43
|
+
if (this.name)
|
|
44
|
+
for (const v of this.values)
|
|
45
|
+
data.append(this.name, v);
|
|
46
|
+
this.internals.setFormValue(data, this.value);
|
|
47
|
+
}
|
|
48
|
+
syncValidity() {
|
|
49
|
+
const c = this.control;
|
|
50
|
+
if (!c)
|
|
51
|
+
return;
|
|
52
|
+
const n = this.values.length;
|
|
53
|
+
const min = Math.max(this.min ?? 0, this.required ? 1 : 0);
|
|
54
|
+
if (this.error)
|
|
55
|
+
this.internals.setValidity({ customError: true }, this.error, c);
|
|
56
|
+
else if (n < min)
|
|
57
|
+
this.internals.setValidity({ valueMissing: true }, min === 1 ? 'Please choose at least one option.' : `Please choose at least ${min} options.`, c);
|
|
58
|
+
else if (this.max !== undefined && n > this.max)
|
|
59
|
+
this.internals.setValidity({ rangeOverflow: true }, `Please choose at most ${this.max} options.`, c);
|
|
60
|
+
else
|
|
61
|
+
this.internals.setValidity({});
|
|
62
|
+
}
|
|
63
|
+
#toggle(value, on) {
|
|
64
|
+
const set = new Set(this.values);
|
|
65
|
+
if (on)
|
|
66
|
+
set.add(value);
|
|
67
|
+
else
|
|
68
|
+
set.delete(value);
|
|
69
|
+
// Keep the declared order.
|
|
70
|
+
this.values = this.#items.map((i) => i.value).filter((v) => set.has(v));
|
|
71
|
+
this.onChange();
|
|
72
|
+
}
|
|
73
|
+
onChange() {
|
|
74
|
+
super.onChange();
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
const chosen = new Set(this.values);
|
|
78
|
+
const full = this.max !== undefined && chosen.size >= this.max;
|
|
79
|
+
const card = this.variant === 'card';
|
|
80
|
+
const message = this.error || (this.showInvalid ? this.internals.validationMessage : '');
|
|
81
|
+
return html `<fieldset class="pm-field" part="field" style="border:0;margin:0;padding:0;min-inline-size:0" aria-describedby=${ifDefined(this.describedBy())}>
|
|
82
|
+
${this.label ? html `<legend class=${this.hideLabel ? 'pm-visually-hidden' : 'pm-label'} part="label"
|
|
83
|
+
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}${this.required ? html `<span aria-hidden="true" style="color:var(--pm-color-danger-text)"> *</span>` : nothing}</legend>` : nothing}
|
|
84
|
+
<div class=${card ? 'pm-choice-grid' : this.orientation === 'horizontal' ? 'pm-cluster' : 'pm-stack'} style="--pm-gap:var(--pm-space-2)">
|
|
85
|
+
${this.#items.map((it) => html `<label class="pm-check-label" ?data-card=${card}>
|
|
86
|
+
<input type="checkbox" class="pm-checkbox" value=${it.value} .checked=${live(chosen.has(it.value))}
|
|
87
|
+
?disabled=${this.disabled || it.disabled || (full && !chosen.has(it.value))} aria-invalid=${message ? 'true' : nothing}
|
|
88
|
+
@change=${(e) => { if (this.readonly) {
|
|
89
|
+
e.target.checked = chosen.has(it.value);
|
|
90
|
+
return;
|
|
91
|
+
} this.#toggle(it.value, e.target.checked); }} />
|
|
92
|
+
<span class="pm-check-text"><span>${it.label}</span>${it.description ? html `<span class="pm-check-desc">${it.description}</span>` : nothing}</span></label>`)}
|
|
93
|
+
</div>
|
|
94
|
+
${this.hint ? html `<span class="pm-hint" id=${`${this.controlId}-hint`}>${this.hint}</span>` : nothing}
|
|
95
|
+
${message ? html `<span class="pm-error" id=${`${this.controlId}-err`} role="alert">${message}</span>` : nothing}
|
|
96
|
+
</fieldset>`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Option declaration for `pm-checkbox-group` (renders nothing itself).
|
|
101
|
+
* @tag pm-choice
|
|
102
|
+
* @attr {string} value - Value submitted when chosen.
|
|
103
|
+
* @attr {string} description - Second line under the label (card variant).
|
|
104
|
+
* @attr {boolean} disabled - Disable this option.
|
|
105
|
+
* @slot - Option label (text).
|
|
106
|
+
*/
|
|
107
|
+
export class PmChoice extends SafeHTMLElement {
|
|
108
|
+
constructor() { super(); this.hidden = true; }
|
|
109
|
+
}
|
|
110
|
+
defineElement('pm-checkbox-group', PmCheckboxGroup);
|
|
111
|
+
defineElement('pm-choice', PmChoice);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmFormControl } from './form-control.js';
|
|
3
|
+
/**
|
|
4
|
+
* Checkbox for turning an option on or off, with an optional mixed state.
|
|
5
|
+
* @fires pm-change - When toggled. detail: { checked, value }
|
|
6
|
+
* @tag pm-checkbox
|
|
7
|
+
* @slot - Label text.
|
|
8
|
+
* @example <pm-checkbox name="terms" required>I agree</pm-checkbox>
|
|
9
|
+
*/
|
|
10
|
+
export declare class PmCheckbox extends PmFormControl {
|
|
11
|
+
#private;
|
|
12
|
+
static styles: import("lit").CSSResult[];
|
|
13
|
+
static componentName: string;
|
|
14
|
+
static properties: PropertyDeclarations;
|
|
15
|
+
checked: boolean;
|
|
16
|
+
indeterminate: boolean;
|
|
17
|
+
protected kind: 'checkbox' | 'switch';
|
|
18
|
+
constructor();
|
|
19
|
+
connectedCallback(): void;
|
|
20
|
+
formResetCallback(): void;
|
|
21
|
+
protected syncFormValue(): void;
|
|
22
|
+
render(): import("lit").TemplateResult<1>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { html, nothing } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { live } from 'lit/directives/live.js';
|
|
4
|
+
import { defineElement } from '../base.js';
|
|
5
|
+
import { PmFormControl } from './form-control.js';
|
|
6
|
+
import checkboxCss from '../styles/checkbox.js';
|
|
7
|
+
/**
|
|
8
|
+
* Checkbox for turning an option on or off, with an optional mixed state.
|
|
9
|
+
* @fires pm-change - When toggled. detail: { checked, value }
|
|
10
|
+
* @tag pm-checkbox
|
|
11
|
+
* @slot - Label text.
|
|
12
|
+
* @example <pm-checkbox name="terms" required>I agree</pm-checkbox>
|
|
13
|
+
*/
|
|
14
|
+
export class PmCheckbox extends PmFormControl {
|
|
15
|
+
static { this.styles = [...PmFormControl.styles, checkboxCss]; }
|
|
16
|
+
static { this.componentName = 'checkbox'; }
|
|
17
|
+
static { this.properties = {
|
|
18
|
+
checked: { type: Boolean, reflect: true },
|
|
19
|
+
indeterminate: { type: Boolean },
|
|
20
|
+
}; }
|
|
21
|
+
#defaultChecked;
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.kind = 'checkbox';
|
|
25
|
+
this.#defaultChecked = false;
|
|
26
|
+
this.checked = false;
|
|
27
|
+
this.indeterminate = false;
|
|
28
|
+
this.value = 'on';
|
|
29
|
+
}
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
super.connectedCallback();
|
|
32
|
+
this.#defaultChecked = this.hasAttribute('checked');
|
|
33
|
+
if (!this.getAttribute('value'))
|
|
34
|
+
this.value = 'on';
|
|
35
|
+
}
|
|
36
|
+
formResetCallback() {
|
|
37
|
+
this.checked = this.#defaultChecked;
|
|
38
|
+
}
|
|
39
|
+
syncFormValue() {
|
|
40
|
+
this.internals.setFormValue(this.checked ? this.value : null);
|
|
41
|
+
}
|
|
42
|
+
render() {
|
|
43
|
+
const isSwitch = this.kind === 'switch';
|
|
44
|
+
return html `<label class="pm-check-label" part="label">
|
|
45
|
+
<input
|
|
46
|
+
data-control
|
|
47
|
+
part="control"
|
|
48
|
+
type="checkbox"
|
|
49
|
+
class=${isSwitch ? 'pm-switch' : 'pm-checkbox'}
|
|
50
|
+
role=${isSwitch ? 'switch' : nothing}
|
|
51
|
+
?switch=${isSwitch}
|
|
52
|
+
id=${this.controlId}
|
|
53
|
+
.checked=${live(this.checked)}
|
|
54
|
+
.indeterminate=${this.indeterminate}
|
|
55
|
+
?required=${this.required}
|
|
56
|
+
?disabled=${this.disabled}
|
|
57
|
+
aria-invalid=${this.showInvalid ? 'true' : nothing}
|
|
58
|
+
aria-describedby=${ifDefined(this.describedBy())}
|
|
59
|
+
@change=${(e) => {
|
|
60
|
+
this.checked = e.target.checked;
|
|
61
|
+
this.indeterminate = false;
|
|
62
|
+
this.emit('pm-change', { checked: this.checked, value: this.value });
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
<span><slot>${this.label}</slot></span>
|
|
66
|
+
</label>
|
|
67
|
+
${this.hint ? html `<div class="pm-hint" id=${`${this.controlId}-hint`} part="hint">${this.hint}</div>` : nothing}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
defineElement('pm-checkbox', PmCheckbox);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
import { type Lang } from '../highlight.js';
|
|
4
|
+
/** Remove the indentation the markup around a snippet added, and blank lines at both ends. */
|
|
5
|
+
export declare function dedent(text: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Code snippet with syntax colours, a copy button and optional line numbers.
|
|
8
|
+
*
|
|
9
|
+
* Put the code in the `code` property, or as text inside the element (escape `<` as `<` in HTML). The language
|
|
10
|
+
* is detected when not given. Long snippets can start collapsed with `max-lines`.
|
|
11
|
+
* @tag pm-code-block
|
|
12
|
+
* @slot - The code, as text (used when `code` is not set).
|
|
13
|
+
* @fires pm-copy - The code was copied. detail: { value }
|
|
14
|
+
* @example <pm-code-block label="install" language="shell">npm install @prismora/elements</pm-code-block>
|
|
15
|
+
*/
|
|
16
|
+
export declare class PmCodeBlock extends PmElement {
|
|
17
|
+
#private;
|
|
18
|
+
static componentName: string;
|
|
19
|
+
static styles: import("lit").CSSResult[];
|
|
20
|
+
static properties: PropertyDeclarations;
|
|
21
|
+
/** The code to show. When not set, the element's text content is used. */
|
|
22
|
+
code?: string;
|
|
23
|
+
/** markup (HTML, Vue, Svelte), js (also TypeScript and JSX), css, shell, json or text. Detected when omitted. */
|
|
24
|
+
language?: Lang;
|
|
25
|
+
/** File name or title shown in the bar instead of the language name. */
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Number each line. */
|
|
28
|
+
lineNumbers: boolean;
|
|
29
|
+
/** Wrap long lines instead of scrolling sideways. */
|
|
30
|
+
wrap: boolean;
|
|
31
|
+
/** Collapse snippets longer than this many lines behind a "Show all" button. */
|
|
32
|
+
maxLines?: number;
|
|
33
|
+
/** Hide the copy button. */
|
|
34
|
+
hideCopy: boolean;
|
|
35
|
+
_copied: boolean;
|
|
36
|
+
_open: boolean;
|
|
37
|
+
_text: string;
|
|
38
|
+
constructor();
|
|
39
|
+
connectedCallback(): void;
|
|
40
|
+
disconnectedCallback(): void;
|
|
41
|
+
/** The code as shown. */
|
|
42
|
+
get value(): string;
|
|
43
|
+
/** Copy the code (also done by the button). */
|
|
44
|
+
copy(): Promise<void>;
|
|
45
|
+
render(): import("lit").TemplateResult<1>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
3
|
+
import { PmElement, defineElement } from '../base.js';
|
|
4
|
+
import { LANG_LABEL, detectLang, highlight } from '../highlight.js';
|
|
5
|
+
import extrasCss from '../styles/extras.js';
|
|
6
|
+
/** Remove the indentation the markup around a snippet added, and blank lines at both ends. */
|
|
7
|
+
export function dedent(text) {
|
|
8
|
+
const lines = text.replace(/\t/g, ' ').split('\n');
|
|
9
|
+
while (lines.length && !lines[0].trim())
|
|
10
|
+
lines.shift();
|
|
11
|
+
while (lines.length && !lines[lines.length - 1].trim())
|
|
12
|
+
lines.pop();
|
|
13
|
+
const width = (l) => l.match(/^ */)[0].length;
|
|
14
|
+
// Code that starts right after the opening tag has an unindented first line: measure the lines after it.
|
|
15
|
+
const inline = lines.length > 1 && width(lines[0]) === 0;
|
|
16
|
+
const indent = Math.min(...lines.slice(inline ? 1 : 0).filter((l) => l.trim()).map(width));
|
|
17
|
+
if (!Number.isFinite(indent))
|
|
18
|
+
return lines.join('\n');
|
|
19
|
+
return lines.map((l, i) => (inline && i === 0 ? l : l.slice(Math.min(indent, width(l))))).join('\n');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Code snippet with syntax colours, a copy button and optional line numbers.
|
|
23
|
+
*
|
|
24
|
+
* Put the code in the `code` property, or as text inside the element (escape `<` as `<` in HTML). The language
|
|
25
|
+
* is detected when not given. Long snippets can start collapsed with `max-lines`.
|
|
26
|
+
* @tag pm-code-block
|
|
27
|
+
* @slot - The code, as text (used when `code` is not set).
|
|
28
|
+
* @fires pm-copy - The code was copied. detail: { value }
|
|
29
|
+
* @example <pm-code-block label="install" language="shell">npm install @prismora/elements</pm-code-block>
|
|
30
|
+
*/
|
|
31
|
+
export class PmCodeBlock extends PmElement {
|
|
32
|
+
static { this.componentName = 'code-block'; }
|
|
33
|
+
static { this.styles = [...PmElement.styles, extrasCss, css `:host { display: block; min-inline-size: 0; } :host([hidden]) { display: none; }`]; }
|
|
34
|
+
static { this.properties = {
|
|
35
|
+
code: {}, language: {}, label: {}, lineNumbers: { type: Boolean, attribute: 'line-numbers' }, wrap: { type: Boolean, reflect: true },
|
|
36
|
+
maxLines: { type: Number, attribute: 'max-lines' }, hideCopy: { type: Boolean, attribute: 'hide-copy' },
|
|
37
|
+
_copied: { state: true }, _open: { state: true }, _text: { state: true },
|
|
38
|
+
}; }
|
|
39
|
+
#timer = 0;
|
|
40
|
+
#observer;
|
|
41
|
+
constructor() { super(); this.lineNumbers = false; this.wrap = false; this.hideCopy = false; this._copied = false; this._open = false; this._text = ''; }
|
|
42
|
+
connectedCallback() {
|
|
43
|
+
super.connectedCallback();
|
|
44
|
+
this.#read();
|
|
45
|
+
// Frameworks fill the text after the element connects.
|
|
46
|
+
this.#observer = new MutationObserver(() => this.#read());
|
|
47
|
+
this.#observer.observe(this, { childList: true, characterData: true, subtree: true });
|
|
48
|
+
}
|
|
49
|
+
disconnectedCallback() { super.disconnectedCallback(); this.#observer?.disconnect(); clearTimeout(this.#timer); }
|
|
50
|
+
#read() { this._text = dedent(this.textContent ?? ''); }
|
|
51
|
+
/** The code as shown. */
|
|
52
|
+
get value() { return this.code !== undefined ? dedent(this.code) : this._text; }
|
|
53
|
+
/** Copy the code (also done by the button). */
|
|
54
|
+
async copy() {
|
|
55
|
+
try {
|
|
56
|
+
await navigator.clipboard.writeText(this.value);
|
|
57
|
+
this._copied = true;
|
|
58
|
+
this.emit('pm-copy', { value: this.value });
|
|
59
|
+
clearTimeout(this.#timer);
|
|
60
|
+
this.#timer = window.setTimeout(() => (this._copied = false), 2000);
|
|
61
|
+
}
|
|
62
|
+
catch { /* clipboard blocked: the text can still be selected */ }
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
const code = this.value;
|
|
66
|
+
const lang = this.language ?? detectLang(code);
|
|
67
|
+
const lines = code.split('\n');
|
|
68
|
+
const long = !!this.maxLines && lines.length > this.maxLines;
|
|
69
|
+
const collapsed = long && !this._open;
|
|
70
|
+
const marked = highlight(code, lang);
|
|
71
|
+
// Line numbers need one element per line; tokens never span lines except comments and strings, which are re-wrapped.
|
|
72
|
+
const body = this.lineNumbers ? marked.split('\n').map((l) => `<span class="pm-code-line">${l}</span>`).join('\n') : marked;
|
|
73
|
+
const title = this.label ?? LANG_LABEL[lang] ?? '';
|
|
74
|
+
return html `<div class="pm-code" part="base" ?data-wrap=${this.wrap} ?data-lines=${this.lineNumbers} ?data-collapsed=${collapsed}
|
|
75
|
+
style=${long ? `--_max: ${this.maxLines * 1.6 + 2}em` : nothing}>
|
|
76
|
+
${title || !this.hideCopy ? html `<div class="pm-code-bar" part="bar">
|
|
77
|
+
<span class="pm-code-label">${title}</span>
|
|
78
|
+
${this.hideCopy ? nothing : html `<button type="button" class="pm-code-btn" part="copy" @click=${() => this.copy()}>${this._copied ? 'Copied' : 'Copy'}<span class="pm-visually-hidden"> code</span></button>`}
|
|
79
|
+
</div>` : nothing}
|
|
80
|
+
<pre part="pre" tabindex="0" aria-label=${this.label ? `Code: ${this.label}` : 'Code'}><code>${unsafeHTML(body)}</code></pre>
|
|
81
|
+
${long ? html `<button type="button" class="pm-code-btn pm-code-more" aria-expanded=${String(this._open)} @click=${() => (this._open = !this._open)}>${this._open ? 'Show less' : `Show all ${lines.length} lines`}</button>` : nothing}
|
|
82
|
+
<span class="pm-visually-hidden" aria-live="polite">${this._copied ? 'Copied' : ''}</span>
|
|
83
|
+
</div>`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
defineElement('pm-code-block', PmCodeBlock);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type PropertyDeclarations, type PropertyValues } from 'lit';
|
|
2
|
+
import { PmFormControl } from './form-control.js';
|
|
3
|
+
export interface Hsva {
|
|
4
|
+
h: number;
|
|
5
|
+
s: number;
|
|
6
|
+
v: number;
|
|
7
|
+
a: number;
|
|
8
|
+
}
|
|
9
|
+
/** Parse #rgb, #rgba, #rrggbb, #rrggbbaa, rgb()/rgba() into HSVA (0–360, 0–1). */
|
|
10
|
+
export declare function parseColor(input: string): Hsva | undefined;
|
|
11
|
+
export declare function hsvaToRgb({ h, s, v }: Hsva): [number, number, number];
|
|
12
|
+
/** "#rrggbb", or "#rrggbbaa" when alpha < 1. */
|
|
13
|
+
export declare function toHex(c: Hsva): string;
|
|
14
|
+
/**
|
|
15
|
+
* Colour picker: a swatch + hex field with a popup (or `inline` panel) holding a saturation/brightness area, hue and
|
|
16
|
+
* optional `alpha` sliders, preset `swatches` and the EyeDropper where supported.
|
|
17
|
+
*
|
|
18
|
+
* Value is "#rrggbb" ("#rrggbbaa" with alpha) and is submitted with forms. Keys on the area: arrows ±1%, Shift ±10%.
|
|
19
|
+
* @attr {boolean} mobile - Native mobile pattern on phones: opens as a swipeable bottom sheet (inherits from ancestors such as `<html mobile>`; `mobile="false"` opts out).
|
|
20
|
+
* @tag pm-color-picker
|
|
21
|
+
* @example <pm-color-picker label="Brand colour" value="#7c5cff" swatches="#7c5cff,#0ea5e9,#22c55e,#f59e0b,#ef4444"></pm-color-picker>
|
|
22
|
+
*/
|
|
23
|
+
export declare class PmColorPicker extends PmFormControl {
|
|
24
|
+
#private;
|
|
25
|
+
static componentName: string;
|
|
26
|
+
static styles: import("lit").CSSResult[];
|
|
27
|
+
static properties: PropertyDeclarations;
|
|
28
|
+
/** Allow transparency (adds an alpha slider; value becomes #rrggbbaa when not opaque). */
|
|
29
|
+
alpha: boolean;
|
|
30
|
+
/** Render the panel inline instead of in a popup. */
|
|
31
|
+
inline: boolean;
|
|
32
|
+
/** Preset colours: comma-separated or a JSON array. */
|
|
33
|
+
swatches?: string | string[];
|
|
34
|
+
placeholder?: string;
|
|
35
|
+
_open: boolean;
|
|
36
|
+
_hsva: Hsva;
|
|
37
|
+
_text?: string;
|
|
38
|
+
constructor();
|
|
39
|
+
protected willUpdate(changed: PropertyValues<this>): void;
|
|
40
|
+
protected syncValidity(): void;
|
|
41
|
+
open(): void;
|
|
42
|
+
close(focus?: boolean): void;
|
|
43
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
44
|
+
disconnectedCallback(): void;
|
|
45
|
+
render(): import("lit").TemplateResult<1>;
|
|
46
|
+
}
|