@bouko/react 2.7.7 → 2.7.8

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.
@@ -4,13 +4,14 @@ type FieldProps<T> = {
4
4
  label?: string;
5
5
  style?: string;
6
6
  value?: T;
7
- update: (x: T) => void;
7
+ update?: (x: T) => void;
8
+ updateForm?: (id: string, x: T) => void;
8
9
  required?: boolean;
9
10
  disabled?: boolean;
10
11
  note?: ReactNode;
11
12
  };
12
13
  type Variant = "normal" | "ghost";
13
- type Props = Omit<FieldProps<string>, "id"> & {
14
+ type Props<T> = FieldProps<T> & {
14
15
  type?: "text" | "number" | "email" | "password";
15
16
  variant?: Variant;
16
17
  style?: string;
@@ -34,5 +35,5 @@ type Props = Omit<FieldProps<string>, "id"> & {
34
35
  * @param {string} placeholder - Placeholder text for the input. (optional)
35
36
  * @param {Function} onEnter - Callback when `Enter` key is pressed. (optional)
36
37
  **/
37
- export default function Input({ type, variant, style, value, update, onEnter, disabled, placeholder, ...props }: Props): import("react/jsx-runtime").JSX.Element;
38
+ export default function Input<T>({ id, type, variant, style, value, update, updateForm, onEnter, disabled, placeholder, ...props }: Props<T>): import("react/jsx-runtime").JSX.Element;
38
39
  export {};
@@ -25,8 +25,14 @@ const fieldStyles = {
25
25
  * @param {string} placeholder - Placeholder text for the input. (optional)
26
26
  * @param {Function} onEnter - Callback when `Enter` key is pressed. (optional)
27
27
  **/
28
- export default function Input({ type = "text", variant, style, value, update, onEnter, disabled, placeholder, ...props }) {
29
- return (_jsx(Field, { ...props, children: _jsx("input", { type: type, className: cn(styles({ variant }), style), placeholder: placeholder, value: value, onChange: ({ target: { value } }) => update?.(value), onKeyUp: ({ key }) => key === "Enter" && value ? onEnter?.(value) : null, disabled: disabled }) }));
28
+ export default function Input({ id, type = "text", variant, style, value, update, updateForm, onEnter, disabled, placeholder, ...props }) {
29
+ const handleUpdate = (value) => {
30
+ if (id && updateForm)
31
+ updateForm(id, value);
32
+ else if (update)
33
+ update(value);
34
+ };
35
+ return (_jsx(Field, { ...props, children: _jsx("input", { type: type, className: cn(styles({ variant }), style), placeholder: placeholder, value: value, onChange: ({ target: { value } }) => handleUpdate(value), onKeyUp: ({ key }) => key === "Enter" && value ? onEnter?.(value) : null, disabled: disabled }) }));
30
36
  }
31
37
  const styles = tv({
32
38
  base: "px-3 py-2 duration-200 rounded text-xs sm:text-sm placeholder:text-primary-darker text-primary disabled:brightness-90 disabled:cursor-not-allowed",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.7.7",
4
+ "version": "2.7.8",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",