@aristobyte-ui/switch 2.3.6 → 2.5.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.
@@ -0,0 +1,54 @@
1
+ "use client";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ import * as React from "react";
19
+ export var Switch = function (_a) {
20
+ var onChange = _a.onChange, label = _a.label, _b = _a.alignLabel, alignLabel = _b === void 0 ? "vertical" : _b, checked = _a.checked, _c = _a.switchSize, switchSize = _c === void 0 ? "md" : _c, _d = _a.variant, variant = _d === void 0 ? "default" : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, trackIcon = _a.trackIcon, thumbIcon = _a.thumbIcon, _f = _a.className, className = _f === void 0 ? "" : _f, _g = _a.style, style = _g === void 0 ? {} : _g;
21
+ var id = React.useId();
22
+ var _h = __read(React.useState(!!checked), 2), isChecked = _h[0], setIsChecked = _h[1];
23
+ var handleChange = function () {
24
+ setIsChecked(function (prev) { return !prev; });
25
+ if (onChange)
26
+ onChange();
27
+ };
28
+ var baseClasses = [
29
+ "switch",
30
+ "switch-size-".concat(switchSize),
31
+ "switch-variant-".concat(variant),
32
+ "switch-align-label-".concat(alignLabel),
33
+ disabled && "switch--disabled",
34
+ className,
35
+ ]
36
+ .filter(Boolean)
37
+ .join(" ");
38
+ return (React.createElement("label", { htmlFor: id, className: baseClasses, style: style },
39
+ React.createElement("input", { id: id, type: "checkbox", disabled: disabled, checked: isChecked, onChange: handleChange }),
40
+ React.createElement("span", { className: "switch__track relative rounded-full overflow-hidden transition-colors duration-300 ease-in-out" },
41
+ (trackIcon === null || trackIcon === void 0 ? void 0 : trackIcon.checked) && (React.createElement("span", { className: "switch__track-icon switch__track-icon--checked absolute top-1/2 flex items-center justify-center transition-all duration-200 ease-out z-0" }, trackIcon.checked.component({
42
+ size: trackIcon.checked.size,
43
+ color: trackIcon.checked.color,
44
+ }))),
45
+ React.createElement("span", { className: "switch__thumb absolute top-1/2 left-0 bg-white rounded-full transform -translate-y-1/2 transition-all duration-200 ease-out flex items-center justify-center z-10" }, thumbIcon && (React.createElement("span", { className: "switch__thumb-icon flex items-center justify-center" }, thumbIcon.component({
46
+ size: thumbIcon.size,
47
+ color: thumbIcon.color,
48
+ })))),
49
+ (trackIcon === null || trackIcon === void 0 ? void 0 : trackIcon.unchecked) && (React.createElement("span", { className: "switch__track-icon switch__track-icon--unchecked absolute top-1/2 flex items-center justify-center transition-all duration-200 ease-out z-0" }, trackIcon.unchecked.component({
50
+ size: trackIcon.unchecked.size,
51
+ color: trackIcon.unchecked.color,
52
+ })))),
53
+ label && React.createElement("span", { className: "switch__label ml-2" }, label)));
54
+ };
@@ -0,0 +1 @@
1
+ export * from "./Switch";
@@ -0,0 +1 @@
1
+ export * from './components';
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ "use client";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __read = (this && this.__read) || function (o, n) {
37
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
38
+ if (!m) return o;
39
+ var i = m.call(o), r, ar = [], e;
40
+ try {
41
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
42
+ }
43
+ catch (error) { e = { error: error }; }
44
+ finally {
45
+ try {
46
+ if (r && !r.done && (m = i["return"])) m.call(i);
47
+ }
48
+ finally { if (e) throw e.error; }
49
+ }
50
+ return ar;
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.Switch = void 0;
54
+ var React = __importStar(require("react"));
55
+ var Switch = function (_a) {
56
+ var onChange = _a.onChange, label = _a.label, _b = _a.alignLabel, alignLabel = _b === void 0 ? "vertical" : _b, checked = _a.checked, _c = _a.switchSize, switchSize = _c === void 0 ? "md" : _c, _d = _a.variant, variant = _d === void 0 ? "default" : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, trackIcon = _a.trackIcon, thumbIcon = _a.thumbIcon, _f = _a.className, className = _f === void 0 ? "" : _f, _g = _a.style, style = _g === void 0 ? {} : _g;
57
+ var id = React.useId();
58
+ var _h = __read(React.useState(!!checked), 2), isChecked = _h[0], setIsChecked = _h[1];
59
+ var handleChange = function () {
60
+ setIsChecked(function (prev) { return !prev; });
61
+ if (onChange)
62
+ onChange();
63
+ };
64
+ var baseClasses = [
65
+ "switch",
66
+ "switch-size-".concat(switchSize),
67
+ "switch-variant-".concat(variant),
68
+ "switch-align-label-".concat(alignLabel),
69
+ disabled && "switch--disabled",
70
+ className,
71
+ ]
72
+ .filter(Boolean)
73
+ .join(" ");
74
+ return (React.createElement("label", { htmlFor: id, className: baseClasses, style: style },
75
+ React.createElement("input", { id: id, type: "checkbox", disabled: disabled, checked: isChecked, onChange: handleChange }),
76
+ React.createElement("span", { className: "switch__track relative rounded-full overflow-hidden transition-colors duration-300 ease-in-out" },
77
+ (trackIcon === null || trackIcon === void 0 ? void 0 : trackIcon.checked) && (React.createElement("span", { className: "switch__track-icon switch__track-icon--checked absolute top-1/2 flex items-center justify-center transition-all duration-200 ease-out z-0" }, trackIcon.checked.component({
78
+ size: trackIcon.checked.size,
79
+ color: trackIcon.checked.color,
80
+ }))),
81
+ React.createElement("span", { className: "switch__thumb absolute top-1/2 left-0 bg-white rounded-full transform -translate-y-1/2 transition-all duration-200 ease-out flex items-center justify-center z-10" }, thumbIcon && (React.createElement("span", { className: "switch__thumb-icon flex items-center justify-center" }, thumbIcon.component({
82
+ size: thumbIcon.size,
83
+ color: thumbIcon.color,
84
+ })))),
85
+ (trackIcon === null || trackIcon === void 0 ? void 0 : trackIcon.unchecked) && (React.createElement("span", { className: "switch__track-icon switch__track-icon--unchecked absolute top-1/2 flex items-center justify-center transition-all duration-200 ease-out z-0" }, trackIcon.unchecked.component({
86
+ size: trackIcon.unchecked.size,
87
+ color: trackIcon.unchecked.color,
88
+ })))),
89
+ label && React.createElement("span", { className: "switch__label ml-2" }, label)));
90
+ };
91
+ exports.Switch = Switch;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Switch"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./components"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aristobyte-ui/switch",
3
3
  "description": "A fully typed, customizable Switch/toggle component for React with multiple sizes, variants, label alignments, and optional icons. Built to integrate seamlessly with AristoByteUI design tokens and SCSS modules.",
4
- "version": "2.3.6",
4
+ "version": "2.5.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "author": "AristoByte <info@aristobyte.com>",
@@ -43,6 +43,10 @@
43
43
  "module": "es/src/main/index.js",
44
44
  "peerDependencies": {
45
45
  "react": "^19.1.0",
46
- "react-dom": "^19.1.0"
46
+ "react-dom": "^19.1.0",
47
+ "sass": "^1.97.3"
48
+ },
49
+ "dependencies": {
50
+ "@aristobyte-ui/utils": "2.5.0"
47
51
  }
48
52
  }
package/README.md DELETED
@@ -1,98 +0,0 @@
1
- # `@aristobyte-ui/switch`
2
-
3
- <p align="center">
4
- <img src="https://img.shields.io/badge/TypeScript-5.8-blue?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript" />
5
- <img src="https://img.shields.io/badge/Build-Turbo-green?style=for-the-badge&logo=turbo&logoColor=white" alt="TurboRepo" />
6
- <img src="https://img.shields.io/badge/Lint-Strict-red?style=for-the-badge&logo=eslint&logoColor=white" alt="ESLint" />
7
- <img src="https://img.shields.io/badge/License-MIT-black?style=for-the-badge&logo=open-source-initiative&logoColor=white" alt="License" />
8
- <img src="https://img.shields.io/badge/AristoByte-UI-purple?style=for-the-badge&logo=react&logoColor=white" alt="AristoByte UI" />
9
- <img src="https://img.shields.io/badge/Node-20.17.0+-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js >=20.17.0" />
10
- <img src="https://img.shields.io/badge/Yarn-1.22+-2C8EBB?style=for-the-badge&logo=yarn&logoColor=white" alt="Yarn >=1.22" />
11
- <img src="https://img.shields.io/badge/NPM-10.8+-CB3837?style=for-the-badge&logo=npm&logoColor=white" alt="NPM >=10.8" />
12
- </p>
13
-
14
- A highly flexible and type-safe Switch component for React with multiple sizes, variants, and label alignment options.
15
-
16
- ## 📦 Installation
17
-
18
- ```bash
19
- # Install via Yarn
20
- yarn add -D @aristobyte-ui/switch
21
-
22
- # Or via npm
23
- npm install -D @aristobyte-ui/switch
24
-
25
- # Or via pnpm
26
- pnpm add -D @aristobyte-ui/switch
27
- ```
28
-
29
- ## 🛠 Usage
30
-
31
- ```tsx
32
- import { Switch } from "@aristobyte-ui/switch";
33
-
34
- export const Demo = () => (
35
- <Switch
36
- label="Enable notifications"
37
- alignLabel="horizontal"
38
- switchSize="md"
39
- variant="primary"
40
- checked={true}
41
- onChange={() => console.log("Toggled!")}
42
- />
43
- );
44
- ```
45
-
46
- ## 📂 Presets Available
47
-
48
- **alignLabel**: `"horizontal"` | `"vertical"` (default: `"vertical"`)
49
-
50
- **switchSize**: `"xsm"` | `"sm"` | `"md"` | `"lg"` | `"xlg"` (default: `"md"`)
51
-
52
- **variant**: `"default"` | `"primary"` | `"secondary"` | `"success"` | `"error"` | `"warning"` (default: `"default"`)
53
-
54
- **trackIcon** & **thumbIcon**: Optional React components for custom icons
55
-
56
- **disabled**: Boolean flag to disable switch
57
-
58
- ## 🔧 Example in a Package
59
-
60
- ```tsx
61
- <Switch
62
- label="Dark Mode"
63
- switchSize="lg"
64
- variant="secondary"
65
- trackIcon={{ checked: CheckIcon, unchecked: CloseIcon }}
66
- thumbIcon={StarIcon}
67
- checked={false}
68
- />
69
- ```
70
-
71
- ## 📊 Why This Matters
72
-
73
- - **Performance-first:** Lightweight CSS transitions ensure smooth toggling with zero layout thrashing.
74
- - **Fully typed:** TypeScript-first API for predictable integration and IDE autocomplete.
75
- - **AristoByteUI ready:** Integrates seamlessly with design tokens and SCSS modules.
76
- - **Flexible:** Supports multiple sizes, label alignments, variants, and custom icons.
77
-
78
- ## 🏆 Philosophy
79
-
80
- - **Modular architecture:** Switch component is fully composable.
81
- - **Declarative styling:** SCSS modules keep styles maintainable and scoped.
82
- - **Strict typing & runtime flexibility:** Props fully typed while allowing runtime overrides.
83
- - **Developer experience optimized:** Easy to use with predictable behavior and minimal boilerplate.
84
-
85
- ## 📜 License
86
-
87
- [MIT](./LICENSE) © AristoByte
88
-
89
- ## 🛡 Shields Showcase
90
-
91
- <p align="center">
92
- <img src="https://img.shields.io/badge/Consistency-100%25-green?style=for-the-badge&logo=typescript" />
93
- <img src="https://img.shields.io/badge/Maintained-Active-brightgreen?style=for-the-badge&logo=github" />
94
- <img src="https://img.shields.io/badge/Strictness-High-critical?style=for-the-badge&logo=eslint" />
95
- <img src="https://img.shields.io/badge/Declarations-Enabled-blue?style=for-the-badge&logo=typescript" />
96
- <img src="https://img.shields.io/badge/Monorepo-Turbo-green?style=for-the-badge&logo=monorepo" />
97
- <img src="https://img.shields.io/badge/Interop-ESM%2FCJS-orange?style=for-the-badge&logo=javascript" />
98
- </p>