Skip to content

Commit

Permalink
chore(field): refactor start/end padding
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 462008763
  • Loading branch information
asyncLiz authored and copybara-github committed Jul 19, 2022
1 parent 1ef99c8 commit 0d5d344
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
37 changes: 16 additions & 21 deletions field/lib/_outlined-field-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ $dark-theme: values(
);
}

@include _container-padding-horizontal(
map.get($theme, container-padding-horizontal)
);
@include _container-padding-horizontal($theme);
@include _container-shape(map.get($theme, container-shape));
@include _outline-color(
(
Expand Down Expand Up @@ -165,35 +163,32 @@ $dark-theme: values(
);
}

@mixin _container-padding-horizontal($padding) {
@mixin _container-padding-horizontal($theme) {
// Add padding that will grow to compensate for the outline's shape.
// This is needed to prevent the outline border from clipping with the label
// and is mirrored in the container padding to align the content and resting
// label with the adjusted floating label.
$padding: map.get($theme, container-padding-horizontal);
$shape: map.get($theme, container-shape);
$label-padding: map.get($theme, outline-label-padding);

.md3-field__outline-start,
.md3-field__start::before,
.md3-field__end::after {
// Outlined variant start section uses min-width instead of padding since it
// needs to add start/end padding to add extra space as needed for shape and
// label padding.
min-width: $padding;
.md3-field__start {
padding-inline-start: max($padding, $shape + $label-padding);
}

.md3-field__end {
padding-inline-end: max($padding, $shape);
}
}

@mixin _container-shape($shape) {
.md3-field__outline {
border-radius: $shape;
}

.md3-field__outline-start,
.md3-field__start::before,
.md3-field__end::after {
padding-inline-start: $shape;
}
}

@mixin _outline-label-padding($padding) {
.md3-field__outline-start,
.md3-field__start::before {
padding-inline-end: $padding;
}

.md3-field__outline-start::before,
.md3-field__outline-start::after {
margin-inline-end: $padding;
Expand Down
17 changes: 0 additions & 17 deletions field/lib/_outlined-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
$_animation-duration: 150ms;

@mixin static-styles() {
.md3-field--outlined {
.md3-field__start::before,
.md3-field__end::after {
@include start-and-end-shape-padding;
}
}

.md3-field__outline {
@include outline;
}
Expand Down Expand Up @@ -74,16 +67,6 @@ $_animation-duration: 150ms;
}
}

@mixin start-and-end-shape-padding() {
// Add a child element that will grow to compensate for the outline's shape.
// This is needed to prevent the outline border from clipping with the label
// and is mirrored in the container padding to align the content and resting
// label with the adjusted floating label.
box-sizing: border-box;
content: '';
display: flex;
}

@mixin outline() {
display: flex;
// Allow events to target elements underneath the outline, such as icons.
Expand Down

0 comments on commit 0d5d344

Please sign in to comment.