basecn

repository·main·Indexed 42 days ago

https://github.com/akash3444/basecn

A React component library that enhances shadcn/ui components by building them on top of Base UI. It provides WAI-ARIA compliant foundations, expanded variants, and Tailwind CSS compatibility for components such as Accordion, Alert Dialog, Autocomplete, and Calendar.

Tokens
18.4K
Snippets
93
Records
156
Agent score
54%

What's inside basecn

  1. Overview of basecn

    main
    basecn is a modern React component library that provides enhanced versions of shadcn/ui components. It is built on top of Base UI to ensure high accessibility and performance. The library is designed for developers who want the styling flexibility of Tailwind CSS combined with the robust, WAI-ARIA compliant foundations of Base UI, offering additional variants and comprehensive usage examples for each component.
  2. What is basecn?

    main

    basecn is a component library that provides shadcn/ui-style components rebuilt on top of Base UI. It combines the familiar APIs and styling patterns of shadcn/ui with the accessibility and performance benefits of Base UI.

    Key characteristics include:

    • Copy-Paste Workflow: You own the full source code, allowing for complete customization without library lock-in.
    • Tailwind CSS: Components are styled using Tailwind utility classes.
    • TypeScript Support: Built with full type safety and IntelliSense support.
    • Base UI Foundation: Leverages Base UI for robust accessibility and keyboard navigation.
  3. Configure Button Group orientation, size, and styling

    main

    The Button Group component is a container for grouping related buttons. It supports several configuration patterns:

    • Orientation: Control the layout direction of the buttons.
    • Size: Adjust the sizing of the group and its constituent buttons.
    • Separators: Add visual dividers between buttons.
    • Split: Create a split button effect where one button is visually separated from the rest of the group.
    • Nesting: Place button groups within other button groups.
    • Input Integration: Use Button Groups in conjunction with Input, Input Group, Dropdown Menu, Select, or Popover components for complex UI controls.
  4. Use Input Group for various input enhancements

    main

    The Input Group component allows you to display additional information, icons, or actions alongside an input or textarea. It supports several common patterns:

    • Icons: Add visual cues inside the input field.
    • Text: Add static labels or suffixes (e.g., currency symbols or units).
    • Buttons: Add actionable elements like 'Search' or 'Clear' directly in the input area.
    • Tooltips: Provide contextual help via hoverable tooltips.
    • Spinners: Indicate loading states within the input.
    • Labels: Integrate labels directly with the input group.
    • Dropdowns: Provide selection menus within the input field.
    • Button Groups: Group multiple actions together within the input container.
    • Textarea Support: Works with multi-line text inputs as well.
  5. Use the Item component for versatile content display

    main

    The Item component is a versatile container designed to display various types of content. It supports several specialized sub-patterns and configurations including:

    • Variants: Different visual styles for the item.
    • Icon: Including icons within the item layout.
    • Avatar: Integrating user avatars.
    • Image: Displaying images as part of the item content.
    • Group: Organizing multiple items into a cohesive group.
    • Header: Adding header sections to items.
    • Link: Making the item or parts of it clickable.
    • Dropdown: Embedding dropdown menus within the item structure.
  6. Configure Accordion behavior using the `multiple` prop

    main

    The Accordion component controls whether multiple items can be open at once using the multiple boolean prop.

    • Single mode (Default): When multiple is not provided or is false, the accordion behaves as a single-item accordion (opening one item closes others).
    • Multiple mode: When multiple is true, multiple accordion items can be expanded simultaneously.

    This differs from Radix UI, which uses a type="single" | "multiple" prop.

    import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/accordion"
    
    // Single mode (Default)
    <Accordion>
      <AccordionItem value="item-1">
        <AccordionTrigger>Is it accessible?</AccordionTrigger>
        <AccordionContent>Yes. It adheres to the WAI-ARIA design pattern.</AccordionContent>
      </AccordionItem>
    </Accordion>
    
    // Multiple mode
    <Accordion multiple>
      <AccordionItem value="item-1">
        <AccordionTrigger>Is it accessible?</AccordionTrigger>
        <AccordionContent>Yes. It adheres to the WAI-ARIA design pattern.</AccordionContent>
      </AccordionItem>
    </Accordion>
  7. Key features of basecn

    main

    basecn provides several core advantages for building React applications:

    • Enhanced shadcn/ui Components: Extends standard shadcn/ui components with more variants and styling options.
    • Base UI Foundation: Uses MUI's Base UI for improved accessibility and performance.
    • Comprehensive Examples: Includes multiple demo variations for each component to showcase different use cases.
    • TypeScript First: Provides full TypeScript support with accurate type definitions.
    • Tailwind CSS Styling: Uses Tailwind CSS, making it easy to customize components within your existing design system.
    • Accessibility: All components are WAI-ARIA compliant.
  8. Compose custom Progress layouts with ProgressLabel and ProgressValue

    main

    While the standard Progress component provides a basic bar, you can achieve complete control over layout and positioning by manually composing the component using ProgressTrack and ProgressIndicator. This is required when you want to include descriptive labels or custom value displays.

    Using ProgressLabel

    Use the ProgressLabel component to display a descriptive text label for the progress bar.

    Using ProgressValue

    Use the ProgressValue component to display the current progress. It accepts a render function that provides two arguments:

    1. formattedValue: The value formatted with a percentage.
    2. progress: The raw progress value.

    This allows for custom formatting, such as appending units (e.g., 'lbs').

    import {
      Progress,
      ProgressLabel,
      ProgressTrack,
      ProgressIndicator,
      ProgressValue,
    } from "@/components/ui/progress";
    
    // Example: Progress with a Label
    <Progress value={50}>
      <ProgressLabel>Progress</ProgressLabel>
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </Progress>
    
    // Example: Progress with a custom formatted Value
    <Progress value={50}>
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
      <ProgressValue>{(formattedValue, progress) => `${progress} lbs`}</ProgressValue>
    </Progress>
  9. How the Form component anatomy works

    main

    Forms are built using a nested component structure. The form.AppForm component provides the context, while form.AppField manages individual field states via a render prop. Inside the field render prop, you use form.Item to group the label, control, description, and error message.

    Core Component Hierarchy:

    • <form.AppForm>: The root provider for the form context.
    • <form.AppField name="...">: A field wrapper that provides a field object via a render prop.
    • <form.Item>: A layout container for a single field's elements.
    • <field.Label>: The accessible label for the field.
    • <field.Control>: The container for the actual input element.
    • <field.Description>: Helper text or instructions for the field.
    • <field.Message>: The error message display for the field.
    <form.AppForm>
      <form.AppField name="...">
        {(field) => (
          <form.Item>
            <field.Label />
            <field.Control>
              { /* Your form field */ }
            </field.Control>
            <field.Description />
            <field.Message />
          </form.Item>
        )}
      </form.AppField>
    </form.AppForm>