@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,28 @@
|
|
|
1
|
+
import { css, html } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { PmElement, defineElement } from '../base.js';
|
|
4
|
+
/**
|
|
5
|
+
* Groups buttons with joined edges.
|
|
6
|
+
* @tag pm-button-group
|
|
7
|
+
* @slot - `pm-button` elements.
|
|
8
|
+
*/
|
|
9
|
+
export class PmButtonGroup extends PmElement {
|
|
10
|
+
static { this.properties = { label: {} }; }
|
|
11
|
+
static { this.styles = [...PmElement.styles, css `:host { display: inline-flex; } [part='base'] { display: inline-flex; }`]; }
|
|
12
|
+
render() {
|
|
13
|
+
return html `<div part="base" role="group" aria-label=${ifDefined(this.label)}>
|
|
14
|
+
<slot @slotchange=${this.#mark}></slot>
|
|
15
|
+
</div>`;
|
|
16
|
+
}
|
|
17
|
+
#mark(e) {
|
|
18
|
+
const items = e.target.assignedElements();
|
|
19
|
+
items.forEach((el, i) => {
|
|
20
|
+
const pos = items.length === 1 ? null : i === 0 ? 'first' : i === items.length - 1 ? 'last' : 'middle';
|
|
21
|
+
if (pos)
|
|
22
|
+
el.setAttribute('data-group', pos);
|
|
23
|
+
else
|
|
24
|
+
el.removeAttribute('data-group');
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
defineElement('pm-button-group', PmButtonGroup);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement, type Size, type Variant } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Button for actions, or a link styled as a button when `href` is set.
|
|
5
|
+
* @tag pm-button
|
|
6
|
+
* @slot - Label.
|
|
7
|
+
* @slot start - Leading icon.
|
|
8
|
+
* @slot end - Trailing icon.
|
|
9
|
+
* @csspart base - The native button / anchor.
|
|
10
|
+
*
|
|
11
|
+
* Invokes other elements like a native button: `commandfor` + `command`
|
|
12
|
+
* (`--open`, `--close`, `--toggle`, `show-modal`, `close`, `toggle-popover`, …) or `popovertarget`.
|
|
13
|
+
*
|
|
14
|
+
* @example <pm-button variant="soft" tone="danger">Delete</pm-button>
|
|
15
|
+
*/
|
|
16
|
+
export declare class PmButton extends PmElement {
|
|
17
|
+
#private;
|
|
18
|
+
static componentName: string;
|
|
19
|
+
static formAssociated: boolean;
|
|
20
|
+
static styles: import("lit").CSSResult[];
|
|
21
|
+
static shadowRootOptions: {
|
|
22
|
+
delegatesFocus: boolean;
|
|
23
|
+
clonable?: boolean;
|
|
24
|
+
customElementRegistry?: CustomElementRegistry;
|
|
25
|
+
mode: ShadowRootMode;
|
|
26
|
+
serializable?: boolean;
|
|
27
|
+
slotAssignment?: SlotAssignmentMode;
|
|
28
|
+
};
|
|
29
|
+
static properties: PropertyDeclarations;
|
|
30
|
+
/** Registered icon name shown before the content (see `registerIcons`); a `start` slot overrides it. */
|
|
31
|
+
iconStart?: string;
|
|
32
|
+
/** Registered icon name shown after the content (see `registerIcons`); an `end` slot overrides it. */
|
|
33
|
+
iconEnd?: string;
|
|
34
|
+
/** id of the element to control (same tree). */
|
|
35
|
+
commandfor?: string;
|
|
36
|
+
/** Command sent to `commandfor`: built-ins (`show-modal`, `close`, `toggle-popover`…) or custom `--name`. */
|
|
37
|
+
command?: string;
|
|
38
|
+
/** id of a popover to toggle (like the native attribute). */
|
|
39
|
+
popovertarget?: string;
|
|
40
|
+
/** Visual style. Theme default: `--pm-default-button-variant`. */
|
|
41
|
+
variant?: Variant;
|
|
42
|
+
size?: Size;
|
|
43
|
+
type: 'button' | 'submit' | 'reset';
|
|
44
|
+
disabled: boolean;
|
|
45
|
+
/** Shows a spinner and blocks interaction while keeping the width. */
|
|
46
|
+
loading: boolean;
|
|
47
|
+
/** Square icon-only button. Requires `label`. */
|
|
48
|
+
icon: boolean;
|
|
49
|
+
/** Renders an `<a>` instead of a `<button>`. */
|
|
50
|
+
href?: string;
|
|
51
|
+
/** Where an `href` link opens (as on `<a>`); `_blank` adds rel="noopener". */
|
|
52
|
+
target?: string;
|
|
53
|
+
/** Accessible name (required for icon-only buttons). */
|
|
54
|
+
label?: string;
|
|
55
|
+
name?: string;
|
|
56
|
+
value?: string;
|
|
57
|
+
constructor();
|
|
58
|
+
render(): import("lit").TemplateResult<1>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { PmElement, defineElement } from '../base.js';
|
|
4
|
+
import buttonCss from '../styles/button.js';
|
|
5
|
+
import { namedIcon } from '../named-icon.js';
|
|
6
|
+
/**
|
|
7
|
+
* Button for actions, or a link styled as a button when `href` is set.
|
|
8
|
+
* @tag pm-button
|
|
9
|
+
* @slot - Label.
|
|
10
|
+
* @slot start - Leading icon.
|
|
11
|
+
* @slot end - Trailing icon.
|
|
12
|
+
* @csspart base - The native button / anchor.
|
|
13
|
+
*
|
|
14
|
+
* Invokes other elements like a native button: `commandfor` + `command`
|
|
15
|
+
* (`--open`, `--close`, `--toggle`, `show-modal`, `close`, `toggle-popover`, …) or `popovertarget`.
|
|
16
|
+
*
|
|
17
|
+
* @example <pm-button variant="soft" tone="danger">Delete</pm-button>
|
|
18
|
+
*/
|
|
19
|
+
export class PmButton extends PmElement {
|
|
20
|
+
static { this.componentName = 'button'; }
|
|
21
|
+
static { this.formAssociated = true; }
|
|
22
|
+
static { this.styles = [...PmElement.styles, buttonCss,
|
|
23
|
+
css `
|
|
24
|
+
:host { display: inline-flex; vertical-align: middle; }
|
|
25
|
+
:host([hidden]) { display: none; }
|
|
26
|
+
.pm-button { inline-size: 100%; }
|
|
27
|
+
:host([data-group='middle']) .pm-button { border-radius: 0; }
|
|
28
|
+
:host([data-group='first']) .pm-button { border-start-end-radius: 0; border-end-end-radius: 0; }
|
|
29
|
+
:host([data-group='last']) .pm-button { border-start-start-radius: 0; border-end-start-radius: 0; }
|
|
30
|
+
:host([data-group]:not([data-group='first'])) { margin-inline-start: -1px; }
|
|
31
|
+
:host(:focus-within) { position: relative; z-index: 1; }
|
|
32
|
+
`,
|
|
33
|
+
]; }
|
|
34
|
+
static { this.shadowRootOptions = { ...PmElement.shadowRootOptions, delegatesFocus: true }; }
|
|
35
|
+
static { this.properties = { iconStart: { attribute: 'icon-start', reflect: true }, iconEnd: { attribute: 'icon-end', reflect: true },
|
|
36
|
+
variant: { reflect: true },
|
|
37
|
+
size: { reflect: true },
|
|
38
|
+
type: { reflect: true },
|
|
39
|
+
disabled: { type: Boolean, reflect: true },
|
|
40
|
+
loading: { type: Boolean, reflect: true },
|
|
41
|
+
icon: { type: Boolean, reflect: true },
|
|
42
|
+
href: {},
|
|
43
|
+
target: {},
|
|
44
|
+
label: {},
|
|
45
|
+
name: {},
|
|
46
|
+
value: {},
|
|
47
|
+
commandfor: {},
|
|
48
|
+
command: {},
|
|
49
|
+
popovertarget: {},
|
|
50
|
+
}; }
|
|
51
|
+
#internals = this.attachInternals();
|
|
52
|
+
constructor() {
|
|
53
|
+
super();
|
|
54
|
+
this.type = 'button';
|
|
55
|
+
this.disabled = false;
|
|
56
|
+
this.loading = false;
|
|
57
|
+
this.icon = false;
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
const variant = this.variant ?? this.defaultFor('variant') ?? 'solid';
|
|
61
|
+
const size = this.size ?? this.defaultFor('size');
|
|
62
|
+
const content = html `<slot name="start">${namedIcon(this.iconStart)}</slot><slot></slot><slot name="end">${namedIcon(this.iconEnd)}</slot>`;
|
|
63
|
+
if (this.href && !this.disabled) {
|
|
64
|
+
return html `<a
|
|
65
|
+
part="base"
|
|
66
|
+
class="pm-button"
|
|
67
|
+
href=${this.href}
|
|
68
|
+
target=${ifDefined(this.target)}
|
|
69
|
+
rel=${ifDefined(this.target === '_blank' ? 'noopener noreferrer' : undefined)}
|
|
70
|
+
data-variant=${variant}
|
|
71
|
+
data-size=${ifDefined(size)}
|
|
72
|
+
?data-icon=${this.icon}
|
|
73
|
+
aria-label=${ifDefined(this.label)}
|
|
74
|
+
>${content}</a
|
|
75
|
+
>`;
|
|
76
|
+
}
|
|
77
|
+
return html `<button
|
|
78
|
+
part="base"
|
|
79
|
+
class="pm-button"
|
|
80
|
+
type="button"
|
|
81
|
+
data-variant=${variant}
|
|
82
|
+
data-size=${ifDefined(size)}
|
|
83
|
+
?data-icon=${this.icon}
|
|
84
|
+
?data-loading=${this.loading}
|
|
85
|
+
?disabled=${this.disabled}
|
|
86
|
+
aria-busy=${this.loading ? 'true' : nothing}
|
|
87
|
+
aria-label=${ifDefined(this.label)}
|
|
88
|
+
@click=${this.#onClick}
|
|
89
|
+
>
|
|
90
|
+
${content}
|
|
91
|
+
</button>`;
|
|
92
|
+
}
|
|
93
|
+
#onClick() {
|
|
94
|
+
if (this.disabled || this.loading)
|
|
95
|
+
return;
|
|
96
|
+
if (this.commandfor || this.popovertarget) {
|
|
97
|
+
this.#invoke();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const form = this.#internals.form;
|
|
101
|
+
if (!form)
|
|
102
|
+
return;
|
|
103
|
+
if (this.type === 'submit') {
|
|
104
|
+
// Submit with this element as the submitter so name/value are included.
|
|
105
|
+
if (this.name) {
|
|
106
|
+
const proxy = document.createElement('input');
|
|
107
|
+
proxy.type = 'hidden';
|
|
108
|
+
proxy.name = this.name;
|
|
109
|
+
proxy.value = this.value ?? '';
|
|
110
|
+
form.append(proxy);
|
|
111
|
+
form.requestSubmit();
|
|
112
|
+
proxy.remove();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
form.requestSubmit();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (this.type === 'reset') {
|
|
119
|
+
form.reset();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Mirrors native invoker semantics for the element referenced by commandfor / popovertarget. */
|
|
123
|
+
#invoke() {
|
|
124
|
+
const root = this.getRootNode();
|
|
125
|
+
const id = this.commandfor ?? this.popovertarget;
|
|
126
|
+
const target = root.getElementById?.(id) ?? document.getElementById(id);
|
|
127
|
+
if (!target)
|
|
128
|
+
return;
|
|
129
|
+
const command = this.commandfor ? (this.command ?? '') : 'toggle-popover';
|
|
130
|
+
const source = this.renderRoot.querySelector('.pm-button') ?? this;
|
|
131
|
+
const ev = Object.assign(new Event('command', { cancelable: true }), { command, source: this });
|
|
132
|
+
if (!target.dispatchEvent(ev))
|
|
133
|
+
return;
|
|
134
|
+
if (target instanceof HTMLDialogElement) {
|
|
135
|
+
if (command === 'show-modal' && !target.open)
|
|
136
|
+
target.showModal();
|
|
137
|
+
else if (command === 'close')
|
|
138
|
+
target.close();
|
|
139
|
+
else if (command === 'request-close')
|
|
140
|
+
target.requestClose?.();
|
|
141
|
+
}
|
|
142
|
+
else if (target.hasAttribute('popover')) {
|
|
143
|
+
const p = target;
|
|
144
|
+
const opts = { source };
|
|
145
|
+
try {
|
|
146
|
+
if (command === 'toggle-popover')
|
|
147
|
+
p.togglePopover(opts);
|
|
148
|
+
else if (command === 'show-popover')
|
|
149
|
+
p.showPopover(opts);
|
|
150
|
+
else if (command === 'hide-popover')
|
|
151
|
+
p.hidePopover();
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
if (command === 'toggle-popover')
|
|
155
|
+
p.togglePopover();
|
|
156
|
+
else if (command === 'show-popover')
|
|
157
|
+
p.showPopover();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
defineElement('pm-button', PmButton);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type PropertyDeclarations, type PropertyValues } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
export declare const parseISODate: (s?: string | null) => Date | undefined;
|
|
4
|
+
export declare const toISODate: (d: Date) => string;
|
|
5
|
+
export declare const todayISO: () => string;
|
|
6
|
+
/** First day of week for a locale (0 = Sunday … 6), via Intl.Locale weekInfo when available. */
|
|
7
|
+
export declare function firstDayOf(locale: string): number;
|
|
8
|
+
/**
|
|
9
|
+
* Calendar (WAI-ARIA date grid) with month and year views: click the title to jump to a month, then to a year.
|
|
10
|
+
*
|
|
11
|
+
* Single date or `range` selection, `months="2"` side by side, min/max, disabled dates, locale-aware week start and
|
|
12
|
+
* names. Keys: arrows move by day/week, PgUp/PgDn month (+Shift year), Home/End week edges, Enter/Space select; in
|
|
13
|
+
* month/year views arrows move, Enter picks, Esc goes back.
|
|
14
|
+
* @tag pm-calendar
|
|
15
|
+
* @fires pm-change - Selection changed. detail: { value } ("YYYY-MM-DD", or "start/end" with range)
|
|
16
|
+
* @example <pm-calendar value="2026-12-02"></pm-calendar>
|
|
17
|
+
*/
|
|
18
|
+
export declare class PmCalendar extends PmElement {
|
|
19
|
+
#private;
|
|
20
|
+
static componentName: string;
|
|
21
|
+
static styles: import("lit").CSSResult[];
|
|
22
|
+
static properties: PropertyDeclarations;
|
|
23
|
+
/** "YYYY-MM-DD", or "YYYY-MM-DD/YYYY-MM-DD" with `range`. */
|
|
24
|
+
value: string;
|
|
25
|
+
min?: string;
|
|
26
|
+
max?: string;
|
|
27
|
+
/** BCP 47 locale for names and week start (defaults to the document language). */
|
|
28
|
+
locale?: string;
|
|
29
|
+
range: boolean;
|
|
30
|
+
/** Override the locale's first day of the week (0 = Sunday). */
|
|
31
|
+
firstDay?: number;
|
|
32
|
+
/** Number of months shown side by side (1–3). */
|
|
33
|
+
months: number;
|
|
34
|
+
/** Current view: day grid, month picker or year picker. */
|
|
35
|
+
view: 'days' | 'months' | 'years';
|
|
36
|
+
/** Return true to disable a date (e.g. weekends, booked days). */
|
|
37
|
+
isDateDisabled?: (iso: string) => boolean;
|
|
38
|
+
_focus: string;
|
|
39
|
+
_hover?: string;
|
|
40
|
+
_anchor?: string;
|
|
41
|
+
/** First visible month ("YYYY-MM-01"). */
|
|
42
|
+
_start: string;
|
|
43
|
+
constructor();
|
|
44
|
+
protected willUpdate(changed: PropertyValues<this>): void;
|
|
45
|
+
/** Show the month containing this date. */
|
|
46
|
+
showDate(iso: string): void;
|
|
47
|
+
render(): import("lit").TemplateResult<1>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import calendarCss from '../styles/calendar.js';
|
|
4
|
+
/* Plain calendar dates ("YYYY-MM-DD") as UTC-midnight Dates: no timezone drift. */
|
|
5
|
+
export const parseISODate = (s) => {
|
|
6
|
+
const m = s?.trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
7
|
+
if (!m)
|
|
8
|
+
return undefined;
|
|
9
|
+
const d = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));
|
|
10
|
+
return d.getUTCMonth() === +m[2] - 1 ? d : undefined;
|
|
11
|
+
};
|
|
12
|
+
export const toISODate = (d) => d.toISOString().slice(0, 10);
|
|
13
|
+
const addDays = (d, n) => new Date(d.getTime() + n * 864e5);
|
|
14
|
+
const addMonths = (d, n) => {
|
|
15
|
+
const r = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + n, 1));
|
|
16
|
+
const last = new Date(Date.UTC(r.getUTCFullYear(), r.getUTCMonth() + 1, 0)).getUTCDate();
|
|
17
|
+
r.setUTCDate(Math.min(d.getUTCDate(), last));
|
|
18
|
+
return r;
|
|
19
|
+
};
|
|
20
|
+
export const todayISO = () => { const n = new Date(); return toISODate(new Date(Date.UTC(n.getFullYear(), n.getMonth(), n.getDate()))); };
|
|
21
|
+
/** First day of week for a locale (0 = Sunday … 6), via Intl.Locale weekInfo when available. */
|
|
22
|
+
export function firstDayOf(locale) {
|
|
23
|
+
try {
|
|
24
|
+
const l = new Intl.Locale(locale);
|
|
25
|
+
const info = l.getWeekInfo?.() ?? l.weekInfo;
|
|
26
|
+
if (info)
|
|
27
|
+
return info.firstDay % 7;
|
|
28
|
+
}
|
|
29
|
+
catch { /* fall through */ }
|
|
30
|
+
return /^en-(US|CA)|^(ja|ko|zh-TW|he|pt-BR)/.test(locale) ? 0 : 1;
|
|
31
|
+
}
|
|
32
|
+
const ARROW = (flip) => html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style=${flip ? 'scale: -1 1' : ''}><path d="M15 6l-6 6 6 6"/></svg>`;
|
|
33
|
+
/**
|
|
34
|
+
* Calendar (WAI-ARIA date grid) with month and year views: click the title to jump to a month, then to a year.
|
|
35
|
+
*
|
|
36
|
+
* Single date or `range` selection, `months="2"` side by side, min/max, disabled dates, locale-aware week start and
|
|
37
|
+
* names. Keys: arrows move by day/week, PgUp/PgDn month (+Shift year), Home/End week edges, Enter/Space select; in
|
|
38
|
+
* month/year views arrows move, Enter picks, Esc goes back.
|
|
39
|
+
* @tag pm-calendar
|
|
40
|
+
* @fires pm-change - Selection changed. detail: { value } ("YYYY-MM-DD", or "start/end" with range)
|
|
41
|
+
* @example <pm-calendar value="2026-12-02"></pm-calendar>
|
|
42
|
+
*/
|
|
43
|
+
export class PmCalendar extends PmElement {
|
|
44
|
+
static { this.componentName = 'calendar'; }
|
|
45
|
+
static { this.styles = [...PmElement.styles, calendarCss, css `:host { display: inline-block; } .nav { display: flex; gap: 2px; }
|
|
46
|
+
.nav button, .pm-calendar-title { display: grid; place-items: center; min-inline-size: 2rem; block-size: 2rem; padding: 0; border: 0; border-radius: var(--pm-radius-md); background: none; color: inherit; font: inherit; cursor: pointer; }
|
|
47
|
+
.pm-calendar-title { display: inline-flex; gap: .25rem; padding-inline: .5rem; margin-inline-start: -.5rem; }
|
|
48
|
+
.pm-calendar-title[disabled] { cursor: default; }
|
|
49
|
+
:is(.nav button, .pm-calendar-title):hover:not(:disabled) { background: var(--pm-color-bg-hover); } .nav button:disabled { opacity: .35; cursor: not-allowed; }
|
|
50
|
+
:is(.nav button, .pm-calendar-title):focus-visible { outline: 2px solid var(--pm-color-ring); }
|
|
51
|
+
.months { display: flex; gap: var(--pm-space-5); align-items: start; flex-wrap: wrap; }
|
|
52
|
+
.month { display: grid; gap: var(--pm-space-1); }
|
|
53
|
+
.month-name { text-align: center; font-weight: var(--pm-font-weight-semibold); text-transform: capitalize; block-size: 2rem; display: grid; place-items: center; }`]; }
|
|
54
|
+
static { this.properties = {
|
|
55
|
+
value: { reflect: true }, min: {}, max: {}, locale: {}, range: { type: Boolean }, firstDay: { type: Number, attribute: 'first-day' },
|
|
56
|
+
months: { type: Number }, view: { reflect: true },
|
|
57
|
+
isDateDisabled: { attribute: false }, _focus: { state: true }, _hover: { state: true }, _anchor: { state: true }, _start: { state: true },
|
|
58
|
+
}; }
|
|
59
|
+
constructor() { super(); this.value = ''; this.range = false; this._focus = ''; this._start = ''; this.months = 1; this.view = 'days'; }
|
|
60
|
+
get #locale() { return this.locale || this.closest('[lang]')?.getAttribute('lang') || navigator.language || 'en-US'; }
|
|
61
|
+
get #range() { const [a, b] = this.value.split('/'); return [a || undefined, b || undefined]; }
|
|
62
|
+
get #count() { return Math.min(3, Math.max(1, Math.floor(this.months) || 1)); }
|
|
63
|
+
willUpdate(changed) {
|
|
64
|
+
if (!this._focus || (changed.has('value') && this.value && !this.renderRoot.querySelector(':focus'))) {
|
|
65
|
+
const first = this.range ? this.#range[0] : this.value;
|
|
66
|
+
this._focus = this.#clamp(parseISODate(first) ? first : todayISO());
|
|
67
|
+
}
|
|
68
|
+
// Keep the focused date inside the visible months.
|
|
69
|
+
const f = this._focus.slice(0, 7) + '-01';
|
|
70
|
+
const last = this._start ? toISODate(addMonths(parseISODate(this._start), this.#count - 1)) : '';
|
|
71
|
+
if (!this._start || f < this._start)
|
|
72
|
+
this._start = f;
|
|
73
|
+
else if (f > last)
|
|
74
|
+
this._start = toISODate(addMonths(parseISODate(f), -(this.#count - 1)));
|
|
75
|
+
}
|
|
76
|
+
#clamp(iso) {
|
|
77
|
+
if (this.min && iso < this.min)
|
|
78
|
+
return this.min;
|
|
79
|
+
if (this.max && iso > this.max)
|
|
80
|
+
return this.max;
|
|
81
|
+
return iso;
|
|
82
|
+
}
|
|
83
|
+
#disabled(iso) { return (!!this.min && iso < this.min) || (!!this.max && iso > this.max) || !!this.isDateDisabled?.(iso); }
|
|
84
|
+
/** Show the month containing this date. */
|
|
85
|
+
showDate(iso) { if (parseISODate(iso)) {
|
|
86
|
+
this._focus = this.#clamp(iso);
|
|
87
|
+
this._start = '';
|
|
88
|
+
} }
|
|
89
|
+
#focusSel(sel) { this.updateComplete.then(() => this.renderRoot.querySelector(sel)?.focus()); }
|
|
90
|
+
#moveFocus(d) {
|
|
91
|
+
this._focus = this.#clamp(toISODate(d));
|
|
92
|
+
this.#focusSel('.pm-day[tabindex="0"]');
|
|
93
|
+
}
|
|
94
|
+
#shift(months) {
|
|
95
|
+
const s = addMonths(parseISODate(this._start), months);
|
|
96
|
+
this._start = toISODate(s);
|
|
97
|
+
const f = addMonths(parseISODate(this._focus), months);
|
|
98
|
+
this._focus = this.#clamp(toISODate(f));
|
|
99
|
+
}
|
|
100
|
+
#origin = '';
|
|
101
|
+
#setView(v) {
|
|
102
|
+
if (this.view === 'days' && v !== 'days')
|
|
103
|
+
this.#origin = this._focus;
|
|
104
|
+
this.view = v;
|
|
105
|
+
this.#focusSel(v === 'days' ? '.pm-day[tabindex="0"]' : '.pm-calendar-cell[tabindex="0"]');
|
|
106
|
+
}
|
|
107
|
+
#select(iso) {
|
|
108
|
+
if (this.#disabled(iso))
|
|
109
|
+
return;
|
|
110
|
+
this._focus = iso;
|
|
111
|
+
if (this.range) {
|
|
112
|
+
if (!this._anchor) {
|
|
113
|
+
this._anchor = iso;
|
|
114
|
+
this.value = `${iso}/`;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const [a, b] = [this._anchor, iso].sort();
|
|
118
|
+
this._anchor = undefined;
|
|
119
|
+
this.value = `${a}/${b}`;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (this.value === iso)
|
|
123
|
+
return;
|
|
124
|
+
this.value = iso;
|
|
125
|
+
}
|
|
126
|
+
this.emit('pm-change', { value: this.value });
|
|
127
|
+
}
|
|
128
|
+
#onKey(e) {
|
|
129
|
+
const d = parseISODate(this._focus);
|
|
130
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
131
|
+
const fd = this.firstDay ?? firstDayOf(this.#locale);
|
|
132
|
+
const dow = (d.getUTCDay() - fd + 7) % 7;
|
|
133
|
+
const map = {
|
|
134
|
+
ArrowRight: () => addDays(d, rtl ? -1 : 1), ArrowLeft: () => addDays(d, rtl ? 1 : -1),
|
|
135
|
+
ArrowDown: () => addDays(d, 7), ArrowUp: () => addDays(d, -7),
|
|
136
|
+
Home: () => addDays(d, -dow), End: () => addDays(d, 6 - dow),
|
|
137
|
+
PageUp: () => addMonths(d, e.shiftKey ? -12 : -1), PageDown: () => addMonths(d, e.shiftKey ? 12 : 1),
|
|
138
|
+
};
|
|
139
|
+
if (map[e.key]) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
this.#moveFocus(map[e.key]());
|
|
142
|
+
}
|
|
143
|
+
else if (e.key === 'Enter' || e.key === ' ') {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
this.#select(this._focus);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Keyboard for the 3×4 month/year pickers. */
|
|
149
|
+
#onPickerKey(e) {
|
|
150
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
151
|
+
const yearView = this.view === 'years';
|
|
152
|
+
const step = { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1, ArrowDown: 3, ArrowUp: -3, PageDown: yearView ? 10 : 12, PageUp: yearView ? -10 : -12 }[e.key];
|
|
153
|
+
const d = parseISODate(this._focus);
|
|
154
|
+
if (step) {
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
this._focus = this.#clamp(toISODate(addMonths(d, step * (yearView ? 12 : 1))));
|
|
157
|
+
this.#focusSel('.pm-calendar-cell[tabindex="0"]');
|
|
158
|
+
}
|
|
159
|
+
else if (e.key === 'Escape' && this.view !== 'days') {
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
e.stopPropagation();
|
|
162
|
+
if (this.view === 'months' && this.#origin) {
|
|
163
|
+
this._focus = this.#origin;
|
|
164
|
+
this._start = '';
|
|
165
|
+
}
|
|
166
|
+
this.#setView(this.view === 'years' ? 'months' : 'days');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
#pickMonth(month) {
|
|
170
|
+
const d = parseISODate(this._focus);
|
|
171
|
+
const y = d.getUTCFullYear();
|
|
172
|
+
const last = new Date(Date.UTC(y, month + 1, 0)).getUTCDate();
|
|
173
|
+
this._focus = this.#clamp(toISODate(new Date(Date.UTC(y, month, Math.min(d.getUTCDate(), last)))));
|
|
174
|
+
this._start = '';
|
|
175
|
+
this.#setView('days');
|
|
176
|
+
}
|
|
177
|
+
#pickYear(year) {
|
|
178
|
+
const d = parseISODate(this._focus);
|
|
179
|
+
const last = new Date(Date.UTC(year, d.getUTCMonth() + 1, 0)).getUTCDate();
|
|
180
|
+
this._focus = this.#clamp(toISODate(new Date(Date.UTC(year, d.getUTCMonth(), Math.min(d.getUTCDate(), last)))));
|
|
181
|
+
this.#setView('months');
|
|
182
|
+
}
|
|
183
|
+
#monthGrid(first, loc, labelId) {
|
|
184
|
+
const m = first.getUTCMonth();
|
|
185
|
+
const fd = this.firstDay ?? firstDayOf(loc);
|
|
186
|
+
const start = addDays(first, -((first.getUTCDay() - fd + 7) % 7));
|
|
187
|
+
const wdLong = new Intl.DateTimeFormat(loc, { weekday: 'long', timeZone: 'UTC' });
|
|
188
|
+
const wdShort = new Intl.DateTimeFormat(loc, { weekday: 'narrow', timeZone: 'UTC' });
|
|
189
|
+
const full = new Intl.DateTimeFormat(loc, { dateStyle: 'full', timeZone: 'UTC' });
|
|
190
|
+
const today = todayISO();
|
|
191
|
+
const [rs, reRaw] = this.#range;
|
|
192
|
+
const preview = this.range && this._anchor && this._hover;
|
|
193
|
+
const re = preview ? (this._hover > this._anchor ? this._hover : this._anchor) : reRaw;
|
|
194
|
+
const rsEff = preview ? (this._hover < this._anchor ? this._hover : this._anchor) : rs;
|
|
195
|
+
const weeks = Array.from({ length: 6 }, (_, w) => Array.from({ length: 7 }, (_, i) => addDays(start, w * 7 + i)));
|
|
196
|
+
const multi = this.#count > 1;
|
|
197
|
+
return html `<table class="pm-calendar-grid" role="grid" aria-labelledby=${labelId} @keydown=${this.#onKey} @pointerleave=${() => (this._hover = undefined)}>
|
|
198
|
+
<thead><tr role="row">${weeks[0].map((d) => html `<th role="columnheader" scope="col" abbr=${wdLong.format(d)}>${wdShort.format(d)}</th>`)}</tr></thead>
|
|
199
|
+
<tbody>${weeks.map((week) => html `<tr role="row">${week.map((d) => {
|
|
200
|
+
const iso = toISODate(d);
|
|
201
|
+
const outside = d.getUTCMonth() !== m;
|
|
202
|
+
if (outside && multi)
|
|
203
|
+
return html `<td role="presentation"><span role="gridcell" class="pm-day" data-blank aria-hidden="true"></span></td>`;
|
|
204
|
+
const selected = this.range ? iso === rsEff || iso === re : iso === this.value;
|
|
205
|
+
const inRange = this.range && !!rsEff && !!re && iso > rsEff && iso < re;
|
|
206
|
+
const dis = this.#disabled(iso);
|
|
207
|
+
return html `<td role="presentation"><span role="gridcell" class="pm-day" tabindex=${iso === this._focus && !outside ? 0 : -1}
|
|
208
|
+
aria-label=${full.format(d)} aria-selected=${selected ? 'true' : 'false'} aria-disabled=${dis ? 'true' : nothing}
|
|
209
|
+
aria-current=${iso === today ? 'date' : nothing} ?data-today=${iso === today} ?data-outside=${outside}
|
|
210
|
+
?data-in-range=${inRange} ?data-range-start=${this.range && iso === rsEff} ?data-range-end=${this.range && iso === re}
|
|
211
|
+
@pointerenter=${() => { if (this._anchor)
|
|
212
|
+
this._hover = iso; }} @click=${() => this.#select(iso)}>${d.getUTCDate()}</span></td>`;
|
|
213
|
+
})}</tr>`)}</tbody>
|
|
214
|
+
</table>`;
|
|
215
|
+
}
|
|
216
|
+
render() {
|
|
217
|
+
const loc = this.#locale;
|
|
218
|
+
const focus = parseISODate(this._focus);
|
|
219
|
+
const fy = focus.getUTCFullYear();
|
|
220
|
+
const startD = parseISODate(this._start);
|
|
221
|
+
const count = this.#count;
|
|
222
|
+
const firsts = Array.from({ length: count }, (_, i) => addMonths(startD, i));
|
|
223
|
+
const lastFirst = firsts[count - 1];
|
|
224
|
+
const monthYear = new Intl.DateTimeFormat(loc, { month: 'long', year: 'numeric', timeZone: 'UTC' });
|
|
225
|
+
const monthName = new Intl.DateTimeFormat(loc, { month: 'long', timeZone: 'UTC' });
|
|
226
|
+
const monthShort = new Intl.DateTimeFormat(loc, { month: 'short', timeZone: 'UTC' });
|
|
227
|
+
const yearFmt = new Intl.DateTimeFormat(loc, { year: 'numeric', timeZone: 'UTC' });
|
|
228
|
+
const minY = this.min ? +this.min.slice(0, 4) : -Infinity;
|
|
229
|
+
const maxY = this.max ? +this.max.slice(0, 4) : Infinity;
|
|
230
|
+
const id = `cal-${this._start}`;
|
|
231
|
+
const chevron = html `<svg viewBox="0 0 24 24" width=".9em" height=".9em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style=${this.view === 'days' ? '' : 'rotate: 180deg'}><path d="M6 9l6 6 6-6"/></svg>`;
|
|
232
|
+
if (this.view === 'months' || this.view === 'years') {
|
|
233
|
+
const years = this.view === 'years';
|
|
234
|
+
const base = years ? Math.floor(fy / 10) * 10 - 1 : fy;
|
|
235
|
+
const cells = Array.from({ length: 12 }, (_, i) => years ? base + i : i);
|
|
236
|
+
const title = years ? `${yearFmt.format(new Date(Date.UTC(base, 0, 1)))} – ${yearFmt.format(new Date(Date.UTC(base + 11, 0, 1)))}` : yearFmt.format(focus);
|
|
237
|
+
const prevDis = years ? base - 1 < minY : fy - 1 < minY;
|
|
238
|
+
const nextDis = years ? base + 12 > maxY : fy + 1 > maxY;
|
|
239
|
+
const step = years ? 120 : 12;
|
|
240
|
+
const curY = new Date().getFullYear();
|
|
241
|
+
const curM = new Date().getMonth();
|
|
242
|
+
return html `<div class="pm-calendar" part="base" data-view=${this.view}>
|
|
243
|
+
<div class="pm-calendar-head">
|
|
244
|
+
<button type="button" class="pm-calendar-title" id=${id} aria-live="polite" ?disabled=${years}
|
|
245
|
+
aria-label=${years ? title : `${title}, choose year`} @click=${() => this.#setView('years')}>${title}${years ? nothing : chevron}</button>
|
|
246
|
+
<span class="nav">
|
|
247
|
+
<button type="button" aria-label=${years ? 'Previous years' : 'Previous year'} ?disabled=${prevDis} @click=${() => { this._focus = this.#clamp(toISODate(addMonths(focus, -step))); }}>${ARROW(false)}</button>
|
|
248
|
+
<button type="button" aria-label=${years ? 'Next years' : 'Next year'} ?disabled=${nextDis} @click=${() => { this._focus = this.#clamp(toISODate(addMonths(focus, step))); }}>${ARROW(true)}</button>
|
|
249
|
+
</span>
|
|
250
|
+
</div>
|
|
251
|
+
<div class="pm-calendar-picker" role="grid" aria-labelledby=${id} @keydown=${this.#onPickerKey}>
|
|
252
|
+
${[0, 1, 2, 3].map((r) => html `<div role="row">${cells.slice(r * 3, r * 3 + 3).map((c) => {
|
|
253
|
+
const isFocus = years ? c === fy : c === focus.getUTCMonth();
|
|
254
|
+
const disabled = years ? c < minY || c > maxY
|
|
255
|
+
: (!!this.min && toISODate(new Date(Date.UTC(fy, c + 1, 0))) < this.min) || (!!this.max && toISODate(new Date(Date.UTC(fy, c, 1))) > this.max);
|
|
256
|
+
const sel = this.value.split('/').filter(Boolean).some((v) => years ? +v.slice(0, 4) === c : +v.slice(0, 4) === fy && +v.slice(5, 7) - 1 === c);
|
|
257
|
+
const current = years ? c === curY : fy === curY && c === curM;
|
|
258
|
+
const label = years ? yearFmt.format(new Date(Date.UTC(c, 0, 1))) : monthShort.format(new Date(Date.UTC(fy, c, 1)));
|
|
259
|
+
return html `<span role="gridcell" class="pm-calendar-cell" tabindex=${isFocus ? 0 : -1} aria-selected=${sel ? 'true' : 'false'}
|
|
260
|
+
aria-disabled=${disabled ? 'true' : nothing} aria-current=${current ? 'date' : nothing} ?data-today=${current}
|
|
261
|
+
aria-label=${years ? label : monthYear.format(new Date(Date.UTC(fy, c, 1)))}
|
|
262
|
+
@click=${() => { if (disabled)
|
|
263
|
+
return; if (years)
|
|
264
|
+
this.#pickYear(c);
|
|
265
|
+
else
|
|
266
|
+
this.#pickMonth(c); }}
|
|
267
|
+
@keydown=${(e) => { if ((e.key === 'Enter' || e.key === ' ') && !disabled) {
|
|
268
|
+
e.preventDefault();
|
|
269
|
+
if (years)
|
|
270
|
+
this.#pickYear(c);
|
|
271
|
+
else
|
|
272
|
+
this.#pickMonth(c);
|
|
273
|
+
} }}>${label}</span>`;
|
|
274
|
+
})}</div>`)}
|
|
275
|
+
</div>
|
|
276
|
+
</div>`;
|
|
277
|
+
}
|
|
278
|
+
const title = count === 1 ? monthYear.format(firsts[0]) : `${monthYear.format(firsts[0])} – ${monthYear.format(lastFirst)}`;
|
|
279
|
+
const prevMonthEnd = toISODate(addDays(firsts[0], -1));
|
|
280
|
+
const nextMonthStart = toISODate(addMonths(lastFirst, 1));
|
|
281
|
+
return html `<div class="pm-calendar" part="base" data-view="days">
|
|
282
|
+
<div class="pm-calendar-head">
|
|
283
|
+
<button type="button" class="pm-calendar-title" id=${id} aria-live="polite" aria-label=${`${title}, choose month and year`}
|
|
284
|
+
@click=${() => this.#setView('months')}>${title}${chevron}</button>
|
|
285
|
+
<span class="nav">
|
|
286
|
+
<button type="button" aria-label="Previous month" ?disabled=${!!this.min && prevMonthEnd < this.min} @click=${() => this.#shift(-1)}>${ARROW(false)}</button>
|
|
287
|
+
<button type="button" aria-label="Next month" ?disabled=${!!this.max && nextMonthStart > this.max} @click=${() => this.#shift(1)}>${ARROW(true)}</button>
|
|
288
|
+
</span>
|
|
289
|
+
</div>
|
|
290
|
+
<div class="months">${firsts.map((first, i) => html `<div class="month">
|
|
291
|
+
${count > 1 ? html `<div class="month-name" id=${`${id}-${i}`}>${monthName.format(first)}</div>` : nothing}
|
|
292
|
+
${this.#monthGrid(first, loc, count > 1 ? `${id}-${i}` : id)}</div>`)}</div>
|
|
293
|
+
</div>`;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
defineElement('pm-calendar', PmCalendar);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Card container that renders the active surface style.
|
|
5
|
+
* @tag pm-card
|
|
6
|
+
* @slot media - Full-bleed image/video at the top.
|
|
7
|
+
* @slot header - Custom header (overrides heading/description).
|
|
8
|
+
* @slot - Body.
|
|
9
|
+
* @slot footer - Actions.
|
|
10
|
+
* @csspart base - The card container.
|
|
11
|
+
* @example <pm-card heading="Usage" description="Last 30 days" surface="glass">…</pm-card>
|
|
12
|
+
*/
|
|
13
|
+
export declare class PmCard extends PmElement {
|
|
14
|
+
static componentName: string;
|
|
15
|
+
static styles: import("lit").CSSResult[];
|
|
16
|
+
static properties: PropertyDeclarations;
|
|
17
|
+
heading?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
size?: 'sm' | 'md';
|
|
20
|
+
/** Hover and press feedback for cards that act as one big link or button. */
|
|
21
|
+
interactive?: boolean;
|
|
22
|
+
render(): import("lit").TemplateResult<1>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { PmElement, defineElement } from '../base.js';
|
|
4
|
+
import surfaceCss from '../styles/surface.js';
|
|
5
|
+
import cardCss from '../styles/card.js';
|
|
6
|
+
/**
|
|
7
|
+
* Card container that renders the active surface style.
|
|
8
|
+
* @tag pm-card
|
|
9
|
+
* @slot media - Full-bleed image/video at the top.
|
|
10
|
+
* @slot header - Custom header (overrides heading/description).
|
|
11
|
+
* @slot - Body.
|
|
12
|
+
* @slot footer - Actions.
|
|
13
|
+
* @csspart base - The card container.
|
|
14
|
+
* @example <pm-card heading="Usage" description="Last 30 days" surface="glass">…</pm-card>
|
|
15
|
+
*/
|
|
16
|
+
export class PmCard extends PmElement {
|
|
17
|
+
static { this.componentName = 'card'; }
|
|
18
|
+
static { this.styles = [...PmElement.styles, surfaceCss, cardCss, css `:host { display: block; } .pm-card { block-size: 100%; }`]; }
|
|
19
|
+
static { this.properties = {
|
|
20
|
+
heading: {},
|
|
21
|
+
description: {},
|
|
22
|
+
size: { reflect: true },
|
|
23
|
+
interactive: { type: Boolean, reflect: true },
|
|
24
|
+
}; }
|
|
25
|
+
render() {
|
|
26
|
+
const hasMedia = this.querySelector(':scope > [slot="media"]');
|
|
27
|
+
const hasFooter = this.querySelector(':scope > [slot="footer"]');
|
|
28
|
+
const hasHeader = this.querySelector(':scope > [slot="header"]');
|
|
29
|
+
return html `<article part="base" class="pm-card" data-size=${ifDefined(this.size)} ?data-interactive=${this.interactive}>
|
|
30
|
+
${hasMedia ? html `<div class="pm-card-media"><slot name="media"></slot></div>` : nothing}
|
|
31
|
+
${hasHeader
|
|
32
|
+
? html `<header><slot name="header"></slot></header>`
|
|
33
|
+
: this.heading || this.description
|
|
34
|
+
? html `<header>
|
|
35
|
+
${this.heading ? html `<div class="pm-card-title" part="title">${this.heading}</div>` : nothing}
|
|
36
|
+
${this.description ? html `<p class="pm-card-description" part="description">${this.description}</p>` : nothing}
|
|
37
|
+
</header>`
|
|
38
|
+
: nothing}
|
|
39
|
+
<slot></slot>
|
|
40
|
+
${hasFooter ? html `<footer part="footer"><slot name="footer"></slot></footer>` : nothing}
|
|
41
|
+
</article>`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
defineElement('pm-card', PmCard);
|