forked from material-components/material-components-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckbox.html
174 lines (162 loc) · 6.89 KB
/
checkbox.html
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<!--
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License
-->
<html class="mdc-typography">
<head>
<meta charset="utf-8">
<title>MDC Checkbox Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="assets/material-components-web.css.js" charset="utf-8"></script>
<style media="screen">
section {
margin-top: .5rem;
padding: 0 .5rem 1rem .5rem;
}
.mdc-theme--dark {
background: #262626;
color: white;
}
.mdc-theme--dark > h2 {
margin-top: 0;
}
/* Example of manually theming a checkbox. Note that this does not take JS-provided animations
into account. */
.mdc-theme--dark .mdc-checkbox__native-control:checked:not(:disabled) ~ .mdc-checkbox__background,
.mdc-theme--dark .mdc-checkbox__native-control:indeterminate:not(:disabled) ~ .mdc-checkbox__background {
background-color: #E91E63;
border-color: #E91E63;
}
.mdc-theme--dark .mdc-checkbox__background::before {
background-color: #E91E63;
}
.mdc-theme--dark .mdc-checkbox__checkmark__path {
stroke: #262626 !important;
}
.mdc-theme--dark .mdc-checkbox__mixedmark {
background-color: #262626;
}
</style>
</head>
<body>
<main>
<h1>MDC Checkbox</h1>
<section>
<h2>CSS Only</h2>
<div class="mdc-form-field">
<div class="mdc-checkbox">
<input type="checkbox"
id="basic-checkbox"
class="mdc-checkbox__native-control"/>
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
viewBox="0 0 24 24">
<path class="mdc-checkbox__checkmark__path"
fill="none"
stroke="white"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
</div>
<label for="basic-checkbox" id="basic-checkbox-label">This is my checkbox</label>
</div>
<button type="button" onclick="document.getElementById('basic-checkbox').indeterminate = true;">Make indeterminate</button>
<button type="button" onclick="this.parentElement.hasAttribute('dir') ? this.parentElement.removeAttribute('dir') : this.parentElement.setAttribute('dir', 'rtl');">Toggle RTL</button>
<button type="button" onclick="document.querySelector('.mdc-form-field').classList.toggle('mdc-form-field--align-end');">Toggle Align End</button>
<button type="button" onclick="document.getElementById('basic-checkbox').disabled = !document.getElementById('basic-checkbox').disabled;">Toggle Disabled</button>
</section>
<section>
<h2>CSS Only - Disabled</h2>
<div class="mdc-form-field">
<div class="mdc-checkbox mdc-checkbox--disabled">
<input type="checkbox"
id="basic-disabled-checkbox"
class="mdc-checkbox__native-control"
disabled />
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
viewBox="0 0 24 24">
<path class="mdc-checkbox__checkmark__path"
fill="none"
stroke="white"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
</div>
<label for="basic-disabled-checkbox" id="basic-disabled-checkbox-label">This is my disabled checkbox</label>
</div>
</section>
<section>
<h2>With Javascript</h2>
<div class="mdc-form-field">
<div id="mdc-js-checkbox" class="mdc-checkbox">
<input type="checkbox"
id="native-js-checkbox"
class="mdc-checkbox__native-control"/>
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
viewBox="0 0 24 24">
<path class="mdc-checkbox__checkmark__path"
fill="none"
stroke="white"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
</div>
<label for="native-js-checkbox" id="my-checkbox-label">This is my checkbox</label>
</div>
<button type="button" id="make-ind">Make indeterminate</button>
</section>
<section class="mdc-theme--dark">
<h2>Dark Theme</h2>
<div class="mdc-form-field">
<div id="mdc-checkbox-dark" class="mdc-checkbox mdc-checkbox--theme-dark">
<input type="checkbox"
id="checkbox-dark"
class="mdc-checkbox__native-control"/>
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
viewBox="0 0 24 24">
<path class="mdc-checkbox__checkmark__path"
fill="none"
stroke="white"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
</div>
<label for="checkbox-dark" id="dark-checkbox-label">This is my checkbox</label>
</div>
<button type="button" onclick="document.getElementById('checkbox-dark').disabled = !document.getElementById('checkbox-dark').disabled;">Toggle Disabled</button>
</section>
</main>
<script src="assets/material-components-web.js" charset="utf-8"></script>
<script>
(function(global) {
'use strict';
var MDCCheckbox = global.mdc.checkbox.MDCCheckbox;
var MDCFormField = global.mdc.formField.MDCFormField;
var checkbox = document.getElementById('mdc-js-checkbox');
var checkboxInstance = new MDCCheckbox(checkbox);
var formField = checkbox.parentElement;
var formFieldInstance = new MDCFormField(formField);
formFieldInstance.input = checkboxInstance;
document.getElementById('make-ind').addEventListener('click', function() {
checkboxInstance.indeterminate = true;
});
})(this);
</script>
</body>
</html>