@timmo001/groundwork-ui 0.9.21 → 0.9.23

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.
@@ -629,7 +629,7 @@
629
629
  {
630
630
  "kind": "variable",
631
631
  "name": "fieldStyles",
632
- "default": "css` :where(gw-input, gw-select, gw-switch, gw-checkbox) { display: flex; flex-direction: column; gap: var(--gw-space-2); font-family: var(--gw-font-sans); color: var(--gw-color-text-primary); } :where(gw-input, gw-select) .gw-field-heading { display: flex; gap: var(--gw-space-1); align-items: center; } :where(gw-input, gw-select) .gw-field-heading > label { font-size: var(--gw-font-size-s); font-weight: var(--gw-font-weight-strong); color: var(--gw-color-text-strong); } /* The (i) button by the label that opens a field's longer help */ :where(gw-input, gw-select) .gw-info { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; padding: 0; color: var(--gw-color-text-secondary); cursor: pointer; background: none; border: 0; border-radius: var(--gw-radius-pill); transition: color var(--gw-motion-fast) var(--gw-motion-easing), background-color var(--gw-motion-fast) var(--gw-motion-easing); } :where(gw-input, gw-select) .gw-info:hover { color: var(--gw-color-text-strong); background: var(--gw-color-fill-neutral-hovered); } :where(gw-input, gw-select) .gw-info:focus-visible { outline: var(--gw-focus-width) solid var(--gw-color-focus); outline-offset: var(--gw-focus-offset); } :where(gw-input, gw-select) .gw-info[hidden] { display: none; } :where(gw-input, gw-select) .gw-info > .icon { width: 1rem; height: 1rem; fill: currentColor; } /* Sizes run xs to xl through --gw-field-scale, around 1 for medium, and the control's height follows the theme's density too */ :where(gw-input, gw-select)[size=\"xs\"] { --gw-field-scale: 0.6; } :where(gw-input, gw-select)[size=\"small\"] { --gw-field-scale: 0.8; } :where(gw-input, gw-select)[size=\"large\"] { --gw-field-scale: 1.2; } :where(gw-input, gw-select)[size=\"xl\"] { --gw-field-scale: 1.4; } :where(gw-input, gw-select) :where(input, .gw-select-trigger) { --gw-field-size: var(--gw-field-scale, 1); --gw-icon-size: calc( 1.25rem * var(--gw-field-size) * var(--gw-control-scale, 1) ); width: 100%; min-height: calc( 2.5rem * var(--gw-field-size) * var(--gw-control-scale, 1) ); padding: 0 calc(var(--gw-space-3) * var(--gw-field-size)); font: inherit; font-size: calc(var(--gw-font-size-s) * var(--gw-field-size)); color: var(--gw-color-text-strong); background: var(--gw-color-surface-lower); border: var(--gw-border-width) solid var(--gw-color-border-normal); border-radius: var(--gw-radius-control); transition: border-color var(--gw-motion-fast) var(--gw-motion-easing); } /* An icon inside the field, before the text, with the text moved clear of it */ gw-input .gw-input-control { position: relative; display: flex; align-items: center; } gw-input .gw-input-control > .icon { position: absolute; inset-inline-start: calc(var(--gw-space-3) * var(--gw-field-scale, 1)); width: calc(1.125rem * var(--gw-field-scale, 1)); height: calc(1.125rem * var(--gw-field-scale, 1)); color: var(--gw-color-text-secondary); pointer-events: none; fill: currentColor; } gw-input .gw-input-control > .icon[hidden] { display: none; } gw-input .gw-input-control > .icon:not([hidden]) + input { padding-inline-start: calc( (var(--gw-space-3) * 2 + 1.125rem) * var(--gw-field-scale, 1) ); } /* The trigger shows the chosen option, with its icon, and a chevron with room around it that turns over while the list is open */ gw-select .gw-select-trigger { display: flex; gap: calc(var(--gw-space-2) * var(--gw-field-size)); align-items: center; padding-inline-end: calc(var(--gw-space-3) * var(--gw-field-size)); text-align: start; cursor: pointer; } gw-select .gw-select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* With an inline label the select sits among toolbar controls, so it's a pill that fits its content, like the toggles and buttons beside it */ gw-select[inline-label] { display: inline-flex; } gw-select[inline-label] .gw-select-trigger { width: auto; padding-inline: calc(var(--gw-space-4) * var(--gw-field-size)) calc(var(--gw-space-3) * var(--gw-field-size)); border-radius: var(--gw-radius-pill); } /* An inline label reads as a quiet prefix to the value */ gw-select .gw-select-inline-label { flex: none; color: var(--gw-color-text-secondary); } gw-select .gw-select-inline-label[hidden] { display: none; } gw-select .gw-select-value[data-placeholder] { color: var(--gw-color-text-secondary); } gw-select .gw-select-trigger > .icon { flex: none; width: var(--gw-icon-size, 1.25rem); height: var(--gw-icon-size, 1.25rem); fill: currentColor; } gw-select .gw-select-trigger > .icon:last-child { color: var(--gw-color-text-secondary); transition: rotate var(--gw-motion-normal) var(--gw-motion-easing); } gw-select[open] .gw-select-trigger > .icon:last-child { rotate: 180deg; } gw-select .gw-select-trigger > .icon[hidden] { display: none; } /* The list opens under the trigger, growing from it, or as a bottom sheet sliding up on phones */ gw-select .gw-select-popup { position: fixed; inset: unset; box-sizing: border-box; max-width: calc(100vw - 12px); padding: 0; margin: 0; overflow: hidden; color: var(--gw-color-text-primary); background: var(--gw-color-surface-overlay); border: max(var(--gw-border-width), 1px) solid var(--gw-color-border-normal); border-radius: var(--gw-radius-panel); box-shadow: var(--gw-shadow-l); opacity: 0; scale: 1 0.96; transform-origin: top; transition: opacity var(--gw-motion-fast) var(--gw-motion-easing), scale var(--gw-motion-normal) var(--gw-motion-easing), translate var(--gw-motion-normal) var(--gw-motion-easing), display var(--gw-motion-normal) allow-discrete, overlay var(--gw-motion-normal) allow-discrete; } gw-select .gw-select-popup[data-placement=\"above\"] { transform-origin: bottom; } gw-select .gw-select-popup:popover-open { opacity: 1; scale: 1; } @starting-style { gw-select .gw-select-popup:popover-open { opacity: 0; scale: 1 0.96; } } gw-select .gw-select-popup[data-placement=\"sheet\"] { inset: auto 0 0; width: 100%; max-width: none; padding-block-end: env(safe-area-inset-bottom); border-end-start-radius: 0; border-end-end-radius: 0; scale: 1; translate: 0 100%; --gw-option-list-height: 60vh; } gw-select .gw-select-popup[data-placement=\"sheet\"]:popover-open { translate: 0 0; } @starting-style { gw-select .gw-select-popup[data-placement=\"sheet\"]:popover-open { translate: 0 100%; } } gw-select .gw-select-popup[data-placement=\"sheet\"]::backdrop { background: rgb(0 0 0 / 40%); } /* With multiple, a full-width Clear under the list empties the choice */ gw-select .gw-select-clear { display: block; width: 100%; min-height: 2.5rem; padding: 0 var(--gw-space-3); font: inherit; font-size: var(--gw-font-size-s); font-weight: var(--gw-font-weight-strong); color: var(--gw-color-text-secondary); cursor: pointer; background: none; border: 0; border-block-start: var(--gw-border-width) solid var(--gw-color-border-quiet); transition: color var(--gw-motion-fast) var(--gw-motion-easing), background-color var(--gw-motion-fast) var(--gw-motion-easing); } gw-select .gw-select-clear:hover { color: var(--gw-color-text-strong); background: var(--gw-color-fill-neutral-hovered); } gw-select .gw-select-clear:focus-visible { outline: var(--gw-focus-width) solid var(--gw-color-focus); outline-offset: calc(var(--gw-focus-width) * -1); } gw-select .gw-select-clear[hidden] { display: none; } :where(gw-input) .gw-input-control:focus-within > .icon { color: var(--gw-color-text-strong); } :where(gw-input, gw-select) :where(input, .gw-select-trigger):hover { border-color: var(--gw-color-border-loud); } :where(gw-input, gw-select, gw-switch, gw-checkbox) :where(input, .gw-select-trigger):focus-visible { outline: var(--gw-focus-width) solid var(--gw-color-focus); outline-offset: var(--gw-focus-offset); } :where(gw-input, gw-select) [aria-invalid=\"true\"] { border-color: var(--gw-color-border-danger); } :where(gw-input, gw-select, gw-switch, gw-checkbox) :disabled { color: var(--gw-color-text-disabled); cursor: not-allowed; } :where(gw-input, gw-select, gw-switch, gw-checkbox) .gw-hint { margin: 0; font-size: var(--gw-font-size-xs); color: var(--gw-color-text-secondary); } :where(gw-input, gw-select, gw-switch, gw-checkbox) .gw-error { margin: 0; font-size: var(--gw-font-size-xs); color: var(--gw-color-danger); } :where(gw-switch, gw-checkbox) > label { display: inline-flex; gap: var(--gw-space-3); align-items: center; font-size: var(--gw-font-size-s); cursor: pointer; } :where(gw-input, gw-switch, gw-checkbox, gw-select) .gw-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } gw-checkbox input { width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--gw-color-fill-accent-resting); } gw-switch input { position: relative; flex: none; width: 2.5rem; height: 1.5rem; margin: 0; cursor: pointer; appearance: none; background: var(--gw-color-surface-lower); border: var(--gw-border-width) solid var(--gw-color-border-loud); border-radius: var(--gw-radius-pill); transition: background-color var(--gw-motion-normal) var(--gw-motion-easing), border-color var(--gw-motion-normal) var(--gw-motion-easing); } gw-switch input::after { position: absolute; inset-block-start: 0.1875rem; inset-inline-start: 0.1875rem; width: 1rem; height: 1rem; content: \"\"; background: var(--gw-color-text-secondary); border-radius: 50%; transition: translate var(--gw-motion-normal) var(--gw-motion-easing), background-color var(--gw-motion-normal) var(--gw-motion-easing); } gw-switch input:checked { background: var(--gw-color-fill-accent-resting); border-color: transparent; } gw-switch input:checked::after { translate: 1rem 0; background: var(--gw-color-on-accent); } gw-switch input:disabled { opacity: 0.5; } `",
632
+ "default": "css` :where(gw-input, gw-select, gw-switch, gw-checkbox) { display: flex; flex-direction: column; gap: var(--gw-space-2); font-family: var(--gw-font-sans); color: var(--gw-color-text-primary); } :where(gw-input, gw-select) .gw-field-heading { display: flex; gap: var(--gw-space-1); align-items: center; } :where(gw-input, gw-select) .gw-field-heading > label { font-size: var(--gw-font-size-s); font-weight: var(--gw-font-weight-strong); color: var(--gw-color-text-strong); } /* The (i) button by the label that opens a field's longer help */ :where(gw-input, gw-select) .gw-info { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; padding: 0; color: var(--gw-color-text-secondary); cursor: pointer; background: none; border: 0; border-radius: var(--gw-radius-pill); transition: color var(--gw-motion-fast) var(--gw-motion-easing), background-color var(--gw-motion-fast) var(--gw-motion-easing); } :where(gw-input, gw-select) .gw-info:hover { color: var(--gw-color-text-strong); background: var(--gw-color-fill-neutral-hovered); } :where(gw-input, gw-select) .gw-info:focus-visible { outline: var(--gw-focus-width) solid var(--gw-color-focus); outline-offset: var(--gw-focus-offset); } :where(gw-input, gw-select) .gw-info[hidden] { display: none; } :where(gw-input, gw-select) .gw-info > .icon { width: 1rem; height: 1rem; fill: currentColor; } /* Sizes run xs to xl through --gw-field-scale, around 1 for medium, and the control's height follows the theme's density too */ :where(gw-input, gw-select)[size=\"xs\"] { --gw-field-scale: 0.6; } :where(gw-input, gw-select)[size=\"small\"] { --gw-field-scale: 0.8; } :where(gw-input, gw-select)[size=\"large\"] { --gw-field-scale: 1.2; } :where(gw-input, gw-select)[size=\"xl\"] { --gw-field-scale: 1.4; } :where(gw-input, gw-select) :where(input, .gw-select-trigger) { --gw-field-size: var(--gw-field-scale, 1); --gw-icon-size: calc( 1.25rem * var(--gw-field-size) * var(--gw-control-scale, 1) ); width: 100%; min-height: calc( 2.5rem * var(--gw-field-size) * var(--gw-control-scale, 1) ); padding: 0 calc(var(--gw-space-3) * var(--gw-field-size)); font: inherit; font-size: calc(var(--gw-font-size-s) * var(--gw-field-size)); color: var(--gw-color-text-strong); background: var(--gw-color-surface-lower); border: var(--gw-border-width) solid var(--gw-color-border-normal); border-radius: var(--gw-radius-control); transition: border-color var(--gw-motion-fast) var(--gw-motion-easing); } /* An icon inside the field, before the text, with the text moved clear of it */ gw-input .gw-input-control { position: relative; display: flex; align-items: center; } gw-input .gw-input-control > .icon { position: absolute; inset-inline-start: calc(var(--gw-space-3) * var(--gw-field-scale, 1)); width: calc(1.125rem * var(--gw-field-scale, 1)); height: calc(1.125rem * var(--gw-field-scale, 1)); color: var(--gw-color-text-secondary); pointer-events: none; fill: currentColor; } gw-input .gw-input-control > .icon[hidden] { display: none; } gw-input .gw-input-control > .icon:not([hidden]) + input { padding-inline-start: calc( (var(--gw-space-3) * 2 + 1.125rem) * var(--gw-field-scale, 1) ); } /* The trigger shows the chosen option, with its icon, and a chevron with room around it that turns over while the list is open */ gw-select .gw-select-trigger { display: flex; gap: calc(var(--gw-space-2) * var(--gw-field-size)); align-items: center; padding-inline-end: calc(var(--gw-space-3) * var(--gw-field-size)); text-align: start; cursor: pointer; } gw-select .gw-select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* With an inline label the select sits among toolbar controls, so it's a pill that fits its content, like the toggles and buttons beside it */ gw-select[inline-label] { display: inline-flex; } gw-select[inline-label] .gw-select-trigger { width: auto; padding-inline: calc(var(--gw-space-4) * var(--gw-field-size)) calc(var(--gw-space-3) * var(--gw-field-size)); border-radius: var(--gw-radius-pill); } /* An inline label reads as a quiet prefix to the value */ gw-select .gw-select-inline-label { flex: none; color: var(--gw-color-text-secondary); } gw-select .gw-select-inline-label[hidden] { display: none; } gw-select .gw-select-value[data-placeholder] { color: var(--gw-color-text-secondary); } gw-select .gw-select-trigger > .icon { flex: none; width: var(--gw-icon-size, 1.25rem); height: var(--gw-icon-size, 1.25rem); fill: currentColor; } gw-select .gw-select-trigger > .icon:last-child { color: var(--gw-color-text-secondary); transition: rotate var(--gw-motion-normal) var(--gw-motion-easing); } gw-select[open] .gw-select-trigger > .icon:last-child { rotate: 180deg; } gw-select .gw-select-trigger > .icon[hidden] { display: none; } /* The list opens under the trigger, growing from it, or as a bottom sheet sliding up on phones */ gw-select .gw-select-popup { position: fixed; inset: unset; box-sizing: border-box; max-width: calc(100vw - 12px); padding: 0; margin: 0; overflow: hidden; color: var(--gw-color-text-primary); background: var(--gw-color-surface-overlay); border: max(var(--gw-border-width), 1px) solid var(--gw-color-border-normal); border-radius: var(--gw-radius-panel); box-shadow: var(--gw-shadow-l); opacity: 0; scale: 1 0.96; transform-origin: top; transition: opacity var(--gw-motion-fast) var(--gw-motion-easing), scale var(--gw-motion-normal) var(--gw-motion-easing), translate var(--gw-motion-normal) var(--gw-motion-easing), display var(--gw-motion-normal) allow-discrete, overlay var(--gw-motion-normal) allow-discrete; } gw-select .gw-select-popup[data-placement=\"above\"] { transform-origin: bottom; } gw-select .gw-select-popup:popover-open { opacity: 1; scale: 1; } @starting-style { gw-select .gw-select-popup:popover-open { opacity: 0; scale: 1 0.96; } } gw-select .gw-select-popup[data-placement=\"sheet\"] { inset: auto 0 0; width: 100%; max-width: none; padding-block-end: env(safe-area-inset-bottom); border-end-start-radius: 0; border-end-end-radius: 0; scale: 1; translate: 0 100%; --gw-option-list-height: 60vh; } gw-select .gw-select-popup[data-placement=\"sheet\"]:popover-open { translate: 0 0; } @starting-style { gw-select .gw-select-popup[data-placement=\"sheet\"]:popover-open { translate: 0 100%; } } gw-select .gw-select-popup[data-placement=\"sheet\"]::backdrop { background: rgb(0 0 0 / 40%); } /* With multiple, a full-width Clear under the list empties the choice */ gw-select .gw-select-clear { display: block; width: 100%; min-height: 2.5rem; padding: 0 var(--gw-space-3); font: inherit; font-size: var(--gw-font-size-s); font-weight: var(--gw-font-weight-strong); color: var(--gw-color-text-secondary); cursor: pointer; background: none; border: 0; border-block-start: var(--gw-border-width) solid var(--gw-color-border-quiet); transition: color var(--gw-motion-fast) var(--gw-motion-easing), background-color var(--gw-motion-fast) var(--gw-motion-easing); } gw-select .gw-select-clear:hover { color: var(--gw-color-text-strong); background: var(--gw-color-fill-neutral-hovered); } gw-select .gw-select-clear:focus-visible { outline: var(--gw-focus-width) solid var(--gw-color-focus); outline-offset: calc(var(--gw-focus-width) * -1); } gw-select .gw-select-clear[hidden] { display: none; } :where(gw-input) .gw-input-control:focus-within > .icon { color: var(--gw-color-text-strong); } :where(gw-input, gw-select) :where(input, .gw-select-trigger):hover { border-color: var(--gw-color-border-loud); } :where(gw-input, gw-select, gw-switch, gw-checkbox) :where(input, .gw-select-trigger):focus-visible { outline: var(--gw-focus-width) solid var(--gw-color-focus); outline-offset: var(--gw-focus-offset); } :where(gw-input, gw-select) [aria-invalid=\"true\"] { border-color: var(--gw-color-border-danger); } :where(gw-input, gw-select, gw-switch, gw-checkbox) :disabled { color: var(--gw-color-text-disabled); cursor: not-allowed; } :where(gw-input, gw-select, gw-switch, gw-checkbox) .gw-hint { margin: 0; font-size: var(--gw-font-size-xs); color: var(--gw-color-text-secondary); } :where(gw-input, gw-select, gw-switch, gw-checkbox) .gw-error { margin: 0; font-size: var(--gw-font-size-xs); color: var(--gw-color-danger); } :where(gw-switch, gw-checkbox) > label { display: inline-flex; gap: var(--gw-space-3); align-items: center; font-size: var(--gw-font-size-s); cursor: pointer; } :where(gw-input, gw-switch, gw-checkbox, gw-select) .gw-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } gw-checkbox input { width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--gw-color-fill-accent-resting); } gw-switch input { position: relative; flex: none; width: 2.5rem; height: 1.5rem; margin: 0; cursor: pointer; appearance: none; background: var(--gw-color-surface-lower); border: var(--gw-border-width) solid var(--gw-color-border-loud); border-radius: var(--gw-radius-pill); transition: background-color var(--gw-motion-normal) var(--gw-motion-easing), border-color var(--gw-motion-normal) var(--gw-motion-easing); } gw-switch input::after { position: absolute; inset-block-start: 0.1875rem; inset-inline-start: 0.1875rem; width: 1rem; height: 1rem; content: \"\"; background: var(--gw-color-text-secondary); border-radius: 50%; transition: translate var(--gw-motion-normal) var(--gw-motion-easing), background-color var(--gw-motion-normal) var(--gw-motion-easing); } gw-switch input:checked { background: var(--gw-color-fill-accent-resting); border-color: transparent; } gw-switch input:checked::after { translate: 1rem 0; background: var(--gw-color-on-accent); } gw-switch input:disabled { opacity: 0.5; } gw-range { display: flex; flex-direction: column; gap: var(--gw-space-2); min-width: 0; font-family: var(--gw-font-sans); color: var(--gw-color-text-primary); } gw-range > label { font-size: var(--gw-font-size-s); font-weight: var(--gw-font-weight-strong); color: var(--gw-color-text-strong); } gw-range .gw-range-control { position: relative; display: block; } gw-range input { display: block; width: 100%; margin: 0; accent-color: var(--gw-color-fill-accent-resting); cursor: pointer; } gw-range input:focus-visible { outline: var(--gw-focus-width) solid var(--gw-color-focus); outline-offset: var(--gw-focus-offset); } gw-range input:disabled { cursor: not-allowed; opacity: 0.5; } /* The value above the thumb while it's held */ gw-range .gw-range-bubble { position: absolute; bottom: calc(100% + var(--gw-space-1)); padding: var(--gw-space-1) var(--gw-space-2); font-size: var(--gw-font-size-xs); font-variant-numeric: tabular-nums; color: var(--gw-color-on-accent); white-space: nowrap; pointer-events: none; background: var(--gw-color-fill-accent-resting); border-radius: var(--gw-radius-control); box-shadow: var(--gw-shadow-s); translate: -50% 0; } gw-range .gw-range-bubble[hidden] { display: none; } gw-range .gw-hint { margin: 0; font-size: var(--gw-font-size-xs); color: var(--gw-color-text-secondary); } gw-range .gw-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } `",
633
633
  "description": "Field components render their native control in light DOM, never in a\nshadow root: password managers and `<label for>` can't reach across one,\nand a form only submits controls it can see. Their styles are adopted into\nwhichever document or shadow root they sit in."
634
634
  },
635
635
  {
@@ -9837,7 +9837,7 @@
9837
9837
  "declarations": [
9838
9838
  {
9839
9839
  "kind": "class",
9840
- "description": "A labeled native `<input>`, with an optional hint and error.",
9840
+ "description": "A labeled native `<input>`, with an optional hint and error. Enter submits\nits form when the form's submit button is a `gw-button`, as it would with a\nnative one.",
9841
9841
  "name": "GwInput",
9842
9842
  "cssProperties": [
9843
9843
  {
@@ -14592,6 +14592,592 @@
14592
14592
  }
14593
14593
  ]
14594
14594
  },
14595
+ {
14596
+ "kind": "javascript-module",
14597
+ "path": "src/gw-range.ts",
14598
+ "declarations": [
14599
+ {
14600
+ "kind": "class",
14601
+ "description": "A labeled native range slider. While it's pressed or dragged, a bubble\nabove the thumb shows the value, so a slider without a readout beside it\nstill says where it is. The native `input` and `change` events bubble out\nas usual.",
14602
+ "name": "GwRange",
14603
+ "cssProperties": [
14604
+ {
14605
+ "description": "The thumb's size. Defaults to 1rem.",
14606
+ "name": "--gw-range-thumb"
14607
+ }
14608
+ ],
14609
+ "members": [
14610
+ {
14611
+ "kind": "field",
14612
+ "name": "properties",
14613
+ "type": {
14614
+ "text": "Properties"
14615
+ },
14616
+ "static": true,
14617
+ "default": "{ label: {}, labelHidden: { type: \"boolean\", attribute: \"label-hidden\" }, name: {}, value: { type: \"number\" }, min: { type: \"number\" }, max: { type: \"number\" }, step: { type: \"number\" }, unit: {}, hint: {}, disabled: { type: \"boolean\" }, }",
14618
+ "inheritedFrom": {
14619
+ "name": "GwElement",
14620
+ "module": "src/element.ts"
14621
+ }
14622
+ },
14623
+ {
14624
+ "kind": "field",
14625
+ "name": "label",
14626
+ "type": {
14627
+ "text": "string"
14628
+ },
14629
+ "default": "\"\""
14630
+ },
14631
+ {
14632
+ "kind": "field",
14633
+ "name": "labelHidden",
14634
+ "type": {
14635
+ "text": "boolean"
14636
+ },
14637
+ "description": "Keeps the label for assistive technology but hides it.",
14638
+ "default": "false"
14639
+ },
14640
+ {
14641
+ "kind": "field",
14642
+ "name": "name",
14643
+ "type": {
14644
+ "text": "string"
14645
+ },
14646
+ "default": "\"\""
14647
+ },
14648
+ {
14649
+ "kind": "field",
14650
+ "name": "value",
14651
+ "type": {
14652
+ "text": "number"
14653
+ },
14654
+ "default": "0"
14655
+ },
14656
+ {
14657
+ "kind": "field",
14658
+ "name": "min",
14659
+ "type": {
14660
+ "text": "number"
14661
+ },
14662
+ "default": "0"
14663
+ },
14664
+ {
14665
+ "kind": "field",
14666
+ "name": "max",
14667
+ "type": {
14668
+ "text": "number"
14669
+ },
14670
+ "default": "100"
14671
+ },
14672
+ {
14673
+ "kind": "field",
14674
+ "name": "step",
14675
+ "type": {
14676
+ "text": "number"
14677
+ },
14678
+ "default": "1"
14679
+ },
14680
+ {
14681
+ "kind": "field",
14682
+ "name": "unit",
14683
+ "type": {
14684
+ "text": "string"
14685
+ },
14686
+ "description": "Shown after the value, such as `%`.",
14687
+ "default": "\"\""
14688
+ },
14689
+ {
14690
+ "kind": "field",
14691
+ "name": "hint",
14692
+ "type": {
14693
+ "text": "string"
14694
+ },
14695
+ "default": "\"\""
14696
+ },
14697
+ {
14698
+ "kind": "field",
14699
+ "name": "disabled",
14700
+ "type": {
14701
+ "text": "boolean"
14702
+ },
14703
+ "default": "false"
14704
+ },
14705
+ {
14706
+ "kind": "field",
14707
+ "name": "#id",
14708
+ "privacy": "private",
14709
+ "readonly": true
14710
+ },
14711
+ {
14712
+ "kind": "field",
14713
+ "name": "#label",
14714
+ "privacy": "private",
14715
+ "readonly": true
14716
+ },
14717
+ {
14718
+ "kind": "field",
14719
+ "name": "#input",
14720
+ "privacy": "private",
14721
+ "readonly": true
14722
+ },
14723
+ {
14724
+ "kind": "field",
14725
+ "name": "#bubble",
14726
+ "privacy": "private",
14727
+ "readonly": true
14728
+ },
14729
+ {
14730
+ "kind": "field",
14731
+ "name": "#hint",
14732
+ "privacy": "private",
14733
+ "readonly": true
14734
+ },
14735
+ {
14736
+ "kind": "method",
14737
+ "name": "#text",
14738
+ "privacy": "private",
14739
+ "return": {
14740
+ "type": {
14741
+ "text": "string"
14742
+ }
14743
+ },
14744
+ "parameters": [
14745
+ {
14746
+ "name": "value",
14747
+ "type": {
14748
+ "text": "number"
14749
+ }
14750
+ }
14751
+ ]
14752
+ },
14753
+ {
14754
+ "kind": "method",
14755
+ "name": "#placeBubble",
14756
+ "privacy": "private"
14757
+ },
14758
+ {
14759
+ "kind": "field",
14760
+ "name": "#release",
14761
+ "privacy": "private",
14762
+ "readonly": true
14763
+ },
14764
+ {
14765
+ "kind": "method",
14766
+ "name": "create",
14767
+ "privacy": "protected",
14768
+ "parameters": [
14769
+ {
14770
+ "name": "root",
14771
+ "type": {
14772
+ "text": "HTMLElement"
14773
+ }
14774
+ }
14775
+ ],
14776
+ "description": "Builds the shadow root's content once, on first connection.",
14777
+ "inheritedFrom": {
14778
+ "name": "GwElement",
14779
+ "module": "src/element.ts"
14780
+ }
14781
+ },
14782
+ {
14783
+ "kind": "method",
14784
+ "name": "update",
14785
+ "privacy": "protected",
14786
+ "parameters": [
14787
+ {
14788
+ "name": "_changed",
14789
+ "type": {
14790
+ "text": "ReadonlySet<string>"
14791
+ }
14792
+ }
14793
+ ],
14794
+ "description": "Sets what the changed properties affect.",
14795
+ "inheritedFrom": {
14796
+ "name": "GwElement",
14797
+ "module": "src/element.ts"
14798
+ }
14799
+ },
14800
+ {
14801
+ "kind": "field",
14802
+ "name": "shadow",
14803
+ "type": {
14804
+ "text": "boolean"
14805
+ },
14806
+ "static": true,
14807
+ "default": "false",
14808
+ "description": "Whether to attach a shadow root. Light DOM elements set this false.",
14809
+ "inheritedFrom": {
14810
+ "name": "GwElement",
14811
+ "module": "src/element.ts"
14812
+ }
14813
+ },
14814
+ {
14815
+ "kind": "field",
14816
+ "name": "styles",
14817
+ "type": {
14818
+ "text": "readonly CSSStyleSheet[]"
14819
+ },
14820
+ "static": true,
14821
+ "default": "[]",
14822
+ "inheritedFrom": {
14823
+ "name": "GwElement",
14824
+ "module": "src/element.ts"
14825
+ }
14826
+ },
14827
+ {
14828
+ "kind": "field",
14829
+ "name": "shadowRootOptions",
14830
+ "type": {
14831
+ "text": "ShadowRootInit"
14832
+ },
14833
+ "static": true,
14834
+ "default": "{ mode: \"open\" }",
14835
+ "description": "How the shadow root is attached.",
14836
+ "inheritedFrom": {
14837
+ "name": "GwElement",
14838
+ "module": "src/element.ts"
14839
+ }
14840
+ },
14841
+ {
14842
+ "kind": "method",
14843
+ "name": "define",
14844
+ "static": true,
14845
+ "parameters": [
14846
+ {
14847
+ "name": "tag",
14848
+ "type": {
14849
+ "text": "string"
14850
+ }
14851
+ }
14852
+ ],
14853
+ "description": "Adds the property accessors, then defines the element.",
14854
+ "inheritedFrom": {
14855
+ "name": "GwElement",
14856
+ "module": "src/element.ts"
14857
+ }
14858
+ },
14859
+ {
14860
+ "kind": "field",
14861
+ "name": "#values",
14862
+ "privacy": "private",
14863
+ "readonly": true,
14864
+ "default": "new Map<string, PropertyValue>()",
14865
+ "inheritedFrom": {
14866
+ "name": "GwElement",
14867
+ "module": "src/element.ts"
14868
+ }
14869
+ },
14870
+ {
14871
+ "kind": "field",
14872
+ "name": "#defaults",
14873
+ "privacy": "private",
14874
+ "readonly": true,
14875
+ "default": "new Map<string, PropertyValue>()",
14876
+ "inheritedFrom": {
14877
+ "name": "GwElement",
14878
+ "module": "src/element.ts"
14879
+ }
14880
+ },
14881
+ {
14882
+ "kind": "field",
14883
+ "name": "#changed",
14884
+ "privacy": "private",
14885
+ "readonly": true,
14886
+ "default": "new Set<string>()",
14887
+ "inheritedFrom": {
14888
+ "name": "GwElement",
14889
+ "module": "src/element.ts"
14890
+ }
14891
+ },
14892
+ {
14893
+ "kind": "field",
14894
+ "name": "#unreflected",
14895
+ "privacy": "private",
14896
+ "readonly": true,
14897
+ "default": "new Set<string>()",
14898
+ "inheritedFrom": {
14899
+ "name": "GwElement",
14900
+ "module": "src/element.ts"
14901
+ }
14902
+ },
14903
+ {
14904
+ "kind": "field",
14905
+ "name": "#created",
14906
+ "privacy": "private",
14907
+ "type": {
14908
+ "text": "boolean"
14909
+ },
14910
+ "default": "false",
14911
+ "inheritedFrom": {
14912
+ "name": "GwElement",
14913
+ "module": "src/element.ts"
14914
+ }
14915
+ },
14916
+ {
14917
+ "kind": "field",
14918
+ "name": "#queued",
14919
+ "privacy": "private",
14920
+ "type": {
14921
+ "text": "boolean"
14922
+ },
14923
+ "default": "false",
14924
+ "inheritedFrom": {
14925
+ "name": "GwElement",
14926
+ "module": "src/element.ts"
14927
+ }
14928
+ },
14929
+ {
14930
+ "kind": "field",
14931
+ "name": "#pending",
14932
+ "privacy": "private",
14933
+ "type": {
14934
+ "text": "Promise<void> | undefined"
14935
+ },
14936
+ "inheritedFrom": {
14937
+ "name": "GwElement",
14938
+ "module": "src/element.ts"
14939
+ }
14940
+ },
14941
+ {
14942
+ "kind": "field",
14943
+ "name": "#reflecting",
14944
+ "privacy": "private",
14945
+ "type": {
14946
+ "text": "boolean"
14947
+ },
14948
+ "default": "false",
14949
+ "inheritedFrom": {
14950
+ "name": "GwElement",
14951
+ "module": "src/element.ts"
14952
+ }
14953
+ },
14954
+ {
14955
+ "kind": "field",
14956
+ "name": "#resolveUpdated",
14957
+ "privacy": "private",
14958
+ "type": {
14959
+ "text": "() => void"
14960
+ },
14961
+ "inheritedFrom": {
14962
+ "name": "GwElement",
14963
+ "module": "src/element.ts"
14964
+ }
14965
+ },
14966
+ {
14967
+ "kind": "field",
14968
+ "name": "#updated",
14969
+ "privacy": "private",
14970
+ "readonly": true,
14971
+ "default": "new Promise<void>((resolve) => { this.#resolveUpdated = resolve; })",
14972
+ "inheritedFrom": {
14973
+ "name": "GwElement",
14974
+ "module": "src/element.ts"
14975
+ }
14976
+ },
14977
+ {
14978
+ "kind": "field",
14979
+ "name": "renderRoot",
14980
+ "type": {
14981
+ "text": "ShadowRoot | HTMLElement"
14982
+ },
14983
+ "readonly": true,
14984
+ "description": "The shadow root, or the element itself for a light DOM element.",
14985
+ "inheritedFrom": {
14986
+ "name": "GwElement",
14987
+ "module": "src/element.ts"
14988
+ }
14989
+ },
14990
+ {
14991
+ "kind": "field",
14992
+ "name": "#own",
14993
+ "privacy": "private",
14994
+ "type": {
14995
+ "text": "typeof GwElement"
14996
+ },
14997
+ "readonly": true,
14998
+ "description": "The element's own class, for its static properties and styles.",
14999
+ "default": "new.target",
15000
+ "inheritedFrom": {
15001
+ "name": "GwElement",
15002
+ "module": "src/element.ts"
15003
+ }
15004
+ },
15005
+ {
15006
+ "kind": "field",
15007
+ "name": "updateComplete",
15008
+ "description": "Resolves once the pending update has run, or the first one before it connects.",
15009
+ "readonly": true,
15010
+ "inheritedFrom": {
15011
+ "name": "GwElement",
15012
+ "module": "src/element.ts"
15013
+ }
15014
+ },
15015
+ {
15016
+ "kind": "method",
15017
+ "name": "defaultOf",
15018
+ "privacy": "protected",
15019
+ "parameters": [
15020
+ {
15021
+ "name": "name",
15022
+ "type": {
15023
+ "text": "string"
15024
+ }
15025
+ }
15026
+ ],
15027
+ "description": "The value a property returns to when its attribute is removed. Defaults\nto the value it was given in the constructor.",
15028
+ "inheritedFrom": {
15029
+ "name": "GwElement",
15030
+ "module": "src/element.ts"
15031
+ }
15032
+ },
15033
+ {
15034
+ "kind": "method",
15035
+ "name": "requestUpdate",
15036
+ "parameters": [
15037
+ {
15038
+ "name": "names",
15039
+ "type": {
15040
+ "text": "readonly string[]"
15041
+ }
15042
+ }
15043
+ ],
15044
+ "description": "Asks for an update with the given properties marked as changed.",
15045
+ "inheritedFrom": {
15046
+ "name": "GwElement",
15047
+ "module": "src/element.ts"
15048
+ }
15049
+ },
15050
+ {
15051
+ "kind": "method",
15052
+ "name": "#flush",
15053
+ "privacy": "private",
15054
+ "inheritedFrom": {
15055
+ "name": "GwElement",
15056
+ "module": "src/element.ts"
15057
+ }
15058
+ },
15059
+ {
15060
+ "kind": "method",
15061
+ "name": "#setProperty",
15062
+ "privacy": "private",
15063
+ "parameters": [
15064
+ {
15065
+ "name": "name",
15066
+ "type": {
15067
+ "text": "string"
15068
+ }
15069
+ },
15070
+ {
15071
+ "name": "options",
15072
+ "type": {
15073
+ "text": "PropertyOptions"
15074
+ }
15075
+ },
15076
+ {
15077
+ "name": "value",
15078
+ "type": {
15079
+ "text": "PropertyValue"
15080
+ }
15081
+ }
15082
+ ],
15083
+ "inheritedFrom": {
15084
+ "name": "GwElement",
15085
+ "module": "src/element.ts"
15086
+ }
15087
+ }
15088
+ ],
15089
+ "attributes": [
15090
+ {
15091
+ "type": {
15092
+ "text": "string"
15093
+ },
15094
+ "description": "The label, also its accessible name.",
15095
+ "name": "label"
15096
+ },
15097
+ {
15098
+ "type": {
15099
+ "text": "boolean"
15100
+ },
15101
+ "description": "Hides the label but keeps it for assistive technology.",
15102
+ "name": "label-hidden"
15103
+ },
15104
+ {
15105
+ "type": {
15106
+ "text": "string"
15107
+ },
15108
+ "description": "The form field name.",
15109
+ "name": "name"
15110
+ },
15111
+ {
15112
+ "type": {
15113
+ "text": "number"
15114
+ },
15115
+ "description": "The value.",
15116
+ "name": "value"
15117
+ },
15118
+ {
15119
+ "type": {
15120
+ "text": "number"
15121
+ },
15122
+ "description": "The lowest value. Defaults to 0.",
15123
+ "name": "min"
15124
+ },
15125
+ {
15126
+ "type": {
15127
+ "text": "number"
15128
+ },
15129
+ "description": "The highest value. Defaults to 100.",
15130
+ "name": "max"
15131
+ },
15132
+ {
15133
+ "type": {
15134
+ "text": "number"
15135
+ },
15136
+ "description": "The step between values. Defaults to 1.",
15137
+ "name": "step"
15138
+ },
15139
+ {
15140
+ "type": {
15141
+ "text": "string"
15142
+ },
15143
+ "description": "Shown after the value in the bubble and for assistive technology, such as `%`. Empty for a plain number.",
15144
+ "name": "unit"
15145
+ },
15146
+ {
15147
+ "type": {
15148
+ "text": "string"
15149
+ },
15150
+ "description": "One line of help under it.",
15151
+ "name": "hint"
15152
+ },
15153
+ {
15154
+ "type": {
15155
+ "text": "boolean"
15156
+ },
15157
+ "description": "Disables it.",
15158
+ "name": "disabled"
15159
+ }
15160
+ ],
15161
+ "superclass": {
15162
+ "name": "LightElement",
15163
+ "module": "/src/fields.js"
15164
+ },
15165
+ "tagName": "gw-range",
15166
+ "customElement": true,
15167
+ "summary": "A labeled slider in light DOM, so forms see it."
15168
+ }
15169
+ ],
15170
+ "exports": [
15171
+ {
15172
+ "kind": "js",
15173
+ "name": "GwRange",
15174
+ "declaration": {
15175
+ "name": "GwRange",
15176
+ "module": "src/gw-range.ts"
15177
+ }
15178
+ }
15179
+ ]
15180
+ },
14595
15181
  {
14596
15182
  "kind": "javascript-module",
14597
15183
  "path": "src/gw-section-title.ts",
@@ -21210,6 +21796,14 @@
21210
21796
  "module": "src/gw-popover.js"
21211
21797
  }
21212
21798
  },
21799
+ {
21800
+ "kind": "js",
21801
+ "name": "*",
21802
+ "declaration": {
21803
+ "name": "*",
21804
+ "module": "src/gw-range.js"
21805
+ }
21806
+ },
21213
21807
  {
21214
21808
  "kind": "js",
21215
21809
  "name": "*",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timmo001/groundwork-ui",
3
- "version": "0.9.21",
3
+ "version": "0.9.23",
4
4
  "description": "Groundwork's framework-free web components, styled by the --gw-* tokens",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/fields.ts CHANGED
@@ -406,6 +406,79 @@ export const fieldStyles = css`
406
406
  gw-switch input:disabled {
407
407
  opacity: 0.5;
408
408
  }
409
+
410
+ gw-range {
411
+ display: flex;
412
+ flex-direction: column;
413
+ gap: var(--gw-space-2);
414
+ min-width: 0;
415
+ font-family: var(--gw-font-sans);
416
+ color: var(--gw-color-text-primary);
417
+ }
418
+
419
+ gw-range > label {
420
+ font-size: var(--gw-font-size-s);
421
+ font-weight: var(--gw-font-weight-strong);
422
+ color: var(--gw-color-text-strong);
423
+ }
424
+
425
+ gw-range .gw-range-control {
426
+ position: relative;
427
+ display: block;
428
+ }
429
+
430
+ gw-range input {
431
+ display: block;
432
+ width: 100%;
433
+ margin: 0;
434
+ accent-color: var(--gw-color-fill-accent-resting);
435
+ cursor: pointer;
436
+ }
437
+
438
+ gw-range input:focus-visible {
439
+ outline: var(--gw-focus-width) solid var(--gw-color-focus);
440
+ outline-offset: var(--gw-focus-offset);
441
+ }
442
+
443
+ gw-range input:disabled {
444
+ cursor: not-allowed;
445
+ opacity: 0.5;
446
+ }
447
+
448
+ /* The value above the thumb while it's held */
449
+ gw-range .gw-range-bubble {
450
+ position: absolute;
451
+ bottom: calc(100% + var(--gw-space-1));
452
+ padding: var(--gw-space-1) var(--gw-space-2);
453
+ font-size: var(--gw-font-size-xs);
454
+ font-variant-numeric: tabular-nums;
455
+ color: var(--gw-color-on-accent);
456
+ white-space: nowrap;
457
+ pointer-events: none;
458
+ background: var(--gw-color-fill-accent-resting);
459
+ border-radius: var(--gw-radius-control);
460
+ box-shadow: var(--gw-shadow-s);
461
+ translate: -50% 0;
462
+ }
463
+
464
+ gw-range .gw-range-bubble[hidden] {
465
+ display: none;
466
+ }
467
+
468
+ gw-range .gw-hint {
469
+ margin: 0;
470
+ font-size: var(--gw-font-size-xs);
471
+ color: var(--gw-color-text-secondary);
472
+ }
473
+
474
+ gw-range .gw-visually-hidden {
475
+ position: absolute;
476
+ width: 1px;
477
+ height: 1px;
478
+ overflow: hidden;
479
+ clip-path: inset(50%);
480
+ white-space: nowrap;
481
+ }
409
482
  `;
410
483
 
411
484
  const adoptStyles = (element: Element, sheet: CSSStyleSheet) => {
package/src/gw-input.ts CHANGED
@@ -10,7 +10,9 @@ import { FieldInfo } from "./field-info.js";
10
10
  import { LightElement, fieldId } from "./fields.js";
11
11
 
12
12
  /**
13
- * A labeled native `<input>`, with an optional hint and error.
13
+ * A labeled native `<input>`, with an optional hint and error. Enter submits
14
+ * its form when the form's submit button is a `gw-button`, as it would with a
15
+ * native one.
14
16
  *
15
17
  * @element gw-input
16
18
  * @summary A labeled text field in light DOM, so forms and autofill see it.
@@ -105,6 +107,30 @@ export class GwInput extends LightElement {
105
107
  this.#input.addEventListener("input", () => {
106
108
  this.value = this.#input.value;
107
109
  });
110
+ // A gw-button's native button is in its shadow root, out of the form's
111
+ // reach, so Enter only submits on its own with a single field. Submit
112
+ // here instead, as a native submit button would
113
+ this.#input.addEventListener("keydown", (event) => {
114
+ const form = this.#input.form;
115
+
116
+ if (
117
+ event.key !== "Enter" ||
118
+ event.isComposing ||
119
+ event.defaultPrevented ||
120
+ form === null ||
121
+ form.querySelector(
122
+ 'button:not([type]), button[type="submit"], input[type="submit"]',
123
+ ) !== null ||
124
+ form.querySelector(
125
+ 'gw-button[type="submit"]:not([disabled], [loading])',
126
+ ) === null
127
+ ) {
128
+ return;
129
+ }
130
+
131
+ event.preventDefault();
132
+ form.requestSubmit();
133
+ });
108
134
  root.append(
109
135
  this.#info.heading,
110
136
  h("span", { class: "gw-input-control" }, this.#icon, this.#input),
@@ -0,0 +1,164 @@
1
+ /**
2
+ * `gw-range`: a labeled native range slider in light DOM.
3
+ * Docs: https://groundwork.timmo.dev/components/inputs/#range
4
+ *
5
+ * @module
6
+ */
7
+ import { h, setAttribute } from "./element.js";
8
+ import { LightElement, fieldId } from "./fields.js";
9
+
10
+ /**
11
+ * A labeled native range slider. While it's pressed or dragged, a bubble
12
+ * above the thumb shows the value, so a slider without a readout beside it
13
+ * still says where it is. The native `input` and `change` events bubble out
14
+ * as usual.
15
+ *
16
+ * @element gw-range
17
+ * @summary A labeled slider in light DOM, so forms see it.
18
+ *
19
+ * @attr {string} label - The label, also its accessible name.
20
+ * @attr {boolean} label-hidden - Hides the label but keeps it for assistive technology.
21
+ * @attr {string} name - The form field name.
22
+ * @attr {number} value - The value.
23
+ * @attr {number} min - The lowest value. Defaults to 0.
24
+ * @attr {number} max - The highest value. Defaults to 100.
25
+ * @attr {number} step - The step between values. Defaults to 1.
26
+ * @attr {string} unit - Shown after the value in the bubble and for assistive technology, such as `%`. Empty for a plain number.
27
+ * @attr {string} hint - One line of help under it.
28
+ * @attr {boolean} disabled - Disables it.
29
+ *
30
+ * @cssprop --gw-range-thumb - The thumb's size. Defaults to 1rem.
31
+ */
32
+ export class GwRange extends LightElement {
33
+ static override properties = {
34
+ label: {},
35
+ labelHidden: { type: "boolean", attribute: "label-hidden" },
36
+ name: {},
37
+ value: { type: "number" },
38
+ min: { type: "number" },
39
+ max: { type: "number" },
40
+ step: { type: "number" },
41
+ unit: {},
42
+ hint: {},
43
+ disabled: { type: "boolean" },
44
+ } as const;
45
+
46
+ declare label: string;
47
+ /** Keeps the label for assistive technology but hides it. */
48
+ declare labelHidden: boolean;
49
+ declare name: string;
50
+ declare value: number;
51
+ declare min: number;
52
+ declare max: number;
53
+ declare step: number;
54
+ /** Shown after the value, such as `%`. */
55
+ declare unit: string;
56
+ declare hint: string;
57
+ declare disabled: boolean;
58
+
59
+ readonly #id = fieldId();
60
+
61
+ readonly #label = h("label", { for: this.#id });
62
+
63
+ readonly #input = h("input", { type: "range", id: this.#id });
64
+
65
+ readonly #bubble = h("span", {
66
+ class: "gw-range-bubble",
67
+ "aria-hidden": "true",
68
+ hidden: "",
69
+ });
70
+
71
+ readonly #hint = h("p", { class: "gw-hint", id: `${this.#id}-hint` });
72
+
73
+ constructor() {
74
+ super();
75
+ this.label = "";
76
+ this.labelHidden = false;
77
+ this.name = "";
78
+ this.value = 0;
79
+ this.min = 0;
80
+ this.max = 100;
81
+ this.step = 1;
82
+ this.unit = "";
83
+ this.hint = "";
84
+ this.disabled = false;
85
+ }
86
+
87
+ #text(value: number): string {
88
+ if (!this.unit) return String(value);
89
+
90
+ return this.unit === "%" ? `${value}%` : `${value} ${this.unit}`;
91
+ }
92
+
93
+ #placeBubble() {
94
+ const value = this.#input.valueAsNumber;
95
+ const span = this.max - this.min;
96
+ const fraction = span > 0 ? (value - this.min) / span : 0;
97
+
98
+ this.#bubble.textContent = this.#text(value);
99
+ // Follows the thumb's center, which travels a thumb's width less than the track
100
+ this.#bubble.style.left = `calc(${fraction * 100}% + (0.5 - ${fraction}) * var(--gw-range-thumb, 1rem))`;
101
+ }
102
+
103
+ readonly #release = () => {
104
+ this.#bubble.hidden = true;
105
+ window.removeEventListener("pointerup", this.#release);
106
+ window.removeEventListener("pointercancel", this.#release);
107
+ };
108
+
109
+ protected override create(root: HTMLElement) {
110
+ this.#input.addEventListener("pointerdown", () => {
111
+ if (this.#input.disabled) return;
112
+
113
+ this.#placeBubble();
114
+ this.#bubble.hidden = false;
115
+ window.addEventListener("pointerup", this.#release);
116
+ window.addEventListener("pointercancel", this.#release);
117
+ });
118
+ this.#input.addEventListener("input", () => {
119
+ this.value = this.#input.valueAsNumber;
120
+ this.#placeBubble();
121
+ });
122
+ root.append(
123
+ this.#label,
124
+ h("span", { class: "gw-range-control" }, this.#input, this.#bubble),
125
+ this.#hint,
126
+ );
127
+ }
128
+
129
+ override disconnectedCallback() {
130
+ super.disconnectedCallback();
131
+ this.#release();
132
+ }
133
+
134
+ protected override update() {
135
+ const input = this.#input;
136
+
137
+ this.#label.textContent = this.label;
138
+ this.#label.className = this.labelHidden ? "gw-visually-hidden" : "";
139
+ setAttribute(input, "name", this.name || null);
140
+ input.min = String(this.min);
141
+ input.max = String(this.max);
142
+ input.step = String(this.step);
143
+ input.disabled = this.disabled;
144
+
145
+ if (input.valueAsNumber !== this.value) input.value = String(this.value);
146
+
147
+ setAttribute(
148
+ input,
149
+ "aria-valuetext",
150
+ this.unit ? this.#text(this.value) : null,
151
+ );
152
+ setAttribute(input, "aria-describedby", this.hint ? this.#hint.id : null);
153
+ this.#hint.textContent = this.hint;
154
+ this.#hint.hidden = !this.hint;
155
+ }
156
+ }
157
+
158
+ GwRange.define("gw-range");
159
+
160
+ declare global {
161
+ interface HTMLElementTagNameMap {
162
+ "gw-range": GwRange;
163
+ }
164
+ }
package/src/index.ts CHANGED
@@ -67,6 +67,8 @@ export * from "./gw-page-header.js";
67
67
 
68
68
  export * from "./gw-popover.js";
69
69
 
70
+ export * from "./gw-range.js";
71
+
70
72
  export * from "./gw-section-title.js";
71
73
 
72
74
  export * from "./gw-segmented.js";