Command palette

@yasinsensoy/web

Web · Components

Transfer

Transfer between two lists: pick from the long list on the left, move to the right.

6 exports

Live example

Preview

All permissions8
Add / edit usersusers.write
Delete usersusers.delete
View ordersorders.read
Issue refundsorders.refund
Reportsreports.read
Export reportsreports.export
Change settingssettings.write
Audit logaudit
Press Space to check, Enter to move to the other list, Ctrl+A to check all.
Role permissions2
View usersusers.read
Billingbilling
Press Space to check, Enter to move to the other list, Ctrl+A to check all.

Code

import { TransferField } from "@yasinsensoy/web";

<TransferField label="Role permissions" name="permissions" items={permissions}
  titles={["All permissions", "Role permissions"]} />

Events

  1. Events appear here when you interact with the preview.

Import

import { Transfer } from "@yasinsensoy/web";

Transfer

componentClient component

Transfer between two lists: pick from the long list on the left, move to the right. For role permissions, team members, columns shown in a table, email recipients.

  • Selection: click a row or press Space; Shift for a range, Ctrl/⌘ + A for all. Double-click or Enter moves a single item across right away.
  • Search: separate in each list, insensitive to locale-specific letters; "select all" selects only the visible ones.
  • Large lists: rows are virtualized; 10,000 items scroll smoothly.
  • Ordering: with orderable the order on the right changes with ↑/↓ or Alt + arrow; the value comes back in this order.
  • One way: with oneWay items are only added; those on the right are removed with ×.
  • Mobile and narrow areas: when the container narrows the lists stack and the arrows turn up/down; rows grow for touch.
  • Form: with name each selected value is submitted separately; required and max work.

For label, description and error see TransferField.

Transfer(props: TransferProps): ReactNode

Examples

<Transfer items={permissions} defaultValue={["read"]} titles={["All permissions", "Role permissions"]} />

<Transfer items={columns} value={visible} onValueChange={setVisible} orderable oneWay />

TransferItem

interface

An item in the Transfer lists.

NameTypeDescription
valuestringUnique value; goes into the form and the value array.
labelReactNodeVisible name. If it isn't text, keywords or value is used in search.
description?ReactNodeDescription below the name (email, code, role).
icon?IconPropIcon or avatar before the name.
disabled?booleanCan't be moved; if selected it stays in the target.
keywords?stringExtra text to match in search (e.g. the label's translation, an abbreviation).

Side of a Transfer list: source or target (the selected ones).

type TransferSide = "source" | "target"

Info given to the renderItem function of Transfer.

NameTypeDescription
sideTransferSideThe list the item is in.
checkedbooleanIs it checked?
querystringSearch text (if you want to highlight it).

Classes that can be passed to the inner parts of Transfer.

NameTypeDescription
list?stringBoth list boxes.
header?stringList title.
item?stringRow.
actions?stringMove buttons in the middle.

TransferProps

interface

Props of the Transfer component.

NameTypeDefaultDescription
itemsreadonly TransferItem[]All items. Selected ones show on the right, the rest on the left. See TransferItem.
value?readonly string[]Values of the selected ones in controlled use, in their order on the right.
defaultValue?readonly string[]Initially selected ones in uncontrolled use.
onValueChange?(value: string[], items: TransferItem[]) => voidCalled with the new values and items when the selection changes.
titles?readonly [ReactNode, ReactNode]List titles. @defaultValue ["Kaynak", "Seçilenler"] (messages.transferSource, messages.transferTarget)
search?boolean | "auto""auto"Search boxes; insensitive to locale-specific letters. "auto" turns them on with more than 8 items.
oneWay?booleanfalseItems only move from left to right; items on the right are removed with ×. For picking a few items from a long list (recipients, permissions).
orderable?booleanfalseThe order on the right can be changed: move checked items with the ↑/↓ buttons, or Alt + arrow on the keyboard (column order, priority list).
max?numberAt most this many items can move to the right.
height?number | string"18rem"Height of the lists.
renderItem?(item: TransferItem, context: TransferRenderContext) => ReactNodeContent of a row; if omitted, the icon, name and description are drawn.
footer?(side: TransferSide) => ReactNodeContent added below the list (e.g. an "Add new" button).
empty?(side: TransferSide) => ReactNodeContent shown in an empty list.
itemHeight?number40Estimated row height (px); the virtual list measures, this is for the first render.
name?stringForm field name; each selected value is submitted separately (getAll(name)).
form?stringId of the form the field belongs to.
required?booleanThe form can't be submitted without at least one selected item.
disabled?booleanDisabled.
id?stringId of the source list (the label's htmlFor).
tooltip?TooltipPropTooltip when hovering the container. See TooltipProp.
className?stringClasses added to the container.
classNames?TransferClassNamesClasses added to the inner parts.
aria-label?stringScreen reader name.
aria-labelledby?stringId of the element naming the component.
aria-describedby?stringId of the element describing the component.
aria-invalid?boolean | "true" | "false"Show as invalid.