npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@highlight-ui/button

v12.2.4

Published

The button

Downloads

19,075

Readme

npm personio.design storybook.personio.design

@highlight-ui/button

Versatile and customizable Button and IconButton components designed to handle user click interactions seamlessly. Enables actions to be triggered with a built-in loading feature, providing asynchronous feedback for improved user experience.

Features

  • Button
    • Supports different variants: default, emphasized, and plain
    • Supports different tones: default, critical, and success
    • Supports an optional icon placed on the left of the label
    • Optional loading state with the spinner
  • IconButton
    • A required icon property is provided
    • Supports different variants: default, emphasized and plain
    • Optional loading state with the spinner

Installation

Using npm:

npm install @highlight-ui/button

Using yarn:

yarn add @highlight-ui/button

Using pnpm:

pnpm install @highlight-ui/button

In your (S)CSS file:

@import url('@highlight-ui/button');

Once the package is installed, you can import the components from the library:

Button

import { Button } from '@highlight-ui/button';

Icon Button

import { IconButton } from '@highlight-ui/button';

Usage

import React from 'react';
import { Button, IconButton } from '@highlight-ui/button';

export default function ButtonExample() {
  return (
    <>
      <Button icon="plus" variant="emphasized" tone="critical" onClick={() => console.log('Button clicked')}>
        Click me!
      </Button>

      <IconButton icon="plus" variant="emphasized" onClick={() => console.log('Button clicked')}/>
    </>
  );
}

Props 📜

All HTMLButtonElement, React.PropsWithChildren and PropsWithMetadata props are accepted with this component. In addition to these, this component has the following props

Button Props

| Prop | Type | Required | Default | Description | | :----------- | :---------------------------------------- | :------- | :---------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | variant | 'default' , 'emphasized' , 'plain' | No | 'default' | Determines the button's appearance (label color, background color) | | tone | 'default' , 'critical' , 'success' (Success is only available for the emphasized variant) | No | 'default' | Determines the button's tone, which is used to convey the importance or context of the action (e.g., color for success, error, etc.) | | onClick | (event: React.MouseEvent) => void | Yes | | Function called when the button is clicked | | children | React.ReactNode | Yes | | The content of the button, usually a text label | | ref | React.Ref<HTMLButtonElement> | No | | Ref for the button element | | block | boolean | No | | Makes the component behave as a block element (take up the whole available space) | | buttonState| 'default' , 'loading' , 'disabled' | No | | Determines the state of the button | | icon | string | No | | The icon to be placed beside the label |

IconButton Props

| Prop | Type | Required | Default | Description | | :----------- | :---------------------------------------- | :------- | :---------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | icon | string | Yes | | The icon to be placed beside the label | | variant | 'default' , 'emphasized', 'plain' | No | 'default' | Determines the button's appearance (label color, background color) | | onClick | (event: React.MouseEvent) => void | Yes | | Function called when the button is clicked | | ref | React.Ref<HTMLButtonElement> | No | | Ref for the button element | | block | boolean | No | | Makes the component behave as a block element (take up the whole available space) | | buttonState| 'default' , 'loading' , 'disabled' | No | | Determines the state of the button |

Accessibility ♿️

The button component follows best practices for accessibility:

  • Uses a native <button> element to ensure proper keyboard navigation and focus handling
  • Uses aria attributes for accessibility features, such as aria-hidden for loading and disabled states or passing the optional aria-label prop to the IconButton
  • Supports keyboard navigation with the outline ring and trigger keys Enter and Space

Testing

The test below shows how the button and icon button can be tested when used within another component.

Button Test

import React, { useState } from 'react';
import { render, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Button } from '@highlight-ui/button';

function ButtonWrapper({children}) {
  const handleClick = () => console.log('button clicked);

  return (
    <Button
      onClick={handleClick}
    >{children}</Button>
  );
}

describe('ButtonWrapperTest', () => {
  const renderButtonWrapper = () => {
    return render(<ButtonWrapper />);
  };

  it('renders the ButtonWrapper and handles the button click', () => {
    const { getByText } = renderButtonWrapper({ children: 'Click me' });

    const buttonElement = getByText('Click me');
    expect(buttonElement).toBeInTheDocument();

    userEvent.click(buttonElement);
    // Add any other expects or assertions based on your wrapper component's behavior
  });
});

IconButton Test

import React, { useState } from 'react';
import { render, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { IconButton, IconButtonProps } from '@highlight-ui/button';

type IconButtonWrapperProps = Omit<IconButtonProps, 'onClick'>;

function IconButtonWrapper(props: IconButtonWrapperProps) {
  const handleClick = () => console.log('button clicked');

  return <IconButton onClick={handleClick} {...props} />;
}

describe('IconButtonWrapperTest', () => {
  const renderIconButtonWrapper = (props) => {
    return render(<IconButtonWrapper {...props} />);
  };

  it('renders the IconButtonWrapper and calls the onClick handler', () => {
    const icon = 'plus';
    const { getByRole } = renderIconButtonWrapper({ icon });

    const buttonElement = getByRole('button');
    expect(buttonElement).toBeInTheDocument();

    userEvent.click(buttonElement);
    // Add any other expects or assertions based on your wrapper component's behavior
  });
});

Place in design system 💻

The button component is a foundational element of the design system and can be used across various services and contexts. It provides a consistent look and feel for user interactions and actions.

Some examples of when to use the button component:

  • Submitting forms
  • Triggering actions like adding, deleting, or editing items
  • Revealing additional content (Modals, dialogs, etc.)

Please visit the design system documentation for usage guidelines and visual examples.

Contributing 🖌️

To contribute to the development of the button component, please follow the contribution guidelines. Your input and expertise are welcome and appreciated!