-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
133 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { FormSection } from "./FormSection"; | ||
import { Input, Switch } from "../../components"; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction | ||
const meta: Meta<typeof FormSection> = { | ||
title: "fragments/FormSection", | ||
component: FormSection, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args | ||
export const Default: Story = { | ||
args: { | ||
title: 'Profile', | ||
description: 'These are my personal information.', | ||
children: ( | ||
<> | ||
<Input label="Firstname" /> | ||
<Input label="Lastname" /> | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
export const Horizontal: Story = { | ||
args: { | ||
title: 'Profile', | ||
description: 'These are my personal information.', | ||
direction: 'horizontal', | ||
children: ( | ||
<> | ||
<Input label="Firstname" /> | ||
<Input label="Lastname" /> | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
export const HorizontalSimple: Story = { | ||
args: { | ||
title: 'Notifications', | ||
description: 'Turn on/off email notifications.', | ||
direction: 'horizontal', | ||
children: <Switch />, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Primary UI component for Form Sections | ||
*/ | ||
|
||
import { tv } from "@nextui-org/react"; | ||
|
||
export interface FormSectionProps { | ||
children: React.ReactNode; | ||
title: string; | ||
description?: string; | ||
direction?: 'vertical' | 'horizontal' | ||
} | ||
|
||
const formSection = tv({ | ||
slots: { | ||
base: 'flex gap-4 py-6 border-t-1 border-default-100 max-w-3xl', | ||
content: 'flex flex-col gap-4 flex-1', | ||
info: 'flex-1', | ||
description: 'text-small text-foreground-500', | ||
}, | ||
variants: { | ||
direction: { | ||
horizontal: { | ||
base: 'flex-row', | ||
content: 'items-end justify-center', | ||
}, | ||
vertical: { | ||
base: 'flex-col', | ||
content: 'items-start', | ||
} | ||
} | ||
}, | ||
defaultVariants: { | ||
direction: 'vertical', | ||
}, | ||
}); | ||
|
||
export const FormSection: React.FC<FormSectionProps> = ({ children, title, description, ...props }) => { | ||
const { base, content, description: descriptionClasses, info } = formSection(props); | ||
|
||
return ( | ||
<div className={base()}> | ||
<div className={info()}> | ||
<h3>{title}</h3> | ||
<p className={descriptionClasses()}>{description}</p> | ||
</div> | ||
<div className={content()}> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters