Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 2ab3aee

Browse files
committed
feat(checkbox) expand density options for checkbox
Create better flexibility for manipulating checkbox while still following Material Design spec - Change checkbox size from 20px to 18px - Keep horizontal size flush when text is blank - Add md-dense support for checkbox - Add alignment math to SCSS - Support custom margin and padding for md-checkbox - Increase size of md-checkbox to properly support touch
1 parent 9d525e5 commit 2ab3aee

File tree

4 files changed

+68
-17
lines changed

4 files changed

+68
-17
lines changed

src/components/checkbox/checkbox.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ angular
3636
* When using the 'md-indeterminate' attribute use 'ng-checked' to define rendering logic instead of using 'ng-model'.
3737
* @param {expression=} ng-checked If this expression evaluates as truthy, the 'md-checked' css class is added to the checkbox and it
3838
* will appear checked.
39+
* @param md-spacing {string=} Override spacing between icon and text. `default` is 36px. Use `wide` for 48px.
40+
* Use `extra-wide` for 56px.
3941
*
4042
* @usage
4143
* <hljs lang="html">
Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,54 @@
1-
//$checkbox-width: 20px !default;
1+
//$checkbox-width: 18px !default;
22
//$checkbox-height: $checkbox-width !default;
33
//$checkbox-border-radius: 2px !default;
44
//$checkbox-border-width: 2px !default;
55
//
66
// ^^ defined in variables.scss
77
//
8-
$checkbox-margin: 16px !default;
9-
$checkbox-text-margin: 10px !default;
10-
$checkbox-top: 12px !default;
8+
$checkbox-margin-end: 16px !default;
9+
$checkbox-text-margin-top: 8px !default;
10+
$container-checkbox-margin: 3px !default;
11+
12+
$checkbox-min-height: 48px !default;
13+
$checkbox-min-height-dense: 36px !default;
14+
$checkbox-text-margin: 48px !default;
15+
$checkbox-text-margin-dense: 36px !default;
16+
17+
// from input.scss
18+
$input-container-margin-top: 18px !default;
19+
$input-container-padding-top: 2px !default;
20+
$input-padding-top: 2px !default;
21+
$input-padding-bottom: 1px !default;
22+
$input-border: 1px !default;
23+
24+
$md-inline-alignment: $input-container-margin-top + $input-container-padding-top
25+
+ $input-padding-top + $input-padding-bottom + $input-border
26+
- $checkbox-text-margin-top !default;
1127

1228
.md-inline-form {
1329
md-checkbox {
14-
margin: 19px 0 18px;
30+
margin-top: $md-inline-alignment;
31+
margin-bottom: auto;
1532
}
1633
}
1734

1835
md-checkbox {
1936
box-sizing: border-box;
2037
display: inline-block;
21-
margin-bottom: $checkbox-margin;
2238
white-space: nowrap;
2339
cursor: pointer;
2440
outline: none;
2541
user-select: none;
2642
position: relative;
2743
min-width: $checkbox-width;
28-
min-height: $checkbox-width;
29-
@include rtl(margin-left, 0, $checkbox-margin);
30-
@include rtl(margin-right, $checkbox-margin, 0);
44+
min-height: $checkbox-min-height;
45+
@include rtl(margin-left, 0, $checkbox-margin-end);
46+
@include rtl(margin-right, $checkbox-margin-end, 0);
3147

3248
&:last-of-type {
3349
margin-left: 0;
3450
margin-right: 0;
3551
}
36-
3752
&.md-focused:not([disabled]) {
3853
.md-container:before {
3954
left: -8px;
@@ -49,22 +64,43 @@ md-checkbox {
4964
}
5065
}
5166

52-
&.md-align-top-left > div.md-container {
53-
top: $checkbox-top;
54-
}
55-
5667
@include checkbox-container;
5768

69+
.md-container {
70+
// Use auto for compatibility with md-checkbox padding
71+
top: auto;
72+
@include rtl(left, initial, auto);
73+
@include rtl(right, auto, initial);
74+
margin: $container-checkbox-margin;
75+
margin-top: $checkbox-height + $container-checkbox-margin;
76+
}
77+
5878
.md-label {
5979
box-sizing: border-box;
6080
position: relative;
6181
display: inline-block;
6282
vertical-align: middle;
6383
white-space: normal;
6484
user-select: text;
85+
margin-top: $checkbox-text-margin-top;
86+
margin-bottom: auto;
87+
88+
@include rtl(margin-left, $checkbox-text-margin, 0);
89+
@include rtl(margin-right, 0, $checkbox-text-margin);
6590

66-
@include rtl(margin-left, $checkbox-text-margin + $checkbox-width, 0);
67-
@include rtl(margin-right, 0, $checkbox-text-margin + $checkbox-width);
91+
&:empty {
92+
// clamp to checkbox-container margins
93+
@include rtl(margin-left, $checkbox-height + ($container-checkbox-margin * 2), 0);
94+
@include rtl(margin-right, 0, $checkbox-height + ($container-checkbox-margin * 2));
95+
}
6896

6997
}
7098
}
99+
100+
@include whenDenseMode('md-checkbox') {
101+
min-height: $checkbox-min-height-dense;
102+
.md-label {
103+
@include rtl(margin-left, $checkbox-text-margin-dense, 0);
104+
@include rtl(margin-right, 0, $checkbox-text-margin-dense);
105+
}
106+
}

src/core/style/mixins.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,16 @@
321321
}
322322
}
323323
}
324+
325+
@mixin whenDenseMode($element) {
326+
:not(.md-dense-disabled-forced) {
327+
#{$element}.md-dense,
328+
#{$element}[md-dense],
329+
.md-dense >,
330+
.md-dense :not(.md-dense-disabled) {
331+
#{$element}:not([md-dense-disabled]):not(.md-dense-disabled) {
332+
@content;
333+
}
334+
}
335+
}
336+
}

src/core/style/variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ $button-fab-padding: rem(1.60) !default;
129129

130130

131131
// Shared Checkbox variables
132-
$checkbox-width: 20px !default;
132+
$checkbox-width: 18px !default;
133133
$checkbox-height: $checkbox-width !default;
134134
$checkbox-border-radius: 2px !default;
135135
$checkbox-border-width: 2px !default;

0 commit comments

Comments
 (0)