Coder Social home page Coder Social logo

bunlong / next-barcode Goto Github PK

View Code? Open in Web Editor NEW
63.0 5.0 9.0 162 KB

React hooks for generating Barcode for your next React apps.

License: MIT License

JavaScript 63.57% TypeScript 36.43%
barcode react reactjs react-hooks javascript typescript react-barcodes hooks barcodes react-barcode

next-barcode's Introduction

next-barcode

React hooks for generating Barcode for your next React apps.

downloads downloads

NPM npm bundle size JavaScript Style Guide

Live demo

๐ŸŽ Features

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

Barcodes Type

๐Ÿ”ง Install

next-barcode is available on npm. It can be installed with the following command:

npm install next-barcode --save

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

yarn add next-barcode

๐Ÿ’ก Usage

SVG

import React from 'react';
import { useBarcode } from 'next-barcode';

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

export default App;

next-barcode svg

Canvas

import React from 'react';
import { useBarcode } from 'next-barcode';

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

export default App;

next-barcode canvas

Image

import React from 'react';
import { useBarcode } from 'next-barcode';

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

export default App;

next-barcode image

Parameters

Prop Type Require Description
value string โœ”๏ธ Text to generate.
options options โŒ Barcode options.

Options

Option Type Default Require Description
format string? auto โŒ Select which barcode type to use. Please check the wikipage of the different barcode types for more information.
width number? 2 โŒ The width option is the width of a single bar.
height number? 100 โŒ The height of the barcode.
displayValue boolean? true โŒ
text string? undefined โŒ Overide the text that is diplayed
fontOptions string? "" โŒ With fontOptions you can add bold or italic text to the barcode.
font string? "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.
textAlign string? "center" โŒ Set the horizontal alignment of the text. Can be left / center / right.
textPosition string? "bottom" โŒ Set the vertical position of the text. Can be bottom / top.
textMargin number? 2 โŒ Set the vertical position of the text. Can be bottom / top.
fontSize number? 20 โŒ Set the size of the text.
background string? "#ffffff" โŒ Set the background of the barcode.
lineColor string? "#000000" โŒ Set the color of the bars and the text.
margin number? 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.
marginTop number? undefined โŒ
marginBottom number? undefined โŒ
marginLeft number? undefined โŒ
marginRight number? undefined โŒ
flat boolean? false โŒ Only for EAN8 / EAN13

๐Ÿ“œ Changelog

Latest version 1.5.0 (2023-07-14):

  • Upgrade dependencies

Details changes for each release are documented in the CHANGELOG.md.

โ— Issues

If you think any of the next-barcode 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 next-barcode 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

๐Ÿ† Contributors

Bunlong
Bunlong
Dennis N.
Dennis N.
Handers
Handers

โš–๏ธ License

The MIT License License: MIT

next-barcode's People

Contributors

bunlong avatar dennis-8 avatar handers85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

next-barcode's Issues

Filter which text can be generated as barcode

Hello, I'm using this package in my project to generate svg barcode. Everything was good until I test it with Vietnamese (image below). I think because Vietnamese contains invalid character for barcode generating? If so please tell me how to check a text before generating barcode to make sure it can be generate to a barcode (to avoid application crash on invalid text).
Thank you so much!
Capture

Change barcode width and height by centimeter?

Hi, I used this react-barcodes to generate barcode from text, but in the requirement for my application I need to adjust the width and height of the barcode image in centimeter. Currently I read in the documentation it says that width is the width of each bar? How to adjust the barcode image using centimeter?
Thank you!

Add validation as property

In the jsbarcode package, on which this package is based, there is a property called valid. All other properties are already available, except valid. Below is an example of how valid is set when creating EAN13.

	_createClass(EAN13, [{
		key: 'valid',
		value: function valid() {
			return this.data.search(/^[0-9]{13}$/) !== -1 && +this.data[12] === checksum(this.data);
		}
	},

Feel free to take a look at this. If it requires more than using the one available in jsbarcode, I am happy to help.

I also noticed you've removed it in your d.ts file

  marginBottom?: number;
  marginLeft?: number;
  marginRight?: number;
  flat?: boolean;
  // valid?: Function; <----- Commented, probably for a good reason

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.