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

add support for antd 5 Beta/3.0 #205

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
60cc117
fix (InitialValues): adjust id, name and htmlFor on several components
jannikbuschke Dec 7, 2021
3f13acc
set version 2.0.3
jannikbuschke Dec 7, 2021
4ca1d04
update package-lock.json
jannikbuschke Dec 7, 2021
f049ed9
remove react 17 upper version limit
jannikbuschke Dec 7, 2021
e86c7a0
set version 2.0.4
jannikbuschke Feb 20, 2022
9128839
update package-lock
jannikbuschke Feb 20, 2022
715fb92
update docs
jannikbuschke May 23, 2020
b9fd8ef
add 'form-item' wrappers for all major core components
jannikbuschke May 23, 2020
9714f38
fix prop
jannikbuschke Dec 13, 2020
c40bc17
fix missing ts dependencies
jannikbuschke Apr 4, 2021
a86eb5b
fix imports
jannikbuschke Jul 28, 2021
b5f9c3b
update devDependencies, remove react peerDependency upper limit, set …
jannikbuschke Nov 28, 2021
3f73ac5
fix (FormItem): reenable name prop
jannikbuschke Nov 28, 2021
6505730
fix (InitialValues): adjust id, name and htmlFor on several components
jannikbuschke Dec 7, 2021
e28c996
set version 2.1.0-beta.8
jannikbuschke Feb 20, 2022
16d7a9e
replace antd/lib/... imports with antd/es/
jannikbuschke May 31, 2022
1040036
set version 2.1.0-beta.9
jannikbuschke May 31, 2022
38b7eb4
updatae package-lock
jannikbuschke May 31, 2022
a19618e
ui (FormItem): add __debug prop
jannikbuschke Jun 7, 2022
a1159a2
add storybook, update to antd5, work in progress
jannikbuschke Dec 1, 2022
dbc3c03
set version 3.0.0-beta.0, update ts version
jannikbuschke Dec 3, 2022
aa805da
migrate some types, breaking change: remove keepOffset from date/time…
jannikbuschke Dec 3, 2022
62e879c
remove tsconfig.es.json
jannikbuschke Dec 3, 2022
dc6de1f
add more stories
jannikbuschke Dec 4, 2022
e90f613
update deps, set version 3.0.0-beta.1
jannikbuschke Dec 4, 2022
2ab6ad8
fix remove-row-button story
jannikbuschke Dec 4, 2022
22a5956
format azure-pipelines
jannikbuschke Dec 4, 2022
a35e096
move components
jannikbuschke Dec 4, 2022
e99f030
Revert "remove tsconfig.es.json"
jannikbuschke Dec 4, 2022
ad8f3c8
add vite based sample app, re-enable tsconfig & tsconfig.es build, se…
jannikbuschke Dec 4, 2022
d33b6a2
update sample app
jannikbuschke Dec 4, 2022
b324ea5
fix date/time pickers, set version 3.0.0-beta.4
jannikbuschke Dec 4, 2022
10b188a
fix Form.Item cannot have multiple children
jannikbuschke Dec 18, 2022
8515bb1
set version 3.0.0-beta.5
jannikbuschke Dec 18, 2022
93ba557
update sample
jannikbuschke Dec 18, 2022
b623c72
fix tree select and transer story
jannikbuschke Dec 18, 2022
a8dde46
improve table story and props
jannikbuschke Dec 18, 2022
8dc20f2
set version 3.0.0-beta.6
jannikbuschke Dec 18, 2022
66c2dd2
update sample-app formik-antd version
jannikbuschke Dec 29, 2022
954ec9d
update input story
jannikbuschke Dec 29, 2022
40b4747
fix form item preventing formiks values to be set
jannikbuschke Jan 7, 2023
55baa28
add format script
jannikbuschke Jan 7, 2023
126e2de
set version 3.0.0-beta.7
jannikbuschke Jan 7, 2023
a3f41ee
Update sample version
jannikbuschke Jan 7, 2023
4d1cec1
fix (ArrayButton): fix import
jannikbuschke Mar 31, 2023
df119f5
set version 3.0.0-beta.8
jannikbuschke Mar 31, 2023
416710e
prevent 'value' being passed down by parent. 'value' is now only set …
jannikbuschke Oct 28, 2023
14e8d4d
update dev dependencies
jannikbuschke Oct 28, 2023
028fa5f
minor fix
jannikbuschke Oct 28, 2023
8a8b61d
set version 3.0.0-beta.9
jannikbuschke Oct 28, 2023
928ebf1
reenable suppressImplicitAnyIndexErrors
jannikbuschke Oct 28, 2023
35275d6
remove advanced components
jannikbuschke Oct 28, 2023
d053582
Fix Input.TextArea & Input.Password
Vincz Jul 15, 2024
69b0477
Merge pull request #219 from Vincz/patch-1
jannikbuschke Jul 16, 2024
930d231
Fix Checkbox.Group value
Vincz Aug 5, 2024
d43de77
Fix Radio.Group
Vincz Aug 5, 2024
7245f18
Merge pull request #221 from Vincz/patch-2
jannikbuschke Aug 22, 2024
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
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,38 @@ There is one special case to be aware of when using field-level validation: When
</Form.Item>
```

## Combined Form.Item and input components

If you happen to wrap each input component in a `Form.Item` component, you might end up with quite a bit of nesting and boilerplate (always duplicating the `name` prop as well as potentially aria labels/values with `htmlFor` and `id`). Instead you can import the components from the path `es/form-items`. There all components are wrapped with a `Form.Item`. Additionally `htmlFor` on `Form.Item` and `id` prop on the ant d input component are set based on the `name` prop.
The following two examples are identicall:

```jsx
import { Input } from 'formik-antd/es/form-items'
```

```jsx
<Input
name='firstName'
formItem={{ validate: validator, conol: false, label: 'First name' }}
/>
```

```jsx
import { Form, Input } from 'formik-antd'
```

```jsx
<Form.Item
htmlFor='firstName'
name='firstName'
label='First name'
validate={validator}
colon={false}
>
<Input id='firstName' name='firstName' />
</Form.Item>
```

## Rendering Validation Feedback

Showing validation messages can be accomplished with the `Form.Item` component (or `FormItem` which is the same). It
Expand Down
25 changes: 25 additions & 0 deletions advanced-components/add-row-button/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react'
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { StoryTemplate } from '../shared'
import Component from './'

export default {
title: 'Array/AddRowButton',
component: Component,
} as ComponentMeta<typeof Component>

const Template: ComponentStory<typeof Component> = () => {
return (
<>
<StoryTemplate initialValues={{ value: null }}>
<div style={{ width: 500 }}>
<Component name='value' createNewRow={() => ({})}>
add row
</Component>
</div>
</StoryTemplate>
</>
)
}

export const Default = Template.bind({})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { ButtonProps } from 'antd/lib/button'
import { ButtonProps } from 'antd/es/button'
import { ArrayButton } from '../array-button'

export function AddRowButton<T = any>({
Expand Down
1 change: 1 addition & 0 deletions advanced-components/add-row-button/style/css.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'antd/es/button/style/css.js'
1 change: 1 addition & 0 deletions advanced-components/add-row-button/style/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'antd/es/button/style'
23 changes: 23 additions & 0 deletions advanced-components/array-button/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react'
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { StoryTemplate } from '../shared'
import Component from './'

export default {
title: 'Array/Button',
component: Component,
} as ComponentMeta<typeof Component>

const Template: ComponentStory<typeof Component> = () => {
return (
<>
<StoryTemplate initialValues={{ value: null }}>
<div style={{ width: 500 }}>
<Component name='value' onClick={(array) => {}} />
</div>
</StoryTemplate>
</>
)
}

export const Default = Template.bind({})
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FieldArray, FieldArrayRenderProps } from 'formik'
import * as React from 'react'
import Button, { ButtonProps } from 'antd/lib/button'
import { Button } from 'antd'
import { ButtonProps } from 'antd/es/button'

export function ArrayButton({
name,
Expand Down
1 change: 1 addition & 0 deletions advanced-components/array-button/style/css.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'antd/es/button/style/css.js'
1 change: 1 addition & 0 deletions advanced-components/array-button/style/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'antd/es/button/style'
187 changes: 187 additions & 0 deletions advanced-components/form-items/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import * as React from 'react'
import {
InputProps,
Input as $Input,
TextAreaProps,
PasswordProps,
} from '../input'
import { Checkbox as $Checkbox } from '../checkbox'
import FormItem, { FormItemProps as $FormItemProps } from '../form-item'
import { CheckboxProps } from '../checkbox'
import { Cascader as $Cascader, CascaderProps } from '../cascader'
import { DatePicker as $DatePicker, DatePickerProps } from '../date-picker'
import { InputNumber as $InputNumber, InputNumberProps } from '../input-number'
import { Mentions as $Mentions, MentionProps } from '../mentions'
import { Radio as $Radio, RadioGroupProps } from '../radio'
import { Rate as $Rate, RateProps } from '../rate'
import { Select as $Select, SelectProps } from '../select'
import { Slider as $Slider, SliderProps } from '../slider'
import { Switch as $Switch, SwitchProps } from '../switch'
import { TimePicker as $TimePicker, TimePickerProps } from '../time-picker'
import { Transfer as $Transfer, TransferProps } from '../transfer'
import { TreeSelect as $TreeSelect, TreeSelectProps } from '../tree-select'
import { TransferItem } from 'antd/es/transfer'
import { BaseOptionType, DefaultOptionType } from 'antd/es/cascader'

type FormItemProps = {
formItem?: Omit<$FormItemProps, 'children' | 'name' | 'id' | 'htmlFor'>
}

export function Input({ formItem, ...rest }: InputProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Input id={rest.name} {...rest} />
</FormItem>
)
}

export function InputNumber({
formItem,
...rest
}: InputNumberProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$InputNumber id={rest.name} {...rest} />
</FormItem>
)
}
export function TextArea({ formItem, ...rest }: TextAreaProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Input.TextArea id={rest.name} {...rest} />
</FormItem>
)
}

Input.TextArea = TextArea

export function Password({ formItem, ...rest }: PasswordProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Input.Password id={rest.name} {...rest} />
</FormItem>
)
}

Input.Password = Password

export function Checkbox({ formItem, ...rest }: CheckboxProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Checkbox id={rest.name} {...rest} />
</FormItem>
)
}

export function Cascader<
OptionType extends DefaultOptionType | BaseOptionType = DefaultOptionType,
>({ formItem, ...rest }: CascaderProps<OptionType> & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Cascader<OptionType> {...rest} />
</FormItem>
)
}

export function DatePicker({
formItem,
...rest
}: DatePickerProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$DatePicker id={rest.name} {...rest} />
</FormItem>
)
}

export function Mentions({ formItem, ...rest }: MentionProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Mentions id={rest.name} {...rest} />
</FormItem>
)
}

export function Radio({ formItem, ...rest }: RadioGroupProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Radio id={rest.name} {...rest} />
</FormItem>
)
}

export function RadioGroup({
formItem,
...rest
}: RadioGroupProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Radio.Group id={rest.name} {...rest} />
</FormItem>
)
}

export function Rate({ formItem, ...rest }: RateProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Rate {...rest} />
</FormItem>
)
}

export function Select({ formItem, ...rest }: SelectProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Select id={rest.name} {...rest} />
</FormItem>
)
}

export function Slider({ formItem, ...rest }: SliderProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Slider id={rest.name} {...rest} />
</FormItem>
)
}

export function Switch({ formItem, ...rest }: SwitchProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Switch {...rest} />
</FormItem>
)
}

export function TimePicker({
formItem,
...rest
}: TimePickerProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$TimePicker id={rest.name} {...rest} />
</FormItem>
)
}

export function Transfer<RecordType extends TransferItem = TransferItem>({
formItem,
...rest
}: TransferProps<RecordType> & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$Transfer {...rest} />
</FormItem>
)
}

export function TreeSelect({
formItem,
...rest
}: TreeSelectProps & FormItemProps) {
return (
<FormItem {...formItem} name={rest.name} htmlFor={rest.name} id={rest.name}>
<$TreeSelect {...rest} />
</FormItem>
)
}
31 changes: 31 additions & 0 deletions advanced-components/remove-row-button/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react'
import { ComponentMeta } from '@storybook/react'
import { StoryTemplate } from '../shared'
import Component from './'
import { Table } from '../table'

export default {
title: 'Array/RemoveRowButton',
component: Component,
} as ComponentMeta<typeof Component>

export const Default = () => (
<StoryTemplate
initialValues={{ value: [{ label: 'item1' }, { label: 'item2' }] }}
>
<div>
<Table<{ label: string }>
name='value'
columns={[
{
title: 'Label',
render: (value, record) => <div>{record.label}</div>,
},
]}
/>
<Component name='value' index={0}>
Remove item at position 0
</Component>
</div>
</StoryTemplate>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { ButtonProps } from 'antd/lib/button'
import { ButtonProps } from 'antd/es/button'
import { ArrayButton } from '../array-button'

export function RemoveRowButton({
Expand Down
1 change: 1 addition & 0 deletions advanced-components/remove-row-button/style/css.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'antd/es/button/style/css.js'
1 change: 1 addition & 0 deletions advanced-components/remove-row-button/style/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'antd/es/button/style'
Loading
Loading