Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adapt Tag to design #693

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
63 changes: 63 additions & 0 deletions lib/experimental/Layouts/Utils/DataItem/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { Meta, StoryObj } from "@storybook/react"

import { fn } from "@storybook/test"
import { DataItem } from "."

const meta: Meta = {
component: DataItem,
parameters: {
layout: "centered",
tags: ["autodocs"],
},
args: {
text: "[email protected]",
},
decorators: [
(Story) => (
<div className="w-64">
<Story />
</div>
),
],
}

export default meta
type Story = StoryObj<typeof meta>

export const Primary: Story = {}

export const Navigable: Story = {
args: {
text: "Isabella Gonzalez",
onClick: fn(),
},
}

export const NavigableWithAvatar: Story = {
args: {
text: "Isabella Gonzalez",
avatar: {
src: "https://github.com/dani-moreno.png",
alt: "I",
},
onClick: fn(),
},
}

export const NavigableWithAlt: Story = {
args: {
text: "Isabella Gonzalez",
avatar: {
alt: "I",
},
onClick: fn(),
},
}

export const NavigableWithAutoAlt: Story = {
args: {
text: "Isabella Gonzalez",
avatar: {},
onClick: fn(),
},
}
110 changes: 110 additions & 0 deletions lib/experimental/Layouts/Utils/DataItem/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { Icon } from "@/components/Utilities/Icon"
import { Avatar } from "@/experimental/Information/Avatar"
import { Check, ChevronRight, LayersFront } from "@/icons"
import { cn } from "@/lib/utils"
import { ComponentProps, forwardRef, useEffect, useState } from "react"
import { getColorFromText } from "../helper"

interface DataItemProps {
text: string
avatar?: Omit<ComponentProps<typeof Avatar>, "alt"> & {
alt?: string
}
onClick?: () => void
}

const COPIED_SHOWN_MS = 1250

export const DataItem = forwardRef<HTMLDivElement, DataItemProps>(
({ text, avatar, onClick }, ref) => {
const [copied, setCopied] = useState(false)

useEffect(() => {
if (copied) {
const timer = setTimeout(() => setCopied(false), COPIED_SHOWN_MS)

return () => clearTimeout(timer)
}
}, [copied])

const copyHandler = async () => {
try {
await navigator.clipboard.writeText(text)
setCopied(true)
} catch (error) {
void error
}
}

const handleClick = onClick ?? copyHandler

const short =
avatar?.alt ??
text
.split(/\s+/)
.slice(0, 2)
.map((e) => e[0])
.join("")
.toLocaleUpperCase()

return (
<div
ref={ref}
role="button"
className={cn(
"group relative flex w-full cursor-pointer flex-row items-center justify-between gap-1.5 rounded-sm py-1.5 pl-1.5 pr-2 font-medium text-f1-foreground transition-colors duration-300 hover:bg-f1-background-secondary",
copied
? "hover:bg-f1-background-positive"
: "hover:bg-f1-background-secondary"
)}
onClick={handleClick}
aria-label={onClick ? "Navigate" : `Copy ${text} to clipboard`}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault()
handleClick()
}
}}
tabIndex={0}
>
<div className="flex flex-row items-center gap-1.5">
{!!avatar && (
<Avatar
alt={short}
src={avatar?.src}
size="xsmall"
color={getColorFromText(text)}
/>
)}
<p>{text}</p>
</div>
{!onClick ? (
<div className="flex items-center text-f1-foreground-secondary">
<Icon
icon={LayersFront}
size="md"
className={cn(
"absolute right-1.5 opacity-0 transition-all duration-300",
!copied && "group-hover:opacity-100"
)}
/>
<Icon
icon={Check}
size="md"
className={cn(
"absolute right-1.5 opacity-0 transition-all duration-300",
copied && "group-hover:opacity-100"
)}
/>
</div>
) : (
<div className="flex items-center text-f1-foreground-secondary opacity-0 transition-all duration-300 group-hover:opacity-100">
<Icon icon={ChevronRight} size="md" />
</div>
)}
</div>
)
}
)

DataItem.displayName = "DataItem"
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
import type { Meta, StoryObj } from "@storybook/react"
import { TagsList } from "."
import { fn } from "@storybook/test"
import { DataList } from "."

const meta: Meta = {
component: TagsList,
component: DataList,
parameters: {
layout: "centered",
tags: ["autodocs"],
},
args: {
tags: [
items: [
{
text: "Management",
avatar: {
alt: "M",
},
text: "[email protected]",
},
{
text: "Engineering",
avatar: {
src: "https://github.com/dani-moreno.png",
alt: "E",
},
onClick: fn(),
},
{
text: "Managers",
avatar: {
alt: "M",
},
onClick: fn(),
},
{
text: "Office/Spain",
avatar: {
alt: "O",
},
avatar: {},
onClick: fn(),
},
{
text: "Office/Remote",
avatar: {
alt: "O",
},
},
{
text: "Engineering/Management",
avatar: {
alt: "E",
},
onClick: fn(),
},
],
},
Expand Down
20 changes: 20 additions & 0 deletions lib/experimental/Layouts/Utils/DataList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ComponentProps, forwardRef } from "react"
import { DataItem } from "../DataItem"

interface DataListProps {
items: ComponentProps<typeof DataItem>[]
}

export const DataList = forwardRef<HTMLDivElement, DataListProps>(
({ items }, ref) => {
return (
<div ref={ref} className="flex flex-col gap-0.5">
{items.map(({ ...props }, i) => (
<DataItem key={i} {...props} />
))}
</div>
)
}
)

DataList.displayName = "DataList"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ComponentProps } from "react"
import avatar from "~/storybook-assets/avatar.jpeg"
import { DetailsItemsList } from "."
import { Weekdays } from "../../../Widgets/Content/Weekdays"
import { TagsList } from "../TagsList"
import { DataList } from "../DataList"

const manager = (
<Badge text="Isabella González" avatar={{ src: avatar, alt: "I" }} />
Expand All @@ -17,8 +17,8 @@ const weekdays = (
/>
)
const teams = (
<TagsList
tags={[
<DataList
items={[
{ text: "Management", avatar: { alt: "M" } },
{ text: "Engineering", avatar: { alt: "E" } },
{ text: "Managers", avatar: { alt: "M" } },
Expand Down
44 changes: 0 additions & 44 deletions lib/experimental/Layouts/Utils/Tag/index.stories.tsx

This file was deleted.

46 changes: 0 additions & 46 deletions lib/experimental/Layouts/Utils/Tag/index.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions lib/experimental/Layouts/Utils/TagsList/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion lib/experimental/Layouts/Utils/exports.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./DataList"
export * from "./DetailsItem"
export * from "./DetailsItemsList"
export * from "./TagsList"
export * from "./VerticalSeparator"
Loading