@purr-react-tailwindcss/components.switch 0.0.5 → 0.0.7

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("clsx"),s=require("react"),b=require("@purr-core/hooks.sync-state-with-props"),m=s.lazy(()=>Promise.resolve().then(()=>require("./_left-label-ciTiWzfK.cjs")).then(a=>({default:a.SwitchLabelLeft}))),j=s.lazy(()=>Promise.resolve().then(()=>require("./_right-label-32-rH0iQ.cjs")).then(a=>({default:a.SwitchLabelRight}))),u=s.forwardRef(({value:a=!1,leftLabel:n="",rightLabel:l="",htmlAttributes:h,inputHtmlAttributes:f,leftLabelHtmlAttributes:w,rightLabelHtmlAttributes:p,onChange:c,disabled:e=!1,required:g=!1,isStandalone:x=!1},S)=>{const{currentValue:t,setCurrentValue:d}=b(a,x),y=i=>{d(i.target.checked),c==null||c(i.target.checked,i)};return r.jsxs("div",{className:"switch inline-flex items-center",...h,children:[r.jsx(s.Suspense,{children:!!n&&r.jsx(m,{htmlAttributes:w,leftLabel:n,disabled:e})}),r.jsx("div",{className:o("relative h-3 w-8 rounded-lg transition-all duration-200 ease-in-out after:pointer-events-none after:absolute after:-left-1 after:-top-1 after:h-5 after:w-5 after:rounded-full after:transition-all after:duration-200 after:ease-in-out",e&&t&&"bg-sky-400/20 after:bg-slate-700",e&&!t&&"bg-white/20 after:bg-gray-500",!e&&t&&"bg-sky-400/50 after:bg-blue-300",!e&&!t&&"bg-white/50 after:bg-gray-200",t?"after:translate-x-5":"after:translate-x-0","switch-pad",t&&"switch-pad--on",e&&"switch-pad--disabled"),children:r.jsx("input",{ref:S,checked:t,onChange:y,disabled:e,type:"checkbox",required:g,className:o("absolute left-0 top-0 h-3 w-8 opacity-0",e?"cursor-not-allowed":"cursor-pointer"),...f})}),r.jsx(s.Suspense,{children:!!l&&r.jsx(j,{htmlAttributes:p,rightLabel:l,disabled:e})})]})});u.displayName="Switch";exports.Switch=u;
1
+ 'use strict';var u=require('clsx'),i=require('react'),q=require('@purr-core/hooks.sync-state-with-props');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var u__default=/*#__PURE__*/_interopDefault(u);var i__default=/*#__PURE__*/_interopDefault(i);var q__default=/*#__PURE__*/_interopDefault(q);var k=Object.defineProperty;var l=(t,e)=>()=>(t&&(e=t(t=0)),e);var n=(t,e)=>{for(var r in e)k(t,r,{get:e[r],enumerable:true});};var c={};n(c,{SwitchLabelLeft:()=>h});var h,f=l(()=>{h=i.memo(({leftLabel:t="",disabled:e=false,htmlAttributes:r})=>t?i__default.default.createElement("span",{className:u__default.default("mr-2 font-sans text-base",e?"cursor-not-allowed text-white/50 opacity-50":"text-white opacity-100","switch-label","switch-label__left",e&&"switch-label__left--disabled"),...r},t):null);h.displayName="SwitchLabelLeft";});var m={};n(m,{SwitchLabelRight:()=>p});var p,w=l(()=>{p=i.memo(({rightLabel:t="",disabled:e=false,htmlAttributes:r})=>t?i__default.default.createElement("span",{className:u__default.default("ml-2 font-sans text-base",e?"cursor-not-allowed text-white/50 opacity-50":"text-white opacity-100","switch-label","switch-label__right",e&&"switch-label__right--disabled"),...r},t):null);p.displayName="SwitchLabelRight";});var z=i.lazy(()=>Promise.resolve().then(()=>(f(),c)).then(t=>({default:t.SwitchLabelLeft}))),R=i.lazy(()=>Promise.resolve().then(()=>(w(),m)).then(t=>({default:t.SwitchLabelRight}))),W=i.forwardRef(({value:t=false,leftLabel:e="",rightLabel:r="",htmlAttributes:S,inputHtmlAttributes:d,leftLabelHtmlAttributes:x,rightLabelHtmlAttributes:L,onChange:y,disabled:a=false,required:v=false,isStandalone:I=false},N)=>{let{currentValue:o,setCurrentValue:_}=q__default.default(t,I),P=s=>{_(s.target.checked),y?.(s.target.checked,s);};return i__default.default.createElement("div",{className:"switch inline-flex items-center",...S},i__default.default.createElement(i.Suspense,null,!!e&&i__default.default.createElement(z,{htmlAttributes:x,leftLabel:e,disabled:a})),i__default.default.createElement("div",{className:u__default.default("relative h-3 w-8 rounded-lg transition-all duration-200 ease-in-out after:pointer-events-none after:absolute after:-left-1 after:-top-1 after:h-5 after:w-5 after:rounded-full after:transition-all after:duration-200 after:ease-in-out",a&&o&&"bg-sky-400/20 after:bg-slate-700",a&&!o&&"bg-white/20 after:bg-gray-500",!a&&o&&"bg-sky-400/50 after:bg-blue-300",!a&&!o&&"bg-white/50 after:bg-gray-200",o?"after:translate-x-5":"after:translate-x-0","switch-pad",o&&"switch-pad--on",a&&"switch-pad--disabled")},i__default.default.createElement("input",{ref:N,checked:o,onChange:P,disabled:a,type:"checkbox",required:v,className:u__default.default("absolute left-0 top-0 h-3 w-8 opacity-0",a?"cursor-not-allowed":"cursor-pointer"),...d})),i__default.default.createElement(i.Suspense,null,!!r&&i__default.default.createElement(R,{htmlAttributes:L,rightLabel:r,disabled:a})))});W.displayName="Switch";exports.Switch=W;
@@ -1,18 +1,18 @@
1
- import { ChangeEvent, HTMLAttributes, InputHTMLAttributes } from 'react';
1
+ import React, { HTMLAttributes, InputHTMLAttributes, ChangeEvent } from 'react';
2
2
  import { FieldError } from 'react-hook-form';
3
3
  import { IExtendable } from '@purr-core/utils.definitions';
4
4
 
5
- export interface ISwitchLeftLabelProps {
5
+ interface ISwitchLeftLabelProps {
6
6
  leftLabel?: string;
7
7
  disabled?: boolean;
8
8
  htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
9
9
  }
10
- export interface ISwitchRightLabelProps {
10
+ interface ISwitchRightLabelProps {
11
11
  rightLabel?: string;
12
12
  disabled?: boolean;
13
13
  htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
14
14
  }
15
- export interface ISwitchProps {
15
+ interface ISwitchProps {
16
16
  value?: boolean;
17
17
  leftLabel?: string;
18
18
  rightLabel?: string;
@@ -27,3 +27,7 @@ export interface ISwitchProps {
27
27
  isStandalone?: boolean;
28
28
  onChange?: (value: boolean, e: ChangeEvent<HTMLInputElement>) => void;
29
29
  }
30
+
31
+ declare const Switch: React.ForwardRefExoticComponent<ISwitchProps & React.RefAttributes<HTMLInputElement>>;
32
+
33
+ export { type ISwitchLeftLabelProps, type ISwitchProps, type ISwitchRightLabelProps, Switch };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,33 @@
1
- export * from './_components';
2
- export * from './_types';
1
+ import React, { HTMLAttributes, InputHTMLAttributes, ChangeEvent } from 'react';
2
+ import { FieldError } from 'react-hook-form';
3
+ import { IExtendable } from '@purr-core/utils.definitions';
4
+
5
+ interface ISwitchLeftLabelProps {
6
+ leftLabel?: string;
7
+ disabled?: boolean;
8
+ htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
9
+ }
10
+ interface ISwitchRightLabelProps {
11
+ rightLabel?: string;
12
+ disabled?: boolean;
13
+ htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
14
+ }
15
+ interface ISwitchProps {
16
+ value?: boolean;
17
+ leftLabel?: string;
18
+ rightLabel?: string;
19
+ htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
20
+ inputHtmlAttributes?: InputHTMLAttributes<HTMLInputElement> & IExtendable;
21
+ leftLabelHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
22
+ rightLabelHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
23
+ fullWidth?: boolean;
24
+ disabled?: boolean;
25
+ required?: boolean;
26
+ error?: FieldError;
27
+ isStandalone?: boolean;
28
+ onChange?: (value: boolean, e: ChangeEvent<HTMLInputElement>) => void;
29
+ }
30
+
31
+ declare const Switch: React.ForwardRefExoticComponent<ISwitchProps & React.RefAttributes<HTMLInputElement>>;
32
+
33
+ export { type ISwitchLeftLabelProps, type ISwitchProps, type ISwitchRightLabelProps, Switch };
package/dist/index.js CHANGED
@@ -1,88 +1 @@
1
- import { jsxs as S, jsx as r } from "react/jsx-runtime";
2
- import l from "clsx";
3
- import { lazy as f, forwardRef as x, Suspense as n } from "react";
4
- import k from "@purr-core/hooks.sync-state-with-props";
5
- const v = f(
6
- () => import("./_left-label-K_1UpPNK.js").then((a) => ({
7
- default: a.SwitchLabelLeft
8
- }))
9
- ), L = f(
10
- () => import("./_right-label-7YaXOwpz.js").then((a) => ({
11
- default: a.SwitchLabelRight
12
- }))
13
- ), N = x(
14
- ({
15
- value: a = !1,
16
- leftLabel: c = "",
17
- rightLabel: o = "",
18
- htmlAttributes: h,
19
- inputHtmlAttributes: u,
20
- leftLabelHtmlAttributes: p,
21
- rightLabelHtmlAttributes: m,
22
- onChange: s,
23
- disabled: t = !1,
24
- required: w = !1,
25
- isStandalone: g = !1
26
- }, d) => {
27
- const { currentValue: e, setCurrentValue: b } = k(
28
- a,
29
- g
30
- ), y = (i) => {
31
- b(i.target.checked), s == null || s(i.target.checked, i);
32
- };
33
- return /* @__PURE__ */ S("div", { className: "switch inline-flex items-center", ...h, children: [
34
- /* @__PURE__ */ r(n, { children: !!c && /* @__PURE__ */ r(
35
- v,
36
- {
37
- htmlAttributes: p,
38
- leftLabel: c,
39
- disabled: t
40
- }
41
- ) }),
42
- /* @__PURE__ */ r(
43
- "div",
44
- {
45
- className: l(
46
- "relative h-3 w-8 rounded-lg transition-all duration-200 ease-in-out after:pointer-events-none after:absolute after:-left-1 after:-top-1 after:h-5 after:w-5 after:rounded-full after:transition-all after:duration-200 after:ease-in-out",
47
- t && e && "bg-sky-400/20 after:bg-slate-700",
48
- t && !e && "bg-white/20 after:bg-gray-500",
49
- !t && e && "bg-sky-400/50 after:bg-blue-300",
50
- !t && !e && "bg-white/50 after:bg-gray-200",
51
- e ? "after:translate-x-5" : "after:translate-x-0",
52
- "switch-pad",
53
- e && "switch-pad--on",
54
- t && "switch-pad--disabled"
55
- ),
56
- children: /* @__PURE__ */ r(
57
- "input",
58
- {
59
- ref: d,
60
- checked: e,
61
- onChange: y,
62
- disabled: t,
63
- type: "checkbox",
64
- required: w,
65
- className: l(
66
- "absolute left-0 top-0 h-3 w-8 opacity-0",
67
- t ? "cursor-not-allowed" : "cursor-pointer"
68
- ),
69
- ...u
70
- }
71
- )
72
- }
73
- ),
74
- /* @__PURE__ */ r(n, { children: !!o && /* @__PURE__ */ r(
75
- L,
76
- {
77
- htmlAttributes: m,
78
- rightLabel: o,
79
- disabled: t
80
- }
81
- ) })
82
- ] });
83
- }
84
- );
85
- N.displayName = "Switch";
86
- export {
87
- N as Switch
88
- };
1
+ import u from'clsx';import i,{lazy,forwardRef,Suspense,memo}from'react';import q from'@purr-core/hooks.sync-state-with-props';var k=Object.defineProperty;var l=(t,e)=>()=>(t&&(e=t(t=0)),e);var n=(t,e)=>{for(var r in e)k(t,r,{get:e[r],enumerable:true});};var c={};n(c,{SwitchLabelLeft:()=>h});var h,f=l(()=>{h=memo(({leftLabel:t="",disabled:e=false,htmlAttributes:r})=>t?i.createElement("span",{className:u("mr-2 font-sans text-base",e?"cursor-not-allowed text-white/50 opacity-50":"text-white opacity-100","switch-label","switch-label__left",e&&"switch-label__left--disabled"),...r},t):null);h.displayName="SwitchLabelLeft";});var m={};n(m,{SwitchLabelRight:()=>p});var p,w=l(()=>{p=memo(({rightLabel:t="",disabled:e=false,htmlAttributes:r})=>t?i.createElement("span",{className:u("ml-2 font-sans text-base",e?"cursor-not-allowed text-white/50 opacity-50":"text-white opacity-100","switch-label","switch-label__right",e&&"switch-label__right--disabled"),...r},t):null);p.displayName="SwitchLabelRight";});var z=lazy(()=>Promise.resolve().then(()=>(f(),c)).then(t=>({default:t.SwitchLabelLeft}))),R=lazy(()=>Promise.resolve().then(()=>(w(),m)).then(t=>({default:t.SwitchLabelRight}))),W=forwardRef(({value:t=false,leftLabel:e="",rightLabel:r="",htmlAttributes:S,inputHtmlAttributes:d,leftLabelHtmlAttributes:x,rightLabelHtmlAttributes:L,onChange:y,disabled:a=false,required:v=false,isStandalone:I=false},N)=>{let{currentValue:o,setCurrentValue:_}=q(t,I),P=s=>{_(s.target.checked),y?.(s.target.checked,s);};return i.createElement("div",{className:"switch inline-flex items-center",...S},i.createElement(Suspense,null,!!e&&i.createElement(z,{htmlAttributes:x,leftLabel:e,disabled:a})),i.createElement("div",{className:u("relative h-3 w-8 rounded-lg transition-all duration-200 ease-in-out after:pointer-events-none after:absolute after:-left-1 after:-top-1 after:h-5 after:w-5 after:rounded-full after:transition-all after:duration-200 after:ease-in-out",a&&o&&"bg-sky-400/20 after:bg-slate-700",a&&!o&&"bg-white/20 after:bg-gray-500",!a&&o&&"bg-sky-400/50 after:bg-blue-300",!a&&!o&&"bg-white/50 after:bg-gray-200",o?"after:translate-x-5":"after:translate-x-0","switch-pad",o&&"switch-pad--on",a&&"switch-pad--disabled")},i.createElement("input",{ref:N,checked:o,onChange:P,disabled:a,type:"checkbox",required:v,className:u("absolute left-0 top-0 h-3 w-8 opacity-0",a?"cursor-not-allowed":"cursor-pointer"),...d})),i.createElement(Suspense,null,!!r&&i.createElement(R,{htmlAttributes:L,rightLabel:r,disabled:a})))});W.displayName="Switch";export{W as Switch};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purr-react-tailwindcss/components.switch",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -25,8 +25,8 @@
25
25
  "react": "*",
26
26
  "clsx": "*",
27
27
  "react-hook-form": "*",
28
- "@purr-core/utils.definitions": "0.0.10",
29
- "@purr-core/hooks.sync-state-with-props": "0.0.7"
28
+ "@purr-core/utils.definitions": "0.0.12",
29
+ "@purr-core/hooks.sync-state-with-props": "0.0.9"
30
30
  },
31
31
  "author": "@DinhThienPhuc",
32
32
  "license": "ISC",
@@ -35,6 +35,8 @@
35
35
  "scripts": {
36
36
  "dev": "vite build --watch",
37
37
  "build": "tsc && vite build",
38
+ "build:vite": "tsc && vite build",
39
+ "build:tsup": "tsup",
38
40
  "lint": "eslint . --ext ts,tsx --max-warnings 0"
39
41
  }
40
42
  }
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
- import { ISwitchLeftLabelProps } from '../_types';
3
-
4
- export declare const SwitchLabelLeft: React.MemoExoticComponent<({ leftLabel, disabled, htmlAttributes, }: ISwitchLeftLabelProps) => React.JSX.Element | null>;
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
- import { ISwitchRightLabelProps } from '../_types';
3
-
4
- export declare const SwitchLabelRight: React.MemoExoticComponent<({ rightLabel, disabled, htmlAttributes, }: ISwitchRightLabelProps) => React.JSX.Element | null>;
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
- import { ISwitchProps } from '../_types';
3
-
4
- export declare const Switch: React.ForwardRefExoticComponent<ISwitchProps & React.RefAttributes<HTMLInputElement>>;
@@ -1,27 +0,0 @@
1
- import { jsx as a } from "react/jsx-runtime";
2
- import i from "clsx";
3
- import { memo as o } from "react";
4
- const r = o(
5
- ({
6
- leftLabel: t = "",
7
- disabled: e = !1,
8
- htmlAttributes: l
9
- }) => t ? /* @__PURE__ */ a(
10
- "span",
11
- {
12
- className: i(
13
- "mr-2 font-sans text-base",
14
- e ? "cursor-not-allowed text-white/50 opacity-50" : "text-white opacity-100",
15
- "switch-label",
16
- "switch-label__left",
17
- e && "switch-label__left--disabled"
18
- ),
19
- ...l,
20
- children: t
21
- }
22
- ) : null
23
- );
24
- r.displayName = "SwitchLabelLeft";
25
- export {
26
- r as SwitchLabelLeft
27
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),a=require("clsx"),c=require("react"),l=c.memo(({leftLabel:e="",disabled:t=!1,htmlAttributes:s})=>e?i.jsx("span",{className:a("mr-2 font-sans text-base",t?"cursor-not-allowed text-white/50 opacity-50":"text-white opacity-100","switch-label","switch-label__left",t&&"switch-label__left--disabled"),...s,children:e}):null);l.displayName="SwitchLabelLeft";exports.SwitchLabelLeft=l;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("clsx"),c=require("react"),i=c.memo(({rightLabel:t="",disabled:e=!1,htmlAttributes:l})=>t?s.jsx("span",{className:a("ml-2 font-sans text-base",e?"cursor-not-allowed text-white/50 opacity-50":"text-white opacity-100","switch-label","switch-label__right",e&&"switch-label__right--disabled"),...l,children:t}):null);i.displayName="SwitchLabelRight";exports.SwitchLabelRight=i;
@@ -1,27 +0,0 @@
1
- import { jsx as l } from "react/jsx-runtime";
2
- import a from "clsx";
3
- import { memo as o } from "react";
4
- const r = o(
5
- ({
6
- rightLabel: t = "",
7
- disabled: e = !1,
8
- htmlAttributes: i
9
- }) => t ? /* @__PURE__ */ l(
10
- "span",
11
- {
12
- className: a(
13
- "ml-2 font-sans text-base",
14
- e ? "cursor-not-allowed text-white/50 opacity-50" : "text-white opacity-100",
15
- "switch-label",
16
- "switch-label__right",
17
- e && "switch-label__right--disabled"
18
- ),
19
- ...i,
20
- children: t
21
- }
22
- ) : null
23
- );
24
- r.displayName = "SwitchLabelRight";
25
- export {
26
- r as SwitchLabelRight
27
- };