forked from PrefectHQ/prefect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] Refactor parts of variables components (PrefectHQ#16084)
- Loading branch information
1 parent
f2221ba
commit 28fd4c3
Showing
26 changed files
with
957 additions
and
651 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
dist | ||
dist-ssr | ||
*.local | ||
.vite | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
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
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,25 @@ | ||
import { TagBadgeGroup } from "@/components/ui/tag-badge-group.tsx"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import type { ComponentProps } from "react"; | ||
|
||
export default { | ||
title: "UI/TagBadgeGroup", | ||
component: TagBadgeGroup, | ||
args: { | ||
tags: [], | ||
}, | ||
// To control input value in Stories via useState() | ||
render: function Render(args: ComponentProps<typeof TagBadgeGroup>) { | ||
return <TagBadgeGroup {...args} />; | ||
}, | ||
} satisfies Meta<typeof TagBadgeGroup>; | ||
|
||
type Story = StoryObj<typeof TagBadgeGroup>; | ||
|
||
export const TwoTags: Story = { | ||
args: { tags: ["testTag", "testTag2"] }, | ||
}; | ||
|
||
export const FourTags: Story = { | ||
args: { tags: ["testTag", "testTag2", "testTag3", "testTag4"] }, | ||
}; |
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,57 @@ | ||
import { Badge, type BadgeProps } from "./badge"; | ||
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./hover-card"; | ||
import { TagBadge } from "./tag-badge"; | ||
|
||
type TagBadgeGroupProps = { | ||
tags: string[]; | ||
variant?: BadgeProps["variant"]; | ||
maxTagsDisplayed?: number; | ||
onTagsChange?: (tags: string[]) => void; | ||
}; | ||
|
||
export const TagBadgeGroup = ({ | ||
tags, | ||
variant, | ||
maxTagsDisplayed = 2, | ||
onTagsChange, | ||
}: TagBadgeGroupProps) => { | ||
const removeTag = (tag: string) => { | ||
onTagsChange?.(tags.filter((t) => t !== tag)); | ||
}; | ||
|
||
const numTags = tags.length; | ||
|
||
if (numTags > maxTagsDisplayed) { | ||
return ( | ||
<HoverCard> | ||
<HoverCardTrigger asChild> | ||
<Badge variant={variant} className="ml-1 whitespace-nowrap"> | ||
{numTags} tags | ||
</Badge> | ||
</HoverCardTrigger> | ||
<HoverCardContent className="flex flex-wrap gap-1"> | ||
{tags.map((tag) => ( | ||
<TagBadge | ||
key={tag} | ||
tag={tag} | ||
onRemove={onTagsChange ? () => removeTag(tag) : undefined} | ||
/> | ||
))} | ||
</HoverCardContent> | ||
</HoverCard> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{tags.map((tag) => ( | ||
<TagBadge | ||
key={tag} | ||
tag={tag} | ||
onRemove={onTagsChange ? () => removeTag(tag) : undefined} | ||
variant={variant} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; |
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,26 @@ | ||
import { X } from "lucide-react"; | ||
import { Badge, type BadgeProps } from "./badge"; | ||
|
||
type TagBadgeProps = { | ||
tag: string; | ||
variant?: BadgeProps["variant"]; | ||
onRemove?: () => void; | ||
}; | ||
|
||
export const TagBadge = ({ tag, variant, onRemove }: TagBadgeProps) => { | ||
return ( | ||
<Badge variant={variant} className="ml-1 max-w-20" title={tag}> | ||
<span className="truncate">{tag}</span> | ||
{onRemove && ( | ||
<button | ||
type="button" | ||
onClick={onRemove} | ||
className="text-muted-foreground hover:text-foreground" | ||
aria-label={`Remove ${tag} tag`} | ||
> | ||
<X size={14} /> | ||
</button> | ||
)} | ||
</Badge> | ||
); | ||
}; |
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
Oops, something went wrong.