{"id":30330115,"url":"https://github.com/naivefun/handtree","last_synced_at":"2025-08-18T02:39:48.025Z","repository":{"id":309994346,"uuid":"1038309730","full_name":"naivefun/handtree","owner":"naivefun","description":"A React tree component for hand-crafted hierarchical interfaces","archived":false,"fork":false,"pushed_at":"2025-08-15T02:38:37.000Z","size":284,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-15T03:26:09.512Z","etag":null,"topics":["react","react-tree","schema-editor","tree-component"],"latest_commit_sha":null,"homepage":"https://naivefun.github.io/handtree/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naivefun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-15T01:05:35.000Z","updated_at":"2025-08-15T02:38:38.000Z","dependencies_parsed_at":"2025-08-15T03:26:19.980Z","dependency_job_id":"a6161dd4-61e5-43b5-acb5-7fa78cedc10f","html_url":"https://github.com/naivefun/handtree","commit_stats":null,"previous_names":["naivefun/handtree"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/naivefun/handtree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naivefun%2Fhandtree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naivefun%2Fhandtree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naivefun%2Fhandtree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naivefun%2Fhandtree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naivefun","download_url":"https://codeload.github.com/naivefun/handtree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naivefun%2Fhandtree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270935917,"owners_count":24670940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","react-tree","schema-editor","tree-component"],"created_at":"2025-08-18T02:39:46.782Z","updated_at":"2025-08-18T02:39:47.994Z","avatar_url":"https://github.com/naivefun.png","language":"TypeScript","readme":"# handtree\n\n[![npm version](https://badge.fury.io/js/handtree.svg)](https://badge.fury.io/js/handtree)\n[![npm downloads](https://img.shields.io/npm/dm/handtree.svg)](https://www.npmjs.com/package/handtree)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/handtree)](https://bundlephobia.com/package/handtree)\n[![TypeScript](https://img.shields.io/badge/TypeScript-ready-blue.svg)](https://www.typescriptlang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA React tree component for **hand-crafted** hierarchical interfaces. Unlike data-driven tree libraries, handtree lets you compose tree structures manually with full control over styling, behavior, and layout.\n\n**[📖 Live Examples \u0026 Documentation →](https://naivefun.github.io/handtree/)**\n\n## Why handtree?\n\nMost tree components are data-driven - they work well when you can normalize your data into a homogeneous structure like `{id, children}`. But many real-world scenarios resist this normalization:\n\n```tsx\n// Hard to normalize - different node types, mixed content\nconst jsonSchema = {\n  User: { type: 'object', required: true, properties: {\n    id: { type: 'string', validation: /\\d+/ },\n    profile: { type: 'object', properties: {\n      name: { type: 'string', maxLength: 50 },\n      settings: { type: 'array', items: 'string' }\n    }}\n  }}\n}\n```\n\nhandtree is perfect when you need to:\n1. **Handle complex nested data structures** that don't fit a uniform schema\n2. **Different node content and behaviors** for different node types (objects vs arrays vs primitives, each with unique styling and interactions)\n\nInstead of forcing your data into a generic tree format, handtree lets you craft each node type exactly as it should appear and behave.\n\n\u003ca href=\"./assets/schema-editor.png\"\u003e\n  \u003cimg src=\"./assets/schema-editor.png\" alt=\"OpenAPI Schema Editor built with handtree\" width=\"600\"\u003e\n\u003c/a\u003e\n\n*Real-world usage: OpenAPI schema editor where each field type (object, array, string, number) has unique rendering, metadata, and interactions. Note the rich details below each field (descriptions, examples, constraints) - this level of content is difficult and often not worth normalizing into a generic tree structure.*\n\n## Used in Production\n\nhandtree powers the hierarchical interfaces in [reapi.com](https://reapi.com) - an OpenAPI schema editor and no-code testing platform. It handles complex nested schemas with hundreds of nodes while maintaining smooth performance and user experience.\n\n## Installation\n\n```bash\nnpm install handtree\n# or\npnpm add handtree\n# or  \nyarn add handtree\n```\n\n## How it works\n\nThe core pattern is using `TreeNode` as a **visual renderer** inside your own data-type-oriented components. You don't use `TreeNode` directly - instead, you create components that understand your specific data structure and use `TreeNode` to render the tree visualization.\n\n```tsx\n// Your data-oriented component\nfunction JsonSchemaNode({ schema, level }) {\n  return (\n    \u003cTreeNode\n      level={level}\n      expandable={schema.type === 'object'}\n      title={\u003cSchemaTitle data={schema} /\u003e}\n      details={\u003cSchemaDetails data={schema} /\u003e}\n    \u003e\n      {schema.properties?.map(prop =\u003e \n        \u003cJsonSchemaNode key={prop.name} schema={prop} level={level + 1} /\u003e\n      )}\n    \u003c/TreeNode\u003e\n  )\n}\n\n// Your custom title component\nfunction SchemaTitle({ data }) {\n  return (\n    \u003cspan className=\"flex items-center gap-2\"\u003e\n      \u003cspan className=\"text-blue-600 font-bold\"\u003e{data.name}\u003c/span\u003e\n      \u003cspan className=\"text-gray-500\"\u003e:\u003c/span\u003e\n      \u003cspan style={{ color: getTypeColor(data.type) }}\u003e{data.type}\u003c/span\u003e\n      {data.required \u0026\u0026 \u003cspan className=\"text-xs bg-red-100 text-red-800 px-1 rounded\"\u003erequired\u003c/span\u003e}\n    \u003c/span\u003e\n  )\n}\n\n// Your custom details component  \nfunction SchemaDetails({ data }) {\n  return data.description ? (\n    \u003cdiv className=\"text-xs text-gray-600 italic py-1\"\u003e\n      {data.description}\n      {data.validation \u0026\u0026 \u003ccode className=\"ml-2 bg-gray-100 px-1\"\u003e{data.validation.toString()}\u003c/code\u003e}\n    \u003c/div\u003e\n  ) : null\n}\n\n// Usage\n\u003cTreeContext.Provider value={{ indent: 24, ancestorLastTrail: [], classNames: {} }}\u003e\n  \u003cJsonSchemaNode schema={mySchema} level={0} /\u003e\n\u003c/TreeContext.Provider\u003e\n```\n\nThis way, `JsonSchemaNode` handles the business logic (what's expandable, how to render titles), while `TreeNode` handles the tree visualization (lines, indentation, expand/collapse UI).\n\n## Beyond Title: Rich Details Support\n\nUnlike traditional tree components that only show a title per node, handtree supports rich **details** content below each title. This is perfect for showing:\n\n- **Documentation** (API descriptions, schema details)\n- **Metadata** (file sizes, timestamps, validation rules)  \n- **Status indicators** (health checks, build results)\n- **Secondary actions** (buttons, links, badges)\n\nThe details section maintains proper tree indentation and connecting lines, creating a clean hierarchical layout even with complex content.\n\n## API Reference\n\n### TreeContext\n\nProvides configuration for the entire tree.\n\n```tsx\ninterface ITreeContext {\n  indent: number                    // Indentation per level (px)\n  ancestorLastTrail: boolean[]      // Internal: tracks line drawing\n  classNames: Record\u003cstring, string\u003e // Custom CSS classes\n}\n```\n\n### TreeNode\n\nThe visual renderer component. This handles tree UI concerns (indentation, connecting lines, expand/collapse icons) while you handle the data concerns in your wrapper component.\n\n```tsx\ninterface TreeNodeProps {\n  level: number                     // Nesting level (0 = root)\n  lastNode?: boolean               // Is this the last sibling?\n  title: React.ReactNode           // Node content (your custom JSX)\n  details?: React.ReactNode        // Additional details below title\n  children?: React.ReactNode       // Child nodes (usually more of your wrapper components)\n  expandable?: boolean             // Can this node be expanded?\n  expanded?: boolean               // Is this node expanded?\n  onToggleExpanded?: () =\u003e void    // Expand/collapse handler\n}\n```\n\n**Key responsibilities:**\n- **Visual structure**: Draws connecting lines, handles indentation\n- **Expand/collapse UI**: Shows icons and handles click interactions\n- **Layout**: Positions title, details, and children properly\n\n**Your wrapper component handles:**\n- **Data interpretation**: What should be expandable? What's the title?\n- **Business logic**: State management, event handling\n- **Content rendering**: Custom styling, icons, badges, etc.\n\n## Examples\n\nExplore interactive examples and see handtree in action:\n\n**[📖 Live Examples \u0026 Documentation →](https://naivefun.github.io/handtree/)**\n\n### Available Examples\n\n- **Basic Tree View** - Simple hierarchical structure showing the core TreeNode API\n- **Interactive JSON Schema Explorer** - Complex nested data with custom styling, expand/collapse state management, and rich details content. Perfect example of handling heterogeneous data structures that resist normalization.\n- **Minimal Example** - Lightweight implementation showing the essential patterns\n\n## Customizing Styles\n\nhandtree uses prefixed CSS classes that you can easily override:\n\n```css\n/* Customize tree lines color */\n.handtree-root {\n  --outline-color: #0066cc;\n}\n\n/* Style the expand/collapse icons */\n.handtree-head {\n  color: #666;\n}\n.handtree-head:hover {\n  color: #0066cc;\n}\n\n/* Customize spacing */\n.handtree-root {\n  --indent-width: 32px;\n  --head-width: 30px;\n}\n```\n\n**Available CSS classes:**\n- `.handtree-root` - Root container\n- `.handtree-node` - Individual node wrapper  \n- `.handtree-head` - Expand/collapse area\n- `.handtree-title` - Title content area\n- `.handtree-details` - Details content area\n- `.handtree-content` - Main content wrapper\n- `.handtree-indent` - Indentation guides\n\n**CSS Variables:**\n- `--outline-color` - Tree connecting lines color\n- `--indent-width` - Indentation per level  \n- `--head-width` - Width of expand/collapse area\n\n## Development\n\n```bash\n# Install dependencies  \npnpm install\n\n# Start development with hot reload\npnpm dev\n\n# View component demos\npnpm ladle:serve\n\n# Build for production\npnpm build\n```\n\n## Contributing\n\nWe welcome contributions! Please see our contributing guidelines for details.\n\n## License\n\nMIT © [Your Name]","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaivefun%2Fhandtree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaivefun%2Fhandtree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaivefun%2Fhandtree/lists"}