change: sidebar:state save in localStorage
This commit is contained in:
parent
b7ef4653f7
commit
b2bd4ae3bb
|
|
@ -3,7 +3,7 @@ import { cn } from '@/lib/utils'
|
|||
import { useEventListener, useVModel } from '@vueuse/core'
|
||||
import { TooltipProvider } from 'radix-vue'
|
||||
import { computed, type HTMLAttributes, type Ref, ref } from 'vue'
|
||||
import { provideSidebarContext, SIDEBAR_COOKIE_MAX_AGE, SIDEBAR_COOKIE_NAME, SIDEBAR_KEYBOARD_SHORTCUT, SIDEBAR_WIDTH, SIDEBAR_WIDTH_ICON } from './utils'
|
||||
import { provideSidebarContext, SIDEBAR_STORAGE_KEY, SIDEBAR_KEYBOARD_SHORTCUT, SIDEBAR_WIDTH, SIDEBAR_WIDTH_ICON } from './utils'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
defaultOpen?: boolean
|
||||
|
|
@ -29,8 +29,8 @@ const open = useVModel(props, 'open', emits, {
|
|||
function setOpen(value: boolean) {
|
||||
open.value = value // emits('update:open', value)
|
||||
|
||||
// This sets the cookie to keep the sidebar state.
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${open.value}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
||||
// This sets the key in localStorage to keep the sidebar state.
|
||||
localStorage.setItem(SIDEBAR_STORAGE_KEY , JSON.stringify(open.value));
|
||||
}
|
||||
|
||||
function setOpenMobile(value: boolean) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import type { ComputedRef, Ref } from 'vue'
|
||||
import { createContext } from 'radix-vue'
|
||||
|
||||
export const SIDEBAR_COOKIE_NAME = 'sidebar:state'
|
||||
export const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
||||
export const SIDEBAR_STORAGE_KEY = 'sidebar:state'
|
||||
export const SIDEBAR_WIDTH = '16rem'
|
||||
export const SIDEBAR_WIDTH_MOBILE = '18rem'
|
||||
export const SIDEBAR_WIDTH_ICON = '3rem'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user