|
1 | 1 | import React from 'react'; |
2 | 2 | import deepmerge from 'deepmerge'; |
3 | | -import styled from 'styled-components'; |
4 | 3 | import css from '@styled-system/css'; |
5 | 4 | import { Input } from '../Input'; |
6 | 5 | import { Element } from '../Element'; |
@@ -43,63 +42,72 @@ const getSVG = (variant, color) => { |
43 | 42 | return header + encoded; |
44 | 43 | }; |
45 | 44 |
|
46 | | -const SelectComponent = styled(Input).attrs({ as: 'select' })<{ |
| 45 | +const SelectComponent: React.FC<{ |
47 | 46 | 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', |
52 | 84 | color: 'input.placeholderForeground', |
53 | 85 | transition: 'all ease', |
54 | 86 | transitionDuration: theme => theme.speeds[2], |
55 | 87 |
|
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%)', |
68 | 96 | }, |
69 | | - }) |
70 | | - ) |
71 | | -); |
72 | 97 |
|
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 |
97 | 101 | 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 | + }, |
100 | 107 | }, |
101 | | - }, |
102 | | - }) |
| 108 | + })} |
| 109 | + {...props} |
| 110 | + /> |
103 | 111 | ); |
104 | 112 |
|
105 | 113 | type SelectProps = React.InputHTMLAttributes<HTMLInputElement> & |
|
0 commit comments