draft-components 2.10.1 → 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/dist/components/slider/calc-position.d.ts +4 -0
- package/dist/components/slider/calc-position.js +3 -0
- package/dist/components/slider/get-offset-relative-to-thumb.js +2 -2
- package/dist/components/slider/range-slider.js +4 -3
- package/dist/components/slider/slider-track.js +3 -2
- package/dist/components/slider/slider.js +3 -2
- package/dist/lib/helpers.d.ts +1 -1
- package/dist/lib/helpers.js +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { formatNumber } from '../../lib/index.js';
|
|
1
|
+
import { formatNumber, formatPercent } from '../../lib/index.js';
|
|
2
2
|
export function getOffsetRelativeToThumb(position) {
|
|
3
3
|
return 'calc(' +
|
|
4
|
-
`${
|
|
4
|
+
`${formatPercent(position)} - ` +
|
|
5
5
|
`var(--dc-slider-thumb-width) * ${formatNumber(position / 2)} + ` +
|
|
6
6
|
`var(--dc-slider-thumb-width) * ${formatNumber((1 - position) / 2)}` +
|
|
7
7
|
')';
|
|
@@ -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
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) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { formatPercent } from '../../lib/index.js';
|
|
2
3
|
export function SliderTrack({ positionStart, positionEnd, children, }) {
|
|
3
|
-
const start =
|
|
4
|
-
const end =
|
|
4
|
+
const start = formatPercent(positionStart);
|
|
5
|
+
const end = formatPercent(positionEnd);
|
|
5
6
|
const background = 'linear-gradient(' +
|
|
6
7
|
'to right, ' +
|
|
7
8
|
`var(--dc-slider-track-bg) ${start}, ` +
|
|
@@ -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
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) {
|
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
|
}
|