@creativecodeco/ui 0.0.2 → 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.
@@ -1,2 +1,2 @@
1
- import { TextBoxType, TextBoxRef } from "./ui/forms";
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 { TextBoxType, TextBoxRef } from "./text-box.types";
2
- export type { TextBoxType, TextBoxRef };
1
+ import { DropDownOption, DropDownType } from './drop-down.types';
2
+ import { TextBoxType, TextBoxRef } from './text-box.types';
3
+ export type { DropDownOption, DropDownType, TextBoxType, TextBoxRef };
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { IconType } from 'react-icons';
2
3
  export interface TextBoxType extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
3
4
  name: string;
4
5
  label?: string;
@@ -6,5 +7,8 @@ export interface TextBoxType extends Omit<React.InputHTMLAttributes<HTMLInputEle
6
7
  error?: string;
7
8
  disabled?: boolean;
8
9
  size?: 'xs' | 'sm' | 'md' | 'lg';
10
+ leftIcon?: IconType;
11
+ rightIcon?: IconType;
12
+ rightButton?: boolean;
9
13
  }
10
14
  export type TextBoxRef = HTMLInputElement;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { DropDownType } from '../../../types';
3
+ declare const DropDown: React.ForwardRefExoticComponent<DropDownType & React.RefAttributes<HTMLInputElement>>;
4
+ export default DropDown;
@@ -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;
@@ -0,0 +1,2 @@
1
+ import DropDown from './drop-down.component';
2
+ export { DropDown };
@@ -0,0 +1,2 @@
1
+ import DropDown from './drop-down.component';
2
+ export { DropDown };
@@ -1,2 +1,3 @@
1
- import { TextBox } from "../../ui/forms/text-box";
2
- export { TextBox };
1
+ import { DropDown } from '../../ui/forms/drop-down';
2
+ import { TextBox } from '../../ui/forms/text-box';
3
+ export { DropDown, TextBox };
@@ -1,2 +1,3 @@
1
- import { TextBox } from "../../ui/forms/text-box";
2
- export { TextBox };
1
+ import { DropDown } from '../../ui/forms/drop-down';
2
+ import { TextBox } from '../../ui/forms/text-box';
3
+ export { DropDown, TextBox };
@@ -1,11 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useImperativeHandle, useRef } from 'react';
3
3
  import cls from 'classnames';
4
- const TextBox = forwardRef(({ name, label, isError, error, disabled, size = 'md', ...otherProps }, ref) => {
4
+ const TextBox = forwardRef(({ name, label, isError, error, disabled, size = 'md', leftIcon: LeftIcon, rightIcon: RightIcon, rightButton, onClick, ...otherProps }, ref) => {
5
5
  const inputRef = useRef(null);
6
6
  useImperativeHandle(ref, () => inputRef.current);
7
- return (_jsxs("div", { className: 'form-control w-full', children: [label && (_jsx("div", { className: 'label', children: _jsx("label", { htmlFor: name, className: 'label-text', children: label }) })), _jsx("input", { ref: inputRef, id: name, name: name, ...otherProps, className: cls('input input-bordered w-full', `input-${size}`, {
8
- 'input-error': isError
9
- }), disabled: disabled }), isError && _jsx("p", { className: 'text-red-500', children: error })] }));
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 })] }));
10
17
  });
11
18
  export default TextBox;
@@ -0,0 +1,2 @@
1
+ import { PropsWithChildren } from 'react';
2
+ export default function CreativeCodeUIProvider({ children }: PropsWithChildren<unknown>): JSX.Element;
@@ -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 './creativecode-ui.provider';
1
+ import CreativeCodeUIProvider from './creativecode/creativecode-ui.provider';
2
2
  export { CreativeCodeUIProvider };
@@ -1,2 +1,2 @@
1
- import CreativeCodeUIProvider from './creativecode-ui.provider';
1
+ import CreativeCodeUIProvider from './creativecode/creativecode-ui.provider';
2
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
- "version": "0.0.2",
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,53 +19,60 @@
11
19
  "main": "lib/index.js",
12
20
  "source": "src/index.ts",
13
21
  "scripts": {
14
- "build-storybook": "npm run build; storybook build",
15
- "build:alias": "tsc-alias -p tsconfig.build.json",
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
- "dev:css": "postcss src/theme/main.css -o dist/theme/main.css --watch",
29
+ "lint": "npm run lint:eslint",
20
30
  "lint:eslint": "eslint .",
21
31
  "lint:fix": "npm run lint:eslint --fix --quiet",
22
- "lint": "npm run lint:eslint",
23
32
  "prepack": "npm run build",
24
33
  "prepare": "husky install",
25
34
  "release": "npm publish --access public",
26
35
  "storybook": "storybook dev -p 6006",
36
+ "test": "jest .",
27
37
  "test:action": "jest --coverage | tee ./coverage.txt && jest --ci --reporters=default --reporters=jest-junit",
28
38
  "test:update": "jest --updateSnapshot",
29
- "test:watch": "jest --watch",
30
- "test": "jest ."
39
+ "test:watch": "jest --watch"
31
40
  },
32
41
  "peerDependencies": {
33
- "react": "18.2.0"
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"
34
47
  },
35
48
  "devDependencies": {
36
- "@babel/core": "7.23.6",
37
- "@babel/preset-react": "7.23.3",
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",
38
53
  "@jest/globals": "29.7.0",
39
- "@storybook/addon-essentials": "7.6.6",
40
- "@storybook/addon-interactions": "7.6.6",
41
- "@storybook/addon-links": "7.6.6",
42
- "@storybook/addon-onboarding": "1.0.10",
43
- "@storybook/blocks": "7.6.6",
44
- "@storybook/react": "7.6.6",
45
- "@storybook/react-webpack5": "7.6.6",
46
- "@storybook/test": "7.6.6",
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",
47
62
  "@testing-library/dom": "9.3.3",
48
- "@testing-library/jest-dom": "5.17.0",
63
+ "@testing-library/jest-dom": "6.1.6",
49
64
  "@testing-library/react": "14.1.2",
50
- "@testing-library/user-event": "14.5.1",
65
+ "@testing-library/user-event": "14.5.2",
51
66
  "@types/jest": "29.5.11",
52
- "@types/node": "20.10.5",
53
- "@types/react": "18.2.45",
67
+ "@types/node": "20.10.6",
68
+ "@types/react": "18.2.46",
54
69
  "@types/react-dom": "18.2.18",
55
- "@typescript-eslint/eslint-plugin": "6.15.0",
70
+ "@typescript-eslint/eslint-plugin": "6.17.0",
56
71
  "autoprefixer": "10.4.16",
57
- "chromatic": "10.1.0",
58
- "classnames": "2.3.2",
59
- "cpx2": "6.0.1",
60
- "daisyui": "4.4.22",
72
+ "chromatic": "10.2.0",
73
+ "classnames": "2.5.1",
74
+ "cpx2": "7.0.1",
75
+ "daisyui": "4.4.24",
61
76
  "eslint": "8.56.0",
62
77
  "eslint-config-prettier": "9.1.0",
63
78
  "eslint-config-standard": "17.1.0",
@@ -65,9 +80,9 @@
65
80
  "eslint-config-standard-with-typescript": "43.0.0",
66
81
  "eslint-plugin-import": "2.29.1",
67
82
  "eslint-plugin-import-order": "2.1.4",
68
- "eslint-plugin-n": "16.5.0",
83
+ "eslint-plugin-n": "16.6.1",
69
84
  "eslint-plugin-node": "11.1.0",
70
- "eslint-plugin-prettier": "5.1.0",
85
+ "eslint-plugin-prettier": "5.1.2",
71
86
  "eslint-plugin-promise": "6.1.1",
72
87
  "eslint-plugin-react": "7.33.2",
73
88
  "eslint-plugin-standard": "5.0.0",
@@ -85,7 +100,9 @@
85
100
  "prop-types": "15.8.1",
86
101
  "react": "18.2.0",
87
102
  "react-dom": "18.2.0",
88
- "storybook": "7.6.6",
103
+ "react-hook-form": "7.49.2",
104
+ "react-icons": "4.12.0",
105
+ "storybook": "7.6.7",
89
106
  "storybook-addon-themes": "6.1.0",
90
107
  "string-width": "7.0.0",
91
108
  "tailwindcss": "3.4.0",
@@ -93,12 +110,10 @@
93
110
  "ts-node": "10.9.2",
94
111
  "tsc-alias": "1.8.8",
95
112
  "tsconfig-paths-webpack-plugin": "4.1.0",
96
- "typescript": "5.3.3"
113
+ "typescript": "5.3.3",
114
+ "usehooks-ts": "^2.9.1"
97
115
  },
98
116
  "files": [
99
117
  "lib"
100
- ],
101
- "dependencies": {
102
- "react-hook-form": "7.49.2"
103
- }
118
+ ]
104
119
  }
@@ -1,3 +0,0 @@
1
- .input-john {
2
- @apply bg-primary;
3
- }
@@ -1,5 +0,0 @@
1
- @import "tailwindcss/base";
2
- @import "tailwindcss/components";
3
- @import "tailwindcss/utilities";
4
-
5
- @import "./input.css";
@@ -1,2 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- export default function CreativeCodeUIProvider({ children, }: PropsWithChildren<unknown>): JSX.Element;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Fragment } from "react";
3
- export default function CreativeCodeUIProvider({ children, }) {
4
- return _jsx(Fragment, { children: children });
5
- }