Components

Every component below has a short description, the code to produce it, and its props. Zuper draws each component with its own design — these examples show the shape of the code, not the exact pixels.

Button

Actions. The only component that takes onPress.

<Button label="Create warranty" onPress={() => ui.toast('Pressed')} />
PropTypeDefaultNotes
labelstring—The button text
variant`'primary''secondary'`'secondary'
disabledbooleanfalse
onPress() => void—Runs in your worker

Text

Text, in three variants.

<Text>Warranty expires on 12 Mar 2027</Text>
PropTypeDefaultNotes
variant`'body''heading''muted'`
childrenstring—

Badge

A status.

<Badge label="Active" tone="success" />
PropTypeDefaultNotes
labelstring—
tone`'neutral''success''warning'

Stack

Layout. Use it instead of div.

<Stack>
	<Text variant="heading">Warranty</Text>
	<Badge label="Active" tone="success" />
	<Text variant="muted">Expires 12 Mar 2027</Text>
</Stack>
PropTypeDefaultNotes
direction`'row''column'`'column'
gap`'small''medium''large'`
childrencomponents—

DescriptionList

Label and value pairs. Values are strings.

<DescriptionList
	items={[
		{ label: 'Customer', value: 'Ava Martin' },
		{ label: 'Status', value: 'In progress' },
		{ label: 'Plan', value: 'Gold, 3 years' },
	]}
/>
PropTypeDefaultNotes
items{ label: string; value: string }[]—Format numbers and dates first

Table

Read-only data. Cells are strings or numbers, so format dates and amounts first.

<Table
	columns={[
		{ key: 'part', label: 'Part' },
		{ key: 'qty', label: 'Qty' },
		{ key: 'amount', label: 'Amount', align: 'end' },
	]}
	rows={[
		{ part: 'Air filter 20x25', qty: 2, amount: '$24.00' },
		{ part: 'Thermostat', qty: 1, amount: '$129.00' },
	]}
	emptyText="No parts used yet"
/>
PropTypeDefaultNotes
columns`{ key; label; align?: 'start''end' }[]`—
rows`Record<string, stringnumber>[]`—
emptyTextstring—Shown when rows is empty

Card

Groups content in a tab.

<Card title="Warranty">
	<DescriptionList items={[{ label: 'Plan', value: 'Gold, 3 years' }, { label: 'Expires', value: '12 Mar 2027' }]} />
</Card>
PropTypeDefaultNotes
titlestring—
childrencomponents—

Image

An image from an https address on any host. A bad address or a failed load shows a placeholder.

<Image src="https://files.acme.com/units/condenser.jpg" alt="Condenser unit" />
PropTypeDefaultNotes
srcstring—https on any host; allowedDomains is not needed
altstring—Text for screen readers, up to 300 characters
size`'small''medium''large'`

New in @zuperpro/app-sdk 2.0.0-beta. On an older SDK, run npm install --save-dev @zuperpro/app-sdk@beta.

  • Any https host. Unlike Frame, Image doesn't need the host in allowedDomains, so you can show Zuper's own files, such as job photos and attachments, whose addresses only arrive at run time.
  • Works in cards, tabs and dialogs, not only in dialogs like Frame.
  • https only. While your app runs from zp app dev, http://localhost images are allowed too.
  • Placeholder. A non-https or invalid address, or an image that fails to load, shows a crossed-out photo icon. Hover it to see why.

TextField

Input for text, a number, a date or a file. Controlled: keep value in state and set it in onChange.

const [note, setNote] = useState('');

<TextField label="Note" placeholder="Add a note for the technician" value={note} onChange={setNote} />
PropTypeDefaultNotes
type`'text''number''date'
labelstring—
valuestring (number: `stringnumber`)—
placeholderstring—text and number
multilinebooleanfalsetext only
min, maxstring (number: `stringnumber`)—
step`stringnumber`—
acceptstring—attachment only, e.g. 'image/*,application/pdf'
requiredbooleanfalse
errorstring—Shown under the field
onChangesee below—

New in @zuperpro/app-sdk 2.0.0-beta. On an older SDK, run npm install --save-dev @zuperpro/app-sdk@beta.

What onChange gets

typeonChange gets
textstring
numbernumber, or null when the field is emptied or holds no valid number
dateA 'YYYY-MM-DD' string, '' when cleared
attachment{ name, size, mimeType, base64 } (AttachmentFile), or null when removed
  • Attachments are one file of at most 5 MB. Zuper reads the file; base64 has no data: prefix. Uploading it is your app's job, usually through a server function.
  • Zuper keeps the picked file, not your state. To clear an attachment field after a submit, remount it with a new key.

Select

A choice of one option, or several with multiple. Controlled, like TextField.

const [plan, setPlan] = useState('gold');

<Select label="Plan" required
	options={[
		{ label: 'Silver, 1 year', value: 'silver' },
		{ label: 'Gold, 3 years', value: 'gold' },
		{ label: 'Platinum, 5 years', value: 'platinum' },
	]}
	value={plan}
	onChange={setPlan}
/>
PropTypeDefaultNotes
options{ label: string; value: string }[]—
multiplebooleanfalsePick several options
valuestring—Single mode
valuesstring[]—With multiple; a separate prop from value
onChange(value: string) => void, or (values: string[]) => void with multiple—
label, placeholder, required, errorThe same as TextField

New in @zuperpro/app-sdk 2.0.0-beta. On an older SDK, run npm install --save-dev @zuperpro/app-sdk@beta.

With multiple, the menu stays open while the user ticks options, and onChange gets every ticked value in the order of options, not the order they were ticked.

Dialog

DialogBody and DialogActions hold a dialog extension's content and footer buttons. Zuper draws the frame, the title and the close button.

export function openNoteDialog() {
	return ui.openDialog<{ note: string }>('note-dialog');
}

export default defineExtension({
	type: 'dialog',
	id: 'note-dialog',
	title: 'Add a note',
	objects: ['job'],
	render: ({ close }) => <NoteForm close={close} />,
});

function NoteForm({ close }: { close: (result?: { note: string }) => void }) {
	const [note, setNote] = useState('');
	return (
		<>
			<DialogBody>
				<TextField label="Note" multiline value={note} onChange={setNote} />
			</DialogBody>
			<DialogActions>
				<Button label="Cancel" onPress={() => close()} />
				<Button label="Save" variant="primary" onPress={() => close({ note })} />
			</DialogActions>
		</>
	);
}
PropTypeDefaultNotes
size (extension)`'sm''md''lg'
render({ record, input, close }) => UI—
close(result?)ui.openDialog resolves with result, or undefined when dismissed

ui.openDialog resolves with what the dialog passes to close(result), or with undefined when the user dismisses it. One dialog per app can be open at a time.

Frame

Shows a web page, such as your own product's screen. Dialogs only.

// zuper.app.json → "allowedDomains": ["pages.acme.com"]
export default defineExtension({
	type: 'dialog',
	id: 'picker',
	title: 'Picker',
	objects: ['job'],
	render: () => (
		<DialogBody>
			<Frame src="https://pages.acme.com/picker" label="Picker" />
		</DialogBody>
	),
});
PropTypeDefaultNotes
srcstring—https, on a host in allowedDomains
labelstring—Accessible name
height`'small''medium''large'
onMessage(m: FrameMessage) => void—Messages from the page (ZuperEmbed)
refFrameHandle—ref.current.send(type, content)
  • Dialogs only. zp app validate and Zuper both refuse a Frame in a card, tab or action. Use a fullscreen dialog with height="fill" to give the page the whole window.
  • https only, on your allowed domains. Zuper checks every address again when it draws the frame, including addresses you build in code. While your app runs from zp app dev, http://localhost and http://127.0.0.1 pages are allowed too, if you list them.
  • The site must allow framing. Many sites send X-Frame-Options or a frame-ancestors policy, and the browser then refuses to show them. Test the page you need.
  • Sandboxed. The page can't navigate the Zuper tab, gets no referrer, and can't read anything of Zuper's.

To exchange messages with the page, see ZuperEmbed.


Did this page help you?