@latte-macchiat-io/latte-vanilla-components 0.0.275 → 0.0.277

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latte-macchiat-io/latte-vanilla-components",
3
- "version": "0.0.275",
3
+ "version": "0.0.277",
4
4
  "description": "Beautiful components for amazing projects, with a touch of Vanilla 🥤",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,12 +1,11 @@
1
1
  import { clsx } from 'clsx';
2
- import { inputRecipe, type InputVariants } from './styles.css';
2
+ import { inputRecipe } from './styles.css';
3
3
 
4
4
  import { InputType } from './types';
5
5
 
6
- export type InputProps = React.InputHTMLAttributes<HTMLInputElement> &
7
- InputVariants & {
8
- type?: InputType;
9
- };
6
+ export type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {
7
+ type?: InputType;
8
+ };
10
9
 
11
10
  export const Input = ({ name, type = 'text', value, required, placeholder, className }: InputProps) => (
12
11
  <input id={name} name={name} type={type} value={value} required={required} placeholder={placeholder} className={clsx(inputRecipe(), className)} />
@@ -1,13 +1,11 @@
1
1
  import { clsx } from 'clsx';
2
2
 
3
- import { textareaRecipe, type TextareaVariants } from './styles.css';
3
+ import { textareaRecipe } from './styles.css';
4
4
 
5
- export type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement> &
6
- TextareaVariants & {
7
- name: string;
8
- hasError?: boolean;
9
- };
5
+ export type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement> & {
6
+ name: string;
7
+ };
10
8
 
11
- export const Textarea = ({ name, size, variant, resize, rows, className }: TextareaProps) => (
12
- <textarea id={name} rows={rows} name={name} className={clsx(textareaRecipe({ size, variant, resize }), className)} />
9
+ export const Textarea = ({ name, rows, className }: TextareaProps) => (
10
+ <textarea id={name} rows={rows} name={name} className={clsx(textareaRecipe(), className)} />
13
11
  );
@@ -1,4 +1,4 @@
1
- export { TextField, type TextFieldProps, type InputType } from './';
1
+ export { TextField, type TextFieldProps } from './';
2
2
  export { type TextFieldVariants } from './styles.css';
3
3
 
4
4
  export * from './Input/export';
@@ -1,47 +1,52 @@
1
1
  import { clsx } from 'clsx';
2
2
  import { useMemo } from 'react';
3
+
3
4
  import { Input } from './Input';
4
5
  import { InputType } from './Input/types';
6
+
5
7
  import { errorMessage, messageContainer, textFieldRecipe } from './styles.css';
6
8
  import { Textarea } from './Textarea';
7
9
 
8
- export type TextFieldProps = React.HTMLAttributes<HTMLDivElement> & {
10
+ type CommonProps = {
9
11
  name: string;
10
12
  label?: string;
11
- value?: string;
12
- rows?: number;
13
- required?: boolean;
14
- placeholder?: string;
15
13
  errors?: string | string[];
16
14
  type?: InputType | 'textarea';
17
- onChange?: (e: { target: { value: string | undefined } }) => void | undefined;
18
15
  };
19
16
 
17
+ export type TextFieldProps =
18
+ | (React.InputHTMLAttributes<HTMLInputElement> & CommonProps)
19
+ | (React.TextareaHTMLAttributes<HTMLTextAreaElement> & CommonProps);
20
+
20
21
  export const TextField = (props: TextFieldProps) => {
22
+ const { label, name, errors, type, className, ...rest } = props;
21
23
  const hasErrors = useMemo(() => {
22
- if (!props.errors) return false;
23
- if (Array.isArray(props.errors)) return props.errors.length > 0;
24
- return Boolean(props.errors);
25
- }, [props.errors]);
24
+ if (!errors) return false;
25
+ if (Array.isArray(errors)) return errors.length > 0;
26
+ return Boolean(errors);
27
+ }, [errors]);
26
28
 
27
- const isTextarea = props.type === 'textarea';
29
+ const isTextarea = type === 'textarea';
28
30
 
29
31
  return (
30
- <div className={clsx(textFieldRecipe(), props.className)}>
31
- {props.label && <label htmlFor={props.name}>{props.label}</label>}
32
-
33
- {isTextarea ? <Textarea {...props} /> : <Input {...props} />}
32
+ <div className={clsx(textFieldRecipe(), className)}>
33
+ {label && <label htmlFor={name}>{label}</label>}
34
34
 
35
+ {isTextarea ? (
36
+ <Textarea {...(rest as React.TextareaHTMLAttributes<HTMLTextAreaElement>)} name={name} />
37
+ ) : (
38
+ <Input {...(rest as React.InputHTMLAttributes<HTMLInputElement>)} name={name} type={type as InputType} />
39
+ )}
35
40
  {hasErrors && (
36
41
  <div className={messageContainer}>
37
- {Array.isArray(props.errors) ? (
38
- props.errors.map((error, index) => (
42
+ {Array.isArray(errors) ? (
43
+ errors.map((error, index) => (
39
44
  <span key={index} className={errorMessage}>
40
45
  {error}
41
46
  </span>
42
47
  ))
43
48
  ) : (
44
- <span className={errorMessage}>{props.errors}</span>
49
+ <span className={errorMessage}>{errors}</span>
45
50
  )}
46
51
  </div>
47
52
  )}