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