basecn
repository·main·Indexed 42 days ago
https://github.com/akash3444/basecnA 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.
What's inside basecn
- 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.
What is basecn?
mainbasecn 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.
Configure Button Group orientation, size, and styling
mainThe 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, orPopovercomponents for complex UI controls.
Use Input Group for various input enhancements
mainThe
Input Groupcomponent allows you to display additional information, icons, or actions alongside aninputortextarea. 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.
Use the Item component for versatile content display
mainThe
Itemcomponent 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.
Build forms with TanStack Form and Zod
mainThebasecnform system uses@tanstack/react-formandzodto create accessible, type-safe, and composable forms. It provides a hook-based API (useAppForm) and a component-based rendering pattern to handle validation, accessibility (ARIA attributes), and error messaging automatically.Use the Switch component
mainThe Switch component is a control that allows users to toggle between a checked and not checked state. It supports various configurations including disabled states, custom colors, thumb icons, and integration with forms.Configure Accordion behavior using the `multiple` prop
mainThe Accordion component controls whether multiple items can be open at once using the
multipleboolean prop.- Single mode (Default): When
multipleis not provided or isfalse, the accordion behaves as a single-item accordion (opening one item closes others). - Multiple mode: When
multipleistrue, 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>- Single mode (Default): When
Key features of basecn
mainbasecn 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.
Compose custom Progress layouts with ProgressLabel and ProgressValue
mainWhile the standard
Progresscomponent provides a basic bar, you can achieve complete control over layout and positioning by manually composing the component usingProgressTrackandProgressIndicator. This is required when you want to include descriptive labels or custom value displays.Using ProgressLabel
Use the
ProgressLabelcomponent to display a descriptive text label for the progress bar.Using ProgressValue
Use the
ProgressValuecomponent to display the current progress. It accepts a render function that provides two arguments:formattedValue: The value formatted with a percentage.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>How the Form component anatomy works
mainForms are built using a nested component structure. The
form.AppFormcomponent provides the context, whileform.AppFieldmanages individual field states via a render prop. Inside the field render prop, you useform.Itemto 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 afieldobject 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>Build complex Data Tables with TanStack Table
mainFor advanced functionality like sorting, filtering, and pagination, do not attempt to build these features manually within the<Table />component. Instead, combine the<Table />components with@tanstack/react-tableto create a robust Data Table.