-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathunit-control-styles.ts
146 lines (127 loc) · 3.37 KB
/
unit-control-styles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* External dependencies
*/
import { css } from '@emotion/react';
import styled from '@emotion/styled';
/**
* Internal dependencies
*/
import { COLORS, CONFIG, rtl } from '../../utils';
import NumberControl from '../../number-control';
import { BackdropUI } from '../../input-control/styles/input-control-styles';
import type { SelectSize } from '../types';
import { space } from '../../ui/utils/space';
// Using `selectSize` instead of `size` to avoid a type conflict with the
// `size` HTML attribute of the `select` element.
type SelectProps = {
selectSize: SelectSize;
};
// TODO: Resolve need to use &&& to increase specificity
// https://github.com/WordPress/gutenberg/issues/18483
export const ValueInput = styled( NumberControl )`
&&& {
input {
display: block;
width: 100%;
}
${ BackdropUI } {
transition: box-shadow 0.1s linear;
}
}
`;
const baseUnitLabelStyles = ( { selectSize }: SelectProps ) => {
const sizes = {
default: css`
box-sizing: border-box;
padding: 2px 1px;
width: 20px;
color: ${ COLORS.gray[ 800 ] };
font-size: 8px;
line-height: 1;
letter-spacing: -0.5px;
text-transform: uppercase;
text-align-last: center;
`,
large: css`
box-sizing: border-box;
min-width: 24px;
max-width: 48px;
height: 24px;
margin-inline-end: ${ space( 2 ) };
padding: ${ space( 1 ) };
color: ${ COLORS.ui.theme };
font-size: 13px;
line-height: 1;
text-align-last: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`,
};
return selectSize === '__unstable-large' ? sizes.large : sizes.default;
};
export const UnitLabel = styled.div< SelectProps >`
&&& {
pointer-events: none;
${ baseUnitLabelStyles };
color: ${ COLORS.gray[ 900 ] };
}
`;
const unitSelectSizes = ( { selectSize = 'default' }: SelectProps ) => {
const sizes = {
default: css`
height: 100%;
border: 1px solid transparent;
transition: box-shadow 0.1s linear, border 0.1s linear;
${ rtl( { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 } )() }
&:not(:disabled):hover {
background-color: ${ COLORS.gray[ 100 ] };
}
&:focus {
border: 1px solid ${ COLORS.ui.borderFocus };
box-shadow: inset 0 0 0
${ CONFIG.borderWidth + ' ' + COLORS.ui.borderFocus };
outline-offset: 0;
outline: 2px solid transparent;
z-index: 1;
}
`,
large: css`
display: flex;
justify-content: center;
align-items: center;
&:hover {
color: ${ COLORS.ui.borderFocus };
box-shadow: inset 0 0 0
${ CONFIG.borderWidth + ' ' + COLORS.ui.borderFocus };
outline: ${ CONFIG.borderWidth } solid transparent; // For High Contrast Mode
}
&:focus {
box-shadow: 0 0 0
${ CONFIG.borderWidthFocus + ' ' + COLORS.ui.borderFocus };
outline: ${ CONFIG.borderWidthFocus } solid transparent; // For High Contrast Mode
}
`,
};
return selectSize === '__unstable-large' ? sizes.large : sizes.default;
};
export const UnitSelect = styled.select< SelectProps >`
// The && counteracts <select> styles in WP forms.css
&& {
appearance: none;
background: transparent;
border-radius: 2px;
border: none;
display: block;
outline: none;
/* Removing margin ensures focus styles neatly overlay the wrapper. */
margin: 0;
min-height: auto;
font-family: inherit;
&:not( :disabled ) {
cursor: pointer;
}
${ baseUnitLabelStyles };
${ unitSelectSizes };
}
`;