Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and simplify Badge css #3950

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
### Bug fixes

- Fixed virtual cursor leaving dialog in `Modal`, `Navigation` and `Sheet` ([#3931](https://github.com/Shopify/polaris-react/pull/3931))
- Simplified output of `Badge`'s css ([#3950](https://github.com/Shopify/polaris-react/pull/3950))

### Documentation

Expand Down
89 changes: 38 additions & 51 deletions src/components/Badge/Badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ $vertical-padding: rem(3px);
$pip-size: rem(10px);
$pip-spacing: ($height - $pip-size) / 2;

@mixin pip-color($color) {
.Pip {
color: $color;
}
}

.Badge {
@include pip-color(var(--p-icon));
--p-component-badge-pip-color: var(--p-icon);
display: inline-flex;
align-items: center;
padding: $vertical-padding $horizontal-padding;
Expand All @@ -40,31 +34,31 @@ $pip-spacing: ($height - $pip-size) / 2;
}

.statusSuccess {
@include pip-color(var(--p-icon-success));
--p-component-badge-pip-color: var(--p-icon-success);
background-color: var(--p-surface-success);
color: var(--p-text);
}

.statusInfo {
@include pip-color(var(--p-icon-highlight));
--p-component-badge-pip-color: var(--p-icon-highlight);
background-color: var(--p-surface-highlight);
color: var(--p-text);
}

.statusAttention {
@include pip-color(color('yellow', 'dark'));
--p-component-badge-pip-color: color('yellow', 'dark');
background-color: color('yellow', 'light');
color: var(--p-text);
}

.statusWarning {
@include pip-color(var(--p-icon-warning));
--p-component-badge-pip-color: var(--p-icon-warning);
background-color: var(--p-surface-warning);
color: var(--p-text, color('orange', 'text'));
}

.statusCritical {
@include pip-color(var(--p-icon-critical));
--p-component-badge-pip-color: var(--p-icon-critical);
background-color: var(--p-surface-critical);
color: var(--p-text);
}
Expand All @@ -77,6 +71,7 @@ $pip-spacing: ($height - $pip-size) / 2;
}

.Pip {
color: var(--p-component-badge-pip-color);
height: $pip-size;
width: $pip-size;
margin: 0 spacing(extra-tight) 0 ($pip-spacing - $horizontal-padding);
Expand All @@ -85,50 +80,42 @@ $pip-spacing: ($height - $pip-size) / 2;
flex-shrink: 0;
}

.progressIncomplete {
.Pip {
background: transparent;
}
.progressIncomplete .Pip {
background: transparent;
}

.progressPartiallyComplete {
.Pip {
background: linear-gradient(
to top,
currentColor,
currentColor 50%,
transparent 50%,
transparent
);

@media print {
position: relative;
overflow: hidden;

&::before {
content: '';
position: absolute;
width: 100%;
height: 50%;
transform: translateY(100%);
box-shadow: 0 0 0 $pip-size currentColor inset;
}
}
.progressPartiallyComplete .Pip {
background: linear-gradient(
to top,
currentColor,
currentColor 50%,
transparent 50%,
transparent
);

// Background colors may be stripped when printing, but box-shadow is not.
// We don't want to use box-shadow as the screen style as it gives a very
// slight halo effect
@media print {
background: none;
// 100px is an arbitrarily large number so that you can't see the curvature
// of the box shadow. y-offset is 3px larger than the spread to make it look
// like it is half-way down the pip (which is 6px tall)
box-shadow: 0 -103px 0 -100px currentColor inset;
}
}

.progressComplete {
.Pip {
background: linear-gradient(
to top,
currentColor,
currentColor 50%,
currentColor 50%
);

@media print {
box-shadow: 0 0 0 $pip-size currentColor inset;
}
.progressComplete .Pip {
background: currentColor;

// Background colors may be stripped when printing, but box-shadow is not.
// We don't want to use box-shadow as the screen style as it gives a very
// slight halo effect
@media print {
background: none;
// 100px is an arbitrarily large number so that you can't see the curvature
// of the box shadow.
box-shadow: 0 0 0 100px currentColor inset;
}
}

Expand Down