Skip to content

Commit 9cb4e72

Browse files
committed
select refactored
1 parent 92aafc6 commit 9cb4e72

File tree

1 file changed

+57
-49
lines changed
  • packages/components/src/components/Select

1 file changed

+57
-49
lines changed

packages/components/src/components/Select/index.tsx

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import deepmerge from 'deepmerge';
3-
import styled from 'styled-components';
43
import css from '@styled-system/css';
54
import { Input } from '../Input';
65
import { Element } from '../Element';
@@ -43,63 +42,72 @@ const getSVG = (variant, color) => {
4342
return header + encoded;
4443
};
4544

46-
const SelectComponent = styled(Input).attrs({ as: 'select' })<{
45+
const SelectComponent: React.FC<{
4746
variant?: string;
48-
}>(({ variant = 'default' }) =>
49-
css(
50-
deepmerge(variantStyles[variant], {
51-
appearance: 'none',
47+
}> = ({ variant = 'default', ...props }) => (
48+
<Input
49+
as="select"
50+
css={css(
51+
deepmerge(variantStyles[variant], {
52+
appearance: 'none',
53+
color: 'input.placeholderForeground',
54+
transition: 'all ease',
55+
transitionDuration: theme => theme.speeds[2],
56+
57+
paddingRight: 5, // select has a caret icon on the right
58+
59+
backgroundImage: theme =>
60+
theme &&
61+
`url(${getSVG(variant, theme.colors.input.placeholderForeground)})`,
62+
backgroundPosition: 'calc(100% - 8px) center',
63+
backgroundRepeat: 'no-repeat',
64+
65+
':hover, :focus': {
66+
color: 'input.foreground',
67+
backgroundImage: theme =>
68+
theme && `url(${getSVG(variant, theme.colors.input.foreground)})`,
69+
},
70+
})
71+
)}
72+
{...props}
73+
/>
74+
);
75+
76+
const SelectWithIcon: React.FC<{ variant?: string }> = ({
77+
variant = 'default',
78+
...props
79+
}) => (
80+
<Element
81+
as="div"
82+
css={css({
83+
position: 'relative',
5284
color: 'input.placeholderForeground',
5385
transition: 'all ease',
5486
transitionDuration: theme => theme.speeds[2],
5587

56-
paddingRight: 5, // select has a caret icon on the right
57-
58-
backgroundImage: theme =>
59-
theme &&
60-
`url(${getSVG(variant, theme.colors.input.placeholderForeground)})`,
61-
backgroundPosition: 'calc(100% - 8px) center',
62-
backgroundRepeat: 'no-repeat',
63-
64-
':hover, :focus': {
65-
color: 'input.foreground',
66-
backgroundImage: theme =>
67-
theme && `url(${getSVG(variant, theme.colors.input.foreground)})`,
88+
select: {
89+
paddingLeft: 7,
90+
},
91+
svg: {
92+
position: 'absolute',
93+
left: 2,
94+
top: '50%',
95+
transform: 'translateY(-50%)',
6896
},
69-
})
70-
)
71-
);
7297

73-
const SelectWithIcon = styled(Element)<{
74-
variant?: string;
75-
}>(({ variant = 'default' }) =>
76-
css({
77-
position: 'relative',
78-
color: 'input.placeholderForeground',
79-
transition: 'all ease',
80-
transitionDuration: theme => theme.speeds[2],
81-
82-
select: {
83-
paddingLeft: 7,
84-
},
85-
svg: {
86-
position: 'absolute',
87-
left: 2,
88-
top: '50%',
89-
transform: 'translateY(-50%)',
90-
},
91-
92-
// hover anywhere on the component should make all elements change
93-
':hover, :focus-within': {
94-
// the svg takes currentcolor
95-
color: 'input.foreground',
96-
select: {
98+
// hover anywhere on the component should make all elements change
99+
':hover, :focus-within': {
100+
// the svg takes currentcolor
97101
color: 'input.foreground',
98-
backgroundImage: theme =>
99-
`url(${getSVG(variant, theme.colors.input.foreground)})`,
102+
select: {
103+
color: 'input.foreground',
104+
backgroundImage: theme =>
105+
`url(${getSVG(variant, theme.colors.input.foreground)})`,
106+
},
100107
},
101-
},
102-
})
108+
})}
109+
{...props}
110+
/>
103111
);
104112

105113
type SelectProps = React.InputHTMLAttributes<HTMLInputElement> &

0 commit comments

Comments
 (0)