Merge "checkbox.less: Set cursor on label instead of pseudo element"
[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 IE6-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-5"><label for="kss-example-5">Standard checkbox</label>
15 // </div>
16 // <div class="mw-ui-checkbox">
17 // <input type="checkbox" id="kss-example-5-2" disabled><label for="kss-example-5-2">Disabled checkbox</label>
18 // </div>
19 //
20 // Styleguide 5.
21 .mw-ui-checkbox {
22 display: inline-block;
23 vertical-align: middle;
24 }
25
26 @checkboxSize: 24px;
27
28 // We use the not selector to cancel out styling on IE 8 and below
29 .mw-ui-checkbox:not(#noop) {
30 // Position relatively so we can make use of absolute pseudo elements
31 position: relative;
32 line-height: @checkboxSize;
33
34 * {
35 vertical-align: middle;
36 }
37
38 input[type="checkbox"] {
39 // we hide the input element as instead we will style the label that follows
40 // we use opacity so that VoiceOver software can still identify it
41 opacity: 0;
42 // ensure the invisible checkbox takes up the required width
43 width: @checkboxSize;
44 height: @checkboxSize;
45
46 // the pseudo before element of the label after the checkbox now looks like a checkbox
47 & + label {
48 cursor: pointer;
49
50 &::before {
51 content: '';
52 position: absolute;
53 left: 0;
54 display: inline-block;
55 border-radius: @borderRadius;
56 margin-right: 18px;
57 width: @checkboxSize;
58 height: @checkboxSize;
59 background-color: #fff;
60 border: 1px solid grey;
61 }
62 }
63
64 // when the input is checked, style the label pseudo before element that followed as a checked checkbox
65 &:checked {
66 + label {
67 &::before {
68 .background-image-svg('images/checked.svg', 'images/checked.png');
69 background-repeat: no-repeat;
70 background-position: center top;
71 }
72 }
73 }
74
75 @focusBottomBorderSize: 3px;
76 &:active,
77 &:focus {
78 + label {
79 &::after {
80 content: '';
81 position: absolute;
82 width: @checkboxSize;
83 height: @checkboxSize - @focusBottomBorderSize + 1; // offset by bottom border
84 // offset from the checkbox by 1px to account for left border
85 left: 1px;
86 border-bottom: solid @focusBottomBorderSize lightgrey;
87 }
88 }
89 }
90
91 // disabled checked boxes have a gray background
92 &:disabled + label {
93 cursor: default;
94
95 &::before {
96 background-color: lightgrey;
97 }
98 }
99 }
100 }