mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
94 lines
2.8 KiB
TypeScript
94 lines
2.8 KiB
TypeScript
import { BoxesIcon, BoxIcon } from 'lucide-react'
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { Badge, cn } from 'ui'
|
|
|
|
import { OrganizationsData } from '@/data/organizations/organizations-query'
|
|
import { useProjectDetailQuery } from '@/data/projects/project-detail-query'
|
|
|
|
export interface ResourceAccessPillItem {
|
|
key: string
|
|
label: string
|
|
isInaccessible?: boolean
|
|
}
|
|
|
|
export const OrganizationAccessPill = ({
|
|
slug,
|
|
organization,
|
|
}: {
|
|
slug: string
|
|
organization: OrganizationsData[number] | undefined
|
|
}) => {
|
|
const isInaccessible = organization == null
|
|
return (
|
|
<Badge
|
|
variant={isInaccessible ? 'destructive' : 'default'}
|
|
className={cn('normal-case text-xs font-normal tracking-normal pr-2', {
|
|
'border-destructive-500': isInaccessible,
|
|
'text-foreground': !isInaccessible,
|
|
})}
|
|
>
|
|
<BoxesIcon
|
|
size={14}
|
|
strokeWidth={1.5}
|
|
className={cn('shrink-0', {
|
|
'text-foreground-lighter': !isInaccessible,
|
|
})}
|
|
/>
|
|
{organization?.name ?? slug}
|
|
{isInaccessible ? <span role="status"> - revoked</span> : null}
|
|
</Badge>
|
|
)
|
|
}
|
|
|
|
export const ProjectAccessPill = ({ projectRef }: { projectRef: string }) => {
|
|
const { data: project, isPending } = useProjectDetailQuery({ ref: projectRef })
|
|
const isInaccessible = project == null && !isPending
|
|
return (
|
|
<Badge
|
|
variant={isInaccessible ? 'destructive' : 'default'}
|
|
className={cn('normal-case text-xs font-normal tracking-normal pr-2', {
|
|
'border-destructive-500': isInaccessible,
|
|
'text-foreground': !isInaccessible,
|
|
})}
|
|
>
|
|
<BoxIcon
|
|
size={14}
|
|
strokeWidth={1.5}
|
|
className={cn('shrink-0', {
|
|
'text-foreground-lighter': !isInaccessible,
|
|
})}
|
|
/>
|
|
{project?.name ?? projectRef}
|
|
{isInaccessible ? <span role="status"> - revoked</span> : null}
|
|
</Badge>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Whether the pill container has wrapped onto multiple lines. Vertically centering the row only
|
|
* reads right when its badges fit on a single line — with wrapped badges the label should sit at
|
|
* the top instead. Measured, not guessed from item count, since wrapping depends on the sheet's
|
|
* width and each badge's label length.
|
|
*/
|
|
export const useResourceAccessWrap = () => {
|
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
const [isWrapped, setIsWrapped] = useState(false)
|
|
|
|
useEffect(() => {
|
|
const container = containerRef.current
|
|
if (!container) return
|
|
|
|
const checkWrapped = () => {
|
|
const firstBadge = container.firstElementChild as HTMLElement | null
|
|
setIsWrapped(firstBadge !== null && container.clientHeight > firstBadge.clientHeight + 2)
|
|
}
|
|
|
|
checkWrapped()
|
|
const observer = new ResizeObserver(checkWrapped)
|
|
observer.observe(container)
|
|
return () => observer.disconnect()
|
|
}, [])
|
|
|
|
return { containerRef, isWrapped }
|
|
}
|