Files
gui/apps/sandbox/use-cases/TestAdaptSelectAndroid.tsx
zeekayandHanzo Dev 751ef5c778 rename the framework to @hanzo/gui and the loader to @hanzogui/loader
Both old names are owned by a different npm account (artemis-prime), so
publishing them returns 403 — which is how this surfaced: the 8.0.0 run
shipped @hanzogui/logo and @hanzogui/demos depending on [email protected], a
version that cannot be published and therefore does not exist. Those two
were uninstallable.

@hanzo/gui and @hanzogui/* are ours, so the framework now carries the name
it is imported by everywhere downstream, and the loader moves under the
scope we control.

The rewrite is limited to package references. `DEBUG?.startsWith('hanzogui')`
is a log-namespace filter and join(dir, 'hanzogui') is a path — rewriting
either would change behaviour, so both are untouched.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-30 20:23:18 -07:00

154 lines
4.1 KiB
TypeScript

import { Check, ChevronDown, ChevronUp } from '@hanzogui/lucide-icons-2'
import React from 'react'
import type { FontSizeTokens, SelectProps } from '@hanzo/gui'
import { Adapt, Select, Sheet, YStack, getFontSize } from '@hanzo/gui'
// Helper to get item label from value - used by renderValue for SSR
const getItemLabel = (value: string) =>
items.find((item) => item.name.toLowerCase() === value)?.name
export default function TestSelectAdapt(props: SelectProps) {
const [val, setVal] = React.useState('apple')
return (
<Select
value={val}
onValueChange={setVal}
disablePreventBodyScroll
renderValue={getItemLabel}
zIndex={200000}
{...props}
>
<Select.Trigger width={220} iconAfter={ChevronDown}>
<Select.Value placeholder="Something" />
</Select.Trigger>
<Adapt when="maxMd" platform="touch">
<Sheet
native={!!props.native}
modal
dismissOnSnapToBottom
animationConfig={{
type: 'spring',
damping: 20,
mass: 1.2,
stiffness: 250,
}}
>
<Sheet.Frame>
<Sheet.ScrollView>
<Adapt.Contents />
</Sheet.ScrollView>
</Sheet.Frame>
<Sheet.Overlay
transition="quick"
enterStyle={{ opacity: 0 }}
exitStyle={{ opacity: 0 }}
/>
</Sheet>
</Adapt>
<Select.Content>
<Select.ScrollUpButton
items="center"
justify="center"
position="relative"
width="100%"
height="$3"
>
<YStack z={10}>
<ChevronUp size={20} />
</YStack>
</Select.ScrollUpButton>
<Select.Viewport
// to do animations:
// transition="quick"
// animateOnly={['transform', 'opacity']}
// enterStyle={{ o: 0, y: -10 }}
// exitStyle={{ o: 0, y: 10 }}
minW={200}
>
<Select.Group>
<Select.Label>Fruits</Select.Label>
{/* for longer lists memoizing these is useful */}
{React.useMemo(
() =>
items.map((item, i) => {
return (
<Select.Item
index={i}
key={item.name}
value={item.name.toLowerCase()}
>
<Select.ItemText>{item.name}</Select.ItemText>
<Select.ItemIndicator marginLeft="auto">
<Check size={16} />
</Select.ItemIndicator>
</Select.Item>
)
}),
[items]
)}
</Select.Group>
{/* Native gets an extra icon */}
{props.native && (
<YStack
position="absolute"
r={0}
t={0}
b={0}
items="center"
justify="center"
width="$4"
pointerEvents="none"
>
<ChevronDown
size={getFontSize((props.size as FontSizeTokens) ?? '$true')}
/>
</YStack>
)}
</Select.Viewport>
<Select.ScrollDownButton
items="center"
justify="center"
position="relative"
width="100%"
height="$3"
>
<YStack z={10}>
<ChevronDown size={20} />
</YStack>
</Select.ScrollDownButton>
</Select.Content>
</Select>
)
}
const items = [
{ name: 'Apple' },
{ name: 'Pear' },
{ name: 'Blackberry' },
{ name: 'Peach' },
{ name: 'Apricot' },
{ name: 'Melon' },
{ name: 'Honeydew' },
{ name: 'Starfruit' },
{ name: 'Blueberry' },
{ name: 'Raspberry' },
{ name: 'Strawberry' },
{ name: 'Mango' },
{ name: 'Pineapple' },
{ name: 'Lime' },
{ name: 'Lemon' },
{ name: 'Coconut' },
{ name: 'Guava' },
{ name: 'Papaya' },
{ name: 'Orange' },
{ name: 'Grape' },
{ name: 'Jackfruit' },
{ name: 'Durian' },
]