This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
/
unit-control-styles.js
130 lines (111 loc) · 2.29 KB
/
unit-control-styles.js
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
/**
* External dependencies
*/
import { css } from '@emotion/react';
import styled from '@emotion/styled';
/**
* Internal dependencies
*/
import { COLORS, rtl } from '../../utils';
import NumberControl from '../../number-control';
export const Root = styled.div`
box-sizing: border-box;
position: relative;
`;
const paddingStyles = ( { disableUnits } ) => {
const value = disableUnits ? 3 : 24;
return css`
${ rtl( { paddingRight: value } )() };
`;
};
const arrowStyles = ( { disableUnits } ) => {
if ( disableUnits ) return '';
return css`
&::-webkit-outer-spin-button,
&::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
`;
};
// TODO: Resolve need to use &&& to increase specificity
// https://github.com/WordPress/gutenberg/issues/18483
export const ValueInput = styled( NumberControl )`
&&& {
input {
appearance: none;
-moz-appearance: textfield;
display: block;
width: 100%;
${ arrowStyles };
${ paddingStyles };
}
}
`;
const unitSizeStyles = ( { size } ) => {
const sizes = {
default: {
height: 28,
lineHeight: '24px',
minHeight: 28,
top: 1,
},
small: {
height: 22,
lineHeight: '18px',
minHeight: 22,
top: 1,
},
};
return css( sizes[ size ] );
};
const baseUnitLabelStyles = ( props ) => {
return css`
appearance: none;
background: transparent;
border-radius: 2px;
border: none;
box-sizing: border-box;
color: ${ COLORS.darkGray[ 500 ] };
display: block;
font-size: 8px;
line-height: 1;
letter-spacing: -0.5px;
outline: none;
padding: 2px 1px;
position: absolute;
text-align-last: center;
text-transform: uppercase;
width: 20px;
${ rtl( { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 } )() }
${ rtl( { right: 0 } )() }
${ unitSizeStyles( props ) }
`;
};
export const UnitLabel = styled.div`
&&& {
pointer-events: none;
${ baseUnitLabelStyles };
}
`;
export const UnitSelect = styled.select`
&&& {
${ baseUnitLabelStyles };
cursor: pointer;
border: 1px solid transparent;
&:hover {
background-color: ${ COLORS.lightGray[ 300 ] };
}
&:focus {
border-color: ${ COLORS.ui.borderFocus };
outline: 2px solid transparent;
outline-offset: 0;
}
&:disabled {
cursor: initial;
&:hover {
background-color: transparent;
}
}
}
`;