Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions apps/v4/registry/new-york-v4/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -599,17 +599,25 @@ function SidebarMenuBadge({
)
}

function getSkeletonWidth(id: string) {
let hash = 0
for (const char of id) {
hash = (hash << 5) - hash + char.charCodeAt(0)
}

return `${50 + (Math.abs(hash) % 41)}%`
}

function SidebarMenuSkeleton({
className,
showIcon = false,
...props
}: React.ComponentProps<"div"> & {
showIcon?: boolean
}) {
// Random width between 50 to 90%.
const width = React.useMemo(() => {
return `${Math.floor(Math.random() * 40) + 50}%`
}, [])
// Deterministic pseudo-random width between 50 to 90%.
const id = React.useId()
const width = React.useMemo(() => getSkeletonWidth(id), [id])

return (
<div
Expand Down
16 changes: 12 additions & 4 deletions deprecated/www/registry/default/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,24 @@ const SidebarMenuBadge = React.forwardRef<
))
SidebarMenuBadge.displayName = "SidebarMenuBadge"

function getSkeletonWidth(id: string) {
let hash = 0
for (const char of id) {
hash = (hash << 5) - hash + char.charCodeAt(0)
}

return `${50 + (Math.abs(hash) % 41)}%`
}

const SidebarMenuSkeleton = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div"> & {
showIcon?: boolean
}
>(({ className, showIcon = false, ...props }, ref) => {
// Random width between 50 to 90%.
const width = React.useMemo(() => {
return `${Math.floor(Math.random() * 40) + 50}%`
}, [])
// Deterministic pseudo-random width between 50 to 90%.
const id = React.useId()
const width = React.useMemo(() => getSkeletonWidth(id), [id])

return (
<div
Expand Down
16 changes: 12 additions & 4 deletions deprecated/www/registry/new-york/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,24 @@ const SidebarMenuBadge = React.forwardRef<
))
SidebarMenuBadge.displayName = "SidebarMenuBadge"

function getSkeletonWidth(id: string) {
let hash = 0
for (const char of id) {
hash = (hash << 5) - hash + char.charCodeAt(0)
}

return `${50 + (Math.abs(hash) % 41)}%`
}

const SidebarMenuSkeleton = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div"> & {
showIcon?: boolean
}
>(({ className, showIcon = false, ...props }, ref) => {
// Random width between 50 to 90%.
const width = React.useMemo(() => {
return `${Math.floor(Math.random() * 40) + 50}%`
}, [])
// Deterministic pseudo-random width between 50 to 90%.
const id = React.useId()
const width = React.useMemo(() => getSkeletonWidth(id), [id])

return (
<div
Expand Down