-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathContent.js
More file actions
62 lines (58 loc) · 1.9 KB
/
Copy pathContent.js
File metadata and controls
62 lines (58 loc) · 1.9 KB
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
import React from 'react';
import styled from '@emotion/styled';
import PropTypes from 'prop-types';
import Option from './Option';
import Input from './Input';
import { LIB_NAME } from '../constants';
import {getByPath} from '../util';
import SelectPropsModel from '../models/SelectPropsModel';
import SelectMethodsModel from '../models/SelectMethodsModel';
import SelectStateModel from '../models/SelectStateModel';
const Content = ({ props, state, methods }) => {
return (
<ContentComponent
className={`${LIB_NAME}-content ${
props.multi ? `${LIB_NAME}-type-multi` : `${LIB_NAME}-type-single`
}`}
onClick={(event) => {
event.stopPropagation();
if (state.dropdown === true && props.closeOnClickInput && !state.search) {
return methods.dropDown('close');
} else {
return methods.dropDown('open');
}
}}>
{props.contentRenderer ? (
props.contentRenderer({ props, state, methods })
) : (
<React.Fragment>
{props.multi
? state.values &&
state.values.map((item) => (
<Option
key={`${getByPath(item, props.valueField)}${getByPath(item, props.labelField)}`}
item={item}
state={state}
props={props}
methods={methods}
/>
))
: state.values &&
state.values.length > 0 && <span>{getByPath(state.values[0], props.labelField)}</span>}
<Input props={props} methods={methods} state={state} />
</React.Fragment>
)}
</ContentComponent>
);
};
Content.propTypes = {
props: PropTypes.shape(SelectPropsModel),
state: PropTypes.shape(SelectStateModel),
methods: PropTypes.shape(SelectMethodsModel),
};
const ContentComponent = styled.div`
display: flex;
flex: 1;
flex-wrap: wrap;
`;
export default Content;