@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.
Files changed (43) hide show
  1. package/lib/hooks/index.d.ts +2 -0
  2. package/lib/hooks/index.js +2 -0
  3. package/lib/hooks/use-safe-button-props.hook.d.ts +283 -0
  4. package/lib/hooks/use-safe-button-props.hook.js +17 -0
  5. package/lib/index.d.ts +2 -1
  6. package/lib/index.js +1 -1
  7. package/lib/theme/css/button.css +65 -0
  8. package/lib/theme/css/main.css +2 -0
  9. package/lib/theme/css/radio.css +47 -0
  10. package/lib/theme/main.css +1572 -149
  11. package/lib/types/index.d.ts +3 -3
  12. package/lib/types/index.js +1 -3
  13. package/lib/types/ui/base/constants.types.d.ts +3 -0
  14. package/lib/types/ui/base/dom.types.d.ts +3 -0
  15. package/lib/types/ui/base/dom.types.js +1 -0
  16. package/lib/types/ui/base/index.d.ts +1 -0
  17. package/lib/types/ui/components/avatar.types.d.ts +1 -1
  18. package/lib/types/ui/components/button.types.d.ts +13 -0
  19. package/lib/types/ui/components/button.types.js +1 -0
  20. package/lib/types/ui/components/index.d.ts +2 -2
  21. package/lib/types/ui/forms/checkbox.types.d.ts +10 -4
  22. package/lib/types/ui/forms/index.d.ts +1 -0
  23. package/lib/types/ui/forms/radio.types.d.ts +19 -0
  24. package/lib/types/ui/forms/radio.types.js +1 -0
  25. package/lib/ui/components/button/button.component.d.ts +4 -0
  26. package/lib/ui/components/button/button.component.js +20 -0
  27. package/lib/ui/components/button/index.d.ts +2 -0
  28. package/lib/ui/components/button/index.js +2 -0
  29. package/lib/ui/components/index.d.ts +1 -0
  30. package/lib/ui/components/index.js +1 -0
  31. package/lib/ui/forms/checkbox/checkbox.component.js +10 -3
  32. package/lib/ui/forms/dropdown/dropdown.component.js +1 -1
  33. package/lib/ui/forms/index.d.ts +2 -0
  34. package/lib/ui/forms/index.js +2 -0
  35. package/lib/ui/forms/radio/index.d.ts +2 -0
  36. package/lib/ui/forms/radio/index.js +2 -0
  37. package/lib/ui/forms/radio/radio.component.d.ts +4 -0
  38. package/lib/ui/forms/radio/radio.component.js +21 -0
  39. package/lib/ui/forms/radio-list/index.d.ts +2 -0
  40. package/lib/ui/forms/radio-list/index.js +2 -0
  41. package/lib/ui/forms/radio-list/radio-list.component.d.ts +3 -0
  42. package/lib/ui/forms/radio-list/radio-list.component.js +9 -0
  43. package/package.json +23 -23
@@ -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';
@@ -1,3 +1 @@
1
- export * from './ui/base';
2
- export * from './ui/components';
3
- export * from './ui/forms';
1
+ export {};
@@ -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,3 @@
1
+ /// <reference types="react" />
2
+ export type ButtonEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
3
+ export type ButtonEventHandler = React.MouseEventHandler<HTMLButtonElement>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,3 @@
1
1
  export type * from './constants.types';
2
+ export type * from './dom.types';
2
3
  export type * from './error.types';
@@ -1,4 +1,4 @@
1
- import { SizeType } from '../../../types';
1
+ import type { SizeType } from '../../../types';
2
2
  export interface AvatarType {
3
3
  src: string;
4
4
  size?: SizeType;
@@ -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
- import { AvatarType } from './avatar.types';
2
- export type { AvatarType };
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 CheckboxType extends ErrorType {
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?: 'left' | 'right';
7
- color?: 'primary' | 'secondary' | 'accent' | 'success' | 'warning' | 'info' | 'error';
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;
@@ -1,3 +1,4 @@
1
1
  export type * from './checkbox.types';
2
2
  export type * from './dropdown.types';
3
+ export type * from './radio.types';
3
4
  export type * from './text-box.types';
@@ -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,4 @@
1
+ import React from 'react';
2
+ import { type ButtonType } from '../../../types';
3
+ declare const Button: React.ForwardRefExoticComponent<ButtonType & React.RefAttributes<HTMLButtonElement>>;
4
+ export default Button;
@@ -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;
@@ -0,0 +1,2 @@
1
+ import Button from './button.component';
2
+ export { Button };
@@ -0,0 +1,2 @@
1
+ import Button from './button.component';
2
+ export { Button };
@@ -1 +1,2 @@
1
1
  export * from './avatar';
2
+ export * from './button';
@@ -1 +1,2 @@
1
1
  export * from './avatar';
2
+ export * from './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, 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', {
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 '../../../ui/forms';
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);
@@ -1,3 +1,5 @@
1
1
  export * from '../../ui/forms/checkbox';
2
2
  export * from '../../ui/forms/dropdown';
3
+ export * from '../../ui/forms/radio';
4
+ export * from '../../ui/forms/radio-list';
3
5
  export * from '../../ui/forms/text-box';
@@ -1,3 +1,5 @@
1
1
  export * from '../../ui/forms/checkbox';
2
2
  export * from '../../ui/forms/dropdown';
3
+ export * from '../../ui/forms/radio';
4
+ export * from '../../ui/forms/radio-list';
3
5
  export * from '../../ui/forms/text-box';
@@ -0,0 +1,2 @@
1
+ import Radio from './radio.component';
2
+ export { Radio };
@@ -0,0 +1,2 @@
1
+ import Radio from './radio.component';
2
+ export { Radio };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { RadioType } from '../../../types';
3
+ declare const Radio: React.ForwardRefExoticComponent<RadioType & React.RefAttributes<HTMLInputElement>>;
4
+ export default Radio;
@@ -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,2 @@
1
+ import RadioList from './radio-list.component';
2
+ export { RadioList };
@@ -0,0 +1,2 @@
1
+ import RadioList from './radio-list.component';
2
+ export { RadioList };
@@ -0,0 +1,3 @@
1
+ import type { RadioListType } from '../../../types';
2
+ declare const RadioList: ({ name, options, isError, error, value, ...otherOptions }: RadioListType) => import("react/jsx-runtime").JSX.Element | undefined;
3
+ export default RadioList;
@@ -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.2.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.2"
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.7",
65
- "@storybook/addon-interactions": "7.6.7",
66
- "@storybook/addon-links": "7.6.7",
67
- "@storybook/addon-mdx-gfm": "7.6.7",
68
- "@storybook/blocks": "7.6.7",
69
- "@storybook/react": "7.6.7",
70
- "@storybook/react-webpack5": "7.6.7",
71
- "@storybook/test": "7.6.7",
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.10.8",
78
- "@types/react": "18.2.47",
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.18.1",
81
- "autoprefixer": "10.4.16",
82
- "chromatic": "10.2.1",
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.5.0",
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.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": "^11.0.0",
107
- "prettier": "3.1.1",
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.0",
111
- "storybook": "7.6.7",
110
+ "react-icons": "5.0.1",
111
+ "storybook": "7.6.10",
112
112
  "storybook-addon-themes": "6.1.0",
113
- "string-width": "7.0.0",
114
- "ts-jest": "29.1.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",