mediawiki.ui: checkbox: Fix states according to spec
[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: 2em;
33
34 // We use the not selector to cancel out styling on IE 8 and below
35 .mw-ui-checkbox:not(#noop) {
36 // Position relatively so we can make use of absolute pseudo elements
37 position: relative;
38 line-height: @checkboxSize;
39
40 * {
41 vertical-align: middle;
42 }
43
44 input[type="checkbox"] {
45 // we hide the input element as instead we will style the label that follows
46 // we use opacity so that VoiceOver software can still identify it
47 opacity: 0;
48 // ensure the invisible checkbox takes up the required width
49 width: @checkboxSize;
50 height: @checkboxSize;
51 // This is needed for Firefox mobile (See bug 71750 to workaround default Firefox stylesheet)
52 max-width: none;
53 margin-right: .4em;
54
55 // the pseudo before element of the label after the checkbox now looks like a checkbox
56 & + label::before {
57 content: '';
58 cursor: pointer;
59 position: absolute;
60 left: 0;
61 border-radius: @borderRadius;
62 width: @checkboxSize;
63 height: @checkboxSize;
64 background-color: #fff;
65 border: 1px solid @colorGray7;
66 .box-sizing(border-box);
67 }
68
69 // when the input is checked, style the label pseudo before element that followed as a checked checkbox
70 &:checked + label::before {
71 .background-image-svg('images/checked.svg', 'images/checked.png');
72 .background-size( @checkboxSize - 0.2em, @checkboxSize - 0.2em );
73 background-repeat: no-repeat;
74 background-position: center center;
75 background-origin: border-box;
76 }
77
78 &:active + label::before {
79 background-color: @colorGray13;
80 border-color: @colorGray13;
81 }
82
83 &:focus + label::before {
84 border-width: 2px;
85 }
86
87 &:hover + label::before {
88 border-bottom-width: 3px;
89 }
90
91 // disabled checkboxes have a gray background
92 &:disabled + label::before {
93 cursor: default;
94 background-color: @colorGray14;
95 border-color: @colorGray14;
96 }
97
98 // disabled and checked checkboxes have a white circle
99 &:disabled:checked + label::before {
100 .background-image-svg('images/checked_disabled.svg', 'images/checked_disabled.png');
101 }
102 }
103 }