Skip to content

Commit

Permalink
Refine getInitialMeta.
Browse files Browse the repository at this point in the history
  • Loading branch information
glin7976 committed May 22, 2024
1 parent d1f0dea commit 08a4354
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 114 deletions.
107 changes: 54 additions & 53 deletions packages/examples-antd/src/examples/Wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,65 @@ interface WizardMeta {
steps: Step[];
}

const wizardMeta: WizardMeta = {
steps: [
{
title: 'Personal Information',
formMeta: {
columns: 2,
fields: [
{ key: 'name.first', label: 'First Name', initialValue: 'Nate', required: true },
{ key: 'name.last', label: 'Last Name', initialValue: 'Wang', required: true },
{ key: 'dob', label: 'Date of Birth', widget: 'date-picker', viewWidget: 'date-view' },
{
key: 'noAccountInfo',
label: 'No Account Info',
widget: 'switch',
// dynamic: true,
tooltip: 'Switch on to remove account step',
},
],
const getInitialMeta = () => {
const wizardMeta: WizardMeta = {
steps: [
{
title: 'Personal Information',
formMeta: {
columns: 2,
fields: [
{ key: 'name.first', label: 'First Name', initialValue: 'Nate', required: true },
{ key: 'name.last', label: 'Last Name', initialValue: 'Wang', required: true },
{ key: 'dob', label: 'Date of Birth', widget: 'date-picker', viewWidget: 'date-view' },
{
key: 'noAccountInfo',
label: 'No Account Info',
widget: 'switch',
// dynamic: true,
tooltip: 'Switch on to remove account step',
},
],
},
},
},
{
title: 'Account Information',
formMeta: {
columns: 2,
fields: [
{
key: 'email',
label: 'Email',
clear: 'right',
rules: [{ type: 'email', message: 'Invalid email' }],
},
{
key: 'security',
label: 'Security Question',
widget: 'select',
placeholder: 'Select a question...',
options: ["What's your pet's name?", 'Your nick name?'],
},
{ key: 'answer', label: 'Security Answer' },
],
{
title: 'Account Information',
formMeta: {
columns: 2,
fields: [
{
key: 'email',
label: 'Email',
clear: 'right',
rules: [{ type: 'email', message: 'Invalid email' }],
},
{
key: 'security',
label: 'Security Question',
widget: 'select',
placeholder: 'Select a question...',
options: ["What's your pet's name?", 'Your nick name?'],
},
{ key: 'answer', label: 'Security Answer' },
],
},
},
},
{
title: 'Contact Information',
formMeta: {
columns: 2,
fields: [
{ key: 'address', label: 'Address', colSpan: 2 },
{ key: 'city', label: 'City' },
{ key: 'phone', label: 'phone' },
],
{
title: 'Contact Information',
formMeta: {
columns: 2,
fields: [
{ key: 'address', label: 'Address', colSpan: 2 },
{ key: 'city', label: 'City' },
{ key: 'phone', label: 'phone' },
],
},
},
},
],
],
};
return wizardMeta;
};

const getInitialMeta = () => ({...wizardMeta, steps: wizardMeta.steps.map((s: Step) => s)});

export default () => {
const [form] = Form.useForm();
const updateOnChange = NiceForm.useUpdateOnChange('*');
Expand Down
121 changes: 61 additions & 60 deletions packages/examples-formik/src/examples/Wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@ebay/nice-form-react/adapters/formikMuiAdapter';
const DateView = ({ value }: { value: Dayjs }) => (value ? value.format('MMM Do YYYY') : 'N/A');

NiceForm.defineWidget('date-view', DateView, ({ field }) => field);
NiceForm.defineWidget('date-view', DateView);

interface StepItem {
title: string;
Expand All @@ -37,70 +37,71 @@ interface FormValues {
phone: string;
}

const wizardMeta = {
steps: [
{
title: 'Personal Information',
formMeta: {
columns: 2,
rowGap: 18,
columnGap: 18,
fields: [
{ key: 'name.first', label: 'First Name', initialValue: 'Nate', required: true },
{ key: 'name.last', label: 'Last Name', initialValue: 'Wang', required: true },
{ key: 'dob', label: 'Date of Birth', widget: 'date-picker', viewWidget: 'date-view' },
{
key: 'noAccountInfo',
label: 'No Account Info',
widget: 'switch',
tooltip: 'Switch on to remove account step',
},
],
const getInitialMeta = () => {
const wizardMeta = {
steps: [
{
title: 'Personal Information',
formMeta: {
columns: 2,
rowGap: 18,
columnGap: 18,
fields: [
{ key: 'name.first', label: 'First Name', initialValue: 'Nate', required: true },
{ key: 'name.last', label: 'Last Name', initialValue: 'Wang', required: true },
{ key: 'dob', label: 'Date of Birth', widget: 'date-picker', viewWidget: 'date-view' },
{
key: 'noAccountInfo',
label: 'No Account Info',
widget: 'switch',
tooltip: 'Switch on to remove account step',
},
],
},
},
},
{
title: 'Account Information',
formMeta: {
columns: 2,
rowGap: 18,
columnGap: 18,
fields: [
{
key: 'email',
label: 'Email',
clear: 'right',
rules: [{ type: 'email', message: 'Invalid email' }],
},
{
key: 'security',
label: 'Security Question',
widget: 'select',
fullWidth: true,
placeholder: 'Select a question...',
options: ["What's your pet's name?", 'Your nick name?'],
},
{ key: 'answer', label: 'Security Answer' },
],
{
title: 'Account Information',
formMeta: {
columns: 2,
rowGap: 18,
columnGap: 18,
fields: [
{
key: 'email',
label: 'Email',
clear: 'right',
rules: [{ type: 'email', message: 'Invalid email' }],
},
{
key: 'security',
label: 'Security Question',
widget: 'select',
fullWidth: true,
placeholder: 'Select a question...',
options: ["What's your pet's name?", 'Your nick name?'],
},
{ key: 'answer', label: 'Security Answer' },
],
},
},
},
{
title: 'Contact Information',
formMeta: {
columns: 2,
rowGap: 18,
columnGap: 18,
fields: [
{ key: 'address', label: 'Address', colSpan: 2 },
{ key: 'city', label: 'City' },
{ key: 'phone', label: 'phone' },
],
{
title: 'Contact Information',
formMeta: {
columns: 2,
rowGap: 18,
columnGap: 18,
fields: [
{ key: 'address', label: 'Address', colSpan: 2 },
{ key: 'city', label: 'City' },
{ key: 'phone', label: 'phone' },
],
},
},
},
],
] as StepItem[],
};
return wizardMeta;
};

const getInitialMeta = () => ({...wizardMeta, steps: wizardMeta.steps.map(((s: StepItem) => s),)});

const Wizard = () => {
const [currentStep, setCurrentStep] = useState(0);
// Clone the meta for dynamic change
Expand Down
2 changes: 1 addition & 1 deletion packages/nice-form-react/src/NiceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ NiceForm.addAdapter = (adapter: NiceFormAdapter) => {
NiceForm.defineWidget = (
name: string,
widget: ReactComponent,
metaConverter: FieldMetaConverter,
metaConverter?: FieldMetaConverter,
) => {
config.defineWidget(name, widget, metaConverter);
};
Expand Down

0 comments on commit 08a4354

Please sign in to comment.