Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mantine): poc for new ChildForm component #3944

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.paper {
border-radius: 0 0 var(--mantine-radius-default) var(--mantine-radius-default);
box-shadow:
inset 0 1px 0 -1px #e5e8e8,
inset 0 4px 2px -2px rgb(55 55 55 / 3%);
}
64 changes: 64 additions & 0 deletions packages/mantine/src/components/child-form/ChildForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
Collapse,
CollapseProps,
Factory,
Paper,
polymorphicFactory,
Stack,
StylesApiProps,
Text,
Title,
useProps,
useStyles,
} from '@mantine/core';
import classes from './ChildForm.module.css';

export type ChildFormStylesNames = 'root' | 'paper';

export interface ChildFormProps extends CollapseProps, StylesApiProps<ChildFormFactory> {
title?: string;
description?: string;
}

type ChildFormFactory = Factory<{
props: ChildFormProps;
defaultRef: HTMLDivElement;
defaultComponent: 'div';
stylesNames: ChildFormStylesNames;
}>;

const defaultProps: Partial<ChildFormProps> = {};

export const ChildForm = polymorphicFactory<ChildFormFactory>((props, ref) => {
const {className, children, style, classNames, styles, unstyled, vars, title, description, ...others} = useProps(
'ChildForm',
defaultProps,
props,
);

const getStyles = useStyles<ChildFormFactory>({
name: 'ChildForm',
classes,
props,
className,
style,
classNames,
styles,
unstyled,
vars,
});

return (
<Collapse ref={ref} {...others} {...getStyles('root')}>
<Paper bg="gray.1" p="md" {...getStyles('paper')}>
{(title || description) && (
<Stack gap={0} mb="md">
{title && <Title order={5}>{title}</Title>}
{description && <Text c="gray.7">{description}</Text>}
</Stack>
)}
<Stack gap="md">{children}</Stack>
</Paper>
</Collapse>
);
});
1 change: 1 addition & 0 deletions packages/mantine/src/components/child-form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ChildForm';
1 change: 1 addition & 0 deletions packages/mantine/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './prompt';
export * from './read-only';
export * from './sticky-footer';
export * from './table';
export * from './child-form';
1 change: 1 addition & 0 deletions packages/website/src/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const Navigation = () => (
<InternalNavLink to="/form/Collection" label="Collection" />
<InternalNavLink to="/form/CopyToClipboard" label="Copy to Clipboard" />
<InternalNavLink to="/form/Form" label="Form" />
<InternalNavLink to="/form/ChildForm" label="Child Form" />
<InternalNavLink to="/form/InlineConfirm" label="Inline confirm" />
</NavLink>
<NavLink label="Feedback" leftSection={<AnnouncementSize16Px height={16} />} defaultOpened>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {ChildForm, TextInput} from '@coveord/plasma-mantine';
const Demo = () => (
<ChildForm in={true}>
<TextInput label="First name" required />
<TextInput label="Last name" required />
</ChildForm>
);
export default Demo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {ChildForm, Stack, Switch, TextInput, useForm} from '@coveord/plasma-mantine';
const Demo = () => {
const form = useForm({
initialValues: {
provideInfo: false,
firstName: '',
lastName: '',
},
});

return (
<Stack gap="md">
<Switch {...form.getInputProps('provideInfo')} label="Provide information" />
<ChildForm in={!!form.values.provideInfo}>
<TextInput label="First name" required {...form.getInputProps('firstName')} />
<TextInput label="Last name" required {...form.getInputProps('lastName')} />
</ChildForm>
</Stack>
);
};
export default Demo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {ChildForm, TextInput} from '@coveord/plasma-mantine';
const Demo = () => (
<ChildForm in={true} title="Personal information" description="Provide the user's personal information">
<TextInput label="First name" required />
<TextInput label="Last name" required />
</ChildForm>
);
export default Demo;
21 changes: 21 additions & 0 deletions packages/website/src/pages/form/ChildForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ChildFormDemo from '@examples/form/child-form/ChildForm.demo?demo';
import ChildFormWithForm from '@examples/form/child-form/ChildFormWithForm.demo?demo';
import ChildFormWithTitleAndDescription from '@examples/form/child-form/ChildFormWithTitleAndDescription.demo?demo';

import {PageLayout} from '../../building-blocs/PageLayout';

const Page = () => (
<PageLayout
section="Form"
title="Child Form"
description="A container part of a form that can be used to group fields that are conditionally displayed together."
id="ChildFrom"
demo={<ChildFormDemo />}
examples={{
withToggle: <ChildFormWithForm title="Display bound to another form field" />,
withTitleAndDescription: <ChildFormWithTitleAndDescription title="Title and description" />,
}}
/>
);

export default Page;