28 lines
574 B
TypeScript
28 lines
574 B
TypeScript
import { writable } from 'svelte/store';
|
|
|
|
const KEY = 'sidebarCollapsed';
|
|
|
|
function createSidebarCollapsed() {
|
|
const initial = typeof localStorage !== 'undefined'
|
|
? localStorage.getItem(KEY) === 'true'
|
|
: false;
|
|
const { subscribe, set, update } = writable(initial);
|
|
|
|
return {
|
|
subscribe,
|
|
toggle() {
|
|
update(v => {
|
|
const next = !v;
|
|
localStorage.setItem(KEY, String(next));
|
|
return next;
|
|
});
|
|
},
|
|
set(value: boolean) {
|
|
localStorage.setItem(KEY, String(value));
|
|
set(value);
|
|
},
|
|
};
|
|
}
|
|
|
|
export const sidebarCollapsed = createSidebarCollapsed();
|