@creativecodeco/ui 0.0.5 → 0.2.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.
Files changed (50) hide show
  1. package/README.md +37 -4
  2. package/lib/index.d.ts +2 -0
  3. package/lib/index.js +2 -0
  4. package/lib/theme/css/avatar.css +37 -0
  5. package/lib/theme/css/checkbox.css +47 -0
  6. package/lib/theme/css/main.css +2 -0
  7. package/lib/theme/main.css +590 -1
  8. package/lib/types/helpers/controller.types.d.ts +5 -5
  9. package/lib/types/index.d.ts +3 -2
  10. package/lib/types/index.js +3 -1
  11. package/lib/types/ui/base/constants.types.d.ts +1 -0
  12. package/lib/types/ui/base/error.types.d.ts +4 -0
  13. package/lib/types/ui/base/error.types.js +1 -0
  14. package/lib/types/ui/base/index.d.ts +2 -0
  15. package/lib/types/ui/base/index.js +1 -0
  16. package/lib/types/ui/components/avatar.types.d.ts +9 -0
  17. package/lib/types/ui/components/avatar.types.js +1 -0
  18. package/lib/types/ui/components/index.d.ts +2 -0
  19. package/lib/types/ui/components/index.js +1 -0
  20. package/lib/types/ui/forms/checkbox.types.d.ts +11 -0
  21. package/lib/types/ui/forms/checkbox.types.js +1 -0
  22. package/lib/types/ui/forms/{drop-down.types.d.ts → dropdown.types.d.ts} +3 -3
  23. package/lib/types/ui/forms/dropdown.types.js +1 -0
  24. package/lib/types/ui/forms/index.d.ts +3 -3
  25. package/lib/types/ui/forms/text-box.types.d.ts +3 -4
  26. package/lib/ui/components/avatar/avatar.component.d.ts +3 -0
  27. package/lib/ui/components/avatar/avatar.component.js +18 -0
  28. package/lib/ui/components/avatar/index.d.ts +2 -0
  29. package/lib/ui/components/avatar/index.js +2 -0
  30. package/lib/ui/components/index.d.ts +1 -0
  31. package/lib/ui/components/index.js +1 -0
  32. package/lib/ui/forms/checkbox/checkbox.component.d.ts +4 -0
  33. package/lib/ui/forms/checkbox/checkbox.component.js +14 -0
  34. package/lib/ui/forms/checkbox/index.d.ts +2 -0
  35. package/lib/ui/forms/checkbox/index.js +2 -0
  36. package/lib/ui/forms/dropdown/dropdown.component.d.ts +4 -0
  37. package/lib/ui/forms/{drop-down/drop-down.component.js → dropdown/dropdown.component.js} +4 -2
  38. package/lib/ui/forms/dropdown/index.d.ts +2 -0
  39. package/lib/ui/forms/dropdown/index.js +2 -0
  40. package/lib/ui/forms/index.d.ts +3 -3
  41. package/lib/ui/forms/index.js +3 -3
  42. package/lib/utils/index.d.ts +1 -0
  43. package/lib/utils/index.js +1 -0
  44. package/lib/utils/string.utils.d.ts +51 -0
  45. package/lib/utils/string.utils.js +75 -0
  46. package/package.json +29 -26
  47. package/lib/ui/forms/drop-down/drop-down.component.d.ts +0 -4
  48. package/lib/ui/forms/drop-down/index.d.ts +0 -2
  49. package/lib/ui/forms/drop-down/index.js +0 -2
  50. /package/lib/types/ui/{forms/drop-down.types.js → base/constants.types.js} +0 -0
@@ -1,2 +1,3 @@
1
- import { DropDownOption, DropDownType, TextBoxType, TextBoxRef } from './ui/forms';
2
- export type { DropDownOption, DropDownType, TextBoxType, TextBoxRef };
1
+ export * from './ui/base';
2
+ export * from './ui/components';
3
+ export * from './ui/forms';
@@ -1 +1,3 @@
1
- export {};
1
+ export * from './ui/base';
2
+ export * from './ui/components';
3
+ export * from './ui/forms';
@@ -0,0 +1 @@
1
+ export type SizeType = 'xs' | 'sm' | 'md' | 'lg';
@@ -0,0 +1,4 @@
1
+ export interface ErrorType {
2
+ isError?: boolean;
3
+ error?: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export type * from './constants.types';
2
+ export type * from './error.types';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { SizeType } from '../../../types';
2
+ export interface AvatarType {
3
+ src: string;
4
+ size?: SizeType;
5
+ withStatus?: boolean;
6
+ isOnline?: boolean;
7
+ rounded?: boolean;
8
+ ring?: boolean;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { AvatarType } from './avatar.types';
2
+ export type { AvatarType };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { ErrorType, SizeType } from '../../../types';
2
+ export interface CheckboxType extends ErrorType {
3
+ name: string;
4
+ label?: string;
5
+ checked?: boolean;
6
+ position?: 'left' | 'right';
7
+ color?: 'primary' | 'secondary' | 'accent' | 'success' | 'warning' | 'info' | 'error';
8
+ size?: SizeType;
9
+ disabled?: boolean;
10
+ }
11
+ export type CheckboxRef = HTMLInputElement;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { TextBoxType } from './text-box.types';
3
- export interface DropDownOption {
3
+ export interface DropdownOption {
4
4
  value: string | number;
5
5
  label: string;
6
6
  }
7
- export interface DropDownType extends TextBoxType {
8
- options?: DropDownOption[];
7
+ export interface DropdownType extends TextBoxType {
8
+ options?: DropdownOption[];
9
9
  onChange?: (option: React.ChangeEvent<HTMLInputElement>) => void;
10
10
  onTextChange?: (text?: string) => void;
11
11
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,3 @@
1
- import { DropDownOption, DropDownType } from './drop-down.types';
2
- import { TextBoxType, TextBoxRef } from './text-box.types';
3
- export type { DropDownOption, DropDownType, TextBoxType, TextBoxRef };
1
+ export type * from './checkbox.types';
2
+ export type * from './dropdown.types';
3
+ export type * from './text-box.types';
@@ -1,12 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import type { IconType } from 'react-icons';
3
- export interface TextBoxType extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
3
+ import type { ErrorType, SizeType } from '../../../types';
4
+ export interface TextBoxType extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'>, ErrorType {
4
5
  name: string;
5
6
  label?: string;
6
- isError?: boolean;
7
- error?: string;
8
7
  disabled?: boolean;
9
- size?: 'xs' | 'sm' | 'md' | 'lg';
8
+ size?: SizeType;
10
9
  leftIcon?: IconType;
11
10
  rightIcon?: IconType;
12
11
  rightButton?: boolean;
@@ -0,0 +1,3 @@
1
+ import type { AvatarType } from '../../../types';
2
+ declare const Avatar: ({ isOnline, ring, rounded, size, src, withStatus }: AvatarType) => import("react/jsx-runtime").JSX.Element;
3
+ export default Avatar;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import cls from 'classnames';
4
+ import { getInitials, isValidUrl } from '../../../utils';
5
+ 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 (_jsx("div", { "data-testid": 'avatar', className: cls('avatar', {
9
+ online: withStatus && isOnline,
10
+ offline: withStatus && !isOnline,
11
+ placeholder: !isUri
12
+ }), children: _jsxs("div", { "data-testid": 'avatar-content', className: cls(`bg-neutral text-neutral-content avatar-size-${size}`, {
13
+ 'rounded-full': rounded,
14
+ rounded: !rounded,
15
+ 'avatar-ring': ring
16
+ }), children: [!isUri && _jsx("span", { children: letters }), isUri && _jsx("img", { src: src, alt: 'Avatar' })] }) }));
17
+ };
18
+ export default Avatar;
@@ -0,0 +1,2 @@
1
+ import Avatar from './avatar.component';
2
+ export { Avatar };
@@ -0,0 +1,2 @@
1
+ import Avatar from './avatar.component';
2
+ export { Avatar };
@@ -0,0 +1 @@
1
+ export * from './avatar';
@@ -0,0 +1 @@
1
+ export * from './avatar';
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { CheckboxType } from '../../../types';
3
+ declare const Checkbox: React.ForwardRefExoticComponent<CheckboxType & React.RefAttributes<HTMLInputElement>>;
4
+ export default Checkbox;
@@ -0,0 +1,14 @@
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 Checkbox = forwardRef(({ name, label, isError, checked, disabled, error, position = 'left', color, size = 'md', ...otherProps }, ref) => {
5
+ const checkbox = () => (_jsx("input", { id: name, name: name, "data-testid": name, ref: ref, type: 'checkbox', checked: checked, className: cls('checkbox', {
6
+ [`checkbox-color-${color}`]: color,
7
+ [`checkbox-size-${size}`]: size
8
+ }), disabled: disabled, ...otherProps }));
9
+ return (_jsxs(_Fragment, { children: [_jsxs("label", { className: cls('label', {
10
+ 'cursor-pointer': !disabled,
11
+ 'cursor-not-allowed': disabled
12
+ }), children: [position === 'left' && checkbox(), label && _jsx("span", { className: 'label-text', children: label }), position === 'right' && checkbox()] }), isError && _jsx("p", { className: 'text-red-500', children: error })] }));
13
+ });
14
+ export default Checkbox;
@@ -0,0 +1,2 @@
1
+ import Checkbox from './checkbox.component';
2
+ export { Checkbox };
@@ -0,0 +1,2 @@
1
+ import Checkbox from './checkbox.component';
2
+ export { Checkbox };
@@ -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;
@@ -3,7 +3,7 @@ import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'r
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, value, ...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();
@@ -21,9 +21,11 @@ const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
21
21
  const option = options.find((option) => String(option.value) === String(value));
22
22
  if (!option) {
23
23
  setLabel('');
24
+ setValueFilter(undefined);
24
25
  return;
25
26
  }
26
27
  setLabel(option.label);
28
+ setValueFilter(option.label);
27
29
  }, [value]);
28
30
  const handleFocus = useCallback(() => {
29
31
  if (disabled) {
@@ -48,4 +50,4 @@ const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
48
50
  : options.filter(({ label }) => label.includes(valueFilter)), [valueFilter, options]);
49
51
  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))) }))] }));
50
52
  });
51
- export default DropDown;
53
+ export default Dropdown;
@@ -0,0 +1,2 @@
1
+ import Dropdown from './dropdown.component';
2
+ export { Dropdown };
@@ -0,0 +1,2 @@
1
+ import Dropdown from './dropdown.component';
2
+ export { Dropdown };
@@ -1,3 +1,3 @@
1
- import { DropDown } from '../../ui/forms/drop-down';
2
- import { TextBox } from '../../ui/forms/text-box';
3
- export { DropDown, TextBox };
1
+ export * from '../../ui/forms/checkbox';
2
+ export * from '../../ui/forms/dropdown';
3
+ export * from '../../ui/forms/text-box';
@@ -1,3 +1,3 @@
1
- import { DropDown } from '../../ui/forms/drop-down';
2
- import { TextBox } from '../../ui/forms/text-box';
3
- export { DropDown, TextBox };
1
+ export * from '../../ui/forms/checkbox';
2
+ export * from '../../ui/forms/dropdown';
3
+ export * from '../../ui/forms/text-box';
@@ -0,0 +1 @@
1
+ export * from './string.utils';
@@ -0,0 +1 @@
1
+ export * from './string.utils';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Generates initials from the given name.
3
+ *
4
+ * @remarks
5
+ * This function takes a full name as input and returns the initials.
6
+ *
7
+ * @param name - The full name from which initials are generated.
8
+ * @returns The initials generated from the name.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Example 1:
13
+ * const name1 = "John Doe";
14
+ * const initials1 = getInitials(name1);
15
+ * console.log(initials1); // Output: "JD"
16
+ *
17
+ * // Example 2:
18
+ * const name2 = "Alice Bob Charlie";
19
+ * const initials2 = getInitials(name2);
20
+ * console.log(initials2); // Output: "AC"
21
+ * ```
22
+ *
23
+ * @public
24
+ */
25
+ export declare function getInitials(name: string): string;
26
+ /**
27
+ * Checks whether the provided string is a valid URL.
28
+ *
29
+ * @param uri - The string to be checked as a URL.
30
+ * @returns A boolean indicating whether the provided string is a valid URL.
31
+ *
32
+ * @remarks
33
+ * This function uses the URL constructor to validate whether the input is a well-formed URL.
34
+ * It returns true if the URL is valid and false otherwise.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Example 1:
39
+ * const url1 = "https://www.example.com";
40
+ * const isValid1 = isValidUrl(url1);
41
+ * console.log(isValid1); // Output: true
42
+ *
43
+ * // Example 2:
44
+ * const url2 = "not_a_valid_url";
45
+ * const isValid2 = isValidUrl(url2);
46
+ * console.log(isValid2); // Output: false
47
+ * ```
48
+ *
49
+ * @public
50
+ */
51
+ export declare function isValidUrl(uri?: string): boolean;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Generates initials from the given name.
3
+ *
4
+ * @remarks
5
+ * This function takes a full name as input and returns the initials.
6
+ *
7
+ * @param name - The full name from which initials are generated.
8
+ * @returns The initials generated from the name.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Example 1:
13
+ * const name1 = "John Doe";
14
+ * const initials1 = getInitials(name1);
15
+ * console.log(initials1); // Output: "JD"
16
+ *
17
+ * // Example 2:
18
+ * const name2 = "Alice Bob Charlie";
19
+ * const initials2 = getInitials(name2);
20
+ * console.log(initials2); // Output: "AC"
21
+ * ```
22
+ *
23
+ * @public
24
+ */
25
+ export function getInitials(name) {
26
+ const words = name.split(' ');
27
+ const getCharAt = (word) => word.charAt(0).toUpperCase();
28
+ if (words.length === 1) {
29
+ return name.substring(0, 2).toUpperCase();
30
+ }
31
+ if (words.length === 2) {
32
+ return words.map(getCharAt).join('');
33
+ }
34
+ return words
35
+ .filter((_, index) => index % 2 === 0)
36
+ .map(getCharAt)
37
+ .join('');
38
+ }
39
+ /**
40
+ * Checks whether the provided string is a valid URL.
41
+ *
42
+ * @param uri - The string to be checked as a URL.
43
+ * @returns A boolean indicating whether the provided string is a valid URL.
44
+ *
45
+ * @remarks
46
+ * This function uses the URL constructor to validate whether the input is a well-formed URL.
47
+ * It returns true if the URL is valid and false otherwise.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Example 1:
52
+ * const url1 = "https://www.example.com";
53
+ * const isValid1 = isValidUrl(url1);
54
+ * console.log(isValid1); // Output: true
55
+ *
56
+ * // Example 2:
57
+ * const url2 = "not_a_valid_url";
58
+ * const isValid2 = isValidUrl(url2);
59
+ * console.log(isValid2); // Output: false
60
+ * ```
61
+ *
62
+ * @public
63
+ */
64
+ export function isValidUrl(uri) {
65
+ if (!uri) {
66
+ return false;
67
+ }
68
+ try {
69
+ new URL(uri);
70
+ return true;
71
+ }
72
+ catch (ignored) {
73
+ return false;
74
+ }
75
+ }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@creativecodeco/ui",
3
- "description": "CreativeCode.com.co UI",
3
+ "description": "System Design CreativeCode.com.co",
4
4
  "keywords": [
5
- "CreativeCode.com.co",
5
+ "creativeCode.com.co",
6
6
  "creativecodeco/ui",
7
- "Tailwindcss",
8
- "Daisyui",
9
- "UI",
10
- "Framework Design"
7
+ "tailwindcss",
8
+ "daisyui",
9
+ "ui",
10
+ "framework design",
11
+ "design system"
11
12
  ],
12
- "version": "0.0.5",
13
+ "version": "0.2.0",
13
14
  "homepage": "https://github.com/creativecodeco/ui",
14
15
  "author": {
15
16
  "name": "John Toro",
@@ -46,9 +47,17 @@
46
47
  "tailwindcss": "3.4.0",
47
48
  "usehooks-ts": "2.9.1"
48
49
  },
50
+ "dependencies": {
51
+ "postcss": "8.4.33",
52
+ "postcss-import": "16.0.0",
53
+ "react": "18.2.0",
54
+ "react-hook-form": "7.49.3",
55
+ "tailwindcss": "3.4.1",
56
+ "usehooks-ts": "2.9.2"
57
+ },
49
58
  "devDependencies": {
50
59
  "@babel/core": "7.23.7",
51
- "@babel/preset-env": "7.23.7",
60
+ "@babel/preset-env": "7.23.8",
52
61
  "@babel/preset-react": "7.23.3",
53
62
  "@babel/preset-typescript": "7.23.3",
54
63
  "@jest/globals": "29.7.0",
@@ -60,20 +69,20 @@
60
69
  "@storybook/react": "7.6.7",
61
70
  "@storybook/react-webpack5": "7.6.7",
62
71
  "@storybook/test": "7.6.7",
63
- "@testing-library/dom": "9.3.3",
64
- "@testing-library/jest-dom": "6.1.6",
72
+ "@testing-library/dom": "9.3.4",
73
+ "@testing-library/jest-dom": "6.2.0",
65
74
  "@testing-library/react": "14.1.2",
66
75
  "@testing-library/user-event": "14.5.2",
67
76
  "@types/jest": "29.5.11",
68
- "@types/node": "20.10.6",
69
- "@types/react": "18.2.46",
77
+ "@types/node": "20.10.8",
78
+ "@types/react": "18.2.47",
70
79
  "@types/react-dom": "18.2.18",
71
- "@typescript-eslint/eslint-plugin": "6.17.0",
80
+ "@typescript-eslint/eslint-plugin": "6.18.1",
72
81
  "autoprefixer": "10.4.16",
73
- "chromatic": "10.2.0",
82
+ "chromatic": "10.2.1",
74
83
  "classnames": "2.5.1",
75
84
  "cpx2": "7.0.1",
76
- "daisyui": "4.4.24",
85
+ "daisyui": "4.5.0",
77
86
  "eslint": "8.56.0",
78
87
  "eslint-config-prettier": "9.1.0",
79
88
  "eslint-config-standard": "17.1.0",
@@ -81,9 +90,9 @@
81
90
  "eslint-config-standard-with-typescript": "43.0.0",
82
91
  "eslint-plugin-import": "2.29.1",
83
92
  "eslint-plugin-import-order": "2.1.4",
84
- "eslint-plugin-n": "16.6.1",
93
+ "eslint-plugin-n": "16.6.2",
85
94
  "eslint-plugin-node": "11.1.0",
86
- "eslint-plugin-prettier": "5.1.2",
95
+ "eslint-plugin-prettier": "5.1.3",
87
96
  "eslint-plugin-promise": "6.1.1",
88
97
  "eslint-plugin-react": "7.33.2",
89
98
  "eslint-plugin-standard": "5.0.0",
@@ -94,25 +103,19 @@
94
103
  "jest-environment-jsdom": "29.7.0",
95
104
  "jest-junit": "16.0.0",
96
105
  "jest-transform-css": "6.0.1",
97
- "postcss": "8.4.32",
98
- "postcss-cli": "11.0.0",
99
- "postcss-import": "15.1.0",
106
+ "postcss-cli": "^11.0.0",
100
107
  "prettier": "3.1.1",
101
108
  "prop-types": "15.8.1",
102
- "react": "18.2.0",
103
109
  "react-dom": "18.2.0",
104
- "react-hook-form": "7.49.2",
105
- "react-icons": "4.12.0",
110
+ "react-icons": "5.0.0",
106
111
  "storybook": "7.6.7",
107
112
  "storybook-addon-themes": "6.1.0",
108
113
  "string-width": "7.0.0",
109
- "tailwindcss": "3.4.0",
110
114
  "ts-jest": "29.1.1",
111
115
  "ts-node": "10.9.2",
112
116
  "tsc-alias": "1.8.8",
113
117
  "tsconfig-paths-webpack-plugin": "4.1.0",
114
- "typescript": "5.3.3",
115
- "usehooks-ts": "2.9.1"
118
+ "typescript": "5.3.3"
116
119
  },
117
120
  "files": [
118
121
  "lib"
@@ -1,4 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import DropDown from './drop-down.component';
2
- export { DropDown };
@@ -1,2 +0,0 @@
1
- import DropDown from './drop-down.component';
2
- export { DropDown };