kopia lustrzana https://github.com/shoelace-style/shoelace
136 wiersze
4.0 KiB
TypeScript
136 wiersze
4.0 KiB
TypeScript
import { css } from 'lit';
|
|
import { focusVisibleSelector } from '~/internal/focus-visible';
|
|
import componentStyles from '~/styles/component.styles';
|
|
|
|
export default css`
|
|
${componentStyles}
|
|
|
|
:host {
|
|
--height: var(--sl-toggle-size);
|
|
--thumb-size: calc(var(--sl-toggle-size) + 4px);
|
|
--width: calc(var(--height) * 2);
|
|
|
|
display: inline-block;
|
|
}
|
|
|
|
.switch {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
font-family: var(--sl-input-font-family);
|
|
font-size: var(--sl-input-font-size-medium);
|
|
font-weight: var(--sl-input-font-weight);
|
|
color: var(--sl-input-color);
|
|
vertical-align: middle;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.switch__control {
|
|
flex: 0 0 auto;
|
|
position: relative;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: var(--width);
|
|
height: var(--height);
|
|
background-color: var(--sl-color-neutral-400);
|
|
border: solid var(--sl-input-border-width) var(--sl-color-neutral-400);
|
|
border-radius: var(--height);
|
|
transition: var(--sl-transition-fast) border-color, var(--sl-transition-fast) background-color;
|
|
}
|
|
|
|
.switch__control .switch__thumb {
|
|
width: var(--thumb-size);
|
|
height: var(--thumb-size);
|
|
background-color: var(--sl-color-neutral-0);
|
|
border-radius: 50%;
|
|
border: solid var(--sl-input-border-width) var(--sl-color-neutral-400);
|
|
transform: translateX(calc((var(--width) - var(--height)) / -2));
|
|
transition: var(--sl-transition-fast) transform ease, var(--sl-transition-fast) background-color,
|
|
var(--sl-transition-fast) border-color, var(--sl-transition-fast) box-shadow;
|
|
}
|
|
|
|
.switch__input {
|
|
position: absolute;
|
|
opacity: 0;
|
|
padding: 0;
|
|
margin: 0;
|
|
pointer-events: none;
|
|
}
|
|
|
|
/* Hover */
|
|
.switch:not(.switch--checked):not(.switch--disabled) .switch__control:hover {
|
|
background-color: var(--sl-color-neutral-400);
|
|
border-color: var(--sl-color-neutral-400);
|
|
}
|
|
|
|
.switch:not(.switch--checked):not(.switch--disabled) .switch__control:hover .switch__thumb {
|
|
background-color: var(--sl-color-neutral-0);
|
|
border-color: var(--sl-color-neutral-400);
|
|
}
|
|
|
|
/* Focus */
|
|
.switch:not(.switch--checked):not(.switch--disabled) .switch__input${focusVisibleSelector} ~ .switch__control {
|
|
background-color: var(--sl-color-neutral-400);
|
|
border-color: var(--sl-color-neutral-400);
|
|
}
|
|
|
|
.switch:not(.switch--checked):not(.switch--disabled)
|
|
.switch__input${focusVisibleSelector}
|
|
~ .switch__control
|
|
.switch__thumb {
|
|
background-color: var(--sl-color-neutral-0);
|
|
border-color: var(--sl-color-primary-600);
|
|
box-shadow: var(--sl-focus-ring);
|
|
}
|
|
|
|
/* Checked */
|
|
.switch--checked .switch__control {
|
|
background-color: var(--sl-color-primary-600);
|
|
border-color: var(--sl-color-primary-600);
|
|
}
|
|
|
|
.switch--checked .switch__control .switch__thumb {
|
|
background-color: var(--sl-color-neutral-0);
|
|
border-color: var(--sl-color-primary-600);
|
|
transform: translateX(calc((var(--width) - var(--height)) / 2));
|
|
}
|
|
|
|
/* Checked + hover */
|
|
.switch.switch--checked:not(.switch--disabled) .switch__control:hover {
|
|
background-color: var(--sl-color-primary-600);
|
|
border-color: var(--sl-color-primary-600);
|
|
}
|
|
|
|
.switch.switch--checked:not(.switch--disabled) .switch__control:hover .switch__thumb {
|
|
background-color: var(--sl-color-neutral-0);
|
|
border-color: var(--sl-color-primary-600);
|
|
}
|
|
|
|
/* Checked + focus */
|
|
.switch.switch--checked:not(.switch--disabled) .switch__input${focusVisibleSelector} ~ .switch__control {
|
|
background-color: var(--sl-color-primary-600);
|
|
border-color: var(--sl-color-primary-600);
|
|
}
|
|
|
|
.switch.switch--checked:not(.switch--disabled)
|
|
.switch__input${focusVisibleSelector}
|
|
~ .switch__control
|
|
.switch__thumb {
|
|
background-color: var(--sl-color-neutral-0);
|
|
border-color: var(--sl-color-primary-600);
|
|
box-shadow: var(--sl-focus-ring);
|
|
}
|
|
|
|
/* Disabled */
|
|
.switch--disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.switch__label {
|
|
line-height: var(--height);
|
|
margin-left: 0.5em;
|
|
user-select: none;
|
|
}
|
|
`;
|