diff --git a/lib/experimental/Layouts/Utils/DataItem/index.stories.tsx b/lib/experimental/Layouts/Utils/DataItem/index.stories.tsx new file mode 100644 index 00000000..107cc2bd --- /dev/null +++ b/lib/experimental/Layouts/Utils/DataItem/index.stories.tsx @@ -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: "fake.employee@factorial.co", + }, + decorators: [ + (Story) => ( +
+ +
+ ), + ], +} + +export default meta +type Story = StoryObj + +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(), + }, +} diff --git a/lib/experimental/Layouts/Utils/DataItem/index.tsx b/lib/experimental/Layouts/Utils/DataItem/index.tsx new file mode 100644 index 00000000..cdb5fb9f --- /dev/null +++ b/lib/experimental/Layouts/Utils/DataItem/index.tsx @@ -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, "alt"> & { + alt?: string + } + onClick?: () => void +} + +const COPIED_SHOWN_MS = 1250 + +export const DataItem = forwardRef( + ({ 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 ( +
{ + if (e.key === "Enter" || e.key === " ") { + e.preventDefault() + handleClick() + } + }} + tabIndex={0} + > +
+ {!!avatar && ( + + )} +

{text}

+
+ {!onClick ? ( +
+ + +
+ ) : ( +
+ +
+ )} +
+ ) + } +) + +DataItem.displayName = "DataItem" diff --git a/lib/experimental/Layouts/Utils/TagsList/index.stories.tsx b/lib/experimental/Layouts/Utils/DataList/index.stories.tsx similarity index 65% rename from lib/experimental/Layouts/Utils/TagsList/index.stories.tsx rename to lib/experimental/Layouts/Utils/DataList/index.stories.tsx index 6a74603a..dd30272a 100644 --- a/lib/experimental/Layouts/Utils/TagsList/index.stories.tsx +++ b/lib/experimental/Layouts/Utils/DataList/index.stories.tsx @@ -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: "fake.email@factorial.co", }, { 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(), }, ], }, diff --git a/lib/experimental/Layouts/Utils/DataList/index.tsx b/lib/experimental/Layouts/Utils/DataList/index.tsx new file mode 100644 index 00000000..62ac39f3 --- /dev/null +++ b/lib/experimental/Layouts/Utils/DataList/index.tsx @@ -0,0 +1,20 @@ +import { ComponentProps, forwardRef } from "react" +import { DataItem } from "../DataItem" + +interface DataListProps { + items: ComponentProps[] +} + +export const DataList = forwardRef( + ({ items }, ref) => { + return ( +
+ {items.map(({ ...props }, i) => ( + + ))} +
+ ) + } +) + +DataList.displayName = "DataList" diff --git a/lib/experimental/Layouts/Utils/DetailsItemsList/index.stories.tsx b/lib/experimental/Layouts/Utils/DetailsItemsList/index.stories.tsx index b7c91f52..47792e85 100644 --- a/lib/experimental/Layouts/Utils/DetailsItemsList/index.stories.tsx +++ b/lib/experimental/Layouts/Utils/DetailsItemsList/index.stories.tsx @@ -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 = ( @@ -17,8 +17,8 @@ const weekdays = ( /> ) const teams = ( - - -export const Primary: Story = {} - -export const Avatar: Story = { - args: { - avatar: { - src: "https://github.com/dani-moreno.png", - alt: "I", - }, - }, -} - -export const Clickable: Story = { - args: { - onClick: fn(), - }, -} - -export const Alt: Story = { - args: { - avatar: undefined, - }, -} diff --git a/lib/experimental/Layouts/Utils/Tag/index.tsx b/lib/experimental/Layouts/Utils/Tag/index.tsx deleted file mode 100644 index a224f019..00000000 --- a/lib/experimental/Layouts/Utils/Tag/index.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { Avatar } from "@/experimental/Information/Avatar" -import { cn } from "@/lib/utils" -import { ComponentProps, forwardRef } from "react" -import { getColorFromText } from "../helper" - -interface TagProps { - text: string - avatar?: ComponentProps - onClick?: () => void -} - -export const Tag = forwardRef( - ({ text, avatar, onClick }, ref) => { - const short = - avatar?.alt ?? - text - .split(/\s+/) - .slice(0, 2) - .map((e) => e[0]) - .join("") - .toLocaleUpperCase() - - return ( -
- - - -

{text}

-
- ) - } -) - -Tag.displayName = "Tag" diff --git a/lib/experimental/Layouts/Utils/TagsList/index.tsx b/lib/experimental/Layouts/Utils/TagsList/index.tsx deleted file mode 100644 index f40c2606..00000000 --- a/lib/experimental/Layouts/Utils/TagsList/index.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { ComponentProps, forwardRef } from "react" -import { Tag } from "../Tag" - -interface TagsListProps { - tags: ComponentProps[] -} - -export const TagsList = forwardRef( - ({ tags }, ref) => { - return ( -
- {tags.map(({ ...props }, i) => ( - - ))} -
- ) - } -) - -TagsList.displayName = "TagsList" diff --git a/lib/experimental/Layouts/Utils/exports.tsx b/lib/experimental/Layouts/Utils/exports.tsx index 263b03f6..168e103c 100644 --- a/lib/experimental/Layouts/Utils/exports.tsx +++ b/lib/experimental/Layouts/Utils/exports.tsx @@ -1,4 +1,4 @@ +export * from "./DataList" export * from "./DetailsItem" export * from "./DetailsItemsList" -export * from "./TagsList" export * from "./VerticalSeparator"