Astryx

Astryx Complex Selector

Component

About

An input or toolbar trigger and dialog-popover shell for custom selector content. Astryx by Meta. Source: https://astryx.atmeta.com/components/ComplexSelector

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Astryx Complex Selector to your project and fits it to your theme.

Code

How Astryx Complex Selector is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

'use client';

/* Copyright (c) 2026 Meta Platforms, Inc. See MIT notice in astryx-complex-selector.tsx. */

import '@/components/ui/astryx-complex-selector-utils/astryx-preview.css';
import {useMemo, useState} from 'react';
import {ComplexSelector} from '@/components/ui/astryx-complex-selector';
import {TextInput} from '@astryxdesign/core/TextInput';
import {TreeList, type TreeListItemData} from '@astryxdesign/core/TreeList';
import {Text} from '@astryxdesign/core/Text';
import {VStack} from '@astryxdesign/core/Layout';

interface DestinationNode {
  id: string;
  label: string;
  path: string;
  children?: DestinationNode[];
}

interface Destination {
  id: string;
  label: string;
  path: string;
}

const destinationTree: DestinationNode[] = [
  {
    id: 'workspace',
    label: 'Workspace',
    path: '/Workspace',
    children: [
      {
        id: 'research',
        label: 'Research',
        path: '/Workspace/Research',
        children: [
          {
            id: 'field-notes',
            label: 'Field notes',
            path: '/Workspace/Research/Field notes',
          },
          {
            id: 'interviews',
            label: 'Interviews',
            path: '/Workspace/Research/Interviews',
          },
        ],
      },
      {
        id: 'roadmap',
        label: 'Roadmap',
        path: '/Workspace/Roadmap',
      },
    ],
  },
  {
    id: 'teams',
    label: 'Teams',
    path: '/Teams',
    children: [
      {
        id: 'design-systems',
        label: 'Design systems',
        path: '/Teams/Design systems',
        children: [
          {
            id: 'accessibility',
            label: 'Accessibility',
            path: '/Teams/Design systems/Accessibility',
          },
        ],
      },
    ],
  },
];

function matches(node: DestinationNode, query: string): boolean {
  if (node.label.toLowerCase().includes(query)) {
    return true;
  }
  return (node.children ?? []).some(child => matches(child, query));
}

function filterTree(
  nodes: DestinationNode[],
  query: string,
): DestinationNode[] {
  if (!query) {
    return nodes;
  }
  return nodes
    .filter(node => matches(node, query))
    .map(node => ({
      ...node,
      children: node.children ? filterTree(node.children, query) : undefined,
    }));
}

function toItems(
  nodes: DestinationNode[],
  selectedId: string,
  onSelect: (value: Destination) => void,
): TreeListItemData[] {
  return nodes.map(node => {
    const hasChildren = (node.children ?? []).length > 0;
    return {
      id: node.id,
      label: node.label,
      isSelected: node.id === selectedId,
      isExpanded: true,
      onClick: hasChildren
        ? undefined
        : () => onSelect({id: node.id, label: node.label, path: node.path}),
      children: hasChildren
        ? toItems(node.children ?? [], selectedId, onSelect)
        : undefined,
    };
  });
}

function DestinationSearch({
  value,
  onChange,
  close,
}: {
  value: Destination;
  onChange: (value: Destination) => void;
  close: () => void;
}) {
  const [query, setQuery] = useState('');
  const items = useMemo(
    () =>
      toItems(
        filterTree(destinationTree, query.toLowerCase()),
        value.id,
        next => {
          onChange(next);
          close();
        },
      ),
    [query, value.id, onChange, close],
  );

  return (
    <VStack gap={3} style={{width: 'min(340px, calc(100vw - 64px))'}}>
      <TextInput
        label="Search destinations"
        isLabelHidden
        value={query}
        onChange={setQuery}
        hasClear
        placeholder="Search folders or teams"
      />
      {items.length > 0 ? (
        <TreeList items={items} density="compact" />
      ) : (
        <Text type="supporting" color="secondary">
          No matching destinations.
        </Text>
      )}
    </VStack>
  );
}

function OfficialSample() {
  const [value, setValue] = useState<Destination>({
    id: 'accessibility',
    label: 'Accessibility',
    path: '/Teams/Design systems/Accessibility',
  });

  return (
    <div style={{width: '100%', minWidth: 0, marginBlockEnd: 'max(0px, calc(790px - 100dvh))'}}>
      <ComplexSelector<Destination>
        label="Destination"
        description="Search and browse nested folders."
        value={value}
        onChange={setValue}
        triggerLabel={value.path}
        width="100%">
        {(selectedValue, onChange, close) => (
          <DestinationSearch
            value={selectedValue}
            onChange={onChange}
            close={close}
          />
        )}
      </ComplexSelector>
    </div>
  );
}

export default function Demo() {
  return (
    <div className="astryx-demo" data-astryx-theme="neutral" data-theme="light">
      <div className="astryx-demo-content" data-centered style={{maxWidth: 410}}>
        <OfficialSample />
      </div>
    </div>
  );
}

Dependencies

More by Astryx

View all
  • Astryx Banner

    Astryx Banner

    61
  • Astryx Avatar

    Astryx Avatar

    34
  • Astryx Aspect Ratio

    Astryx Aspect Ratio

    32
  • Astryx Badge

    Astryx Badge

    30
  • Astryx Button Group

    Astryx Button Group

    29
  • Astryx Chat Composer Drawer

    Astryx Chat Composer Drawer

    27
  • Astryx Toggle Button

    Astryx Toggle Button

    17
  • Astryx Chat Tokenized Text

    Astryx Chat Tokenized Text

    12