Skip to content

Commit 9db5d5e

Browse files
committed
fix(ant): add dual list select component
1 parent eb31dd0 commit 9db5d5e

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import componentTypes from '@data-driven-forms/react-form-renderer/dist/cjs/component-types';
2+
3+
const options = [
4+
{
5+
label: 'Cat',
6+
value: 'cat'
7+
},
8+
{
9+
label: 'Dog',
10+
value: 'dog'
11+
},
12+
{
13+
label: 'Duck',
14+
value: 'duck'
15+
},
16+
{
17+
label: 'Lion',
18+
value: 'lion'
19+
},
20+
{
21+
label: 'Monster',
22+
value: 'monster'
23+
}
24+
];
25+
26+
const schema = {
27+
fields: [
28+
{
29+
component: componentTypes.DUAL_LIST_SELECT,
30+
name: 'default-transfer',
31+
options
32+
}
33+
]
34+
};
35+
36+
export default schema;

packages/ant-component-mapper/demo/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import FormRenderer from '@data-driven-forms/react-form-renderer';
55
import 'antd/dist/antd.css';
66
import './style.css';
77
import demoSchema from '@data-driven-forms/common/src/demoschema';
8+
import dualListSelectSchema from './demo-schemas/dual-list-select-schema'
89
import { componentMapper, FormTemplate } from '../src';
910
import wizardSchema from './demo-schemas/wizard-schema';
1011

@@ -20,7 +21,7 @@ const App = () => (
2021
componentMapper={componentMapper}
2122
FormTemplate={(props) => <FormTemplate layout='vertical' {...props} />}
2223
onSubmit={console.log}
23-
schema={wizardSchema}
24+
schema={dualListSelectSchema}
2425
/>
2526
</div>
2627
);
Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
11
import React from 'react';
2+
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
3+
import { Transfer } from 'antd';
4+
import AntForm from '../common/form-wrapper';
25

3-
export default () => <div>not implemented</div>;
6+
const DualListSelect = (props) => {
7+
const {
8+
input: { onChange, value = [], ...input },
9+
meta,
10+
validateOnMount,
11+
helperText,
12+
description,
13+
FormItemProps,
14+
isRequired,
15+
options = [],
16+
label,
17+
...rest
18+
} = useFieldApi(props);
19+
const dataSource = options.map((option) => ({
20+
key: option.value,
21+
...option
22+
}));
23+
return (
24+
<AntForm
25+
label={label}
26+
meta={meta}
27+
validateOnMount={validateOnMount}
28+
helperText={helperText}
29+
description={description}
30+
FormItemProps={FormItemProps}
31+
isRequired={isRequired}
32+
>
33+
<Transfer
34+
{...input}
35+
targetKeys={value}
36+
onChange={(targetKeys) => onChange(targetKeys.filter((key) => options.find(({ value }) => value === key)))} // for some reason, there was always an empty string in the targetKeys argument
37+
render={({ label }) => label}
38+
dataSource={dataSource}
39+
{...rest}
40+
/>
41+
</AntForm>
42+
);
43+
};
44+
45+
export default DualListSelect;

0 commit comments

Comments
 (0)