Org Chart
NewCustomize
Open levels2
Installation
npx shadcn@latest add https://uibrik.com/r/org-chart.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/org-chart/org-chart.tsx"use client"; import { useEffect, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type PointerEvent as ReactPointerEvent, type ReactNode, } from "react"; import { AnimatePresence, MotionConfig, animate, motion, useMotionValue, useReducedMotion, useTransform, type MotionValue } from "motion/react"; import { IconFocusCentered, IconMinus, IconPlus, IconSearch, IconX } from "@tabler/icons-react"; import { cn } from "@/lib/utils"; import { Avatar, EASE_OUT, FOCUS, LABEL, SHELL } from "../_app/app-kit"; // Org chart explorer. The tree pans (drag, or scroll on a trackpad) and zooms // (pinch, Ctrl/Cmd-scroll, or the buttons) around the pointer. Every node // expands and collapses its reports: children grow out of their manager and // fold back into it, connectors stretch with them, and the camera follows so // the node you pressed stays under your pointer. Large teams of individual // contributors stack in a column instead of spreading the tree wide. //
Adds the files to
components/uibrik/org-chart and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/org-chart.Usage
import { OrgChart } from "@/components/uibrik/org-chart/org-chart";const teamColors = { Executive: "#71717a", Engineering: "#6366f1", Design: "#ec4899", Sales: "#f59e0b", Operations: "#10b981",};<OrgChart defaultDepth={2} stackReports minimap teamColors={teamColors} onSelect={(person) => {}} // root={…}/>Props
OrgChart- defaultDepth
- Type number
- 2
- Levels of the tree open on mount.
- stackReports
- Type boolean
- true
- Teams of three or more individual contributors sit in a column under their manager.
- minimap
- Type boolean
- true
- Overview of the whole tree in the corner. Hidden on narrow screens.
- root
- Type OrgPerson
- SAMPLE_ORG
- { id, name, title, team?, avatar?, email?, location?, timeZone?, reports?: OrgPerson[] }. The person at the top.
- teamColors
- Type Record<string, string>
- DEFAULT_TEAM_COLORS
- Colour of the dot beside each team's titles.
- onSelect
- Type (person: OrgPerson | null) => void
- –
- Called when someone is selected or the profile closes.
- className
- Type string
- –
- Classes for the outer shell. It fills its parent's height.