mirror of
https://github.com/hanzoai/gui.git
synced 2026-10-25 02:31:41 +00:00
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]>
135 lines
3.9 KiB
TypeScript
135 lines
3.9 KiB
TypeScript
import { LinearGradient } from '@hanzogui/linear-gradient'
|
|
import { Check, ChevronDown, ChevronUp } from '@hanzogui/lucide-icons-2'
|
|
import { type Href, router, useParams, usePathname } from 'one'
|
|
import React from 'react'
|
|
import { Adapt, Select, Sheet, YStack } from '@hanzo/gui'
|
|
|
|
export function SourceVersionSwitcher({
|
|
versions,
|
|
componentName,
|
|
}: {
|
|
versions: string[]
|
|
componentName: string
|
|
}) {
|
|
const pathname = usePathname()
|
|
const params = useParams<{ subpath?: string | string[] }>()
|
|
|
|
// Get current version from pathname
|
|
const currentVersion = React.useMemo(() => {
|
|
if (!params.subpath) return versions[0]
|
|
|
|
// params.subpath is an array like ["button", "1.28.0"] or ["button"]
|
|
const subpathArray = Array.isArray(params.subpath) ? params.subpath : [params.subpath]
|
|
|
|
// If there's a second element, it's the version
|
|
return subpathArray.length > 1 ? subpathArray[1] : versions[0]
|
|
}, [params.subpath, versions])
|
|
|
|
const switchVersion = (version: string) => {
|
|
// Navigate to /ui/{componentName}/{version}
|
|
const newPath =
|
|
version === versions[0] ? `/ui/${componentName}` : `/ui/${componentName}/${version}`
|
|
router.push(newPath as Href)
|
|
}
|
|
|
|
// Don't render if only one version
|
|
if (versions.length <= 1) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<Select
|
|
value={currentVersion}
|
|
onValueChange={switchVersion}
|
|
disablePreventBodyScroll
|
|
zIndex={200000}
|
|
>
|
|
<Select.Trigger size="$2" iconAfter={ChevronDown} borderRadius={8}>
|
|
<Select.Value placeholder={versions[0]} fontFamily="$mono" />
|
|
</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
|
|
minW={200}
|
|
borderWidth={1}
|
|
borderColor="$borderColor"
|
|
elevation="$3"
|
|
borderRadius="$4"
|
|
>
|
|
<Select.Group>
|
|
<Select.Label>Source Version</Select.Label>
|
|
{React.useMemo(
|
|
() =>
|
|
versions.map((version, i) => {
|
|
return (
|
|
<Select.Item index={i} key={version} value={version}>
|
|
<Select.ItemText fontFamily="$mono">{version}</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>
|
|
)
|
|
}
|