-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type { ConfigColorMode } from '@kobalte/core/color-mode' | ||
import { useColorMode } from '@kobalte/core/color-mode' | ||
import * as Lucide from 'lucide-solid' | ||
import { type JSX, createSignal, onMount } from 'solid-js' | ||
import { Select } from '#/components/base-ui/select' | ||
import { clx } from '#/libs/utils' | ||
|
||
interface ThemeOption { | ||
value: ConfigColorMode | ||
label: string | ||
icon: (iconClass: string) => JSX.Element | ||
} | ||
|
||
const THEME_OPTIONS: ThemeOption[] = [ | ||
{ | ||
value: 'light', | ||
label: 'Light', | ||
icon: (iconClass: string) => <Lucide.Sun class={iconClass} />, | ||
}, | ||
{ | ||
value: 'dark', | ||
label: 'Dark', | ||
icon: (iconClass: string) => <Lucide.Moon class={iconClass} />, | ||
}, | ||
{ | ||
value: 'system', | ||
label: 'System', | ||
icon: (iconClass: string) => <Lucide.Monitor class={iconClass} />, | ||
}, | ||
] | ||
|
||
export function ThemeSelector() { | ||
const { colorMode, setColorMode } = useColorMode() | ||
const [selectedTheme, setSelectedTheme] = createSignal<ThemeOption>() | ||
|
||
onMount(() => { | ||
// Use MaybeConfigColorMode to get value from custom storage | ||
setSelectedTheme(THEME_OPTIONS.find((option) => option.value === colorMode())) | ||
}) | ||
|
||
const handleThemeChange = (opts: ThemeOption | null) => { | ||
if (opts) { | ||
setSelectedTheme(opts) | ||
setColorMode(opts.value) | ||
} | ||
} | ||
|
||
return ( | ||
<Select<ThemeOption> | ||
options={THEME_OPTIONS} | ||
optionValue="value" | ||
optionTextValue="label" | ||
value={selectedTheme() ?? THEME_OPTIONS[0]} | ||
onChange={handleThemeChange} | ||
gutter={8} | ||
sameWidth={false} | ||
placement="bottom-end" | ||
itemComponent={(props) => ( | ||
<Select.Item | ||
item={props.item} | ||
class={clx( | ||
props.item.rawValue.value === colorMode() ? 'bg-gray-100 dark:bg-gray-700' : '', | ||
'flex cursor-default items-center space-x-2 px-3 py-1 text-sm outline-none transition-colors hover:bg-gray-100 dark:hover:bg-gray-700' | ||
)} | ||
> | ||
{props.item.rawValue.icon('h-4 w-4')} | ||
<Select.ItemLabel>{props.item.rawValue.label}</Select.ItemLabel> | ||
</Select.Item> | ||
)} | ||
> | ||
<Select.Trigger | ||
aria-label="toggle color mode" | ||
class="flex cursor-pointer items-center justify-center rounded-md p-2 text-gray-700 transition hover:bg-gray-100 hover:text-gray-800 dark:text-gray-300 dark:hover:bg-gray-800 dark:hover:text-gray-200" | ||
> | ||
<Select.Value<ThemeOption>> | ||
{(state) => state.selectedOption().icon('h-5 w-5')} | ||
</Select.Value> | ||
</Select.Trigger> | ||
<Select.Portal> | ||
<Select.Content class="z-50 select-none rounded border border-gray-300 bg-white p-1 shadow-md dark:border-none dark:bg-gray-800 dark:text-gray-300 dark:shadow-none"> | ||
<Select.Listbox /> | ||
</Select.Content> | ||
</Select.Portal> | ||
</Select> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
import { ComponentProps } from 'solid-js' | ||
import { ColorModeProvider, ColorModeScript } from '@kobalte/core' | ||
import { MetaProvider } from '@solidjs/meta' | ||
import { ComponentProps, Suspense } from 'solid-js' | ||
import { clx } from '#/libs/utils' | ||
|
||
interface RootLayoutProps extends ComponentProps<'div'> {} | ||
|
||
const PageLoader = () => { | ||
return ( | ||
<div class="size-full min-h-screen bg-background"> | ||
<div class="flex h-full items-center justify-center"> | ||
<h1 class="text-foreground">Loading...</h1> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const RootLayout = (props: RootLayoutProps) => { | ||
return <div class={clx('root-layout', props.class)}>{props.children}</div> | ||
return ( | ||
<MetaProvider> | ||
<Suspense fallback={<PageLoader />}> | ||
<ColorModeProvider> | ||
<div class={clx('root-layout', props.class)}>{props.children}</div> | ||
</ColorModeProvider> | ||
<ColorModeScript storageType="localStorage" /> | ||
</Suspense> | ||
</MetaProvider> | ||
) | ||
} | ||
|
||
export default RootLayout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters