Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/components/toggle/toggle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<slot {checked} />
</label>

<style lang="scss">
<style>
:global(:root) {
--leo-direction: 1;
}
Expand All @@ -108,9 +108,6 @@
--foreground-color: black;
--duration: var(--leo-toggle-transition-duration, 0.12s);
@media (prefers-reduced-motion) {
--duration: 0;
}
--icon-size: var(--leo-icon-size, 20px);
--width: var(--leo-toggle-width, 52px);
Expand Down Expand Up @@ -138,10 +135,6 @@
--icon-size: var(--leo-icon-size, 12px);
}
@theme (dark) {
--foreground-color: white;
}
display: flex;
align-items: center;
flex-direction: var(--label-flex-direction);
Expand All @@ -150,6 +143,18 @@
-webkit-tap-highlight-color: transparent;
}
@media (prefers-reduced-motion) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: modern CSS doesn't support nesting media queries so we have to unnest them

.leo-toggle {
--duration: 0;
}
}
@theme (dark) {
.leo-toggle {
--foreground-color: white;
}
}
.leo-toggle button {
--leo-icon-size: var(--icon-size);
Expand All @@ -159,13 +164,15 @@
height: calc(var(--height) - 2 * var(--padding));
border-radius: var(--leo-radius-full);
padding: var(--padding);
transition: background-color var(--duration) ease-in-out, box-shadow var(--duration) ease-in-out;
transition:
background-color var(--duration) ease-in-out,
box-shadow var(--duration) ease-in-out;
flex-shrink: 0;
&:disabled {
opacity: 0.5;
> .thumb {
& > .thumb {
background: var(--thumb-disabled-color);
}
}
Expand All @@ -188,7 +195,7 @@
);
}
&[aria-checked="false"] .thumb {
&[aria-checked='false'] .thumb {
--thumb-color: var(--leo-color-white);
}
Expand All @@ -204,7 +211,8 @@
calc(var(--thumb-offset) + var(--drag-offset))
),
var(--unchecked-thumb-offset)
) * var(--leo-direction)
) *
var(--leo-direction)
);
height: 100%;
Expand All @@ -228,7 +236,7 @@
align-items: center;
justify-content: center;
.on-icon {
& .on-icon {
transition: opacity var(--duration) ease-in-out;
display: flex;
opacity: 0;
Expand All @@ -238,12 +246,12 @@
&[aria-checked='true'] {
background: var(--checked-color);
.thumb {
& .thumb {
--thumb-offset: var(--checked-thumb-offset);
color: var(--checked-color);
--thumb-disabled-color: var(--thumb-color);
color: var(--checked-color);
.on-icon {
& .on-icon {
opacity: 1;
}
}
Expand Down