diff --git a/playground/nextjs-app-router/app/globals.css b/playground/nextjs-app-router/app/globals.css index ea61247550..fb60fe5d76 100644 --- a/playground/nextjs-app-router/app/globals.css +++ b/playground/nextjs-app-router/app/globals.css @@ -59,18 +59,92 @@ } } -/* Customize Theme */ -/* -@layer base { +/* Customize existing Theme */ + +/* @layer base { :root, .default-light, .default-dark, .base, .cyberpunk, .hacker { - --ock-bg-primary: red; - } -} */ + /* Override specific variables as needed */ + /* --ock-font-family: 'your-custom-value'; + --ock-border-radius: 'your-custom-value'; + --ock-text-primary: 'your-custom-value'; */ + /* } +} */ + + +/* Create your own custom Theme*/ +/* +Usage: + config={{ + appearance: { + mode: 'auto', + theme: 'custom', + }, + }} + + config={{ + appearance: { + mode: 'light', // To use custom-light only. + theme: 'custom', + }, + }} +*/ +.custom-light { + --ock-bg-primary: red; +} + +.custom-dark { + --ock-font-family: 'DM Sans', sans-serif; + --ock-border-radius: 0.5rem; + --ock-border-radius-inner: 0.25rem; + --ock-text-inverse: #1f2937; + --ock-text-foreground: #f9fafb; + --ock-text-foreground-muted: #9ca3af; + --ock-text-error: #d1d5db; + --ock-text-primary: #f3f4f6; + --ock-text-success: #9ca3af; + --ock-text-warning: #d1d5db; + --ock-text-disabled: #4b5563; + + --ock-bg-default: #111827; + --ock-bg-default-hover: #1f2937; + --ock-bg-default-active: #374151; + --ock-bg-alternate: #1f2937; + --ock-bg-alternate-hover: #374151; + --ock-bg-alternate-active: #4b5563; + --ock-bg-inverse: #0f172a; + --ock-bg-inverse-hover: #1e293b; + --ock-bg-inverse-active: #334155; + --ock-bg-primary: green; + --ock-bg-primary-hover: #6b7280; + --ock-bg-primary-active: #9ca3af; + --ock-bg-primary-washed: #1f2937; + --ock-bg-primary-disabled: #374151; + --ock-bg-secondary: #1f2937; + --ock-bg-secondary-hover: #374151; + --ock-bg-secondary-active: #4b5563; + --ock-bg-error: #991b1b; + --ock-bg-warning: #92400e; + --ock-bg-success: #065f46; + --ock-bg-default-reverse: #f9fafb; + + --ock-icon-color-primary: #9ca3af; + --ock-icon-color-foreground: #f9fafb; + --ock-icon-color-foreground-muted: #9ca3af; + --ock-icon-color-inverse: #1f2937; + --ock-icon-color-error: #f87171; + --ock-icon-color-success: #34d399; + --ock-icon-color-warning: #fbbf24; + + --ock-line-primary: #6b7280; + --ock-line-default: #374151; + --ock-line-heavy: #4b5563; + --ock-line-inverse: #e5e7eb; +} @layer base { * { diff --git a/playground/nextjs-app-router/components/form/component-theme.tsx b/playground/nextjs-app-router/components/form/component-theme.tsx index 43eb1323ad..b4d9d4b30a 100644 --- a/playground/nextjs-app-router/components/form/component-theme.tsx +++ b/playground/nextjs-app-router/components/form/component-theme.tsx @@ -29,6 +29,7 @@ export function ComponentTheme() { Base Cyberpunk Hacker + Custom diff --git a/site/docs/pages/guides/themes.mdx b/site/docs/pages/guides/themes.mdx index cd84ff412f..ae496f1ef0 100644 --- a/site/docs/pages/guides/themes.mdx +++ b/site/docs/pages/guides/themes.mdx @@ -25,6 +25,7 @@ OnchainKit offers multiple themes to quickly style your components. Set the them - `base`: Single mode only. - `cyberpunk`: Single mode only. - `hacker`: Single mode only. +- `custom`: Single mode only. If no theme is selected, the **`default`** theme is applied automatically. @@ -60,7 +61,7 @@ If no mode is specified, `auto` mode will be applied by default. config={{ appearance: { mode: 'auto', // 'auto' | 'light' | 'dark' // [!code focus] - theme: 'default', // 'default' | 'base' | 'cyberpunk' | 'hacker' + theme: 'default', // 'default' | 'base' | 'cyberpunk' | 'hacker' | 'your-custom-theme' }, }} > @@ -68,7 +69,8 @@ If no mode is specified, `auto` mode will be applied by default. ## CSS Overrides -You can further customize the appearance by overriding CSS styles. This allows for fine-tuning the look of individual components beyond the provided themes. +Fine-tune specific aspects of an existing theme. +This is useful when you want to make adjustments to the appearance of the components without creating an entirely new theme. ```css @layer base { @@ -78,9 +80,69 @@ You can further customize the appearance by overriding CSS styles. This allows f .base, .cyberpunk, .hacker { + /* Override specific variables as needed */ + --ock-font-family: 'your-custom-value'; + --ock-border-radius: 'your-custom-value'; + --ock-text-primary: 'your-custom-value'; + } +} +``` + +## Custom Theme + +Define an entirely new look and feel for your application. +This gives you complete control over all aspects of the design, including colors, fonts, and other visual properties. + +#### Usage Options: + +##### Automatic Light/Dark Mode Switching: +- To automatically switch between light and dark versions of your custom theme: + +```tsx twoslash +// @noErrors: 2304 17008 1005 + +``` + +##### Single Theme Version: +- To use only one version of your custom theme at all times: + +```tsx twoslash +// @noErrors: 2304 17008 1005 + +``` + +##### Defining a custom theme + +Use CSS variables to define your custom theme. +The class name definitions must include the `-light` or `-dark` suffix. + +```css +@layer base { + .custom-light { + /* Font and Shape */ --ock-font-family: 'your-custom-value'; --ock-border-radius: 'your-custom-value'; --ock-border-radius-inner: 'your-custom-value'; + + /* Text Colors */ --ock-text-inverse: 'your-custom-value'; --ock-text-foreground: 'your-custom-value'; --ock-text-foreground-muted: 'your-custom-value'; @@ -90,6 +152,7 @@ You can further customize the appearance by overriding CSS styles. This allows f --ock-text-warning: 'your-custom-value'; --ock-text-disabled: 'your-custom-value'; + /* Background Colors */ --ock-bg-default: 'your-custom-value'; --ock-bg-default-hover: 'your-custom-value'; --ock-bg-default-active: 'your-custom-value'; @@ -112,6 +175,7 @@ You can further customize the appearance by overriding CSS styles. This allows f --ock-bg-success: 'your-custom-value'; --ock-bg-default-reverse: 'your-custom-value'; + /* Icon Colors */ --ock-icon-color-primary: 'your-custom-value'; --ock-icon-color-foreground: 'your-custom-value'; --ock-icon-color-foreground-muted: 'your-custom-value'; @@ -120,10 +184,15 @@ You can further customize the appearance by overriding CSS styles. This allows f --ock-icon-color-success: 'your-custom-value'; --ock-icon-color-warning: 'your-custom-value'; + /* Line Colors */ --ock-line-primary: 'your-custom-value'; --ock-line-default: 'your-custom-value'; --ock-line-heavy: 'your-custom-value'; --ock-line-inverse: 'your-custom-value'; } + + .custom-dark { + /* Define dark mode custom classes here */ + } } ``` diff --git a/src/types.ts b/src/types.ts index c031b405b5..61d8a30f18 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,7 +21,12 @@ export type isEthereumOptions = { export type Mode = 'auto' | 'light' | 'dark'; // External theme options for users -export type ComponentTheme = 'base' | 'cyberpunk' | 'default' | 'hacker'; +export type ComponentTheme = + | 'base' + | 'cyberpunk' + | 'default' + | 'hacker' + | string; // Internal theme options, including light/dark variants for 'default' export type UseThemeReact = @@ -30,7 +35,8 @@ export type UseThemeReact = | 'default' | 'hacker' | 'default-light' - | 'default-dark'; + | 'default-dark' + | string; /** * Note: exported as public Type