UNPKG

@synergy-design-system/components

Version:

This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define

139 lines (138 loc) 6.76 kB
import type { CSSResultGroup, PropertyValues } from 'lit'; import type { SynergyFormControl } from '../../internal/synergy-element.js'; import SynergyElement from '../../internal/synergy-element.js'; import SynTooltip from '../tooltip/tooltip.component.js'; /** * @summary Ranges allow the user to select values within a given range using one or two thumbs. * @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-range--docs * @status stable * * @dependency syn-tooltip * * @slot label - The range's label. Alternatively, you can use the `label` attribute. * @slot prefix - Used to prepend a presentational icon or similar element to the range. * @slot suffix - Used to append a presentational icon or similar element to the range. * @slot help-text - Text that describes how to use the range. * Alternatively, you can use the `help-text` attribute. * @slot ticks - Used to display tick marks at specific intervals along the range. * * @event syn-blur - Emitted when the control loses focus. * @event syn-change - Emitted when an alteration to the control's value is committed by the user. * @event syn-focus - Emitted when the control gains focus. * @event syn-input - Emitted when the control receives input. * @event syn-invalid - Emitted when the form control has been checked for validity * and its constraints aren't satisfied. * @event syn-move - Emitted when the user moves a thumb, either via touch or keyboard. * Use `Event.preventDefault()` to prevent movement. * * @csspart form-control - The form control that wraps the label, input, and help text. * @csspart form-control-label - The label's wrapper. * @csspart form-control-help-text - The help text's wrapper. * @csspart base - The component's base wrapper. * @csspart input-wrapper - The container that wraps the input track and ticks. * @csspart track-wrapper - The wrapper for the track. * @csspart track - The inactive track. * @csspart active-track - The active track. * @csspart prefix - The container that wraps the prefix. * @csspart suffix - The container that wraps the suffix. * @csspart ticks - The container that wraps the tick marks. * @csspart thumb - The thumb(s) that the user can drag to change the range. * * @csspart tooltip__base - The base of the tooltip * @csspart tooltip__arrow - The arrow of the tooltip * @csspart tooltip__popup - The popup of the tooltip * @csspart tooltip__body - The body of the tooltip * * @cssproperty --thumb-size - The size of a thumb. * @cssproperty --thumb-hit-area-size - The clickable area around the thumb. * Per default this is set to 140% of the thumb size. Must be a scale css value (defaults to 1.4). * @cssproperty --track-hit-area-size - The clickable area around the track (top and left). * @cssproperty --track-color-active - Color of the track representing the current value. * @cssproperty --track-color-inactive - Color of the track that represents the remaining value. * @cssproperty --track-height - The height of the track. * @cssproperty --track-active-offset - The point of origin of the active track, * starting at the left side of the range. */ export default class SynRange extends SynergyElement implements SynergyFormControl { #private; static styles: CSSResultGroup; static dependencies: { 'syn-tooltip': typeof SynTooltip; }; /** The name of the range, submitted as a name/value pair with form data. */ name: string; /** The range's label. If you need to display HTML, use the `label` slot instead. */ label: string; /** The range's help text. If you need to display HTML, use the help-text slot instead. */ helpText: string; /** Disables the range. */ disabled: boolean; /** The minimum acceptable value of the range. */ min: number; /** The maximum acceptable value of the range. */ max: number; /** The interval at which the range will increase and decrease. */ step: number; /** The range's size. */ size: 'small' | 'medium' | 'large'; /** The preferred placement of the range's tooltip. Use "none" to disable the tooltip */ tooltipPlacement: 'top' | 'bottom' | 'none'; /** The current values of the input (in ascending order) as a string of space separated values */ set value(value: string | null); get value(): string | null; /** * Set to true to restrict the movement of a thumb to its next and previous thumb. * This only affects multi range components */ restrictMovement: boolean; /** Gets or sets the current values of the range as an array of numbers */ set valueAsArray(value: readonly number[] | null); get valueAsArray(): readonly number[] | null; /** The default value of the form control. Primarily used for resetting the form control. */ defaultValue: string; /** * By default, form controls are associated with the nearest containing `<form>` element. * This attribute allows you to place the form control outside of a form * and associate it with the form that has this `id`. * The form must be in the same document or shadow root for this to work. */ form: string; /** * A function used to format the tooltip's value. * The value of the thumb is passed as the only argument. * The function should return a string to display in the tooltip. */ tooltipFormatter: (value: number) => string; baseDiv: HTMLDivElement; activeTrack: HTMLDivElement; ticks: HTMLDivElement; thumbs: NodeListOf<HTMLDivElement>; validationInput: HTMLInputElement; private readonly hasSlotController; private readonly formControlController; private localize; private visibilityObserver; constructor(); disconnectedCallback(): void; firstUpdated(): void; protected willUpdate(changedProperties: PropertyValues): void; protected updated(changedProperties: PropertyValues): void; focus(options?: FocusOptions): void; /** * Checks for validity but does not show a validation message. * Returns `true` when valid and `false` when invalid. */ checkValidity(): boolean; /** Checks for validity and shows the browser's validation message if the control is invalid. */ reportValidity(): boolean; /** Sets a custom validation message. Pass an empty string to restore validity. */ setCustomValidity(message: string): void; /** Gets the associated form, if one exists. */ getForm(): HTMLFormElement | null; /** Gets the validity state object */ get validity(): ValidityState; /** Gets the validation message */ get validationMessage(): string; private renderThumbs; render(): import("lit").TemplateResult<1>; }