-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add enhanceGetInputProps demos
- Loading branch information
Showing
8 changed files
with
284 additions
and
12 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/@docs/demos/src/demos/form/Form.demo.enhanceGetInputProps.tsx
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,59 @@ | ||
import React from 'react'; | ||
import { NumberInput, TextInput } from '@mantine/core'; | ||
import { useForm } from '@mantine/form'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
|
||
const code = ` | ||
import { NumberInput, TextInput } from '@mantine/core'; | ||
import { useForm } from '@mantine/form'; | ||
interface FormValues { | ||
name: string; | ||
age: number | string; | ||
} | ||
function Demo() { | ||
const form = useForm<FormValues>({ | ||
initialValues: { name: '', age: '' }, | ||
enhanceGetInputProps: (payload) => ({ | ||
disabled: payload.field === 'name', | ||
}), | ||
}); | ||
return ( | ||
<> | ||
<TextInput {...form.getInputProps('name')} label="Name" placeholder="Name" /> | ||
<NumberInput {...form.getInputProps('age')} label="Age" placeholder="Age" mt="md" /> | ||
</> | ||
); | ||
} | ||
`; | ||
|
||
interface FormValues { | ||
name: string; | ||
age: number | string; | ||
} | ||
|
||
function Demo() { | ||
const form = useForm<FormValues>({ | ||
initialValues: { name: '', age: '' }, | ||
enhanceGetInputProps: (payload) => ({ | ||
disabled: payload.field === 'name', | ||
}), | ||
}); | ||
|
||
return ( | ||
<> | ||
<TextInput {...form.getInputProps('name')} label="Name" placeholder="Name" /> | ||
<NumberInput {...form.getInputProps('age')} label="Age" placeholder="Age" mt="md" /> | ||
</> | ||
); | ||
} | ||
|
||
export const enhanceGetInputProps: MantineDemo = { | ||
type: 'code', | ||
component: Demo, | ||
code, | ||
centered: true, | ||
maxWidth: 340, | ||
}; |
73 changes: 73 additions & 0 deletions
73
packages/@docs/demos/src/demos/form/Form.demo.enhanceGetInputPropsForm.tsx
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,73 @@ | ||
import React from 'react'; | ||
import { Button, NumberInput, TextInput } from '@mantine/core'; | ||
import { useForm } from '@mantine/form'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
|
||
const code = ` | ||
import { NumberInput, TextInput } from '@mantine/core'; | ||
import { useForm } from '@mantine/form'; | ||
interface FormValues { | ||
name: string; | ||
age: number | string; | ||
} | ||
function Demo() { | ||
const form = useForm<FormValues>({ | ||
initialValues: { name: '', age: '' }, | ||
enhanceGetInputProps: (payload) => { | ||
if (!payload.form.initialized) { | ||
return { disabled: true }; | ||
} | ||
return {}; | ||
}, | ||
}); | ||
return ( | ||
<> | ||
<TextInput {...form.getInputProps('name')} label="Your name" placeholder="Your name" /> | ||
<NumberInput {...form.getInputProps('age')} label="Age" placeholder="Age" mt="md" /> | ||
<Button onClick={() => form.initialize({ name: 'John', age: 20 })} mt="md"> | ||
Initialize form | ||
</Button> | ||
</> | ||
); | ||
} | ||
`; | ||
|
||
interface FormValues { | ||
name: string; | ||
age: number | string; | ||
} | ||
|
||
function Demo() { | ||
const form = useForm<FormValues>({ | ||
initialValues: { name: '', age: '' }, | ||
enhanceGetInputProps: (payload) => { | ||
if (!payload.form.initialized) { | ||
return { disabled: true }; | ||
} | ||
|
||
return {}; | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<TextInput {...form.getInputProps('name')} label="Your name" placeholder="Your name" /> | ||
<NumberInput {...form.getInputProps('age')} label="Age" placeholder="Age" mt="md" /> | ||
<Button onClick={() => form.initialize({ name: 'John', age: 20 })} mt="md"> | ||
Initialize form | ||
</Button> | ||
</> | ||
); | ||
} | ||
|
||
export const enhanceGetInputPropsForm: MantineDemo = { | ||
type: 'code', | ||
component: Demo, | ||
code, | ||
centered: true, | ||
maxWidth: 340, | ||
}; |
77 changes: 77 additions & 0 deletions
77
packages/@docs/demos/src/demos/form/Form.demo.enhanceGetInputPropsOptions.tsx
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,77 @@ | ||
import React from 'react'; | ||
import { NumberInput, TextInput } from '@mantine/core'; | ||
import { useForm } from '@mantine/form'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
|
||
const code = ` | ||
import { NumberInput, TextInput } from '@mantine/core'; | ||
import { useForm } from '@mantine/form'; | ||
interface FormValues { | ||
name: string; | ||
age: number | string; | ||
} | ||
function Demo() { | ||
const form = useForm<FormValues>({ | ||
initialValues: { name: '', age: '' }, | ||
enhanceGetInputProps: (payload) => { | ||
if (payload.options.fieldType === 'name') { | ||
return { | ||
label: 'Your name', | ||
placeholder: 'Your name', | ||
withAsterisk: true, | ||
description: 'Your personal information is stored securely. (Just kidding!)', | ||
}; | ||
} | ||
return {}; | ||
}, | ||
}); | ||
return ( | ||
<> | ||
<TextInput {...form.getInputProps('name', { fieldType: 'name' })} /> | ||
<NumberInput {...form.getInputProps('age')} label="Age" placeholder="Age" mt="md" /> | ||
</> | ||
); | ||
} | ||
`; | ||
|
||
interface FormValues { | ||
name: string; | ||
age: number | string; | ||
} | ||
|
||
function Demo() { | ||
const form = useForm<FormValues>({ | ||
initialValues: { name: '', age: '' }, | ||
enhanceGetInputProps: (payload) => { | ||
if (payload.options.fieldType === 'name') { | ||
return { | ||
label: 'Your name', | ||
placeholder: 'Your name', | ||
withAsterisk: true, | ||
description: 'Your personal information is stored securely. (Just kidding!)', | ||
}; | ||
} | ||
|
||
return {}; | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<TextInput {...form.getInputProps('name', { fieldType: 'name' })} /> | ||
<NumberInput {...form.getInputProps('age')} label="Age" placeholder="Age" mt="md" /> | ||
</> | ||
); | ||
} | ||
|
||
export const enhanceGetInputPropsOptions: MantineDemo = { | ||
type: 'code', | ||
component: Demo, | ||
code, | ||
centered: true, | ||
maxWidth: 340, | ||
}; |
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