diff --git a/lib/controls/check-box-input.tsx b/lib/controls/check-box-input.tsx index 43dfbb0..afeb67f 100644 --- a/lib/controls/check-box-input.tsx +++ b/lib/controls/check-box-input.tsx @@ -2,7 +2,7 @@ import { forwardRef } from "react"; import type { InputHTMLAttributes } from "react"; import { useField } from "~/use-field"; -type CheckBoxInputProps = Omit< +export type CheckBoxInputProps = Omit< InputHTMLAttributes, "type" > & { diff --git a/lib/controls/input.tsx b/lib/controls/input.tsx index c0704a9..1916bab 100644 --- a/lib/controls/input.tsx +++ b/lib/controls/input.tsx @@ -2,7 +2,7 @@ import { forwardRef } from "react"; import type { InputHTMLAttributes } from "react"; import { useField } from "~/use-field"; -type InputProps = InputHTMLAttributes & { +export type InputProps = InputHTMLAttributes & { name: string; }; diff --git a/lib/controls/radio-button-input.tsx b/lib/controls/radio-button-input.tsx deleted file mode 100644 index 444881a..0000000 --- a/lib/controls/radio-button-input.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { forwardRef } from "react"; -import type { InputHTMLAttributes } from "react"; -import { useField } from "~/use-field"; - -type RadioButtonInputProps = Omit< - InputHTMLAttributes, - "type" -> & { - name: string; - value: string; -}; - -export const RadioButtonInput = forwardRef< - HTMLInputElement, - RadioButtonInputProps ->(({ name, value, onChange, ...props }, ref) => { - let field = useField(name); - - return ( - { - onChange?.(e); - field.setValue(value); - field.setTouched(); - }} - value={value} - /> - ); -}); diff --git a/lib/controls/radio-input.tsx b/lib/controls/radio-input.tsx new file mode 100644 index 0000000..04cfba9 --- /dev/null +++ b/lib/controls/radio-input.tsx @@ -0,0 +1,33 @@ +import { forwardRef } from "react"; +import type { InputHTMLAttributes } from "react"; +import { useField } from "~/use-field"; + +export type RadioInputProps = Omit< + InputHTMLAttributes, + "type" +> & { + name: string; + value: string; +}; + +export const RadioInput = forwardRef( + ({ name, value, onChange, ...props }, ref) => { + let field = useField(name); + + return ( + { + onChange?.(e); + field.setValue(value); + field.setTouched(); + }} + value={value} + /> + ); + } +); diff --git a/lib/controls/select.tsx b/lib/controls/select.tsx index d480e9c..c908467 100644 --- a/lib/controls/select.tsx +++ b/lib/controls/select.tsx @@ -2,7 +2,7 @@ import { forwardRef } from "react"; import type { SelectHTMLAttributes } from "react"; import { useField } from "~/use-field"; -type SelectProps = SelectHTMLAttributes & { +export type SelectProps = SelectHTMLAttributes & { name: string; }; diff --git a/lib/controls/text-area.tsx b/lib/controls/text-area.tsx index 4fd2f31..a42ac86 100644 --- a/lib/controls/text-area.tsx +++ b/lib/controls/text-area.tsx @@ -2,11 +2,11 @@ import { forwardRef } from "react"; import type { TextareaHTMLAttributes } from "react"; import { useField } from "~/use-field"; -type InputProps = TextareaHTMLAttributes & { +export type TextAreaProps = TextareaHTMLAttributes & { name: string; }; -export const TextArea = forwardRef( +export const TextArea = forwardRef( ({ name, onChange, ...props }, ref) => { let field = useField(name); diff --git a/lib/index.ts b/lib/index.ts index fe5f233..77ab1a6 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,2 +1,36 @@ -export { SignalForm } from "./form"; export { Input } from "./controls/input"; +export type { InputProps } from "./controls/input"; +export { CheckBoxInput } from "./controls/check-box-input"; +export type { CheckBoxInputProps } from "./controls/check-box-input"; +export { RadioInput } from "./controls/radio-input"; +export type { RadioInputProps } from "./controls/radio-input"; +export { Select } from "./controls/select"; +export type { SelectProps } from "./controls/select"; +export { TextArea } from "./controls/text-area"; +export type { TextAreaProps } from "./controls/text-area"; + +export { parseFormData } from "./utils/parse-form-data"; + +export * from "./utils/validate"; +export type * from "./utils/validate"; + +export * from "./context"; +export type * from "./context"; + +export * from "./fields-array-for"; +export type * from "./fields-array-for"; + +export * from "./fields-for"; +export type * from "./fields-for"; + +export * from "./form"; +export type * from "./form"; + +export * from "./use-field"; +export type * from "./use-field"; + +export * from "./use-fields-array"; +export type * from "./use-fields-array"; + +export * from "./use-is-submitting"; +export type * from "./use-is-submitting"; diff --git a/lib/utils/parse-form-data.ts b/lib/utils/parse-form-data.ts index 46f52d9..ac22e54 100644 --- a/lib/utils/parse-form-data.ts +++ b/lib/utils/parse-form-data.ts @@ -1,6 +1,6 @@ type ParsedObject = { [key: string]: any }; -export function parseFormData(formData: FormData) { +export function parseFormData(formData: FormData): ParsedObject { let result: ParsedObject = {}; // Iterate over each form data entry diff --git a/package.json b/package.json index 3522933..1abc20b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test": "vitest run", "lint": "eslint . --ext .ts,.tsx,.js,.jsx", "format": "prettier --write .", - "check": "tsc && npm run css-check", + "check": "tsc", "release": "npm run check && npm run build && changeset publish", "storybook": "storybook dev -p 6006", "build-storybook": "storybook build", diff --git a/scripts/css-check.ts b/scripts/css-check.ts deleted file mode 100644 index d423b4c..0000000 --- a/scripts/css-check.ts +++ /dev/null @@ -1,21 +0,0 @@ -import recursive from "recursive-readdir"; -import { blue, bold } from "kolorist"; - -// TODO: Change to relative path -recursive("./lib", ["stories"], (error, files) => { - if (error) { - // eslint-disable-next-line no-console - console.error(error); - } else { - files.forEach((file) => { - if (file.endsWith(".css") && !file.endsWith(".module.css")) { - let fileName = file?.split(".").slice(0, -1).join("."); - - throw new Error( - // prettier-ignore - `Only CSS modules are supported. Rename ${blue(bold(fileName + ".css"))} to ${blue(bold(fileName + ".module.css"))}` - ); - } - }); - } -}); diff --git a/src/App.tsx b/src/App.tsx index 1181f60..847dc14 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { Button } from "../lib"; +import { SignalForm } from "../lib"; import "./App.css"; function App() { @@ -28,7 +28,7 @@ function App() {

Presents

Vite + React

-