2019-06-24 13:18:47 +00:00
|
|
|
import React from 'react'
|
|
|
|
import styled, { css } from 'styled-components'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-08-08 10:47:12 +00:00
|
|
|
import { Icons } from '../icons'
|
2019-12-18 11:05:13 +00:00
|
|
|
import { tablet } from '../../utils/device'
|
2019-06-24 13:18:47 +00:00
|
|
|
|
2019-07-11 13:27:45 +00:00
|
|
|
const itemTruncate = css`
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const fontStyle = css`
|
2019-09-06 13:50:37 +00:00
|
|
|
font-family: 'Open Sans', sans-serif, Arial;
|
2019-07-11 13:27:45 +00:00
|
|
|
font-style: normal;
|
|
|
|
`;
|
|
|
|
|
2019-09-06 13:50:37 +00:00
|
|
|
const disabledAndHeaderStyle = css`
|
|
|
|
color: #A3A9AE;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
cursor: default;
|
|
|
|
background-color: white;
|
|
|
|
}
|
|
|
|
`;
|
2019-07-11 13:27:45 +00:00
|
|
|
|
2019-09-06 13:50:37 +00:00
|
|
|
const StyledDropdownItem = styled.div`
|
2020-08-24 08:20:40 +00:00
|
|
|
display: flex;
|
2019-09-06 13:50:37 +00:00
|
|
|
width: 100%;
|
2020-02-06 14:08:39 +00:00
|
|
|
max-width: 500px;
|
2019-09-06 13:50:37 +00:00
|
|
|
border: 0px;
|
|
|
|
cursor: pointer;
|
|
|
|
margin: 0px;
|
2019-12-27 07:28:02 +00:00
|
|
|
padding: 0px 16px;
|
|
|
|
line-height: 32px;
|
2019-07-11 13:27:45 +00:00
|
|
|
box-sizing: border-box;
|
|
|
|
text-align: left;
|
|
|
|
background: none;
|
|
|
|
text-decoration: none;
|
2019-06-24 13:18:47 +00:00
|
|
|
user-select: none;
|
2019-12-11 05:58:41 +00:00
|
|
|
outline: 0 !important;
|
2020-02-03 13:08:18 +00:00
|
|
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
2019-06-24 13:18:47 +00:00
|
|
|
|
2019-07-11 13:27:45 +00:00
|
|
|
${fontStyle}
|
2019-06-24 13:18:47 +00:00
|
|
|
|
2019-07-11 13:27:45 +00:00
|
|
|
font-weight: 600;
|
2019-11-07 12:47:04 +00:00
|
|
|
font-size: 13px;
|
|
|
|
color: #333333;
|
2019-09-06 13:50:37 +00:00
|
|
|
text-transform: none;
|
2019-07-11 13:27:45 +00:00
|
|
|
|
|
|
|
${itemTruncate}
|
2019-09-06 13:50:37 +00:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: ${props => props.noHover ? 'white' : '#F8F9F9'};
|
|
|
|
text-align: left;
|
2019-06-24 13:18:47 +00:00
|
|
|
}
|
2019-09-06 13:50:37 +00:00
|
|
|
|
|
|
|
${props => props.isSeparator &&
|
|
|
|
`
|
2019-12-27 07:28:02 +00:00
|
|
|
padding: 0px 16px;
|
2020-08-17 13:43:47 +00:00
|
|
|
border: 1px solid #ECEEF1;
|
2019-09-06 13:50:37 +00:00
|
|
|
cursor: default;
|
2019-12-27 08:48:50 +00:00
|
|
|
margin: 6px 16px 6px;
|
2019-09-06 13:50:37 +00:00
|
|
|
line-height: 1px;
|
|
|
|
height: 1px;
|
|
|
|
width: calc(100% - 32px);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
cursor: default;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
${props => props.isHeader &&
|
|
|
|
`
|
|
|
|
${disabledAndHeaderStyle}
|
|
|
|
|
|
|
|
text-transform: uppercase;
|
2020-03-26 14:10:14 +00:00
|
|
|
break-before: column;
|
2019-09-06 13:50:37 +00:00
|
|
|
`
|
|
|
|
}
|
2019-12-18 11:05:13 +00:00
|
|
|
|
|
|
|
@media ${ tablet } {
|
2019-12-27 07:28:02 +00:00
|
|
|
line-height: 36px;
|
2019-12-18 11:05:13 +00:00
|
|
|
}
|
2019-09-06 13:50:37 +00:00
|
|
|
|
|
|
|
${props => props.disabled && disabledAndHeaderStyle }
|
2019-06-24 13:18:47 +00:00
|
|
|
`;
|
|
|
|
|
2020-08-24 08:20:40 +00:00
|
|
|
const IconWrapper = styled.div`
|
2020-09-11 09:55:30 +00:00
|
|
|
display:flex;
|
2019-08-08 10:47:12 +00:00
|
|
|
width: 16px;
|
2019-07-26 14:23:40 +00:00
|
|
|
margin-right: 8px;
|
2019-08-08 10:47:12 +00:00
|
|
|
line-height: 14px;
|
2019-07-26 14:23:40 +00:00
|
|
|
`;
|
|
|
|
|
2019-08-08 10:47:12 +00:00
|
|
|
const DropDownItem = props => {
|
2019-07-31 11:45:01 +00:00
|
|
|
//console.log("DropDownItem render");
|
2019-09-06 13:50:37 +00:00
|
|
|
const { isSeparator, label, icon, children, disabled , onClick } = props;
|
|
|
|
const color = disabled ? '#A3A9AE' : '#333333';
|
|
|
|
|
2020-06-25 15:11:34 +00:00
|
|
|
const onClickAction = (e) => {
|
|
|
|
onClick && !disabled && onClick(e);
|
2019-09-06 13:50:37 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 11:45:01 +00:00
|
|
|
return (
|
2019-09-06 13:50:37 +00:00
|
|
|
<StyledDropdownItem {...props} onClick={onClickAction}>
|
2019-07-31 11:45:01 +00:00
|
|
|
{icon &&
|
|
|
|
<IconWrapper>
|
2019-09-06 13:50:37 +00:00
|
|
|
{React.createElement(Icons[icon], { size: "scale", color: color, isfill: true })}
|
2019-07-31 11:45:01 +00:00
|
|
|
</IconWrapper>
|
|
|
|
}
|
2020-08-24 08:20:40 +00:00
|
|
|
{isSeparator ? '\u00A0' : label ? label : children && children}
|
2019-07-31 11:45:01 +00:00
|
|
|
</StyledDropdownItem>
|
|
|
|
);
|
2019-08-08 10:47:12 +00:00
|
|
|
};
|
2019-06-24 13:18:47 +00:00
|
|
|
|
|
|
|
DropDownItem.propTypes = {
|
2019-07-31 11:45:01 +00:00
|
|
|
isSeparator: PropTypes.bool,
|
|
|
|
isHeader: PropTypes.bool,
|
|
|
|
tabIndex: PropTypes.number,
|
|
|
|
label: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
2019-09-06 13:50:37 +00:00
|
|
|
icon: PropTypes.string,
|
2019-09-09 13:56:54 +00:00
|
|
|
noHover: PropTypes.bool,
|
|
|
|
onClick: PropTypes.func,
|
2019-11-27 13:39:21 +00:00
|
|
|
children: PropTypes.any,
|
|
|
|
className: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
|
2019-06-24 13:18:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DropDownItem.defaultProps = {
|
2019-07-31 11:45:01 +00:00
|
|
|
isSeparator: false,
|
|
|
|
isHeader: false,
|
|
|
|
tabIndex: -1,
|
|
|
|
label: '',
|
2019-09-06 13:50:37 +00:00
|
|
|
disabled: false,
|
2019-11-07 12:47:04 +00:00
|
|
|
noHover: false
|
2019-06-24 13:18:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DropDownItem
|