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

Commit e240126

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 size flush when text is blank - Add md-spacing options for different density styles - Add alignment math to SCSS - Support custom margin and padding for md-checkbox In case users don't want to use the current spacing of 36px, users can now opt-in to use less dense options as seen in spec.
1 parent 9a2c47d commit e240126

File tree

3 files changed

+66
-17
lines changed

3 files changed

+66
-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">

src/components/checkbox/checkbox.scss

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,57 @@
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+
// md-spacing values (horizontal spacing with icons)
13+
// default = 36px (Angular Material default)
14+
// wide = 48px (Material Design Spec dense)
15+
// extra-wide = 56px (Material Design Spec default)
16+
$checkbox-text-margin: 36px !default;
17+
$checkbox-text-margin-wide: 48px !default;
18+
$checkbox-text-margin-extra-wide: 56px !default;
19+
20+
// from input.scss
21+
$input-container-margin-top: 18px !default;
22+
$input-container-padding-top: 2px !default;
23+
$input-padding-top: 2px !default;
24+
$input-padding-bottom: 1px !default;
25+
$input-border: 1px !default;
26+
27+
$md-inline-alignment: $input-container-margin-top + $input-container-padding-top
28+
+ $input-padding-top + $input-padding-bottom + $input-border
29+
- $checkbox-text-margin-top !default;
1130

1231
.md-inline-form {
1332
md-checkbox {
14-
margin: 19px 0 18px;
33+
margin-top: $md-inline-alignment;
34+
margin-bottom: auto;
1535
}
1636
}
1737

1838
md-checkbox {
1939
box-sizing: border-box;
2040
display: inline-block;
21-
margin-bottom: $checkbox-margin;
2241
white-space: nowrap;
2342
cursor: pointer;
2443
outline: none;
2544
user-select: none;
2645
position: relative;
2746
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);
47+
min-height: $checkbox-width * 2;
48+
@include rtl(margin-left, 0, $checkbox-margin-end);
49+
@include rtl(margin-right, $checkbox-margin-end, 0);
3150

3251
&:last-of-type {
3352
margin-left: 0;
3453
margin-right: 0;
3554
}
36-
3755
&.md-focused:not([disabled]) {
3856
.md-container:before {
3957
left: -8px;
@@ -49,22 +67,51 @@ md-checkbox {
4967
}
5068
}
5169

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

72+
.md-container {
73+
// Use auto for compatibility with md-checkbox padding
74+
top: auto;
75+
@include rtl(left, initial, auto);
76+
@include rtl(right, auto, initial);
77+
margin: $container-checkbox-margin;
78+
margin-top: $checkbox-height + $container-checkbox-margin;
79+
}
80+
5881
.md-label {
5982
box-sizing: border-box;
6083
position: relative;
6184
display: inline-block;
6285
vertical-align: middle;
6386
white-space: normal;
6487
user-select: text;
88+
margin-top: $checkbox-text-margin-top;
89+
margin-bottom: auto;
6590

66-
@include rtl(margin-left, $checkbox-text-margin + $checkbox-width, 0);
67-
@include rtl(margin-right, 0, $checkbox-text-margin + $checkbox-width);
91+
@include rtl(margin-left, $checkbox-text-margin, 0);
92+
@include rtl(margin-right, 0, $checkbox-text-margin);
6893

94+
&:empty {
95+
// clamp to checkbox-container margins
96+
@include rtl(margin-left, $checkbox-height + ($container-checkbox-margin * 2), 0);
97+
@include rtl(margin-right, 0, $checkbox-height + ($container-checkbox-margin * 2));
98+
}
99+
100+
}
101+
102+
[md-spacing="wide"] &:not[md-spacing="default"],
103+
&[md-spacing="wide"] {
104+
._md-label {
105+
@include rtl(margin-left, $checkbox-text-margin-wide, 0);
106+
@include rtl(margin-right, 0, $checkbox-text-margin-wide);
107+
}
108+
}
109+
110+
[md-spacing="extra-wide"] &:not[md-spacing="default"],
111+
&[md-spacing="extra-wide"]{
112+
._md-label {
113+
@include rtl(margin-left, $checkbox-text-margin-extra-wide, 0);
114+
@include rtl(margin-right, 0, $checkbox-text-margin-extra-wide);
115+
}
69116
}
70117
}

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)