You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP →
Socket
Book a DemoInstallSign in
Socket

react-barcodes

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-barcodes

React hooks to generate Barcode.

1.2.0
latest
Source
npm
Version published
Weekly downloads
3.1K
-7.07%
Maintainers
2
Weekly downloads
Ā 
Created
Source

react-barcodes

react-barcodes

React hooks for generating Barcodes.

Live demo

šŸŽ Features

  • Compatible with both JavaScript and TypeScript
  • Generate as SVG, Canvas and Image
  • Support multiple barcodes type

Barcodes Type

šŸ”§ Install

react-barcodes is available on npm. It can be installed with the following command:

npm install react-barcodes --save

react-barcodes is available on yarn as well. It can be installed with the following command:

yarn add react-barcodes

šŸ’” Usage

SVG

import React from 'react';
import { useBarcode } from 'react-barcodes';

function App() {
  const { inputRef } = useBarcode({
    value: 'react-barcodes',
    options: {
      background: '#ccffff',
    }
  });
  
  return <svg ref={inputRef} />;
};

export default App;
react-barcodes svg

Canvas

import React from 'react';
import { useBarcode } from 'react-barcodes';

function App() {
  const { inputRef } = useBarcode({
    value: 'react-barcodes',
    options: {
      displayValue: false,
      background: '#ffc0cb',
    }
  });
  
  return <canvas ref={inputRef} />;
};

export default App;
react-barcodes canvas

Image

import React from 'react';
import { useBarcode } from 'react-barcodes';

function App() {
  const { inputRef } = useBarcode({
    value: 'react-barcodes',
    options: {
      background: '#ffff00',
    }
  });
  
  return <img ref={inputRef} />;
};

export default App;
react-barcodes image

Parameters

PropTypeRequireDescription
valuestringāœ”ļøText to generate.
optionsoptionsāŒBarcode options.

Options

OptionTypeDefaultRequireDescription
formatstring?autoāŒSelect which barcode type to use. Please check the wikipage of the different barcode types for more information.
widthnumber?2āŒThe width option is the width of a single bar.
heightnumber?100āŒThe height of the barcode.
displayValueboolean?trueāŒ
textstring?undefinedāŒOveride the text that is diplayed
fontOptionsstring?""āŒWith fontOptions you can add bold or italic text to the barcode.
fontstring?"monospace"āŒDefine the font used for the text in the generated barcode. This can be any default font or a font defined by a @font-face rule.
textAlignstring?"center"āŒSet the horizontal alignment of the text. Can be left / center / right.
textPositionstring?"bottom"āŒSet the vertical position of the text. Can be bottom / top.
textMarginnumber?2āŒSet the vertical position of the text. Can be bottom / top.
fontSizenumber?20āŒSet the size of the text.
backgroundstring?"#ffffff"āŒSet the background of the barcode.
lineColorstring?"#000000"āŒSet the color of the bars and the text.
marginnumber?10āŒSet the space margin around the barcode. If nothing else is set, all side will inherit the margins property but can be replaced if you want to set them separably.
marginTopnumber?undefinedāŒ
marginBottomnumber?undefinedāŒ
marginLeftnumber?undefinedāŒ
marginRightnumber?undefinedāŒ
flatboolean?falseāŒOnly for EAN8 / EAN13

šŸ’– Wrap Up

If you think any of the react-barcodes can be improved, please do open a PR with any updates and submit any issues. Also, I will continue to improve this, so you might want to watch/star this repository to revisit.

🌟 Contribution

We'd love to have your helping hand on contributions to react-barcodes by forking and sending a pull request!

Your contributions are heartily ā™” welcome, recognized and appreciated. (āœæā— ā€æā— )

How to contribute:

  • Open pull request with improvements
  • Discuss ideas in issues
  • Spread the word
  • Reach out with any feedback

āš–ļø License

The MIT License License: MIT

Keywords

react

FAQs

Package last updated on 14 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts