-
Notifications
You must be signed in to change notification settings - Fork 1
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
Create PersonListItem component #1071
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Check, Placeholder } from "@/icons/app" | ||
import type { Meta, StoryObj } from "@storybook/react" | ||
import { PersonListItem } from "./index" | ||
|
||
const meta = { | ||
title: "Experimental/Lists/PersonListItem", | ||
component: PersonListItem, | ||
tags: ["autodocs"], | ||
} satisfies Meta<typeof PersonListItem> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof PersonListItem> | ||
|
||
export const Default: Story = { | ||
args: { | ||
person: { | ||
firstName: "John", | ||
lastName: "Smith", | ||
avatarUrl: "https://i.pravatar.cc/300", | ||
avatarBadge: { | ||
icon: Check, | ||
type: "positive", | ||
}, | ||
}, | ||
description: "Software Engineer", | ||
rightTag: { | ||
text: "Parental leave", | ||
color: "army", | ||
}, | ||
}, | ||
} | ||
|
||
export const WithActions: Story = { | ||
args: { | ||
person: { | ||
firstName: "Sarah", | ||
lastName: "Johnson", | ||
avatarUrl: "https://i.pravatar.cc/300", | ||
}, | ||
description: "Product Designer", | ||
actions: { | ||
primary: { | ||
icon: Placeholder, | ||
label: "Message", | ||
onClick: () => console.log("Primary action clicked"), | ||
}, | ||
secondary: { | ||
icon: Placeholder, | ||
onClick: () => console.log("Secondary action clicked"), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const WithTags: Story = { | ||
args: { | ||
person: { | ||
firstName: "Emma", | ||
lastName: "Wilson", | ||
avatarUrl: "https://i.pravatar.cc/300", | ||
}, | ||
bottomTags: [ | ||
{ text: "Label", icon: Placeholder }, | ||
{ text: "Label", icon: Placeholder }, | ||
{ text: "Label", icon: Placeholder }, | ||
{ text: "Label", icon: Placeholder }, | ||
], | ||
}, | ||
} | ||
|
||
export const Minimal: Story = { | ||
args: { | ||
person: { | ||
firstName: "Emma", | ||
lastName: "Wilson", | ||
avatarUrl: "https://i.pravatar.cc/300", | ||
}, | ||
description: "Software Engineer", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Button } from "@/components/Actions/Button" | ||
import { Icon, IconType } from "@/components/Utilities/Icon" | ||
import { BadgeProps } from "@/experimental/exports" | ||
import { PersonAvatar } from "@/experimental/Information/Avatars/PersonAvatar" | ||
import { DotTag, DotTagProps } from "@/experimental/Information/Tags/DotTag" | ||
import { RawTag, RawTagProps } from "@/experimental/Information/Tags/RawTag" | ||
import { InfoCircle } from "@/icons/app" | ||
import React from "react" | ||
|
||
export type PersonListItemProps = { | ||
person: { | ||
firstName: string | ||
lastName: string | ||
avatarUrl?: string | ||
avatarBadge?: Omit<BadgeProps, "size"> | ||
} | ||
description?: string | ||
bottomTags: Omit<RawTagProps, "noBorder">[] | ||
rightTag?: DotTagProps | ||
actions?: { | ||
primary?: { | ||
icon?: IconType | ||
label: string | ||
onClick: () => void | ||
} | ||
secondary?: { | ||
icon: IconType | ||
onClick: () => void | ||
} | ||
} | ||
onClick: () => void | ||
} | ||
|
||
export const PersonListItem = React.forwardRef< | ||
HTMLDivElement, | ||
PersonListItemProps | ||
>(({ person, onClick, ...props }, ref) => { | ||
const handleClick = () => { | ||
onClick() | ||
} | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
className="flex w-full flex-row flex-wrap items-center gap-2 rounded-md border p-2 hover:bg-f1-background-hover focus:outline focus:outline-1 focus:outline-offset-1 focus:outline-f1-border-selected-bold" | ||
onClick={handleClick} | ||
> | ||
<PersonAvatar | ||
firstName={person.firstName} | ||
lastName={person.lastName} | ||
src={person.avatarUrl} | ||
badge={person.avatarBadge} | ||
/> | ||
|
||
<div className="flex flex-1 flex-col"> | ||
<div className="flex flex-1 flex-row items-center gap-1"> | ||
<span className="truncate font-medium">{`${person.firstName} ${person.lastName}`}</span> | ||
<Icon | ||
icon={InfoCircle} | ||
size="sm" | ||
className="text-f1-icon-secondary" | ||
/> | ||
</div> | ||
{"bottomTags" in props && ( | ||
<div className="-ml-1.5 flex flex-row items-center text-f1-foreground-secondary [&>div]:-mr-1"> | ||
{props.bottomTags.map((tag, i) => ( | ||
<> | ||
<RawTag key={tag.text} {...tag} noBorder /> | ||
{i < props.bottomTags.length - 1 && <span>·</span>} | ||
</> | ||
))} | ||
</div> | ||
)} | ||
{"description" in props && props.description && ( | ||
<p className="truncate text-f1-foreground-secondary"> | ||
{props.description} | ||
</p> | ||
)} | ||
</div> | ||
|
||
<div className="flex flex-row items-center justify-between gap-2"> | ||
{"rightTag" in props && props.rightTag && ( | ||
<DotTag {...props.rightTag} /> | ||
)} | ||
{"actions" in props && ( | ||
<div className="flex flex-1 flex-row items-center justify-end gap-2"> | ||
{props.actions?.primary && ( | ||
<Button | ||
variant="outline" | ||
onClick={props.actions.primary.onClick} | ||
label={props.actions.primary.label} | ||
icon={props.actions.primary.icon} | ||
/> | ||
)} | ||
|
||
{props.actions?.secondary && ( | ||
<Button | ||
variant="outline" | ||
onClick={props.actions.secondary.onClick} | ||
label="Secondary" | ||
icon={props.actions.secondary.icon} | ||
hideLabel | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
}) | ||
|
||
PersonListItem.displayName = "PersonListItem" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we simplify the type? I am lost with logical AND and OR props, it's quite puzzling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure, I'll try to simplify it