@creativecodeco/ui 0.6.2 → 1.0.0
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/README.md +13 -19
- package/lib/helpers/index.js +8 -2
- package/lib/helpers/react-hook-form/controller.component.js +7 -4
- package/lib/helpers/react-hook-form/index.js +7 -2
- package/lib/hooks/index.js +8 -2
- package/lib/hooks/use-safe-button-props.hook.d.ts +98 -97
- package/lib/hooks/use-safe-button-props.hook.js +17 -8
- package/lib/index.js +23 -7
- package/lib/theme/css/accordion.css +5 -7
- package/lib/theme/css/avatar.css +19 -21
- package/lib/theme/css/badge.css +38 -44
- package/lib/theme/css/button.css +49 -53
- package/lib/theme/css/checkbox.css +31 -35
- package/lib/theme/css/main.css +3 -4
- package/lib/theme/css/radio.css +31 -35
- package/lib/theme/css/span.css +2 -4
- package/lib/theme/css/textbox.css +115 -0
- package/lib/theme/index.js +10 -6
- package/lib/theme/main.css +2669 -4112
- package/lib/types/helpers/controller.types.js +2 -1
- package/lib/types/index.js +2 -1
- package/lib/types/ui/base/constants.types.js +2 -1
- package/lib/types/ui/base/dom.types.js +2 -1
- package/lib/types/ui/base/error.types.js +2 -1
- package/lib/types/ui/base/index.js +2 -1
- package/lib/types/ui/components/accordion.types.js +2 -1
- package/lib/types/ui/components/avatar.types.js +2 -1
- package/lib/types/ui/components/badge.types.js +2 -1
- package/lib/types/ui/components/button.types.js +2 -1
- package/lib/types/ui/components/index.js +2 -1
- package/lib/types/ui/forms/checkbox.types.js +2 -1
- package/lib/types/ui/forms/dropdown.types.d.ts +1 -1
- package/lib/types/ui/forms/dropdown.types.js +2 -1
- package/lib/types/ui/forms/index.d.ts +1 -1
- package/lib/types/ui/forms/index.js +2 -1
- package/lib/types/ui/forms/radio.types.js +2 -1
- package/lib/types/ui/forms/textbox.types.js +2 -0
- package/lib/ui/components/accordion/accordion.component.js +11 -6
- package/lib/ui/components/accordion/index.js +8 -2
- package/lib/ui/components/avatar/avatar.component.js +18 -13
- package/lib/ui/components/avatar/index.js +8 -2
- package/lib/ui/components/badge/badge.component.js +12 -7
- package/lib/ui/components/badge/index.js +8 -2
- package/lib/ui/components/button/button.component.js +18 -13
- package/lib/ui/components/button/index.js +8 -2
- package/lib/ui/components/index.js +20 -4
- package/lib/ui/forms/checkbox/checkbox.component.js +15 -10
- package/lib/ui/forms/checkbox/index.js +8 -2
- package/lib/ui/forms/dropdown/dropdown.component.js +20 -18
- package/lib/ui/forms/dropdown/index.js +8 -2
- package/lib/ui/forms/index.d.ts +1 -1
- package/lib/ui/forms/index.js +21 -5
- package/lib/ui/forms/radio/index.js +8 -2
- package/lib/ui/forms/radio/radio.component.js +15 -10
- package/lib/ui/forms/radio-list/index.js +8 -2
- package/lib/ui/forms/radio-list/radio-list.component.js +6 -4
- package/lib/ui/forms/textbox/index.d.ts +2 -0
- package/lib/ui/forms/textbox/index.js +8 -0
- package/lib/ui/forms/textbox/textbox.component.js +26 -0
- package/lib/ui/provider/creativecode/creativecode-ui.provider.js +8 -5
- package/lib/ui/provider/index.js +8 -2
- package/lib/utils/index.js +17 -1
- package/lib/utils/string.utils.js +7 -3
- package/package.json +54 -61
- package/lib/theme/css/text-box.css +0 -113
- package/lib/types/ui/forms/text-box.types.js +0 -1
- package/lib/ui/forms/text-box/index.d.ts +0 -2
- package/lib/ui/forms/text-box/index.js +0 -2
- package/lib/ui/forms/text-box/text-box.component.js +0 -21
- /package/lib/types/ui/forms/{text-box.types.d.ts → textbox.types.d.ts} +0 -0
- /package/lib/ui/forms/{text-box/text-box.component.d.ts → textbox/textbox.component.d.ts} +0 -0
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/types/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
3
8
|
const Accordion = ({ name, join, options, iconType = 'arrow', multiple }) => {
|
|
4
|
-
return (
|
|
9
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)('flex flex-wrap', {
|
|
5
10
|
'join join-vertical w-full': join,
|
|
6
11
|
'gap-2': !join
|
|
7
|
-
}), children: options.map(({ header, body }, index) => (
|
|
12
|
+
}), children: options.map(({ header, body }, index) => ((0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)('collapse bg-base-200', {
|
|
8
13
|
[`accordion-type-${iconType}`]: iconType,
|
|
9
14
|
'join-item border border-base-300': join
|
|
10
|
-
}), children: [
|
|
15
|
+
}), children: [(0, jsx_runtime_1.jsx)("input", { type: multiple ? 'checkbox' : 'radio', name: name }), (0, jsx_runtime_1.jsx)("div", { className: 'collapse-title text-xl font-medium', children: header }), (0, jsx_runtime_1.jsx)("div", { className: 'collapse-content', children: body })] }, index))) }));
|
|
11
16
|
};
|
|
12
|
-
|
|
17
|
+
exports.default = Accordion;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Accordion = void 0;
|
|
7
|
+
const accordion_component_1 = __importDefault(require("./accordion.component"));
|
|
8
|
+
exports.Accordion = accordion_component_1.default;
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
9
|
+
const utils_1 = require("../../../utils");
|
|
5
10
|
const Avatar = ({ isOnline = false, ring = false, rounded = false, size = 'md', src, withStatus = false }) => {
|
|
6
|
-
const isUri = useMemo(() => isValidUrl(src), [src]);
|
|
7
|
-
const letters = useMemo(() => getInitials(src), [src, isUri]);
|
|
8
|
-
return (
|
|
9
|
-
online: withStatus && isOnline,
|
|
10
|
-
offline: withStatus && !isOnline,
|
|
11
|
-
placeholder: !isUri
|
|
12
|
-
}), children:
|
|
11
|
+
const isUri = (0, react_1.useMemo)(() => (0, utils_1.isValidUrl)(src), [src]);
|
|
12
|
+
const letters = (0, react_1.useMemo)(() => (0, utils_1.getInitials)(src), [src, isUri]);
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)("div", { "data-testid": 'avatar', className: (0, classnames_1.default)('avatar', {
|
|
14
|
+
'avatar-online': withStatus && isOnline,
|
|
15
|
+
'avatar-offline': withStatus && !isOnline,
|
|
16
|
+
'avatar-placeholder': !isUri
|
|
17
|
+
}), children: (0, jsx_runtime_1.jsxs)("div", { "data-testid": 'avatar-content', className: (0, classnames_1.default)('text-neutral-content', {
|
|
13
18
|
'bg-neutral': !isUri,
|
|
14
19
|
[`avatar-size-${size}`]: size,
|
|
15
20
|
'rounded-full': rounded,
|
|
16
21
|
rounded: !rounded,
|
|
17
22
|
'avatar-ring': ring
|
|
18
|
-
}), children: [!isUri &&
|
|
23
|
+
}), children: [!isUri && (0, jsx_runtime_1.jsx)("span", { children: letters }), isUri && (0, jsx_runtime_1.jsx)("img", { src: src, alt: 'Avatar' })] }) }));
|
|
19
24
|
};
|
|
20
|
-
|
|
25
|
+
exports.default = Avatar;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Avatar = void 0;
|
|
7
|
+
const avatar_component_1 = __importDefault(require("./avatar.component"));
|
|
8
|
+
exports.Avatar = avatar_component_1.default;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
4
9
|
const Badge = ({ children, color, icon: Icon, iconPosition = 'left', outline, size = 'md' }) => {
|
|
5
|
-
const newIcon = useMemo(() => {
|
|
10
|
+
const newIcon = (0, react_1.useMemo)(() => {
|
|
6
11
|
if (!Icon) {
|
|
7
12
|
return;
|
|
8
13
|
}
|
|
9
|
-
return
|
|
14
|
+
return (0, jsx_runtime_1.jsx)(Icon, {});
|
|
10
15
|
}, [Icon]);
|
|
11
|
-
return (
|
|
16
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)('badge', {
|
|
12
17
|
[`badge-color-${color}`]: !outline && color,
|
|
13
18
|
[`badge-${color}`]: outline && color,
|
|
14
19
|
'badge-outline': outline,
|
|
@@ -16,4 +21,4 @@ const Badge = ({ children, color, icon: Icon, iconPosition = 'left', outline, si
|
|
|
16
21
|
'gap-2': Icon
|
|
17
22
|
}), children: [iconPosition === 'left' && newIcon, children, iconPosition === 'right' && newIcon] }));
|
|
18
23
|
};
|
|
19
|
-
|
|
24
|
+
exports.default = Badge;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Badge = void 0;
|
|
7
|
+
const badge_component_1 = __importDefault(require("./badge.component"));
|
|
8
|
+
exports.Badge = badge_component_1.default;
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
9
|
+
const hooks_1 = require("../../../hooks");
|
|
10
|
+
const Button = (0, react_1.forwardRef)(({ children, isLink, color, outline, size = 'md', icon: Icon, iconPosition = 'left', loading, loadingLabel, ...otherProps }, ref) => {
|
|
11
|
+
const safeProps = (0, hooks_1.useSafeButtonProps)({ loading, ...otherProps });
|
|
12
|
+
const newIcon = (0, react_1.useMemo)(() => {
|
|
8
13
|
if (!Icon) {
|
|
9
14
|
return;
|
|
10
15
|
}
|
|
11
|
-
return
|
|
16
|
+
return (0, jsx_runtime_1.jsx)(Icon, {});
|
|
12
17
|
}, [Icon]);
|
|
13
|
-
const content = useMemo(() => {
|
|
18
|
+
const content = (0, react_1.useMemo)(() => {
|
|
14
19
|
if (loading) {
|
|
15
|
-
return (
|
|
20
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: 'span-loading' }), loadingLabel] }));
|
|
16
21
|
}
|
|
17
|
-
return (
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [iconPosition === 'left' && newIcon, children, iconPosition === 'right' && newIcon] }));
|
|
18
23
|
}, [loading, loadingLabel, iconPosition, children, newIcon]);
|
|
19
|
-
return (
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)("button", { ref: ref, className: (0, classnames_1.default)('btn', {
|
|
20
25
|
'button-link': isLink,
|
|
21
26
|
'btn-outline': !isLink && outline,
|
|
22
27
|
[`btn-${color}`]: outline && color,
|
|
@@ -25,4 +30,4 @@ const Button = forwardRef(({ children, isLink, color, outline, size = 'md', icon
|
|
|
25
30
|
'button-loading': loading
|
|
26
31
|
}), ...safeProps, children: content }));
|
|
27
32
|
});
|
|
28
|
-
|
|
33
|
+
exports.default = Button;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Button = void 0;
|
|
7
|
+
const button_component_1 = __importDefault(require("./button.component"));
|
|
8
|
+
exports.Button = button_component_1.default;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./accordion"), exports);
|
|
18
|
+
__exportStar(require("./avatar"), exports);
|
|
19
|
+
__exportStar(require("./badge"), exports);
|
|
20
|
+
__exportStar(require("./button"), exports);
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
9
|
+
const Checkbox = (0, react_1.forwardRef)(({ name, label, isError, disabled, error, position = 'left', color, size = 'md', checked, value, onChange, ...otherProps }, ref) => {
|
|
5
10
|
const handleChange = (e) => {
|
|
6
11
|
onChange?.({
|
|
7
12
|
isChecked: e.target.checked,
|
|
@@ -9,13 +14,13 @@ const Checkbox = forwardRef(({ name, label, isError, disabled, error, position =
|
|
|
9
14
|
label
|
|
10
15
|
});
|
|
11
16
|
};
|
|
12
|
-
const checkbox = () => (
|
|
17
|
+
const checkbox = () => ((0, jsx_runtime_1.jsx)("input", { id: name, name: name, "data-testid": name, ref: ref, type: 'checkbox', className: (0, classnames_1.default)('checkbox', {
|
|
13
18
|
[`checkbox-color-${color}`]: color,
|
|
14
19
|
[`checkbox-size-${size}`]: size
|
|
15
20
|
}), disabled: disabled, checked: checked, onChange: handleChange, ...otherProps }));
|
|
16
|
-
return (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: 'form-control', children: (0, jsx_runtime_1.jsxs)("label", { className: (0, classnames_1.default)('label', {
|
|
22
|
+
'cursor-pointer': !disabled,
|
|
23
|
+
'cursor-not-allowed': disabled
|
|
24
|
+
}), htmlFor: name, children: [position === 'left' && checkbox(), label && (0, jsx_runtime_1.jsx)("span", { className: 'label-text', children: label }), position === 'right' && checkbox(), isError && (0, jsx_runtime_1.jsx)("p", { className: 'text-red-500', children: error })] }) }));
|
|
20
25
|
});
|
|
21
|
-
|
|
26
|
+
exports.default = Checkbox;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Checkbox = void 0;
|
|
7
|
+
const checkbox_component_1 = __importDefault(require("./checkbox.component"));
|
|
8
|
+
exports.Checkbox = checkbox_component_1.default;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const [
|
|
10
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const fa_1 = require("react-icons/fa");
|
|
6
|
+
const usehooks_ts_1 = require("usehooks-ts");
|
|
7
|
+
const textbox_1 = require("../textbox");
|
|
8
|
+
const Dropdown = (0, react_1.forwardRef)(({ name, options = [], disabled, onChange, onTextChange, value, ...otherProps }, ref) => {
|
|
9
|
+
const [label, setLabel] = (0, react_1.useState)('');
|
|
10
|
+
const [open, setOpen] = (0, react_1.useState)(false);
|
|
11
|
+
const [valueFilter, setValueFilter] = (0, react_1.useState)();
|
|
12
|
+
const refOutside = (0, react_1.useRef)(null);
|
|
11
13
|
const handleClickOutside = () => {
|
|
12
14
|
const option = options.find(({ label }) => String(label) === String(valueFilter));
|
|
13
15
|
if (!option) {
|
|
@@ -16,8 +18,8 @@ const Dropdown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
|
|
|
16
18
|
}
|
|
17
19
|
setOpen(false);
|
|
18
20
|
};
|
|
19
|
-
useOnClickOutside(refOutside, handleClickOutside);
|
|
20
|
-
useEffect(() => {
|
|
21
|
+
(0, usehooks_ts_1.useOnClickOutside)(refOutside, handleClickOutside);
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
21
23
|
const option = options.find((option) => String(option.value) === String(value));
|
|
22
24
|
if (!option) {
|
|
23
25
|
setLabel('');
|
|
@@ -27,27 +29,27 @@ const Dropdown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
|
|
|
27
29
|
setLabel(option.label);
|
|
28
30
|
setValueFilter(option.label);
|
|
29
31
|
}, [value]);
|
|
30
|
-
const handleFocus = useCallback(() => {
|
|
32
|
+
const handleFocus = (0, react_1.useCallback)(() => {
|
|
31
33
|
if (disabled) {
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
36
|
setOpen(true);
|
|
35
37
|
}, [open, disabled]);
|
|
36
|
-
const handleSelect = useCallback((option) => {
|
|
38
|
+
const handleSelect = (0, react_1.useCallback)((option) => {
|
|
37
39
|
onChange?.({
|
|
38
40
|
target: { value: String(option.value) }
|
|
39
41
|
});
|
|
40
42
|
setLabel(option.label);
|
|
41
43
|
setOpen(false);
|
|
42
44
|
}, [onChange]);
|
|
43
|
-
const handleChange = useCallback(({ target: { value } }) => {
|
|
45
|
+
const handleChange = (0, react_1.useCallback)(({ target: { value } }) => {
|
|
44
46
|
onTextChange?.(value);
|
|
45
47
|
setValueFilter(value);
|
|
46
48
|
setLabel(value);
|
|
47
49
|
}, [onTextChange, setValueFilter]);
|
|
48
|
-
const filterOptions = useMemo(() => !valueFilter
|
|
50
|
+
const filterOptions = (0, react_1.useMemo)(() => !valueFilter
|
|
49
51
|
? options
|
|
50
52
|
: options.filter(({ label }) => label.includes(valueFilter)), [valueFilter, options]);
|
|
51
|
-
return (
|
|
53
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: 'dropdown block', children: [(0, jsx_runtime_1.jsx)(textbox_1.TextBox, { name: name, tabIndex: 0, ref: ref, disabled: disabled, rightButton: true, rightIcon: fa_1.FaSortDown, onFocus: handleFocus, onChange: handleChange, ...otherProps, value: label }), open && ((0, jsx_runtime_1.jsx)("ul", { tabIndex: 0, className: 'dropdown-content z-1 menu w-full bg-base-100 shadow rounded-box', id: `options-${name}`, ref: refOutside, role: 'listitem', "data-testid": `options-${name}`, children: filterOptions.map((option) => ((0, jsx_runtime_1.jsx)("li", { value: option.value, onClick: () => handleSelect(option), children: (0, jsx_runtime_1.jsx)("a", { children: option.label }) }, option.value))) }))] }));
|
|
52
54
|
});
|
|
53
|
-
|
|
55
|
+
exports.default = Dropdown;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Dropdown = void 0;
|
|
7
|
+
const dropdown_component_1 = __importDefault(require("./dropdown.component"));
|
|
8
|
+
exports.Dropdown = dropdown_component_1.default;
|
package/lib/ui/forms/index.d.ts
CHANGED
package/lib/ui/forms/index.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("../../ui/forms/checkbox"), exports);
|
|
18
|
+
__exportStar(require("../../ui/forms/dropdown"), exports);
|
|
19
|
+
__exportStar(require("../../ui/forms/radio"), exports);
|
|
20
|
+
__exportStar(require("../../ui/forms/radio-list"), exports);
|
|
21
|
+
__exportStar(require("../../ui/forms/textbox"), exports);
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Radio = void 0;
|
|
7
|
+
const radio_component_1 = __importDefault(require("./radio.component"));
|
|
8
|
+
exports.Radio = radio_component_1.default;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
9
|
+
const Radio = (0, react_1.forwardRef)(({ name, label, isError, disabled, error, position = 'left', color, size = 'md', checked, value, onChange, ...otherProps }, ref) => {
|
|
5
10
|
const handleChange = (e) => {
|
|
6
11
|
onChange?.({
|
|
7
12
|
isChecked: e.target.checked,
|
|
@@ -9,13 +14,13 @@ const Radio = forwardRef(({ name, label, isError, disabled, error, position = 'l
|
|
|
9
14
|
label
|
|
10
15
|
});
|
|
11
16
|
};
|
|
12
|
-
const radio = () => (
|
|
17
|
+
const radio = () => ((0, jsx_runtime_1.jsx)("input", { ref: ref, id: name, name: name, "data-testid": name, type: 'radio', className: (0, classnames_1.default)('radio', {
|
|
13
18
|
[`radio-color-${color}`]: color,
|
|
14
19
|
[`radio-size-${size}`]: size
|
|
15
20
|
}), disabled: disabled, checked: checked, onChange: handleChange, ...otherProps }));
|
|
16
|
-
return (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: 'form-control', children: (0, jsx_runtime_1.jsxs)("label", { className: (0, classnames_1.default)('label justify-start gap-3', {
|
|
22
|
+
'cursor-pointer': !disabled,
|
|
23
|
+
'cursor-not-allowed': disabled
|
|
24
|
+
}), htmlFor: name, children: [position === 'left' && radio(), label && (0, jsx_runtime_1.jsx)("span", { className: 'label-text', children: label }), position === 'right' && radio(), isError && (0, jsx_runtime_1.jsx)("p", { className: 'text-red-500', children: error })] }) }));
|
|
20
25
|
});
|
|
21
|
-
|
|
26
|
+
exports.default = Radio;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RadioList = void 0;
|
|
7
|
+
const radio_list_component_1 = __importDefault(require("./radio-list.component"));
|
|
8
|
+
exports.RadioList = radio_list_component_1.default;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const radio_1 = require("../radio");
|
|
3
5
|
const RadioList = ({ name, options, isError, error, value, ...otherOptions }) => {
|
|
4
6
|
if (!options || options.length === 0) {
|
|
5
7
|
return;
|
|
6
8
|
}
|
|
7
|
-
return (
|
|
9
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: 'form-control', children: [options.map((option) => ((0, jsx_runtime_1.jsx)(radio_1.Radio, { name: name, ...option, ...otherOptions, checked: String(option.value) === String(value) }, option.value))), isError && (0, jsx_runtime_1.jsx)("p", { className: 'text-red-500', children: error })] }));
|
|
8
10
|
};
|
|
9
|
-
|
|
11
|
+
exports.default = RadioList;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TextBox = void 0;
|
|
7
|
+
const textbox_component_1 = __importDefault(require("./textbox.component"));
|
|
8
|
+
exports.TextBox = textbox_component_1.default;
|