|
| 1 | +@mixin format-input { |
| 2 | + & + [class$="__label"]::before { |
| 3 | + @content; |
| 4 | + } |
| 5 | +} |
| 6 | + |
| 7 | +@mixin format-label { |
| 8 | + & + [class$="__label"] { |
| 9 | + @content; |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +@mixin checkbox-and-radio-colors( |
| 14 | + $bg-color: $theme-input-background-color, |
| 15 | + $selected-color: "default" |
| 16 | +) { |
| 17 | + $input-text-color: get-color-token-from-bg($bg-color); |
| 18 | + $input-bg-color: if( |
| 19 | + $bg-color == "default", |
| 20 | + $theme-body-background-color, |
| 21 | + $bg-color |
| 22 | + ); |
| 23 | + $input-active-color: nth( |
| 24 | + get-link-tokens-from-bg($bg-color, $preferred-link-token: $selected-color), |
| 25 | + 1 |
| 26 | + ); |
| 27 | + $input-disabled-alpha: -0.7; |
| 28 | + $input-disabled-alpha--strong: -0.5; |
| 29 | + $input-disabled-alpha--weak: -0.8; |
| 30 | + $input-border-alpha: -0; |
| 31 | + $color-input-disabled: adjust-color( |
| 32 | + color($input-text-color), |
| 33 | + $alpha: $input-disabled-alpha |
| 34 | + ); |
| 35 | + $color-input-disabled--strong: adjust-color( |
| 36 | + color($input-text-color), |
| 37 | + $alpha: $input-disabled-alpha--strong |
| 38 | + ); |
| 39 | + $color-input-disabled--weak: adjust-color( |
| 40 | + color($input-text-color), |
| 41 | + $alpha: $input-disabled-alpha--weak |
| 42 | + ); |
| 43 | + $input-darkmode: if(lightness(color($input-bg-color)) < 50%, true, false); |
| 44 | + $input-checkmark: if($input-darkmode, "correct8-alt", "correct8"); |
| 45 | + |
| 46 | + .usa-checkbox, |
| 47 | + .usa-radio { |
| 48 | + background: color($input-bg-color); |
| 49 | + } |
| 50 | + |
| 51 | + .usa-checkbox__label, |
| 52 | + .usa-radio__label { |
| 53 | + color: color($input-text-color); |
| 54 | + &::before { |
| 55 | + background: color($input-bg-color); |
| 56 | + box-shadow: 0 0 0 units($theme-input-select-border-width) |
| 57 | + adjust-color(color($input-text-color), $alpha: $input-border-alpha); |
| 58 | + } |
| 59 | + } |
| 60 | + .usa-checkbox__input, |
| 61 | + .usa-radio__input { |
| 62 | + &:checked { |
| 63 | + @include format-input { |
| 64 | + background-color: color($input-active-color); |
| 65 | + box-shadow: 0 0 0 units($theme-input-select-border-width) |
| 66 | + color($input-active-color); |
| 67 | + } |
| 68 | + } |
| 69 | + &:disabled { |
| 70 | + @include format-label { |
| 71 | + color: $color-input-disabled; |
| 72 | + } |
| 73 | + @include format-input { |
| 74 | + background-color: color($input-bg-color); |
| 75 | + box-shadow: 0 0 0 units($theme-input-select-border-width) |
| 76 | + $color-input-disabled; |
| 77 | + } |
| 78 | + } |
| 79 | + &--tile { |
| 80 | + @include format-label { |
| 81 | + background-color: color($input-bg-color); |
| 82 | + border: units($theme-input-tile-border-width) solid |
| 83 | + $color-input-disabled; |
| 84 | + color: color($input-text-color); |
| 85 | + } |
| 86 | + &:checked { |
| 87 | + @include format-label { |
| 88 | + background-color: adjust-color( |
| 89 | + color($input-active-color), |
| 90 | + $alpha: -0.9 |
| 91 | + ); |
| 92 | + border-color: color($input-active-color); |
| 93 | + } |
| 94 | + } |
| 95 | + &:disabled:checked { |
| 96 | + @include format-label { |
| 97 | + background-color: color($input-bg-color); |
| 98 | + border-color: $color-input-disabled; |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + .usa-checkbox__input { |
| 104 | + &:checked, |
| 105 | + &:checked:disabled { |
| 106 | + @include format-input { |
| 107 | + @include add-background-svg($input-checkmark); |
| 108 | + } |
| 109 | + } |
| 110 | + &:checked:disabled { |
| 111 | + @include format-input { |
| 112 | + background-color: $color-input-disabled; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + .usa-radio__input { |
| 117 | + &:checked { |
| 118 | + @include format-input { |
| 119 | + box-shadow: 0 0 0 units($theme-input-select-border-width) |
| 120 | + color($input-active-color), |
| 121 | + inset 0 0 0 units($theme-input-select-border-width) |
| 122 | + color($input-bg-color); |
| 123 | + } |
| 124 | + } |
| 125 | + &:checked:disabled { |
| 126 | + @include format-input { |
| 127 | + background-color: $color-input-disabled--weak; |
| 128 | + box-shadow: 0 0 0 2px $color-input-disabled, |
| 129 | + inset 0 0 0 2px color($input-bg-color); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
| 134 | + |
1 | 135 | @include override-prose { |
2 | 136 | .usa-input-list { |
3 | 137 | @include add-list-reset; |
|
11 | 145 | } |
12 | 146 | } |
13 | 147 |
|
| 148 | +@include checkbox-and-radio-colors; |
| 149 | + |
14 | 150 | .usa-checkbox__input, |
15 | 151 | .usa-radio__input { |
16 | 152 | // The actual input element is only visible to screen readers, because |
17 | 153 | // all visual styling is done via the label. |
18 | 154 | @include sr-only(); |
19 | 155 |
|
20 | | - .lt-ie9 & { |
21 | | - border: 0; |
22 | | - float: left; |
23 | | - margin: units(0.5) units(0.5) 0 0; |
24 | | - position: static; |
25 | | - width: auto; |
| 156 | + &:focus { |
| 157 | + @include format-input { |
| 158 | + @include focus-outline(null, null, null, 0.5); |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + &:disabled { |
| 163 | + @include format-input { |
| 164 | + cursor: not-allowed; |
| 165 | + } |
| 166 | + @include format-label { |
| 167 | + cursor: not-allowed; |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + // Checkboxes and radios with tap-friendly targets |
| 172 | + &--tile { |
| 173 | + @include format-label { |
| 174 | + border-radius: radius($theme-input-tile-border-radius); |
| 175 | + margin-top: units(1); |
| 176 | + padding: units(1.5) units(2) units(1.5) units(5); |
| 177 | + } |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +.usa-radio__input { |
| 182 | + &:checked { |
| 183 | + @include format-input { |
| 184 | + @media print { |
| 185 | + box-shadow: inset 0 0 0 units($theme-input-select-border-width) |
| 186 | + color("white"), |
| 187 | + inset 0 0 0 units(2) color("primary"), |
| 188 | + 0 0 0 units($theme-input-select-border-width) color("primary"); |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | +} |
| 193 | + |
| 194 | +.usa-checkbox__input { |
| 195 | + &:checked, |
| 196 | + &:checked:disabled { |
| 197 | + @include format-input { |
| 198 | + background-position: center center; |
| 199 | + background-size: units(1.5) auto; |
| 200 | + @media print { |
| 201 | + background-image: none; |
| 202 | + background-color: color("white"); |
| 203 | + content: url("#{$theme-image-path}/checkbox-check-print.svg"); |
| 204 | + text-indent: 0; |
| 205 | + } |
| 206 | + } |
26 | 207 | } |
27 | 208 | } |
28 | 209 |
|
|
35 | 216 | padding-left: units($input-select-margin-right + $theme-input-select-size); |
36 | 217 | position: relative; |
37 | 218 | text-indent: units(-$input-select-margin-right - $theme-input-select-size); |
38 | | -} |
39 | 219 |
|
40 | | -.usa-checkbox__label::before, |
41 | | -.usa-radio__label::before { |
42 | | - background: color("white"); |
43 | | - content: " "; |
44 | | - display: inline-block; |
45 | | - left: units($theme-input-select-border-width); |
46 | | - position: relative; |
47 | | - vertical-align: middle\0; // Target IE 11 and below to vertically center inputs |
48 | | - white-space: pre; |
| 220 | + &:before { |
| 221 | + content: " "; |
| 222 | + display: inline-block; |
| 223 | + left: units($theme-input-select-border-width); |
| 224 | + line-height: units($theme-input-select-size); |
| 225 | + margin-right: units($input-select-margin-right); |
| 226 | + position: relative; |
| 227 | + text-indent: 0; |
| 228 | + vertical-align: middle\0; // Target IE 11 and below to vertically center inputs |
| 229 | + white-space: pre; |
| 230 | + } |
49 | 231 | } |
50 | 232 |
|
51 | 233 | .usa-checkbox__label::before { |
|
57 | 239 | @include u-circle($theme-input-select-size); |
58 | 240 | } |
59 | 241 |
|
60 | | -.usa-checkbox__label::before, |
61 | | -.usa-radio__label::before { |
62 | | - box-shadow: 0 0 0 units($theme-input-select-border-width) color("base"); |
63 | | - line-height: units($theme-input-select-size); |
64 | | - margin-right: units($input-select-margin-right); |
65 | | - text-indent: 0; |
66 | | -} |
67 | | - |
68 | | -.usa-checkbox__input:checked + .usa-checkbox__label::before, |
69 | | -.usa-radio__input:checked + .usa-radio__label::before { |
70 | | - background-color: color("primary"); |
71 | | - box-shadow: 0 0 0 units($theme-input-select-border-width) color("primary"); |
72 | | -} |
73 | | - |
74 | | -.usa-radio__input:checked + .usa-radio__label::before { |
75 | | - box-shadow: 0 0 0 units($theme-input-select-border-width) color("primary"), |
76 | | - inset 0 0 0 units($theme-input-select-border-width) color("white"); |
77 | | - |
78 | | - @media print { |
79 | | - box-shadow: inset 0 0 0 units($theme-input-select-border-width) |
80 | | - color("white"), |
81 | | - inset 0 0 0 units(2) color("primary"), |
82 | | - 0 0 0 units($theme-input-select-border-width) color("primary"); |
83 | | - } |
84 | | -} |
85 | | - |
86 | | -.usa-checkbox__input:checked + .usa-checkbox__label::before, |
87 | | -.usa-checkbox__input:checked:disabled + .usa-checkbox__label::before { |
88 | | - @include add-background-svg("correct8"); |
89 | | - background-position: center center; |
90 | | - background-size: units(1.5) auto; |
91 | | - |
92 | | - @media print { |
93 | | - background-image: none; |
94 | | - background-color: color("white"); |
95 | | - content: url("#{$theme-image-path}/checkbox-check-print.svg"); |
96 | | - text-indent: 0; |
97 | | - } |
98 | | -} |
99 | | - |
100 | | -.usa-radio__input:focus + .usa-radio__label::before { |
101 | | - @include focus-outline(null, null, null, 0.5); |
102 | | -} |
103 | | - |
104 | | -.usa-checkbox__input:disabled + .usa-checkbox__label, |
105 | | -.usa-radio__input:disabled + .usa-radio__label { |
106 | | - color: color("disabled"); |
107 | | - cursor: not-allowed; |
108 | | -} |
109 | | - |
110 | | -.usa-checkbox__input:focus + .usa-checkbox__label::before { |
111 | | - @include focus-outline; |
112 | | -} |
113 | | - |
114 | | -.usa-checkbox__input:disabled + .usa-checkbox__label::before, |
115 | | -.usa-radio__input:disabled + .usa-radio__label::before { |
116 | | - background: color("disabled-light"); |
117 | | - box-shadow: 0 0 0 units($theme-input-select-border-width) color("disabled"); |
118 | | - cursor: not-allowed; |
119 | | -} |
120 | | - |
121 | | -.usa-radio__input:checked:disabled + .usa-radio__label::before { |
122 | | - background: color("disabled-dark"); |
123 | | - box-shadow: 0 0 0 2px color("disabled-dark"), |
124 | | - inset 0 0 0 2px color("disabled-light"); |
125 | | -} |
126 | | - |
127 | | -// Checkboxes and radios with tap-friendly targets |
128 | | -.usa-checkbox__input--tile + .usa-checkbox__label, |
129 | | -.usa-radio__input--tile + .usa-radio__label { |
130 | | - border: units($theme-input-tile-border-width) solid |
131 | | - color($theme-input-tile-border-color); |
132 | | - border-radius: radius($theme-input-tile-border-radius); |
133 | | - margin-top: units(1); |
134 | | - padding: units(1.5) units(2) units(1.5) units(5); |
135 | | -} |
136 | | - |
137 | | -.usa-checkbox__input--tile:checked + .usa-checkbox__label, |
138 | | -.usa-radio__input--tile:checked + .usa-radio__label { |
139 | | - background-color: color($theme-input-tile-background-color-selected); |
140 | | - border-color: color($theme-input-tile-border-color-selected); |
141 | | -} |
142 | | - |
143 | | -.usa-checkbox__input--tile:disabled:checked + .usa-checkbox__label, |
144 | | -.usa-radio__input--tile:disabled:checked + .usa-radio__label { |
145 | | - background-color: color("disabled-light"); |
146 | | - border-color: color($theme-input-tile-border-color); |
147 | | -} |
148 | | - |
149 | 242 | .usa-checkbox__label-description, |
150 | 243 | .usa-radio__label-description { |
151 | 244 | display: block; |
152 | 245 | font-size: size("ui", "2xs"); |
153 | 246 | margin-top: units(1); |
154 | 247 | text-indent: 0; |
155 | 248 | } |
| 249 | + |
| 250 | +// Test code for scoped custom colors |
| 251 | +/* |
| 252 | +.checkbox-tests { |
| 253 | + @include set-text-and-bg("green-80"); |
| 254 | + @include checkbox-and-radio-colors("green-80", "green-warm-10v"); |
| 255 | + padding: units(2); |
| 256 | + border-radius: radius("md"); |
| 257 | +} |
| 258 | +*/ |
0 commit comments