@purr-react-styled-components/components.switch 0.0.1

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,4 @@
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>;
@@ -0,0 +1,4 @@
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>;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ISwitchProps } from '../_types';
3
+
4
+ export declare const Switch: React.ForwardRefExoticComponent<ISwitchProps & React.RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,13 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import i from "clsx";
3
+ import { memo as a } from "react";
4
+ import { S as m } from "./index-phcxjttL.js";
5
+ const s = a(({
6
+ leftLabel: e = "",
7
+ disabled: l = !1,
8
+ htmlAttributes: t
9
+ }) => e ? /* @__PURE__ */ r(m.LeftLabel, { ...t, $disabled: l, className: i("switch-label", "switch-label__left", l && "switch-label__left--disabled"), children: e }) : null);
10
+ s.displayName = "SwitchLabelLeft";
11
+ export {
12
+ s as SwitchLabelLeft
13
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),s=require("clsx"),c=require("react"),a=require("./index-CQvAkNbD.cjs"),l=c.memo(({leftLabel:e="",disabled:t=!1,htmlAttributes:i})=>e?r.jsx(a.Styled.LeftLabel,{...i,$disabled:t,className:s("switch-label","switch-label__left",t&&"switch-label__left--disabled"),children:e}):null);l.displayName="SwitchLabelLeft";exports.SwitchLabelLeft=l;
@@ -0,0 +1,13 @@
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ import r from "clsx";
3
+ import { memo as a } from "react";
4
+ import { S as m } from "./index-phcxjttL.js";
5
+ const s = a(({
6
+ rightLabel: t = "",
7
+ disabled: i = !1,
8
+ htmlAttributes: l
9
+ }) => t ? /* @__PURE__ */ e(m.RightLabel, { ...l, $disabled: i, className: r("switch-label", "switch-label__right", i && "switch-label__right--disabled"), children: t }) : null);
10
+ s.displayName = "SwitchLabelRight";
11
+ export {
12
+ s as SwitchLabelRight
13
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),s=require("clsx"),c=require("react"),a=require("./index-CQvAkNbD.cjs"),i=c.memo(({rightLabel:e="",disabled:t=!1,htmlAttributes:l})=>e?r.jsx(a.Styled.RightLabel,{...l,$disabled:t,className:s("switch-label","switch-label__right",t&&"switch-label__right--disabled"),children:e}):null);i.displayName="SwitchLabelRight";exports.SwitchLabelRight=i;
@@ -0,0 +1,13 @@
1
+ export declare const Styled: {
2
+ Container: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
3
+ Pad: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
4
+ $isOn: boolean;
5
+ $disabled: boolean;
6
+ }>> & string;
7
+ LeftLabel: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {
8
+ $disabled: boolean;
9
+ }>> & string;
10
+ RightLabel: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {
11
+ $disabled: boolean;
12
+ }>> & string;
13
+ };
@@ -0,0 +1,30 @@
1
+ import { ChangeEvent, HTMLAttributes, InputHTMLAttributes } from 'react';
2
+ import { FieldError } from 'react-hook-form';
3
+ import { IExtendable } from '@purr-core/utils.definitions';
4
+
5
+ export interface ISwitchProps {
6
+ value?: boolean;
7
+ leftLabel?: string;
8
+ rightLabel?: string;
9
+ htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
10
+ inputHtmlAttributes?: InputHTMLAttributes<HTMLInputElement> & IExtendable;
11
+ leftHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
12
+ rightHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
13
+ className?: string;
14
+ fullWidth?: boolean;
15
+ disabled?: boolean;
16
+ required?: boolean;
17
+ error?: FieldError;
18
+ isStandalone?: boolean;
19
+ onChange?: (value: boolean, e: ChangeEvent<HTMLInputElement>) => void;
20
+ }
21
+ export interface ISwitchLeftLabelProps {
22
+ leftLabel?: string;
23
+ disabled?: boolean;
24
+ htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
25
+ }
26
+ export interface ISwitchRightLabelProps {
27
+ rightLabel?: string;
28
+ disabled?: boolean;
29
+ htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
30
+ }
@@ -0,0 +1 @@
1
+ "use strict";const e=require("react/jsx-runtime"),f=require("clsx"),n=require("react"),j=require("@purr-core/hooks.sync-state-with-props"),r=require("styled-components"),p=({$disabled:t})=>t?r.css(["opacity:0.5;cursor:not-allowed;"]):r.css(["opacity:1;"]),d=({$disabled:t})=>r.css(["color:",';font-size:16px;font-family:"Verdana",sans-serif;'],t?"#ffffff80":"#ffffff"),l={Container:r.div.withConfig({displayName:"_style__Container",componentId:"sc-1bz7btz-0"})(["display:inline-flex;align-items:center;"]),Pad:r.div.withConfig({displayName:"_style__Pad",componentId:"sc-1bz7btz-1"})(["position:relative;transition:all 200ms ease-in-out;width:34px;height:14px;border-radius:7px;background-color:",';&::after{position:absolute;pointer-events:none;transition:all 200ms ease-in-out;content:"";width:20px;height:20px;border-radius:50%;background-color:',";transform:",";}& > input{position:absolute;height:20px;width:34px;top:-3px;opacity:0;cursor:",";}"],({$isOn:t,$disabled:i})=>i?t?"rgb(144, 202, 249, 0.2)":"rgb(255, 255, 255, 0.2)":t?"rgb(144, 202, 249, 0.5)":"rgb(255, 255, 255, 0.5)",({$isOn:t,$disabled:i})=>i?t?"rgb(64, 90, 112)":"rgb(117, 117, 117)":t?"rgb(144, 202, 249)":"rgb(224, 224, 224)",({$isOn:t})=>t?"translate(17px, -3px)":"translate(-3px, -3px)",({$disabled:t})=>t?"not-allowed":"pointer"),LeftLabel:r.span.withConfig({displayName:"_style__LeftLabel",componentId:"sc-1bz7btz-2"})(["margin-right:8px;",";",";"],d,p),RightLabel:r.span.withConfig({displayName:"_style__RightLabel",componentId:"sc-1bz7btz-3"})(["margin-left:8px;",";",";"],d,p)},q=n.lazy(()=>Promise.resolve().then(()=>require("./_left-label-e5Y000QP.cjs")).then(t=>({default:t.SwitchLabelLeft}))),N=n.lazy(()=>Promise.resolve().then(()=>require("./_right-label-C8otwS0i.cjs")).then(t=>({default:t.SwitchLabelRight}))),h=n.forwardRef(({value:t=!1,leftLabel:i="",rightLabel:u="",htmlAttributes:b,inputHtmlAttributes:x,leftHtmlAttributes:g,rightHtmlAttributes:m,onChange:a,className:y="",disabled:s=!1,required:w=!1,isStandalone:S=!1},L)=>{const{currentValue:o,setCurrentValue:_}=j(t,S),z=c=>{_(c.target.checked),a==null||a(c.target.checked,c)};return e.jsxs(l.Container,{...b,className:f("switch",y),children:[e.jsx(n.Suspense,{children:!!i&&e.jsx(q,{htmlAttributes:g,leftLabel:i,disabled:s})}),e.jsx(l.Pad,{$isOn:o,$disabled:s,className:f("switch-pad",o&&"switch-pad--on",s&&"switch-pad--disabled"),children:e.jsx("input",{...x,ref:L,checked:o,onChange:z,disabled:s,type:"checkbox",required:w})}),e.jsx(n.Suspense,{children:!!u&&e.jsx(N,{htmlAttributes:m,rightLabel:u,disabled:s})})]})});h.displayName="Switch";exports.Styled=l;exports.Switch=h;
@@ -0,0 +1,71 @@
1
+ import { jsxs as k, jsx as r } from "react/jsx-runtime";
2
+ import p from "clsx";
3
+ import { lazy as m, forwardRef as C, Suspense as f } from "react";
4
+ import R from "@purr-core/hooks.sync-state-with-props";
5
+ import n, { css as l } from "styled-components";
6
+ const d = ({
7
+ $disabled: t
8
+ }) => t ? l(["opacity:0.5;cursor:not-allowed;"]) : l(["opacity:1;"]), h = ({
9
+ $disabled: t
10
+ }) => l(["color:", ';font-size:16px;font-family:"Verdana",sans-serif;'], t ? "#ffffff80" : "#ffffff"), u = {
11
+ Container: n.div.withConfig({
12
+ displayName: "_style__Container",
13
+ componentId: "sc-1bz7btz-0"
14
+ })(["display:inline-flex;align-items:center;"]),
15
+ Pad: n.div.withConfig({
16
+ displayName: "_style__Pad",
17
+ componentId: "sc-1bz7btz-1"
18
+ })(["position:relative;transition:all 200ms ease-in-out;width:34px;height:14px;border-radius:7px;background-color:", ';&::after{position:absolute;pointer-events:none;transition:all 200ms ease-in-out;content:"";width:20px;height:20px;border-radius:50%;background-color:', ";transform:", ";}& > input{position:absolute;height:20px;width:34px;top:-3px;opacity:0;cursor:", ";}"], ({
19
+ $isOn: t,
20
+ $disabled: e
21
+ }) => e ? t ? "rgb(144, 202, 249, 0.2)" : "rgb(255, 255, 255, 0.2)" : t ? "rgb(144, 202, 249, 0.5)" : "rgb(255, 255, 255, 0.5)", ({
22
+ $isOn: t,
23
+ $disabled: e
24
+ }) => e ? t ? "rgb(64, 90, 112)" : "rgb(117, 117, 117)" : t ? "rgb(144, 202, 249)" : "rgb(224, 224, 224)", ({
25
+ $isOn: t
26
+ }) => t ? "translate(17px, -3px)" : "translate(-3px, -3px)", ({
27
+ $disabled: t
28
+ }) => t ? "not-allowed" : "pointer"),
29
+ LeftLabel: n.span.withConfig({
30
+ displayName: "_style__LeftLabel",
31
+ componentId: "sc-1bz7btz-2"
32
+ })(["margin-right:8px;", ";", ";"], h, d),
33
+ RightLabel: n.span.withConfig({
34
+ displayName: "_style__RightLabel",
35
+ componentId: "sc-1bz7btz-3"
36
+ })(["margin-left:8px;", ";", ";"], h, d)
37
+ }, v = m(() => import("./_left-label-czhdZw61.js").then((t) => ({
38
+ default: t.SwitchLabelLeft
39
+ }))), I = m(() => import("./_right-label-C447B9ho.js").then((t) => ({
40
+ default: t.SwitchLabelRight
41
+ }))), P = C(({
42
+ value: t = !1,
43
+ leftLabel: e = "",
44
+ rightLabel: c = "",
45
+ htmlAttributes: b,
46
+ inputHtmlAttributes: g,
47
+ leftHtmlAttributes: y,
48
+ rightHtmlAttributes: x,
49
+ onChange: a,
50
+ className: w = "",
51
+ disabled: i = !1,
52
+ required: L = !1,
53
+ isStandalone: S = !1
54
+ }, _) => {
55
+ const {
56
+ currentValue: o,
57
+ setCurrentValue: z
58
+ } = R(t, S), N = (s) => {
59
+ z(s.target.checked), a == null || a(s.target.checked, s);
60
+ };
61
+ return /* @__PURE__ */ k(u.Container, { ...b, className: p("switch", w), children: [
62
+ /* @__PURE__ */ r(f, { children: !!e && /* @__PURE__ */ r(v, { htmlAttributes: y, leftLabel: e, disabled: i }) }),
63
+ /* @__PURE__ */ r(u.Pad, { $isOn: o, $disabled: i, className: p("switch-pad", o && "switch-pad--on", i && "switch-pad--disabled"), children: /* @__PURE__ */ r("input", { ...g, ref: _, checked: o, onChange: N, disabled: i, type: "checkbox", required: L }) }),
64
+ /* @__PURE__ */ r(f, { children: !!c && /* @__PURE__ */ r(I, { htmlAttributes: x, rightLabel: c, disabled: i }) })
65
+ ] });
66
+ });
67
+ P.displayName = "Switch";
68
+ export {
69
+ u as S,
70
+ P as a
71
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CQvAkNbD.cjs");exports.Switch=e.Switch;
@@ -0,0 +1,2 @@
1
+ export * from './_components';
2
+ export * from './_types';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { a as r } from "./index-phcxjttL.js";
2
+ export {
3
+ r as Switch
4
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@purr-react-styled-components/components.switch",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "peerDependencies": {
24
+ "typescript": "*",
25
+ "react": "*",
26
+ "styled-components": "*",
27
+ "clsx": "*",
28
+ "react-hook-form": "*",
29
+ "@purr-core/utils.definitions": "0.0.4",
30
+ "@purr-core/hooks.sync-state-with-props": "0.0.2"
31
+ },
32
+ "author": "@DinhThienPhuc",
33
+ "license": "ISC",
34
+ "description": "",
35
+ "sideEffects": false,
36
+ "scripts": {
37
+ "dev": "vite build --watch",
38
+ "build": "tsc && vite build",
39
+ "lint": "eslint . --ext ts,tsx --max-warnings 0"
40
+ }
41
+ }