Files
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

137 lines
4.0 KiB
TypeScript

import React, { ElementType } from 'react'
import { Check, ChevronDown, ChevronUp } from '@hanzogui/lucide-icons-2'
import type { FontSizeTokens, SelectProps } from '@hanzo/gui'
import { Adapt, Label, Select, Sheet, XStack, YStack, getFontSize } from '@hanzo/gui'
import { LinearGradient } from '@hanzogui/linear-gradient'
import { type Href, usePathname, useRouter } from 'one'
export function VersionSwitcher({ versions }: { versions: { name: string }[] }) {
return (
<YStack gap="$4">
<XStack width="100%" items="center" gap="$4">
<VersionSwitcherItem versions={versions} />
</XStack>
</YStack>
)
}
export function VersionSwitcherItem({ versions }: { versions: { name: string }[] }) {
const router = useRouter()
const pathname = usePathname()
const [val, setVal] = React.useState(
() => pathname.split('/').pop() ?? versions[0].name
)
const switchVersion = (version: string) => {
setVal(version)
const noSlash = pathname.replace(/\/$/, '')
const rootPath = noSlash.replace(/\/\d+\.\d+\.\d+$/, '')
if (version === versions[0].name) return
const newPathname = `${rootPath}/${version}`
router.push(newPathname as Href)
}
return (
<Select
value={val}
onValueChange={switchVersion}
disablePreventBodyScroll
zIndex={200000}
>
<Select.Trigger maxWidth={220} iconAfter={ChevronDown} borderRadius={8}>
<Select.Value placeholder="2.0.0" />
</Select.Trigger>
<Adapt when="maxMd" platform="touch">
<Sheet modal dismissOnSnapToBottom transition="medium">
<Sheet.Frame>
<Sheet.ScrollView>
<Adapt.Contents />
</Sheet.ScrollView>
</Sheet.Frame>
<Sheet.Overlay
backgroundColor="$shadowColor"
transition="lazy"
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>
<LinearGradient
start={[0, 0]}
end={[0, 1]}
fullscreen
colors={['$background', 'transparent']}
rounded="$4"
/>
</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>Versions</Select.Label>
{/* for longer lists memoizing these is useful */}
{React.useMemo(
() =>
versions.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>
)
}),
[versions]
)}
</Select.Group>
</Select.Viewport>
<Select.ScrollDownButton
items="center"
justify="center"
position="relative"
width="100%"
height="$3"
>
<YStack z={10}>
<ChevronDown size={20} />
</YStack>
<LinearGradient
start={[0, 0]}
end={[0, 1]}
fullscreen
colors={['transparent', '$background']}
rounded="$4"
/>
</Select.ScrollDownButton>
</Select.Content>
</Select>
)
}