fix(segment): set colors in the parent segment and remove the unused color property (#16590)

* style(theming): clean up sass TODOs

* fix(item): use proper padding on small buttons in an item

* refactor(components): remove color from unused components

* chore(components): update build files to remove color

* fix(tab-bar): remove unused layout prop

* test(segment): add custom test and update standalone

* docs(segment): update usage examples to remove layout

* test(segment): update tests to remove layout

* test(tab-bar): update tests to remove layout

* fix(segment): set the colors in the parent segment

but use them in the child segment button

This allows the user to customize all of the segment buttons from segment, while still allowing the `color` property to take precedence, and they can also edit the segment button colors directly if desired.

This actually fixes some bugs surrounding colors and allows customization for a segment inside of a toolbar.

references #14853

* style(sass): fix lint errors

* chore(build): build files

* fix(segment-button): use transparent background

* docs(segment-button): add color activated back

* why does the build hate me

* fix(segment): set initial css variables to avoid inheriting

* fix(segment): set initial color activated

also add new line to the nav readme because reasons

* test(segment): parent mode should match children
This commit is contained in:
Brandy Carney
2018-12-05 18:12:14 -05:00
committed by Manu MA
parent 68e26192a5
commit 8029df344a
36 changed files with 432 additions and 222 deletions

View File

@ -4,6 +4,19 @@
// iOS Segment
// --------------------------------------------------
:host {
--background: #{$segment-button-ios-background-color};
--background-hover: #{$segment-button-ios-background-color-hover};
--background-activated: #{$segment-button-ios-background-color-activated};
--background-checked: #{$segment-button-ios-background-color-checked};
--color: #{$segment-button-ios-text-color};
--color-checked: #{$segment-button-ios-text-color-checked};
--color-disabled: #{ion-color(primary, base, $segment-button-ios-opacity-disabled)};
--color-checked-disabled: #{ion-color(primary, contrast, $segment-button-ios-opacity-disabled)};
--border-color: #{$segment-button-ios-border-color};
--indicator-color: transparent;
}
:host(.segment-disabled) {
opacity: $segment-ios-opacity-disabled;
}
@ -16,6 +29,7 @@
--border-color: #{current-color(base)};
--background-hover: #{current-color(base, .04)};
background: transparent;
color: #{current-color(base)};
}
@ -51,10 +65,11 @@
}
:host-context(ion-toolbar):not(.ion-color)::slotted(ion-segment-button) {
--background-checked: var(--color);
--border-color: var(--color);
--color: #{var(--ion-toolbar-color-unchecked, $segment-button-ios-text-color)};
--color-checked: #{var(--ion-toolbar-color-checked, $segment-button-ios-text-color-checked)};
color: #{var(--ion-toolbar-color-unchecked, var(--color))};
}
:host-context(ion-toolbar):not(.ion-color)::slotted(.segment-button-checked) {
color: #{var(--ion-toolbar-color-checked, var(--color-checked))};
}
// Segment: Color Toolbar

View File

@ -4,6 +4,17 @@
// Material Design Segment
// --------------------------------------------------
:host {
--background: #{$segment-button-md-background};
--background-checked: #{$segment-button-md-background-checked};
--background-hover: #{$segment-button-md-background-hover};
--background-activated: #{$segment-button-md-background-activated};
--color: #{$segment-button-md-text-color};
--color-checked: #{$segment-button-md-text-color-checked};
--color-checked-disabled: var(--color-checked);
--indicator-color: transparent;
}
:host(.segment-disabled) {
opacity: $segment-md-opacity-disabled;
}
@ -15,6 +26,9 @@
--background-hover: #{current-color(base, .04)};
--background-activated: #{current-color(base, .16)};
--ripple-color: #{current-color(base)};
background: transparent;
color: $segment-button-md-text-color;
}
:host(.ion-color)::slotted(.segment-button-checked) {
@ -31,8 +45,11 @@
// --------------------------------------------------
:host-context(ion-toolbar):not(.ion-color)::slotted(ion-segment-button) {
--color: #{var(--ion-toolbar-color-unchecked, $segment-button-md-text-color)};
--color-checked: #{var(--ion-toolbar-color-checked, $segment-button-md-text-color-checked)};
color: #{var(--ion-toolbar-color-unchecked, var(--color))};
}
:host-context(ion-toolbar):not(.ion-color)::slotted(.segment-button-checked) {
color: #{var(--ion-toolbar-color-checked, var(--color-checked))};
}

View File

@ -4,6 +4,10 @@
// --------------------------------------------------
:host {
--indicator-color-checked: initial;
--ripple-color: initial;
--color-activated: initial;
@include font-smoothing();
display: flex;

View File

@ -0,0 +1,12 @@
import { newE2EPage } from '@stencil/core/testing';
test('segment: custom', async () => {
const page = await newE2EPage({
url: '/src/components/segment/test/custom?ionic:_testing=true'
});
await page.waitFor(250);
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -0,0 +1,261 @@
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="UTF-8">
<title>Segment - Custom</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet">
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
<script src="../../../../../dist/ionic.js"></script>
</head>
<body>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-segment value="Free">
<ion-segment-button value="Paid">
<ion-label>Paid</ion-label>
</ion-segment-button>
<ion-segment-button value="Free">
<ion-label>Free</ion-label>
</ion-segment-button>
<ion-segment-button value="Top">
<ion-label>Top</ion-label>
</ion-segment-button>
</ion-segment>
</ion-toolbar>
<ion-toolbar>
<ion-segment class="custom-icon" value="instagram">
<ion-segment-button class="segment-facebook" value="facebook">
<ion-label>Facebook</ion-label>
<ion-icon name="logo-facebook"></ion-icon>
</ion-segment-button>
<ion-segment-button class="segment-instagram" value="instagram">
<ion-label>Instagram</ion-label>
<ion-icon name="logo-instagram"></ion-icon>
</ion-segment-button>
<ion-segment-button class="segment-slack" value="slack">
<ion-label>Slack</ion-label>
<ion-icon name="logo-slack"></ion-icon>
</ion-segment-button>
</ion-segment>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-segment class="custom" value="active">
<ion-segment-button value="active">
<ion-label>Active</ion-label>
</ion-segment-button>
<ion-segment-button value="disabled" disabled="true">
<ion-label>Disabled</ion-label>
</ion-segment-button>
<ion-segment-button value="inactive" disabled="false">
<ion-label>Inactive</ion-label>
</ion-segment-button>
</ion-segment>
<ion-segment class="custom-icon" value="instagram">
<ion-segment-button class="segment-facebook" value="facebook">
<ion-label>Facebook</ion-label>
<ion-icon name="logo-facebook"></ion-icon>
</ion-segment-button>
<ion-segment-button class="segment-instagram" value="instagram">
<ion-label>Instagram</ion-label>
<ion-icon name="logo-instagram"></ion-icon>
</ion-segment-button>
<ion-segment-button class="segment-slack" value="slack">
<ion-label>Slack</ion-label>
<ion-icon name="logo-slack"></ion-icon>
</ion-segment-button>
</ion-segment>
<ion-segment class="custom-color" color="danger" value="dining">
<ion-segment-button value="dining">
<ion-label>Dining</ion-label>
<ion-icon name="cafe"></ion-icon>
</ion-segment-button>
<ion-segment-button value="travel">
<ion-label>Travel</ion-label>
<ion-icon name="airplane"></ion-icon>
</ion-segment-button>
<ion-segment-button value="entertainment">
<ion-label>Entertainment</ion-label>
<ion-icon name="radio"></ion-icon>
</ion-segment-button>
</ion-segment>
<h2>Activated</h2>
<ion-segment>
<ion-segment-button class="activated" value="Paid">
<ion-label>Paid</ion-label>
</ion-segment-button>
<ion-segment-button class="activated" value="Free">
<ion-label>Free</ion-label>
</ion-segment-button>
<ion-segment-button class="activated" value="Top">
<ion-label>Top</ion-label>
</ion-segment-button>
</ion-segment>
<ion-segment class="custom-icon">
<ion-segment-button class="activated segment-facebook" value="facebook">
<ion-label>Facebook</ion-label>
<ion-icon name="logo-facebook"></ion-icon>
</ion-segment-button>
<ion-segment-button class="activated segment-instagram" value="instagram">
<ion-label>Instagram</ion-label>
<ion-icon name="logo-instagram"></ion-icon>
</ion-segment-button>
<ion-segment-button class="activated segment-slack" value="slack">
<ion-label>Slack</ion-label>
<ion-icon name="logo-slack"></ion-icon>
</ion-segment-button>
</ion-segment>
</ion-content>
</ion-app>
</body>
<script>
var segment = document.getElementById('browserSegment');
var results = document.getElementById('browserResults');
checkUrl();
segment.addEventListener('ionChange', function () {
checkUrl();
});
function checkUrl() {
var url = window.location.href;
if (url.search('#bookmarks') > -1) {
setResults('bookmarks');
} else if (url.search('#reading') > -1) {
setResults('reading');
} else if (url.search('#links') > -1) {
setResults('links');
}
}
function setResults(value) {
results.innerHTML = value.charAt(0).toUpperCase() + value.slice(1);
segment.value = value;
}
</script>
<style>
body {
margin: 0;
}
ion-segment {
margin-bottom: 10px;
}
ion-toolbar ion-segment {
margin-bottom: 0;
}
pre {
border: 1px solid #e6e9ee;
background: white;
margin: 10px;
padding: 4px;
line-height: 24px;
}
code {
display: block;
padding: 0.5em;
background: #ffffff;
word-wrap: normal;
white-space: pre;
color: #314361;
}
.custom {
--background: papayawhip;
--background-checked: navy;
--border-color: navy;
--border-color-checked: navy;
--border-color-disabled: navy;
--color: navy;
--color-activated: purple;
--color-checked: papayawhip;
--color-disabled: rgba(0, 0, 0, 0.3);
}
/* Custom Icon Segment MD */
.md .custom-icon {
--indicator-color: lightgray;
}
.md .segment-facebook {
--background-hover: rgba(59, 89, 153, .04);
--color-activated: #3b5999;
--color-checked: #3b5999;
}
.md .segment-instagram {
--background-hover: rgba(228, 64, 95, .04);
--color-activated: #e4405f;
--color-checked: #e4405f;
}
.md .segment-slack {
--background-hover: rgba(58, 175, 133, .04);
--color-activated: #3aaf85;
--color-checked: #3aaf85;
}
/* Custom Icon Segment iOS */
.ios .custom-icon ion-segment-button {
--border-width: 0;
}
.ios .segment-facebook {
--color: #3b5999;
--color-checked: #ffffff;
--background-hover: rgba(59, 89, 153, .1);
--background-activated: rgba(59, 89, 153, .16);
--background-checked: #3b5999;
}
.ios .segment-instagram {
--color: #e4405f;
--color-checked: #ffffff;
--background-hover: rgba(228, 64, 95, .1);
--background-activated: rgba(228, 64, 95, .16);
--background-checked: #e4405f;
}
.ios .segment-slack {
--color: #3aaf85;
--color-checked: #ffffff;
--background-hover: rgba(58, 175, 133, .1);
--background-activated: rgba(58, 175, 133, .16);
--background-checked: #3aaf85;
}
.custom-icon ion-icon {
font-size: 44px;
}
/* This CSS should not apply */
.custom-color {
--background: purple;
--color: blue;
}
</style>
</html>

View File

@ -21,7 +21,7 @@
<ion-content>
<h2>Mode: ios</h2>
<ion-segment id="modeSegment" name="iosMode" value="kittens">
<ion-segment mode="ios" id="modeSegment" name="iosMode" value="kittens">
<ion-segment-button mode="ios" value="puppies">
<ion-label>Puppies</ion-label>
</ion-segment-button>
@ -36,7 +36,7 @@
<hr>
<h2>Mode: md</h2>
<ion-segment name="mdMode" value="kittens">
<ion-segment mode="md" name="mdMode" value="kittens">
<ion-segment-button mode="md" value="puppies">
<ion-label>Puppies</ion-label>
</ion-segment-button>

View File

@ -72,15 +72,15 @@
<!-- Icon top -->
<ion-segment>
<ion-segment-button layout="icon-top">
<ion-segment-button>
<ion-label>Item One</ion-label>
<ion-icon name="call"></ion-icon>
</ion-segment-button>
<ion-segment-button checked layout="icon-top">
<ion-segment-button checked>
<ion-label>Item Two</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-segment-button>
<ion-segment-button layout="icon-top">
<ion-segment-button>
<ion-label>Item Three</ion-label>
<ion-icon name="pin"></ion-icon>
</ion-segment-button>

View File

@ -53,7 +53,7 @@
<ion-segment color="secondary" value="active">
<ion-segment-button value="active">
<ion-label>Active</ion-label>
<ion-label>Active</ion-label>
</ion-segment-button>
<ion-segment-button value="disabled" disabled="true">
<ion-label>Disabled</ion-label>
@ -76,20 +76,19 @@
</ion-segment>
<ion-segment class="custom-icon" value="instagram">
<ion-segment-button layout="icon-top" class="segment-facebook" value="facebook">
<ion-segment-button class="segment-facebook" value="facebook">
<ion-label>Facebook</ion-label>
<ion-icon name="logo-facebook"></ion-icon>
</ion-segment-button>
<ion-segment-button layout="icon-top" class="segment-instagram" value="instagram">
<ion-segment-button class="segment-instagram" value="instagram">
<ion-label>Instagram</ion-label>
<ion-icon name="logo-instagram"></ion-icon>
</ion-segment-button>
<ion-segment-button layout="icon-top" class="segment-slack" value="slack">
<ion-segment-button class="segment-slack" value="slack">
<ion-label>Slack</ion-label>
<ion-icon name="logo-slack"></ion-icon>
</ion-segment-button>
</ion-segment>
</body>
<script>
@ -98,7 +97,7 @@
checkUrl();
segment.addEventListener('ionChange', function() {
segment.addEventListener('ionChange', function () {
checkUrl();
});
@ -157,10 +156,14 @@
--border-color-disabled: navy;
--border-color: navy;
--color-checked: papayawhip;
--color-disabled: rgba(0,0,0,0.3);
--color-disabled: rgba(0, 0, 0, 0.3);
--color: navy;
}
.custom-icon {
--indicator-color: lightgray;
}
.segment-facebook {
--background-hover: rgba(59, 89, 153, .04);
--color-checked: #3b5999;
@ -179,5 +182,7 @@
.custom-icon ion-icon {
font-size: 44px;
}
</style>
</html>

View File

@ -146,15 +146,15 @@
<!-- Icon top -->
<ion-toolbar color="danger">
<ion-segment>
<ion-segment-button layout="icon-top">
<ion-segment-button>
<ion-label>Item One</ion-label>
<ion-icon name="call"></ion-icon>
</ion-segment-button>
<ion-segment-button checked layout="icon-top">
<ion-segment-button checked>
<ion-label>Item Two</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-segment-button>
<ion-segment-button layout="icon-top">
<ion-segment-button>
<ion-label>Item Three</ion-label>
<ion-icon name="pin"></ion-icon>
</ion-segment-button>