@purr-react-styled-components/components.radio-group 0.0.8 → 0.0.10
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 +51 -1
- package/dist/{_types.d.ts → index.d.cts} +10 -6
- package/dist/index.d.ts +38 -2
- package/dist/index.js +51 -76
- package/package.json +7 -5
- package/dist/_components/_option.d.ts +0 -4
- package/dist/_components/index.d.ts +0 -4
- package/dist/_style.d.ts +0 -9
package/dist/index.cjs
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';var y=require('clsx'),h=require('react'),G=require('@purr-core/hooks.sync-state-with-props'),m=require('styled-components'),utils_helpers=require('@purr-core/utils.helpers');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var y__default=/*#__PURE__*/_interopDefault(y);var h__default=/*#__PURE__*/_interopDefault(h);var G__default=/*#__PURE__*/_interopDefault(G);var m__default=/*#__PURE__*/_interopDefault(m);var i={Container:m__default.default.div`
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: ${({$direction:o})=>o};
|
|
4
|
+
align-items: ${({$direction:o})=>o==="column"?"flex-start":"inherit"};
|
|
5
|
+
gap: 16px;
|
|
6
|
+
position: relative;
|
|
7
|
+
`,OptionLabel:m__default.default.label`
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: 12px;
|
|
11
|
+
cursor: ${({$disabled:o})=>o?"not-allowed":"pointer"};
|
|
12
|
+
opacity: ${({$disabled:o})=>o?.4:1};
|
|
13
|
+
`,OptionInput:m__default.default.input`
|
|
14
|
+
appearance: none;
|
|
15
|
+
width: 16px;
|
|
16
|
+
height: 16px;
|
|
17
|
+
border: 1px solid #d9d9d9;
|
|
18
|
+
border-radius: 50%;
|
|
19
|
+
background-color: #ffffff;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
transition: all 300ms ease-in-out;
|
|
22
|
+
|
|
23
|
+
&::before {
|
|
24
|
+
content: "";
|
|
25
|
+
display: block;
|
|
26
|
+
margin-top: 4px;
|
|
27
|
+
margin-left: 4px;
|
|
28
|
+
width: 6px;
|
|
29
|
+
height: 6px;
|
|
30
|
+
border-radius: 50%;
|
|
31
|
+
background-color: #ffffff;
|
|
32
|
+
transform: scale(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&:checked::before {
|
|
36
|
+
transform: scale(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&:checked {
|
|
40
|
+
background-color: #44403c;
|
|
41
|
+
border-color: #44403c;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&[type="radio" i] {
|
|
45
|
+
margin: 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&:hover:not(:disabled) {
|
|
49
|
+
border-color: #44403c;
|
|
50
|
+
}
|
|
51
|
+
`};var f=h.memo(({label:o,value:r,name:e,disabled:t,htmlAttributes:u,isStandalone:n,currentValue:s,setCurrentValue:l,onChange:p})=>{let d=n?void 0:s===r,b=h.useCallback(c=>{p?.(r,c),l?.(r);},[p,l,r]);return h__default.default.createElement(i.OptionLabel,{$disabled:t,...u,className:"radio-group-option"},h__default.default.createElement(i.OptionInput,{className:y__default.default("radio-group-option-input",d?"radio-group-option-input--checked":""),name:e,type:"radio",value:r,checked:d,onChange:b,disabled:t}),o)},utils_helpers.arePropsShallowEqual(["currentValue"],(o,r,e)=>{if(o==="currentValue")return e.currentValue===e.value==(r.currentValue===r.value)}));f.displayName="RadioGroupOption";var S=h.forwardRef(({options:o,className:r,name:e,value:t="",onChange:u,isStandalone:n=false,direction:s="column",disabled:l=false,htmlAttributes:p,optionHtmlAttributes:d},b)=>{let{currentValue:c,setCurrentValue:x}=G__default.default(t,n);return h__default.default.createElement(i.Container,{...p,$direction:s,className:y__default.default("radio-group",r)},o?.map(a=>h__default.default.createElement(f,{key:a.key,label:a.label,value:a.value,name:e,htmlAttributes:d??a.htmlAttributes,isStandalone:n,currentValue:c,setCurrentValue:x,onChange:u,disabled:a.disabled??l})))});S.displayName="RadioGroup";exports.RadioGroup=S;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { ReactNode, 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?: ReactNode;
|
|
9
9
|
htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
10
10
|
disabled?: boolean;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
interface IRadioGroupOptionProps extends IRadioGroupOption {
|
|
13
13
|
name: string;
|
|
14
14
|
currentValue?: string;
|
|
15
15
|
isStandalone?: boolean;
|
|
16
16
|
setCurrentValue?: (value: string) => void;
|
|
17
17
|
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
interface IRadioGroupLabelProps {
|
|
20
20
|
label?: ReactNode;
|
|
21
21
|
htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
interface IRadioGroupProps {
|
|
24
24
|
className?: string;
|
|
25
25
|
options: IRadioGroupOption[];
|
|
26
26
|
name: string;
|
|
@@ -32,3 +32,7 @@ export interface IRadioGroupProps {
|
|
|
32
32
|
optionHtmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
33
33
|
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<IRadioGroupProps & React.RefAttributes<HTMLElement>>;
|
|
37
|
+
|
|
38
|
+
export { type IRadioGroupLabelProps, type IRadioGroupOption, type IRadioGroupOptionProps, type IRadioGroupProps, RadioGroup, type TRadioGroupDirection };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React, { ReactNode, 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?: ReactNode;
|
|
9
|
+
htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface IRadioGroupOptionProps extends IRadioGroupOption {
|
|
13
|
+
name: string;
|
|
14
|
+
currentValue?: string;
|
|
15
|
+
isStandalone?: boolean;
|
|
16
|
+
setCurrentValue?: (value: string) => void;
|
|
17
|
+
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
+
}
|
|
19
|
+
interface IRadioGroupLabelProps {
|
|
20
|
+
label?: ReactNode;
|
|
21
|
+
htmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
22
|
+
}
|
|
23
|
+
interface IRadioGroupProps {
|
|
24
|
+
className?: string;
|
|
25
|
+
options: IRadioGroupOption[];
|
|
26
|
+
name: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
isStandalone?: boolean;
|
|
29
|
+
direction?: TRadioGroupDirection;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
|
|
32
|
+
optionHtmlAttributes?: LabelHTMLAttributes<HTMLLabelElement> & IExtendable;
|
|
33
|
+
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<IRadioGroupProps & React.RefAttributes<HTMLElement>>;
|
|
37
|
+
|
|
38
|
+
export { type IRadioGroupLabelProps, type IRadioGroupOption, type IRadioGroupOptionProps, type IRadioGroupProps, RadioGroup, type TRadioGroupDirection };
|
package/dist/index.js
CHANGED
|
@@ -1,76 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
$
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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";
|
|
74
|
-
export {
|
|
75
|
-
R as RadioGroup
|
|
76
|
-
};
|
|
1
|
+
import y from'clsx';import h,{memo,useCallback,forwardRef}from'react';import G from'@purr-core/hooks.sync-state-with-props';import m from'styled-components';import {arePropsShallowEqual}from'@purr-core/utils.helpers';var i={Container:m.div`
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: ${({$direction:o})=>o};
|
|
4
|
+
align-items: ${({$direction:o})=>o==="column"?"flex-start":"inherit"};
|
|
5
|
+
gap: 16px;
|
|
6
|
+
position: relative;
|
|
7
|
+
`,OptionLabel:m.label`
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: 12px;
|
|
11
|
+
cursor: ${({$disabled:o})=>o?"not-allowed":"pointer"};
|
|
12
|
+
opacity: ${({$disabled:o})=>o?.4:1};
|
|
13
|
+
`,OptionInput:m.input`
|
|
14
|
+
appearance: none;
|
|
15
|
+
width: 16px;
|
|
16
|
+
height: 16px;
|
|
17
|
+
border: 1px solid #d9d9d9;
|
|
18
|
+
border-radius: 50%;
|
|
19
|
+
background-color: #ffffff;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
transition: all 300ms ease-in-out;
|
|
22
|
+
|
|
23
|
+
&::before {
|
|
24
|
+
content: "";
|
|
25
|
+
display: block;
|
|
26
|
+
margin-top: 4px;
|
|
27
|
+
margin-left: 4px;
|
|
28
|
+
width: 6px;
|
|
29
|
+
height: 6px;
|
|
30
|
+
border-radius: 50%;
|
|
31
|
+
background-color: #ffffff;
|
|
32
|
+
transform: scale(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&:checked::before {
|
|
36
|
+
transform: scale(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&:checked {
|
|
40
|
+
background-color: #44403c;
|
|
41
|
+
border-color: #44403c;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&[type="radio" i] {
|
|
45
|
+
margin: 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&:hover:not(:disabled) {
|
|
49
|
+
border-color: #44403c;
|
|
50
|
+
}
|
|
51
|
+
`};var f=memo(({label:o,value:r,name:e,disabled:t,htmlAttributes:u,isStandalone:n,currentValue:s,setCurrentValue:l,onChange:p})=>{let d=n?void 0:s===r,b=useCallback(c=>{p?.(r,c),l?.(r);},[p,l,r]);return h.createElement(i.OptionLabel,{$disabled:t,...u,className:"radio-group-option"},h.createElement(i.OptionInput,{className:y("radio-group-option-input",d?"radio-group-option-input--checked":""),name:e,type:"radio",value:r,checked:d,onChange:b,disabled:t}),o)},arePropsShallowEqual(["currentValue"],(o,r,e)=>{if(o==="currentValue")return e.currentValue===e.value==(r.currentValue===r.value)}));f.displayName="RadioGroupOption";var S=forwardRef(({options:o,className:r,name:e,value:t="",onChange:u,isStandalone:n=false,direction:s="column",disabled:l=false,htmlAttributes:p,optionHtmlAttributes:d},b)=>{let{currentValue:c,setCurrentValue:x}=G(t,n);return h.createElement(i.Container,{...p,$direction:s,className:y("radio-group",r)},o?.map(a=>h.createElement(f,{key:a.key,label:a.label,value:a.value,name:e,htmlAttributes:d??a.htmlAttributes,isStandalone:n,currentValue:c,setCurrentValue:x,onChange:u,disabled:a.disabled??l})))});S.displayName="RadioGroup";export{S as RadioGroup};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purr-react-styled-components/components.radio-group",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"react": "*",
|
|
26
26
|
"styled-components": "*",
|
|
27
27
|
"clsx": "*",
|
|
28
|
-
"@purr-core/utils.definitions": "0.0.
|
|
29
|
-
"@purr-core/utils.helpers": "0.0.
|
|
30
|
-
"@purr-core/hooks.sync-state-with-props": "0.0.
|
|
28
|
+
"@purr-core/utils.definitions": "0.0.12",
|
|
29
|
+
"@purr-core/utils.helpers": "0.0.12",
|
|
30
|
+
"@purr-core/hooks.sync-state-with-props": "0.0.9"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@purr-react-styled-components/components.form-field": "0.0.
|
|
33
|
+
"@purr-react-styled-components/components.form-field": "0.0.3"
|
|
34
34
|
},
|
|
35
35
|
"author": "@DinhThienPhuc",
|
|
36
36
|
"license": "ISC",
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
"scripts": {
|
|
40
40
|
"dev": "vite build --watch",
|
|
41
41
|
"build": "tsc && vite build",
|
|
42
|
+
"build:vite": "tsc && vite build",
|
|
43
|
+
"build:tsup": "tsup",
|
|
42
44
|
"lint": "eslint . --ext ts,tsx --max-warnings 0"
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -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, disabled, htmlAttributes, isStandalone, currentValue, setCurrentValue, onChange, }: IRadioGroupOptionProps) => React.JSX.Element>;
|
package/dist/_style.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const Styled: {
|
|
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;
|
|
7
|
-
}>> & string;
|
|
8
|
-
OptionInput: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, never>> & string;
|
|
9
|
-
};
|