TANCN Documentation

repository·main·Indexed 20 days ago

https://github.com/vijayabaskar56/tancn

A form and table builder application built with TanStack technologies. TANCN provides a visual drag-and-drop interface to create dynamic, type-safe forms and performant tables with automatic code generation, real-time preview, and integration with ShadCN UI, Radix UI, and Tailwind CSS. It includes specialized components like MiniFormBuilder, DataGrid, and a comprehensive ThemeProvider for managing application appearance.

Tokens
10.2K
Snippets
33
Records
38
Agent score
71%

What's inside TANCN

  1. Overview of TANCN features

    main

    TANCN is a form and table builder designed for TanStack users. Key capabilities include:

    • Drag & Drop Builder: Visual interface for rapid form and table construction.
    • Type-Safe Code Generation: Produces fully typed React components and automatic validation schemas.
    • ShadCN UI Integration: Generates accessible components using ShadCN UI, Radix UI, and Tailwind CSS.
    • Advanced Form Structures: Supports multi-step forms and dynamic field arrays.
    • Data-Grid & Filtering: Capability to build complex tables with advanced filtering for large datasets.
    • Configuration Management: Save, share, and export configurations and generated code.
  2. How to use the TANCN Form Builder

    main

    TANCN provides a visual interface to build complex, type-safe forms and tables. Follow these steps to generate code for your project:

    1. Navigate to the Form Builder: Access the builder section within the application.
    2. Build UI: Use the drag-and-drop interface to add and arrange form fields.
    3. Configure Logic: Set up validation rules and specific field properties.
    4. Live Preview: Use the real-time preview feature to test form behavior and styling as you build.
    5. Export: Once satisfied, export the generated code to integrate it into your React/TypeScript project.
  3. Install and run TANCN locally

    main

    To set up the TANCN development environment, clone the repository, install dependencies using bun, and start the web development server.

    Prerequisites

    • Bun installed on your system.

    Setup Steps

    1. Clone the repository:
      git clone <repository-url>
      cd tancn
    2. Install dependencies:
      bun install
    3. Start the development server:
      bun run dev:web

    Once started, the application is accessible at http://localhost:3001.

    git clone <repository-url>
    cd tancn
    bun install
    bun run dev:web
  4. Apply fade masks to ScrollArea

    main

    You can add visual fade masks to the edges of a ScrollArea to indicate more content is available. This is controlled via the maskHeight prop. When the content is scrolled to an edge, the mask for that edge will fade out.

    • Set maskHeight={0} to disable masks entirely.
    • The mask uses the background color of your theme to create the fade effect.
    // Adds a 50px fade mask to the top and bottom edges
    <ScrollArea maskHeight={50}>
      {/* content */}
    </ScrollArea>
  5. Use the ThemeProvider to manage application appearance

    main

    Wrap your application with ThemeProvider to enable theme switching and persistence. It supports light/dark modes, system preference synchronization, and custom theme attributes (like data-theme or class).

    Key configuration options:

    • themes: An array of available theme names (e.g., ['light', 'dark', 'ocean']).
    • defaultTheme: The theme to use if no preference is stored. If enableSystem is true, this can be 'system'.
    • attribute: The HTML attribute used to apply the theme. Can be 'class', a data-* string (e.g., 'data-theme'), or an array of both.
    • value: A mapping object to translate theme names to specific attribute values.
    • enableSystem: If true, allows the 'system' theme which follows the user's OS preference.
    • storageKey: The localStorage key used to persist the user's choice.
    <ThemeProvider 
      themes={['light', 'dark']} 
      defaultTheme='system' 
      attribute='class'
    >
      <App />
    </ThemeProvider>
  6. Configure theme attribute mapping with the value prop

    main

    If your theme names do not match the exact values you want to appear in your HTML attributes (e.g., you want a theme named ocean to apply the class theme-ocean), use the value prop in ThemeProvider.

    The value prop is an object where the key is the theme name and the value is the attribute value.

    <ThemeProvider
      themes={['light', 'dark', 'ocean']}
      attribute="class"
      value={{
        light: 'theme-light',
        dark: 'theme-dark',
        ocean: 'theme-ocean'
      }}
    >
      <App />
    </ThemeProvider>
  7. Configure ScrollBar visibility with the `type` prop

    main

    The type prop on ScrollArea determines when the scrollbar is visible on pointer-based devices:

    • "hover": The scrollbar is hidden by default and becomes visible when hovering over the area.
    • "scroll": The scrollbar is hidden by default and becomes visible while the user is actively scrolling.
    • "always": The scrollbar is always visible.
    • "auto": (Implicitly handled by the underlying primitive) standard behavior.
    // Scrollbar only shows when hovering
    <ScrollArea type="hover">
      {/* content */}
    </ScrollArea>
    
    // Scrollbar only shows during active scrolling
    <ScrollArea type="scroll">
      {/* content */}
    </ScrollArea>
  8. Configure useFileUpload options

    main

    When initializing useFileUpload, you can pass a FileUploadOptions object to customize validation and behavior:

    OptionTypeDefaultDescription
    maxFilesnumberInfinityMaximum number of files allowed (only applies if multiple is true).
    maxSizenumberInfinityMaximum file size in bytes.
    acceptstring"*"Comma-separated list of accepted file types or extensions (e.g., "image/*, .pdf").
    multiplebooleanfalseWhether multiple files can be selected/uploaded.
    initialFilesFileMetadata[][]An array of existing file metadata to seed the initial state.
    onFilesChange(files: FileWithPreview[]) => voidundefinedCallback triggered whenever the file list changes.
    onFilesAdded(addedFiles: FileWithPreview[]) => voidundefinedCallback triggered specifically when new valid files are added.
  9. Configure the DataGrid component

    main

    The DataGrid component is a wrapper around @tanstack/react-table that provides layout styling, loading states, and context for child components. It requires a table instance from TanStack Table.

    Key Props

    • table: The TanStack Table instance (required).
    • recordCount: Total number of records (required).
    • isLoading: Boolean indicating if the grid is in a loading state.
    • loadingMode: Determines the loading UI style. Options: 'skeleton' (default) or 'spinner'.
    • onRowClick: Callback function triggered when a row is clicked.
    • tableLayout: Configuration object for visual styling (e.g., dense, rowBorder, headerSticky, columnsResizable).
    • tableClassNames: Object to override specific CSS classes for parts of the table (e.g., base, header, body, footer).
    import { DataGrid } from "@/components/ui/data-grid";
    
    <DataGrid
      table={tableInstance}
      recordCount={totalCount}
      isLoading={loading}
      tableLayout={{
        dense: true,
        rowBorder: true,
        headerSticky: true,
      }}
    >
      {/* Grid children components go here */}
    </DataGrid>
  10. Customize ScrollBar with the ScrollBar component

    main

    The ScrollBar component can be used to manually place or customize the scrollbar. It is designed to work within a ScrollArea context. Note that on touch devices, ScrollBar will return null and render nothing.

    Props

    PropTypeDefaultDescription
    orientation"vertical" | "horizontal""vertical"The direction of the scrollbar.
    classNamestring-CSS classes for the scrollbar container.
    import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
    
    function Example() {
      return (
        <ScrollArea className="h-[200px]">
          <div className="p-4">Content</div>
          <ScrollBar orientation="vertical" />
        </ScrollArea>
      );
    }
  11. Use FormElementsDropdown to add nested or multi-step elements

    main

    The FormElementsDropdown component is used to append new form elements to a specific field index or step within a multi-step form. It provides a dropdown menu containing a list of available form elements (excluding static ones by default).

    Props

    • fieldIndex (optional): The index of the field where the nested element should be appended.
    • stepIndex (optional): The index of the form step.
    • type (optional): Determines the insertion logic. Use 'MS' for multi-step or 'FA' for form arrays.
    • arrayId (optional): Required if type is 'FA' to specify which form array is being updated.
    • j (optional): Used when isFormArrayField is true to specify a sub-index.
    • isFormArrayField (optional): Boolean flag to indicate if the element is being added to a form array field.
    <FormElementsDropdown 
      fieldIndex={0} 
      stepIndex={1} 
      type="MS" 
    />
  12. Use UnifiedFormElementsDropdown for different insertion contexts

    main

    The UnifiedFormElementsDropdown component is a versatile component that adapts its behavior and UI based on the provided context. It is ideal when you need a single component type to handle different structural additions in your form builder.

    Contexts

    • nested: Appends an element to a specific fieldIndex within a step.
    • multistep: Appends an element to a specific stepIndex (sets fieldIndex to null).
    • formarray: Creates a new FormElement with default properties (like id, name, and label) and appends it to the arrayField of a specific formArrayId.

    Props

    • context: One of 'nested', 'multistep', or 'formarray'.
    • fieldIndex (optional): Required for nested context.
    • stepIndex (optional): Required for multistep context.
    • formArrayId (optional): Required for formarray context.

    Supported Form Element Types (for formarray context)

    When using the formarray context, the component automatically initializes the new element with appropriate defaults for types such as Input, Textarea, Checkbox, Select, RadioGroup, Switch, Slider, DatePicker, Password, OTP, MultiSelect, and ToggleGroup.

    // Example for adding to a form array
    <UnifiedFormElementsDropdown 
      context="formarray" 
      formArrayId="field_123" 
    />
    
    // Example for adding to a multi-step form
    <UnifiedFormElementsDropdown 
      context="multistep" 
      stepIndex={0} 
    />