@creativecodeco/ui 0.0.1 → 0.0.3
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 +87 -1
- package/lib/helpers/index.d.ts +2 -0
- package/lib/helpers/index.js +2 -0
- package/lib/helpers/react-hook-form/controller.component.d.ts +3 -0
- package/lib/helpers/react-hook-form/controller.component.js +5 -0
- package/lib/helpers/react-hook-form/index.d.ts +2 -0
- package/lib/helpers/react-hook-form/index.js +2 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +5 -3
- package/lib/theme/css/main.css +5 -0
- package/lib/theme/css/text-box.css +87 -0
- package/lib/theme/main.css +1313 -0
- package/lib/types/helpers/controller.types.d.ts +9 -0
- package/lib/types/helpers/controller.types.js +1 -0
- package/lib/types/index.d.ts +2 -2
- package/lib/types/ui/forms/drop-down.types.d.ts +11 -0
- package/lib/types/ui/forms/drop-down.types.js +1 -0
- package/lib/types/ui/forms/index.d.ts +3 -2
- package/lib/types/ui/forms/text-box.types.d.ts +7 -1
- package/lib/ui/forms/drop-down/drop-down.component.d.ts +4 -0
- package/lib/ui/forms/drop-down/drop-down.component.js +43 -0
- package/lib/ui/forms/drop-down/index.d.ts +2 -0
- package/lib/ui/forms/drop-down/index.js +2 -0
- package/lib/ui/forms/index.d.ts +3 -2
- package/lib/ui/forms/index.js +3 -2
- package/lib/ui/forms/text-box/text-box.component.d.ts +2 -2
- package/lib/ui/forms/text-box/text-box.component.js +13 -3
- package/lib/ui/provider/creativecode/creativecode-ui.provider.d.ts +2 -0
- package/lib/ui/provider/creativecode/creativecode-ui.provider.js +9 -0
- package/lib/ui/provider/index.d.ts +2 -2
- package/lib/ui/provider/index.js +2 -2
- package/package.json +72 -28
- package/lib/theme/tailwindcss/input.css +0 -3
- package/lib/theme/tailwindcss/main.css +0 -5
- package/lib/ui/provider/creativecode-ui.provider.d.ts +0 -2
- package/lib/ui/provider/creativecode-ui.provider.js +0 -5
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FieldPath, FieldValues, ControllerProps as RHFControllerProps } from 'react-hook-form';
|
|
3
|
+
import { TextBox } from '../../ui/forms';
|
|
4
|
+
type TextBoxType = {
|
|
5
|
+
as: typeof TextBox;
|
|
6
|
+
} & React.ComponentProps<typeof TextBox>;
|
|
7
|
+
type Inputs = TextBoxType;
|
|
8
|
+
export type ControllerType<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<RHFControllerProps<TFieldValues, TName>, 'render'> & Inputs;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TextBoxType, TextBoxRef } from
|
|
2
|
-
export type { TextBoxType, TextBoxRef };
|
|
1
|
+
import { DropDownOption, DropDownType, TextBoxType, TextBoxRef } from './ui/forms';
|
|
2
|
+
export type { DropDownOption, DropDownType, TextBoxType, TextBoxRef };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TextBoxType } from './text-box.types';
|
|
3
|
+
export interface DropDownOption {
|
|
4
|
+
value: string | number;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DropDownType extends TextBoxType {
|
|
8
|
+
options?: DropDownOption[];
|
|
9
|
+
onChange?: (option: React.ChangeEvent<HTMLInputElement>) => void;
|
|
10
|
+
onTextChange?: (text?: string) => void;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DropDownOption, DropDownType } from './drop-down.types';
|
|
2
|
+
import { TextBoxType, TextBoxRef } from './text-box.types';
|
|
3
|
+
export type { DropDownOption, DropDownType, TextBoxType, TextBoxRef };
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { IconType } from 'react-icons';
|
|
3
|
+
export interface TextBoxType extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
|
|
2
4
|
name: string;
|
|
3
5
|
label?: string;
|
|
4
6
|
isError?: boolean;
|
|
5
7
|
error?: string;
|
|
6
8
|
disabled?: boolean;
|
|
9
|
+
size?: 'xs' | 'sm' | 'md' | 'lg';
|
|
10
|
+
leftIcon?: IconType;
|
|
11
|
+
rightIcon?: IconType;
|
|
12
|
+
rightButton?: boolean;
|
|
7
13
|
}
|
|
8
14
|
export type TextBoxRef = HTMLInputElement;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { FaSortDown } from 'react-icons/fa';
|
|
4
|
+
import { useOnClickOutside } from 'usehooks-ts';
|
|
5
|
+
import { TextBox } from '../../../ui/forms';
|
|
6
|
+
const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextChange, ...otherProps }, ref) => {
|
|
7
|
+
const [label, setLabel] = useState('');
|
|
8
|
+
const [open, setOpen] = useState(false);
|
|
9
|
+
const [valueFilter, setValueFilter] = useState();
|
|
10
|
+
const refOutside = useRef(null);
|
|
11
|
+
const handleClickOutside = () => {
|
|
12
|
+
const option = options.find(({ label }) => String(label) === String(valueFilter));
|
|
13
|
+
if (!option) {
|
|
14
|
+
setLabel('');
|
|
15
|
+
onTextChange?.();
|
|
16
|
+
}
|
|
17
|
+
setOpen(false);
|
|
18
|
+
};
|
|
19
|
+
useOnClickOutside(refOutside, handleClickOutside);
|
|
20
|
+
const handleFocus = useCallback(() => {
|
|
21
|
+
if (disabled) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
setOpen(true);
|
|
25
|
+
}, [open, disabled]);
|
|
26
|
+
const handleSelect = useCallback((option) => {
|
|
27
|
+
onChange?.({
|
|
28
|
+
target: { value: String(option.value) }
|
|
29
|
+
});
|
|
30
|
+
setLabel(option.label);
|
|
31
|
+
setOpen(false);
|
|
32
|
+
}, [onChange]);
|
|
33
|
+
const handleChange = useCallback(({ target: { value } }) => {
|
|
34
|
+
onTextChange?.(value);
|
|
35
|
+
setValueFilter(value);
|
|
36
|
+
setLabel(value);
|
|
37
|
+
}, [onTextChange, setValueFilter]);
|
|
38
|
+
const filterOptions = useMemo(() => !valueFilter
|
|
39
|
+
? options
|
|
40
|
+
: options.filter(({ label }) => label.includes(valueFilter)), [valueFilter, options]);
|
|
41
|
+
return (_jsxs("div", { className: 'dropdown block', children: [_jsx(TextBox, { name: name, tabIndex: 0, ref: ref, disabled: disabled, rightButton: true, rightIcon: FaSortDown, value: label, onFocus: handleFocus, onChange: handleChange, ...otherProps }), open && (_jsx("ul", { tabIndex: 0, className: 'dropdown-content z-[1] menu w-full bg-base-100', id: `options-${name}`, ref: refOutside, role: 'listitem', "data-testid": `options-${name}`, children: filterOptions.map((option) => (_jsx("li", { value: option.value, onClick: () => handleSelect(option), children: _jsx("a", { children: option.label }) }, option.value))) }))] }));
|
|
42
|
+
});
|
|
43
|
+
export default DropDown;
|
package/lib/ui/forms/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DropDown } from '../../ui/forms/drop-down';
|
|
2
|
+
import { TextBox } from '../../ui/forms/text-box';
|
|
3
|
+
export { DropDown, TextBox };
|
package/lib/ui/forms/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DropDown } from '../../ui/forms/drop-down';
|
|
2
|
+
import { TextBox } from '../../ui/forms/text-box';
|
|
3
|
+
export { DropDown, TextBox };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { TextBoxType } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TextBoxType } from '../../../types/ui/forms';
|
|
3
3
|
declare const TextBox: React.ForwardRefExoticComponent<TextBoxType & React.RefAttributes<HTMLInputElement>>;
|
|
4
4
|
export default TextBox;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useImperativeHandle, useRef } from
|
|
3
|
-
|
|
2
|
+
import { forwardRef, useImperativeHandle, useRef } from 'react';
|
|
3
|
+
import cls from 'classnames';
|
|
4
|
+
const TextBox = forwardRef(({ name, label, isError, error, disabled, size = 'md', leftIcon: LeftIcon, rightIcon: RightIcon, rightButton, onClick, ...otherProps }, ref) => {
|
|
4
5
|
const inputRef = useRef(null);
|
|
5
6
|
useImperativeHandle(ref, () => inputRef.current);
|
|
6
|
-
return (_jsxs("div", { className:
|
|
7
|
+
return (_jsxs("div", { className: 'form-control w-full flex', children: [label && (_jsx("div", { className: 'label', children: _jsx("label", { htmlFor: name, className: 'label-text', children: label }) })), _jsxs("div", { className: 'relative', children: [LeftIcon && (_jsx(LeftIcon, { className: cls('text-box-left-icon', {
|
|
8
|
+
[`text-box-left-icon-size-${size}`]: size
|
|
9
|
+
}) })), _jsx("input", { ref: inputRef, id: name, name: name, "data-testid": name, ...otherProps, onClick: onClick, className: cls('input input-bordered w-full', `text-box-size-${size}`, {
|
|
10
|
+
'input-error': isError,
|
|
11
|
+
'text-box-with-left-icon': LeftIcon,
|
|
12
|
+
'text-box-with-right-icon': RightIcon
|
|
13
|
+
}), disabled: disabled }), RightIcon && (_jsx(RightIcon, { className: cls('text-box-right-icon', {
|
|
14
|
+
[`text-box-right-icon-size-${size}`]: size,
|
|
15
|
+
'cursor-pointer': rightButton
|
|
16
|
+
}), onClick: () => rightButton && inputRef.current?.click() }))] }), isError && _jsx("p", { className: 'text-red-500', children: error })] }));
|
|
7
17
|
});
|
|
8
18
|
export default TextBox;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect } from 'react';
|
|
3
|
+
export default function CreativeCodeUIProvider({ children }) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const html = document.querySelector('html');
|
|
6
|
+
html?.setAttribute('data-theme', 'creativecode');
|
|
7
|
+
}, []);
|
|
8
|
+
return _jsx(Fragment, { children: children });
|
|
9
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import CreativeCodeUIProvider from
|
|
2
|
-
export
|
|
1
|
+
import CreativeCodeUIProvider from './creativecode/creativecode-ui.provider';
|
|
2
|
+
export { CreativeCodeUIProvider };
|
package/lib/ui/provider/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import CreativeCodeUIProvider from
|
|
2
|
-
export
|
|
1
|
+
import CreativeCodeUIProvider from './creativecode/creativecode-ui.provider';
|
|
2
|
+
export { CreativeCodeUIProvider };
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creativecodeco/ui",
|
|
3
3
|
"description": "CreativeCode.com.co UI",
|
|
4
|
-
"
|
|
4
|
+
"keywords": [
|
|
5
|
+
"CreativeCode.com.co",
|
|
6
|
+
"creativecodeco/ui",
|
|
7
|
+
"Tailwindcss",
|
|
8
|
+
"Daisyui",
|
|
9
|
+
"UI",
|
|
10
|
+
"Framework Design"
|
|
11
|
+
],
|
|
12
|
+
"version": "0.0.3",
|
|
5
13
|
"homepage": "https://github.com/creativecodeco/ui",
|
|
6
14
|
"author": {
|
|
7
15
|
"name": "John Toro",
|
|
@@ -11,49 +19,80 @@
|
|
|
11
19
|
"main": "lib/index.js",
|
|
12
20
|
"source": "src/index.ts",
|
|
13
21
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"build:css": "postcss src/theme/main.css -o dist/theme/main.css --minify; cpx 'src/theme/*[.]css' 'lib/theme/tailwindcss'",
|
|
22
|
+
"dev": "npm run storybook",
|
|
23
|
+
"dev:css": "postcss src/theme/main.css -o lib/theme/main.css --watch",
|
|
17
24
|
"build": "rm -rf lib; tsc -p tsconfig.build.json; npm run build:alias; npm run build:css",
|
|
25
|
+
"build:alias": "tsc-alias -p tsconfig.build.json",
|
|
26
|
+
"build:css": "postcss src/theme/main.css -o lib/theme/main.css --minify; cpx 'src/theme/*[.]css' 'lib/theme/css'",
|
|
27
|
+
"build-storybook": "npm run build; storybook build",
|
|
18
28
|
"chromatic": "chromatic --only-changed true",
|
|
19
|
-
"
|
|
29
|
+
"lint": "npm run lint:eslint",
|
|
30
|
+
"lint:eslint": "eslint .",
|
|
31
|
+
"lint:fix": "npm run lint:eslint --fix --quiet",
|
|
20
32
|
"prepack": "npm run build",
|
|
33
|
+
"prepare": "husky install",
|
|
21
34
|
"release": "npm publish --access public",
|
|
22
|
-
"storybook": "storybook dev -p 6006"
|
|
35
|
+
"storybook": "storybook dev -p 6006",
|
|
36
|
+
"test": "jest .",
|
|
37
|
+
"test:action": "jest --coverage | tee ./coverage.txt && jest --ci --reporters=default --reporters=jest-junit",
|
|
38
|
+
"test:update": "jest --updateSnapshot",
|
|
39
|
+
"test:watch": "jest --watch"
|
|
23
40
|
},
|
|
24
41
|
"peerDependencies": {
|
|
25
|
-
"
|
|
42
|
+
"postcss": "8.4.32",
|
|
43
|
+
"postcss-import": "15.1.0",
|
|
44
|
+
"react": "18.2.0",
|
|
45
|
+
"react-hook-form": "7.49.2",
|
|
46
|
+
"tailwindcss": "3.4.0"
|
|
26
47
|
},
|
|
27
48
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@storybook/
|
|
34
|
-
"@storybook/
|
|
35
|
-
"@storybook/
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
49
|
+
"@babel/core": "7.23.7",
|
|
50
|
+
"@babel/preset-env": "^7.23.7",
|
|
51
|
+
"@babel/preset-react": "^7.23.3",
|
|
52
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
53
|
+
"@jest/globals": "29.7.0",
|
|
54
|
+
"@storybook/addon-essentials": "7.6.7",
|
|
55
|
+
"@storybook/addon-interactions": "7.6.7",
|
|
56
|
+
"@storybook/addon-links": "7.6.7",
|
|
57
|
+
"@storybook/addon-mdx-gfm": "^7.6.7",
|
|
58
|
+
"@storybook/blocks": "7.6.7",
|
|
59
|
+
"@storybook/react": "7.6.7",
|
|
60
|
+
"@storybook/react-webpack5": "7.6.7",
|
|
61
|
+
"@storybook/test": "7.6.7",
|
|
62
|
+
"@testing-library/dom": "9.3.3",
|
|
63
|
+
"@testing-library/jest-dom": "6.1.6",
|
|
64
|
+
"@testing-library/react": "14.1.2",
|
|
65
|
+
"@testing-library/user-event": "14.5.2",
|
|
66
|
+
"@types/jest": "29.5.11",
|
|
67
|
+
"@types/node": "20.10.6",
|
|
68
|
+
"@types/react": "18.2.46",
|
|
38
69
|
"@types/react-dom": "18.2.18",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
71
|
+
"autoprefixer": "10.4.16",
|
|
72
|
+
"chromatic": "10.2.0",
|
|
73
|
+
"classnames": "2.5.1",
|
|
74
|
+
"cpx2": "7.0.1",
|
|
75
|
+
"daisyui": "4.4.24",
|
|
43
76
|
"eslint": "8.56.0",
|
|
44
77
|
"eslint-config-prettier": "9.1.0",
|
|
45
78
|
"eslint-config-standard": "17.1.0",
|
|
46
79
|
"eslint-config-standard-react": "13.0.0",
|
|
47
80
|
"eslint-config-standard-with-typescript": "43.0.0",
|
|
48
81
|
"eslint-plugin-import": "2.29.1",
|
|
49
|
-
"eslint-plugin-
|
|
82
|
+
"eslint-plugin-import-order": "2.1.4",
|
|
83
|
+
"eslint-plugin-n": "16.6.1",
|
|
50
84
|
"eslint-plugin-node": "11.1.0",
|
|
51
|
-
"eslint-plugin-prettier": "5.1.
|
|
85
|
+
"eslint-plugin-prettier": "5.1.2",
|
|
52
86
|
"eslint-plugin-promise": "6.1.1",
|
|
53
87
|
"eslint-plugin-react": "7.33.2",
|
|
54
88
|
"eslint-plugin-standard": "5.0.0",
|
|
55
89
|
"eslint-plugin-storybook": "0.6.15",
|
|
56
90
|
"eslint-plugin-unused-imports": "3.0.0",
|
|
91
|
+
"husky": "8.0.3",
|
|
92
|
+
"jest": "29.7.0",
|
|
93
|
+
"jest-environment-jsdom": "29.7.0",
|
|
94
|
+
"jest-junit": "16.0.0",
|
|
95
|
+
"jest-transform-css": "6.0.1",
|
|
57
96
|
"postcss": "8.4.32",
|
|
58
97
|
"postcss-cli": "11.0.0",
|
|
59
98
|
"postcss-import": "15.1.0",
|
|
@@ -61,13 +100,18 @@
|
|
|
61
100
|
"prop-types": "15.8.1",
|
|
62
101
|
"react": "18.2.0",
|
|
63
102
|
"react-dom": "18.2.0",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
103
|
+
"react-hook-form": "7.49.2",
|
|
104
|
+
"react-icons": "4.12.0",
|
|
105
|
+
"storybook": "7.6.7",
|
|
106
|
+
"storybook-addon-themes": "6.1.0",
|
|
107
|
+
"string-width": "7.0.0",
|
|
67
108
|
"tailwindcss": "3.4.0",
|
|
109
|
+
"ts-jest": "29.1.1",
|
|
110
|
+
"ts-node": "10.9.2",
|
|
68
111
|
"tsc-alias": "1.8.8",
|
|
69
|
-
"tsconfig-paths-webpack-plugin": "
|
|
70
|
-
"typescript": "5.3.3"
|
|
112
|
+
"tsconfig-paths-webpack-plugin": "4.1.0",
|
|
113
|
+
"typescript": "5.3.3",
|
|
114
|
+
"usehooks-ts": "^2.9.1"
|
|
71
115
|
},
|
|
72
116
|
"files": [
|
|
73
117
|
"lib"
|