2017-10-09 16:35:52 +03:00
|
|
|
import React from 'react';
|
2017-10-09 21:01:34 +03:00
|
|
|
import styled from 'styled-components';
|
2017-10-11 17:56:24 +03:00
|
|
|
import is, { isNot } from 'styled-is';
|
2017-10-09 16:35:52 +03:00
|
|
|
import remcalc from 'remcalc';
|
2017-10-23 17:09:49 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-09 21:01:34 +03:00
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
import BaseInput, { Stylable } from './base/input';
|
|
|
|
|
2017-10-11 17:56:24 +03:00
|
|
|
const chevron =
|
|
|
|
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOSIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgOSA2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjx0aXRsZT5hcnJvdzogcmlnaHQ8L3RpdGxlPjxwYXRoIGQ9Ik05IDEuMzg2TDcuNjQ4IDAgNC41IDMuMjI4IDEuMzUyIDAgMCAxLjM4NiA0LjUgNnoiIGZpbGw9IiM0OTQ5NDkiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==';
|
|
|
|
|
|
|
|
const chevronDisabled =
|
|
|
|
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOSIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgOSA2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjx0aXRsZT5hcnJvdzogcmlnaHQ8L3RpdGxlPjxwYXRoIGQ9Ik05IDEuMzg2TDcuNjQ4IDAgNC41IDMuMjI4IDEuMzUyIDAgMCAxLjM4NiA0LjUgNnoiIGZpbGw9IiNEOEQ4RDgiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==';
|
|
|
|
|
2017-10-09 16:35:52 +03:00
|
|
|
const SelectWrapper = styled.div`
|
|
|
|
position: relative;
|
|
|
|
display: inline-flex;
|
2017-10-19 16:36:18 +03:00
|
|
|
|
2017-11-23 14:18:38 +02:00
|
|
|
width: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
|
2017-10-09 16:35:52 +03:00
|
|
|
${isNot('fluid')`
|
2017-11-23 14:18:38 +02:00
|
|
|
min-width: ${remcalc(300)};
|
2017-10-09 16:35:52 +03:00
|
|
|
`};
|
2017-10-13 23:00:19 +03:00
|
|
|
|
2017-10-09 16:35:52 +03:00
|
|
|
&:after {
|
|
|
|
content: '';
|
|
|
|
width: ${remcalc(10)};
|
|
|
|
height: ${remcalc(10)};
|
2017-10-11 17:56:24 +03:00
|
|
|
background: url(${chevron}) center center no-repeat;
|
2017-10-09 16:35:52 +03:00
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
transform: translateY(-50%);
|
|
|
|
right: ${remcalc(12)};
|
2018-02-23 17:59:12 +02:00
|
|
|
pointer-events: none;
|
2017-10-09 16:35:52 +03:00
|
|
|
}
|
2017-10-13 23:00:19 +03:00
|
|
|
|
2017-11-22 14:13:33 +02:00
|
|
|
${is('embedded')`
|
2018-02-22 01:02:09 +02:00
|
|
|
width: auto;
|
|
|
|
max-width: auto;
|
|
|
|
min-width: 0;
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
right: ${remcalc(6)};
|
|
|
|
}
|
2017-11-22 14:13:33 +02:00
|
|
|
`};
|
|
|
|
|
2017-10-11 17:56:24 +03:00
|
|
|
${is('disabled')`
|
|
|
|
&:after {
|
|
|
|
background: url(${chevronDisabled}) center center no-repeat;
|
|
|
|
}
|
|
|
|
`};
|
|
|
|
`;
|
|
|
|
|
2018-03-28 15:51:34 +03:00
|
|
|
const select = BaseInput(Stylable('select'));
|
|
|
|
const StyledSelect = styled(select)`
|
2017-10-23 17:09:49 +03:00
|
|
|
position: relative;
|
2017-11-16 12:47:32 +02:00
|
|
|
padding: ${remcalc(12)};
|
|
|
|
padding-right: ${remcalc(25)};
|
2017-11-23 14:18:38 +02:00
|
|
|
|
2018-01-31 17:08:17 +02:00
|
|
|
&::-ms-expand {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:56:24 +03:00
|
|
|
${is('disabled')`
|
|
|
|
border-color: ${props => props.theme.grey};
|
|
|
|
color: ${props => props.theme.grey};
|
|
|
|
`};
|
2017-11-16 12:47:32 +02:00
|
|
|
|
2017-11-22 14:13:33 +02:00
|
|
|
${is('embedded')`
|
2018-01-12 17:25:26 +02:00
|
|
|
width: auto;
|
2017-11-22 14:13:33 +02:00
|
|
|
border: none;
|
|
|
|
border-bottom: ${remcalc(1)} solid ${props => props.theme.text};
|
|
|
|
border-radius: 0;
|
|
|
|
background: transparent;
|
|
|
|
padding: 0;
|
2018-02-01 12:38:12 +02:00
|
|
|
padding-right: ${remcalc(16)};
|
2017-11-22 14:13:33 +02:00
|
|
|
display: inline;
|
|
|
|
height: ${remcalc(24)};
|
|
|
|
appearance: none;
|
|
|
|
min-height: 0;
|
2018-01-16 13:23:00 +02:00
|
|
|
color: ${props => props.theme.text};
|
2018-03-20 12:47:32 +02:00
|
|
|
`};
|
2018-01-16 13:23:00 +02:00
|
|
|
|
2017-11-16 12:47:32 +02:00
|
|
|
${is('wrapped')`
|
|
|
|
border: none;
|
|
|
|
width: ${remcalc(65)};
|
|
|
|
border-left: ${remcalc(1)} solid ${props => props.theme.grey};
|
|
|
|
border-radius: 0 ${remcalc(4)} ${remcalc(4)} 0;
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
border-left: ${remcalc(1)} solid ${props => props.theme.grey};
|
|
|
|
}
|
|
|
|
`};
|
2017-10-09 16:35:52 +03:00
|
|
|
`;
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
/**
|
|
|
|
* @example ./usage-select.md
|
|
|
|
*/
|
2017-10-23 17:09:49 +03:00
|
|
|
const Select = ({ children, fluid, ...rest }) => (
|
2017-11-22 14:13:33 +02:00
|
|
|
<SelectWrapper fluid={fluid} {...rest}>
|
2017-10-13 23:00:19 +03:00
|
|
|
<StyledSelect {...rest} fluid={fluid}>
|
|
|
|
{children}
|
|
|
|
</StyledSelect>
|
2017-10-09 16:35:52 +03:00
|
|
|
</SelectWrapper>
|
|
|
|
);
|
2017-10-23 17:09:49 +03:00
|
|
|
|
|
|
|
export default Select;
|
|
|
|
|
|
|
|
Select.propTypes = {
|
|
|
|
/**
|
|
|
|
* Is the Select disabled ?
|
|
|
|
*/
|
|
|
|
disabled: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
|
|
|
Select.defaultProps = {
|
|
|
|
disabled: false
|
|
|
|
};
|