@purr-react-styled-components/components.radio-group 0.0.6 → 0.0.8

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.
@@ -1,4 +1,4 @@
1
1
  import { default as React } from 'react';
2
2
  import { IRadioGroupOptionProps } from '../_types';
3
3
 
4
- export declare const RadioGroupOption: React.MemoExoticComponent<({ label, value, name, htmlAttributes, isStandalone, currentValue, setCurrentValue, onChange, }: IRadioGroupOptionProps) => React.JSX.Element>;
4
+ export declare const RadioGroupOption: React.MemoExoticComponent<({ label, value, name, disabled, htmlAttributes, isStandalone, currentValue, setCurrentValue, onChange, }: IRadioGroupOptionProps) => React.JSX.Element>;
package/dist/_style.d.ts CHANGED
@@ -1,9 +1,9 @@
1
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
- Label: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {
4
- $hasValue?: boolean;
2
+ Container: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
3
+ $direction: "row" | "column";
4
+ }>> & string;
5
+ OptionLabel: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, {
6
+ $disabled?: boolean;
5
7
  }>> & string;
6
- OptionLabel: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, never>> & string;
7
8
  OptionInput: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, never>> & string;
8
- OptionLabelText: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
9
9
  };
package/dist/_types.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { ChangeEvent, HTMLAttributes, LabelHTMLAttributes } from 'react';
1
+ import { ChangeEvent, HTMLAttributes, LabelHTMLAttributes, ReactNode } from 'react';
2
2
  import { IExtendable } from '@purr-core/utils.definitions';
3
3
 
4
4
  export type TRadioGroupDirection = "column" | "row";
5
5
  export interface IRadioGroupOption {
6
6
  key: string;
7
7
  value: string;
8
- label?: string;
8
+ label?: ReactNode;
9
9
  htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
10
+ disabled?: boolean;
10
11
  }
11
12
  export interface IRadioGroupOptionProps extends IRadioGroupOption {
12
13
  name: string;
@@ -16,8 +17,7 @@ export interface IRadioGroupOptionProps extends IRadioGroupOption {
16
17
  onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
17
18
  }
18
19
  export interface IRadioGroupLabelProps {
19
- label?: string;
20
- hasValue?: boolean;
20
+ label?: ReactNode;
21
21
  htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
22
22
  }
23
23
  export interface IRadioGroupProps {
@@ -25,11 +25,10 @@ export interface IRadioGroupProps {
25
25
  options: IRadioGroupOption[];
26
26
  name: string;
27
27
  value?: string;
28
- label?: string;
29
28
  isStandalone?: boolean;
30
29
  direction?: TRadioGroupDirection;
30
+ disabled?: boolean;
31
31
  htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
32
- labelHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
33
32
  optionHtmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
34
33
  onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
35
34
  }
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-BctM_nBW.cjs");exports.RadioGroup=e.RadioGroup;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),y=require("clsx"),m=require("react"),_=require("@purr-core/hooks.sync-state-with-props"),f=require("styled-components"),k=require("@purr-core/utils.helpers"),b={Container:f.div.withConfig({displayName:"_style__Container",componentId:"sc-192tru7-0"})(["display:flex;flex-direction:",";align-items:",";gap:16px;position:relative;"],({$direction:e})=>e,({$direction:e})=>e==="column"?"flex-start":"inherit"),OptionLabel:f.label.withConfig({displayName:"_style__OptionLabel",componentId:"sc-192tru7-1"})(["display:flex;align-items:center;gap:12px;cursor:",";opacity:",";"],({$disabled:e})=>e?"not-allowed":"pointer",({$disabled:e})=>e?.4:1),OptionInput:f.input.withConfig({displayName:"_style__OptionInput",componentId:"sc-192tru7-2"})(['appearance:none;width:16px;height:16px;border:1px solid #d9d9d9;border-radius:50%;background-color:#ffffff;cursor:pointer;transition:all 300ms ease-in-out;&::before{content:"";display:block;margin-top:4px;margin-left:4px;width:6px;height:6px;border-radius:50%;background-color:#ffffff;transform:scale(0);}&:checked::before{transform:scale(1);}&:checked{background-color:#44403c;border-color:#44403c;}&[type="radio" i]{margin:0;}&:hover:not(:disabled){border-color:#44403c;}'])},g=m.memo(({label:e,value:r,name:o,disabled:a,htmlAttributes:s,isStandalone:n,currentValue:p,setCurrentValue:t,onChange:i})=>{const c=n?void 0:p===r,h=m.useCallback(u=>{i==null||i(r,u),t==null||t(r)},[i,t,r]);return d.jsxs(b.OptionLabel,{$disabled:a,...s,className:"radio-group-option",children:[d.jsx(b.OptionInput,{className:y("radio-group-option-input",c?"radio-group-option-input--checked":""),name:o,type:"radio",value:r,checked:c,onChange:h,disabled:a}),e]})},k.arePropsShallowEqual(["currentValue"],(e,r,o)=>{switch(e){case"currentValue":return o.currentValue===o.value==(r.currentValue===r.value);default:return}}));g.displayName="RadioGroupOption";const x=m.forwardRef(({options:e,className:r,name:o,value:a="",onChange:s,isStandalone:n=!1,direction:p="column",disabled:t=!1,htmlAttributes:i,optionHtmlAttributes:c},h)=>{const{currentValue:u,setCurrentValue:w}=_(a,n);return d.jsx(b.Container,{...i,$direction:p,className:y("radio-group",r),children:e==null?void 0:e.map(l=>d.jsx(g,{label:l.label,value:l.value,name:o,htmlAttributes:c??l.htmlAttributes,isStandalone:n,currentValue:u,setCurrentValue:w,onChange:s,disabled:l.disabled??t},l.key))})});x.displayName="RadioGroup";exports.RadioGroup=x;
package/dist/index.js CHANGED
@@ -1,4 +1,76 @@
1
- import { R as a } from "./index-Br4lojAK.js";
1
+ import { jsxs as x, jsx as m } from "react/jsx-runtime";
2
+ import h from "clsx";
3
+ import { memo as w, useCallback as k, forwardRef as N } from "react";
4
+ import _ from "@purr-core/hooks.sync-state-with-props";
5
+ import u from "styled-components";
6
+ import { arePropsShallowEqual as O } from "@purr-core/utils.helpers";
7
+ const f = {
8
+ Container: u.div.withConfig({
9
+ displayName: "_style__Container",
10
+ componentId: "sc-192tru7-0"
11
+ })(["display:flex;flex-direction:", ";align-items:", ";gap:16px;position:relative;"], ({
12
+ $direction: r
13
+ }) => r, ({
14
+ $direction: r
15
+ }) => r === "column" ? "flex-start" : "inherit"),
16
+ OptionLabel: u.label.withConfig({
17
+ displayName: "_style__OptionLabel",
18
+ componentId: "sc-192tru7-1"
19
+ })(["display:flex;align-items:center;gap:12px;cursor:", ";opacity:", ";"], ({
20
+ $disabled: r
21
+ }) => r ? "not-allowed" : "pointer", ({
22
+ $disabled: r
23
+ }) => r ? 0.4 : 1),
24
+ OptionInput: u.input.withConfig({
25
+ displayName: "_style__OptionInput",
26
+ componentId: "sc-192tru7-2"
27
+ })(['appearance:none;width:16px;height:16px;border:1px solid #d9d9d9;border-radius:50%;background-color:#ffffff;cursor:pointer;transition:all 300ms ease-in-out;&::before{content:"";display:block;margin-top:4px;margin-left:4px;width:6px;height:6px;border-radius:50%;background-color:#ffffff;transform:scale(0);}&:checked::before{transform:scale(1);}&:checked{background-color:#44403c;border-color:#44403c;}&[type="radio" i]{margin:0;}&:hover:not(:disabled){border-color:#44403c;}'])
28
+ }, y = w(({
29
+ label: r,
30
+ value: e,
31
+ name: o,
32
+ disabled: a,
33
+ htmlAttributes: d,
34
+ isStandalone: n,
35
+ currentValue: p,
36
+ setCurrentValue: t,
37
+ onChange: i
38
+ }) => {
39
+ const c = n ? void 0 : p === e, b = k((s) => {
40
+ i == null || i(e, s), t == null || t(e);
41
+ }, [i, t, e]);
42
+ return /* @__PURE__ */ x(f.OptionLabel, { $disabled: a, ...d, className: "radio-group-option", children: [
43
+ /* @__PURE__ */ m(f.OptionInput, { className: h("radio-group-option-input", c ? "radio-group-option-input--checked" : ""), name: o, type: "radio", value: e, checked: c, onChange: b, disabled: a }),
44
+ r
45
+ ] });
46
+ }, O(["currentValue"], (r, e, o) => {
47
+ switch (r) {
48
+ case "currentValue":
49
+ return o.currentValue === o.value == (e.currentValue === e.value);
50
+ default:
51
+ return;
52
+ }
53
+ }));
54
+ y.displayName = "RadioGroupOption";
55
+ const R = N(({
56
+ options: r,
57
+ className: e,
58
+ name: o,
59
+ value: a = "",
60
+ onChange: d,
61
+ isStandalone: n = !1,
62
+ direction: p = "column",
63
+ disabled: t = !1,
64
+ htmlAttributes: i,
65
+ optionHtmlAttributes: c
66
+ }, b) => {
67
+ const {
68
+ currentValue: s,
69
+ setCurrentValue: g
70
+ } = _(a, n);
71
+ return /* @__PURE__ */ m(f.Container, { ...i, $direction: p, className: h("radio-group", e), children: r == null ? void 0 : r.map((l) => /* @__PURE__ */ m(y, { label: l.label, value: l.value, name: o, htmlAttributes: c ?? l.htmlAttributes, isStandalone: n, currentValue: s, setCurrentValue: g, onChange: d, disabled: l.disabled ?? t }, l.key)) });
72
+ });
73
+ R.displayName = "RadioGroup";
2
74
  export {
3
- a as RadioGroup
75
+ R as RadioGroup
4
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purr-react-styled-components/components.radio-group",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -25,10 +25,12 @@
25
25
  "react": "*",
26
26
  "styled-components": "*",
27
27
  "clsx": "*",
28
- "@purr-core/utils.definitions": "0.0.8",
29
- "@purr-core/utils.helpers": "0.0.8",
30
- "@purr-react-styled-components/components.flex-box": "0.0.6",
31
- "@purr-core/hooks.sync-state-with-props": "0.0.6"
28
+ "@purr-core/utils.definitions": "0.0.10",
29
+ "@purr-core/utils.helpers": "0.0.10",
30
+ "@purr-core/hooks.sync-state-with-props": "0.0.7"
31
+ },
32
+ "devDependencies": {
33
+ "@purr-react-styled-components/components.form-field": "0.0.1"
32
34
  },
33
35
  "author": "@DinhThienPhuc",
34
36
  "license": "ISC",
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
- import { IRadioGroupLabelProps } from '../_types';
3
-
4
- export declare const RadioGroupLabel: React.MemoExoticComponent<({ label, hasValue, htmlAttributes }: IRadioGroupLabelProps) => React.JSX.Element>;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),i=require("clsx"),t=require("react"),u=require("./index-BctM_nBW.cjs"),r=t.memo(({label:a="",hasValue:e,htmlAttributes:o})=>l.jsx(u.Styled.Label,{...o,$hasValue:e,className:i("radio-group-label",e&&"radio-group-label--hasValue"),children:a}));r.displayName="RadioGroupLabel";exports.RadioGroupLabel=r;
@@ -1,13 +0,0 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- import l from "clsx";
3
- import { memo as m } from "react";
4
- import { S as i } from "./index-Br4lojAK.js";
5
- const p = m(({
6
- label: r = "",
7
- hasValue: o,
8
- htmlAttributes: a
9
- }) => /* @__PURE__ */ e(i.Label, { ...a, $hasValue: o, className: l("radio-group-label", o && "radio-group-label--hasValue"), children: r }));
10
- p.displayName = "RadioGroupLabel";
11
- export {
12
- p as RadioGroupLabel
13
- };
@@ -1 +0,0 @@
1
- "use strict";const o=require("react/jsx-runtime"),y=require("clsx"),n=require("react"),w=require("@purr-core/hooks.sync-state-with-props"),O=require("@purr-react-styled-components/components.flex-box"),s=require("styled-components"),L=require("@purr-core/utils.helpers"),l={Container:s.div.withConfig({displayName:"_style__Container",componentId:"sc-192tru7-0"})(["display:flex;flex-direction:column;gap:16px;"]),Label:s.span.withConfig({displayName:"_style__Label",componentId:"sc-192tru7-1"})(["transition:color 200ms ease-in-out;color:",';font-size:16px;font-family:"Verdana",sans-serif;'],({$hasValue:e})=>e?"#90caf9":"#ffffffb3"),OptionLabel:s.label.withConfig({displayName:"_style__OptionLabel",componentId:"sc-192tru7-2"})(["display:flex;align-items:center;gap:12px;cursor:pointer;"]),OptionInput:s.input.withConfig({displayName:"_style__OptionInput",componentId:"sc-192tru7-3"})(['appearance:none;width:16px;height:16px;border:2px solid #90caf9;border-radius:50%;&::before{transition:transform 200ms ease-in-out;content:"";display:block;margin-top:2px;margin-left:2px;width:8px;height:8px;border-radius:50%;background-color:#90caf9;transform:scale(0);}&:checked::before{transform:scale(1);}&[type="radio" i]{margin:0;}']),OptionLabelText:s.span.withConfig({displayName:"_style__OptionLabelText",componentId:"sc-192tru7-4"})(['font-family:"Verdana",sans-serif;font-size:16px;color:#ffffff;'])},g=n.memo(({label:e,value:t,name:i,htmlAttributes:c,isStandalone:p,currentValue:f,setCurrentValue:r,onChange:a})=>{const u=p?void 0:f===t,m=n.useCallback(h=>{a==null||a(t,h),r==null||r(t)},[a,r,t]),x=n.useMemo(()=>o.jsx(l.OptionLabelText,{className:"radio-group-option-label",children:e}),[e]);return o.jsxs(l.OptionLabel,{...c,className:"radio-group-option",children:[o.jsx(l.OptionInput,{className:y("radio-group-option-input",u?"radio-group-option-input--checked":""),name:i,type:"radio",value:t,checked:u,onChange:m}),x]})},L.arePropsShallowEqual(["currentValue"],(e,t,i)=>{switch(e){case"currentValue":return i.currentValue===i.value==(t.currentValue===t.value);default:return}}));g.displayName="RadioGroupOption";const R=n.lazy(()=>Promise.resolve().then(()=>require("./_label-0hq1Ffuv.cjs")).then(e=>({default:e.RadioGroupLabel}))),_=n.forwardRef(({options:e,className:t,name:i,value:c="",label:p="",onChange:f,isStandalone:r=!1,direction:a="column",htmlAttributes:u,labelHtmlAttributes:m,optionHtmlAttributes:x},h)=>{const{currentValue:b,setCurrentValue:N}=w(c,r);return o.jsxs(l.Container,{...u,className:y("radio-group",t),children:[o.jsx(n.Suspense,{children:!!p&&o.jsx(R,{hasValue:!!b,label:p,htmlAttributes:m})}),o.jsx(O.FlexBox,{gap:"16px",flexDirection:a,alignItems:a==="column"?"flex-start":void 0,children:e==null?void 0:e.map(d=>o.jsx(g,{label:d.label,value:d.value,name:i,htmlAttributes:x??d.htmlAttributes,isStandalone:r,currentValue:b,setCurrentValue:N,onChange:f},d.key))})]})});_.displayName="RadioGroup";exports.RadioGroup=_;exports.Styled=l;
@@ -1,85 +0,0 @@
1
- import { jsx as i, jsxs as x } from "react/jsx-runtime";
2
- import y from "clsx";
3
- import { memo as N, useCallback as w, useMemo as O, lazy as L, forwardRef as R, Suspense as I } from "react";
4
- import k from "@purr-core/hooks.sync-state-with-props";
5
- import { FlexBox as G } from "@purr-react-styled-components/components.flex-box";
6
- import n from "styled-components";
7
- import { arePropsShallowEqual as S } from "@purr-core/utils.helpers";
8
- const d = {
9
- Container: n.div.withConfig({
10
- displayName: "_style__Container",
11
- componentId: "sc-192tru7-0"
12
- })(["display:flex;flex-direction:column;gap:16px;"]),
13
- Label: n.span.withConfig({
14
- displayName: "_style__Label",
15
- componentId: "sc-192tru7-1"
16
- })(["transition:color 200ms ease-in-out;color:", ';font-size:16px;font-family:"Verdana",sans-serif;'], ({
17
- $hasValue: e
18
- }) => e ? "#90caf9" : "#ffffffb3"),
19
- OptionLabel: n.label.withConfig({
20
- displayName: "_style__OptionLabel",
21
- componentId: "sc-192tru7-2"
22
- })(["display:flex;align-items:center;gap:12px;cursor:pointer;"]),
23
- OptionInput: n.input.withConfig({
24
- displayName: "_style__OptionInput",
25
- componentId: "sc-192tru7-3"
26
- })(['appearance:none;width:16px;height:16px;border:2px solid #90caf9;border-radius:50%;&::before{transition:transform 200ms ease-in-out;content:"";display:block;margin-top:2px;margin-left:2px;width:8px;height:8px;border-radius:50%;background-color:#90caf9;transform:scale(0);}&:checked::before{transform:scale(1);}&[type="radio" i]{margin:0;}']),
27
- OptionLabelText: n.span.withConfig({
28
- displayName: "_style__OptionLabelText",
29
- componentId: "sc-192tru7-4"
30
- })(['font-family:"Verdana",sans-serif;font-size:16px;color:#ffffff;'])
31
- }, g = N(({
32
- label: e,
33
- value: o,
34
- name: r,
35
- htmlAttributes: l,
36
- isStandalone: s,
37
- currentValue: m,
38
- setCurrentValue: t,
39
- onChange: a
40
- }) => {
41
- const p = s ? void 0 : m === o, f = w((b) => {
42
- a == null || a(o, b), t == null || t(o);
43
- }, [a, t, o]), u = O(() => /* @__PURE__ */ i(d.OptionLabelText, { className: "radio-group-option-label", children: e }), [e]);
44
- return /* @__PURE__ */ x(d.OptionLabel, { ...l, className: "radio-group-option", children: [
45
- /* @__PURE__ */ i(d.OptionInput, { className: y("radio-group-option-input", p ? "radio-group-option-input--checked" : ""), name: r, type: "radio", value: o, checked: p, onChange: f }),
46
- u
47
- ] });
48
- }, S(["currentValue"], (e, o, r) => {
49
- switch (e) {
50
- case "currentValue":
51
- return r.currentValue === r.value == (o.currentValue === o.value);
52
- default:
53
- return;
54
- }
55
- }));
56
- g.displayName = "RadioGroupOption";
57
- const V = L(() => import("./_label-3aIov1Gh.js").then((e) => ({
58
- default: e.RadioGroupLabel
59
- }))), v = R(({
60
- options: e,
61
- className: o,
62
- name: r,
63
- value: l = "",
64
- label: s = "",
65
- onChange: m,
66
- isStandalone: t = !1,
67
- direction: a = "column",
68
- htmlAttributes: p,
69
- labelHtmlAttributes: f,
70
- optionHtmlAttributes: u
71
- }, b) => {
72
- const {
73
- currentValue: h,
74
- setCurrentValue: _
75
- } = k(l, t);
76
- return /* @__PURE__ */ x(d.Container, { ...p, className: y("radio-group", o), children: [
77
- /* @__PURE__ */ i(I, { children: !!s && /* @__PURE__ */ i(V, { hasValue: !!h, label: s, htmlAttributes: f }) }),
78
- /* @__PURE__ */ i(G, { gap: "16px", flexDirection: a, alignItems: a === "column" ? "flex-start" : void 0, children: e == null ? void 0 : e.map((c) => /* @__PURE__ */ i(g, { label: c.label, value: c.value, name: r, htmlAttributes: u ?? c.htmlAttributes, isStandalone: t, currentValue: h, setCurrentValue: _, onChange: m }, c.key)) })
79
- ] });
80
- });
81
- v.displayName = "RadioGroup";
82
- export {
83
- v as R,
84
- d as S
85
- };