mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 14:01:20 +08:00
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:
@ -7,13 +7,17 @@
|
||||
/**
|
||||
* @prop --background: Background of the segment button
|
||||
* @prop --background-checked: Background of the checked segment button
|
||||
* @prop --background-disabled: Background of the disabled segment button
|
||||
*
|
||||
* @prop --background-hover: Background of the segment button on hover
|
||||
* @prop --background-focused: Background of the segment button when focused with the tab key
|
||||
*
|
||||
* @prop --background-hover-opacity: Opacity of the segment button background on hover
|
||||
* @prop --background-focused-opacity: Opacity of the segment button background when focused with the tab key
|
||||
*
|
||||
* @prop --color: Color of the segment button
|
||||
* @prop --color-checked: Color of the checked segment button
|
||||
* @prop --color-disabled: Color of the disabled segment button
|
||||
* @prop --color-hover: Color of the segment button on hover
|
||||
* @prop --color-focused: Color of the segment button when focused with the tab key
|
||||
*
|
||||
* @prop --border-radius: Radius of the segment button border
|
||||
* @prop --border-color: Color of the segment button border
|
||||
@ -39,7 +43,7 @@
|
||||
* @prop --indicator-transform: Transform of the indicator for the checked segment button
|
||||
*/
|
||||
--color: initial;
|
||||
--color-hover: initial;
|
||||
--color-hover: var(--color);
|
||||
--color-checked: var(--color);
|
||||
--color-disabled: var(--color);
|
||||
--padding-start: 0;
|
||||
@ -105,9 +109,29 @@
|
||||
contain: content;
|
||||
cursor: pointer;
|
||||
|
||||
overflow: hidden;
|
||||
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.button-native::after {
|
||||
@include button-state();
|
||||
}
|
||||
|
||||
.button-inner {
|
||||
display: flex;
|
||||
position: relative;
|
||||
|
||||
flex-flow: inherit;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
|
||||
// Segment Button: Checked
|
||||
// --------------------------------------------------
|
||||
@ -122,22 +146,40 @@
|
||||
// --------------------------------------------------
|
||||
|
||||
:host(.segment-button-disabled) {
|
||||
background: var(--background-disabled);
|
||||
color: var(--color-disabled);
|
||||
cursor: default;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
|
||||
// Segment Button: Focused
|
||||
// --------------------------------------------------
|
||||
|
||||
:host(.ion-focused) .button-native {
|
||||
color: var(--color-focused);
|
||||
|
||||
&::after {
|
||||
background: var(--background-focused);
|
||||
|
||||
opacity: var(--background-focused-opacity);
|
||||
}
|
||||
}
|
||||
|
||||
// Segment Button: Hover
|
||||
// --------------------------------------------------
|
||||
|
||||
@media (any-hover: hover) {
|
||||
:host(:hover) {
|
||||
background: var(--background-hover);
|
||||
color: var(--color-hover, var(--color));
|
||||
:host(:hover) .button-native {
|
||||
color: var(--color-hover);
|
||||
|
||||
&::after {
|
||||
background: var(--background-hover);
|
||||
|
||||
opacity: var(--background-hover-opacity);
|
||||
}
|
||||
}
|
||||
|
||||
:host(.segment-button-checked:hover) {
|
||||
color: var(--color-hover, var(--color-checked));
|
||||
:host(.segment-button-checked:hover) .button-native {
|
||||
color: var(--color-checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user