Merge "Fix 'Tags' padding to keep it farther from the edge and document the source...
[lhc/web/wiklou.git] / resources / src / mediawiki.ui / components / checkbox.less
1 @import 'mediawiki.mixins';
2 @import 'mediawiki.ui/variables';
3
4 // Checkbox
5 //
6 // Styling checkboxes in a way that works cross browser is a tricky problem to solve.
7 // In MediaWiki UI put a checkbox and label inside a mw-ui-checkbox div.
8 // This renders in all browsers except IE 6-8 which do not support the `:checked` selector;
9 // these are kept backwards-compatible using the `:not( #noop )` selector.
10 // You should give the checkbox and label matching `id` and `for` attributes, respectively.
11 //
12 // Markup:
13 // <div class="mw-ui-checkbox">
14 // <input type="checkbox" id="kss-example-3">
15 // <label for="kss-example-3">Standard checkbox</label>
16 // </div>
17 // <div class="mw-ui-checkbox">
18 // <input type="checkbox" id="kss-example-3-checked" checked>
19 // <label for="kss-example-3-checked">Standard checked checkbox</label>
20 // </div>
21 // <div class="mw-ui-checkbox">
22 // <input type="checkbox" id="kss-example-3-disabled" disabled>
23 // <label for="kss-example-3-disabled">Disabled checkbox</label>
24 // </div>
25 // <div class="mw-ui-checkbox">
26 // <input type="checkbox" id="kss-example-3-disabled-checked" disabled checked>
27 // <label for="kss-example-3-disabled-checked">Disabled checked checkbox</label>
28 // </div>
29 //
30 // Styleguide 3.
31 .mw-ui-checkbox {
32 display: inline-block;
33 line-height: @sizeInputBinary;
34 vertical-align: middle;
35 }
36
37 // We use the `:not` selector to cancel out styling on IE 8 and below
38 // Note: This may be broken on older Opera Mini devices.
39 .mw-ui-checkbox:not( #noop ) {
40 display: table;
41 // Position relatively so we can make use of absolute pseudo elements
42 position: relative;
43
44 * {
45 // Reset font sizes, see T74727
46 font: inherit;
47 vertical-align: middle;
48 }
49
50 [ type='checkbox' ] {
51 display: table-cell;
52 position: relative;
53 // Ensure the invisible input takes up the required `width` & `height`
54 width: @sizeInputBinary;
55 height: @sizeInputBinary;
56 // Support: Firefox mobile to override user-agent stylesheet, see T73750
57 max-width: none;
58 margin: 0;
59 // Hide `input[type=checkbox]` and instead style the label that follows
60 // Support: VoiceOver. Use `opacity` so that VoiceOver can still identify the checkbox
61 opacity: 0;
62 // Render *on top of* the label, so that it's still clickable, see T98905
63 z-index: 1;
64
65 & + label {
66 display: table-cell;
67 padding-left: 0.4em;
68 }
69
70 // Pseudo `:before` element of the label after the checkbox now looks like a checkbox
71 & + label:before {
72 content: '';
73 background-color: #fff;
74 background-origin: border-box;
75 background-position: center center;
76 background-repeat: no-repeat;
77 .background-size( 0, 0 );
78 .box-sizing( border-box );
79 position: absolute;
80 // Ensure alignment of checkbox to middle of the text in long labels, see T85241
81 top: 50%;
82 left: 0;
83 width: @sizeInputBinary;
84 height: @sizeInputBinary;
85 margin-top: -( @sizeInputBinary / 2 );
86 border: 1px solid @colorGray7;
87 border-radius: @borderRadius;
88 }
89
90 // Apply a checkmark on the pseudo `:before` element when the input is checked
91 &:checked + label:before {
92 .background-image-svg( 'images/checkbox-checked.svg', 'images/checkbox-checked.png' );
93 .background-size( 90%, 90% );
94 }
95
96 &:enabled {
97 cursor: pointer;
98
99 & + label {
100 cursor: pointer;
101 }
102
103 & + label:before {
104 cursor: pointer;
105 .transition( ~'background-color 100ms, color 100ms, border-color 100ms, box-shadow 100ms' );
106 }
107
108 // `:focus` has to come first, otherwise a specificity race with `:hover:focus` etc is necessary
109 &:focus + label:before {
110 border-color: @colorProgressive;
111 box-shadow: @boxShadowWidgetFocus;
112 }
113
114 &:hover + label:before {
115 border-color: @colorProgressive;
116 }
117
118 &:active + label:before {
119 background-color: @colorProgressiveActive;
120 border-color: @borderColorInputBinaryActive;
121 box-shadow: @boxShadowInputBinaryActive;
122 }
123
124 &:checked {
125 & + label:before {
126 background-color: @backgroundColorInputBinaryChecked;
127 border-color: @borderColorInputBinaryChecked;
128 }
129
130 &:focus + label:before {
131 background-color: @backgroundColorInputBinaryChecked;
132 border-color: @borderColorInputBinaryChecked;
133 box-shadow: @boxShadowProgressiveFocus;
134 }
135
136 &:hover + label:before {
137 background-color: @colorProgressiveHighlight;
138 border-color: @colorProgressiveHighlight;
139 }
140
141 &:active + label:before {
142 background-color: @backgroundColorInputBinaryActive;
143 border-color: @borderColorInputBinaryActive;
144 }
145 }
146 }
147
148 // disabled checkboxes have a gray background
149 &:disabled + label:before {
150 background-color: @colorGray12;
151 border-color: @colorGray12;
152 }
153 }
154 }