Skip to content

feat(components): Add Copy Link button to Input component #7131

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

Open
wants to merge 5 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
218 changes: 112 additions & 106 deletions apps/www/app/(app)/examples/cards/components/team-members.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChevronDown } from "lucide-react"
"use client"

import { useState } from "react"
import { ChevronDown } from "lucide-react"
import {
Avatar,
AvatarFallback,
Expand Down Expand Up @@ -27,7 +29,96 @@ import {
PopoverTrigger,
} from "@/registry/new-york/ui/popover"

export function DemoTeamMembers() {
const roles = [
{
label: "Viewer",
description: "Can view and comment.",
},
{
label: "Developer",
description: "Can view, comment and edit.",
},
{
label: "Billing",
description: "Can view, comment and manage billing.",
},
{
label: "Owner",
description: "Admin-level access to all resources.",
},
]

function RoleSelect({ value, onChange }: { value: string, onChange: (val: string) => void }) {
const [open, setOpen] = useState(false)

return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button variant="outline" size="sm" className="ml-auto">
{value} <ChevronDown className="ml-1 h-4 w-4 text-muted-foreground" />
</Button>
</PopoverTrigger>
<PopoverContent className="p-0" align="end">
<Command>
<CommandInput placeholder="Select new role..." />
<CommandList>
<CommandEmpty>No roles found.</CommandEmpty>
<CommandGroup className="p-1.5">
{roles.map((role) => (
<CommandItem
key={role.label}
onSelect={() => {
onChange(role.label)
setOpen(false)
}}
className="flex flex-col items-start px-4 py-2"
>
<p>{role.label}</p>
<p className="text-sm text-muted-foreground">
{role.description}
</p>
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
)
}

export function CardsTeamMembers() {
const [rolesByEmail, setRolesByEmail] = useState<Record<string, string>>({
"[email protected]": "Owner",
"[email protected]": "Member",
"[email protected]": "Member",
})

const updateRole = (email: string, newRole: string) => {
setRolesByEmail((prev) => ({ ...prev, [email]: newRole }))
}

const members = [
{
name: "Sofia Davis",
email: "[email protected]",
avatar: "/avatars/01.png",
fallback: "SD",
},
{
name: "Jackson Lee",
email: "[email protected]",
avatar: "/avatars/02.png",
fallback: "JL",
},
{
name: "Isabella Nguyen",
email: "[email protected]",
avatar: "/avatars/03.png",
fallback: "IN",
},
]

return (
<Card>
<CardHeader>
Expand All @@ -37,112 +128,27 @@ export function DemoTeamMembers() {
</CardDescription>
</CardHeader>
<CardContent className="grid gap-6">
<div className="flex items-center justify-between space-x-4">
<div className="flex items-center space-x-4">
<Avatar>
<AvatarImage src="/avatars/01.png" />
<AvatarFallback>OM</AvatarFallback>
</Avatar>
<div>
<p className="text-sm font-medium leading-none">Sofia Davis</p>
<p className="text-sm text-muted-foreground">[email protected]</p>
</div>
</div>
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" className="ml-auto">
Owner <ChevronDown className="text-muted-foreground" />
</Button>
</PopoverTrigger>
<PopoverContent className="p-0" align="end">
<Command>
<CommandInput placeholder="Select new role..." />
<CommandList>
<CommandEmpty>No roles found.</CommandEmpty>
<CommandGroup>
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Viewer</p>
<p className="text-sm text-muted-foreground">
Can view and comment.
</p>
</CommandItem>
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Developer</p>
<p className="text-sm text-muted-foreground">
Can view, comment and edit.
</p>
</CommandItem>
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Billing</p>
<p className="text-sm text-muted-foreground">
Can view, comment and manage billing.
</p>
</CommandItem>
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Owner</p>
<p className="text-sm text-muted-foreground">
Admin-level access to all resources.
</p>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
</div>
<div className="flex items-center justify-between space-x-4">
<div className="flex items-center space-x-4">
<Avatar>
<AvatarImage src="/avatars/02.png" />
<AvatarFallback>JL</AvatarFallback>
</Avatar>
<div>
<p className="text-sm font-medium leading-none">Jackson Lee</p>
<p className="text-sm text-muted-foreground">[email protected]</p>
{members.map((member) => (
<div
key={member.email}
className="flex items-center justify-between space-x-4"
>
<div className="flex items-center space-x-4">
<Avatar className="h-8 w-8">
<AvatarImage src={member.avatar} alt="Image" />
<AvatarFallback>{member.fallback}</AvatarFallback>
</Avatar>
<div>
<p className="text-sm font-medium leading-none">{member.name}</p>
<p className="text-sm text-muted-foreground">{member.email}</p>
</div>
</div>
<RoleSelect
value={rolesByEmail[member.email]}
onChange={(role) => updateRole(member.email, role)}
/>
</div>
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" className="ml-auto">
Member <ChevronDown className="text-muted-foreground" />
</Button>
</PopoverTrigger>
<PopoverContent className="p-0" align="end">
<Command>
<CommandInput placeholder="Select new role..." />
<CommandList>
<CommandEmpty>No roles found.</CommandEmpty>
<CommandGroup className="p-1.5">
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Viewer</p>
<p className="text-sm text-muted-foreground">
Can view and comment.
</p>
</CommandItem>
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Developer</p>
<p className="text-sm text-muted-foreground">
Can view, comment and edit.
</p>
</CommandItem>
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Billing</p>
<p className="text-sm text-muted-foreground">
Can view, comment and manage billing.
</p>
</CommandItem>
<CommandItem className="teamaspace-y-1 flex flex-col items-start px-4 py-2">
<p>Owner</p>
<p className="text-sm text-muted-foreground">
Admin-level access to all resources.
</p>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
</div>
))}
</CardContent>
</Card>
)
Expand Down
21 changes: 15 additions & 6 deletions apps/www/app/(app)/examples/mail/components/mail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export function Mail({
const [isCollapsed, setIsCollapsed] = React.useState(defaultCollapsed)
const [mail] = useMail()

const [searchQuery, setSearchQuery] = React.useState("")
const filteredMails = mails.filter(
(item) =>
item.subject.toLowerCase().includes(searchQuery.toLowerCase()) ||
item.text.toLowerCase().includes(searchQuery.toLowerCase())
)


return (
<TooltipProvider delayDuration={0}>
<ResizablePanelGroup
Expand Down Expand Up @@ -205,16 +213,17 @@ export function Mail({
<form>
<div className="relative">
<Search className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
<Input placeholder="Search" className="pl-8" />
<Input placeholder="Search" className="pl-8" value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}/>
</div>
</form>
</div>
<TabsContent value="all" className="m-0">
<MailList items={mails} />
</TabsContent>
<TabsContent value="unread" className="m-0">
<MailList items={mails.filter((item) => !item.read)} />
</TabsContent>
<MailList items={filteredMails} />
</TabsContent>
<TabsContent value="unread" className="m-0">
<MailList items={filteredMails.filter((item) => !item.read)} />
</TabsContent>
</Tabs>
</ResizablePanel>
<ResizableHandle withHandle />
Expand Down
11 changes: 10 additions & 1 deletion apps/www/components/cards/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ import {
SelectValue,
} from "@/registry/new-york/ui/select"
import { Separator } from "@/registry/new-york/ui/separator"
import { useRef } from "react"

export function CardsShare() {
const inputRef = useRef<HTMLInputElement>(null);
const handleCopy = () => {
if (inputRef.current) {
navigator.clipboard.writeText(inputRef.current.value);
}
};

return (
<Card>
<CardHeader className="pb-3">
Expand All @@ -41,9 +49,10 @@ export function CardsShare() {
<Input
id="link"
value="http://example.com/link/to/document"
ref={inputRef}
readOnly
/>
<Button className="shrink-0">Copy Link</Button>
<Button className="shrink-0" onClick={handleCopy}>Copy Link</Button>
</div>
<Separator className="my-4" />
<div className="space-y-4">
Expand Down
Loading