UNPKG

taro-code

Version:

Taro.js barcode & qrcode, Image & Canvas

20 lines 1.03 kB
import React, { forwardRef, useImperativeHandle, useMemo } from 'react'; import { Image } from '@tarojs/components'; import barcode from '../../common/barcode'; const Barcode = forwardRef(({ className, text = '', scale = 4, width = 300, height = 60, style = {}, foregroundColor = '#000000', backgroundColor = '#FFFFFF', }, ref) => { const image = useMemo(() => barcode({ text, scale, whiteColor: backgroundColor, blackColor: foregroundColor, }), [text, scale, backgroundColor, foregroundColor]); useImperativeHandle(ref, () => { return { image }; }, [image]); const widthString = width != null ? `${width}px` : ''; const heightString = height != null ? `${height}px` : ''; const finalStyle = Object.assign({ width: widthString, height: heightString }, style); return React.createElement(Image, { className: className, style: finalStyle, src: image !== null && image !== void 0 ? image : '' }); }); export default Barcode; //# sourceMappingURL=index.js.map