Skip to content

Commit

Permalink
feat: theme
Browse files Browse the repository at this point in the history
  • Loading branch information
yongheng2016 committed May 31, 2024
1 parent b80c492 commit 956c363
Show file tree
Hide file tree
Showing 17 changed files with 1,804 additions and 64 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bytetrade/ui",
"version": "0.0.85",
"version": "0.1.0",
"private": false,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -12,7 +12,8 @@
"lib": "vue-cli-service build --target lib --name bytetrade-ui --dest lib packages/index.ts && tsc --emitDeclarationOnly -p tsconfig.json && npm run copy-folder",
"posttest": "npm run format",
"prepare": "husky install",
"storybook": "storybook dev -p 6006"
"storybook": "storybook dev -p 6006",
"build-dev": "npm run lib && yalc push"
},
"main": "lib/bytetrade-ui.common.js",
"browser": {
Expand Down
12 changes: 8 additions & 4 deletions packages/Menu/src/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div class="bt-menu-container q-pa-md">
<Theme :show-theme-toggle="props.showThemeToggle"></Theme>
<div class="q-pb-lg" v-if="$slots.header">
<slot name="header"></slot>
</div>
Expand All @@ -14,7 +15,7 @@
}"
>
<div class="row items-center">
<div style="flex: 1" class="text-subtitle2 text-grey-5">
<div style="flex: 1" class="text-subtitle2 text-ink-3">
{{ item.label }}
</div>
<div>
Expand Down Expand Up @@ -84,7 +85,7 @@
<MenuItem
v-else
:activeClass="activeClassConputed"
:same-activeable="sameActiveable"
:same-activeable="sameActiveable"
:data="child"
@select="selectHandler"
v-model="link"
Expand All @@ -111,6 +112,7 @@ import SubMenu from "./SubMenu.vue";
import { Item } from "./Menu";
import ItemLabel from "./ItemLabel.vue";
import AvatarIcon from "./AvatarIcon.vue";
import Theme from "../../theme/src/IndexPage.vue";
interface Props {
/**
Expand Down Expand Up @@ -139,10 +141,12 @@ interface Props {
*/
hideExpandIcon: boolean;
sameActiveable: boolean;
sameActiveable: boolean;
showThemeToggle: boolean;
}
const props = withDefaults(defineProps<Props>(), {
sameActiveable: false
sameActiveable: false,
showThemeToggle: false
});
const link = ref(props.defaultActive || props.modelValue);
Expand Down
19 changes: 13 additions & 6 deletions packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import BtMenu from "./Menu";
import BtScrollArea from "./ScrollArea";
import BtNotify from "./notify";
import BtDialog from "./dialog";
import { NotifyDefinedType } from './notify/type'

import { NotifyDefinedType } from "./notify/type";
import BtTheme from "./theme";
import useColor from "./utils/useColor";

const components = [
BtButton,
BtLoading,
Expand All @@ -27,7 +29,8 @@ const components = [
VueDragResize,
UploadFromFiles,
BtMenu,
BtScrollArea
BtScrollArea,
BtTheme
];

// const app = createApp(Apps);
Expand Down Expand Up @@ -68,7 +71,9 @@ export default {
VueDragResize,
UploadFromFiles,
BtMenu,
BtScrollArea
BtScrollArea,
BtTheme,
useColor
};

export {
Expand All @@ -82,6 +87,8 @@ export {
BtMenu,
BtScrollArea,
BtNotify,
NotifyDefinedType,
BtDialog
NotifyDefinedType,
BtDialog,
BtTheme,
useColor
};
7 changes: 7 additions & 0 deletions packages/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { App } from "vue";

import BtTheme from "./src/IndexPage.vue";

export default (app: App) => {
app.component(BtTheme.name, BtTheme);
};
140 changes: 140 additions & 0 deletions packages/theme/src/IndexPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<template>
<q-toggle
v-if="props.showThemeToggle"
v-model="isDark"
@update:model-value="change"
/>
</template>

<script setup lang="ts">
import { watchEffect, ref, defineProps } from "vue";
import { useQuasar, setCssVar, getCssVar, colors } from "quasar";
interface Props {
showThemeToggle: boolean;
}
const props = withDefaults(defineProps<Props>(), {
showToggle: false
});
const { getPaletteColor, changeAlpha } = colors;
const $q = useQuasar();
const isDark = ref(false);
if (props.showThemeToggle) {
$q.dark.set(true);
isDark.value = true;
}
const change = () => {
$q.dark.toggle();
};
const variables = [
"background-1",
"background-2",
"background-3",
"background-4",
"background-5",
"background-6",
"background-hover",
"background-selected",
"separator",
"separator-2",
"ink-1",
"ink-2",
"ink-3",
"ink-on-brand",
"ink-on-brand-disabled",
"input-bg-disabled",
"input-stroke",
"input-stroke-hover",
"input-stroke-disabled",
"radio-stroke",
"radio-stroke-hover",
"radio-stroke-disabled",
"btn-bg-hover",
"btn-bg-pressed",
"btn-stroke",
"btn-stroke-hover",
"btn-stroke-disabled",
"orange-soft",
"orange-alpha",
"orange-default",
"orange-hover",
"orange-pressed",
"orange-disabled",
"blue-soft",
"blue-alpha",
"blue-default",
"blue-hover",
"blue-pressed",
"blue-disabled",
"red-soft",
"red-alpha",
"red-default",
"red-hover",
"red-pressed",
"red-disabled",
"yellow-soft",
"yellow-alpha",
"yellow-default",
"yellow-hover",
"yellow-pressed",
"yellow-disabled",
"green-soft",
"green-alpha",
"green-default",
"green-hover",
"green-pressed",
"green-disabled",
"teal-soft",
"teal-alpha",
"teal-default",
"teal-hover",
"teal-pressed",
"teal-disabled",
"light-blue-soft",
"light-blue-alpha",
"light-blue-default",
"light-blue-hover",
"light-blue-pressed",
"light-blue-disabled",
"light-green-soft",
"light-green-alpha",
"light-green-default",
"light-green-hover",
"light-green-pressed",
"light-green-disabled"
];
const light = variables.map((item) => ({
name: item,
value: getPaletteColor(`${item}-light`)
}));
const dark = variables.map((item) => ({
name: item,
value: getPaletteColor(`${item}-dark`)
}));
watchEffect(() => {
if ($q.dark.isActive) {
dark.forEach((item) => {
setCssVar(item.name, item.value);
});
} else {
light.forEach((item) => {
setCssVar(item.name, item.value);
});
}
});
</script>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
name: "BtTheme"
});
</script>
<style></style>
20 changes: 20 additions & 0 deletions packages/utils/useColor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useQuasar, colors } from "quasar";
import { ref, watchEffect } from "vue";

const { getPaletteColor } = colors;
const $q = useQuasar();

function useColor(variable: string) {
const $q = useQuasar();
const color = ref(getPaletteColor(variable));

watchEffect(() => {
color.value = $q.dark.isActive
? getPaletteColor(variable)
: getPaletteColor(variable);
});

return { color };
}

export default useColor;
Loading

0 comments on commit 956c363

Please sign in to comment.