@purr-react-tailwindcss/components.radio-group 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 +1 -1
- package/dist/{_types.d.ts → index.d.cts} +10 -6
- package/dist/index.d.ts +42 -2
- package/dist/index.js +1 -144
- package/package.json +6 -4
- package/dist/_components/_label.d.ts +0 -4
- package/dist/_components/_option.d.ts +0 -4
- package/dist/_components/index.d.ts +0 -4
- package/dist/_label-Bwrjrv60.js +0 -21
- package/dist/_label-VT0fJVvQ.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';var g=require('clsx'),s=require('react'),z=require('@purr-core/hooks.sync-state-with-props'),utils_helpers=require('@purr-core/utils.helpers');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);var s__default=/*#__PURE__*/_interopDefault(s);var z__default=/*#__PURE__*/_interopDefault(z);var L=Object.defineProperty;var k=(e,o)=>()=>(e&&(o=e(e=0)),o);var y=(e,o)=>{for(var r in o)L(e,r,{get:o[r],enumerable:true});};var N={};y(N,{RadioGroupLabel:()=>G});var G,R=k(()=>{G=s.memo(({label:e="",hasValue:o,htmlAttributes:r})=>s__default.default.createElement("span",{className:g__default.default("text-base transition-colors duration-200 ease-in-out",o?"text-blue-300":"text-white","radio-group-label"),...r},e));G.displayName="RadioGroupLabel";});var x=s.memo(({label:e,value:o,name:r,htmlAttributes:t,textHTMLAttributes:i,checkBoxHTMLAttributes:l,checkBoxTickHTMLAttributes:f,isStandalone:u,currentValue:m,setCurrentValue:d,onChange:c})=>{let b=s.useRef(null),a=u?b.current?.checked:m===o,h=u?void 0:m===o,n=s.useCallback(I=>{c?.(o,I),d?.(o);},[c,d,o]),w=s.useMemo(()=>s__default.default.createElement("span",{className:"radio-group-option-label text-base text-white",...i},e),[e,i]);return s__default.default.createElement("label",{className:"radio-group-option flex cursor-pointer items-center gap-3",...t},s__default.default.createElement("span",{className:"relative flex"},s__default.default.createElement("input",{className:g__default.default("h-4 w-4 appearance-none rounded-full border-2 border-blue-300","radio-group-option-input",a?"radio-group-option-input--checked":""),name:r,type:"radio",value:o,checked:h,onChange:n,ref:b,...l}),s__default.default.createElement("span",{className:g__default.default("absolute left-1 top-1 h-2 w-2 rounded-full bg-blue-300 transition-transform duration-200 ease-in-out",a?"scale-100 transform":"scale-0 transform"),...f})),w)},utils_helpers.arePropsShallowEqual(["currentValue"],(e,o,r)=>{if(e==="currentValue")return r.currentValue===r.value==(o.currentValue===o.value)}));x.displayName="RadioGroupOption";var W=s.lazy(()=>Promise.resolve().then(()=>(R(),N)).then(e=>({default:e.RadioGroupLabel}))),_=s.forwardRef(({options:e,name:o,value:r="",label:t="",onChange:i,isStandalone:l=false,direction:f="column",htmlAttributes:u,labelHtmlAttributes:m,optionHtmlAttributes:d,optionGroupHtmlAttributes:c},b)=>{let{currentValue:a,setCurrentValue:h}=z__default.default(r,l);return s__default.default.createElement("div",{className:"radio-group flex flex-col gap-4",...u},s__default.default.createElement(s.Suspense,null,!!t&&s__default.default.createElement(W,{hasValue:!!a,label:t,htmlAttributes:m})),s__default.default.createElement("div",{className:g__default.default("flex gap-4",f==="column"?"flex-col items-start":"flex-row"),...c},e?.map(n=>s__default.default.createElement(x,{...n,key:n.key,name:o,htmlAttributes:d??n.htmlAttributes,isStandalone:l,currentValue:a,setCurrentValue:h,onChange:i}))))});_.displayName="RadioGroup";exports.RadioGroup=_;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { LabelHTMLAttributes, HTMLAttributes, ChangeEvent } from 'react';
|
|
2
2
|
import { IExtendable } from '@purr-core/utils.definitions';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type TRadioGroupDirection = "column" | "row";
|
|
5
|
+
interface IRadioGroupOption {
|
|
6
6
|
key: string;
|
|
7
7
|
value: string;
|
|
8
8
|
label?: string;
|
|
@@ -11,19 +11,19 @@ export interface IRadioGroupOption {
|
|
|
11
11
|
checkBoxHTMLAttributes?: LabelHTMLAttributes<HTMLInputElement> & IExtendable;
|
|
12
12
|
checkBoxTickHTMLAttributes?: LabelHTMLAttributes<HTMLInputElement> & IExtendable;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
interface IRadioGroupOptionProps extends IRadioGroupOption {
|
|
15
15
|
name: string;
|
|
16
16
|
currentValue?: string;
|
|
17
17
|
isStandalone?: boolean;
|
|
18
18
|
setCurrentValue?: (value: string) => void;
|
|
19
19
|
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
interface IRadioGroupLabelProps {
|
|
22
22
|
label?: string;
|
|
23
23
|
hasValue?: boolean;
|
|
24
24
|
htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
interface IRadioGroupProps {
|
|
27
27
|
options: IRadioGroupOption[];
|
|
28
28
|
name: string;
|
|
29
29
|
value?: string;
|
|
@@ -36,3 +36,7 @@ export interface IRadioGroupProps {
|
|
|
36
36
|
optionGroupHtmlAttributes?: LabelHTMLAttributes<HTMLDivElement> & IExtendable;
|
|
37
37
|
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<IRadioGroupProps & React.RefAttributes<HTMLElement>>;
|
|
41
|
+
|
|
42
|
+
export { type IRadioGroupLabelProps, type IRadioGroupOption, type IRadioGroupOptionProps, type IRadioGroupProps, RadioGroup, type TRadioGroupDirection };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React, { LabelHTMLAttributes, HTMLAttributes, ChangeEvent } from 'react';
|
|
2
|
+
import { IExtendable } from '@purr-core/utils.definitions';
|
|
3
|
+
|
|
4
|
+
type TRadioGroupDirection = "column" | "row";
|
|
5
|
+
interface IRadioGroupOption {
|
|
6
|
+
key: string;
|
|
7
|
+
value: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
10
|
+
textHTMLAttributes?: LabelHTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
11
|
+
checkBoxHTMLAttributes?: LabelHTMLAttributes<HTMLInputElement> & IExtendable;
|
|
12
|
+
checkBoxTickHTMLAttributes?: LabelHTMLAttributes<HTMLInputElement> & IExtendable;
|
|
13
|
+
}
|
|
14
|
+
interface IRadioGroupOptionProps extends IRadioGroupOption {
|
|
15
|
+
name: string;
|
|
16
|
+
currentValue?: string;
|
|
17
|
+
isStandalone?: boolean;
|
|
18
|
+
setCurrentValue?: (value: string) => void;
|
|
19
|
+
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
20
|
+
}
|
|
21
|
+
interface IRadioGroupLabelProps {
|
|
22
|
+
label?: string;
|
|
23
|
+
hasValue?: boolean;
|
|
24
|
+
htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
25
|
+
}
|
|
26
|
+
interface IRadioGroupProps {
|
|
27
|
+
options: IRadioGroupOption[];
|
|
28
|
+
name: string;
|
|
29
|
+
value?: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
isStandalone?: boolean;
|
|
32
|
+
direction?: TRadioGroupDirection;
|
|
33
|
+
htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
|
|
34
|
+
labelHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
35
|
+
optionHtmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
36
|
+
optionGroupHtmlAttributes?: LabelHTMLAttributes<HTMLDivElement> & IExtendable;
|
|
37
|
+
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<IRadioGroupProps & React.RefAttributes<HTMLElement>>;
|
|
41
|
+
|
|
42
|
+
export { type IRadioGroupLabelProps, type IRadioGroupOption, type IRadioGroupOptionProps, type IRadioGroupProps, RadioGroup, type TRadioGroupDirection };
|
package/dist/index.js
CHANGED
|
@@ -1,144 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { memo as y, useRef as g, useCallback as G, useMemo as O, lazy as j, forwardRef as A, Suspense as E, createElement as L } from "react";
|
|
3
|
-
import R from "clsx";
|
|
4
|
-
import S from "@purr-core/hooks.sync-state-with-props";
|
|
5
|
-
import { arePropsShallowEqual as q } from "@purr-core/utils.helpers";
|
|
6
|
-
const N = y(
|
|
7
|
-
({
|
|
8
|
-
label: r,
|
|
9
|
-
value: e,
|
|
10
|
-
name: o,
|
|
11
|
-
htmlAttributes: c,
|
|
12
|
-
textHTMLAttributes: u,
|
|
13
|
-
checkBoxHTMLAttributes: n,
|
|
14
|
-
checkBoxTickHTMLAttributes: m,
|
|
15
|
-
isStandalone: d,
|
|
16
|
-
currentValue: p,
|
|
17
|
-
setCurrentValue: t,
|
|
18
|
-
onChange: a
|
|
19
|
-
}) => {
|
|
20
|
-
var x;
|
|
21
|
-
const f = g(null), s = d ? (x = f.current) == null ? void 0 : x.checked : p === e, h = d ? void 0 : p === e, i = G(
|
|
22
|
-
(k) => {
|
|
23
|
-
a == null || a(e, k), t == null || t(e);
|
|
24
|
-
},
|
|
25
|
-
[a, t, e]
|
|
26
|
-
), w = O(
|
|
27
|
-
() => /* @__PURE__ */ l(
|
|
28
|
-
"span",
|
|
29
|
-
{
|
|
30
|
-
className: "radio-group-option-label text-base text-white",
|
|
31
|
-
...u,
|
|
32
|
-
children: r
|
|
33
|
-
}
|
|
34
|
-
),
|
|
35
|
-
[r, u]
|
|
36
|
-
);
|
|
37
|
-
return /* @__PURE__ */ b(
|
|
38
|
-
"label",
|
|
39
|
-
{
|
|
40
|
-
className: "radio-group-option flex cursor-pointer items-center gap-3",
|
|
41
|
-
...c,
|
|
42
|
-
children: [
|
|
43
|
-
/* @__PURE__ */ b("span", { className: "relative flex", children: [
|
|
44
|
-
/* @__PURE__ */ l(
|
|
45
|
-
"input",
|
|
46
|
-
{
|
|
47
|
-
className: R(
|
|
48
|
-
"h-4 w-4 appearance-none rounded-full border-2 border-blue-300",
|
|
49
|
-
"radio-group-option-input",
|
|
50
|
-
s ? "radio-group-option-input--checked" : ""
|
|
51
|
-
),
|
|
52
|
-
name: o,
|
|
53
|
-
type: "radio",
|
|
54
|
-
value: e,
|
|
55
|
-
checked: h,
|
|
56
|
-
onChange: i,
|
|
57
|
-
ref: f,
|
|
58
|
-
...n
|
|
59
|
-
}
|
|
60
|
-
),
|
|
61
|
-
/* @__PURE__ */ l(
|
|
62
|
-
"span",
|
|
63
|
-
{
|
|
64
|
-
className: R(
|
|
65
|
-
"absolute left-1 top-1 h-2 w-2 rounded-full bg-blue-300 transition-transform duration-200 ease-in-out",
|
|
66
|
-
s ? "scale-100 transform" : "scale-0 transform"
|
|
67
|
-
),
|
|
68
|
-
...m
|
|
69
|
-
}
|
|
70
|
-
)
|
|
71
|
-
] }),
|
|
72
|
-
w
|
|
73
|
-
]
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
},
|
|
77
|
-
q(["currentValue"], (r, e, o) => {
|
|
78
|
-
switch (r) {
|
|
79
|
-
case "currentValue":
|
|
80
|
-
return o.currentValue === o.value == (e.currentValue === e.value);
|
|
81
|
-
default:
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
);
|
|
86
|
-
N.displayName = "RadioGroupOption";
|
|
87
|
-
const z = j(
|
|
88
|
-
() => import("./_label-Bwrjrv60.js").then((r) => ({
|
|
89
|
-
default: r.RadioGroupLabel
|
|
90
|
-
}))
|
|
91
|
-
), I = A(
|
|
92
|
-
({
|
|
93
|
-
options: r,
|
|
94
|
-
name: e,
|
|
95
|
-
value: o = "",
|
|
96
|
-
label: c = "",
|
|
97
|
-
onChange: u,
|
|
98
|
-
isStandalone: n = !1,
|
|
99
|
-
direction: m = "column",
|
|
100
|
-
htmlAttributes: d,
|
|
101
|
-
labelHtmlAttributes: p,
|
|
102
|
-
optionHtmlAttributes: t,
|
|
103
|
-
optionGroupHtmlAttributes: a
|
|
104
|
-
}, f) => {
|
|
105
|
-
const { currentValue: s, setCurrentValue: h } = S(o, n);
|
|
106
|
-
return /* @__PURE__ */ b("div", { className: "radio-group flex flex-col gap-4", ...d, children: [
|
|
107
|
-
/* @__PURE__ */ l(E, { children: !!c && /* @__PURE__ */ l(
|
|
108
|
-
z,
|
|
109
|
-
{
|
|
110
|
-
hasValue: !!s,
|
|
111
|
-
label: c,
|
|
112
|
-
htmlAttributes: p
|
|
113
|
-
}
|
|
114
|
-
) }),
|
|
115
|
-
/* @__PURE__ */ l(
|
|
116
|
-
"div",
|
|
117
|
-
{
|
|
118
|
-
className: R(
|
|
119
|
-
"flex gap-4",
|
|
120
|
-
m === "column" ? "flex-col items-start" : "flex-row"
|
|
121
|
-
),
|
|
122
|
-
...a,
|
|
123
|
-
children: r == null ? void 0 : r.map((i) => /* @__PURE__ */ L(
|
|
124
|
-
N,
|
|
125
|
-
{
|
|
126
|
-
...i,
|
|
127
|
-
key: i.key,
|
|
128
|
-
name: e,
|
|
129
|
-
htmlAttributes: t ?? i.htmlAttributes,
|
|
130
|
-
isStandalone: n,
|
|
131
|
-
currentValue: s,
|
|
132
|
-
setCurrentValue: h,
|
|
133
|
-
onChange: u
|
|
134
|
-
}
|
|
135
|
-
))
|
|
136
|
-
}
|
|
137
|
-
)
|
|
138
|
-
] });
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
I.displayName = "RadioGroup";
|
|
142
|
-
export {
|
|
143
|
-
I as RadioGroup
|
|
144
|
-
};
|
|
1
|
+
import g from'clsx';import s,{memo,useRef,useCallback,useMemo,lazy,forwardRef,Suspense}from'react';import z from'@purr-core/hooks.sync-state-with-props';import {arePropsShallowEqual}from'@purr-core/utils.helpers';var L=Object.defineProperty;var k=(e,o)=>()=>(e&&(o=e(e=0)),o);var y=(e,o)=>{for(var r in o)L(e,r,{get:o[r],enumerable:true});};var N={};y(N,{RadioGroupLabel:()=>G});var G,R=k(()=>{G=memo(({label:e="",hasValue:o,htmlAttributes:r})=>s.createElement("span",{className:g("text-base transition-colors duration-200 ease-in-out",o?"text-blue-300":"text-white","radio-group-label"),...r},e));G.displayName="RadioGroupLabel";});var x=memo(({label:e,value:o,name:r,htmlAttributes:t,textHTMLAttributes:i,checkBoxHTMLAttributes:l,checkBoxTickHTMLAttributes:f,isStandalone:u,currentValue:m,setCurrentValue:d,onChange:c})=>{let b=useRef(null),a=u?b.current?.checked:m===o,h=u?void 0:m===o,n=useCallback(I=>{c?.(o,I),d?.(o);},[c,d,o]),w=useMemo(()=>s.createElement("span",{className:"radio-group-option-label text-base text-white",...i},e),[e,i]);return s.createElement("label",{className:"radio-group-option flex cursor-pointer items-center gap-3",...t},s.createElement("span",{className:"relative flex"},s.createElement("input",{className:g("h-4 w-4 appearance-none rounded-full border-2 border-blue-300","radio-group-option-input",a?"radio-group-option-input--checked":""),name:r,type:"radio",value:o,checked:h,onChange:n,ref:b,...l}),s.createElement("span",{className:g("absolute left-1 top-1 h-2 w-2 rounded-full bg-blue-300 transition-transform duration-200 ease-in-out",a?"scale-100 transform":"scale-0 transform"),...f})),w)},arePropsShallowEqual(["currentValue"],(e,o,r)=>{if(e==="currentValue")return r.currentValue===r.value==(o.currentValue===o.value)}));x.displayName="RadioGroupOption";var W=lazy(()=>Promise.resolve().then(()=>(R(),N)).then(e=>({default:e.RadioGroupLabel}))),_=forwardRef(({options:e,name:o,value:r="",label:t="",onChange:i,isStandalone:l=false,direction:f="column",htmlAttributes:u,labelHtmlAttributes:m,optionHtmlAttributes:d,optionGroupHtmlAttributes:c},b)=>{let{currentValue:a,setCurrentValue:h}=z(r,l);return s.createElement("div",{className:"radio-group flex flex-col gap-4",...u},s.createElement(Suspense,null,!!t&&s.createElement(W,{hasValue:!!a,label:t,htmlAttributes:m})),s.createElement("div",{className:g("flex gap-4",f==="column"?"flex-col items-start":"flex-row"),...c},e?.map(n=>s.createElement(x,{...n,key:n.key,name:o,htmlAttributes:d??n.htmlAttributes,isStandalone:l,currentValue:a,setCurrentValue:h,onChange:i}))))});_.displayName="RadioGroup";export{_ as RadioGroup};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purr-react-tailwindcss/components.radio-group",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"typescript": "*",
|
|
25
25
|
"react": "*",
|
|
26
26
|
"clsx": "*",
|
|
27
|
-
"@purr-core/utils.
|
|
28
|
-
"@purr-core/utils.
|
|
29
|
-
"@purr-core/hooks.sync-state-with-props": "0.0.
|
|
27
|
+
"@purr-core/utils.definitions": "0.0.12",
|
|
28
|
+
"@purr-core/utils.helpers": "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 { IRadioGroupOptionProps } from '../_types';
|
|
3
|
-
|
|
4
|
-
export declare const RadioGroupOption: React.MemoExoticComponent<({ label, value, name, htmlAttributes, textHTMLAttributes, checkBoxHTMLAttributes, checkBoxTickHTMLAttributes, isStandalone, currentValue, setCurrentValue, onChange, }: IRadioGroupOptionProps) => React.JSX.Element>;
|
package/dist/_label-Bwrjrv60.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
-
import a from "clsx";
|
|
3
|
-
import { memo as i } from "react";
|
|
4
|
-
const s = i(
|
|
5
|
-
({ label: o = "", hasValue: e, htmlAttributes: r }) => /* @__PURE__ */ t(
|
|
6
|
-
"span",
|
|
7
|
-
{
|
|
8
|
-
className: a(
|
|
9
|
-
"text-base transition-colors duration-200 ease-in-out",
|
|
10
|
-
e ? "text-blue-300" : "text-white",
|
|
11
|
-
"radio-group-label"
|
|
12
|
-
),
|
|
13
|
-
...r,
|
|
14
|
-
children: o
|
|
15
|
-
}
|
|
16
|
-
)
|
|
17
|
-
);
|
|
18
|
-
s.displayName = "RadioGroupLabel";
|
|
19
|
-
export {
|
|
20
|
-
s as RadioGroupLabel
|
|
21
|
-
};
|
package/dist/_label-VT0fJVvQ.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),i=require("clsx"),s=require("react"),e=s.memo(({label:t="",hasValue:o,htmlAttributes:r})=>a.jsx("span",{className:i("text-base transition-colors duration-200 ease-in-out",o?"text-blue-300":"text-white","radio-group-label"),...r,children:t}));e.displayName="RadioGroupLabel";exports.RadioGroupLabel=e;
|