diff --git a/components.d.ts b/components.d.ts index ae1710f0..2750ce66 100644 --- a/components.d.ts +++ b/components.d.ts @@ -21,16 +21,21 @@ declare module '@vue/runtime-core' { Bip39Generator: typeof import('./src/tools/bip39-generator/bip39-generator.vue')['default'] CaseConverter: typeof import('./src/tools/case-converter/case-converter.vue')['default'] CButton: typeof import('./src/ui/c-button/c-button.vue')['default'] + 'CButton.demo': typeof import('./src/ui/c-button/c-button.demo.vue')['default'] CCard: typeof import('./src/ui/c-card/c-card.vue')['default'] + 'CCard.demo': typeof import('./src/ui/c-card/c-card.demo.vue')['default'] ChmodCalculator: typeof import('./src/tools/chmod-calculator/chmod-calculator.vue')['default'] Chronometer: typeof import('./src/tools/chronometer/chronometer.vue')['default'] CLink: typeof import('./src/ui/c-link/c-link.vue')['default'] + 'CLink.demo': typeof import('./src/ui/c-link/c-link.demo.vue')['default'] CollapsibleToolMenu: typeof import('./src/components/CollapsibleToolMenu.vue')['default'] ColorConverter: typeof import('./src/tools/color-converter/color-converter.vue')['default'] ColoredCard: typeof import('./src/components/ColoredCard.vue')['default'] CopyableIpLike: typeof import('./src/tools/ipv4-subnet-calculator/copyable-ip-like.vue')['default'] CrontabGenerator: typeof import('./src/tools/crontab-generator/crontab-generator.vue')['default'] DateTimeConverter: typeof import('./src/tools/date-time-converter/date-time-converter.vue')['default'] + 'Demo.routes': typeof import('./src/ui/demo/demo.routes.vue')['default'] + DemoWrapper: typeof import('./src/ui/demo/demo-wrapper.vue')['default'] DeviceInformation: typeof import('./src/tools/device-information/device-information.vue')['default'] DiffViewer: typeof import('./src/tools/json-diff/diff-viewer/diff-viewer.vue')['default'] DockerRunToDockerComposeConverter: typeof import('./src/tools/docker-run-to-docker-compose-converter/docker-run-to-docker-compose-converter.vue')['default'] diff --git a/src/config.ts b/src/config.ts index c0545f6a..2558d038 100644 --- a/src/config.ts +++ b/src/config.ts @@ -23,9 +23,9 @@ export const config = figue({ env: { doc: 'Application current env', format: 'enum', - values: ['production', 'development', 'test'], + values: ['production', 'development', 'preview', 'test'], default: 'development', - env: 'MODE', + env: 'VITE_VERCEL_ENV', }, }, plausible: { diff --git a/src/router.ts b/src/router.ts index f16b418c..00c20c74 100644 --- a/src/router.ts +++ b/src/router.ts @@ -4,6 +4,7 @@ import HomePage from './pages/Home.page.vue'; import NotFound from './pages/404.page.vue'; import { tools } from './tools'; import { config } from './config'; +import { routes as demoRoutes } from './ui/demo/demo.routes'; const toolsRoutes = tools.map(({ path, name, component, ...config }) => ({ path, @@ -32,6 +33,7 @@ const router = createRouter({ }, ...toolsRoutes, ...toolsRedirectRoutes, + ...(config.app.env === 'development' ? demoRoutes : []), { path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound }, ], }); diff --git a/src/ui/c-button/c-button.demo.vue b/src/ui/c-button/c-button.demo.vue new file mode 100644 index 00000000..988659f5 --- /dev/null +++ b/src/ui/c-button/c-button.demo.vue @@ -0,0 +1,29 @@ + + + + + diff --git a/src/ui/c-button/c-button.theme.ts b/src/ui/c-button/c-button.theme.ts index 2f25e6fd..87ad89f3 100644 --- a/src/ui/c-button/c-button.theme.ts +++ b/src/ui/c-button/c-button.theme.ts @@ -1,240 +1,76 @@ +import { darken, lighten } from '../color/color.models'; import { defineThemes } from '../theme/theme.models'; import { appThemes } from '../theme/themes'; -export const { useTheme } = defineThemes({ - dark: { - basic: { - default: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: 'rgba(255, 255, 255, 0.08)', - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: 'rgba(255, 255, 255, 0.12)', - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: 'rgba(255, 255, 255, 0.24)', - }, - - outline: { - color: appThemes.dark.primary.color, - }, - }, - - primary: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.primary.color, - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.primary.colorHover, - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.primary.colorPressed, - }, - - outline: { - color: appThemes.dark.primary.color, - }, - }, - - warning: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.warning.color, - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.warning.colorHover, - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.warning.colorPressed, - }, - - outline: { - color: appThemes.dark.warning.color, - }, - }, - }, - - text: { - default: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: 'transparent', - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: 'rgba(255, 255, 255, 0.12)', - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: 'rgba(255, 255, 255, 0.82)', - }, - - outline: { - color: appThemes.dark.primary.color, - }, - }, - - primary: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.primary.color, - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.primary.colorHover, - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.primary.colorPressed, - }, - - outline: { - color: appThemes.dark.primary.color, - }, - }, - - warning: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.warning.color, - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.warning.colorHover, - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.dark.warning.colorPressed, - }, - - outline: { - color: appThemes.dark.warning.color, - }, - }, - }, - }, - light: { - basic: { - default: { - textColor: appThemes.light.text.baseColor, - backgroundColor: 'rgba(46, 51, 56, 0.05)', - - hover: { - textColor: appThemes.light.text.baseColor, - backgroundColor: 'rgba(46, 51, 56, 0.09)', - }, - - pressed: { - textColor: appThemes.light.text.baseColor, - backgroundColor: 'rgba(46, 51, 56, 0.22)', - }, - - outline: { - color: appThemes.light.primary.color, - }, - }, - - primary: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.light.primary.color, - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.light.primary.colorHover, - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.light.primary.colorPressed, - }, - - outline: { - color: appThemes.light.primary.color, - }, - }, - - warning: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.light.warning.color, - - hover: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.light.warning.colorHover, - }, - - pressed: { - textColor: appThemes.dark.text.baseColor, - backgroundColor: appThemes.light.warning.colorPressed, - }, - - outline: { - color: appThemes.light.warning.color, - }, - }, - }, - text: { - default: { - textColor: appThemes.light.text.baseColor, - backgroundColor: 'transparent', - - hover: { - textColor: appThemes.light.text.baseColor, - backgroundColor: 'rgba(46, 51, 56, 0.09)', - }, - - pressed: { - textColor: appThemes.light.text.baseColor, - backgroundColor: 'rgba(46, 51, 56, 0.13)', - }, - - outline: { - color: appThemes.light.primary.color, - }, - }, - primary: { - textColor: appThemes.light.primary.color, - backgroundColor: 'transparent', - - hover: { - textColor: appThemes.light.primary.colorHover, - backgroundColor: 'rgba(46, 51, 56, 0.09)', - }, - - pressed: { - textColor: appThemes.light.primary.colorPressed, - backgroundColor: 'rgba(46, 51, 56, 0.13)', - }, - - outline: { - color: appThemes.light.primary.color, - }, - }, - warning: { - textColor: appThemes.light.warning.color, - backgroundColor: 'transparent', - - hover: { - textColor: appThemes.light.warning.colorHover, - backgroundColor: 'rgba(46, 51, 56, 0.09)', - }, - - pressed: { - textColor: appThemes.light.warning.colorPressed, - backgroundColor: 'rgba(46, 51, 56, 0.13)', - }, - - outline: { - color: appThemes.light.warning.color, - }, - }, - }, - }, +const createState = ({ + textColor, + backgroundColor, + hoverBackground, + hoveredTextColor = textColor, + pressedBackground, + pressedTextColor = textColor, +}: { + textColor: string; + backgroundColor: string; + hoverBackground: string; + hoveredTextColor?: string; + pressedBackground: string; + pressedTextColor?: string; +}) => ({ + textColor, + backgroundColor, + hover: { textColor: hoveredTextColor, backgroundColor: hoverBackground }, + pressed: { textColor: pressedTextColor, backgroundColor: pressedBackground }, +}); + +const createTheme = ({ style }: { style: 'light' | 'dark' }) => { + const theme = appThemes[style]; + + return { + basic: { + default: createState({ + textColor: theme.text.baseColor, + backgroundColor: theme.default.color, + hoverBackground: theme.default.colorHover, + pressedBackground: theme.default.colorPressed, + }), + primary: createState({ + textColor: theme.primary.color, + backgroundColor: theme.primary.colorFaded, + hoverBackground: lighten(theme.primary.colorFaded, 30), + pressedBackground: darken(theme.primary.colorFaded, 30), + }), + warning: createState({ + textColor: theme.text.baseColor, + backgroundColor: theme.warning.color, + hoverBackground: theme.warning.colorHover, + pressedBackground: theme.warning.colorPressed, + }), + }, + text: { + default: createState({ + textColor: theme.text.baseColor, + backgroundColor: 'transparent', + hoverBackground: theme.default.colorHover, + pressedBackground: theme.default.colorPressed, + }), + primary: createState({ + textColor: theme.primary.color, + backgroundColor: 'transparent', + hoverBackground: theme.primary.colorFaded, + pressedBackground: darken(theme.primary.colorFaded, 30), + }), + warning: createState({ + textColor: theme.text.baseColor, + backgroundColor: theme.warning.color, + hoverBackground: theme.warning.colorHover, + pressedBackground: theme.warning.colorPressed, + }), + }, + }; +}; + +export const { useTheme } = defineThemes({ + dark: createTheme({ style: 'dark' }), + light: createTheme({ style: 'light' }), }); diff --git a/src/ui/c-button/c-button.vue b/src/ui/c-button/c-button.vue index f52a0699..2cbc4fd4 100644 --- a/src/ui/c-button/c-button.vue +++ b/src/ui/c-button/c-button.vue @@ -14,6 +14,7 @@ diff --git a/src/ui/c-link/c-link.vue b/src/ui/c-link/c-link.vue index df101208..a7d1b831 100644 --- a/src/ui/c-link/c-link.vue +++ b/src/ui/c-link/c-link.vue @@ -16,7 +16,15 @@ const props = defineProps<{ const { href, to } = toRefs(props); const theme = useTheme(); -const tag = computed(() => (href?.value ? 'a' : RouterLink)); +const tag = computed(() => { + if (href?.value) { + return 'a'; + } + if (to?.value) { + return RouterLink; + } + return 'span'; +}); diff --git a/src/ui/demo/demo.routes.ts b/src/ui/demo/demo.routes.ts new file mode 100644 index 00000000..0e9a9e4e --- /dev/null +++ b/src/ui/demo/demo.routes.ts @@ -0,0 +1,25 @@ +import type { RouteRecordRaw } from 'vue-router'; + +const demoPages = import.meta.glob('../*/*.demo.vue'); + +export const demoRoutes = Object.keys(demoPages).map((path) => { + const [, , fileName] = path.split('/'); + const name = fileName.split('.').shift(); + + console.log(path); + + return { + path: name, + name, + component: () => import(/* @vite-ignore */ path), + } as RouteRecordRaw; +}); + +export const routes = [ + { + path: '/c-lib', + name: 'c-lib', + children: demoRoutes, + component: () => import('./demo-wrapper.vue'), + }, +]; diff --git a/src/ui/theme/themes.ts b/src/ui/theme/themes.ts index eca63dbd..18b2c8d0 100644 --- a/src/ui/theme/themes.ts +++ b/src/ui/theme/themes.ts @@ -3,16 +3,20 @@ import { defineThemes } from './theme.models'; export const { themes: appThemes, useTheme: useAppTheme } = defineThemes({ light: { text: { - baseColor: 'rgb(51, 54, 57)', - mutedColor: 'rgba(118, 124, 130)', + baseColor: '#333639', + mutedColor: '#767c82', + }, + default: { + color: 'rgba(46, 51, 56, 0.05)', + colorHover: 'rgba(46, 51, 56, 0.09)', + colorPressed: 'rgba(46, 51, 56, 0.22)', }, - primary: { color: '#18a058', colorHover: '#1ea54c', colorPressed: '#0C7A43', + colorFaded: '#18a0582f', }, - warning: { color: '#f59e0b', colorHover: '#f59e0b', @@ -33,14 +37,19 @@ export const { themes: appThemes, useTheme: useAppTheme } = defineThemes({ }, dark: { text: { - baseColor: 'rgba(255, 255, 255, 0.82)', - mutedColor: 'rgba(255, 255, 255, 0.5)', + baseColor: '#ffffffd1', + mutedColor: '#ffffff80', + }, + default: { + color: 'rgba(255, 255, 255, 0.08)', + colorHover: 'rgba(255, 255, 255, 0.12)', + colorPressed: 'rgba(255, 255, 255, 0.24)', }, - primary: { color: '#1ea54c', colorHover: '#36AD6A', colorPressed: '#0C7A43', + colorFaded: '#18a0582f', }, warning: { color: '#f59e0b',