0.0.1 • Published 11 months ago

@droid-tech/react-ts-badge v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

Badge Component

The Badge component is a versatile React component that adds a small badge to its child content. It's built with TypeScript, providing type safety and easy integration into React projects.

Features

  • Two variants: dot and standard
  • Customizable badge content
  • Flexible positioning
  • Color customization
  • Invisible mode
  • Maximum value display
  • Blinking animation option
  • TypeScript support for type safety

Installation

To use the Badge component in your React application, install it via npm:

npm install @droid-tech/react-ts-badge

Usage

To use the Badge component, import it and wrap it around the content you want to badge:

import Badge from "@droid-tech/react-ts-badge";

const MyComponent = () => {
  return (
    <Badge badgeContent={4}>
      <YourComponent />
    </Badge>
  );
};

Props

The Badge component accepts the following props:

PropTypeDefaultDescription
variant'dot' \| 'standard''standard'The variant of the badge
badgeContentReact.ReactNode-The content of the badge
colorstring'#fff'The text color of the badge
bgcolorstring'#bdbdbd'The background color of the badge
position'top-right' \| 'bottom-right' \| 'bottom-left' \| 'top-left''top-right'The position of the badge
anchorOrigin'top-right' \| 'bottom-right' \| 'bottom-left' \| 'top-left''top-right'The anchor point for the badge
invisiblebooleanfalseWhether the badge should be invisible
maxnumber99The maximum value to display
blinkbooleanfalseWhether the badge should blink
childrenReact.ReactNode-The content to be badged

Customization

Variants

The Badge component supports two variants:

  1. 'standard': A rounded rectangle badge with content
  2. 'dot': A small circular badge without content
<Badge variant="dot" badgeContent={''}>
  <YourComponent />
</Badge>

Colors

You can customize the text color and background color of the badge:

<Badge badgeContent={4} color="#ffffff" bgcolor="#ff0000">
  <YourComponent />
</Badge>

Position

You can adjust the position of the badge:

<Badge badgeContent={4} position="bottom-left">
  <YourComponent />
</Badge>

Maximum Value

You can set a maximum value for numeric content:

<Badge badgeContent={1000} max={999}>
  <YourComponent />
</Badge>

This will display as "999+" for any value over 999.

Blinking Animation

You can make the badge blink:

<Badge badgeContent={4} blink={true}>
  <YourComponent />
</Badge>

Accessibility

The Badge component is designed to be accessible, providing visual feedback for notifications or status indicators. However, ensure that you're also providing alternative ways for users to access this information for better accessibility.

Conclusion

The Badge component provides a flexible and customizable way to add badges to elements in your React application. With its various customization options and TypeScript support, it can easily be integrated into your project to provide visual indicators for notifications, status, or other information.

0.0.1

11 months ago