|
1 | | -import { style, globalStyle } from 'treat'; |
| 1 | +import { style, styleMap } from 'treat'; |
2 | 2 |
|
3 | 3 | export const root = style({ |
4 | 4 | position: 'relative', |
5 | | - flexDirection: 'column-reverse', // because we select the `label` using the CSS `+` adjacent sibling selector |
6 | 5 | display: 'flex', |
7 | | - textAlign: 'left', |
| 6 | + flexDirection: 'column', |
8 | 7 | }); |
9 | 8 |
|
10 | | -export const textArea = style(({ palette, sizing, shadows, shape, typography }) => ({ |
11 | | - // reset |
12 | | - display: 'inherit', |
13 | | - margin: 0, |
14 | | - outline: 0, |
15 | | - boxSizing: 'border-box', |
16 | | - backgroundClip: 'padding-box', |
17 | | - whiteSpace: 'nowrap', |
18 | | - '--webkit-appearance': 'none', |
19 | | - // ./reset |
20 | | - boxShadow: shadows.line, |
21 | | - border: `1px solid ${palette.border}`, |
22 | | - borderRadius: shape.borderRadius.tiny, |
23 | | - minWidth: 256, |
24 | | - minHeight: sizing('tiny') * 6, |
25 | | - padding: sizing('tiny') - 2.5, |
26 | | - backgroundColor: palette.white, |
27 | | - ...typography.variant('small'), |
28 | | - textAlign: 'inherit', |
29 | | - color: palette.textDark, |
30 | | - ':invalid': { |
31 | | - borderColor: palette.warning, |
32 | | - }, |
33 | | - '::placeholder': { |
34 | | - color: palette.light('textDark'), |
35 | | - }, |
36 | | -})); |
| 9 | +export const label = style(() => ({})); |
37 | 10 |
|
38 | | -export const label = style(({ palette }) => ({ |
39 | | - selectors: { |
40 | | - [`${textArea}:invalid + &`]: { |
41 | | - color: palette.warning, |
| 11 | +export const textArea = styleMap(({ palette, sizing, shape, typography }) => ({ |
| 12 | + container: { |
| 13 | + display: 'flex', |
| 14 | + flexWrap: 'nowrap', |
| 15 | + alignItems: 'center', |
| 16 | + backgroundColor: palette.surface, |
| 17 | + borderRadius: shape.borderRadius.small, |
| 18 | + border: `1px solid ${palette.border}`, |
| 19 | + }, |
| 20 | + root: { |
| 21 | + flex: 1, |
| 22 | + border: 0, |
| 23 | + outline: 0, |
| 24 | + margin: 0, |
| 25 | + backgroundColor: 'transparent', |
| 26 | + backgroundClip: 'padding-box', |
| 27 | + color: palette.text, |
| 28 | + padding: sizing('small'), |
| 29 | + ...typography.variant('regular'), |
| 30 | + textAlign: 'inherit', |
| 31 | + textOverflow: 'ellipsis', |
| 32 | + whiteSpace: 'nowrap', |
| 33 | + '--webkit-appearance': 'none', |
| 34 | + '::placeholder': { |
| 35 | + color: palette.light('text'), |
42 | 36 | }, |
| 37 | + minWidth: 256, |
| 38 | + minHeight: sizing('large'), |
43 | 39 | }, |
44 | 40 | })); |
45 | 41 |
|
46 | 42 | export const dense = style(({ sizing }) => ({ |
47 | 43 | selectors: { |
48 | | - [`${textArea}&`]: { |
49 | | - padding: sizing('tiny') / 2 + 0.5, |
| 44 | + [`${label}&`]: { |
| 45 | + lineHeight: 1.125, |
| 46 | + }, |
| 47 | + [`${textArea.root}&`]: { |
| 48 | + padding: sizing('tiny'), |
50 | 49 | }, |
51 | 50 | }, |
52 | 51 | })); |
53 | 52 |
|
54 | 53 | export const disabled = style(({ palette }) => ({ |
55 | 54 | selectors: { |
56 | | - [`${textArea}&`]: { |
57 | | - boxShadow: 'none', |
| 55 | + [`${textArea.container}&`]: { |
58 | 56 | cursor: 'not-allowed', |
59 | | - color: palette.lighten('textDark', 0.68), |
| 57 | + backgroundColor: palette.disabled, |
60 | 58 | }, |
61 | 59 | }, |
62 | 60 | })); |
63 | 61 |
|
64 | | -globalStyle(`${textArea}:hover:not(${disabled}), ${textArea}:focus`, ({ palette }) => ({ |
65 | | - borderColor: palette.dark('border'), |
| 62 | +export const invalid = style(({ palette }) => ({ |
| 63 | + selectors: { |
| 64 | + [`${textArea.container}&`]: { |
| 65 | + borderColor: palette.warning, |
| 66 | + }, |
| 67 | + [`${textArea.root}&`]: { |
| 68 | + borderColor: palette.warning, |
| 69 | + }, |
| 70 | + }, |
66 | 71 | })); |
67 | 72 |
|
68 | | -globalStyle( |
69 | | - `${textArea}:hover:not(${disabled}):invalid, ${textArea}:focus:invalid`, |
70 | | - ({ palette }) => ({ |
71 | | - borderColor: palette.dark('warning'), |
72 | | - }), |
73 | | -); |
| 73 | +export const focused = style(({ palette, shadows }) => ({ |
| 74 | + selectors: { |
| 75 | + [`${textArea.container}&`]: { |
| 76 | + boxShadow: shadows.line, |
| 77 | + outline: `${palette.focus} auto 5px`, |
| 78 | + }, |
| 79 | + }, |
| 80 | +})); |
0 commit comments