Updated
Smart Paste
NewCustomize
Max6
Duration0.40s
Installation
npx shadcn@latest add https://uibrik.com/r/smart-paste.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/smart-paste/smart-paste.tsx"use client"; import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type ClipboardEvent, type KeyboardEvent, type ReactNode, type RefObject, } from "react"; import { animate, AnimatePresence, LayoutGroup, motion, useReducedMotion } from "motion/react"; import { cn } from "@/lib/utils"; // Smart Paste. A field for links. Paste a URL, or type one and press Enter or // Space, and the raw text folds into a chip: the box shrinks from the width // of the text to the width of the chip while the URL fades out under the // favicon, title and domain. The chip lands where the text was, so nothing // jumps. Titles and icons come from `resolve`; until they arrive (or without // it) the chip shows the domain, and the chip eases to its new width when the // title lands.
Adds the files to
components/uibrik/smart-paste and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/smart-paste.Usage
import { SmartPaste } from "@/components/uibrik/smart-paste/smart-paste";const defaultValue = [ "https://github.com/vercel/next.js", "linear.app/changelog",];<SmartPaste placeholder="Paste a link" max={6} duration={0.4} openOnClick disabled={false} defaultValue={defaultValue} label="Links" // value={["…"]} // onChange={(links) => {}} // favicon={(url) => {}} // resolve={(url, signal) => {}}/>Where to use Smart Paste
Attaching links to issues
Pasted URLs become readable chips with titles, so a ticket shows what each link is.
Pairs with Issue Tracker
Resources and references
A list of docs or designs reads as names instead of long URLs.
Pairs with Tag Input
Composers and forms
Links stay editable: Backspace turns a chip back into its URL in place.
Pairs with Email Composer
Props
SmartPaste- placeholder
- Type string
- "Paste a link"
- Shown while there are no links.
- max
- Type number
- 6
- Most links allowed.
- duration
- Type number
- 0.4
- How long a chip takes to fold or unfold.
- openOnClick
- Type boolean
- true
- Open a chip's link in a new tab when it's clicked.
- disabled
- Type boolean
- false
- Grey the field out and ignore input.
- value / onChange
- Type string[] / (links) => void
- –
- Controlled links, as typed or pasted.
- defaultValue
- Type string[]
- –
- Links on mount when uncontrolled.
- favicon
- Type (url) => ReactNode | string
- –
- The icon for a link, worked out at once: a node, or an image URL that fades in once loaded. Point image URLs at your own favicon proxy or a service; leave out for letter tiles.
- resolve
- Type (url, signal) => LinkMeta | null | Promise<LinkMeta | null>
- –
- Looks up a link's title (and a better icon), once per link. Return a value to show it on the first frame, or a promise; the chip eases to its new width when it lands. Fetch through your own server: browsers block reading other sites' pages.
- label
- Type string
- "Links"
- Names the field for screen readers.
- className
- Type string
- –
- Classes for the field.