Type, then Enter or a comma to add a tag; suggestions, checks for duplicates and emails, and pasting a list.
Labels
billing
design
docs
mobile
performance
regression
security
tablet
Enter or a comma adds one. Paste a list to add several.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { sx } from "./ui/uicontext/components/Sx.ts"import { TagInput } from "./ui/uicontext/components/TagInput.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 28rem)" } })const labels = ["bug", "billing", "checkout", "design", "docs", "mobile", "performance", "regression", "security", "tablet"]const Message = UiSchema.TaggedEnum({ RequestedLabels: { tags: Schema.Array(Schema.String) } })// an issue's labels: pick the workspace's own, or type a new oneexport const IssueLabels = Html.component({ name: "IssueLabels", model: Schema.Struct({ labels: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ labels: ["bug", "checkout"] }), update: { RequestedLabels: ($, { tags }) => $.evolve({ labels: tags }) }, view: (h, { labels: chosen }) => h.div.attrs(sx(styles.wrap)).children( TagInput(h, { props: { label: "Labels", tags: chosen, suggestions: labels, placeholder: "Add a label", max: 6, description: "Enter or a comma adds one. Paste a list to add several." }, onEmit: { RequestedTags: ({ tags }) => Message.RequestedLabels({ tags }) }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/tag-inputUsage
import { TagInput } from "./ui/uicontext/components/TagInput.ts"const Message = UiSchema.TaggedEnum({ RequestedLabels: { tags: Schema.Array(Schema.String) } })export const LabelsField = (h: Html.H<typeof Message.Type>, labels: ReadonlyArray<string>) => TagInput(h, { props: { label: "Labels", tags: labels, suggestions: ["bug", "design", "docs"] }, onEmit: { RequestedTags: ({ tags }) => Message.RequestedLabels({ tags }) }, })Examples
Invite by email
Addresses are checked as they're added, and a long one shortens in its chip. Try pasting “[email protected], not-an-email”.
Invite by email
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { formatCount } from "./ui/uicontext/components/domain/Format.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { TagInput } from "./ui/uicontext/components/TagInput.ts"const styles = stylex.create({ form: { display: "grid", gap: 12, justifyItems: "start", inlineSize: "min(100%, 30rem)" }, field: { inlineSize: "100%" } })const Message = UiSchema.TaggedEnum({ RequestedInvitees: { tags: Schema.Array(Schema.String) } })// invite by email: each address is checked as it's added; paste a column from a spreadsheet to add them allexport const InviteByEmail = Html.component({ name: "InviteByEmail", model: Schema.Struct({ invitees: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ invitees: ["[email protected]"] }), update: { RequestedInvitees: ($, { tags }) => $.evolve({ invitees: tags }) }, view: (h, { invitees }) => h.div.attrs(sx(styles.form)).children( h.div.attrs(sx(styles.field)).children( TagInput(h, { props: { label: "Invite by email", tags: invitees, kind: "email", suggestions: ["[email protected]", "[email protected]", "[email protected]"], placeholder: "[email protected]", max: 20, }, onEmit: { RequestedTags: ({ tags }) => Message.RequestedInvitees({ tags }) }, }), ), Button(h, { tone: "primary" }).attrs({ disabled: invitees.length === 0 ? "" : undefined }).children(invitees.length === 0 ? "Send invites" : `Send ${formatCount(invitees.length, "invite")}`), ),})API reference
Props
| Name | Type | Description |
|---|---|---|
labelrequired | string | What the tags are: "Labels", "Invite by email". |
tagsrequired | string[] | The tags so far. The caller keeps them and stores what RequestedTags asks for. |
suggestions | string[] | Tags to offer as you type: the labels a workspace already has, the people you work with. |
suggestionsOnly | boolean | Only suggestions can be added, not new text: a fixed set of labels. |
kind | "text" | "email" | email checks each tag is an address and opens the email keyboard on a phone. |
max | number | The most tags allowed. |
placeholder | string | — |
description | string | A line under the field. |
disabled | boolean | — |
name | string | Submits each tag under this form field name. |
Events
| Event | Payload | Description |
|---|---|---|
RequestedTags | { tags: string[] } | The tags asked for, all of them: store them and pass them back as tags. |