feat(components): improve button states and add new css properties (#19440)

Before users had to know the exact opacity that the MD/iOS spec called for in order to change the hover or focused background color. This allows them to change the background without having to know the opacity. 

- changes apply to Action Sheet (Buttons), Back Button, Button, FAB Button, Item, Menu Button, Segment Button, Tab Button
- greatly reduces the requirement by users to set the background hover, focused states for dark modes and custom themes, also eliminates the need to know what the hover opacity is for each based on the spec
- updates the MD dark theme per their spec
- adds a component guide for internal use changing Ionic components

references #18279 fixes #20213 fixes #19965

BREAKING CHANGE:

*Activated Class*

The `activated` class that is automatically added to buttons on press has been renamed to `ion-activated`. This will be more consistent with our `ion-focused` class we add and also will reduce conflicts with user's CSS.

*CSS Variables*

The `--background-hover`, `--background-focused` and `--background-activated` CSS variables on components that render native buttons will now have an opacity automatically set. If you are setting any of these like the following:

```
--background-hover: rgba(44, 44, 44, 0.08);
```

You will likely not see a hover state anymore. It should be updated to only set the desired color:

```
--background-hover: rgba(44, 44, 44);
```

If the opacity desired is something other than what the spec asks for, use:

```
--background-hover: rgba(44, 44, 44);
--background-hover-opacity: 1;
```
This commit is contained in:
Brandy Carney
2020-01-23 16:57:47 -05:00
committed by GitHub
parent 445f129e2d
commit 94159291b2
114 changed files with 3641 additions and 1487 deletions

View File

@ -175,17 +175,19 @@ export const TabButtonExample: React.FC = () => (
## CSS Custom Properties
| Name | Description |
| ---------------------- | ------------------------------------------------------------------------------------------------------------- |
| `--background` | Background of the tab button |
| `--background-focused` | Background of the tab button when focused with the tab key |
| `--color` | Color of the tab button |
| `--color-selected` | Color of the selected tab button |
| `--padding-bottom` | Bottom padding of the tab button |
| `--padding-end` | Right padding if direction is left-to-right, and left padding if direction is right-to-left of the tab button |
| `--padding-start` | Left padding if direction is left-to-right, and right padding if direction is right-to-left of the tab button |
| `--padding-top` | Top padding of the tab button |
| `--ripple-color` | Color of the button ripple effect |
| Name | Description |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------- |
| `--background` | Background of the tab button |
| `--background-focused` | Background of the tab button when focused with the tab key |
| `--background-focused-opacity` | Opacity of the tab button background when focused with the tab key |
| `--color` | Color of the tab button |
| `--color-focused` | Color of the tab button when focused with the tab key |
| `--color-selected` | Color of the selected tab button |
| `--padding-bottom` | Bottom padding of the tab button |
| `--padding-end` | Right padding if direction is left-to-right, and left padding if direction is right-to-left of the tab button |
| `--padding-start` | Left padding if direction is left-to-right, and right padding if direction is right-to-left of the tab button |
| `--padding-top` | Top padding of the tab button |
| `--ripple-color` | Color of the button ripple effect |
## Dependencies

View File

@ -22,13 +22,13 @@ $tab-button-ios-max-width: 240px !default;
$tab-button-ios-text-color: $tabbar-ios-color !default;
/// @prop - Text color of the active tab button
$tab-button-ios-text-color-active: $tabbar-ios-color-activated !default;
$tab-button-ios-text-color-active: $tabbar-ios-color-selected !default;
/// @prop - Icon color of the inactive tab button
$tab-button-ios-icon-color: $tabbar-ios-color !default;
/// @prop - Icon color of the active tab button
$tab-button-ios-icon-color-active: $tabbar-ios-color-activated !default;
$tab-button-ios-icon-color-active: $tabbar-ios-color-selected !default;
/// @prop - Font size of the tab button text
$tab-button-ios-font-size: 10px !default;

View File

@ -28,13 +28,13 @@ $tab-button-md-font-weight: normal !default;
$tab-button-md-text-color: $tabbar-md-color !default;
/// @prop - Text color of the active tab button
$tab-button-md-text-color-active: $tabbar-md-color-activated !default;
$tab-button-md-text-color-active: $tabbar-md-color-selected !default;
/// @prop - Icon color of the inactive tab button
$tab-button-md-icon-color: $tabbar-md-color !default;
/// @prop - Icon color of the active tab button
$tab-button-md-icon-color-active: $tabbar-md-color-activated !default;
$tab-button-md-icon-color-active: $tabbar-md-color-selected !default;
/// @prop - Margin top on the tab button icon
$tab-button-md-icon-margin-top: 16px !default;

View File

@ -4,8 +4,10 @@
/**
* @prop --background: Background of the tab button
* @prop --background-focused: Background of the tab button when focused with the tab key
* @prop --background-focused-opacity: Opacity of the tab button background when focused with the tab key
*
* @prop --color: Color of the tab button
* @prop --color-focused: Color of the tab button when focused with the tab key
* @prop --color-selected: Color of the selected tab button
*
* @prop --padding-top: Top padding of the tab button
@ -16,6 +18,7 @@
* @prop --ripple-color: Color of the button ripple effect
*/
--ripple-color: var(--color-selected);
--background-focused-opacity: 1;
flex: 1;
@ -34,7 +37,8 @@
// Tab Button: Native
// --------------------------------------------------
a {
.button-native {
@include border-radius(inherit);
@include margin(0);
@include padding(var(--padding-top), var(--padding-end), var(--padding-bottom), var(--padding-start));
@include text-inherit();
@ -63,8 +67,35 @@ a {
-webkit-user-drag: none;
}
:host(.ion-focused) {
background: var(--background-focused);
.button-native::after {
@include button-state();
}
.button-inner {
display: flex;
position: relative;
flex-flow: inherit;
align-items: inherit;
justify-content: inherit;
width: 100%;
height: 100%;
z-index: 1;
}
// Tab Button: States
// --------------------------------------------------
:host(.ion-focused) .button-native {
color: var(--color-focused);
&::after {
background: var(--background-focused);
opacity: var(--background-focused-opacity);
}
}
@media (any-hover: hover) {
@ -73,10 +104,6 @@ a {
}
}
// Tab Button: States
// --------------------------------------------------
:host(.tab-selected) {
color: var(--color-selected);
}

View File

@ -161,8 +161,10 @@ export class TabButton implements ComponentInterface, AnchorInterface {
'ion-focusable': true
}}
>
<a {...attrs} tabIndex={-1}>
<slot></slot>
<a {...attrs} tabIndex={-1} class="button-native">
<span class="button-inner">
<slot></slot>
</span>
{mode === 'md' && <ion-ripple-effect type="unbounded"></ion-ripple-effect>}
</a>
</Host>