Skip to content

Commit

Permalink
Added dark/light theme switching support to AddressInput and AmountIn…
Browse files Browse the repository at this point in the history
…put components using @radix-ui/colors and Tailwind.
  • Loading branch information
kkomelin committed Jan 9, 2025
1 parent c8e8bfa commit 2c953c8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"@mysten/sui": "^1.18.0",
"@mysten/suins": "^0.4.2",
"@mysten/wallet-standard": "^0.13.20",
"@radix-ui/colors": "^3.0.0",
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@tanstack/react-query": "^5.62.16",
Expand Down Expand Up @@ -174,5 +175,5 @@
},
"bugs": {
"url": "https://github.com/suiware/kit/issues"
}
}
}
1 change: 1 addition & 0 deletions packages/kit/src/components/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import debounce from 'lodash.debounce'
import { ChangeEvent, FC, useCallback, useEffect, useState } from 'react'
import { resolveSuinsName } from '~~/helpers/suins'


const DEBOUNCE_DELAY = 500

export interface IAddressInput {
Expand Down
19 changes: 16 additions & 3 deletions packages/kit/src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@
.sk-address-input, .sk-amount-input {
@apply flex flex-col gap-1;
& input {
@apply w-full rounded-lg border px-3 py-1.5 focus:outline-none focus:ring-2 focus:ring-blue-500 border-gray-300;

@apply w-full rounded-lg border px-3 py-1.5
border-slate3 bg-slate1 text-slate12
focus:outline-none focus:ring-2 focus:ring-blue7
dark:border-slateDark3 dark:bg-slateDark1 dark:text-slateDark12;
&:hover {
@apply border-slate7
dark:border-slateDark7;
}
&:focus {
@apply border-blue7 dark:border-blueDark7 dark:ring-blueDark7;
}
&.error {
@apply border-red-500 focus:ring-red-500;
@apply border-red7 bg-red3 focus:ring-red7
dark:border-redDark7 dark:bg-redDark3 dark:ring-redDark7;
}
}
& span {
@apply text-sm text-red-500;
@apply text-sm text-red7
dark:text-redDark7;
}
}
}
48 changes: 44 additions & 4 deletions packages/kit/tailwind.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,56 @@
import {
blue,
blueDark,
red,
redDark,
slate,
slateDark,
} from '@radix-ui/colors'

/**
* Convert keys of the given object from "slate1" to "slateDark1".
*
* @param {object} obj
* @param {string} colorName
* @returns
*/
const prefixDarkColors = (obj, colorName) => {
return Object.entries(obj).reduce((acc, [key, value]) => {
// Extract just the number from the key
const numberKey = key.replace(/^[a-zA-Z]+/, '')
acc[`${colorName}Dark${numberKey}`] = value
return acc
}, {})
}

/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{ts,tsx}",
// Support multiple approaches for switching between light and dark mode.
darkMode: [
'variant',
[
'@media (prefers-color-scheme: dark) { &:not(.light *) }',
'&:is(.dark *)',
],
],
content: ['./src/**/*.{ts,tsx}'],
theme: {
extend: {},
extend: {
colors: {
...slate,
...blue,
...red,
...prefixDarkColors(slateDark, 'slate'),
...prefixDarkColors(blueDark, 'blue'),
...prefixDarkColors(redDark, 'red'),
},
},
},
plugins: [],
corePlugins: {
preflight: false,
},
experimental: {
optimizeUniversalDefaults: true,
}
},
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 2c953c8

Please sign in to comment.