summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.ui/components/checkbox.less
blob: 4829f5f6b59c2a6255b96da7685713f6b713f01f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@import "mediawiki.mixins";
@import "mediawiki.ui/variables";

// Checkbox
//
// Styling checkboxes in a way that works cross browser is a tricky problem to solve.
// In MediaWiki UI put a checkbox and label inside a mw-ui-checkbox div.
// This renders in all browsers except IE6-8 which do not support the :checked selector;
// these are kept backwards-compatible using the :not(#noop) selector.
// You should give the checkbox and label matching "id" and "for" attributes, respectively.
//
// Markup:
// <div class="mw-ui-checkbox">
//   <input type="checkbox" id="kss-example-3">
//   <label for="kss-example-3">Standard checkbox</label>
// </div>
// <div class="mw-ui-checkbox">
//   <input type="checkbox" id="kss-example-3-checked" checked>
//   <label for="kss-example-3-checked">Standard checked checkbox</label>
// </div>
// <div class="mw-ui-checkbox">
//   <input type="checkbox" id="kss-example-3-disabled" disabled>
//   <label for="kss-example-3-disabled">Disabled checkbox</label>
// </div>
// <div class="mw-ui-checkbox">
//   <input type="checkbox" id="kss-example-3-disabled-checked" disabled checked>
//   <label for="kss-example-3-disabled-checked">Disabled checked checkbox</label>
// </div>
//
// Styleguide 3.
.mw-ui-checkbox {
	display: inline-block;
	vertical-align: middle;
}

@checkboxSize: 2em;

// We use the not selector to cancel out styling on IE 8 and below
// We also disable this styling on javascript disabled devices. This fixes the issue with
// Opera Mini where checking/unchecking doesn't apply styling but potentially leaves other
// more capable browsers with unstyled checkboxes.
.client-js .mw-ui-checkbox:not(#noop) {
	// Position relatively so we can make use of absolute pseudo elements
	position: relative;
	display: table;

	* {
		// reset font sizes (see bug 72727)
		font: inherit;
		vertical-align: middle;
	}

	input[type="checkbox"] {
		// we hide the input element as instead we will style the label that follows
		// we use opacity so that VoiceOver software can still identify it
		opacity: 0;
		// ensure the invisible checkbox takes up the required width
		width: @checkboxSize;
		height: @checkboxSize;
		// This is needed for Firefox mobile (See bug 71750 to workaround default Firefox stylesheet)
		max-width: none;
		margin: 0;
		margin-right: 0.4em;
		display: table-cell;

		& + label {
			display: table-cell;
		}

		// the pseudo before element of the label after the checkbox now looks like a checkbox
		& + label::before {
			.transition( 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) );
			content: '';
			cursor: pointer;
			.box-sizing(border-box);
			position: absolute;
			left: 0;
			border-radius: @borderRadius;
			width: @checkboxSize;
			height: @checkboxSize;
			line-height: @checkboxSize;
			background-color: #fff;
			border: 1px solid @colorGray7;
			// align the checkbox to middle of the text
			top: 50%;
			margin-top: -1em;
			.background-image-svg('images/checked.svg', 'images/checked.png');
			.background-size( @checkboxSize - 0.2em, @checkboxSize - 0.2em );
			background-repeat: no-repeat;
			background-position: center center;
			background-origin: border-box;
			background-size: 0 0;
		}

		// when the input is checked, style the label pseudo before element that followed as a checked checkbox
		&:checked + label::before {
			background-size: 100% 100%;
		}

		&:active + label::before {
			background-color: @colorGray13;
			border-color: @colorGray13;
		}

		&:focus + label::before {
			border-width: 2px;
		}

		&:focus:hover + label::before,
		&:hover + label::before {
			border-bottom-width: 3px;
		}

		// disabled checkboxes have a gray background
		&:disabled + label::before {
			cursor: default;
			background-color: @colorGray14;
			border-color: @colorGray14;
		}

		// disabled and checked checkboxes have a white circle
		&:disabled:checked + label::before {
			.background-image-svg('images/checked_disabled.svg', 'images/checked_disabled.png');
		}
	}
}