본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

OrganizationChart

원문 보기 위키 갱신

OrganizationChart은 계층적인 조직 데이터를 시각화하는 컴포넌트예요. 트리 구조의 조직도를 그릴 때, 연결선과 중첩을 직접 관리하지 않아도 되게 해줘요.

출처: 문서

본문

사용법 (Usage)

import { OrganizationChart } from '@primereact/ui/organizationchart';

_OrganizationChart.Nodes_는 노드마다 렌더 함수를 한 번씩 호출하고 연결선과 중첩을 대신 만들어 줘요. 코드에 재귀가 필요 없어요. 각 노드는 _uKey_로 식별돼요.

<OrganizationChart.Root value={data}>
    <OrganizationChart.Nodes>
        {({ node }) => (
            <OrganizationChart.Node uKey={node.key}>
                <OrganizationChart.Content>
                    <OrganizationChart.Label>{node.label}</OrganizationChart.Label>
                </OrganizationChart.Content>
            </OrganizationChart.Node>
        )}
    </OrganizationChart.Nodes>
</OrganizationChart.Root>

예시 (Examples)

기본 (Basic)

기본 차트는 _value_에서 노드 모음을 렌더링해요.

접기 (Collapsible)

_OrganizationChart.Toggle_과 OrganizationChart.ToggleIndicator 그리고 그 match 속성(expanded 또는 collapsed)을 추가하면, 노드가 자기 하위 트리를 접을 수 있게 돼요. 노드는 자식이 있을 때 접을 수 있어요.

제어 (Controlled)

_collapsedKeys_와 onCollapsedChange 속성으로 확장을 프로그래밍 방식으로 제어할 수 있어요. true로 존재하는 키는 접힌 상태이고, 없는 키는 펼쳐진 상태를 유지해요.

콘텐츠 (Content)

OrganizationChart.Content 안에는 무엇이든 렌더링할 수 있어요. 노드 페이로드가 여러분만의 데이터 필드를 담고 있어요.

선택 (Selection)

단일 (Single)

_selectionMode_를 _single_로 설정하면 최대 하나의 노드만 선택 상태를 유지해요. 선택은 _selectionKeys_와 _onSelectionChange_로 바인딩해요.

다중 (Multiple)

_multiple_에서는 각 노드가 독립적으로 토글돼요.

체크박스 (Checkbox)

checkbox 모드에서 _OrganizationChart.Selection_은 isSelected, isPartiallySelected, _toggle_을 노출해요. 노드를 선택하면 하위 항목으로 전파되고 조상 노드에 부분 선택 상태를 반영해요.

서브 컴포넌트 (Sub-Components)

OrganizationChart.Root, OrganizationChart.Nodes, OrganizationChart.Node, OrganizationChart.Content, OrganizationChart.Label, OrganizationChart.Toggle, OrganizationChart.ToggleIndicator, _OrganizationChart.Selection_은 Primitive API에서 확인하세요.

훅 (Hooks)

_useOrganizationChart_는 Headless API에서 확인하세요.

접근성 (Accessibility)

WAI-ARIA 준수 세부사항과 키보드 지원은 OrganizationChart Primitive에서 확인하세요.

OrganizationChart API

OrganizationChart 컴포넌트의 API 문서예요.

OrganizationChartRoot

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartRootInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartRootInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartRootInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartRootInstance) => ReactNode null The render function to render the component with instance access.
children any null The children to render.

Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access. Typed as any to avoid JSX type errors when used directly in templates. | | value | TreeNode[] | null | The data of the org chart. | | gap | number | number[] | [40, 56] | The gap between nodes, as a single value or [x, y] . | | selectionMode | "checkbox" | "multiple" | "single" | null | The selection mode. When omitted, nodes are not selectable. checkbox cascades selection to descendants and reflects a partial state on ancestors. | | collapsedKeys | OrganizationChartCollapsedKeys | null | Controlled collapsed keys. A key with true is collapsed; absent keys are expanded. | | defaultCollapsedKeys | OrganizationChartCollapsedKeys | null | Initial collapsed keys for uncontrolled mode. | | onCollapsedChange | (event: UseOrganizationChartCollapsedChangeEvent) => void | null | Fires when the collapsed state changes. | | selectionKeys | OrganizationChartSelectionKeys | null | Controlled selection keys. | | defaultSelectionKeys | OrganizationChartSelectionKeys | null | Initial selection keys for uncontrolled mode. | | onSelectionChange | (event: UseOrganizationChartSelectionChangeEvent) => void | null | Fires when the selection state changes. | | [key: string] | any | null | | | pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |

State

Name Type Default Description
collapsedKeys OrganizationChartCollapsedKeys null The current collapsed keys.
selectionKeys OrganizationChartSelectionKeys null The current selection keys.

Exposes

Name Type Default Description
getNodes () => TreeNode[] null Returns the org chart nodes (the original value ).
findNodeByKey (key: string) => undefined | TreeNode null Looks up a node by its key.
getNodeLevel (key: string) => number null Returns the 1-based depth of a node by its key.
toggleNodeSelect (key?: string, event?: SyntheticEvent<Element, Event>) => void null Toggle the selection state of a node (respecting selectionMode ).
toggleNodeCollapse (key?: string, event?: SyntheticEvent<Element, Event>) => void null Toggle the collapsed state of a node.
isExpandable (node?: TreeNode) => boolean null Whether a node can be expanded/collapsed (has children).
isSelectable () => boolean null Whether nodes are selectable (a selectionMode is set).
isCollapsed (node?: TreeNode) => boolean null Whether a node is collapsed.
isSelected (node?: TreeNode) => boolean null Whether a node is selected.
isPartiallySelected (node?: TreeNode) => boolean null Whether a node is partially selected (checkbox mode).
rootProps { data-scope: "organizationchart"; data-part: "root"; role: "tree"; aria-multiselectable: boolean } null Returns pre-built props for the root element.
getTreeProps (node: undefined | TreeNode, level: number) => UseOrganizationChartTreeProps null Returns pre-built props for a tree (connector wrapper) element.
getNodeProps (node: undefined | TreeNode, handleClick: (event: MouseEvent) => void) => UseOrganizationChartNodeProps null Returns pre-built props for a node element.
getCollapseButtonProps (node: undefined | TreeNode, handleClick: (event: MouseEvent) => void) => { data-scope: "organizationchart"; data-part: "toggle"; onClick: (event: MouseEvent) => void; onKeyDown: (event: KeyboardEvent) => void } null Returns pre-built props for a collapse toggle button element.
getToggleIndicatorProps () => { data-scope: "organizationchart"; data-part: "toggle-indicator"; aria-hidden: true } null Returns pre-built props for the toggle indicator (state-matched icon slot) element.
subtreeProps { data-scope: "organizationchart"; data-part: "subtree"; role: "group" } null Pre-built props for the children subtree element.
orgChartStyle CSSProperties null CSS custom properties for the configured gap.
handleNodeKeyDown (event: KeyboardEvent, key?: string) => void null Handles key down on a node.
handleCollapseKeyDown (event: KeyboardEvent, key?: string) => void null Handles key down on a collapse button.
state OrganizationChartRootState null The state of the OrganizationChart component.

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChart component. [object Object]

Types

Label Description Data
Instance Instance of OrganizationChart component. [object Object]

OrganizationChartNodes

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartNodesInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartNodesInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartNodesInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartNodesInstance) => ReactNode null The render function to render the component with instance access.
children ReactNode | ((row: OrganizationChartNodeRow) => ReactNode) null Render-prop. Called once per node with its row payload; must return the node UI.
[key: string] any null
pt-{optionName}-* - null Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChartNodes component. [object Object]

Types

Label Description Data
Instance Instance of OrganizationChartNodes component. [object Object]

OrganizationChartNode

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartNodeInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartNodeInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartNodeInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartNodeInstance) => ReactNode null The render function to render the component with instance access.
children any null The children to render.

Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access. Typed as any to avoid JSX type errors when used directly in templates. | | uKey | string | '' | The unique key identifying this node in the data. Used to resolve node state from the headless layer. | | [key: string] | any | null | | | pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |

Exposes

Name Type Default Description
node undefined | TreeNode null The resolved node data, or undefined when the key is unknown.
expanded boolean null Whether the node is expanded (not collapsed).
leaf boolean null Whether the node has no children.
selected boolean null Whether the node is selected.

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChartNode component. [object Object]

Types

Label Description Data
Instance Instance of OrganizationChartNode component. [object Object]

OrganizationChartContent

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartContentInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartContentInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartContentInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartContentInstance) => ReactNode null The render function to render the component with instance access.
children any null The children to render.

Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access. Typed as any to avoid JSX type errors when used directly in templates. | | [key: string] | any | null | | | pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChartContent component. [object Object]

OrganizationChartLabel

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartLabelInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartLabelInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartLabelInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartLabelInstance) => ReactNode null The render function to render the component with instance access.
children any null The children to render.

Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access. Typed as any to avoid JSX type errors when used directly in templates. | | [key: string] | any | null | | | pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChartLabel component. [object Object]

OrganizationChartToggle

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartToggleInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartToggleInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartToggleInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartToggleInstance) => ReactNode null The render function to render the component with instance access.
children any null The children to render.

Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access. Typed as any to avoid JSX type errors when used directly in templates. | | [key: string] | any | null | | | pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |

Exposes

Name Type Default Description
isExpanded boolean null Whether the associated node is expanded (not collapsed).

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChartToggle component. [object Object]

OrganizationChartToggleIndicator

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartToggleIndicatorInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartToggleIndicatorInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartToggleIndicatorInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartToggleIndicatorInstance) => ReactNode null The render function to render the component with instance access.
children any null The children to render.

Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access. Typed as any to avoid JSX type errors when used directly in templates. | | match | OrganizationChartToggleIndicatorMatch | 'always' | Render this slot only when the toggle state matches. always renders regardless of state. | | [key: string] | any | null | | | pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChartToggleIndicator component. [object Object]

Types

Label Description Data
Instance Instance of OrganizationChartToggleIndicator component. [object Object]

OrganizationChartSelection

Props

Name Type Default Description
ref Ref null The reference to the component instance.
pIf boolean true Whether the component should be rendered.
style CSSProperties | ((instance?: OrganizationChartSelectionInstance) => undefined | CSSProperties) null The style to apply to the component.
className string | ((instance?: OrganizationChartSelectionInstance) => undefined | string) null The class name to apply to the component.
as null | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent | ReactElement<unknown, string | JSXElementConstructor> | Iterable<ReactNode, any, any> | ReactPortal | Promise null The component type to render.
asChild boolean false Whether the component should be rendered as a child component.
instance OrganizationChartSelectionInstance null The instance to pass to the component.
pt SafeRecord null The pass-through props to pass to the component.
ptOptions PassThroughOptions null The pass-through options to pass to the component.
unstyled boolean null Whether the component should be rendered without classes.
dt unknown null The design token to use for the component.
styles StylesOptions null The styles to use for the component.
render (instance: OrganizationChartSelectionInstance) => ReactNode null The render function to render the component with instance access.
children any null The children to render.

Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access. Typed as any to avoid JSX type errors when used directly in templates. | | [key: string] | any | null | | | pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |

Exposes

Name Type Default Description
isSelected boolean null Whether the current node is selected.
isPartiallySelected boolean null Whether the current node is partially selected (checkbox mode — some but not all descendants selected).
isSelectable boolean null Whether the current node can be selected.
toggle (event: SyntheticEvent) => void null Toggle selection for the current node.

Interfaces

Label Description Data
PassThroughOptions Defines passthrough(pt) options of OrganizationChartSelection component. [object Object]

테마 (Theming)

CSS 클래스 (CSS Classes)

styled 모드에서 사용하는 클래스 이름 목록이에요.

ClassName Description
p-organizationchart Class name of the root element
p-organizationchart-tree Class name of the per-node connector wrapper element ( <li role="treeitem"> )
p-organizationchart-subtree Class name of the children subtree element ( <ul role="group"> )
p-organizationchart-node Class name of the node box element
p-organizationchart-node-content Class name of the node content element
p-organizationchart-node-label Class name of the node label element
p-organizationchart-node-toggle-button Class name of the toggle button element
p-organizationchart-node-toggle-button-icon Class name of the toggle indicator element (state-matched icon slot)
p-organizationchart-node-selection Class name of the selection slot element

디자인 토큰 (Design Tokens)

디자인 토큰 목록이에요.

Token CSS Variable Description
organizationchart.gutter --p-organizationchart-gutter Gutter of root
organizationchart.transition.duration --p-organizationchart-transition-duration Transition duration of root
organizationchart.node.background --p-organizationchart-node-background Background of node
organizationchart.node.hover.background --p-organizationchart-node-hover-background Hover background of node
organizationchart.node.selected.background --p-organizationchart-node-selected-background Selected background of node
organizationchart.node.border.color --p-organizationchart-node-border-color Border color of node
organizationchart.node.color --p-organizationchart-node-color Color of node
organizationchart.node.selected.color --p-organizationchart-node-selected-color Selected color of node
organizationchart.node.hover.color --p-organizationchart-node-hover-color Hover color of node
organizationchart.node.padding --p-organizationchart-node-padding Padding of node
organizationchart.node.toggleable.padding --p-organizationchart-node-toggleable-padding Toggleable padding of node
organizationchart.node.border.radius --p-organizationchart-node-border-radius Border radius of node
organizationchart.node.font.size --p-organizationchart-node-font-size Font size of node
organizationchart.node.font.weight --p-organizationchart-node-font-weight Font weight of node
organizationchart.node.focus.ring.width --p-organizationchart-node-focus-ring-width Focus ring width of node
organizationchart.node.focus.ring.style --p-organizationchart-node-focus-ring-style Focus ring style of node
organizationchart.node.focus.ring.color --p-organizationchart-node-focus-ring-color Focus ring color of node
organizationchart.node.focus.ring.offset --p-organizationchart-node-focus-ring-offset Focus ring offset of node
organizationchart.node.focus.ring.shadow --p-organizationchart-node-focus-ring-shadow Focus ring shadow of node
organizationchart.node.toggle.button.background --p-organizationchart-node-toggle-button-background Background of node toggle button
organizationchart.node.toggle.button.hover.background --p-organizationchart-node-toggle-button-hover-background Hover background of node toggle button
organizationchart.node.toggle.button.border.color --p-organizationchart-node-toggle-button-border-color Border color of node toggle button
organizationchart.node.toggle.button.color --p-organizationchart-node-toggle-button-color Color of node toggle button
organizationchart.node.toggle.button.hover.color --p-organizationchart-node-toggle-button-hover-color Hover color of node toggle button
organizationchart.node.toggle.button.size --p-organizationchart-node-toggle-button-size Size of node toggle button
organizationchart.node.toggle.button.border.radius --p-organizationchart-node-toggle-button-border-radius Border radius of node toggle button
organizationchart.node.toggle.button.focus.ring.width --p-organizationchart-node-toggle-button-focus-ring-width Focus ring width of node toggle button
organizationchart.node.toggle.button.focus.ring.style --p-organizationchart-node-toggle-button-focus-ring-style Focus ring style of node toggle button
organizationchart.node.toggle.button.focus.ring.color --p-organizationchart-node-toggle-button-focus-ring-color Focus ring color of node toggle button
organizationchart.node.toggle.button.focus.ring.offset --p-organizationchart-node-toggle-button-focus-ring-offset Focus ring offset of node toggle button
organizationchart.node.toggle.button.focus.ring.shadow --p-organizationchart-node-toggle-button-focus-ring-shadow Focus ring shadow of node toggle button
organizationchart.node.toggle.button.icon.size --p-organizationchart-node-toggle-button-icon-size Icon size of node toggle button
organizationchart.connector.color --p-organizationchart-connector-color Color of connector
organizationchart.connector.border.radius --p-organizationchart-connector-border-radius Border radius of connector
organizationchart.connector.height --p-organizationchart-connector-height Height of connector

더 알아보기 (Learn more)

  • OrganizationChart 서브 컴포넌트의 세부 API를 Primitive 문서에서 살펴보세요.
  • collapsedKeys와 체크박스 선택을 조합해 대화형 조직도를 만들어 보세요.