@zauru-sdk/components 1.0.81 → 1.0.83
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/CHANGELOG.md +16 -0
- package/dist/Form/RadioButtonGroup/index.d.ts +20 -0
- package/dist/Form/index.d.ts +1 -0
- package/dist/cjs/Form/RadioButtonGroup/index.js +26 -0
- package/dist/cjs/Form/index.js +1 -0
- package/dist/esm/Form/RadioButtonGroup/index.js +21 -0
- package/dist/esm/Form/index.js +1 -0
- package/package.json +6 -6
- package/src/Form/RadioButtonGroup/index.tsx +108 -0
- package/src/Form/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.0.83](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.82...v1.0.83) (2024-08-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @zauru-sdk/components
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.0.82](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.81...v1.0.82) (2024-07-31)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @zauru-sdk/components
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [1.0.81](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.80...v1.0.81) (2024-07-31)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @zauru-sdk/components
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type RadioButtonProps = {
|
|
3
|
+
id?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
options: {
|
|
6
|
+
label: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}[];
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
orientation?: "vertical" | "horizontal";
|
|
11
|
+
onChange?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
error?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
helpText?: string;
|
|
16
|
+
className?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const RadioButtonGroupWithoutValidation: (props: RadioButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare const RadioButtonGroup: (props: RadioButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export {};
|
package/dist/Form/index.d.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RadioButtonGroup = exports.RadioButtonGroupWithoutValidation = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const icons_1 = require("@zauru-sdk/icons");
|
|
6
|
+
const redux_1 = require("@zauru-sdk/redux");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const RadioButtonGroupWithoutValidation = (props) => {
|
|
9
|
+
const { id, name, options, defaultValue, orientation = "vertical", onChange, disabled = false, error, title, helpText, className, } = props;
|
|
10
|
+
const [selectedValue, setSelectedValue] = (0, react_1.useState)(defaultValue);
|
|
11
|
+
const [showTooltip, setShowTooltip] = (0, react_1.useState)(false);
|
|
12
|
+
const handleChange = (event) => {
|
|
13
|
+
setSelectedValue(event.target.value);
|
|
14
|
+
onChange && onChange(event.target.value, event);
|
|
15
|
+
};
|
|
16
|
+
const containerClass = orientation === "vertical" ? "flex flex-col" : "flex flex-row space-x-5";
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: `radio-button-group ${className}`, children: [title && ((0, jsx_runtime_1.jsx)("label", { htmlFor: id, className: "block mb-1 text-sm font-medium text-gray-700", children: title })), (0, jsx_runtime_1.jsx)("div", { className: containerClass, children: options.map((option, index) => ((0, jsx_runtime_1.jsxs)("label", { className: "flex items-center space-x-2", children: [(0, jsx_runtime_1.jsx)("input", { type: "radio", id: id ? `${id}-${option.value}` : undefined, name: name, value: option.value, checked: selectedValue === option.value, onChange: handleChange, disabled: disabled, className: "focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300" }), (0, jsx_runtime_1.jsx)("span", { className: "text-sm text-gray-700", children: option.label })] }, index))) }), helpText && ((0, jsx_runtime_1.jsxs)("div", { className: "relative cursor-pointer", onMouseEnter: () => setShowTooltip(true), onMouseLeave: () => setShowTooltip(false), children: [(0, jsx_runtime_1.jsx)(icons_1.IdeaIconSVG, {}), showTooltip && ((0, jsx_runtime_1.jsx)("div", { className: "absolute mt-2 p-2 bg-white border rounded shadow text-black z-50", children: helpText }))] })), error && ((0, jsx_runtime_1.jsxs)("p", { className: "mt-2 text-sm text-red-600", children: [(0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: "Oops!" }), " ", error] }))] }));
|
|
18
|
+
};
|
|
19
|
+
exports.RadioButtonGroupWithoutValidation = RadioButtonGroupWithoutValidation;
|
|
20
|
+
const RadioButtonGroup = (props) => {
|
|
21
|
+
const { formValidations } = (0, redux_1.useAppSelector)((state) => state.formValidation);
|
|
22
|
+
const error = formValidations[props.name ?? "-1"];
|
|
23
|
+
props = { ...props, error };
|
|
24
|
+
return (0, jsx_runtime_1.jsx)(exports.RadioButtonGroupWithoutValidation, { ...props });
|
|
25
|
+
};
|
|
26
|
+
exports.RadioButtonGroup = RadioButtonGroup;
|
package/dist/cjs/Form/index.js
CHANGED
|
@@ -27,3 +27,4 @@ __exportStar(require("./TextArea/index.js"), exports);
|
|
|
27
27
|
__exportStar(require("./TextField/index.js"), exports);
|
|
28
28
|
__exportStar(require("./TimePicker/index.js"), exports);
|
|
29
29
|
__exportStar(require("./YesNo/index.js"), exports);
|
|
30
|
+
__exportStar(require("./RadioButtonGroup/index.js"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { IdeaIconSVG } from "@zauru-sdk/icons";
|
|
3
|
+
import { useAppSelector } from "@zauru-sdk/redux";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
export const RadioButtonGroupWithoutValidation = (props) => {
|
|
6
|
+
const { id, name, options, defaultValue, orientation = "vertical", onChange, disabled = false, error, title, helpText, className, } = props;
|
|
7
|
+
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
|
8
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
9
|
+
const handleChange = (event) => {
|
|
10
|
+
setSelectedValue(event.target.value);
|
|
11
|
+
onChange && onChange(event.target.value, event);
|
|
12
|
+
};
|
|
13
|
+
const containerClass = orientation === "vertical" ? "flex flex-col" : "flex flex-row space-x-5";
|
|
14
|
+
return (_jsxs("div", { className: `radio-button-group ${className}`, children: [title && (_jsx("label", { htmlFor: id, className: "block mb-1 text-sm font-medium text-gray-700", children: title })), _jsx("div", { className: containerClass, children: options.map((option, index) => (_jsxs("label", { className: "flex items-center space-x-2", children: [_jsx("input", { type: "radio", id: id ? `${id}-${option.value}` : undefined, name: name, value: option.value, checked: selectedValue === option.value, onChange: handleChange, disabled: disabled, className: "focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300" }), _jsx("span", { className: "text-sm text-gray-700", children: option.label })] }, index))) }), helpText && (_jsxs("div", { className: "relative cursor-pointer", onMouseEnter: () => setShowTooltip(true), onMouseLeave: () => setShowTooltip(false), children: [_jsx(IdeaIconSVG, {}), showTooltip && (_jsx("div", { className: "absolute mt-2 p-2 bg-white border rounded shadow text-black z-50", children: helpText }))] })), error && (_jsxs("p", { className: "mt-2 text-sm text-red-600", children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] }))] }));
|
|
15
|
+
};
|
|
16
|
+
export const RadioButtonGroup = (props) => {
|
|
17
|
+
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
18
|
+
const error = formValidations[props.name ?? "-1"];
|
|
19
|
+
props = { ...props, error };
|
|
20
|
+
return _jsx(RadioButtonGroupWithoutValidation, { ...props });
|
|
21
|
+
};
|
package/dist/esm/Form/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.83",
|
|
4
4
|
"description": "Componentes reutilizables en las WebApps de Zauru.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@reduxjs/toolkit": "^2.2.1",
|
|
35
35
|
"@remix-run/react": "^2.8.1",
|
|
36
|
-
"@zauru-sdk/common": "^1.0.
|
|
37
|
-
"@zauru-sdk/hooks": "^1.0.
|
|
36
|
+
"@zauru-sdk/common": "^1.0.83",
|
|
37
|
+
"@zauru-sdk/hooks": "^1.0.83",
|
|
38
38
|
"@zauru-sdk/icons": "^1.0.60",
|
|
39
|
-
"@zauru-sdk/types": "^1.0.
|
|
40
|
-
"@zauru-sdk/utils": "^1.0.
|
|
39
|
+
"@zauru-sdk/types": "^1.0.83",
|
|
40
|
+
"@zauru-sdk/utils": "^1.0.83",
|
|
41
41
|
"framer-motion": "^11.0.8",
|
|
42
42
|
"jsonwebtoken": "^9.0.2",
|
|
43
43
|
"react": "^18.2.0",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"react-select": "^5.8.0",
|
|
48
48
|
"styled-components": "^5.3.5"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "ee7c5a89327913cc2cb8755e215014e236e8799d"
|
|
51
51
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { IdeaIconSVG } from "@zauru-sdk/icons";
|
|
2
|
+
import { useAppSelector } from "@zauru-sdk/redux";
|
|
3
|
+
import React, { useState } from "react";
|
|
4
|
+
|
|
5
|
+
type RadioButtonProps = {
|
|
6
|
+
id?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
options: { label: string; value: string }[];
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
orientation?: "vertical" | "horizontal";
|
|
11
|
+
onChange?: (
|
|
12
|
+
value: string,
|
|
13
|
+
event: React.ChangeEvent<HTMLInputElement>
|
|
14
|
+
) => void;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
helpText?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const RadioButtonGroupWithoutValidation = (props: RadioButtonProps) => {
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
name,
|
|
26
|
+
options,
|
|
27
|
+
defaultValue,
|
|
28
|
+
orientation = "vertical",
|
|
29
|
+
onChange,
|
|
30
|
+
disabled = false,
|
|
31
|
+
error,
|
|
32
|
+
title,
|
|
33
|
+
helpText,
|
|
34
|
+
className,
|
|
35
|
+
} = props;
|
|
36
|
+
|
|
37
|
+
const [selectedValue, setSelectedValue] = useState<string | undefined>(
|
|
38
|
+
defaultValue
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const [showTooltip, setShowTooltip] = useState<boolean>(false);
|
|
42
|
+
|
|
43
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
44
|
+
setSelectedValue(event.target.value);
|
|
45
|
+
onChange && onChange(event.target.value, event);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const containerClass =
|
|
49
|
+
orientation === "vertical" ? "flex flex-col" : "flex flex-row space-x-5";
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className={`radio-button-group ${className}`}>
|
|
53
|
+
{title && (
|
|
54
|
+
<label
|
|
55
|
+
htmlFor={id}
|
|
56
|
+
className="block mb-1 text-sm font-medium text-gray-700"
|
|
57
|
+
>
|
|
58
|
+
{title}
|
|
59
|
+
</label>
|
|
60
|
+
)}
|
|
61
|
+
<div className={containerClass}>
|
|
62
|
+
{options.map((option, index) => (
|
|
63
|
+
<label key={index} className="flex items-center space-x-2">
|
|
64
|
+
<input
|
|
65
|
+
type="radio"
|
|
66
|
+
id={id ? `${id}-${option.value}` : undefined}
|
|
67
|
+
name={name}
|
|
68
|
+
value={option.value}
|
|
69
|
+
checked={selectedValue === option.value}
|
|
70
|
+
onChange={handleChange}
|
|
71
|
+
disabled={disabled}
|
|
72
|
+
className="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300"
|
|
73
|
+
/>
|
|
74
|
+
<span className="text-sm text-gray-700">{option.label}</span>
|
|
75
|
+
</label>
|
|
76
|
+
))}
|
|
77
|
+
</div>
|
|
78
|
+
{helpText && (
|
|
79
|
+
<div
|
|
80
|
+
className="relative cursor-pointer"
|
|
81
|
+
onMouseEnter={() => setShowTooltip(true)}
|
|
82
|
+
onMouseLeave={() => setShowTooltip(false)}
|
|
83
|
+
>
|
|
84
|
+
<IdeaIconSVG />
|
|
85
|
+
{showTooltip && (
|
|
86
|
+
<div className="absolute mt-2 p-2 bg-white border rounded shadow text-black z-50">
|
|
87
|
+
{helpText}
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
{error && (
|
|
93
|
+
<p className="mt-2 text-sm text-red-600">
|
|
94
|
+
<span className="font-medium">Oops!</span> {error}
|
|
95
|
+
</p>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const RadioButtonGroup = (props: RadioButtonProps) => {
|
|
102
|
+
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
103
|
+
const error = formValidations[props.name ?? "-1"];
|
|
104
|
+
|
|
105
|
+
props = { ...props, error };
|
|
106
|
+
|
|
107
|
+
return <RadioButtonGroupWithoutValidation {...props} />;
|
|
108
|
+
};
|
package/src/Form/index.ts
CHANGED