2.0.1 • Published 3 years ago

react-dynamic-badge v2.0.1

Weekly downloads
19
License
MIT
Repository
github
Last release
3 years ago

travis

React-Dynamic-Badge

Screenshot

A responsive component that shows a badge if an array of strings overflows the parent element.

<DynamicBadge
    items={[
        "Item 1",
        "Item 2",
        "Item 3",
        "Item 4",
    ]}
/>

Technical Documentation

Installing

$ npm install react-dynamic-badge

Exports

The default export is <DynamicBadge>. Here's how to use it:

import { DynamicBadge } from 'react-dynamic-badge';

<DynamicBadge>

A <DynamicBadge> element will calculate the width of the parent element and show only the items that can fit. If an item overflows it will be hidden and a badge will be shown. If there is only one item and it overflows ellipsis is used. The font is inherited from the containing element.

DynamicBadge Usage

import React from 'react';
import ReactDOM from 'react-dom';
import { DynamicBadge } from 'react-dynamic-badge';

class App extends React.Component {

  render() {
    return (
      <div style={{ width: "50%", border: "1px dashed" }}>
        <DynamicBadge
            items={[
                "Item 1",
                "Item 2",
                "Item 3",
                "Item 4",
            ]}
        />
      </div>
    );
  }
}

ReactDOM.render(<App/>, document.body);

<DynamicBadge> Props:

NameTypeRequiredDefaultDescription
badgeClassstringno"bdg-badge"It's possible to use a custom class for the badge.
itemsarray of stringsyes[]The items to be displayed. If not set, it falls back to an empty array (nothing is shown).
minWidthintnoSets the minimum width for the text to be shown; defaults at 1/2 characters depending on the font and character.
onlyBadgeboolnofalseIf set to true it will display only the badge and no text.
resizeDebounceintno1The debounce value for the resize event in ms. The smaller the value the quicker the badge will be updated on resize.

License

MIT

2.0.1

3 years ago

2.0.0

3 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.1

4 years ago

1.1.3

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago