mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-05 07:52:07 +08:00
24 lines
553 B
TypeScript
24 lines
553 B
TypeScript
import { type Ref } from "vue";
|
|
|
|
import { useUserLocalStorage } from "./userLocalStorage";
|
|
|
|
interface ToggleStateInterface {
|
|
toggled: Ref<boolean>;
|
|
toggle: () => void;
|
|
}
|
|
|
|
export function usePersistentToggle(uniqueId: string): ToggleStateInterface {
|
|
const localStorageKey = `toggle-state-${uniqueId}`;
|
|
const toggled = useUserLocalStorage(localStorageKey, false);
|
|
|
|
// Expose a function for toggling state
|
|
const toggle = () => {
|
|
toggled.value = !toggled.value;
|
|
};
|
|
|
|
return {
|
|
toggled,
|
|
toggle,
|
|
};
|
|
}
|