mirror of
https://github.com/zadam/trilium.git
synced 2025-12-12 18:34:24 +01:00
feat(widgets/toggle): disable transitions on first render
This commit is contained in:
parent
e0f7d65f77
commit
9f2ed2f9d4
@ -24,6 +24,14 @@
|
|||||||
border-radius: 24px;
|
border-radius: 24px;
|
||||||
background-color: var(--switch-off-track-background);
|
background-color: var(--switch-off-track-background);
|
||||||
transition: background 200ms ease-in;
|
transition: background 200ms ease-in;
|
||||||
|
|
||||||
|
&.disable-transitions {
|
||||||
|
transition: none !important;
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
transition: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.switch-widget .switch-button.on {
|
.switch-widget .switch-button.on {
|
||||||
@ -103,4 +111,4 @@ body[dir=rtl] .switch-widget .switch-button.on:after {
|
|||||||
|
|
||||||
.switch-widget .switch-help-button:hover {
|
.switch-widget .switch-help-button:hover {
|
||||||
color: var(--main-text-color);
|
color: var(--main-text-color);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
import clsx from "clsx";
|
||||||
import "./FormToggle.css";
|
import "./FormToggle.css";
|
||||||
import HelpButton from "./HelpButton";
|
import HelpButton from "./HelpButton";
|
||||||
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
interface FormToggleProps {
|
interface FormToggleProps {
|
||||||
currentValue: boolean | null;
|
currentValue: boolean | null;
|
||||||
@ -13,13 +15,22 @@ interface FormToggleProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function FormToggle({ currentValue, helpPage, switchOnName, switchOnTooltip, switchOffName, switchOffTooltip, onChange, disabled }: FormToggleProps) {
|
export default function FormToggle({ currentValue, helpPage, switchOnName, switchOnTooltip, switchOffName, switchOffTooltip, onChange, disabled }: FormToggleProps) {
|
||||||
|
const [ disableTransition, setDisableTransition ] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setDisableTransition(false);
|
||||||
|
}, 100);
|
||||||
|
return () => clearTimeout(timeout);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="switch-widget">
|
<div className="switch-widget">
|
||||||
<span className="switch-name">{ currentValue ? switchOffName : switchOnName }</span>
|
<span className="switch-name">{ currentValue ? switchOffName : switchOnName }</span>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<div
|
<div
|
||||||
className={`switch-button ${currentValue ? "on" : ""} ${disabled ? "disabled" : ""}`}
|
className={clsx("switch-button", { "on": currentValue, disabled, "disable-transitions": disableTransition })}
|
||||||
title={currentValue ? switchOffTooltip : switchOnTooltip }
|
title={currentValue ? switchOffTooltip : switchOnTooltip }
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user