Skip to content

Commit

Permalink
Add exports
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Nov 13, 2023
1 parent c39867d commit da7913d
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 65 deletions.
2 changes: 1 addition & 1 deletion lib/controls/check-box-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLInputElement>,
"type"
> & {
Expand Down
2 changes: 1 addition & 1 deletion lib/controls/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { forwardRef } from "react";
import type { InputHTMLAttributes } from "react";
import { useField } from "~/use-field";

type InputProps = InputHTMLAttributes<HTMLInputElement> & {
export type InputProps = InputHTMLAttributes<HTMLInputElement> & {
name: string;
};

Expand Down
34 changes: 0 additions & 34 deletions lib/controls/radio-button-input.tsx

This file was deleted.

33 changes: 33 additions & 0 deletions lib/controls/radio-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { forwardRef } from "react";
import type { InputHTMLAttributes } from "react";
import { useField } from "~/use-field";

export type RadioInputProps = Omit<
InputHTMLAttributes<HTMLInputElement>,
"type"
> & {
name: string;
value: string;
};

export const RadioInput = forwardRef<HTMLInputElement, RadioInputProps>(
({ name, value, onChange, ...props }, ref) => {
let field = useField<string>(name);

return (
<input
type="radio"
ref={ref}
{...props}
name={field.name}
checked={field.value.value?.toString() === value.toString()}
onChange={(e) => {
onChange?.(e);
field.setValue(value);
field.setTouched();
}}
value={value}
/>
);
}
);
2 changes: 1 addition & 1 deletion lib/controls/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { forwardRef } from "react";
import type { SelectHTMLAttributes } from "react";
import { useField } from "~/use-field";

type SelectProps = SelectHTMLAttributes<HTMLSelectElement> & {
export type SelectProps = SelectHTMLAttributes<HTMLSelectElement> & {
name: string;
};

Expand Down
4 changes: 2 additions & 2 deletions lib/controls/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { forwardRef } from "react";
import type { TextareaHTMLAttributes } from "react";
import { useField } from "~/use-field";

type InputProps = TextareaHTMLAttributes<HTMLTextAreaElement> & {
export type TextAreaProps = TextareaHTMLAttributes<HTMLTextAreaElement> & {
name: string;
};

export const TextArea = forwardRef<HTMLTextAreaElement, InputProps>(
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
({ name, onChange, ...props }, ref) => {
let field = useField<string>(name);

Expand Down
36 changes: 35 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 1 addition & 1 deletion lib/utils/parse-form-data.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 0 additions & 21 deletions scripts/css-check.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button } from "../lib";
import { SignalForm } from "../lib";
import "./App.css";

function App() {
Expand Down Expand Up @@ -28,7 +28,7 @@ function App() {
<h2>Presents</h2>
<h1>Vite + React</h1>
<div className="card">
<Button size="medium" type="primary" />
<SignalForm></SignalForm>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
Expand Down

0 comments on commit da7913d

Please sign in to comment.