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:

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


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

Return Value

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


Interactions with Other System Components


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.