draft-components 2.10.0 → 2.10.2
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/css/draft-components.css +11 -3
- package/dist/components/slider/calc-position.d.ts +4 -0
- package/dist/components/slider/calc-position.js +3 -0
- package/dist/components/slider/range-slider.d.ts +2 -2
- package/dist/components/slider/range-slider.js +7 -6
- package/dist/components/slider/slider-thumb.js +3 -3
- package/dist/components/slider/slider.js +5 -4
- package/dist/lib/helpers.d.ts +1 -1
- package/dist/lib/helpers.js +2 -2
- package/package.json +1 -1
package/css/draft-components.css
CHANGED
|
@@ -1995,6 +1995,7 @@
|
|
|
1995
1995
|
/* Label properties */
|
|
1996
1996
|
--dc-slider-label-gap: 4px;
|
|
1997
1997
|
--dc-slider-label-height: 24px;
|
|
1998
|
+
--dc-slider-label-max-width: 80px;
|
|
1998
1999
|
--dc-slider-label-padding-x: 0.5em;
|
|
1999
2000
|
--dc-slider-label-radius: 6px;
|
|
2000
2001
|
--dc-slider-label-border: 1px solid var(--dc-white);
|
|
@@ -2038,7 +2039,7 @@
|
|
|
2038
2039
|
min-height: var(--dc-slider-thumb-height);
|
|
2039
2040
|
}
|
|
2040
2041
|
|
|
2041
|
-
.dc-
|
|
2042
|
+
.dc-slider__body_has_labels {
|
|
2042
2043
|
margin-top: calc(
|
|
2043
2044
|
var(--dc-slider-label-height) +
|
|
2044
2045
|
var(--dc-slider-label-gap)
|
|
@@ -2151,7 +2152,7 @@
|
|
|
2151
2152
|
box-shadow: var(--dc-slider-thumb-shadow);
|
|
2152
2153
|
}
|
|
2153
2154
|
|
|
2154
|
-
.dc-
|
|
2155
|
+
.dc-slider__label {
|
|
2155
2156
|
font: var(--dc-text-xs);
|
|
2156
2157
|
font-variant-numeric: tabular-nums;
|
|
2157
2158
|
color: var(--dc-slider-label-text-color);
|
|
@@ -2169,6 +2170,7 @@
|
|
|
2169
2170
|
box-sizing: border-box;
|
|
2170
2171
|
height: var(--dc-slider-label-height);
|
|
2171
2172
|
min-width: var(--dc-slider-label-height);
|
|
2173
|
+
max-width: var(--dc-slider-label-max-width);
|
|
2172
2174
|
padding: 0 var(--dc-slider-label-padding-x);
|
|
2173
2175
|
transform: translateX(-50%);
|
|
2174
2176
|
border: var(--dc-slider-label-border);
|
|
@@ -2176,8 +2178,14 @@
|
|
|
2176
2178
|
background: var(--dc-slider-label-bg);
|
|
2177
2179
|
}
|
|
2178
2180
|
|
|
2181
|
+
.dc-slider__label-text {
|
|
2182
|
+
overflow: hidden;
|
|
2183
|
+
white-space: nowrap;
|
|
2184
|
+
text-overflow: ellipsis;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2179
2187
|
.dc-slider__input_active,
|
|
2180
|
-
.dc-
|
|
2188
|
+
.dc-slider__label_active {
|
|
2181
2189
|
z-index: 1;
|
|
2182
2190
|
}
|
|
2183
2191
|
|
|
@@ -11,7 +11,7 @@ export type RangeSliderProps = {
|
|
|
11
11
|
className?: string;
|
|
12
12
|
disabled?: boolean;
|
|
13
13
|
fullWidth?: boolean;
|
|
14
|
-
|
|
14
|
+
showLabels?: boolean;
|
|
15
15
|
iconLeft?: ReactNode;
|
|
16
16
|
iconRight?: ReactNode;
|
|
17
17
|
tickMarks?: SliderTickMark[];
|
|
@@ -27,4 +27,4 @@ export type RangeSliderProps = {
|
|
|
27
27
|
onChange: (value: RangeSliderValue) => void;
|
|
28
28
|
formatValue?: (value: number) => ReactNode;
|
|
29
29
|
};
|
|
30
|
-
export declare function RangeSlider({ 'aria-label': ariaLabel, id, style, className, disabled, fullWidth,
|
|
30
|
+
export declare function RangeSlider({ 'aria-label': ariaLabel, id, style, className, disabled, fullWidth, showLabels, iconLeft, iconRight, tickMarks, step, min, minThumbName, minThumbAriaLabel, max, maxThumbName, maxThumbAriaLabel, name, value: range, onChange, formatValue, }: RangeSliderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId, useState } from 'react';
|
|
3
|
+
import { classNames } from '../../lib/index.js';
|
|
4
|
+
import { calcPosition } from './calc-position.js';
|
|
3
5
|
import { SliderTrack } from './slider-track.js';
|
|
4
6
|
import { SliderThumb } from './slider-thumb.js';
|
|
5
|
-
import { classNames } from '../../lib/index.js';
|
|
6
7
|
import { SliderTickMarks } from './slider-tick-marks.js';
|
|
7
8
|
const numberFormatter = new Intl.NumberFormat();
|
|
8
|
-
export function RangeSlider({ 'aria-label': ariaLabel, id, style, className, disabled, fullWidth,
|
|
9
|
+
export function RangeSlider({ 'aria-label': ariaLabel, id, style, className, disabled, fullWidth, showLabels, iconLeft, iconRight, tickMarks, step = 1, min = 0, minThumbName, minThumbAriaLabel, max = 100, maxThumbName, maxThumbAriaLabel, name, value: range, onChange, formatValue = numberFormatter.format, }) {
|
|
9
10
|
const defaultId = useId();
|
|
10
11
|
const [focusedThumb, setFocusedThumb] = useState('min');
|
|
11
|
-
const positionMin = range.min
|
|
12
|
-
const positionMax = range.max
|
|
12
|
+
const positionMin = calcPosition(range.min, { min, max });
|
|
13
|
+
const positionMax = calcPosition(range.max, { min, max });
|
|
13
14
|
let dataListId;
|
|
14
15
|
let tickMarksElement;
|
|
15
16
|
if (tickMarks && tickMarks.length > 0) {
|
|
@@ -41,7 +42,7 @@ export function RangeSlider({ 'aria-label': ariaLabel, id, style, className, dis
|
|
|
41
42
|
'dc-slider_full-width': fullWidth,
|
|
42
43
|
}), name: name, disabled: disabled, "aria-label": ariaLabel, children: _jsxs("div", { className: classNames({
|
|
43
44
|
'dc-slider__body': true,
|
|
44
|
-
'dc-
|
|
45
|
+
'dc-slider__body_has_labels': showLabels,
|
|
45
46
|
'dc-slider__body_has_tick-marks': tickMarksElement,
|
|
46
|
-
}), children: [iconLeft, _jsxs(SliderTrack, { positionStart: positionMin, positionEnd: positionMax, children: [tickMarksElement, _jsx(SliderThumb, { name: minThumbName || (name && `${name}[min]`), active: focusedThumb === 'min', "aria-label": minThumbAriaLabel, showLabel:
|
|
47
|
+
}), children: [iconLeft, _jsxs(SliderTrack, { positionStart: positionMin, positionEnd: positionMax, children: [tickMarksElement, _jsx(SliderThumb, { name: minThumbName || (name && `${name}[min]`), active: focusedThumb === 'min', "aria-label": minThumbAriaLabel, showLabel: showLabels, dataListId: dataListId, position: positionMin, step: step, min: min, max: max, value: range.min, formatValue: formatValue, onChange: handleChangeMin, onFocus: handleFocusMinThumb }), _jsx(SliderThumb, { name: maxThumbName || (name && `${name}[max]`), active: focusedThumb === 'max', "aria-label": maxThumbAriaLabel, showLabel: showLabels, dataListId: dataListId, position: positionMax, step: step, min: min, max: max, value: range.max, formatValue: formatValue, onChange: handleChangeMax, onFocus: handleFocusMaxThumb })] }), iconRight] }) }));
|
|
47
48
|
}
|
|
@@ -9,7 +9,7 @@ export function SliderThumb({ 'aria-label': ariaLabel, id, name, active, disable
|
|
|
9
9
|
'dc-slider__input': true,
|
|
10
10
|
'dc-slider__input_active': active,
|
|
11
11
|
}), type: "range", name: name, "aria-label": ariaLabel, list: dataListId, step: step, min: min, max: max, disabled: disabled, value: value, onChange: handleChange, onFocus: onFocus, onBlur: onBlur }), showLabel && (_jsx("output", { style: { left: getOffsetRelativeToThumb(position) }, className: classNames({
|
|
12
|
-
'dc-
|
|
13
|
-
'dc-
|
|
14
|
-
}), htmlFor: id, children: formatValue(value) }))] }));
|
|
12
|
+
'dc-slider__label': true,
|
|
13
|
+
'dc-slider__label_active': active,
|
|
14
|
+
}), htmlFor: id, children: _jsx("span", { className: "dc-slider__label-text", children: formatValue(value) }) }))] }));
|
|
15
15
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId } from 'react';
|
|
3
|
+
import { classNames } from '../../lib/index.js';
|
|
4
|
+
import { calcPosition } from './calc-position.js';
|
|
3
5
|
import { SliderTrack } from './slider-track.js';
|
|
4
6
|
import { SliderThumb } from './slider-thumb.js';
|
|
5
|
-
import { classNames } from '../../lib/index.js';
|
|
6
7
|
import { SliderTickMarks } from './slider-tick-marks.js';
|
|
7
8
|
const numberFormatter = new Intl.NumberFormat();
|
|
8
|
-
export function Slider({ 'aria-label': ariaLabel, id, style, className, disabled, fullWidth, showLabel
|
|
9
|
+
export function Slider({ 'aria-label': ariaLabel, id, style, className, disabled, fullWidth, showLabel, iconLeft, iconRight, tickMarks, step = 1, min = 0, max = 100, name, value, onChange, formatValue = numberFormatter.format, }) {
|
|
9
10
|
const defaultId = useId();
|
|
10
11
|
const thumbId = id || `${defaultId}slider-thumb`;
|
|
11
|
-
const position = value
|
|
12
|
+
const position = calcPosition(value, { min, max });
|
|
12
13
|
let dataListId;
|
|
13
14
|
let tickMarksElement;
|
|
14
15
|
if (tickMarks && tickMarks.length > 0) {
|
|
@@ -21,7 +22,7 @@ export function Slider({ 'aria-label': ariaLabel, id, style, className, disabled
|
|
|
21
22
|
'dc-slider_full-width': fullWidth,
|
|
22
23
|
}), children: _jsxs("div", { className: classNames({
|
|
23
24
|
'dc-slider__body': true,
|
|
24
|
-
'dc-
|
|
25
|
+
'dc-slider__body_has_labels': showLabel,
|
|
25
26
|
'dc-slider__body_has_tick-marks': tickMarksElement,
|
|
26
27
|
}), children: [iconLeft, _jsxs(SliderTrack, { positionStart: 0, positionEnd: position, children: [tickMarksElement, _jsx(SliderThumb, { id: thumbId, name: name, "aria-label": ariaLabel, disabled: disabled, showLabel: showLabel, dataListId: dataListId, position: position, step: step, min: min, max: max, value: value, onChange: onChange, formatValue: formatValue })] }), iconRight] }) }));
|
|
27
28
|
}
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export declare function assertIfNullable<T>(value: T, message?: string): asserts
|
|
|
4
4
|
export declare function exhaustiveCheck(value: never, message?: string): never;
|
|
5
5
|
export declare function noop(): undefined;
|
|
6
6
|
export declare function formatNumber(num: number, fractionDigits?: number): number;
|
|
7
|
-
export declare function formatPercent(percent: number): string;
|
|
7
|
+
export declare function formatPercent(percent: number, fractionDigits?: number): string;
|
|
8
8
|
export {};
|
package/dist/lib/helpers.js
CHANGED
|
@@ -23,6 +23,6 @@ export function noop() {
|
|
|
23
23
|
export function formatNumber(num, fractionDigits = 5) {
|
|
24
24
|
return Number(num.toFixed(fractionDigits));
|
|
25
25
|
}
|
|
26
|
-
export function formatPercent(percent) {
|
|
27
|
-
return `${formatNumber(percent * 100)}%`;
|
|
26
|
+
export function formatPercent(percent, fractionDigits = 2) {
|
|
27
|
+
return `${formatNumber(percent * 100, fractionDigits)}%`;
|
|
28
28
|
}
|