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