@creativecodeco/ui 0.0.3 → 0.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @creativecodeco/ui
2
2
 
3
- <img src="https://www.creativecode.com.co/wp-content/uploads/2020/01/CreativeCode.png" alt="CreativeCode.com.co" width="120" />
3
+ ![CreativeCode.com.co](https://www.creativecode.com.co/wp-content/uploads/2024/01/CreativeCode.png)
4
4
 
5
5
  > System Design CreativeCode.com.co
6
6
 
@@ -25,11 +25,11 @@ yarn add @creativecodeco/ui
25
25
  ### Dependencies
26
26
 
27
27
  ```bash
28
- npm install --save-dev tailwindcss postcss postcss-import autoprefixer
28
+ npm install --save-dev tailwindcss postcss postcss-import autoprefixer usehooks-ts
29
29
 
30
30
  or
31
31
 
32
- yarn add -D tailwindcss postcss postcss-import autoprefixer
32
+ yarn add -D tailwindcss postcss postcss-import autoprefixer usehooks-ts
33
33
  ```
34
34
 
35
35
  ### Setting Tailwind
@@ -93,3 +93,5 @@ export default function RootLayout({ children }) {
93
93
  ## License
94
94
 
95
95
  MIT © [CreativeCode.com.co](https://github.com/creativecodeco)
96
+
97
+ Web [CreativeCode.com.co](https://creativecode.com.co)
@@ -1,3 +1,3 @@
1
1
  import { type FieldPath, type FieldValues } from 'react-hook-form';
2
- import { ControllerType } from '../../types/helpers/controller.types';
2
+ import type { ControllerType } from '../../types/helpers/controller.types';
3
3
  export default function Controller<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, name, as: Input, defaultValue, shouldUnregister, rules, ...rest }: ControllerType<TFieldValues, TName>): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import type { FieldPath, FieldValues, ControllerProps as RHFControllerProps } from 'react-hook-form';
3
- import { TextBox } from '../../ui/forms';
3
+ import { DropDown, TextBox } from '../../ui/forms';
4
4
  type TextBoxType = {
5
5
  as: typeof TextBox;
6
6
  } & React.ComponentProps<typeof TextBox>;
7
- type Inputs = TextBoxType;
7
+ type DropDownType = {
8
+ as: typeof DropDown;
9
+ } & React.ComponentProps<typeof DropDown>;
10
+ type Inputs = TextBoxType | DropDownType;
8
11
  export type ControllerType<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<RHFControllerProps<TFieldValues, TName>, 'render'> & Inputs;
9
12
  export {};
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
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
5
  import { TextBox } from '../../../ui/forms';
6
- const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextChange, ...otherProps }, ref) => {
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);
9
9
  const [valueFilter, setValueFilter] = useState();
@@ -17,6 +17,14 @@ const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
17
17
  setOpen(false);
18
18
  };
19
19
  useOnClickOutside(refOutside, handleClickOutside);
20
+ useEffect(() => {
21
+ const option = options.find((option) => String(option.value) === String(value));
22
+ if (!option) {
23
+ setLabel('');
24
+ return;
25
+ }
26
+ setLabel(option.label);
27
+ }, [value]);
20
28
  const handleFocus = useCallback(() => {
21
29
  if (disabled) {
22
30
  return;
@@ -38,6 +46,6 @@ const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
38
46
  const filterOptions = useMemo(() => !valueFilter
39
47
  ? options
40
48
  : 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))) }))] }));
49
+ return (_jsxs("div", { className: 'dropdown block', children: [_jsx(TextBox, { name: name, tabIndex: 0, ref: ref, disabled: disabled, rightButton: true, rightIcon: FaSortDown, onFocus: handleFocus, onChange: handleChange, ...otherProps, value: label }), 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
50
  });
43
51
  export default DropDown;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "UI",
10
10
  "Framework Design"
11
11
  ],
12
- "version": "0.0.3",
12
+ "version": "0.0.5",
13
13
  "homepage": "https://github.com/creativecodeco/ui",
14
14
  "author": {
15
15
  "name": "John Toro",
@@ -43,18 +43,19 @@
43
43
  "postcss-import": "15.1.0",
44
44
  "react": "18.2.0",
45
45
  "react-hook-form": "7.49.2",
46
- "tailwindcss": "3.4.0"
46
+ "tailwindcss": "3.4.0",
47
+ "usehooks-ts": "2.9.1"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@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",
51
+ "@babel/preset-env": "7.23.7",
52
+ "@babel/preset-react": "7.23.3",
53
+ "@babel/preset-typescript": "7.23.3",
53
54
  "@jest/globals": "29.7.0",
54
55
  "@storybook/addon-essentials": "7.6.7",
55
56
  "@storybook/addon-interactions": "7.6.7",
56
57
  "@storybook/addon-links": "7.6.7",
57
- "@storybook/addon-mdx-gfm": "^7.6.7",
58
+ "@storybook/addon-mdx-gfm": "7.6.7",
58
59
  "@storybook/blocks": "7.6.7",
59
60
  "@storybook/react": "7.6.7",
60
61
  "@storybook/react-webpack5": "7.6.7",
@@ -111,7 +112,7 @@
111
112
  "tsc-alias": "1.8.8",
112
113
  "tsconfig-paths-webpack-plugin": "4.1.0",
113
114
  "typescript": "5.3.3",
114
- "usehooks-ts": "^2.9.1"
115
+ "usehooks-ts": "2.9.1"
115
116
  },
116
117
  "files": [
117
118
  "lib"