@versini/ui-toggle 4.0.4 → 4.0.6

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/README.md CHANGED
@@ -1,3 +1,106 @@
1
1
  # @versini/ui-toggle
2
2
 
3
- A simple toggle component for React.
3
+ [![npm version](https://img.shields.io/npm/v/@versini/ui-toggle?style=flat-square)](https://www.npmjs.com/package/@versini/ui-toggle)
4
+
5
+ > An accessible and customizable React toggle switch component built with TypeScript and TailwindCSS.
6
+
7
+ The Toggle component provides an intuitive switch interface for binary choices with comprehensive accessibility features and customizable styling options.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Features](#features)
12
+ - [Installation](#installation)
13
+ - [Usage](#usage)
14
+ - [API](#api)
15
+
16
+ ## Features
17
+
18
+ - **♿ Accessible**: WCAG compliant with proper ARIA attributes and keyboard navigation
19
+ - **🎨 Customizable**: Multiple sizes, themes, and styling options
20
+ - **🔧 TypeScript**: Fully typed with comprehensive prop definitions
21
+ - **🌲 Tree-shakeable**: Lightweight and optimized for bundle size
22
+ - **⌨️ Keyboard Friendly**: Full keyboard navigation support
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install @versini/ui-toggle
28
+ ```
29
+
30
+ > **Note**: This component requires TailwindCSS and the `@versini/ui-styles` plugin for proper styling. See the [root README](../../README.md#tailwindcss-setup) for complete setup instructions.
31
+
32
+ ## Usage
33
+
34
+ ### Basic Toggle
35
+
36
+ ```tsx
37
+ import { Toggle } from "@versini/ui-toggle";
38
+
39
+ function App() {
40
+ const [enabled, setEnabled] = useState(false);
41
+
42
+ return (
43
+ <Toggle
44
+ label="Enable notifications"
45
+ checked={enabled}
46
+ onChange={setEnabled}
47
+ />
48
+ );
49
+ }
50
+ ```
51
+
52
+ ### Toggle with Description
53
+
54
+ ```tsx
55
+ import { Toggle } from "@versini/ui-toggle";
56
+
57
+ function App() {
58
+ return (
59
+ <Toggle
60
+ label="Dark mode"
61
+ labelHidden={false}
62
+ helperText="Switch between light and dark theme"
63
+ checked={darkMode}
64
+ onChange={setDarkMode}
65
+ />
66
+ );
67
+ }
68
+ ```
69
+
70
+ ## Examples
71
+
72
+ ### Settings Panel
73
+
74
+ ```tsx
75
+ import { Toggle } from "@versini/ui-toggle";
76
+
77
+ function SettingsPanel() {
78
+ const [settings, setSettings] = useState({
79
+ notifications: true,
80
+ autoSave: false,
81
+ darkMode: true
82
+ });
83
+
84
+ return (
85
+ <div className="space-y-4">
86
+ <Toggle
87
+ label="Push notifications"
88
+ checked={settings.notifications}
89
+ onChange={(checked) =>
90
+ setSettings({ ...settings, notifications: checked })
91
+ }
92
+ />
93
+ <Toggle
94
+ label="Auto-save"
95
+ checked={settings.autoSave}
96
+ onChange={(checked) => setSettings({ ...settings, autoSave: checked })}
97
+ />
98
+ <Toggle
99
+ label="Dark mode"
100
+ checked={settings.darkMode}
101
+ onChange={(checked) => setSettings({ ...settings, darkMode: checked })}
102
+ />
103
+ </div>
104
+ );
105
+ }
106
+ ```
@@ -1,8 +1,8 @@
1
1
  import { jsxs as p, jsx as c } from "react/jsx-runtime";
2
- import t from "clsx";
3
- const b = "av-toggle", k = () => t("peer", "h-6", "w-11", "rounded-full"), h = ({
2
+ import r from "clsx";
3
+ const b = "av-toggle", k = () => r("peer", "h-6", "w-11", "rounded-full"), h = ({
4
4
  focusMode: e
5
- }) => t(
5
+ }) => r(
6
6
  "peer-focus:outline",
7
7
  "peer-focus:outline-2",
8
8
  "peer-focus:outline-offset-2",
@@ -12,14 +12,14 @@ const b = "av-toggle", k = () => t("peer", "h-6", "w-11", "rounded-full"), h = (
12
12
  "peer-focus:outline-focus-light dark:peer-focus:outline-focus-dark": e === "alt-system",
13
13
  "peer-focus:outline-focus-dark dark:peer-focus:outline-focus-light": e === "system"
14
14
  }
15
- ), m = () => t(
15
+ ), m = () => r(
16
16
  "peer-checked:after:translate-x-full",
17
17
  // background color when checked
18
18
  "peer-checked:bg-violet-500",
19
19
  // knob circle and border color when checked
20
20
  "peer-checked:after:bg-white",
21
21
  "peer-checked:after:border-white"
22
- ), y = () => t(
22
+ ), y = () => r(
23
23
  "after:left-[2px]",
24
24
  "after:top-[2px]",
25
25
  "after:border",
@@ -33,36 +33,36 @@ const b = "av-toggle", k = () => t("peer", "h-6", "w-11", "rounded-full"), h = (
33
33
  "after:content-['']"
34
34
  ), x = ({
35
35
  mode: e,
36
- noBorder: r
37
- }) => t({
38
- border: !r,
36
+ noBorder: t
37
+ }) => r({
38
+ border: !t,
39
39
  "border-border-dark bg-surface-medium": e === "light",
40
40
  "border-border-light bg-surface-darker": e === "dark",
41
41
  "border-border-light bg-surface-darker dark:border-border-dark dark:bg-surface-medium": e === "alt-system",
42
42
  "border-border-dark bg-surface-medium dark:border-border-light dark:bg-surface-darker": e === "system"
43
43
  }), C = ({
44
44
  mode: e,
45
- labelHidden: r
46
- }) => r ? "sr-only" : t("ml-2 text-sm", {
45
+ labelHidden: t
46
+ }) => t ? "sr-only" : r("ml-2 text-sm", {
47
47
  "text-copy-dark": e === "light",
48
48
  "text-copy-lighter": e === "dark",
49
49
  "text-copy-lighter dark:text-copy-dark": e === "alt-system",
50
50
  "text-copy-dark dark:text-copy-lighter": e === "system"
51
- }), T = ({ className: e }) => t(
51
+ }), T = ({ className: e }) => r(
52
52
  b,
53
53
  "relative flex cursor-pointer items-center",
54
54
  e
55
55
  ), w = ({
56
56
  mode: e,
57
- focusMode: r,
57
+ focusMode: t,
58
58
  labelHidden: a,
59
59
  className: l,
60
60
  noBorder: o
61
61
  }) => ({
62
- toggle: t(
62
+ toggle: r(
63
63
  k(),
64
64
  x({ mode: e, noBorder: o }),
65
- h({ focusMode: r }),
65
+ h({ focusMode: t }),
66
66
  y(),
67
67
  m()
68
68
  ),
@@ -71,23 +71,23 @@ const b = "av-toggle", k = () => t("peer", "h-6", "w-11", "rounded-full"), h = (
71
71
  wrapper: T({ className: l })
72
72
  }), K = ({
73
73
  checked: e = !1,
74
- onChange: r,
74
+ onChange: t,
75
75
  label: a,
76
76
  labelHidden: l = !1,
77
77
  name: o,
78
- mode: u = "system",
79
- focusMode: g = "system",
80
- className: f,
81
- noBorder: d = !1
78
+ mode: g = "system",
79
+ focusMode: u = "system",
80
+ className: n,
81
+ noBorder: f = !1
82
82
  }) => {
83
83
  const s = w({
84
- mode: u,
85
- focusMode: g,
84
+ mode: g,
85
+ focusMode: u,
86
86
  labelHidden: l,
87
- className: f,
88
- noBorder: d
89
- }), n = (i) => {
90
- r == null || r(i.target.checked);
87
+ className: n,
88
+ noBorder: f
89
+ }), d = (i) => {
90
+ t?.(i.target.checked);
91
91
  };
92
92
  return /* @__PURE__ */ p("label", { className: s.wrapper, children: [
93
93
  /* @__PURE__ */ c(
@@ -97,7 +97,7 @@ const b = "av-toggle", k = () => t("peer", "h-6", "w-11", "rounded-full"), h = (
97
97
  checked: e,
98
98
  type: "checkbox",
99
99
  className: s.input,
100
- onChange: n
100
+ onChange: d
101
101
  }
102
102
  ),
103
103
  /* @__PURE__ */ c("div", { className: s.toggle }),
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { TOGGLE_CLASSNAME as o, Toggle as r } from "./components/Toggle/Toggle.js";
2
2
  /*!
3
- @versini/ui-toggle v4.0.4
3
+ @versini/ui-toggle v4.0.6
4
4
  © 2025 gizmette.com
5
5
  */
6
6
  try {
7
7
  window.__VERSINI_UI_TOGGLE__ || (window.__VERSINI_UI_TOGGLE__ = {
8
- version: "4.0.4",
9
- buildTime: "06/20/2025 05:21 PM EDT",
8
+ version: "4.0.6",
9
+ buildTime: "08/07/2025 04:11 PM EDT",
10
10
  homepage: "https://github.com/aversini/ui-components",
11
11
  license: "MIT"
12
12
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-toggle",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -27,6 +27,7 @@
27
27
  "dev:types": "tsup --watch src",
28
28
  "dev": "npm-run-all clean --parallel dev:js dev:types",
29
29
  "lint": "biome lint src",
30
+ "lint:fix": "biome check src --write --no-errors-on-unmatched",
30
31
  "prettier": "biome check --write --no-errors-on-unmatched",
31
32
  "start": "static-server dist --port 5173",
32
33
  "test:coverage:ui": "vitest --coverage --ui",
@@ -39,15 +40,15 @@
39
40
  "react-dom": "^18.3.1 || ^19.0.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@versini/ui-types": "5.0.4"
43
+ "@versini/ui-types": "5.0.6"
43
44
  },
44
45
  "dependencies": {
45
46
  "@tailwindcss/typography": "0.5.16",
46
47
  "clsx": "2.1.1",
47
- "tailwindcss": "4.1.10"
48
+ "tailwindcss": "4.1.11"
48
49
  },
49
50
  "sideEffects": [
50
51
  "**/*.css"
51
52
  ],
52
- "gitHead": "2fffae99315244f0662bdecbe45a89bc770f0f15"
53
+ "gitHead": "42daab1fb88c366495abbc1db78a9987de05e59b"
53
54
  }