Skip to content

Commit e373857

Browse files
Samuell1marcosmoura
authored andcommitted
feat(MdCheckbox): add indeterminate variant (#1597)
* feat(MdCheckbox): add `indeterminate` look, prop * docs(MdCheckbox): indeterminate option * docs(MdCheckbox): add indeterminate example * style(MdCheckbox): improve css styles to maintain the correct pattern
1 parent 5ca1979 commit e373857

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

docs/app/pages/Components/Checkbox/Checkbox.vue

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
type: 'String',
5353
description: 'The checkbox unique id.',
5454
defaults: 'a random string'
55+
},
56+
{
57+
name: 'indeterminate',
58+
type: 'Boolean',
59+
description: 'Enables the indeterminate look of the checkbox.',
60+
defaults: 'false'
5561
}
5662
]
5763
},

docs/app/pages/Components/Checkbox/examples/RegularCheckboxes.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<md-checkbox v-model="obj" :value="obj1">Object 1</md-checkbox>
1010
<md-checkbox v-model="obj" :value="obj2">Object 2</md-checkbox>
1111

12+
<md-checkbox v-model="indeterminate" indeterminate>Indeterminate</md-checkbox>
13+
1214
<table>
1315
<tr>
1416
<th>Array</th>
@@ -40,7 +42,8 @@
4042
disabled: true,
4143
obj1: {name: 'obj1'},
4244
obj2: {name: 'obj2'},
43-
obj: null
45+
obj: null,
46+
indeterminate: true
4447
})
4548
}
4649
</script>

src/components/MdCheckbox/MdCheckbox.vue

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="md-checkbox" :class="[$mdActiveTheme, checkClasses]">
33
<div class="md-checkbox-container" @click.stop="toggleCheck">
44
<md-ripple md-centered :md-active.sync="rippleActive" :md-disabled="disabled">
5-
<input type="checkbox" v-bind="{ id, name, disabled, required, value }">
5+
<input type="checkbox" v-bind="{ id, name, disabled, required, value }" :indeterminate.prop="indeterminate">
66
</md-ripple>
77
</div>
88

@@ -115,6 +115,22 @@
115115
}
116116
}
117117
118+
.md-checkbox.md-indeterminate {
119+
.md-checkbox-container {
120+
&:after {
121+
width: 12px;
122+
height: 2px;
123+
top: 50%;
124+
left: 50%;
125+
z-index: 7;
126+
border-style: solid;
127+
border-width: 0 0 2px;
128+
opacity: 0;
129+
transform: translate(-50%, -50%) !important;
130+
}
131+
}
132+
}
133+
118134
.md-checkbox.md-checked {
119135
.md-checkbox-container {
120136
&:after {

src/components/MdCheckbox/MdCheckboxMixin.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export default {
1212
},
1313
name: [String, Number],
1414
required: Boolean,
15-
disabled: Boolean
15+
disabled: Boolean,
16+
indeterminate: Boolean
1617
},
1718
model: {
1819
prop: 'model',
@@ -43,7 +44,8 @@ export default {
4344
return {
4445
'md-checked': this.isSelected,
4546
'md-disabled': this.disabled,
46-
'md-required': this.required
47+
'md-required': this.required,
48+
'md-indeterminate': this.indeterminate
4749
}
4850
}
4951
},

src/components/MdCheckbox/theme.scss

+38
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
}
1616
}
1717

18+
&.md-indeterminate {
19+
.md-checkbox-container {
20+
border-color: rgba(#000, .54);
21+
background-color: rgba(#fff, .3);
22+
&:after {
23+
border-color: rgba(#000, .54);
24+
}
25+
}
26+
.md-ripple {
27+
color: rgba(#000, .54);
28+
}
29+
}
30+
1831
&.md-checked.md-primary {
1932
.md-checkbox-container {
2033
@include md-theme-property(background-color, primary);
@@ -27,6 +40,18 @@
2740
}
2841

2942
@if md-get-theme-mode() == light {
43+
&.md-indeterminate {
44+
.md-checkbox-container {
45+
border-color: rgba(#000, .54);
46+
background-color: transparent;
47+
&:after {
48+
border-color: rgba(#000, .54);
49+
}
50+
}
51+
.md-ripple {
52+
color: rgba(#000, .54);
53+
}
54+
}
3055
.md-checkbox-container {
3156
border-color: rgba(#000, .54);
3257
}
@@ -44,6 +69,19 @@
4469
}
4570
}
4671
} @else {
72+
&.md-indeterminate {
73+
.md-checkbox-container {
74+
border-color: rgba(#fff, .7);
75+
background-color: transparent;
76+
&:after {
77+
border-color: rgba(#fff, .7);
78+
}
79+
}
80+
.md-ripple {
81+
color: rgba(#fff, .7);
82+
}
83+
}
84+
4785
.md-checkbox-container {
4886
border-color: rgba(#fff, .7);
4987
}

0 commit comments

Comments
 (0)