Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
wip: grid-layout theme color
Browse files Browse the repository at this point in the history
  • Loading branch information
hormers committed Feb 10, 2023
1 parent ba84978 commit ba1ee76
Show file tree
Hide file tree
Showing 15 changed files with 361 additions and 81 deletions.
11 changes: 6 additions & 5 deletions packages/grid-layouts/src/components/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
useLayoutTab,
useLayoutContent,
} from '@vben/stores'
import {useAppConfig, useGridLayoutContainerElStyle, useTheme} from '@vben/hooks'
import { ref } from 'vue'
import {useAppConfig, createGridLayoutListen, createThemeColorListen} from '@vben/hooks'
import {nextTick, ref} from 'vue'
import { MaybeElementRef } from '@vben/utils'
const { headerRef } = storeToRefs(useLayoutHeader() as StoreGeneric)
Expand All @@ -22,9 +22,10 @@ const { contentRef } = storeToRefs(useLayoutContent() as StoreGeneric)
const containerRef = ref<MaybeElementRef>(null)
const { navBarMode } = useAppConfig()
useGridLayoutContainerElStyle(containerRef)
const {} = useTheme(true)
nextTick(()=>{
createGridLayoutListen(containerRef)
createThemeColorListen(containerRef)
})
</script>
<template>
<section
Expand Down
8 changes: 7 additions & 1 deletion packages/grid-layouts/src/components/Main.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<script lang="ts" setup>
import { useLayoutHeader } from '@vben/stores'
import { useAppConfig } from '@vben/hooks'
import {useAppConfig, useAppInject} from '@vben/hooks'
import { StoreGeneric, storeToRefs } from 'pinia'
const { headerWidth, headerHeight } = storeToRefs(
useLayoutHeader() as StoreGeneric,
)
const { sidebar } = useAppConfig()
const { isMobile } = useAppInject()
</script>
<template>
<main class="vben-grid-layout-main">
<div>headerWidth: {{ headerWidth }}, headerHeight: {{ headerHeight }}</div>
___________________________________________________________________________
<div>useAppConfig : {{ sidebar }}</div>
<div>isMobile: {{ isMobile }}</div>

<VbenButton>
大丰收的
</VbenButton>
<!-- <RouterView />-->
</main>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<template>
<!-- 2424 -->
<div
class="h-full p-x-12px grid-center cursor-pointer hover:bg-[#f6f6f6] transition-colors-300"
class="h-full p-x-12px grid-center cursor-pointer hover:bg-[var(--header-action-hover-bg-color)] transition-colors-300"
>
<slot></slot>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const showHeaderLogo = computed(() => {
</script>
<template>
<header
class="grid-area-[grid-header] grid grid-cols-2 content-center overflow-hidden relative"
class="grid-area-[grid-header] grid grid-cols-2 content-center
overflow-hidden relative bg-[var(--header-background-color)]
color-[var(--header-text-color)] transition-colors-300"
:class="[header.visible ? 'visible' : 'invisible']"
>
<div class="h-[var(--header-height)] grid-col-start-1 grid-col-end-3 flex">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const showSidebarLogo = computed(()=>{
</script>
<template>
<div
class="grid-area-[grid-sidebar] relative"
class="grid-area-[grid-sidebar] relative bg-[var(--aside-background-color)] transition-colors-300 color-[var(--aside-text-color)]"
:class="[
{ 'pb-40px': showFooterTrigger },
sidebar.visible ? 'visible' : 'invisible overflow-hidden',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { tabTar } = useAppConfig()
</script>
<template>
<div
class="grid-area-[grid-tab-bar] grid grid-cols-2 content-center overflow-hidden relative"
class="grid-area-[grid-tab-bar] grid grid-cols-2 content-center overflow-hidden relative dark:dark-800"
:class="[tabTar.visible ? 'visible' : 'invisible']"
>
<div class="h-[var(--tab-bar-height)] grid-col-start-1 grid-col-end-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import SecondaryBorder from '../comm/SecondaryBorder.vue'
</script>
<template>
<div class="h-full w-36px grid-center cursor-pointer relative">
<div class="h-full w-36px grid-center cursor-pointer relative color-blue-gray-400 hover:color-blue-gray-800 dark:hover:color-blue-gray-50">
<slot></slot>
<SecondaryBorder left />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { sidebar, toggleCollapse } = useAppConfig()
<VbenIconify
:class="[sidebar.collapsed ? '-rotate-180' : 'rotate-0']"
icon="ph:caret-left-bold"
hover-color="var(--trigger-hover-icon-color)"
color="var(--trigger-icon-color)"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/web/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './useCopyToClipboard'
export * from './useGridLayoutContainerElStyle'
export * from './useLayout'
export * from './useTheme'
export * from './useAppInject'
export * from './useAppContext'
2 changes: 1 addition & 1 deletion packages/hooks/src/web/useAppInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export function useAppInject() {
const values = useAppProviderContext()

return {
getIsMobile: computed(() => unref(values.isMobile)),
isMobile: computed(() => unref(values.isMobile)),
}
}
62 changes: 0 additions & 62 deletions packages/hooks/src/web/useGridLayoutContainerElStyle.ts

This file was deleted.

147 changes: 147 additions & 0 deletions packages/hooks/src/web/useLayout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { useAppConfig } from '../config'
import { unref, watchEffect } from 'vue'
import { useLayoutHeader, useLayoutSidebar } from '@vben/stores'
import {
useCssVar,
MaybeElementRef,
lighten,
pickTextColorBasedOnBgColor,
darken,
addClass,
} from '@vben/utils'

const HEADER_HEIGHT = '--header-height'
const HEADER_BG_COLOR_VAR = '--header-background-color'
const HEADER_TEXT_COLOR_VAR = '--header-text-color'
const HEADER_ACTION_HOVER_BG_COLOR_VAR = '--header-action-hover-bg-color'

const ASIDE_WIDTH = '--aside-width'
const ASIDE_DARK_BG_COLOR = '--aside-background-color'
const ASIDE_TEXT_COLOR_VAR = '--aside-text-color'

const TAB_BAR_HEIGHT = '--tab-bar-height'

const FOOTER_HEIGHT = '--footer-height'

const LIGHT_TEXT_COLOR = 'rgba(0,0,0,.85)'
const DARK_TEXT_COLOR = '#fff'

export function createThemeColorListen(el: MaybeElementRef | null) {
const {
sidebar,
header,
grayMode,
colorWeak,
theme,
toggleGrayMode,
toggleColorWeak,
} = useAppConfig()

const { sidebarRef } = useLayoutSidebar()
const { headerRef } = useLayoutHeader()

const headerBgColor = useCssVar(
HEADER_BG_COLOR_VAR,
headerRef as MaybeElementRef,
{
initialValue: `${unref(header).bgColor}px`,
},
)

const headerTextColor = useCssVar(
HEADER_TEXT_COLOR_VAR,
headerRef as MaybeElementRef,
{
initialValue: LIGHT_TEXT_COLOR,
},
)
const headerActionHoverBgColor = useCssVar(
HEADER_ACTION_HOVER_BG_COLOR_VAR,
headerRef as MaybeElementRef,
)

const sidebarBgColor = useCssVar(
ASIDE_DARK_BG_COLOR,
sidebarRef as MaybeElementRef,
{
initialValue: `${unref(sidebar).bgColor}px`,
},
)

const asideTextColor = useCssVar(
ASIDE_TEXT_COLOR_VAR,
sidebarRef as MaybeElementRef,
{
initialValue: LIGHT_TEXT_COLOR,
},
)

watchEffect(() => {
headerBgColor.value = unref(header).bgColor
headerTextColor.value = pickTextColorBasedOnBgColor(
unref(header).bgColor,
LIGHT_TEXT_COLOR,
DARK_TEXT_COLOR,
)
headerActionHoverBgColor.value = ['#fff', '#ffffff'].includes(
unref(header).bgColor.toLowerCase(),
)
? darken(unref(header).bgColor, 6)
: lighten(unref(header).bgColor, 6)

sidebarBgColor.value = unref(sidebar).bgColor
asideTextColor.value = pickTextColorBasedOnBgColor(
unref(sidebar).bgColor,
LIGHT_TEXT_COLOR,
DARK_TEXT_COLOR,
)
toggleGrayMode(unref(grayMode))
toggleColorWeak(unref(colorWeak))
addClass(document.documentElement, unref(theme))
})
}

export function createGridLayoutListen(el: MaybeElementRef | null) {
const { isTopMenu, isMixSidebar, sidebar, header, footer, tabTar } =
useAppConfig()
const asideWidth = useCssVar(ASIDE_WIDTH, el, {
initialValue: `${unref(sidebar).width}px`,
})
const headerHeight = useCssVar(HEADER_HEIGHT, el, {
initialValue: `${unref(header).height}px`,
})
const tabBarHeight = useCssVar(TAB_BAR_HEIGHT, el, {
initialValue: `${unref(tabTar).height}px`,
})
const footerHeight = useCssVar(FOOTER_HEIGHT, el, {
initialValue: `${unref(footer).height}px`,
})

watchEffect(() => {
const getAsideWidth = () => {
if (unref(isTopMenu) || !unref(sidebar).visible) return 0
if (unref(sidebar).collapsed) return unref(sidebar).collapsedWidth
if (unref(isMixSidebar)) return unref(sidebar).mixSidebarWidth
return unref(sidebar).width
}

const getHeaderHeight = () => {
if (!unref(header).visible) return 0
return unref(header).height
}

const getTabBarHeight = () => {
if (!unref(tabTar).visible) return 0
return unref(tabTar).height
}

const getFooterHeight = () => {
if (!unref(footer).visible) return 0
return unref(footer).height
}
asideWidth.value = `${getAsideWidth()}px`
headerHeight.value = `${getHeaderHeight()}px`
tabBarHeight.value = `${getTabBarHeight()}px`
footerHeight.value = `${getFooterHeight()}px`
})
}
18 changes: 12 additions & 6 deletions packages/styles/src/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

/* layout start */

--layout-border-color: rgb(239, 239, 245);
--layout-color: #fff;
--layout-text-color: rgb(51, 54, 57);
--layout-border-color: rgb(239, 239, 245);
--layout-toggle-button-icon-color: rgb(51, 54, 57);

/* header */
--header-height: 48px;
--header-width: calc(100% - var(--aside-width));
--header-background-color: #fff;
--header-text-color: rgba(0,0,0,0.85);
--header-icon-color: var(--header-text-color);
--header-action-hover-bg-color: #f6f6f6;

/* tab */
--tab-bar-height: 36px;
Expand All @@ -30,13 +31,17 @@
/* aside */
--aside-height: calc(100% - var(--header-height));
--aside-width: 210px;
--aside-background-color: #001628;
--aside-background-color: #001529;
--aside-submenu-background-color: #0c2135;
--aside-text-color: #fff;

--trigger-color: #fff;
--trigger-color: rgb(72, 72, 78);
--trigger-border: 1px solid rgb(239, 239, 245);
--trigger-border-color: rgb(239, 239, 245);
--trigger-icon-color: rgb(51, 54, 57);
/*--trigger-border-color: rgb(239, 239, 245);*/
--trigger-icon-color: #f3f1f1;
/*--trigger-icon-color: rgb(51, 54, 57);*/
--trigger-hover-icon-color: #fff;

/* main */
--main-height: calc(100% - var(--footer-height));
Expand All @@ -47,6 +52,7 @@
--footer-width: 100%;

/* layout end */

}

@media (prefers-color-scheme: dark) {
Expand Down
Loading

0 comments on commit ba1ee76

Please sign in to comment.