@m3e/slider 1.0.0-rc.1 → 1.0.0-rc.3

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/src/SliderSize.ts DELETED
@@ -1,2 +0,0 @@
1
- /** Specifies the possible sizes of a slider. */
2
- export type SliderSize = "extra-small" | "small" | "medium" | "large" | "extra-large";
@@ -1,230 +0,0 @@
1
- import { css, CSSResultGroup, html, LitElement, PropertyValues, unsafeCSS } from "lit";
2
- import { customElement, property, query } from "lit/decorators.js";
3
-
4
- import {
5
- AttachInternals,
6
- DesignToken,
7
- Dirty,
8
- Disabled,
9
- Focusable,
10
- FormAssociated,
11
- formValue,
12
- M3eFocusRingElement,
13
- Role,
14
- Touched,
15
- } from "@m3e/core";
16
-
17
- /**
18
- * A thumb used to select a value in a slider.
19
- *
20
- * @description
21
- * The `m3e-slider-thumb` component is used within a `m3e-slider` to represent and select a specific value.
22
- * This component supports continuous and discrete input, form association, and accessibility semantics.
23
- * It emits `input` and `change` events to reflect value updates.
24
- *
25
- * @example
26
- * The following example illustrates a labelled slider with thumb used to select a single numeric value.
27
- * ```html
28
- * <m3e-slider labelled>
29
- * <m3e-slider-thumb value="50"></m3e-slider-thumb>
30
- * </m3e-slider>
31
- * ```
32
- *
33
- * @example
34
- * The next example illustrates a labelled range slider with two thumbs used to select a minimum and maximum numeric value.
35
- * ```html
36
- * <m3e-slider labelled>
37
- * <m3e-slider-thumb value="25"></m3e-slider-thumb>
38
- * <m3e-slider-thumb value="75"></m3e-slider-thumb>
39
- * </m3e-slider>
40
- * ```
41
- *
42
- * @tag m3e-slider-thumb
43
- *
44
- * @attr disabled - Whether the element is disabled.
45
- * @attr name - The name that identifies the element when submitting the associated form.
46
- * @attr value - The value of the thumb.
47
- *
48
- * @fires input - Emitted when the value changes.
49
- * @fires change - Emitted when the value changes.
50
- *
51
- * @cssprop --m3e-slider-thumb-width - Width of the slider thumb.
52
- * @cssprop --m3e-slider-thumb-padding - Horizontal padding around the thumb.
53
- * @cssprop --m3e-slider-thumb-color - Active color of the slider thumb when enabled.
54
- * @cssprop --m3e-slider-thumb-pressed-width - Width of the thumb when pressed.
55
- * @cssprop --m3e-slider-thumb-disabled-color - Color of the thumb when disabled.
56
- * @cssprop --m3e-slider-thumb-disabled-opacity - Opacity of the thumb when disabled.
57
- * @cssprop --m3e-slider-label-width - Width of the floating label above the thumb.
58
- * @cssprop --m3e-slider-label-container-color - Background color of the label container.
59
- * @cssprop --m3e-slider-label-color - Text color of the label.
60
- * @cssprop --m3e-slider-label-font-size - Font size of the label text.
61
- * @cssprop --m3e-slider-label-font-weight - Font weight of the label text.
62
- * @cssprop --m3e-slider-label-line-height - Line height of the label text.
63
- * @cssprop --m3e-slider-label-tracking - Letter spacing of the label text.
64
- */
65
- @customElement("m3e-slider-thumb")
66
- export class M3eSliderThumbElement extends Dirty(
67
- Touched(FormAssociated(Focusable(Disabled(AttachInternals(Role(LitElement, "slider"))))))
68
- ) {
69
- /** The styles of the element. */
70
- static override styles: CSSResultGroup = css`
71
- :host {
72
- display: block;
73
- box-sizing: border-box;
74
- position: absolute;
75
- outline: none;
76
- top: 0;
77
- bottom: 0;
78
- border-radius: var(--m3e-slider-thumb-shape, ${DesignToken.shape.corner.full});
79
- }
80
- .base {
81
- box-sizing: border-box;
82
- vertical-align: middle;
83
- display: inline-flex;
84
- align-items: center;
85
- justify-content: center;
86
- position: relative;
87
- width: 100%;
88
- height: 100%;
89
- border-radius: inherit;
90
- }
91
- .touch {
92
- position: absolute;
93
- height: 3rem;
94
- left: 0;
95
- right: 0;
96
- }
97
- .wrapper {
98
- display: inline-flex;
99
- justify-content: center;
100
- height: 100%;
101
- border-radius: inherit;
102
- width: calc(var(--m3e-slider-thumb-width, 0.25rem) + calc(var(--m3e-slider-thumb-padding, 0.375em) * 2));
103
- }
104
- .focus-ring {
105
- --m3e-focus-ring-growth-factor: 1.5;
106
- top: calc(0px - var(--m3e-focus-ring-thickness, 0.1875rem));
107
- bottom: calc(0px - var(--m3e-focus-ring-thickness, 0.1875rem));
108
- left: var(--m3e-focus-ring-thickness, 0.1875rem);
109
- right: var(--m3e-focus-ring-thickness, 0.1875rem);
110
- }
111
- .label {
112
- user-select: none;
113
- position: absolute;
114
- display: flex;
115
- align-items: center;
116
- justify-content: center;
117
- visibility: var(--_slider-label-visibility, hidden);
118
- opacity: var(--_slider-label-opacity, 0);
119
- transform: var(--_slider-label-transform, scale(0));
120
- transition: ${unsafeCSS(
121
- `opacity ${DesignToken.motion.duration.short3} ${DesignToken.motion.easing.standard},
122
- transform ${DesignToken.motion.duration.short3} ${DesignToken.motion.easing.standard},
123
- visibility ${DesignToken.motion.duration.short3} ${DesignToken.motion.easing.standard} allow-discrete`
124
- )};
125
- width: var(--m3e-slider-label-width, 3rem);
126
- height: var(--_m3e-slider-label-height, 2.75rem);
127
- top: calc(0px - var(--_m3e-slider-label-height, 2.75rem) - var(--_m3e-slider-label-margin, 0.25rem));
128
- left: calc(0px - 100%);
129
- border-radius: var(--m3e-slider-label-shape, ${DesignToken.shape.corner.full});
130
- background-color: var(--m3e-slider-label-container-color, ${DesignToken.color.inverseSurface});
131
- color: var(--m3e-slider-label-color, ${DesignToken.color.inverseOnSurface});
132
- font-size: var(--m3e-slider-label-font-size, ${DesignToken.typescale.standard.label.medium.fontSize});
133
- font-weight: var(--m3e-slider-label-font-weight, ${DesignToken.typescale.standard.label.medium.fontWeight});
134
- line-height: var(--m3e-slider-label-line-height, ${DesignToken.typescale.standard.label.medium.lineHeight});
135
- letter-spacing: var(--m3e-slider-label-tracking, ${DesignToken.typescale.standard.label.medium.tracking});
136
- }
137
- @starting-style {
138
- .label {
139
- opacity: 0;
140
- transform: scale(0);
141
- }
142
- }
143
- .handle {
144
- height: 100%;
145
- width: var(--m3e-slider-thumb-width, 0.25rem);
146
- border-radius: inherit;
147
- transition: ${unsafeCSS(`width ${DesignToken.motion.duration.short2} ${DesignToken.motion.easing.standard}`)};
148
- }
149
- :host(:active:not([aria-disabled="true"])) .handle {
150
- width: var(--m3e-slider-thumb-pressed-width, 0.125rem);
151
- }
152
- :host(:not([aria-disabled="true"])) .handle {
153
- background-color: var(--m3e-slider-thumb-color, ${DesignToken.color.primary});
154
- }
155
- :host([aria-disabled="true"]) .handle {
156
- opacity: var(--m3e-slider-thumb-disabled-opacity, 38%);
157
- background-color: var(--m3e-slider-thumb-disabled-color, ${DesignToken.color.onSurface});
158
- }
159
- @media (prefers-reduced-motion) {
160
- .label {
161
- transition: none;
162
- }
163
- }
164
- @media (forced-colors: active) {
165
- .label {
166
- forced-color-adjust: none;
167
- background-color: CanvasText;
168
- color: Canvas;
169
- }
170
- :host(:not([aria-disabled="true"])) .handle {
171
- background-color: CanvasText;
172
- }
173
- :host([aria-disabled="true"]) .handle {
174
- opacity: unset;
175
- background-color: GrayText;
176
- }
177
- }
178
- `;
179
-
180
- /** @private */ @query(".focus-ring") private readonly _focusRing?: M3eFocusRingElement;
181
-
182
- /**
183
- * The value of the thumb.
184
- * @default null
185
- */
186
- @property({ type: Number, reflect: true }) value: number | null = null;
187
-
188
- /** @inheritdoc */
189
- override get [formValue](): string | File | FormData | null {
190
- return this.value?.toString() ?? null;
191
- }
192
-
193
- /** @internal */
194
- get #labelText(): string {
195
- return this.closest("m3e-slider")?.displayWith?.(this.value) ?? this.value?.toString() ?? "";
196
- }
197
-
198
- /** @inheritdoc */
199
- protected override firstUpdated(_changedProperties: PropertyValues<this>): void {
200
- super.firstUpdated(_changedProperties);
201
- this._focusRing?.attach(this);
202
- }
203
-
204
- /** @inheritdoc */
205
- protected override update(changedProperties: PropertyValues<this>): void {
206
- super.update(changedProperties);
207
-
208
- if (changedProperties.has("value")) {
209
- this.dispatchEvent(new Event("value-change", { bubbles: true }));
210
- }
211
- }
212
-
213
- /** @inheritdoc */
214
- protected override render(): unknown {
215
- return html`<div class="label" aria-hidden="true">${this.#labelText}</div>
216
- <div class="base">
217
- <m3e-focus-ring class="focus-ring" ?disabled="${this.disabled}"></m3e-focus-ring>
218
- <div class="touch" aria-hidden="true"></div>
219
- <div class="wrapper">
220
- <div class="handle"></div>
221
- </div>
222
- </div>`;
223
- }
224
- }
225
-
226
- declare global {
227
- interface HTMLElementTagNameMap {
228
- "m3e-slider-thumb": M3eSliderThumbElement;
229
- }
230
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./SliderElement";
2
- export * from "./SliderSize";
3
- export * from "./SliderThumbElement";
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist/src"
6
- },
7
- "include": ["src/**/*.ts", "**/*.mjs", "**/*.js"],
8
- "exclude": []
9
- }