-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathindex.js
70 lines (61 loc) · 1.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { MultiSelectNested } from '@strapi/design-system';
import upperFirst from 'lodash/upperFirst';
const options = [
{
label: 'All',
children: [
{ label: 'images (JPEG, PNG, GIF, SVG, TIFF, ICO, DVU)', value: 'images' },
{ label: 'videos (MPEG, MP4, Quicktime, WMV, AVI, FLV)', value: 'videos' },
{ label: 'audios (MP3, WAV, OGG)', value: 'audios' },
{ label: 'files (CSV, ZIP, PDF, Excel, JSON, ...)', value: 'files' },
],
},
];
const AllowedTypesSelect = ({ intlLabel, name, onChange, value }) => {
const { formatMessage } = useIntl();
/* eslint-disable indent */
const displayedValue =
value === null || value.length === 0
? formatMessage({ id: 'global.none', defaultMessage: 'None' })
: [...value]
.sort()
.map((v) => upperFirst(v))
.join(', ');
/* eslint-enable indent */
const label = intlLabel.id
? formatMessage({ id: intlLabel.id, defaultMessage: intlLabel.defaultMessage })
: name;
return (
<MultiSelectNested
id="select1"
label={label}
customizeContent={() => displayedValue}
onChange={(values) => {
if (values.length > 0) {
onChange({ target: { name, value: values, type: 'allowed-types-select' } });
} else {
onChange({ target: { name, value: null, type: 'allowed-types-select' } });
}
}}
options={options}
value={value || []}
/>
);
};
AllowedTypesSelect.defaultProps = {
value: null,
};
AllowedTypesSelect.propTypes = {
intlLabel: PropTypes.shape({
id: PropTypes.string.isRequired,
defaultMessage: PropTypes.string.isRequired,
values: PropTypes.object,
}).isRequired,
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
value: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
};
export default AllowedTypesSelect;