Board
import { Board, Mosaic } from '@dxos/react-ui-mosaic';import { Dnd } from '@dxos/react-ui-dnd';npm install @dxos/react-ui-mosaic @dxos/react-ui-dnd @effect/atom-reactA board is a row of columns, each a stack of cards the user can drag. Cards move within a column and across columns, and columns move by the handle in their header.
The board reads a model of atoms.
Wrap your app in RegistryProvider from @effect/atom-react. This is best practice, because your app then controls
the registry that the board reads. Without a provider, the board reads the library’s default registry.
Add the package’s strings from @dxos/react-ui-mosaic/translations to the resourceExtensions of Theme.Provider.
| Part | What it is |
|---|---|
Board.Root |
The root, which reads a BoardModel. The model gives the columns, a column’s items, and an id for each |
Board.Content |
The row of columns, drawn as a Tile each. Its eventHandler takes columns |
Board.Column.Root |
A column, draggable by the element passed as dragHandle |
Board.Column.Header |
The column’s header. Its dragHandleRef is the column’s handle |
Board.Column.Body |
The column’s cards, drawn as a Tile each in a scroll area. Its eventHandler takes cards |
Board.Column.Footer |
A toolbar under the column. It has an add button when it gets onAdd or the model has onItemCreate |
Board.Item |
The default card |
Board.Placeholder |
The gap a dropped card would land in |
Board.Debug |
The state of the drag, for development |
Model a board
Section titled “Model a board”A BoardModel gives the board an atom for the columns and an atom for each column’s cards, so a change redraws only
the columns it touches.
Example (Holding a board in one atom)
import { const RegistryContext: React.Context<AtomRegistry>
Provides a React context that supplies the AtomRegistry used by Atom hooks and
hydration helpers, defaulting to a standalone registry when no provider is
present.
When to use
Use to supply an existing AtomRegistry through React context when hooks or
hydration helpers need to share registry state that is managed outside
RegistryProvider.
RegistryContext } from '@effect/atom-react/RegistryContext';import * as import Atom
Atom from 'effect/reactivity/Atom';import { function useContext<T>(context: React.Context<T>): T
Accepts a context object (the value returned from React.createContext) and returns the current
context value, as given by the nearest context provider for the given context.
useContext, function useMemo<T>(factory: () => T, deps: React.DependencyList): T
useMemo will only recompute the memoized value when one of the deps has changed.
useMemo, function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)
Returns a stateful value, and a function to update it.
useState } from 'react';import { type interface DndContainerHandler<TData = any, TObject = any>
Handler implemented by drop containers.
DndContainerHandler, type type DndData = DndTileData<any, any> | DndPlaceholderData<any> | DndContainerData
DndData, type type DndTileData<TData = any, TLocation = any> = { type: "tile"; containerId: string; id: string; data: TData; location: TLocation; bounds?: DOMRect;}
Draggable item.
Tiles may contain arbitrary data (which may not be an ECHO object; e.g., search result).
DndTileData } from '@dxos/react-ui-dnd';import { type interface BoardModel<TColumn = any, TItem = any>
BoardModel } from '@dxos/react-ui-mosaic';
type type Task = { id: string; title: string;}
Task = { id: string
id: string; title: string
title: string };
type type Column = { id: string; name: string; tasks: Task[];}
Column = { id: string
id: string; name: string
name: string; tasks: Task[]
tasks: type Task = { id: string; title: string;}
Task[] };
const const COLUMNS: Column[]
COLUMNS: type Column = { id: string; name: string; tasks: Task[];}
Column[] = [ { id: string
id: 'todo', name: string
name: 'To do', tasks: Task[]
tasks: [ { id: string
id: '1', title: string
title: 'Write the blog post' }, { id: string
id: '2', title: string
title: 'Record the demo' }, ], }, { id: string
id: 'doing', name: string
name: 'Doing', tasks: Task[]
tasks: [ { id: string
id: '3', title: string
title: 'Update the docs' }, { id: string
id: '4', title: string
title: 'Fix the login bug' }, ], }, { id: string
id: 'done', name: string
name: 'Done', tasks: Task[]
tasks: [{ id: string
id: '5', title: string
title: 'Ship the beta' }] },];
const const isColumn: (value: unknown) => value is Column
isColumn = (value: unknown
value: unknown): value: unknown
value is type Column = { id: string; name: string; tasks: Task[];}
Column => typeof value: unknown
value === 'object' && value: object | null
value !== null && 'tasks' in value: object
value;
const const isTask: (value: unknown) => value is Task
isTask = (value: unknown
value: unknown): value: unknown
value is type Task = { id: string; title: string;}
Task => typeof value: unknown
value === 'object' && value: object | null
value !== null && 'title' in value: object
value && !('tasks' in value: object & Record<"title", unknown>
value);
/** * `list` with the dragged item at the drop: after the tile it was dropped on, in the gap a placeholder names, or * at the end when dropped on the container. */const const place: <T extends { id: string;}>(list: T[], source: DndTileData<T>, target?: DndData) => T[]
list with the dragged item at the drop: after the tile it was dropped on, in the gap a placeholder names, or
at the end when dropped on the container.
place = <function (type parameter) T in <T extends { id: string;}>(list: T[], source: DndTileData<T>, target?: DndData): T[]
T extends { id: string
id: string }>( list: T[]
list: function (type parameter) T in <T extends { id: string;}>(list: T[], source: DndTileData<T>, target?: DndData): T[]
T[], source: DndTileData<T>
source: type DndTileData<TData = any, TLocation = any> = { type: "tile"; containerId: string; id: string; data: TData; location: TLocation; bounds?: DOMRect;}
Draggable item.
Tiles may contain arbitrary data (which may not be an ECHO object; e.g., search result).
DndTileData<function (type parameter) T in <T extends { id: string;}>(list: T[], source: DndTileData<T>, target?: DndData): T[]
T>, target: DndData | undefined
target?: type DndData = DndTileData<any, any> | DndPlaceholderData<any> | DndContainerData
DndData,): function (type parameter) T in <T extends { id: string;}>(list: T[], source: DndTileData<T>, target?: DndData): T[]
T[] => { const const rest: T[]
rest = list: T[]
list.Array<T>.filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[] (+1 overload)
Returns the elements of an array that meet the condition specified in a callback function.
filter((item: T extends { id: string; }
item) => item: T extends { id: string; }
item.id: string
id !== source: DndTileData<T>
source.id: string
id); const const index: number
index = target: DndData | undefined
target?.type: "tile" | "placeholder" | "container" | undefined
type === 'tile' ? const rest: T[]
rest.Array<T>.findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number
Returns the index of the first element in the array where predicate is true, and -1
otherwise.
findIndex((item: T extends { id: string; }
item) => item: T extends { id: string; }
item.id: string
id === target: DndTileData<any, any>
target.id: string
id) + 1 : target: DndPlaceholderData<any> | DndContainerData | undefined
target?.type: "placeholder" | "container" | undefined
type === 'placeholder' ? var Math: Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.Math.floor(x: number): number
Returns the greatest integer less than or equal to its numeric argument.
floor(var Number: NumberConstructor(value?: any) => number
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number(target: DndPlaceholderData<any>
target.location: any
location)) : const rest: T[]
rest.Array<T>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length; const const at: number
at = var Math: Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.Math.min(...values: number[]): number
Returns the smaller of a set of supplied numeric expressions.
min(var Math: Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.Math.max(...values: number[]): number
Returns the larger of a set of supplied numeric expressions.
max(const index: number
index, 0), const rest: T[]
rest.Array<T>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length); return [...const rest: T[]
rest.Array<T>.slice(start?: number, end?: number): T[]
Returns a copy of a section of an array.
For both start and end, a negative index can be used to indicate an offset from the end of the array.
For example, -2 refers to the second to last element of the array.
slice(0, const at: number
at), source: DndTileData<T>
source.data: T extends { id: string; }
data, ...const rest: T[]
rest.Array<T>.slice(start?: number, end?: number): T[]
Returns a copy of a section of an array.
For both start and end, a negative index can be used to indicate an offset from the end of the array.
For example, -2 refers to the second to last element of the array.
slice(const at: number
at)];};
/** The board reads its columns, and each column's cards, from one atom; a drop writes it and the board follows. */const const useTaskBoard: () => { model: BoardModel<Column, Task>; setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void; columnHandler: DndContainerHandler<Column, any>;}
The board reads its columns, and each column's cards, from one atom; a drop writes it and the board follows.
useTaskBoard = () => { const const registry: AtomRegistry
registry = useContext<AtomRegistry>(context: React.Context<AtomRegistry>): AtomRegistry
Accepts a context object (the value returned from React.createContext) and returns the current
context value, as given by the nearest context provider for the given context.
useContext(const RegistryContext: React.Context<AtomRegistry>
Provides a React context that supplies the AtomRegistry used by Atom hooks and
hydration helpers, defaulting to a standalone registry when no provider is
present.
When to use
Use to supply an existing AtomRegistry through React context when hooks or
hydration helpers need to share registry state that is managed outside
RegistryProvider.
RegistryContext); const [const columns: Atom.Writable<Column[], Column[]>
columns] = useState<Atom.Writable<Column[], Column[]>>(initialState: Atom.Writable<Column[], Column[]> | (() => Atom.Writable<Column[], Column[]>)): [Atom.Writable<Column[], Column[]>, React.Dispatch<React.SetStateAction<Atom.Writable<Column[], Column[]>>>] (+1 overload)
Returns a stateful value, and a function to update it.
useState(() => import Atom
Atom.const make: <Column[]>(initialValue: Column[]) => Atom.Writable<Column[], Column[]> (+5 overloads)
Creates an atom from a synchronous value or read function, or from an Effect or Stream whose state is exposed as an AsyncResult; plain values create writable state atoms.
make(const COLUMNS: Column[]
COLUMNS));
const const model: BoardModel<Column, Task>
model = useMemo<BoardModel<Column, Task>>(factory: () => BoardModel<Column, Task>, deps: React.DependencyList): BoardModel<Column, Task>
useMemo will only recompute the memoized value when one of the deps has changed.
useMemo<interface BoardModel<TColumn = any, TItem = any>
BoardModel<type Column = { id: string; name: string; tasks: Task[];}
Column, type Task = { id: string; title: string;}
Task>>(() => { const const tasks: (arg: string) => Atom.Atom<Task[]>
tasks = import Atom
Atom.const family: <string, Atom.Atom<Task[]>>(f: (arg: string) => Atom.Atom<Task[]>) => (arg: string) => Atom.Atom<Task[]>
Creates a memoized atom factory that returns the same object for the same argument, using weak references for cached values when the platform supports them.
family((id: string
id: string) => import Atom
Atom.const make: <Task[]>(create: (get: Atom.AtomContext) => Task[]) => Atom.Atom<Task[]> (+5 overloads)
Creates an atom from a synchronous value or read function, or from an Effect or Stream whose state is exposed as an AsyncResult; plain values create writable state atoms.
make( (get: Atom.AtomContext
get) => get: Atom.AtomContext<Column[]>(atom: Atom.Atom<Column[]>) => Column[]
get(const columns: Atom.Writable<Column[], Column[]>
columns).Array<Column>.find(predicate: (value: Column, index: number, obj: Column[]) => unknown, thisArg?: any): Column | undefined (+1 overload)
Returns the value of the first element in the array where predicate is true, and undefined
otherwise.
find((column: Column
column) => column: Column
column.id: string
id === id: string
id)?.tasks: Task[] | undefined
tasks ?? [], ), ); return { BoardModel<Column, Task>.getColumnId: GetId<Column>
getColumnId: (column: Column
column) => column: Column
column.id: string
id, BoardModel<Column, Task>.getItemId: GetId<Task>
getItemId: (task: Task
task) => task: Task
task.id: string
id, BoardModel<Column, Task>.isColumn: (obj: unknown) => obj is Column
isColumn, BoardModel<Column, Task>.isItem: (obj: unknown) => obj is Task
isItem: const isTask: (value: unknown) => value is Task
isTask, BoardModel<Column, Task>.columns: Atom.Atom<Column[] | readonly Column[]>
columns, BoardModel<Column, Task>.items: (column: Column) => Atom.Atom<Task[]>
items: (column: Column
column) => const tasks: (arg: string) => Atom.Atom<Task[]>
tasks(column: Column
column.id: string
id), BoardModel<Column, Task>.getColumns: () => Column[]
getColumns: () => const registry: AtomRegistry
registry.AtomRegistry.get: <Column[]>(atom: Atom.Atom<Column[]>) => Column[]
get(const columns: Atom.Writable<Column[], Column[]>
columns), BoardModel<Column, Task>.getItems: (column: Column) => Task[]
getItems: (column: Column
column) => const registry: AtomRegistry
registry.AtomRegistry.get: <Task[]>(atom: Atom.Atom<Task[]>) => Task[]
get(const tasks: (arg: string) => Atom.Atom<Task[]>
tasks(column: Column
column.id: string
id)), }; }, [const registry: AtomRegistry
registry, const columns: Atom.Writable<Column[], Column[]>
columns]);
const const setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks = (id: string
id: string, update: (tasks: Task[]) => Task[]
update: (tasks: Task[]
tasks: type Task = { id: string; title: string;}
Task[]) => type Task = { id: string; title: string;}
Task[]) => const registry: AtomRegistry
registry.AtomRegistry.set: <Column[], Column[]>(atom: Atom.Writable<Column[], Column[]>, value: Column[]) => void
set( const columns: Atom.Writable<Column[], Column[]>
columns, const registry: AtomRegistry
registry .AtomRegistry.get: <Column[]>(atom: Atom.Atom<Column[]>) => Column[]
get(const columns: Atom.Writable<Column[], Column[]>
columns) .Array<Column>.map<Column>(callbackfn: (value: Column, index: number, array: Column[]) => Column, thisArg?: any): Column[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((column: Column
column) => column: Column
column.id: string
id === id: string
id ? { ...column: Column
column, tasks: Task[]
tasks: update: (tasks: Task[]) => Task[]
update(column: Column
column.tasks: Task[]
tasks) } : column: Column
column, ), );
const const columnHandler: DndContainerHandler<Column, any>
columnHandler: interface DndContainerHandler<TData = any, TObject = any>
Handler implemented by drop containers.
DndContainerHandler<type Column = { id: string; name: string; tasks: Task[];}
Column> = { DndContainerHandler<Column, any>.id: string
Container identifier. Must be unique per live container instance across the whole Dnd.Root
(use useContainerId to append a discriminator when the same object may mount in multiple containers).
id: 'columns', DndContainerHandler<Column, any>.canDrop?: ((props: { source: DndTileData<Column, any>;}) => boolean) | undefined
Determine if the item can be dropped into this container.
NOTE: This is continuously called while dragging (doesn't require mouse movement).
canDrop: ({ source: DndTileData<Column, any>
source }) => const isColumn: (value: unknown) => value is Column
isColumn(source: DndTileData<Column, any>
source.data: Column
data), DndContainerHandler<Column, any>.onDrop?: ((props: { source: DndTileData<Column, any>; target?: DndData;}) => void) | undefined
Insert/rearrange the item at the given location.
onDrop: ({ source: DndTileData<Column, any>
source, target: DndData | undefined
target }) => const registry: AtomRegistry
registry.AtomRegistry.set: <Column[], Column[]>(atom: Atom.Writable<Column[], Column[]>, value: Column[]) => void
set(const columns: Atom.Writable<Column[], Column[]>
columns, const place: <Column>(list: Column[], source: DndTileData<Column>, target?: DndData) => Column[]
list with the dragged item at the drop: after the tile it was dropped on, in the gap a placeholder names, or
at the end when dropped on the container.
place(const registry: AtomRegistry
registry.AtomRegistry.get: <Column[]>(atom: Atom.Atom<Column[]>) => Column[]
get(const columns: Atom.Writable<Column[], Column[]>
columns), source: DndTileData<Column, any>
source, target: DndData | undefined
target)), };
return { model: BoardModel<Column, Task>
model, setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks, columnHandler: DndContainerHandler<Column, any>
columnHandler };};
COLUMNS goes into one atom, which holds the columns in order, each with its cards in order. The model derives the atom
for each column’s cards from it. place puts a dropped item where the drop landed:
- If the user drops the item on a card,
placeputs it after that card. - If the user drops the item on a placeholder,
placeputs it in the gap between two cards. - If the user drops the item on the container,
placeputs it at the end.
Draw and drag
Section titled “Draw and drag”A column’s body draws a Mosaic.Tile for each card. Each column’s eventHandler takes cards:
onDropplaces a card in the column.onTakeruns on the column a card leaves, so that column can remove the card once the other column has it.
When the user drops a card in its own column, the column gets only onDrop, which reorders the card. Dnd.Root
tracks the drag across the board.
Example (Dragging cards and columns)
import { const useAtomValue: { <A>(atom: Atom.Atom<A>): A; <A, B>(atom: Atom.Atom<A>, f: (_: A) => B): B;}
Subscribes to an atom in the current React registry and returns its current
value, optionally mapped through a selector.
When to use
Use when a React component needs to render from an atom value without also
returning a setter.
Details
When a selector is provided, the hook subscribes to the atom and applies the
selector to its value from the current RegistryContext.
Gotchas
Late Suspense boundaries hydrate with the same atom snapshot as earlier
readers, then update to the live value. The snapshot lasts until all readers
unsubscribe. Changes before the first reader hydrates or after the last
unsubscribes can still cause mismatches, as can a derived atom first read
inside a late boundary.
useAtomValue } from '@effect/atom-react/Hooks';import { type (alias) interface CSSPropertiesimport CSSProperties
CSSProperties, function createContext<T>(defaultValue: T): React.Context<T>
Lets you create a
Context
that components can provide or read.
createContext, function useContext<T>(context: React.Context<T>): T
Accepts a context object (the value returned from React.createContext) and returns the current
context value, as given by the nearest context provider for the given context.
useContext, function useMemo<T>(factory: () => T, deps: React.DependencyList): T
useMemo will only recompute the memoized value when one of the deps has changed.
useMemo, function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)
Returns a stateful value, and a function to update it.
useState } from 'react';import { const Dnd: { Root: { ({ children }: { children?: React.ReactNode | undefined; }): React.JSX.Element; displayName: string; };}
Dnd, type interface DndContainerHandler<TData = any, TObject = any>
Handler implemented by drop containers.
DndContainerHandler } from '@dxos/react-ui-dnd';import { const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board, const Mosaic: { Container: import("react").ForwardRefExoticComponent<Omit<MosaicContainerProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>; Tile: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: any; location: import("@dxos/react-ui-dnd").DndLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: import("@dxos/react-ui/Focus").ItemBinding; size?: import("@dxos/react-ui-dnd").Size; onSizeChange?: (size: import("@dxos/react-ui-dnd").Size) => void; minSize?: number; maxSize?: number; debug?: boolean; }>, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { asChild?: boolean; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>; ... 5 more ...; VirtualStack: <TData = any>(props: import("node_modules/@dxos/react-ui-mosaic/dist/types/src/components/Mosaic/Stack").MosaicVirtualStackProps<TData> & { ref?: import("react").Ref<HTMLDivElement>; }) => import("react").ReactElement;}
Mosaic, type type MosaicTileProps<TData = any, TLocation = DndLocation> = Omit<React.PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: TData; location: TLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: FocusItemBinding; size?: Size; onSizeChange?: (size: Size) => void; minSize?: number; maxSize?: number; debug?: boolean;}>, "className"> & { classNames?: ClassNameValue;}
MosaicTileProps, function useBoard<TColumn = any, TItem = any>(displayName?: string): BoardContextValue<TColumn, TItem>
Hook to read the board model from context (e.g. in custom column tiles). Pass TColumn and TItem for typed model.
useBoard } from '@dxos/react-ui-mosaic';import * as import Card
Card from '@dxos/react-ui/Card';
const const TaskCard: ({ data: task, location, draggable, }: MosaicTileProps<Task>) => React.JSX.Element
TaskCard = ({ data: Task
data: task: Task
task, location: DndLocation
location, draggable: boolean | undefined
draggable,}: type MosaicTileProps<TData = any, TLocation = DndLocation> = Omit<React.PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: TData; location: TLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: FocusItemBinding; size?: Size; onSizeChange?: (size: Size) => void; minSize?: number; maxSize?: number; debug?: boolean;}>, "className"> & { classNames?: ClassNameValue;}
MosaicTileProps<type Task = { id: string; title: string;}
Task>) => ( <const Mosaic: { Container: import("react").ForwardRefExoticComponent<Omit<MosaicContainerProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>; Tile: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: any; location: import("@dxos/react-ui-dnd").DndLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: import("@dxos/react-ui/Focus").ItemBinding; size?: import("@dxos/react-ui-dnd").Size; onSizeChange?: (size: import("@dxos/react-ui-dnd").Size) => void; minSize?: number; maxSize?: number; debug?: boolean; }>, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { asChild?: boolean; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>; ... 5 more ...; VirtualStack: <TData = any>(props: import("node_modules/@dxos/react-ui-mosaic/dist/types/src/components/Mosaic/Stack").MosaicVirtualStackProps<TData> & { ref?: import("react").Ref<HTMLDivElement>; }) => import("react").ReactElement;}
Mosaic.type Tile: React.ForwardRefExoticComponent<Omit<Omit<React.PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: any; location: import("@dxos/react-ui-dnd").DndLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: import("@dxos/react-ui/Focus").ItemBinding; size?: import("@dxos/react-ui-dnd").Size; onSizeChange?: (size: import("@dxos/react-ui-dnd").Size) => void; minSize?: number; maxSize?: number; debug?: boolean;}>, "className"> & { ...;} & { ...;}, "className"> & { ...;} & Pick<...> & React.RefAttributes<...>>
Tile id: string
id={task: Task
task.id: string
id} data: any
data={task: Task
task} location: DndLocation
location={location: DndLocation
location} draggable?: boolean | undefined
draggable={draggable: boolean | undefined
draggable} > <import Card
Card.const Root: React.ForwardRefExoticComponent<Omit<Omit<Card.RootProps, "classNames">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export Root
A card one level above its host (level='+1'), whose Header, Body and Footer share one content edge. With grid it
is a rail Container (the child div wins the asChild merge, so the part keeps the card scope); without, a plain
column that creates no grid. With onClick the card is a button (Enter and Space activate it); nested actions and
menus stop their clicks reaching it.
Root> <import Card
Card.const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export Header
A block row across the card's rails holding the Title: a Block or icon-only Button before the Title fills the start
rail, and the last one after it the end rail, so the Title starts at the content edge.
Header> <import Card
Card.const Title: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<TypographyProps, "lines" | "tone" | "truncate"> & React.RefAttributes<HTMLHeadingElement>>export Title
An h3 on Typography, so it clamps (lines), truncates and takes a tone like any text.
Title>{task: Task
task.title: string
title}</import Card
Card.const Title: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<TypographyProps, "lines" | "tone" | "truncate"> & React.RefAttributes<HTMLHeadingElement>>export Title
An h3 on Typography, so it clamps (lines), truncates and takes a tone like any text.
Title> </import Card
Card.const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export Header
A block row across the card's rails holding the Title: a Block or icon-only Button before the Title fills the start
rail, and the last one after it the end rail, so the Title starts at the content edge.
Header> </import Card
Card.const Root: React.ForwardRefExoticComponent<Omit<Omit<Card.RootProps, "classNames">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export Root
A card one level above its host (level='+1'), whose Header, Body and Footer share one content edge. With grid it
is a rail Container (the child div wins the asChild merge, so the part keeps the card scope); without, a plain
column that creates no grid. With onClick the card is a button (Enter and Space activate it); nested actions and
menus stop their clicks reaching it.
Root> </const Mosaic: { Container: import("react").ForwardRefExoticComponent<Omit<MosaicContainerProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>; Tile: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: any; location: import("@dxos/react-ui-dnd").DndLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: import("@dxos/react-ui/Focus").ItemBinding; size?: import("@dxos/react-ui-dnd").Size; onSizeChange?: (size: import("@dxos/react-ui-dnd").Size) => void; minSize?: number; maxSize?: number; debug?: boolean; }>, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { asChild?: boolean; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>; ... 5 more ...; VirtualStack: <TData = any>(props: import("node_modules/@dxos/react-ui-mosaic/dist/types/src/components/Mosaic/Stack").MosaicVirtualStackProps<TData> & { ref?: import("react").Ref<HTMLDivElement>; }) => import("react").ReactElement;}
Mosaic.type Tile: React.ForwardRefExoticComponent<Omit<Omit<React.PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: any; location: import("@dxos/react-ui-dnd").DndLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: import("@dxos/react-ui/Focus").ItemBinding; size?: import("@dxos/react-ui-dnd").Size; onSizeChange?: (size: import("@dxos/react-ui-dnd").Size) => void; minSize?: number; maxSize?: number; debug?: boolean;}>, "className"> & { ...;} & { ...;}, "className"> & { ...;} & Pick<...> & React.RefAttributes<...>>
Tile>);
/** Writes one column's cards; the board's columns read it from context. */const const SetTasksContext: React.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>
Writes one column's cards; the board's columns read it from context.
SetTasksContext = createContext<(id: string, update: (tasks: Task[]) => Task[]) => void>(defaultValue: (id: string, update: (tasks: Task[]) => Task[]) => void): React.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>
Lets you create a
Context
that components can provide or read.
createContext< (id: string
id: string, update: (tasks: Task[]) => Task[]
update: (tasks: Task[]
tasks: type Task = { id: string; title: string;}
Task[]) => type Task = { id: string; title: string;}
Task[]) => void>(() => {});
/** A column moves by its header's handle; a card taken from another column leaves that one when it lands here. */const const TaskColumn: ({ data: column, location, draggable, }: MosaicTileProps<Column>) => React.JSX.Element
A column moves by its header's handle; a card taken from another column leaves that one when it lands here.
TaskColumn = ({ data: Column
data: column: Column
column, location: DndLocation
location, draggable: boolean | undefined
draggable,}: type MosaicTileProps<TData = any, TLocation = DndLocation> = Omit<React.PropsWithChildren<{ className?: string; dragHandle?: HTMLElement | null; allowedEdges?: Edge[]; id: string; data: TData; location: TLocation; draggable?: boolean; nativeDragPreview?: boolean; reorderOnEnter?: boolean; current?: boolean; selected?: boolean; binding?: FocusItemBinding; size?: Size; onSizeChange?: (size: Size) => void; minSize?: number; maxSize?: number; debug?: boolean;}>, "className"> & { classNames?: ClassNameValue;}
MosaicTileProps<type Column = { id: string; name: string; tasks: Task[];}
Column>) => { const { const model: BoardModel<Column, Task>
model } = useBoard<Column, Task>(displayName?: string): BoardContextValue<Column, Task>
Hook to read the board model from context (e.g. in custom column tiles). Pass TColumn and TItem for typed model.
useBoard<type Column = { id: string; name: string; tasks: Task[];}
Column, type Task = { id: string; title: string;}
Task>(); const const setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks = useContext<(id: string, update: (tasks: Task[]) => Task[]) => void>(context: React.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>): (id: string, update: (tasks: Task[]) => Task[]) => void
Accepts a context object (the value returned from React.createContext) and returns the current
context value, as given by the nearest context provider for the given context.
useContext(const SetTasksContext: React.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>
Writes one column's cards; the board's columns read it from context.
SetTasksContext); const const count: number
count = useAtomValue<Task[]>(atom: Atom.Atom<Task[]>): Task[] (+1 overload)
Subscribes to an atom in the current React registry and returns its current
value, optionally mapped through a selector.
When to use
Use when a React component needs to render from an atom value without also
returning a setter.
Details
When a selector is provided, the hook subscribes to the atom and applies the
selector to its value from the current RegistryContext.
Gotchas
Late Suspense boundaries hydrate with the same atom snapshot as earlier
readers, then update to the live value. The snapshot lasts until all readers
unsubscribe. Changes before the first reader hydrates or after the last
unsubscribes can still cause mismatches, as can a derived atom first read
inside a late boundary.
useAtomValue(const model: BoardModel<Column, Task>
model.BoardModel<Column, Task>.items: (column: Column) => Atom.Atom<Task[]>
items(column: Column
column)).Array<Task>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length; const [const dragHandle: HTMLButtonElement | null
dragHandle, const setDragHandle: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>
setDragHandle] = useState<HTMLButtonElement | null>(initialState: HTMLButtonElement | (() => HTMLButtonElement | null) | null): [HTMLButtonElement | null, React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>] (+1 overload)
Returns a stateful value, and a function to update it.
useState<interface HTMLButtonElement
The HTMLButtonElement interface provides properties and methods (beyond the regular HTMLElement interface it also has available to it by inheritance) for manipulating elements.
HTMLButtonElement | null>(null); const const eventHandler: DndContainerHandler<Task, any>
eventHandler = useMemo<DndContainerHandler<Task, any>>(factory: () => DndContainerHandler<Task, any>, deps: React.DependencyList): DndContainerHandler<Task, any>
useMemo will only recompute the memoized value when one of the deps has changed.
useMemo<interface DndContainerHandler<TData = any, TObject = any>
Handler implemented by drop containers.
DndContainerHandler<type Task = { id: string; title: string;}
Task>>( () => ({ DndContainerHandler<Task, any>.id: string
Container identifier. Must be unique per live container instance across the whole Dnd.Root
(use useContainerId to append a discriminator when the same object may mount in multiple containers).
id: `column-${column: Column
column.id: string
id}`, DndContainerHandler<Task, any>.canDrop?: ((props: { source: DndTileData<Task, any>;}) => boolean) | undefined
Determine if the item can be dropped into this container.
NOTE: This is continuously called while dragging (doesn't require mouse movement).
canDrop: ({ source: DndTileData<Task, any>
source }) => const isTask: (value: unknown) => value is Task
isTask(source: DndTileData<Task, any>
source.data: Task
data), DndContainerHandler<Task, any>.onTake?: ((props: { source: DndTileData<Task, any>;}, cb: (object: any) => Promise<boolean>) => void) | undefined
Request the object to be dropped.
This allows the source container to clone/mutate/swap the object before it is dropped.
If the callback returns true, then the callback may decide to remove the item from the source container,
completing the transfer.
onTake: ({ source: DndTileData<Task, any>
source }, take: (object: any) => Promise<boolean>
take) => void take: (object: any) => Promise<boolean>
take(source: DndTileData<Task, any>
source.data: Task
data).Promise<boolean>.then<false | void, never>(onfulfilled?: ((value: boolean) => false | void | PromiseLike<false | void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<false | void>
Attaches callbacks for the resolution and/or rejection of the Promise.
then( (taken: boolean
taken) => taken: boolean
taken && const setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks(column: Column
column.id: string
id, (tasks: Task[]
tasks) => tasks: Task[]
tasks.Array<Task>.filter(predicate: (value: Task, index: number, array: Task[]) => unknown, thisArg?: any): Task[] (+1 overload)
Returns the elements of an array that meet the condition specified in a callback function.
filter((task: Task
task) => task: Task
task.id: string
id !== source: DndTileData<Task, any>
source.id: string
id), ), ), DndContainerHandler<Task, any>.onDrop?: ((props: { source: DndTileData<Task, any>; target?: DndData;}) => void) | undefined
Insert/rearrange the item at the given location.
onDrop: ({ source: DndTileData<Task, any>
source, target: DndData | undefined
target }) => const setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks(column: Column
column.id: string
id, (tasks: Task[]
tasks) => const place: <Task>(list: Task[], source: DndTileData<Task>, target?: DndData) => Task[]
list with the dragged item at the drop: after the tile it was dropped on, in the gap a placeholder names, or
at the end when dropped on the container.
place(tasks: Task[]
tasks, source: DndTileData<Task, any>
source, target: DndData | undefined
target)), }), [column: Column
column.id: string
id, const setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks], );
return ( <const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board.type Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>;}
Column.type Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined;} & { dragHandle?: HTMLButtonElement | null;}) & { ref?: React.Ref<HTMLDivElement>;}) => React.ReactElement
Root data: Column
data={column: Column
column} location: DndLocation
location={location: DndLocation
location} draggable?: boolean | undefined
draggable={draggable: boolean | undefined
draggable} dragHandle?: HTMLButtonElement | null | undefined
dragHandle={const dragHandle: HTMLButtonElement | null
dragHandle} classNames?: ClassNameValue
classNames='grid grid-rows-[var(--dx-rail-action)_1fr]' > <const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board.type Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>;}
Column.type Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>;}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>
Header label: string
label={`${column: Column
column.name: string
name} (${const count: number
count})`} dragHandleRef?: React.Ref<HTMLButtonElement> | undefined
dragHandleRef={const setDragHandle: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>
setDragHandle} /> <const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board.type Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>;}
Column.type Body: <TItem = Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined;}) & { ref?: React.Ref<HTMLDivElement>;}) => React.ReactElement
Body data: any
data={column: Column
column} eventHandler?: DndContainerHandler<any, any> | undefined
eventHandler={const eventHandler: DndContainerHandler<Task, any>
eventHandler} Tile?: MosaicStackTileComponent<Task> | undefined
Tile={const TaskCard: ({ data: task, location, draggable, }: MosaicTileProps<Task>) => React.JSX.Element
TaskCard} /> </const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board.type Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>;}
Column.type Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined;} & { dragHandle?: HTMLButtonElement | null;}) & { ref?: React.Ref<HTMLDivElement>;}) => React.ReactElement
Root> );};
/** Narrower columns than the theme's card width, so three fit in a small frame. */// `CSSProperties` has no key for a custom property.const const NARROW_COLUMNS: React.CSSProperties
Narrower columns than the theme's card width, so three fit in a small frame.
NARROW_COLUMNS = { 'display': 'contents', '--spacing-card-default-width': '9rem',} as (alias) interface CSSPropertiesimport CSSProperties
CSSProperties;
/** Three columns of tasks: drag a card within or across columns, or drag a column by its handle. */export const const TaskBoard: () => React.JSX.Element
Three columns of tasks: drag a card within or across columns, or drag a column by its handle.
TaskBoard = () => { const { const model: BoardModel<Column, Task>
model, const setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks, const columnHandler: DndContainerHandler<Column, any>
columnHandler } = const useTaskBoard: () => { model: BoardModel<Column, Task>; setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void; columnHandler: DndContainerHandler<Column, any>;}
The board reads its columns, and each column's cards, from one atom; a drop writes it and the board follows.
useTaskBoard();
return ( <const SetTasksContext: React.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>
Writes one column's cards; the board's columns read it from context.
SetTasksContext.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>.Provider: React.Provider<(id: string, update: (tasks: Task[]) => Task[]) => void>
Provider ProviderProps<(id: string, update: (tasks: Task[]) => Task[]) => void>.value: (id: string, update: (tasks: Task[]) => Task[]) => void
value={const setTasks: (id: string, update: (tasks: Task[]) => Task[]) => void
setTasks}> <JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div HTMLAttributes<T>.style?: React.CSSProperties | undefined
style={const NARROW_COLUMNS: React.CSSProperties
Narrower columns than the theme's card width, so three fit in a small frame.
NARROW_COLUMNS}> <const Dnd: { Root: { ({ children }: { children?: React.ReactNode | undefined; }): React.JSX.Element; displayName: string; };}
Dnd.type Root: { ({ children }: { children?: React.ReactNode | undefined; }): React.JSX.Element; displayName: string;}
Root> <const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board.type Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement
Root model: BoardModel<Column, Task>
model={const model: BoardModel<Column, Task>
model}> <const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board.type Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>;}) => React.ReactElement
Content eventHandler?: DndContainerHandler<Column, any> | undefined
eventHandler={const columnHandler: DndContainerHandler<Column, any>
columnHandler} Tile?: MosaicStackTileComponent<Column> | undefined
Tile={const TaskColumn: ({ data: column, location, draggable, }: MosaicTileProps<Column>) => React.JSX.Element
A column moves by its header's handle; a card taken from another column leaves that one when it lands here.
TaskColumn} /> </const Board: { Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement; Content: <TColumn = any>(props: BoardContentProps<TColumn> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Column: { Root: <TColumn = unknown>(props: (BoardColumnProps<TColumn> & { children?: React.ReactNode | undefined; } & { dragHandle?: HTMLButtonElement | null; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Header: React.ForwardRefExoticComponent<Omit<{ label: string; dragHandleRef?: React.Ref<HTMLButtonElement>; }, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>; Body: <TItem = import("@dxos/echo/Obj").Unknown>(props: (Pick<BoardColumnProps<any>, "data"> & Pick<import("@dxos/react-ui-mosaic").MosaicContainerProps, "debug" | "eventHandler"> & { Tile?: import("@dxos/react-ui-mosaic").MosaicStackTileComponent<TItem> | undefined; }) & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Footer: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & { data?: any; onAdd?: () => void; } & React.RefAttributes<HTMLDivElement>>; }; Item: <TItem extends import("@dxos/echo/Obj").Unknown = any>(props: BoardItemProps<TItem> & { ref?: React.Ref<HTMLDivElement>; }) => React.ReactElement; Placeholder: { ...; }; Debug: React.ForwardRefExoticComponent<Omit<{}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue; } & React.RefAttributes<HTMLDivElement>>;}
Board.type Root: <TColumn = any, TItem = any>(props: BoardRootProps<TColumn, TItem>) => React.ReactElement
Root> </const Dnd: { Root: { ({ children }: { children?: React.ReactNode | undefined; }): React.JSX.Element; displayName: string; };}
Dnd.type Root: { ({ children }: { children?: React.ReactNode | undefined; }): React.JSX.Element; displayName: string;}
Root> </JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div> </const SetTasksContext: React.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>
Writes one column's cards; the board's columns read it from context.
SetTasksContext.Context<(id: string, update: (tasks: Task[]) => Task[]) => void>.Provider: React.Provider<(id: string, update: (tasks: Task[]) => Task[]) => void>
Provider> );};
TaskColumn gives its eventHandler to the column’s body, and its canDrop takes only tasks. Board.Content gets
columnHandler, which takes only columns. The header’s dragHandleRef sets the handle that drags the column.
The story at the top of this page runs this example.
Composer’s Kanban plugin uses Board over ECHO objects, where each column is a value of a field and a drop writes the
field.