From 4d0f13a197488ccc5b42295dcc53810976297be5 Mon Sep 17 00:00:00 2001 From: Juan Di Toro Date: Sat, 7 Oct 2023 18:12:27 +0200 Subject: [PATCH] chore: small refactor using CVA --- .../lume/LumeDashboard/LumeDashboard.tsx | 67 ++++++++++++------- .../lume/LumeIdentity/LumeIdentity.tsx | 6 +- .../lume/LumeIdentity/components.tsx | 6 +- tsconfig.json | 8 +-- vite.config.ts | 11 +-- 5 files changed, 60 insertions(+), 38 deletions(-) diff --git a/src/components/lume/LumeDashboard/LumeDashboard.tsx b/src/components/lume/LumeDashboard/LumeDashboard.tsx index 8c8ec70..9f08183 100644 --- a/src/components/lume/LumeDashboard/LumeDashboard.tsx +++ b/src/components/lume/LumeDashboard/LumeDashboard.tsx @@ -1,25 +1,21 @@ import * as Dialog from "@radix-ui/react-dialog" import { Chain, useLume } from "../LumeProvider" -import Logo from "../../../assets/lume-logo.png"; +import Logo from "../../../assets/lume-logo.png" +import { cva } from "class-variance-authority" +import { cn } from "../../utils" -const SYNCSTATE_TO_TEXT: Record = { - done: 'Synced', - error: 'Issue', - syncing: 'Syncing' + +const SYNCSTATE_TO_TEXT: Record = { + done: "Synced", + error: "Issue", + syncing: "Syncing" } -const SYNC_STATE_TO_TW_COLOR: Record = { - 'done': 'text-primary', - 'error': 'text-red-500', - 'syncing': 'text-orange-500', -} - - const LumeDashboard = () => { const { chains } = useLume() - const contentChains = chains.filter(c => c.type === 'content'); - const blockchainChains = chains.filter(c => c.type === 'blockchain'); + const contentChains = chains.filter((c) => c.type === "content") + const blockchainChains = chains.filter((c) => c.type === "blockchain") return ( @@ -33,14 +29,24 @@ const LumeDashboard = () => {

Content

- {contentChains.map((chain, index) => )} + {contentChains.map((chain, index) => ( + + ))}

Blockchain

- {blockchainChains.map((chain, index) => )} + {blockchainChains.map((chain, index) => ( + + ))}
@@ -49,14 +55,29 @@ const LumeDashboard = () => { ) } +const chainIndicatorVariant = cva("chainIndicatorVariant", { + variants: { + syncState: { + done: "text-primary", + error: "text-red-500", + syncing: "text-orange-500" + } + } +}); const ChainIndicator = ({ chain }: { chain: Chain }) => { - return
- -
- {chain.name} - {SYNCSTATE_TO_TEXT[chain.syncState]} + return ( +
+ +
+ {chain.name} + + {SYNCSTATE_TO_TEXT[chain.syncState]} + +
-
+ ) } const CircularProgress = ({ @@ -71,7 +92,7 @@ const CircularProgress = ({ return ( = ({}) => { +const LumeIdentity: React.FC = () => { const { visibleComponent, setVisibleComponent } = useSwitchableComponent(ComponentList.SubmitButton) const isSubmitButtonInView = [ComponentList.SubmitButton.index].includes(visibleComponent.index) @@ -81,4 +79,4 @@ export default function Wrapped() { -}; +} diff --git a/src/components/lume/LumeIdentity/components.tsx b/src/components/lume/LumeIdentity/components.tsx index 23b2a44..c187d8a 100644 --- a/src/components/lume/LumeIdentity/components.tsx +++ b/src/components/lume/LumeIdentity/components.tsx @@ -7,7 +7,7 @@ import React from "react"; import { useLumeIndentity } from "./LumeIdentityContext"; // Extracted components -const SubmitButtonComponent = ({ }) => { +const SubmitButtonComponent = () => { const { setVisibleComponent } = useSwitchableComponent(); return ( I get it, I'll keep it safe. Let's see the key. diff --git a/tsconfig.json b/tsconfig.json index 3151cdf..2035b72 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,10 +22,10 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "baseUrl": ".", - "paths": { - "@/*": ["src/*"], - "@/styles/*": ["styles/*"], - }, + // "paths": { + // "@/*": ["src/*"], + // "@/styles/*": ["styles/*"], + // }, "typeRoots": ["src/vite-env.d.ts"] }, "include": [ diff --git a/vite.config.ts b/vite.config.ts index 2af8d31..dee6b3f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,17 +1,20 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' -// import scopeTailwind from "vite-plugin-scope-tailwind"; +import scopeTailwind from "vite-plugin-scope-tailwind"; import { resolve } from 'path' // import reactTailwindClassnamePrefixer from "./lib/vite-plugin-react-classname-prefixer"; import svgr from "vite-plugin-svgr"; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [svgr(), react()], + plugins: [svgr(), react(), scopeTailwind({react: true})], resolve: { + // I have no clue why aliases are not working at all... alias: { - '@/styles/': resolve(__dirname, './styles'), - '@/': resolve(__dirname, './src'), + '@styles/': resolve(__dirname, './styles'), + '@components/': resolve(__dirname, './src/components'), + '@assets/': resolve(__dirname, './src/assets'), + '@': resolve(__dirname, './src'), }, }, })