@creativecodeco/ui 0.2.0 → 0.4.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/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/use-safe-button-props.hook.d.ts +283 -0
- package/lib/hooks/use-safe-button-props.hook.js +17 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/theme/css/button.css +65 -0
- package/lib/theme/css/main.css +2 -0
- package/lib/theme/css/radio.css +47 -0
- package/lib/theme/main.css +1572 -149
- package/lib/types/index.d.ts +3 -3
- package/lib/types/index.js +1 -3
- package/lib/types/ui/base/constants.types.d.ts +3 -0
- package/lib/types/ui/base/dom.types.d.ts +3 -0
- package/lib/types/ui/base/dom.types.js +1 -0
- package/lib/types/ui/base/index.d.ts +1 -0
- package/lib/types/ui/components/avatar.types.d.ts +1 -1
- package/lib/types/ui/components/button.types.d.ts +13 -0
- package/lib/types/ui/components/button.types.js +1 -0
- package/lib/types/ui/components/index.d.ts +2 -2
- package/lib/types/ui/forms/checkbox.types.d.ts +10 -4
- package/lib/types/ui/forms/index.d.ts +1 -0
- package/lib/types/ui/forms/radio.types.d.ts +19 -0
- package/lib/types/ui/forms/radio.types.js +1 -0
- package/lib/ui/components/button/button.component.d.ts +4 -0
- package/lib/ui/components/button/button.component.js +20 -0
- package/lib/ui/components/button/index.d.ts +2 -0
- package/lib/ui/components/button/index.js +2 -0
- package/lib/ui/components/index.d.ts +1 -0
- package/lib/ui/components/index.js +1 -0
- package/lib/ui/forms/checkbox/checkbox.component.js +10 -3
- package/lib/ui/forms/dropdown/dropdown.component.js +1 -1
- package/lib/ui/forms/index.d.ts +2 -0
- package/lib/ui/forms/index.js +2 -0
- package/lib/ui/forms/radio/index.d.ts +2 -0
- package/lib/ui/forms/radio/index.js +2 -0
- package/lib/ui/forms/radio/radio.component.d.ts +4 -0
- package/lib/ui/forms/radio/radio.component.js +21 -0
- package/lib/ui/forms/radio-list/index.d.ts +2 -0
- package/lib/ui/forms/radio-list/index.js +2 -0
- package/lib/ui/forms/radio-list/radio-list.component.d.ts +3 -0
- package/lib/ui/forms/radio-list/radio-list.component.js +9 -0
- package/package.json +23 -23
package/lib/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './ui/base';
|
|
2
|
-
export * from './ui/components';
|
|
3
|
-
export * from './ui/forms';
|
|
1
|
+
export type * from './ui/base';
|
|
2
|
+
export type * from './ui/components';
|
|
3
|
+
export type * from './ui/forms';
|
package/lib/types/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
1
|
export type SizeType = 'xs' | 'sm' | 'md' | 'lg';
|
|
2
|
+
export type ColorType = 'primary' | 'secondary' | 'accent' | 'success' | 'warning' | 'info' | 'error';
|
|
3
|
+
export type ColorButtonType = 'primary' | 'secondary' | 'accent' | 'success' | 'warning' | 'info' | 'error' | 'ghost' | 'neutral';
|
|
4
|
+
export type PositionType = 'left' | 'right';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ColorButtonType, SizeType } from '../../../types';
|
|
3
|
+
import type { IconType } from 'react-icons';
|
|
4
|
+
import type { PositionType } from '../../../types';
|
|
5
|
+
export interface ButtonType extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
6
|
+
isLink?: boolean;
|
|
7
|
+
color?: ColorButtonType;
|
|
8
|
+
outline?: boolean;
|
|
9
|
+
size?: SizeType;
|
|
10
|
+
icon?: IconType;
|
|
11
|
+
iconPosition?: PositionType;
|
|
12
|
+
}
|
|
13
|
+
export type ButtonRef = HTMLButtonElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
1
|
+
export type * from './avatar.types';
|
|
2
|
+
export type * from './button.types';
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import type { ErrorType, SizeType } from '../../../types';
|
|
2
|
-
export interface
|
|
1
|
+
import type { ColorType, ErrorType, PositionType, SizeType } from '../../../types';
|
|
2
|
+
export interface CheckboxItemType {
|
|
3
|
+
label?: string;
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
value: string | number;
|
|
6
|
+
}
|
|
7
|
+
export interface CheckboxType extends CheckboxItemType, ErrorType {
|
|
3
8
|
name: string;
|
|
4
9
|
label?: string;
|
|
5
10
|
checked?: boolean;
|
|
6
|
-
position?:
|
|
7
|
-
color?:
|
|
11
|
+
position?: PositionType;
|
|
12
|
+
color?: ColorType;
|
|
8
13
|
size?: SizeType;
|
|
9
14
|
disabled?: boolean;
|
|
15
|
+
onChange?: (value: CheckboxItemType) => void;
|
|
10
16
|
}
|
|
11
17
|
export type CheckboxRef = HTMLInputElement;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ColorType, ErrorType, PositionType, SizeType } from '../../../types';
|
|
2
|
+
export interface RadioItemType {
|
|
3
|
+
label?: string;
|
|
4
|
+
value?: string | number;
|
|
5
|
+
}
|
|
6
|
+
export interface RadioType extends RadioItemType, ErrorType {
|
|
7
|
+
name: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
checked?: boolean;
|
|
10
|
+
position?: PositionType;
|
|
11
|
+
color?: ColorType;
|
|
12
|
+
size?: SizeType;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
onChange?: (value: RadioItemType) => void;
|
|
15
|
+
}
|
|
16
|
+
export type RadioRef = HTMLInputElement;
|
|
17
|
+
export interface RadioListType extends RadioType {
|
|
18
|
+
options: Omit<RadioType, 'name'>[];
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import cls from 'classnames';
|
|
4
|
+
import { useSafeButtonProps } from '../../../hooks';
|
|
5
|
+
const Button = forwardRef(({ children, isLink, color, outline, size = 'md', icon: Icon, iconPosition = 'left', disabled, ...otherProps }, ref) => {
|
|
6
|
+
const safeProps = useSafeButtonProps({ disabled, ...otherProps });
|
|
7
|
+
const getIcon = () => {
|
|
8
|
+
if (!Icon) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
return _jsx(Icon, {});
|
|
12
|
+
};
|
|
13
|
+
return (_jsxs("button", { ref: ref, className: cls('button', {
|
|
14
|
+
'button-link': isLink,
|
|
15
|
+
'button-outline': !isLink && outline,
|
|
16
|
+
[`button-color-${color}`]: !isLink && color,
|
|
17
|
+
[`button-size-${size}`]: size !== 'md'
|
|
18
|
+
}), ...safeProps, children: [iconPosition === 'left' && getIcon(), children, iconPosition === 'right' && getIcon()] }));
|
|
19
|
+
});
|
|
20
|
+
export default Button;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
import cls from 'classnames';
|
|
4
|
-
const Checkbox = forwardRef(({ name, label, isError,
|
|
5
|
-
const
|
|
4
|
+
const Checkbox = forwardRef(({ name, label, isError, disabled, error, position = 'left', color, size = 'md', checked, value, onChange, ...otherProps }, ref) => {
|
|
5
|
+
const handleChange = (e) => {
|
|
6
|
+
onChange?.({
|
|
7
|
+
isChecked: e.target.checked,
|
|
8
|
+
value,
|
|
9
|
+
label
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const checkbox = () => (_jsx("input", { id: name, name: name, "data-testid": name, ref: ref, type: 'checkbox', className: cls('checkbox', {
|
|
6
13
|
[`checkbox-color-${color}`]: color,
|
|
7
14
|
[`checkbox-size-${size}`]: size
|
|
8
|
-
}), disabled: disabled, ...otherProps }));
|
|
15
|
+
}), disabled: disabled, checked: checked, onChange: handleChange, ...otherProps }));
|
|
9
16
|
return (_jsxs(_Fragment, { children: [_jsxs("label", { className: cls('label', {
|
|
10
17
|
'cursor-pointer': !disabled,
|
|
11
18
|
'cursor-not-allowed': disabled
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { FaSortDown } from 'react-icons/fa';
|
|
4
4
|
import { useOnClickOutside } from 'usehooks-ts';
|
|
5
|
-
import { TextBox } from '
|
|
5
|
+
import { TextBox } from '../text-box';
|
|
6
6
|
const Dropdown = forwardRef(({ name, options = [], disabled, onChange, onTextChange, value, ...otherProps }, ref) => {
|
|
7
7
|
const [label, setLabel] = useState('');
|
|
8
8
|
const [open, setOpen] = useState(false);
|
package/lib/ui/forms/index.d.ts
CHANGED
package/lib/ui/forms/index.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import cls from 'classnames';
|
|
4
|
+
const Radio = forwardRef(({ name, label, isError, disabled, error, position = 'left', color, size = 'md', checked, value, onChange, ...otherProps }, ref) => {
|
|
5
|
+
const handleChange = (e) => {
|
|
6
|
+
onChange?.({
|
|
7
|
+
isChecked: e.target.checked,
|
|
8
|
+
value,
|
|
9
|
+
label
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const radio = () => (_jsx("input", { ref: ref, id: name, name: name, "data-testid": name, type: 'radio', className: cls('radio', {
|
|
13
|
+
[`radio-color-${color}`]: color,
|
|
14
|
+
[`radio-size-${size}`]: size
|
|
15
|
+
}), disabled: disabled, checked: checked, onChange: handleChange, ...otherProps }));
|
|
16
|
+
return (_jsxs(_Fragment, { children: [_jsxs("label", { className: cls('label justify-start gap-3', {
|
|
17
|
+
'cursor-pointer': !disabled,
|
|
18
|
+
'cursor-not-allowed': disabled
|
|
19
|
+
}), children: [position === 'left' && radio(), label && _jsx("span", { className: 'label-text', children: label }), position === 'right' && radio()] }), isError && _jsx("p", { className: 'text-red-500', children: error })] }));
|
|
20
|
+
});
|
|
21
|
+
export default Radio;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Radio } from '../radio';
|
|
3
|
+
const RadioList = ({ name, options, isError, error, value, ...otherOptions }) => {
|
|
4
|
+
if (!options || options.length === 0) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
return (_jsxs("div", { className: 'form-control', children: [options.map((option) => (_jsx(Radio, { name: name, ...option, ...otherOptions, checked: String(option.value) === String(value) }, option.value))), isError && _jsx("p", { className: 'text-red-500', children: error })] }));
|
|
8
|
+
};
|
|
9
|
+
export default RadioList;
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"framework design",
|
|
11
11
|
"design system"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.4.0",
|
|
14
14
|
"homepage": "https://github.com/creativecodeco/ui",
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "John Toro",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"react": "18.2.0",
|
|
54
54
|
"react-hook-form": "7.49.3",
|
|
55
55
|
"tailwindcss": "3.4.1",
|
|
56
|
-
"usehooks-ts": "2.9.
|
|
56
|
+
"usehooks-ts": "2.9.5"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@babel/core": "7.23.7",
|
|
@@ -61,33 +61,33 @@
|
|
|
61
61
|
"@babel/preset-react": "7.23.3",
|
|
62
62
|
"@babel/preset-typescript": "7.23.3",
|
|
63
63
|
"@jest/globals": "29.7.0",
|
|
64
|
-
"@storybook/addon-essentials": "7.6.
|
|
65
|
-
"@storybook/addon-interactions": "7.6.
|
|
66
|
-
"@storybook/addon-links": "7.6.
|
|
67
|
-
"@storybook/addon-mdx-gfm": "7.6.
|
|
68
|
-
"@storybook/blocks": "7.6.
|
|
69
|
-
"@storybook/react": "7.6.
|
|
70
|
-
"@storybook/react-webpack5": "7.6.
|
|
71
|
-
"@storybook/test": "7.6.
|
|
64
|
+
"@storybook/addon-essentials": "7.6.10",
|
|
65
|
+
"@storybook/addon-interactions": "7.6.10",
|
|
66
|
+
"@storybook/addon-links": "7.6.10",
|
|
67
|
+
"@storybook/addon-mdx-gfm": "7.6.10",
|
|
68
|
+
"@storybook/blocks": "7.6.10",
|
|
69
|
+
"@storybook/react": "7.6.10",
|
|
70
|
+
"@storybook/react-webpack5": "7.6.10",
|
|
71
|
+
"@storybook/test": "7.6.10",
|
|
72
72
|
"@testing-library/dom": "9.3.4",
|
|
73
73
|
"@testing-library/jest-dom": "6.2.0",
|
|
74
74
|
"@testing-library/react": "14.1.2",
|
|
75
75
|
"@testing-library/user-event": "14.5.2",
|
|
76
76
|
"@types/jest": "29.5.11",
|
|
77
|
-
"@types/node": "20.
|
|
78
|
-
"@types/react": "18.2.
|
|
77
|
+
"@types/node": "20.11.5",
|
|
78
|
+
"@types/react": "18.2.48",
|
|
79
79
|
"@types/react-dom": "18.2.18",
|
|
80
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
81
|
-
"autoprefixer": "10.4.
|
|
82
|
-
"chromatic": "10.
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "6.19.0",
|
|
81
|
+
"autoprefixer": "10.4.17",
|
|
82
|
+
"chromatic": "10.3.1",
|
|
83
83
|
"classnames": "2.5.1",
|
|
84
84
|
"cpx2": "7.0.1",
|
|
85
|
-
"daisyui": "4.
|
|
85
|
+
"daisyui": "4.6.0",
|
|
86
86
|
"eslint": "8.56.0",
|
|
87
87
|
"eslint-config-prettier": "9.1.0",
|
|
88
88
|
"eslint-config-standard": "17.1.0",
|
|
89
89
|
"eslint-config-standard-react": "13.0.0",
|
|
90
|
-
"eslint-config-standard-with-typescript": "43.0.
|
|
90
|
+
"eslint-config-standard-with-typescript": "43.0.1",
|
|
91
91
|
"eslint-plugin-import": "2.29.1",
|
|
92
92
|
"eslint-plugin-import-order": "2.1.4",
|
|
93
93
|
"eslint-plugin-n": "16.6.2",
|
|
@@ -103,15 +103,15 @@
|
|
|
103
103
|
"jest-environment-jsdom": "29.7.0",
|
|
104
104
|
"jest-junit": "16.0.0",
|
|
105
105
|
"jest-transform-css": "6.0.1",
|
|
106
|
-
"postcss-cli": "
|
|
107
|
-
"prettier": "3.
|
|
106
|
+
"postcss-cli": "11.0.0",
|
|
107
|
+
"prettier": "3.2.4",
|
|
108
108
|
"prop-types": "15.8.1",
|
|
109
109
|
"react-dom": "18.2.0",
|
|
110
|
-
"react-icons": "5.0.
|
|
111
|
-
"storybook": "7.6.
|
|
110
|
+
"react-icons": "5.0.1",
|
|
111
|
+
"storybook": "7.6.10",
|
|
112
112
|
"storybook-addon-themes": "6.1.0",
|
|
113
|
-
"string-width": "7.
|
|
114
|
-
"ts-jest": "29.1.
|
|
113
|
+
"string-width": "7.1.0",
|
|
114
|
+
"ts-jest": "29.1.2",
|
|
115
115
|
"ts-node": "10.9.2",
|
|
116
116
|
"tsc-alias": "1.8.8",
|
|
117
117
|
"tsconfig-paths-webpack-plugin": "4.1.0",
|