Skip to content

Commit

Permalink
feat: add hidden field (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
totraev authored Dec 19, 2024
1 parent 12b8043 commit 95c9c58
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-keys-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@babylonlabs-io/bbn-core-ui": patch
---

add hidden field
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from "./widgets/form/TextField";
export * from "./widgets/form/CheckboxField";
export * from "./widgets/form/RadioField";
export * from "./widgets/form/SelectField";
export * from "./widgets/form/HiddenField";
export * from "./widgets/form/hooks";
export * from "./widgets/form/hooks";

Expand Down
28 changes: 28 additions & 0 deletions src/widgets/form/HiddenField/HiddenField.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Meta, StoryObj } from "@storybook/react";

import { Form } from "@/widgets/form/Form";

import { HiddenField } from "./HiddenField";

const meta: Meta<typeof HiddenField> = {
component: HiddenField,
tags: ["autodocs"],
};

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
name: "hidden_field",
value: "test",
},
decorators: [
(Story) => (
<Form onChange={console.log}>
<Story />
</Form>
),
],
};
9 changes: 9 additions & 0 deletions src/widgets/form/HiddenField/HiddenField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { HTMLProps } from "react";
import { useFormContext } from "react-hook-form";

export function HiddenField({ name, ...inputProps }: HTMLProps<HTMLInputElement> & { name: string }) {
const { register } = useFormContext();
const props = register(name);

return <input {...inputProps} {...props} type="hidden" />;
}
1 change: 1 addition & 0 deletions src/widgets/form/HiddenField/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./HiddenField";

0 comments on commit 95c9c58

Please sign in to comment.