Search the documentation

Type to search page titles, component names and descriptions.

    Data Display

    QrCode

    A code a phone can scan, drawn on the server.

    import { QrCode } from 'faifo-design'

    QrCode draws a QR symbol as SVG on the server: it prints, scales and needs no script. It is always dark on a light plate, in either theme, and is named for what scanning does. qrSvg returns the same symbol as a standalone SVG file.

    #When to use

    • Use it for a payment request, a link or a pairing code.
    • Print what a person must read beside the code; a QR code is not a label.

    #Examples

    Each example is a specimen of the package catalogue, rendered on the server exactly as shown in its code.

    #QR code

    A code a phone scans, drawn on the server: black on a white plate in either theme, named for what scanning does, with what a person must read printed beside it.

    INV-1042 · 13,020,000 ₫
    Bank
    Example Bank
    Account
    0123 4567 8910
    Amount
    13,020,000 ₫
    Reference
    INV-1042
    Show codeHide code
    import { DescriptionList, Inline, QrCode } from 'faifo-design'
    
    export const Example = () => (
      <Inline
        items={[
          <QrCode
            value="https://example.com/invoices/INV-1042/pay?amount=13020000"
            label="Pay invoice INV-1042 by bank transfer"
            caption="INV-1042 · 13,020,000 ₫"
          />,
          <DescriptionList
            columns="auto"
            items={[
              { id: 'bank', label: 'Bank', value: 'Example Bank' },
              { id: 'account', label: 'Account', value: '0123 4567 8910' },
              { id: 'amount', label: 'Amount', value: '13,020,000 ₫' },
              { id: 'reference', label: 'Reference', value: 'INV-1042' },
            ]}
          />,
          <QrCode
            value="WIFI:S:Example;T:WPA;P:example-pass;;"
            label="Join the shop's Wi-Fi"
            size="small"
          />,
        ]}
      />
    )

    #API

    Generated from the package source. A property without a description has none in the source yet.

    #QrCodeComponent

    A QR code a phone can scan: a payment request, a link, a pairing code. The symbol is an SVG drawn on the server from encodeQr, so it prints, scales and needs no script. It is always dark on a light plate with its quiet zone, in either theme, because scanners need that contrast. The symbol is an image named by label; what it carries that a person needs to read (the account, the amount) belongs in caption, never only in the code.

    PropertyDescriptionTypeDefault
    valuerequiredThe text the code carries, such as a payment request. Encoded as UTF-8.string–
    labelrequiredThe accessible name of the symbol: what scanning it does, such as "Pay 13,020,000 ₫ by bank transfer".string–
    captionPrinted under the symbol for people who cannot scan it, such as the account and the amount.string | TemplateResult | null–
    errorCorrection–QrErrorCorrection'M'
    size–'small' | 'default' | 'large''default'

    #qrSvgFunction

    The same symbol as a standalone SVG file, for an <img>, a download or a printed document that cannot carry the design system's stylesheet. The white plate and black modules are drawn into the file itself, since nothing styles it; label becomes its <title>.

    function qrSvg(value: string, options: { label: string; errorCorrection?: QrErrorCorrection | undefined; }): string
    ParameterType
    valuerequiredstring
    optionsrequired{ label: string; errorCorrection?: QrErrorCorrection }
    Returnsstring

    #Types

    #QrCodeProps

    The properties of QrCode, listed above.

    #QrErrorCorrection

    A QR Code Model 2 encoder (ISO/IEC 18004) for QrCode: byte mode over UTF-8, versions 1 to 40, the four error correction levels, Reed-Solomon codewords per block, the eight masks scored by the standard's penalty rules, and the format and version information. It has no dependency and draws nothing: it returns which modules are dark. Its construction follows the one laid out in Project Nayuki's QR Code generator library (MIT).

    type QrErrorCorrection = 'L' | 'M' | 'Q' | 'H'

    #Hooks

    The data-ui values these components render. Select them in tests and behaviour; their look belongs to the design system. See Contract.

    • qr-code
    • qr-code-symbol
    • qr-code-caption