mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
@ -123,6 +123,15 @@ Emitted when the toggle has focus.
|
|||||||
Emitted when the styles change.
|
Emitted when the styles change.
|
||||||
|
|
||||||
|
|
||||||
|
## CSS Custom Properties
|
||||||
|
|
||||||
|
| Name | Description |
|
||||||
|
| ----------------------------- | -------------------------------------------- |
|
||||||
|
| `--background` | Background of the toggle |
|
||||||
|
| `--background-checked` | Background of the toggle when checked |
|
||||||
|
| `--handle-background` | Background of the toggle handle |
|
||||||
|
| `--handle-background-checked` | Background of the toggle handle when checked |
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
|
@ -23,9 +23,17 @@
|
|||||||
<ion-toggle checked color="light"></ion-toggle>
|
<ion-toggle checked color="light"></ion-toggle>
|
||||||
<ion-toggle checked color="medium"></ion-toggle>
|
<ion-toggle checked color="medium"></ion-toggle>
|
||||||
<ion-toggle checked color="dark"></ion-toggle>
|
<ion-toggle checked color="dark"></ion-toggle>
|
||||||
|
<ion-toggle checked class="custom"></ion-toggle>
|
||||||
|
|
||||||
<!-- Disabled -->
|
<!-- Disabled -->
|
||||||
<ion-toggle checked disabled></ion-toggle>
|
<ion-toggle checked disabled></ion-toggle>
|
||||||
<ion-toggle checked disabled color="secondary"></ion-toggle>
|
<ion-toggle checked disabled color="secondary"></ion-toggle>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.custom {
|
||||||
|
--background-checked: papayawhip;
|
||||||
|
--handle-background-checked: purple;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
--checked-background: #{current-color(base)};
|
--background: #{$toggle-ios-background-color-off};
|
||||||
--checked-knob: #{current-color(base)};
|
--background-checked: #{ion-color(primary, base)};
|
||||||
|
--handle-background: #{$toggle-ios-handle-background-color};
|
||||||
|
--handle-background-checked: #{$toggle-ios-handle-background-color};
|
||||||
|
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
|
|
||||||
@ -18,6 +20,13 @@
|
|||||||
contain: strict;
|
contain: strict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host(.ion-color.toggle-checked) .toggle-icon {
|
||||||
|
background: current-color(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host(.ion-color.toggle-checked) .toggle-inner {
|
||||||
|
background: current-color(contrast);
|
||||||
|
}
|
||||||
|
|
||||||
// iOS Toggle Background Track: Unchecked
|
// iOS Toggle Background Track: Unchecked
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
@ -53,7 +62,7 @@
|
|||||||
|
|
||||||
transition: transform $toggle-ios-transition-duration;
|
transition: transform $toggle-ios-transition-duration;
|
||||||
|
|
||||||
background-color: $toggle-ios-background-color-off;
|
background: var(--background);
|
||||||
|
|
||||||
content: "";
|
content: "";
|
||||||
}
|
}
|
||||||
@ -73,7 +82,7 @@
|
|||||||
|
|
||||||
transition: transform $toggle-ios-transition-duration, width 120ms ease-in-out 80ms, left 110ms ease-in-out 80ms, right 110ms ease-in-out 80ms;
|
transition: transform $toggle-ios-transition-duration, width 120ms ease-in-out 80ms, left 110ms ease-in-out 80ms, right 110ms ease-in-out 80ms;
|
||||||
|
|
||||||
background-color: $toggle-ios-handle-background-color;
|
background: var(--handle-background);
|
||||||
|
|
||||||
box-shadow: $toggle-ios-handle-box-shadow;
|
box-shadow: $toggle-ios-handle-box-shadow;
|
||||||
will-change: transform;
|
will-change: transform;
|
||||||
@ -85,7 +94,7 @@
|
|||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
:host(.toggle-checked) .toggle-icon {
|
:host(.toggle-checked) .toggle-icon {
|
||||||
background-color: var(--checked-knob);
|
background: var(--background-checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +112,8 @@
|
|||||||
|
|
||||||
:host(.toggle-checked) .toggle-inner {
|
:host(.toggle-checked) .toggle-inner {
|
||||||
@include transform(translate3d($toggle-ios-width - $toggle-ios-handle-width - ($toggle-ios-border-width * 2), 0, 0));
|
@include transform(translate3d($toggle-ios-width - $toggle-ios-handle-width - ($toggle-ios-border-width * 2), 0, 0));
|
||||||
|
|
||||||
|
background: var(--handle-background-checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
--checked-background: #{current-color(base, $toggle-md-track-background-color-alpha-on)};
|
--background: #{$toggle-md-track-background-color-off};
|
||||||
--checked-knob: #{current-color(base)};
|
--background-checked: #{ion-color(primary, base, $toggle-md-track-background-color-alpha-on)};
|
||||||
|
--handle-background: #{$toggle-md-handle-background-color-off};
|
||||||
|
--handle-background-checked: #{ion-color(primary, base)};
|
||||||
|
|
||||||
@include padding($toggle-md-padding-top, $toggle-md-padding-end, $toggle-md-padding-bottom, $toggle-md-padding-start);
|
@include padding($toggle-md-padding-top, $toggle-md-padding-end, $toggle-md-padding-bottom, $toggle-md-padding-start);
|
||||||
|
|
||||||
@ -20,6 +22,13 @@
|
|||||||
contain: strict;
|
contain: strict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host(.ion-color.toggle-checked) .toggle-icon {
|
||||||
|
background: current-color(base, $toggle-md-track-background-color-alpha-on);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host(.ion-color.toggle-checked) .toggle-inner {
|
||||||
|
background: current-color(base);
|
||||||
|
}
|
||||||
|
|
||||||
// Material Design Toggle Background Track: Unchecked
|
// Material Design Toggle Background Track: Unchecked
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
@ -35,7 +44,7 @@
|
|||||||
|
|
||||||
transition: background-color $toggle-md-transition-duration;
|
transition: background-color $toggle-md-transition-duration;
|
||||||
|
|
||||||
background-color: $toggle-md-track-background-color-off;
|
background: var(--background);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +64,7 @@
|
|||||||
transition-duration: $toggle-md-transition-duration;
|
transition-duration: $toggle-md-transition-duration;
|
||||||
transition-property: transform, background-color;
|
transition-property: transform, background-color;
|
||||||
|
|
||||||
background-color: $toggle-md-handle-background-color-off;
|
background: var(--handle-background);
|
||||||
|
|
||||||
box-shadow: $toggle-md-handle-box-shadow;
|
box-shadow: $toggle-md-handle-box-shadow;
|
||||||
will-change: transform, background-color;
|
will-change: transform, background-color;
|
||||||
@ -67,7 +76,7 @@
|
|||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
:host(.toggle-checked) .toggle-icon {
|
:host(.toggle-checked) .toggle-icon {
|
||||||
background-color: var(--checked-background);
|
background: var(--background-checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Material Design Toggle Inner Knob: Checked
|
// Material Design Toggle Inner Knob: Checked
|
||||||
@ -76,7 +85,7 @@
|
|||||||
:host(.toggle-checked) .toggle-inner {
|
:host(.toggle-checked) .toggle-inner {
|
||||||
@include transform(translate3d($toggle-md-track-width - $toggle-md-handle-width, 0, 0));
|
@include transform(translate3d($toggle-md-track-width - $toggle-md-handle-width, 0, 0));
|
||||||
|
|
||||||
background-color: var(--checked-knob);
|
background: var(--handle-background-checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,8 +4,12 @@
|
|||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
--ion-color-base: #{ion-color(primary, base)};
|
/**
|
||||||
--ion-color-base-rgb: #{ion-color(primary, base, null, true)};
|
* @prop --background: Background of the toggle
|
||||||
|
* @prop --background-checked: Background of the toggle when checked
|
||||||
|
* @prop --handle-background: Background of the toggle handle
|
||||||
|
* @prop --handle-background-checked: Background of the toggle handle when checked
|
||||||
|
*/
|
||||||
|
|
||||||
// TODO can we remove important here
|
// TODO can we remove important here
|
||||||
/* stylelint-disable-next-line declaration-no-important */
|
/* stylelint-disable-next-line declaration-no-important */
|
||||||
|
@ -94,7 +94,7 @@ export class Toggle implements CheckboxInput {
|
|||||||
'interactive-disabled': this.disabled,
|
'interactive-disabled': this.disabled,
|
||||||
});
|
});
|
||||||
if (this.gesture) {
|
if (this.gesture) {
|
||||||
this.gesture.setDisabled(this.disabled);
|
this.gesture.disabled = this.disabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,11 +112,11 @@ export class Toggle implements CheckboxInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gesture = (await import('../../utils/gesture/gesture')).createGesture({
|
this.gesture = (await import('../../utils/gesture/gesture')).create({
|
||||||
el: this.el,
|
el: this.el,
|
||||||
queue: this.queue,
|
queue: this.queue,
|
||||||
gestureName: 'toggle',
|
gestureName: 'toggle',
|
||||||
gesturePriority: 100,
|
gesturePriority: 30,
|
||||||
threshold: 0,
|
threshold: 0,
|
||||||
onStart: this.onDragStart.bind(this),
|
onStart: this.onDragStart.bind(this),
|
||||||
onMove: this.onDragMove.bind(this),
|
onMove: this.onDragMove.bind(this),
|
||||||
|
Reference in New Issue
Block a user