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