Skip to content

Commit

Permalink
drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-moreno committed Jan 16, 2025
1 parent 25b5853 commit f30b459
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/experimental/Information/Headers/BaseHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function BaseHeader({
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 md:hidden">
{metadata && <Metadata items={allMetadata} />}
</div>
<div className="flex w-full shrink-0 flex-wrap items-center gap-x-3 gap-y-4 md:w-fit md:flex-row-reverse md:gap-y-2 md:overflow-x-auto">
<div className="flex w-full shrink-0 flex-wrap items-center gap-x-2 gap-y-3 md:w-fit md:flex-row-reverse md:gap-y-2 md:overflow-x-auto">
{primaryAction && (
<>
<div className="hidden md:block">
Expand All @@ -107,7 +107,7 @@ export function BaseHeader({
</>
)}
{primaryAction && (secondaryActions || otherActions) && (
<div className="hidden h-4 w-px bg-f1-background-secondary md:block" />
<div className="mx-1 hidden h-4 w-px bg-f1-background-secondary md:block" />
)}
{secondaryActions &&
secondaryActions.map((action) => (
Expand Down
28 changes: 25 additions & 3 deletions lib/experimental/Information/Headers/Metadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
StatusTag,
StatusVariant,
} from "@/experimental/Information/Tags/StatusTag"
import { MobileDropdown } from "@/experimental/Navigation/Dropdown"
import { Tooltip } from "@/experimental/Overlays/Tooltip"
import { cn } from "@/lib/utils"
import { AnimatePresence, motion } from "framer-motion"
Expand Down Expand Up @@ -53,6 +54,7 @@ function renderMetadataValue(item: MetadataItem) {
function MetadataItem({ item }: { item: MetadataItem }) {
const [isActive, setIsActive] = useState(false)
const isAction = item.actions?.length
const metadataValue = renderMetadataValue(item)

return (
<div className="flex h-8 items-center gap-2">
Expand All @@ -68,9 +70,29 @@ function MetadataItem({ item }: { item: MetadataItem }) {
onBlur={() => isAction && setIsActive(false)}
className="relative flex h-5 w-fit items-center hover:cursor-default"
>
<div className="font-medium text-f1-foreground">
{renderMetadataValue(item)}
<div
className={cn(
"hidden font-medium text-f1-foreground md:block",
!isAction && "block"
)}
>
{metadataValue}
</div>
{isAction && (
<div className="w-full md:hidden">
<MobileDropdown
items={
item.actions?.map((action) => ({
label: action.label,
icon: action.icon,
onClick: action.onClick,
})) ?? []
}
>
{metadataValue}
</MobileDropdown>
</div>
)}
<AnimatePresence>
{isActive && isAction && (
<motion.div
Expand All @@ -84,7 +106,7 @@ function MetadataItem({ item }: { item: MetadataItem }) {
transition={{ duration: 0.1 }}
>
<div className="flex h-5 items-center font-medium text-f1-foreground">
{renderMetadataValue(item)}
{metadataValue}
</div>
{isAction && (
<motion.div
Expand Down
44 changes: 31 additions & 13 deletions lib/experimental/Navigation/Dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, ButtonProps } from "@/components/Actions/Button"
import { IconType } from "@/components/Utilities/Icon"
import { Icon, IconType } from "@/components/Utilities/Icon"
import { AvatarVariant } from "@/experimental/Information/Avatars/utils"
import { Ellipsis, EllipsisHorizontal } from "@/icons/app"
import { EllipsisHorizontal } from "@/icons/app"
import { Link } from "@/lib/linkHandler"
import { cn } from "@/lib/utils"
import {
Expand All @@ -17,7 +17,6 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/ui/dropdown-menu"
import { Separator } from "@/ui/separator"
import { useState } from "react"
import { NavigationItem } from "../utils"
import { DropdownItemContent } from "./DropdownItem"
Expand Down Expand Up @@ -71,7 +70,7 @@ const DropdownItem = ({ item }: { item: DropdownItemObject }) => {

export function Dropdown({
items,
icon = Ellipsis,
icon = EllipsisHorizontal,
size,
children,
}: DropdownProps) {
Expand All @@ -89,7 +88,7 @@ export function Dropdown({
/>
)}
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuContent align="start">
{items.map((item, index) =>
item === "separator" ? (
<DropdownMenuSeparator key={index} />
Expand Down Expand Up @@ -121,10 +120,13 @@ export const MobileDropdown = ({ items, children }: DropdownProps) => {
</DrawerTrigger>
<DrawerOverlay className="bg-f1-background-overlay" />
<DrawerContent className="bg-f1-background">
<div className="flex flex-col gap-2 p-4">
<div className="flex flex-col px-2 pb-3 pt-2">
{items.map((item, index) =>
item === "separator" ? (
<Separator key={`separator-${index}`} />
<div
key={`separator-${index}`}
className="mx-[-8px] my-2 h-px w-[calc(100%+16px)] bg-f1-border-secondary"
/>
) : item.href ? (
<Link
{...item}
Expand All @@ -138,17 +140,33 @@ export const MobileDropdown = ({ items, children }: DropdownProps) => {
<DropdownItemContent item={item} />
</Link>
) : (
<Button
<button
key={item.label}
label={item.label}
onClick={() => {
item.onClick?.()
setOpen(false)
}}
variant={item.critical ? "critical" : "outline"}
icon={item.icon}
size="lg"
/>
className="flex w-full items-center gap-2 p-3"
>
{item.icon && (
<span
className={cn(
"h-5 w-5 text-f1-icon",
item.critical && "text-f1-icon-critical"
)}
>
<Icon icon={item.icon} size="md" />
</span>
)}
<span
className={cn(
"font-medium",
item.critical && "text-f1-foreground-critical"
)}
>
{item.label}
</span>
</button>
)
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const DrawerContent = React.forwardRef<
<DrawerPrimitive.Content
ref={ref}
className={cn(
"bg-background fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border",
"bg-background fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-xl",
className
)}
{...props}
>
<div className="bg-muted mx-auto mt-4 h-2 w-[100px] rounded-full" />
<div className="mx-auto mt-2 h-1 w-8 rounded-full bg-f1-border" />
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const DropdownMenuItem = React.forwardRef<
<DropdownMenuPrimitive.Item
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded px-3 py-2 text-base font-medium outline-none transition-colors after:absolute after:inset-x-1 after:inset-y-0 after:h-full after:rounded after:bg-f1-background-hover after:opacity-0 after:transition-opacity after:duration-75 after:content-[''] first:pt-3 first:after:top-1 first:after:h-[calc(100%-0.25rem)] last:pb-3 last:after:bottom-1 last:after:h-[calc(100%-0.25rem)] hover:after:opacity-100 focus:after:opacity-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"relative flex cursor-default select-none items-center rounded py-2 pl-3 pr-5 text-base font-medium outline-none transition-colors after:absolute after:inset-x-1 after:inset-y-0 after:h-full after:rounded after:bg-f1-background-hover after:opacity-0 after:transition-opacity after:duration-75 after:content-[''] first:pt-3 first:after:top-1 first:after:h-[calc(100%-0.25rem)] last:pb-3 last:after:bottom-1 last:after:h-[calc(100%-0.25rem)] hover:after:opacity-100 focus:after:opacity-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"focus:outline-none focus:ring-0 focus:ring-transparent", // Temporal fix for Gamma issue
inset && "pl-8",
className
Expand Down

0 comments on commit f30b459

Please sign in to comment.