more-button.tsx
Overview
The more-button.tsx file defines a reusable React component named MoreButton. This component renders a stylized button designed to indicate additional options or actions, commonly represented by an ellipsis icon (...). It leverages a base Button component and integrates the Ellipsis icon from the lucide-react icon library.
Key features of this component include:
Forwarding refs to allow parent components to access the underlying DOM button element.
Accepting all props supported by the base
Buttoncomponent (ButtonProps), enabling flexible customization.Applying specific styles that make the button invisible by default but visible on hover of its parent container (using TailwindCSS utility classes).
Setting a default button size to
iconwhen no size is provided, ensuring consistent icon button sizing.
This component is ideal for use cases such as dropdown triggers, contextual menus, or any UI element where additional user options need to be indicated succinctly.
Detailed Explanation
Imports
cn(from@/lib/utils): A utility function for conditional className concatenation.Ellipsis(fromlucide-react): An SVG icon component representing three dots (...).React: React library for UI composition.ButtonandButtonProps(from./ui/button): A base button component and its props interface, presumably styled and customized for the project.
MoreButton Component
export const MoreButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, size, ...props }, ref) => {
return (
<Button
ref={ref}
variant="ghost"
size={size || 'icon'}
className={cn('invisible group-hover:visible size-3.5', className)}
{...props}
>
<Ellipsis />
</Button>
);
},
);
Description
MoreButton is a React functional component that wraps the base Button component, forwarding the ref to it and rendering an Ellipsis icon inside. The component applies specific styling to control its visibility and size and accepts all typical button properties.
Parameters
className(string | undefined): Additional CSS classes to customize appearance.size(string | undefined): Controls the size of the button, defaults to'icon'if not provided....props(ButtonProps): Any other props accepted by the baseButtoncomponent.ref(React.Ref<HTMLButtonElement>): Ref forwarded to the underlying button element.
Return Value
Returns a React element representing a button styled as a "more options" button with an ellipsis icon.
Usage Example
import { MoreButton } from './more-button';
function Example() {
const buttonRef = React.useRef<HTMLButtonElement>(null);
return (
<div className="group relative">
<p>Item 1</p>
<MoreButton
ref={buttonRef}
onClick={() => alert('More options clicked')}
aria-label="More options"
/>
</div>
);
}
In this example, the MoreButton is invisible by default and becomes visible when the surrounding div with the group class is hovered, enabling contextual access to additional actions.
Implementation Details
Styling Logic: The component uses TailwindCSS classes:
invisiblehides the button by default.group-hover:visiblemakes the button visible when the parent.groupcontainer is hovered.size-3.5presumably controls the button's size to approximately 3.5 units (custom Tailwind sizing).
Default Size: If no
sizeprop is provided, it defaults to'icon', which is likely a predefined size for icon-only buttons in the baseButtoncomponent.Ref Forwarding: Using
React.forwardRefallows consumers ofMoreButtonto obtain a reference to the actual button element, useful for focusing or managing focus programmatically.Composition: The component is composed atop the base
Buttoncomponent, ensuring consistent styling and behavior across the UI library.
Interactions with Other System Components
Base Button (
./ui/button):MoreButtonrelies on the baseButtoncomponent for core button functionality, styling variants, and prop typings.Icon Library (
lucide-react): Uses theEllipsisicon from this SVG icon library for consistent and scalable iconography.Utility (
cn): Thecnutility function merges conditional and static class names to form the finalclassNameprop passed to the button.Parent Components / Layouts: The visibility toggle relies on the parent element having the
groupclass to enable thegroup-hoverTailwind feature.
Visual Diagram
componentDiagram
MoreButton <.. Button : uses
MoreButton --> Ellipsis : renders inside
MoreButton --> cn : uses for className concatenation
Summary
The more-button.tsx file provides a specialized button component that integrates an ellipsis icon inside a styled button element. Its primary purpose is to offer a visually subtle button that reveals itself on hover, commonly used to represent "more options" in a UI. Built on top of a base Button component and utilizing iconography from lucide-react, it supports forwarding refs and accepts all base button props allowing for flexible use.
This component fits into the system as a reusable UI primitive for menus, toolbars, lists, or any feature requiring a contextual "more actions" button with minimal visual clutter.
If you need further details on the base Button component or utility functions like cn, please consult their respective documentation files.