-
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
8 changed files
with
195 additions
and
59 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,46 @@ | ||
import { Fragment, ReactElement } from 'react' | ||
import { Divider, Spacer } from '@chakra-ui/react' | ||
import cx from 'classnames' | ||
|
||
export type FormProps = { | ||
sections?: FormSection[] | ||
} | ||
|
||
export type FormSection = { | ||
title: string | ||
rows?: FormRow[] | ||
} | ||
|
||
export type FormRow = { | ||
label: string | ||
content?: ReactElement | ||
} | ||
|
||
export const Form = ({ sections }: FormProps) => ( | ||
<div className={cx('flex', 'flex-col', 'gap-0')}> | ||
{sections?.map((section, sectionIndex) => ( | ||
<Fragment key={`section-${sectionIndex}`}> | ||
<div className={cx('flex', 'flex-col', 'gap-1', 'py-1.5')}> | ||
<span className={cx('font-bold')}>{section.title}</span> | ||
{section.rows?.map((row, rowIndex) => ( | ||
<div | ||
key={`row-${rowIndex}`} | ||
className={cx( | ||
'flex', | ||
'flex-row', | ||
'items-center', | ||
'gap-1', | ||
`h-[40px]`, | ||
)} | ||
> | ||
<span>{row.label}</span> | ||
<Spacer /> | ||
{row.content} | ||
</div> | ||
))} | ||
</div> | ||
{sectionIndex !== sections?.length - 1 ? <Divider /> : null} | ||
</Fragment> | ||
))} | ||
</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
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
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
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
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
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
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,91 @@ | ||
import { IconButton, Switch } from '@chakra-ui/react' | ||
// @ts-expect-error ignored | ||
import { Form, IconEdit, IconDelete } from '@koupr/ui' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import cx from 'classnames' | ||
|
||
const meta: Meta<typeof Form> = { | ||
title: 'Components/Form', | ||
component: Form, | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof Form> | ||
|
||
export const Default: Story = { | ||
args: { | ||
sections: [ | ||
{ | ||
title: 'Basics', | ||
rows: [ | ||
{ | ||
label: 'Full name', | ||
content: ( | ||
<> | ||
<span>Bruce Wayne</span> | ||
<IconButton | ||
icon={<IconEdit />} | ||
className={cx('h-[40px]', 'w-[40px]')} | ||
aria-label="Edit" | ||
/> | ||
</> | ||
), | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'Credentials', | ||
rows: [ | ||
{ | ||
label: 'Email', | ||
content: ( | ||
<> | ||
<span>bruce.wayne@koupr.com</span> | ||
<IconButton | ||
icon={<IconEdit />} | ||
className={cx('h-[40px]', 'w-[40px]')} | ||
aria-label="Edit" | ||
/> | ||
</> | ||
), | ||
}, | ||
{ | ||
label: 'Password', | ||
content: ( | ||
<IconButton | ||
icon={<IconEdit />} | ||
className={cx('h-[40px]', 'w-[40px]')} | ||
aria-label="Edit" | ||
/> | ||
), | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'Theme', | ||
rows: [ | ||
{ | ||
label: 'Dark mode', | ||
content: <Switch />, | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'Advanced', | ||
rows: [ | ||
{ | ||
label: 'Delete account', | ||
content: ( | ||
<IconButton | ||
icon={<IconDelete />} | ||
variant="solid" | ||
colorScheme="red" | ||
aria-label="Delete account" | ||
/> | ||
), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
} |