UNPKG

@ionic/core

Version:

Base components for Ionic

237 lines (215 loc) • 6.09 kB
:host { /** * @prop --background: Background of the toggle * @prop --background-checked: Background of the toggle when checked * @prop --border-radius: Border radius of the toggle track * * @prop --handle-background: Background of the toggle handle * @prop --handle-background-checked: Background of the toggle handle when checked * * @prop --handle-border-radius: Border radius of the toggle handle * @prop --handle-box-shadow: Box shadow of the toggle handle * @prop --handle-height: Height of the toggle handle * @prop --handle-max-height: Maximum height of the toggle handle * @prop --handle-width: Width of the toggle handle * @prop --handle-spacing: Horizontal spacing around the toggle handle * @prop --handle-transition: Transition of the toggle handle */ /* stylelint-disable-next-line declaration-no-important */ box-sizing: content-box !important; display: inline-block; position: relative; outline: none; contain: content; cursor: pointer; touch-action: none; user-select: none; z-index: 2; } :host(.ion-focused) input { border: 2px solid #5e9ed6; } :host(.toggle-disabled) { pointer-events: none; } label { left: 0; top: 0; margin-left: 0; margin-right: 0; margin-top: 0; margin-bottom: 0; position: absolute; width: 100%; height: 100%; border: 0; background: transparent; cursor: pointer; appearance: none; outline: none; display: flex; align-items: center; opacity: 0; pointer-events: none; } [dir=rtl] label, :host-context([dir=rtl]) label { left: unset; right: unset; right: 0; } label::-moz-focus-inner { border: 0; } input { position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; outline: 0; clip: rect(0 0 0 0); opacity: 0; overflow: hidden; -webkit-appearance: none; -moz-appearance: none; } .toggle-icon-wrapper { display: flex; position: relative; align-items: center; width: 100%; height: 100%; transition: var(--handle-transition); will-change: transform; } .toggle-icon { border-radius: var(--border-radius); display: block; position: relative; width: 100%; height: 100%; background: var(--background); pointer-events: none; overflow: inherit; } :host(.toggle-checked) .toggle-icon { background: var(--background-checked); } .toggle-inner { left: var(--handle-spacing); border-radius: var(--handle-border-radius); position: absolute; width: var(--handle-width); height: var(--handle-height); max-height: var(--handle-max-height); transition: var(--handle-transition); background: var(--handle-background); box-shadow: var(--handle-box-shadow); contain: strict; } [dir=rtl] .toggle-inner, :host-context([dir=rtl]) .toggle-inner { left: unset; right: unset; right: var(--handle-spacing); } :host(.toggle-checked) .toggle-icon-wrapper { transform: translate3d(calc(100% - var(--handle-width)), 0, 0); } :host-context([dir=rtl]):host(.toggle-checked) .toggle-icon-wrapper, :host-context([dir=rtl]).toggle-checked .toggle-icon-wrapper { transform: translate3d(calc(-100% + var(--handle-width)), 0, 0); } :host(.toggle-checked) .toggle-inner { transform: translate3d(calc(var(--handle-spacing) * -2), 0, 0); background: var(--handle-background-checked); } :host-context([dir=rtl]):host(.toggle-checked) .toggle-inner, :host-context([dir=rtl]).toggle-checked .toggle-inner { transform: translate3d(calc(var(--handle-spacing) * 2), 0, 0); } :host { --background: rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.088); --background-checked: var(--ion-color-primary, #3880ff); --border-radius: 16px; --handle-background: #ffffff; --handle-background-checked: #ffffff; --handle-border-radius: 25.5px; --handle-box-shadow: 0 3px 12px rgba(0, 0, 0, 0.16), 0 3px 1px rgba(0, 0, 0, 0.1); --handle-height: calc(32px - (2px * 2)); --handle-max-height: calc(100% - (var(--handle-spacing) * 2)); --handle-width: calc(32px - (2px * 2)); --handle-spacing: 2px; --handle-transition: transform 300ms, width 120ms ease-in-out 80ms, left 110ms ease-in-out 80ms, right 110ms ease-in-out 80ms; width: 51px; height: 32px; contain: strict; overflow: hidden; } :host(.ion-color.toggle-checked) .toggle-icon { background: var(--ion-color-base); } .toggle-icon { transform: translate3d(0, 0, 0); transition: background-color 300ms; } .toggle-inner { will-change: transform; } :host(.toggle-activated) .toggle-icon::before, :host(.toggle-checked) .toggle-icon::before { transform: scale3d(0, 0, 0); } :host(.toggle-activated.toggle-checked) .toggle-inner::before { transform: scale3d(0, 0, 0); } :host(.toggle-activated) .toggle-inner { width: calc(var(--handle-width) + 6px); } :host(.toggle-activated.toggle-checked) .toggle-icon-wrapper { transform: translate3d(calc(100% - var(--handle-width) - 6px), 0, 0); } :host-context([dir=rtl]):host(.toggle-activated.toggle-checked) .toggle-icon-wrapper, :host-context([dir=rtl]).toggle-activated.toggle-checked .toggle-icon-wrapper { transform: translate3d(calc(-100% + var(--handle-width) + 6px), 0, 0); } :host(.toggle-disabled) { opacity: 0.3; } :host(.in-item[slot]) { margin-left: 0; margin-right: 0; margin-top: 0; margin-bottom: 0; padding-left: 20px; padding-right: 10px; padding-top: 6px; padding-bottom: 5px; } @supports (margin-inline-start: 0) or (-webkit-margin-start: 0) { :host(.in-item[slot]) { padding-left: unset; padding-right: unset; -webkit-padding-start: 20px; padding-inline-start: 20px; -webkit-padding-end: 10px; padding-inline-end: 10px; } } :host(.in-item[slot=start]) { padding-left: 0; padding-right: 16px; padding-top: 6px; padding-bottom: 5px; } @supports (margin-inline-start: 0) or (-webkit-margin-start: 0) { :host(.in-item[slot=start]) { padding-left: unset; padding-right: unset; -webkit-padding-start: 0; padding-inline-start: 0; -webkit-padding-end: 16px; padding-inline-end: 16px; } }