Skip to main content
Publication is pending: @nipost/postcode-widget is not on npm yet. That is how it will be installed; until then, build the SDK from sdks/widget-js in the gateway repository.
Install the SDK, or drop the CDN script into your page:
The script build exposes the same API on a PostcodeWidget global.

Usage

open() overlays a modal, runs the whole flow in a shadow root so neither your CSS nor the widget’s can reach the other, and resolves with the PostcodeSelection, or null if the user dismissed it with the close button, Escape, or a press outside the card. The promise rejects when the call itself cannot work: a missing key, an unusable platformBaseUrlOverride or styleUrl, a second widget opened while one is already on screen, a page with no origin (opened as a file:// URL), or a call made where there is no DOM (server-side rendering).

Options

Origins

The publishable key carries an origin allowlist, and because the widget calls the platform from the browser, the Origin header your page sends is what gets checked. Every origin that opens the widget must be on the key, or the request comes back 403 origin_not_allowed, shown on the identity screen and passed to onError. Add every production, staging and development origin when you create the key.

Theming

Every token is optional; anything you leave out keeps the NIPOST default. The two font stacks exist because the package bundles no fonts. Colours take hex (#fff, #EBC700, #EBC700CC) or rgb() / rgba() with numeric channels, radii are pixel numbers clamped to 64, and font stacks may only contain the characters a font stack needs. Values that are none of those are dropped rather than written into a stylesheet.

Find by location

“Get Postcode on Map” opens a MapLibre map that follows the browser’s position, draws its accuracy circle, and reveals the postcode plate segment by segment as the fix tightens: state and LGA above 50 m, district from 50 m, area from 20 m, and the full unit at 8 m or better. Nearby postcodes appear as tappable markers for the cases where the exact building is ambiguous. Geolocation needs a secure context, so serve the embedding page over HTTPS, and note that a Permissions Policy on your page that blocks geolocation blocks it here too. If the map library cannot load, the screen says so and the postcode still resolves without it.

Bundle size

Prefer the npm build when you have a bundler.