@glob-ui/slider 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/index.d.mts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +120 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +95 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Martínez E
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glob-ui/slider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A range input with a visible fill. It is the native `<input type="range">`, so keyboard, forms and screen readers work as usual.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @glob-ui/slider
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
Full docs, examples and the accessibility table: [Slider](https://github.com/kevin-martineze/GlobUI/tree/main/apps/docs/content/docs/components/slider.mdx).
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT. See [LICENSE](./LICENSE).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
declare const sliderVariants: (props?: ({
|
|
6
|
+
size?: "sm" | "md" | null | undefined;
|
|
7
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
8
|
+
interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "defaultValue" | "onChange" | "size">, VariantProps<typeof sliderVariants> {
|
|
9
|
+
value?: number;
|
|
10
|
+
defaultValue?: number;
|
|
11
|
+
/** Called with the new number on every change. */
|
|
12
|
+
onValueChange?: (value: number) => void;
|
|
13
|
+
/** Marks the slider as invalid for assistive technology (use with Field). */
|
|
14
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
15
|
+
}
|
|
16
|
+
declare const Slider: react.ForwardRefExoticComponent<SliderProps & react.RefAttributes<HTMLInputElement>>;
|
|
17
|
+
|
|
18
|
+
export { Slider, type SliderProps, sliderVariants };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
declare const sliderVariants: (props?: ({
|
|
6
|
+
size?: "sm" | "md" | null | undefined;
|
|
7
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
8
|
+
interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "defaultValue" | "onChange" | "size">, VariantProps<typeof sliderVariants> {
|
|
9
|
+
value?: number;
|
|
10
|
+
defaultValue?: number;
|
|
11
|
+
/** Called with the new number on every change. */
|
|
12
|
+
onValueChange?: (value: number) => void;
|
|
13
|
+
/** Marks the slider as invalid for assistive technology (use with Field). */
|
|
14
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
15
|
+
}
|
|
16
|
+
declare const Slider: react.ForwardRefExoticComponent<SliderProps & react.RefAttributes<HTMLInputElement>>;
|
|
17
|
+
|
|
18
|
+
export { Slider, type SliderProps, sliderVariants };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
36
|
+
var __export = (target, all) => {
|
|
37
|
+
for (var name in all)
|
|
38
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
+
};
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
+
}
|
|
46
|
+
return to;
|
|
47
|
+
};
|
|
48
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
49
|
+
|
|
50
|
+
// src/index.ts
|
|
51
|
+
var index_exports = {};
|
|
52
|
+
__export(index_exports, {
|
|
53
|
+
Slider: () => Slider,
|
|
54
|
+
sliderVariants: () => sliderVariants
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(index_exports);
|
|
57
|
+
|
|
58
|
+
// src/slider.tsx
|
|
59
|
+
var import_react = require("react");
|
|
60
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
61
|
+
var import_utils = require("@glob-ui/utils");
|
|
62
|
+
var import_hooks = require("@glob-ui/hooks");
|
|
63
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
64
|
+
var sliderVariants = (0, import_class_variance_authority.cva)(
|
|
65
|
+
[
|
|
66
|
+
// Native range input: keyboard, form submission, RTL and screen readers come with it.
|
|
67
|
+
"w-full cursor-pointer appearance-none rounded-glob-sm bg-transparent focus-visible:outline-none",
|
|
68
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
69
|
+
// Track (WebKit and Firefox). The WebKit fill is a gradient up to --glob-slider-fill.
|
|
70
|
+
"[&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full",
|
|
71
|
+
"[&::-webkit-slider-runnable-track]:bg-[linear-gradient(to_right,var(--glob-primary)_var(--glob-slider-fill),var(--glob-surface-hover)_var(--glob-slider-fill))]",
|
|
72
|
+
"[&::-moz-range-track]:h-1.5 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-glob-surface-hover",
|
|
73
|
+
"[&::-moz-range-progress]:h-1.5 [&::-moz-range-progress]:rounded-full [&::-moz-range-progress]:bg-glob-primary",
|
|
74
|
+
// Thumb. The margin centres a 16 px thumb on the 6 px track in WebKit.
|
|
75
|
+
"[&::-webkit-slider-thumb]:-mt-[5px] [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-glob-primary [&::-webkit-slider-thumb]:bg-glob-surface",
|
|
76
|
+
"[&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-glob-primary [&::-moz-range-thumb]:bg-glob-surface",
|
|
77
|
+
"[&:focus-visible::-webkit-slider-thumb]:shadow-[0_0_0_3px_var(--glob-ring)] [&:focus-visible::-moz-range-thumb]:shadow-[0_0_0_3px_var(--glob-ring)]",
|
|
78
|
+
"motion-reduce:transition-none"
|
|
79
|
+
],
|
|
80
|
+
{
|
|
81
|
+
variants: {
|
|
82
|
+
size: {
|
|
83
|
+
sm: "[&::-webkit-slider-thumb]:size-3 [&::-webkit-slider-thumb]:-mt-[4px] [&::-moz-range-thumb]:size-3",
|
|
84
|
+
md: ""
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
defaultVariants: {
|
|
88
|
+
size: "md"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
var Slider = (0, import_react.forwardRef)(
|
|
93
|
+
(_a, ref) => {
|
|
94
|
+
var _b = _a, { className, size, value, defaultValue, onValueChange, min = 0, max = 100, disabled, style } = _b, props = __objRest(_b, ["className", "size", "value", "defaultValue", "onValueChange", "min", "max", "disabled", "style"]);
|
|
95
|
+
const [current, setCurrent] = (0, import_hooks.useControllableState)(value, defaultValue != null ? defaultValue : Number(min), onValueChange);
|
|
96
|
+
const span = Number(max) - Number(min);
|
|
97
|
+
const percent = span > 0 ? (current - Number(min)) / span * 100 : 0;
|
|
98
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
99
|
+
"input",
|
|
100
|
+
__spreadValues({
|
|
101
|
+
ref,
|
|
102
|
+
type: "range",
|
|
103
|
+
min,
|
|
104
|
+
max,
|
|
105
|
+
value: current,
|
|
106
|
+
disabled,
|
|
107
|
+
onChange: (e) => setCurrent(Number(e.target.value)),
|
|
108
|
+
className: (0, import_utils.cn)(sliderVariants({ size, className })),
|
|
109
|
+
style: __spreadProps(__spreadValues({}, style), { ["--glob-slider-fill"]: `${percent}%` })
|
|
110
|
+
}, props)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
Slider.displayName = "Slider";
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
Slider,
|
|
118
|
+
sliderVariants
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/slider.tsx"],"sourcesContent":["export { Slider, sliderVariants } from \"./slider\"\nexport type { SliderProps } from \"./slider\"\n","\"use client\"\n\nimport { forwardRef } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\nimport { useControllableState } from \"@glob-ui/hooks\"\n\nconst sliderVariants = cva(\n [\n // Native range input: keyboard, form submission, RTL and screen readers come with it.\n \"w-full cursor-pointer appearance-none rounded-glob-sm bg-transparent focus-visible:outline-none\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n // Track (WebKit and Firefox). The WebKit fill is a gradient up to --glob-slider-fill.\n \"[&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full\",\n \"[&::-webkit-slider-runnable-track]:bg-[linear-gradient(to_right,var(--glob-primary)_var(--glob-slider-fill),var(--glob-surface-hover)_var(--glob-slider-fill))]\",\n \"[&::-moz-range-track]:h-1.5 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-glob-surface-hover\",\n \"[&::-moz-range-progress]:h-1.5 [&::-moz-range-progress]:rounded-full [&::-moz-range-progress]:bg-glob-primary\",\n // Thumb. The margin centres a 16 px thumb on the 6 px track in WebKit.\n \"[&::-webkit-slider-thumb]:-mt-[5px] [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-glob-primary [&::-webkit-slider-thumb]:bg-glob-surface\",\n \"[&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-glob-primary [&::-moz-range-thumb]:bg-glob-surface\",\n \"[&:focus-visible::-webkit-slider-thumb]:shadow-[0_0_0_3px_var(--glob-ring)] [&:focus-visible::-moz-range-thumb]:shadow-[0_0_0_3px_var(--glob-ring)]\",\n \"motion-reduce:transition-none\",\n ],\n {\n variants: {\n size: {\n sm: \"[&::-webkit-slider-thumb]:size-3 [&::-webkit-slider-thumb]:-mt-[4px] [&::-moz-range-thumb]:size-3\",\n md: \"\",\n },\n },\n defaultVariants: {\n size: \"md\",\n },\n }\n)\n\nexport interface SliderProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"type\" | \"value\" | \"defaultValue\" | \"onChange\" | \"size\">,\n VariantProps<typeof sliderVariants> {\n value?: number\n defaultValue?: number\n /** Called with the new number on every change. */\n onValueChange?: (value: number) => void\n /** Marks the slider as invalid for assistive technology (use with Field). */\n \"aria-invalid\"?: boolean | \"true\" | \"false\"\n}\n\nconst Slider = forwardRef<HTMLInputElement, SliderProps>(\n ({ className, size, value, defaultValue, onValueChange, min = 0, max = 100, disabled, style, ...props }, ref) => {\n const [current, setCurrent] = useControllableState<number>(value, defaultValue ?? Number(min), onValueChange)\n const span = Number(max) - Number(min)\n const percent = span > 0 ? ((current - Number(min)) / span) * 100 : 0\n\n return (\n <input\n ref={ref}\n type=\"range\"\n min={min}\n max={max}\n value={current}\n disabled={disabled}\n onChange={(e) => setCurrent(Number(e.target.value))}\n className={cn(sliderVariants({ size, className }))}\n style={{ ...style, [\"--glob-slider-fill\" as string]: `${percent}%` }}\n {...props}\n />\n )\n }\n)\nSlider.displayName = \"Slider\"\n\nexport { Slider, sliderVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAA2B;AAC3B,sCAAuC;AACvC,mBAAmB;AACnB,mBAAqC;AAiD/B;AA/CN,IAAM,qBAAiB;AAAA,EACrB;AAAA;AAAA,IAEE;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAaA,IAAM,aAAS;AAAA,EACb,CAAC,IAAwG,QAAQ;AAAhH,iBAAE,aAAW,MAAM,OAAO,cAAc,eAAe,MAAM,GAAG,MAAM,KAAK,UAAU,MAhDxF,IAgDG,IAA+F,kBAA/F,IAA+F,CAA7F,aAAW,QAAM,SAAO,gBAAc,iBAAe,OAAS,OAAW,YAAU;AACpF,UAAM,CAAC,SAAS,UAAU,QAAI,mCAA6B,OAAO,sCAAgB,OAAO,GAAG,GAAG,aAAa;AAC5G,UAAM,OAAO,OAAO,GAAG,IAAI,OAAO,GAAG;AACrC,UAAM,UAAU,OAAO,KAAM,UAAU,OAAO,GAAG,KAAK,OAAQ,MAAM;AAEpE,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,MAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,MAAM,WAAW,OAAO,EAAE,OAAO,KAAK,CAAC;AAAA,QAClD,eAAW,iBAAG,eAAe,EAAE,MAAM,UAAU,CAAC,CAAC;AAAA,QACjD,OAAO,iCAAK,QAAL,EAAY,CAAC,oBAA8B,GAAG,GAAG,OAAO,IAAI;AAAA,SAC/D;AAAA,IACN;AAAA,EAEJ;AACF;AACA,OAAO,cAAc;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/slider.tsx
|
|
35
|
+
import { forwardRef } from "react";
|
|
36
|
+
import { cva } from "class-variance-authority";
|
|
37
|
+
import { cn } from "@glob-ui/utils";
|
|
38
|
+
import { useControllableState } from "@glob-ui/hooks";
|
|
39
|
+
import { jsx } from "react/jsx-runtime";
|
|
40
|
+
var sliderVariants = cva(
|
|
41
|
+
[
|
|
42
|
+
// Native range input: keyboard, form submission, RTL and screen readers come with it.
|
|
43
|
+
"w-full cursor-pointer appearance-none rounded-glob-sm bg-transparent focus-visible:outline-none",
|
|
44
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
45
|
+
// Track (WebKit and Firefox). The WebKit fill is a gradient up to --glob-slider-fill.
|
|
46
|
+
"[&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full",
|
|
47
|
+
"[&::-webkit-slider-runnable-track]:bg-[linear-gradient(to_right,var(--glob-primary)_var(--glob-slider-fill),var(--glob-surface-hover)_var(--glob-slider-fill))]",
|
|
48
|
+
"[&::-moz-range-track]:h-1.5 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-glob-surface-hover",
|
|
49
|
+
"[&::-moz-range-progress]:h-1.5 [&::-moz-range-progress]:rounded-full [&::-moz-range-progress]:bg-glob-primary",
|
|
50
|
+
// Thumb. The margin centres a 16 px thumb on the 6 px track in WebKit.
|
|
51
|
+
"[&::-webkit-slider-thumb]:-mt-[5px] [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-glob-primary [&::-webkit-slider-thumb]:bg-glob-surface",
|
|
52
|
+
"[&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-glob-primary [&::-moz-range-thumb]:bg-glob-surface",
|
|
53
|
+
"[&:focus-visible::-webkit-slider-thumb]:shadow-[0_0_0_3px_var(--glob-ring)] [&:focus-visible::-moz-range-thumb]:shadow-[0_0_0_3px_var(--glob-ring)]",
|
|
54
|
+
"motion-reduce:transition-none"
|
|
55
|
+
],
|
|
56
|
+
{
|
|
57
|
+
variants: {
|
|
58
|
+
size: {
|
|
59
|
+
sm: "[&::-webkit-slider-thumb]:size-3 [&::-webkit-slider-thumb]:-mt-[4px] [&::-moz-range-thumb]:size-3",
|
|
60
|
+
md: ""
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
defaultVariants: {
|
|
64
|
+
size: "md"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
var Slider = forwardRef(
|
|
69
|
+
(_a, ref) => {
|
|
70
|
+
var _b = _a, { className, size, value, defaultValue, onValueChange, min = 0, max = 100, disabled, style } = _b, props = __objRest(_b, ["className", "size", "value", "defaultValue", "onValueChange", "min", "max", "disabled", "style"]);
|
|
71
|
+
const [current, setCurrent] = useControllableState(value, defaultValue != null ? defaultValue : Number(min), onValueChange);
|
|
72
|
+
const span = Number(max) - Number(min);
|
|
73
|
+
const percent = span > 0 ? (current - Number(min)) / span * 100 : 0;
|
|
74
|
+
return /* @__PURE__ */ jsx(
|
|
75
|
+
"input",
|
|
76
|
+
__spreadValues({
|
|
77
|
+
ref,
|
|
78
|
+
type: "range",
|
|
79
|
+
min,
|
|
80
|
+
max,
|
|
81
|
+
value: current,
|
|
82
|
+
disabled,
|
|
83
|
+
onChange: (e) => setCurrent(Number(e.target.value)),
|
|
84
|
+
className: cn(sliderVariants({ size, className })),
|
|
85
|
+
style: __spreadProps(__spreadValues({}, style), { ["--glob-slider-fill"]: `${percent}%` })
|
|
86
|
+
}, props)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
Slider.displayName = "Slider";
|
|
91
|
+
export {
|
|
92
|
+
Slider,
|
|
93
|
+
sliderVariants
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/slider.tsx"],"sourcesContent":["\"use client\"\n\nimport { forwardRef } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\nimport { useControllableState } from \"@glob-ui/hooks\"\n\nconst sliderVariants = cva(\n [\n // Native range input: keyboard, form submission, RTL and screen readers come with it.\n \"w-full cursor-pointer appearance-none rounded-glob-sm bg-transparent focus-visible:outline-none\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n // Track (WebKit and Firefox). The WebKit fill is a gradient up to --glob-slider-fill.\n \"[&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full\",\n \"[&::-webkit-slider-runnable-track]:bg-[linear-gradient(to_right,var(--glob-primary)_var(--glob-slider-fill),var(--glob-surface-hover)_var(--glob-slider-fill))]\",\n \"[&::-moz-range-track]:h-1.5 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-glob-surface-hover\",\n \"[&::-moz-range-progress]:h-1.5 [&::-moz-range-progress]:rounded-full [&::-moz-range-progress]:bg-glob-primary\",\n // Thumb. The margin centres a 16 px thumb on the 6 px track in WebKit.\n \"[&::-webkit-slider-thumb]:-mt-[5px] [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-glob-primary [&::-webkit-slider-thumb]:bg-glob-surface\",\n \"[&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-glob-primary [&::-moz-range-thumb]:bg-glob-surface\",\n \"[&:focus-visible::-webkit-slider-thumb]:shadow-[0_0_0_3px_var(--glob-ring)] [&:focus-visible::-moz-range-thumb]:shadow-[0_0_0_3px_var(--glob-ring)]\",\n \"motion-reduce:transition-none\",\n ],\n {\n variants: {\n size: {\n sm: \"[&::-webkit-slider-thumb]:size-3 [&::-webkit-slider-thumb]:-mt-[4px] [&::-moz-range-thumb]:size-3\",\n md: \"\",\n },\n },\n defaultVariants: {\n size: \"md\",\n },\n }\n)\n\nexport interface SliderProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"type\" | \"value\" | \"defaultValue\" | \"onChange\" | \"size\">,\n VariantProps<typeof sliderVariants> {\n value?: number\n defaultValue?: number\n /** Called with the new number on every change. */\n onValueChange?: (value: number) => void\n /** Marks the slider as invalid for assistive technology (use with Field). */\n \"aria-invalid\"?: boolean | \"true\" | \"false\"\n}\n\nconst Slider = forwardRef<HTMLInputElement, SliderProps>(\n ({ className, size, value, defaultValue, onValueChange, min = 0, max = 100, disabled, style, ...props }, ref) => {\n const [current, setCurrent] = useControllableState<number>(value, defaultValue ?? Number(min), onValueChange)\n const span = Number(max) - Number(min)\n const percent = span > 0 ? ((current - Number(min)) / span) * 100 : 0\n\n return (\n <input\n ref={ref}\n type=\"range\"\n min={min}\n max={max}\n value={current}\n disabled={disabled}\n onChange={(e) => setCurrent(Number(e.target.value))}\n className={cn(sliderVariants({ size, className }))}\n style={{ ...style, [\"--glob-slider-fill\" as string]: `${percent}%` }}\n {...props}\n />\n )\n }\n)\nSlider.displayName = \"Slider\"\n\nexport { Slider, sliderVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAC3B,SAAS,WAA8B;AACvC,SAAS,UAAU;AACnB,SAAS,4BAA4B;AAiD/B;AA/CN,IAAM,iBAAiB;AAAA,EACrB;AAAA;AAAA,IAEE;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAaA,IAAM,SAAS;AAAA,EACb,CAAC,IAAwG,QAAQ;AAAhH,iBAAE,aAAW,MAAM,OAAO,cAAc,eAAe,MAAM,GAAG,MAAM,KAAK,UAAU,MAhDxF,IAgDG,IAA+F,kBAA/F,IAA+F,CAA7F,aAAW,QAAM,SAAO,gBAAc,iBAAe,OAAS,OAAW,YAAU;AACpF,UAAM,CAAC,SAAS,UAAU,IAAI,qBAA6B,OAAO,sCAAgB,OAAO,GAAG,GAAG,aAAa;AAC5G,UAAM,OAAO,OAAO,GAAG,IAAI,OAAO,GAAG;AACrC,UAAM,UAAU,OAAO,KAAM,UAAU,OAAO,GAAG,KAAK,OAAQ,MAAM;AAEpE,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,MAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,MAAM,WAAW,OAAO,EAAE,OAAO,KAAK,CAAC;AAAA,QAClD,WAAW,GAAG,eAAe,EAAE,MAAM,UAAU,CAAC,CAAC;AAAA,QACjD,OAAO,iCAAK,QAAL,EAAY,CAAC,oBAA8B,GAAG,GAAG,OAAO,IAAI;AAAA,SAC/D;AAAA,IACN;AAAA,EAEJ;AACF;AACA,OAAO,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glob-ui/slider",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^19"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@glob-ui/hooks": "0.2.0",
|
|
30
|
+
"@glob-ui/utils": "0.2.0",
|
|
31
|
+
"class-variance-authority": "^0.7.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^8.5.1"
|
|
35
|
+
},
|
|
36
|
+
"description": "A range input with a visible fill. It is the native `<input type=\"range\">`, so keyboard, forms and screen readers work as usual.",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"react",
|
|
39
|
+
"glob-ui",
|
|
40
|
+
"components",
|
|
41
|
+
"accessible",
|
|
42
|
+
"tailwind",
|
|
43
|
+
"slider"
|
|
44
|
+
],
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"author": "Kevin Martínez E",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/kevin-martineze/GlobUI.git",
|
|
50
|
+
"directory": "packages/slider"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/kevin-martineze/GlobUI#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/kevin-martineze/GlobUI/issues"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"provenance": true
|
|
59
|
+
},
|
|
60
|
+
"sideEffects": false,
|
|
61
|
+
"type": "commonjs",
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18.18"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsup",
|
|
67
|
+
"dev": "tsup --watch --no-clean"
|
|
68
|
+
}
|
|
6
69
|
}
|