Skip to content

Commit

Permalink
feat: preferred color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
bbohlender committed Feb 28, 2024
1 parent 02f7ad2 commit 6b96f03
Show file tree
Hide file tree
Showing 45 changed files with 212 additions and 79 deletions.
2 changes: 1 addition & 1 deletion examples/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EffectComposer, TiltShift2 } from '@react-three/postprocessing'
import { Container, Root, Text } from '@react-three/uikit'
import { Activity, CreditCard, DollarSign, Users } from '@react-three/uikit-lucide'

import { DefaultColors, colors } from '@/defaults'
import { DefaultColors, colors } from '@/theme'
import { Button } from '@/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/card'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/tabs'
Expand Down
2 changes: 1 addition & 1 deletion examples/dashboard/src/components/MainNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentPropsWithoutRef } from 'react'
import { Container, Text } from '@react-three/uikit'
import { colors } from '@/defaults'
import { colors } from '@/theme'

export function MainNav(props: Omit<ComponentPropsWithoutRef<typeof Container>, 'children'>) {
return (
Expand Down
2 changes: 1 addition & 1 deletion examples/dashboard/src/components/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Container, Text } from '@react-three/uikit'
import { colors } from '@/defaults'
import { colors } from '@/theme'

const data = [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/dashboard/src/components/RecentSales.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, Text } from '@react-three/uikit'
import { Avatar } from '@/avatar'
import { colors } from '@/defaults'
import { colors } from '@/theme'

export function RecentSales() {
return (
Expand Down
2 changes: 1 addition & 1 deletion examples/dashboard/src/components/UserNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DialogTitle,
DialogTrigger,
} from '@/dialog'
import { colors } from '@/defaults'
import { colors } from '@/theme'
import { Switch } from '@/switch'

const notifications = [
Expand Down
2 changes: 1 addition & 1 deletion examples/default/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Perf } from 'r3f-perf'

import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/accordion'
import { Alert, AlertDescription, AlertIcon, AlertTitle } from '@/alert'
import { DefaultColors, colors } from '@/defaults'
import { DefaultColors, colors } from '@/theme'
import { Avatar } from '@/avatar'
import { Badge } from '@/badge'
import { Button } from '@/button'
Expand Down
2 changes: 1 addition & 1 deletion examples/market/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Canvas } from '@react-three/fiber'
import { EffectComposer, TiltShift2 } from '@react-three/postprocessing'
import { Root, Container, Image, Text, Fullscreen, DefaultProperties } from '@react-three/uikit'
import { PlusCircle } from '@react-three/uikit-lucide'
import { DefaultColors, colors } from '@/defaults.js'
import { DefaultColors, colors } from '@/theme.js'
import { DialogAnchor } from '@/dialog.js'
import { Tabs, TabsList, TabsContent, TabsTrigger } from '@/tabs.js'
import { Separator } from '@/separator.js'
Expand Down
2 changes: 1 addition & 1 deletion examples/market/src/components/album-artwork.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Container, Text, Image } from '@react-three/uikit'
import { Album } from '../data/albums.js'
import { ComponentPropsWithoutRef } from 'react'
import { colors } from '@/defaults.js'
import { colors } from '@/theme.js'

export function AlbumArtwork({
album,
Expand Down
18 changes: 17 additions & 1 deletion examples/market/src/components/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Button } from '@/button'
import { Menubar, MenubarMenu, MenubarTrigger } from '@/menubar.js'
import { SvgIconFromText, Text } from '@react-three/uikit'
import { Container, SvgIconFromText, Text, getPreferredColorScheme, setPreferredColorScheme } from '@react-three/uikit'
import { useState } from 'react'
import { Moon, Sun, SunMoon } from '@react-three/uikit-lucide'

export function Menu() {
const [pcs, updatePCS] = useState(() => getPreferredColorScheme())
return (
<Menubar borderRadius={0} paddingX={8} lg={{ paddingX: 16 }}>
<MenubarMenu>
Expand Down Expand Up @@ -34,6 +38,18 @@ export function Menu() {
<Text>Account</Text>
</MenubarTrigger>
</MenubarMenu>
<Container flexGrow={1} />

<MenubarMenu>
<MenubarTrigger
onClick={() => {
setPreferredColorScheme(pcs === 'light' ? 'dark' : pcs === 'dark' ? 'system' : 'light')
updatePCS(getPreferredColorScheme())
}}
>
{pcs === 'dark' ? <Moon /> : pcs === 'system' ? <SunMoon /> : <Sun />}
</MenubarTrigger>
</MenubarMenu>
</Menubar>
)
}
5 changes: 3 additions & 2 deletions examples/uikit/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ export default function App() {
keepAspectRatio={false}
borderRight={100}
>
<Box>
<mesh>
<planeGeometry />
<meshPhongMaterial depthWrite={false} transparent />
</Box>
</mesh>
</Content>
<Content width={100}>
<Gltf src="example.glb" />
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useCloseDialog,
} from './dialog.js'
import { Container, DefaultProperties } from '@react-three/uikit'
import { colors } from './defaults.js'
import { colors } from './theme.js'

export const AlertDialogOverlay = DialogOverlay

Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/alert.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AllOptionalProperties, Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef, ReactNode } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const alertVariants = {
default: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/badge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AllOptionalProperties, Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const badgeVariants = {
default: {
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AllOptionalProperties, Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const buttonVariants = {
default: {
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef, ReactNode } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

export function Card({ children, ...props }: ComponentPropsWithoutRef<typeof Container>) {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Container } from '@react-three/uikit'
import { Check } from '@react-three/uikit-lucide'
import { ComponentPropsWithoutRef, useState } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

export function Checkbox({
defaultChecked,
Expand Down
38 changes: 0 additions & 38 deletions packages/kits/default/defaults.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kits/default/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Container, DefaultProperties } from '@react-three/uikit'
import { colors } from './defaults.js'
import { colors } from './theme.js'
import {
ComponentPropsWithoutRef,
ReactNode,
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/menubar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef, ReactNode } from 'react'
import { colors } from './defaults'
import { colors } from './theme'

export function MenubarMenu({ children }: { children?: ReactNode }) {
return <>{children}</>
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Container, Text } from '@react-three/uikit'
import { ChevronLeft, ChevronRight, MoreHorizontal } from '@react-three/uikit-lucide'
import { ComponentPropsWithoutRef } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

export function Pagination(props: ComponentPropsWithoutRef<typeof Container>) {
return <Container marginX="auto" flexDirection="row" width="100%" justifyContent="center" {...props} />
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/progress.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container } from '@react-three/uikit'
import { ComponentPropsWithoutRef, useMemo } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'
import { WithReactive } from '@react-three/uikit/dist/properties/utils.js'
import { computed } from '@preact/signals-core'

Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/radio-group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container } from '@react-three/uikit'
import { ComponentPropsWithoutRef, createContext, useContext, useMemo, useState } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const RadioGroupContext = createContext<{
value?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/separator.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container } from '@react-three/uikit'
import { ComponentPropsWithoutRef } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

export function Separator({
orientation = 'horizontal',
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container } from '@react-three/uikit'
import { ComponentPropsWithoutRef, useMemo, useRef } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'
import { useFrame } from '@react-three/fiber'
import { signal } from '@preact/signals-core'

Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/slider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Container, ComponentInternals } from '@react-three/uikit'
import { colors } from './defaults.js'
import { colors } from './theme.js'
import { ComponentPropsWithoutRef, useMemo, useRef, useState } from 'react'
import { EventHandlers, ThreeEvent } from '@react-three/fiber/dist/declarations/src/core/events.js'
import { Vector3 } from 'three'
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/switch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container } from '@react-three/uikit'
import { ComponentPropsWithoutRef, useState } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

export function Switch({
defaultChecked,
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef, ReactNode, createContext, useContext, useMemo, useState } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const TabsContext = createContext<{
value?: string
Expand Down
65 changes: 65 additions & 0 deletions packages/kits/default/theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { basedOnPreferredColorScheme, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef } from 'react'
import { Color } from 'three'

function hsl(h: number, s: number, l: number) {
return new Color().setHSL(h / 360, s / 100, l / 100, 'srgb')
}

export const colors = basedOnPreferredColorScheme({
light: {
background: hsl(0, 0, 100),
foreground: hsl(222.2, 84, 4.9),
card: hsl(0, 0, 1),
cardForeground: hsl(222.2, 84, 4.9),
popover: hsl(0, 0, 100),
popoverForeground: hsl(222.2, 84, 4.9),
primary: hsl(100.2, 0.774, 51.2),
primaryForeground: hsl(210, 40, 98),
secondary: hsl(210, 40, 96.1),
secondaryForeground: hsl(222.2, 47.4, 11.2),
muted: hsl(210, 40, 96.1),
mutedForeground: hsl(215.4, 16.3, 46.9),
accent: hsl(210, 40, 96.1),
accentForeground: hsl(222.2, 47.4, 11.2),
destructive: hsl(0, 72.22, 50.59),
destructiveForeground: hsl(210, 40, 98),
border: hsl(214.3, 31.8, 91.4),
input: hsl(214.3, 31.8, 91.4),
ring: hsl(222.2, 84, 4.9),
},
dark: {
background: hsl(222.2, 84, 4.9),
foreground: hsl(210, 40, 98),
card: hsl(222.2, 84, 4.9),
cardForeground: hsl(210, 40, 98),
popover: hsl(222.2, 84, 4.9),
popoverForeground: hsl(210, 40, 98),
primary: hsl(210, 40, 98),
primaryForeground: hsl(222.2, 47.4, 11.2),
secondary: hsl(217.2, 32.6, 17.5),
secondaryForeground: hsl(210, 40, 98),
muted: hsl(217.2, 32.6, 17.5),
mutedForeground: hsl(215, 20.2, 65.1),
accent: hsl(217.2, 32.6, 17.5),
accentForeground: hsl(210, 40, 98),
destructive: hsl(0, 62.8, 30.6),
destructiveForeground: hsl(210, 40, 98),
border: hsl(217.2, 32.6, 17.5),
input: hsl(217.2, 32.6, 17.5),
ring: hsl(212.7, 26.8, 83.9),
},
})

export function DefaultColors(props: ComponentPropsWithoutRef<typeof DefaultProperties>) {
return (
<DefaultProperties
scrollbarColor={colors.foreground}
scrollbarBorderRadius={4}
scrollbarOpacity={0.3}
borderColor={colors.border}
color={colors.foreground}
{...props}
/>
)
}
2 changes: 1 addition & 1 deletion packages/kits/default/toggle-group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef, createContext, useContext, useState } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const toggleVariants = {
default: {
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef, useState } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const toggleVariants = {
default: {
Expand Down
2 changes: 1 addition & 1 deletion packages/kits/default/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, DefaultProperties } from '@react-three/uikit'
import { ComponentPropsWithoutRef, createContext, useContext, useEffect, useRef, useState } from 'react'
import { colors } from './defaults.js'
import { colors } from './theme.js'

const TooltipContext = createContext<boolean>(null as any)

Expand Down
2 changes: 2 additions & 0 deletions packages/uikit/src/components/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { useRootGroupRef } from '../utils.js'
import { useApplyResponsiveProperties } from '../responsive.js'
import { Group } from 'three'
import { ElementType, OrderInfoProvider, ZIndexOffset, useOrderInfo } from '../order.js'
import { useApplyPreferredColorSchemeProperties } from '../dark.js'

export type ContainerProperties = WithConditionals<
WithClasses<
Expand Down Expand Up @@ -95,6 +96,7 @@ export const Container = forwardRef<

//apply all properties
useApplyProperties(collection, properties)
useApplyPreferredColorSchemeProperties(collection, properties)
useApplyResponsiveProperties(collection, properties)
const hoverHandlers = useApplyHoverProperties(collection, properties)
finalizeCollection(collection)
Expand Down
Loading

0 comments on commit 6b96f03

Please sign in to comment.