Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add story
  • Loading branch information
aslilac committed Jan 11, 2024
commit 985d8d0474b8ea5b3d65b3ce496dd44b6935c858
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import { mockApiError, MockTemplate } from "testHelpers/entities";
import { TemplateSettingsPageView } from "./TemplateSettingsPageView";
import type { Meta, StoryObj } from "@storybook/react";

const meta: Meta<typeof TemplateSettingsPageView> = {
title: "pages/TemplateSettingsPage",
Expand Down
69 changes: 69 additions & 0 deletions site/src/utils/formUtils.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { Meta, StoryObj } from "@storybook/react";
import { type FC } from "react";
import TextField from "@mui/material/TextField";
import { Form } from "components/Form/Form";
import { getFormHelpers } from "./formUtils";
import { useFormik } from "formik";
import { action } from "@storybook/addon-actions";

interface ExampleFormProps {
value?: string;
maxLength?: number;
}

const ExampleForm: FC<ExampleFormProps> = ({ value, maxLength }) => {
const form = useFormik({
initialValues: {
value,
},
onSubmit: action("submit"),
});

const getFieldHelpers = getFormHelpers(form, null);

return (
<Form>
<TextField
label="Value"
rows={2}
{...getFieldHelpers("value", { maxLength })}
/>
</Form>
);
};

const meta: Meta<typeof ExampleForm> = {
title: "utilities/getFormHelpers",
component: ExampleForm,
};

export default meta;
type Story = StoryObj<typeof Form>;

export const UnderMaxLength: Story = {
args: {
value: "a".repeat(98),
maxLength: 128,
},
};

export const CloseToMaxLength: Story = {
args: {
value: "a".repeat(99),
maxLength: 128,
},
};

export const AtMaxLength: Story = {
args: {
value: "a".repeat(128),
maxLength: 128,
},
};

export const OverMaxLength: Story = {
args: {
value: "a".repeat(129),
maxLength: 128,
},
};