From 17ef1c386a043e5d3d7767a5bfe3ac364561deed Mon Sep 17 00:00:00 2001 From: Bela Bohlender Date: Tue, 5 Mar 2024 18:58:12 +0100 Subject: [PATCH] feat: ui for selecting and installing apfel component --- examples/apfel/src/App.tsx | 148 ++++++++++++++++++++++++++--------- packages/kits/apfel/card.tsx | 1 + packages/kits/apfel/tabs.tsx | 38 ++++----- 3 files changed, 129 insertions(+), 58 deletions(-) diff --git a/examples/apfel/src/App.tsx b/examples/apfel/src/App.tsx index 2fef0fb6..75ac3fd7 100644 --- a/examples/apfel/src/App.tsx +++ b/examples/apfel/src/App.tsx @@ -1,7 +1,6 @@ import { Canvas } from '@react-three/fiber' -import { Fullscreen, Text, Container, setPreferredColorScheme } from '@react-three/uikit' -import { BoxSelect, ChevronRight, Info } from '@react-three/uikit-lucide' -import { Perf } from 'r3f-perf' +import { Fullscreen, Text, Container } from '@react-three/uikit' +import { BoxSelect, ChevronRight, Copy, Info } from '@react-three/uikit-lucide' import { XWebPointers, noEvents } from '@coconut-xr/xinteraction/react' import { Card } from '@/card' import { Checkbox } from '@/checkbox' @@ -13,28 +12,82 @@ import { Loading } from '@/loading' import { Slider } from '@/slider' import { TabBar, TabBarItem } from '@/tab-bar' import { Defaults } from '@/theme' +import { useState } from 'react' + +const componentPages = { + card: CardPage, + checkbox: CheckboxesPage, + button: ButtonsPage, + list: ListsPage, + slider: SlidersPage, + tabs: TabsPage, + tabBar: TabBarsPage, + progress: ProgressPage, + loading: LoadingPage, +} +const defaultComponent = 'button' export default function App() { + const [component, set] = useState(() => { + const params = new URLSearchParams(window.location.search) + let selected = params.get('component') + if (selected == null || !(selected in componentPages)) { + selected = defaultComponent + } + return selected as keyof typeof componentPages + }) + const setComponent = (value: keyof typeof componentPages) => { + const params = new URLSearchParams(window.location.search) + params.set('component', value) + history.replaceState(null, '', '?' + params.toString()) + set(value) + } + const ComponentPage = componentPages[component] return ( - - - - - + + + + + {Object.keys(componentPages).map((name) => ( + + + {name[0].toUpperCase()} + {name.slice(1)} + + + ))} + + + + - - + + + + npx uikit component add apfel {component} + + + + + ) } @@ -48,9 +101,20 @@ export function CheckboxesPage() { ) } +export function CardPage() { + return ( + + Hello World! + + This is the apfel kit. + + + ) +} + export function ButtonsPage() { return ( - + @@ -227,8 +291,8 @@ export function ButtonsPage() { export function ListsPage() { return ( - - + + - + - - - - - - - - - - - - - + + + + + + + + ) +} + +export function LoadingPage() { + return ( + + + + + ) } -export function SegmentedControlsPage() { +export function TabsPage() { return ( @@ -432,7 +499,14 @@ export function SegmentedControlsPage() { export function SlidersPage() { return ( - + diff --git a/packages/kits/apfel/card.tsx b/packages/kits/apfel/card.tsx index 1cddda1d..a906e63c 100644 --- a/packages/kits/apfel/card.tsx +++ b/packages/kits/apfel/card.tsx @@ -12,6 +12,7 @@ export function Card({ children, ...props }: ComponentPropsWithoutRef {children} diff --git a/packages/kits/apfel/tabs.tsx b/packages/kits/apfel/tabs.tsx index ca39efb1..a2c79446 100644 --- a/packages/kits/apfel/tabs.tsx +++ b/packages/kits/apfel/tabs.tsx @@ -46,11 +46,11 @@ export function Tabs({ & export function TabsButton({ children, value, disabled, ...props }: SegmentedControlButtonProps) { const { value: currentValue, onValueChange, disabled: tabsDisabled } = useContext(TabsContext) as TabsContext + const selected = currentValue === value && !tabsDisabled + return ( { @@ -81,25 +82,20 @@ export function TabsButton({ children, value, disabled, ...props }: SegmentedCon onValueChange?.(value) props.onClick?.(e) }} + backgroundColor={colors.foreground} + borderColor={colors.foreground} + backgroundOpacity={selected ? 0.3 : 0} + borderOpacity={selected ? 0.3 : 0} + border={2} + borderRadius={16} + borderBend={0.3} + backgroundMaterialClass={GlassMaterial} + flexDirection="row" + alignItems="center" + gapColumn={10} > - {currentValue === value && !tabsDisabled && ( - - )} - - - {children} - + + {children} )