npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

portakal-template-builder-rn

v2.0.0

Published

React Native template builder for portakal-template. Visual row/cell/element editor with slash-command variable autocomplete, live SVG preview, validation, and theming. Expo-first, works on iOS, Android, tablet, and web.

Downloads

240

Readme

portakal-template-builder-rn

A React Native template builder component for portakal-template.

Your app's end users assemble label templates visually — rows, cells, and elements — with a live preview, slash-command variable autocomplete, inline validation, and theming. They never type raw JSON.

  • Expo-first, works on iOS, Android, tablet, and web (react-native-web)
  • Native components only — TouchableOpacity, TextInput, ScrollView, Modal, FlatList
  • Live react-native-svg preview of the exact compileTemplate().svg string — preview and printed output share the same resolved layout and can't drift
  • Responsive: portrait stacks (editor above, preview below); landscape/tablet/web goes two-pane with a sticky preview
  • Theming via a simple colors/spacing/typography object; defaultTheme + darkTheme included

Install

npm install portakal-template-builder-rn react-native-svg

Peer dependencies (install yourself): react, react-native, react-native-svg.

Quick start

import { TemplateBuilder, darkTheme } from "portakal-template-builder-rn";

const variables = [
  { key: "store.name", label: "Store Name", description: "The store name printed on the label", sample: "Acme Store" },
  { key: "order.number", label: "Order Number", description: "The order's number, also encoded in the barcode", sample: "1024" },
  { key: "order.time", label: "Order Time", description: "When the order was placed", sample: "14:30" },
  { key: "order.id", label: "Order ID", description: "Unique order id used in the QR code", sample: "abc123" },
  { key: "order.total", label: "Order Total", description: "Total amount for the order", sample: "29.48" },
];

const spec = { width: 65, height: 40, unit: "mm", dpi: 203, font0Mode: "points" };

export function LabelTemplateScreen() {
  return (
    <TemplateBuilder
      template={initialTemplate}   // a portakal-template TemplateSchema
      variables={variables}
      spec={spec}
      theme={darkTheme}
      onChange={(schema) => save(schema)}   // persist the draft
      showCode
    />
  );
}

Props

| Prop | Type | Description | |---|---|---| | template | TemplateSchema | Initial template. The builder keeps a draft and calls onChange on each edit. | | variables | VariableSpec[] | Allowed variables. Drives / autocomplete, the ⓘ help modal, and sample preview data. | | spec | PrintSpec | Printer spec — the preview compiles against this. | | theme? | BuilderTheme | Colors/spacing/typography (default defaultTheme). | | onChange? | (schema) => void | Called with the current draft after every mutation. | | sampleData? | Record<string, unknown> | Override the preview data (default: built from variable samples). | | onPreview? | ({ tsc, zpl, svg }) => void | Called after each debounced preview render. | | showCode? | boolean | Show the collapsible compiled TSC/ZPL panel. | | editable? | boolean | Allow editing (default true; false renders a read-only view). |

VariableSpec

| Field | Type | Description | |---|---|---| | key | string | Dotted key, e.g. "order.number" — used as {{order.number}} in templates. | | label | string | Human label shown in autocomplete and the help modal. | | description | string | Developer-provided docs shown in the help modal. | | sample | string \| number | Used to build preview sample data. |

Slash-command variable autocomplete

In any text field (text, barcode, QR content):

  • Type / to start composing a variable. A bare / with nothing typed shows no suggestions — pressing space leaves the / literal.
  • Type after / (e.g. /ord) to filter variables by key, label, or description (top 5 shown).
  • Tap a suggestion to insert {{key}} in place of the token.
  • The ⓘ button beside each field opens the help modal listing every variable with its key, label, description, and sample.

Images

The image element has a built-in picker: choose a photo from the device library and the builder resizes it to the cell's width, converts it to a 1-bit bitmap (with a live monochrome preview), and writes the descriptor into the template. Width, dither algorithm, threshold, and invert are all editable, and there's an "Edit descriptor manually" escape hatch.

Picking is powered by two optional Expo modules — install them in your app (they are not required unless you use images):

npx expo install expo-image-picker expo-image-manipulator

expo-image-picker also needs its config plugin for the photos permission:

{ "expo": { "plugins": ["expo-image-picker"] } }

Validation

Every change is validated against the allowed variables and template structure using validateTemplate from portakal-template. Errors show as a banner above the preview. You can reuse the same validator server-side:

import { validateTemplate } from "portakal-template-builder-rn"; // re-exported

const { valid, errors } = validateTemplate(savedSchema, { allowedVariables: variables.map(v => ({ key: v.key })) });

Theming

import { TemplateBuilder, resolveTheme } from "portakal-template-builder-rn";

const myTheme = resolveTheme({
  colors: { primary: "#2563eb", background: "#0f172a", surface: "#1e293b" },
  radius: 12,
});

Layout

  • Portrait (width < 700): preview on top, editor below.
  • Landscape / tablet / web (width ≥ 700): editor on the left, sticky preview on the right.

Rows & text scaling

  • Each row has a Height (%) and a Scale (%) field.
  • Scale (50–300%, default 100%) stretches that row's text horizontally only — the row height (y-axis) and auto-computed font size stay fixed, like BarTender's width scaling. It maps to rows[].textScale in the schema.
  • Dynamic (repeat) rows inherit the row's Scale on every expanded row.

Example app

A minimal standalone Expo app lives in examples/expo/. From that directory:

npm install
npx expo start            # iOS / Android (Expo Go)
npx expo start --web      # web (react-native-web)

It renders the builder with the order-label template, a light/dark toggle, and a debug panel showing the current schema JSON.

How it works

  • State: a pure reducer (src/state/builderReducer.ts) keeps percent sums sane — adding a row divides all heights proportionally; adding a cell rebalances widths to sum 100.
  • Preview: compileTemplate(template, sampleData, { spec }) runs debounced (~200 ms) and renders result.svg via SvgXml. The compiled TSC/ZPL panel shows the exact strings the printer receives.
  • Autocomplete: a pure tokenizer (src/state/slash.ts) detects the slash token at the caret and produces insertion replacements.

License

MIT.