Files
ruoyi-plus-vben5-h/packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue
xingyu a4736a49f8 feat: migrate to Tailwind CSS v4 (#7614)
* chore: update deps

* feat: use jsonc/x language

* chore: update eslint 10.0

* fix: no-useless-assignment

* feat: add CLAUDE.md

* chore: ignore

* feat: claude

* fix: lint

* chore: suppot eslint v10

* fix: lint

* fix: lint

* fix: type check

* fix: unit test

* fix: Suggested fix

* fix: unit test

* chore: update stylelint v17

* chore: update all major deps

* fix:  echarts console warn

* chore: update vitest v4

* feat: add skills ignores

* chore: update deps

* chore: update deps

* fix: cspell

* chore: update deps

* chore: update tailwindcss v4

* chore: remove postcss config

* fix: no use catalog

* chore: tailwind v4 config

* fix: tailwindcss v4 sort

* feat: use eslint-plugin-better-tailwindcss

* fix: Interference between enforce-consistent-line-wrapping, jsx-curly-brace-presence and Prettier

* fix: Interference between enforce-consistent-line-wrapping, jsx-curly-brace-presence and Prettier

* fix(lint): resolve prettier and better-tailwindcss formatting conflicts

* fix(tailwind): update theme references and lint sources

* style(format): normalize apps docs and playground vue files

* style(format): normalize core ui-kit components

* style(format): normalize effects ui and layout components
2026-03-10 05:08:45 +08:00

163 lines
4.4 KiB
Vue

<script setup lang="ts">
import type { BuiltinThemePreset } from '@vben/preferences';
import type { BuiltinThemeType } from '@vben/types';
import { computed, ref, watch } from 'vue';
import { UserRoundPen } from '@vben/icons';
import { $t } from '@vben/locales';
import { BUILT_IN_THEME_PRESETS } from '@vben/preferences';
import { convertToHsl, TinyColor } from '@vben/utils';
import { useThrottleFn } from '@vueuse/core';
defineOptions({
name: 'PreferenceBuiltinTheme',
});
const props = defineProps<{ isDark: boolean }>();
const colorInput = ref();
const modelValue = defineModel<BuiltinThemeType>({ default: 'default' });
const themeColorPrimary = defineModel<string>('themeColorPrimary');
const updateThemeColorPrimary = useThrottleFn(
(value: string) => {
themeColorPrimary.value = value;
},
300,
true,
true,
);
const inputValue = computed(() => {
return new TinyColor(themeColorPrimary.value || '').toHexString();
});
const builtinThemePresets = computed(() => {
return [...BUILT_IN_THEME_PRESETS];
});
function typeView(name: BuiltinThemeType) {
switch (name) {
case 'custom': {
return $t('preferences.theme.builtin.custom');
}
case 'deep-blue': {
return $t('preferences.theme.builtin.deepBlue');
}
case 'deep-green': {
return $t('preferences.theme.builtin.deepGreen');
}
case 'default': {
return $t('preferences.theme.builtin.default');
}
case 'gray': {
return $t('preferences.theme.builtin.gray');
}
case 'green': {
return $t('preferences.theme.builtin.green');
}
case 'neutral': {
return $t('preferences.theme.builtin.neutral');
}
case 'orange': {
return $t('preferences.theme.builtin.orange');
}
case 'pink': {
return $t('preferences.theme.builtin.pink');
}
case 'rose': {
return $t('preferences.theme.builtin.rose');
}
case 'sky-blue': {
return $t('preferences.theme.builtin.skyBlue');
}
case 'slate': {
return $t('preferences.theme.builtin.slate');
}
case 'violet': {
return $t('preferences.theme.builtin.violet');
}
case 'yellow': {
return $t('preferences.theme.builtin.yellow');
}
case 'zinc': {
return $t('preferences.theme.builtin.zinc');
}
}
}
function handleSelect(theme: BuiltinThemePreset) {
modelValue.value = theme.type;
}
function handleInputChange(e: Event) {
const target = e.target as HTMLInputElement;
updateThemeColorPrimary(convertToHsl(target.value));
}
function selectColor() {
colorInput.value?.[0]?.click?.();
}
watch(
() => [modelValue.value, props.isDark] as [BuiltinThemeType, boolean],
([themeType, isDark], [_, isDarkPrev]) => {
const theme = builtinThemePresets.value.find(
(item) => item.type === themeType,
);
if (theme) {
const primaryColor = isDark
? theme.darkPrimaryColor || theme.primaryColor
: theme.primaryColor;
if (!(theme.type === 'custom' && isDark !== isDarkPrev)) {
themeColorPrimary.value = primaryColor || theme.color;
}
}
},
);
</script>
<template>
<div class="flex w-full flex-wrap justify-between">
<template v-for="theme in builtinThemePresets" :key="theme.type">
<div class="flex cursor-pointer flex-col" @click="handleSelect(theme)">
<div
:class="{
'outline-box-active': theme.type === modelValue,
}"
class="group outline-box flex-center cursor-pointer"
>
<template v-if="theme.type !== 'custom'">
<div
:style="{ backgroundColor: theme.color }"
class="mx-9 my-2 size-5 rounded-md"
></div>
</template>
<template v-else>
<div class="size-full px-9 py-2" @click.stop="selectColor">
<div class="relative flex-center size-5 rounded-sm">
<UserRoundPen
class="absolute z-1 size-5 opacity-60 group-hover:opacity-100"
/>
<input
ref="colorInput"
:value="inputValue"
class="absolute inset-0 opacity-0"
type="color"
@input="handleInputChange"
/>
</div>
</div>
</template>
</div>
<div class="my-2 text-center text-xs text-muted-foreground">
{{ typeView(theme.type) }}
</div>
</div>
</template>
</div>
</template>