@globalpayments-private/gpds-pattern-web
v0.1.52
Published
GPDS pattern library for Web — UDS (Unified Design System) pattern components — admin portal, login, resource list, record form and record show — as framework-free web components.
Readme
@globalpayments-private/gpds-pattern-web
UDS (Unified Design System) pattern components for Web, as framework-free custom elements built with Stencil.
A pattern is not a control: it is a whole end-to-end workflow — signing in, browsing a resource, editing a record, running an admin portal — packaged as one element. You supply providers (your data API, your identity platform) and configuration as data; the pattern owns the workflow.
| Pattern | Tag | React | Journey |
| ------------- | ------------------------- | ---------------------- | ------------------------------------------------------------------------------------------ |
| Admin portal | uds-pattern-admin | UdsPatternAdmin | Auth gate, navigation, routing and a list / create / edit / show page per resource. |
| Login | uds-pattern-login | UdsPatternLogin | Sign-in with the password-reset branch. |
| Resource list | uds-pattern-list | UdsPatternList | Tabs, search, filters, sort, paging, selection, bulk delete and export, with URL state. |
| Dashboard | uds-pattern-dashboard | UdsPatternDashboard | KPIs and charts from aggregated data, drilling into the records behind every figure. |
| Record form | uds-pattern-record-form | UdsPatternRecordForm | Create / edit from sections as data: validation, reference choices, undoable save, delete. |
| Record show | uds-pattern-record-show | UdsPatternRecordShow | Profile card, tabbed sections and related-records panels. |
These six are the whole public surface. The atomic controls the patterns render internally (buttons, inputs, tables, menus…) are implementation details — they are not exported, wrapped for any framework, or documented, and will be replaced by the formal UDS component library. Anything a UDS component covers is out of scope here; a pattern is only worth shipping when it abstracts a journey.
Framework bindings ship as their own packages, at the same version:
| Package | For |
| -------------------------------------------------- | -------------------------------------- |
| @globalpayments-private/gpds-pattern-web | Vanilla JS / any framework (this one). |
| @globalpayments-private/gpds-pattern-web-react | React 19 components. |
| @globalpayments-private/gpds-pattern-web-vue | Vue 3 components. |
| @globalpayments-private/gpds-pattern-web-angular | Angular standalone components. |
Install
npm install @globalpayments-private/gpds-pattern-web @globalpayments-private/gpds-pattern-web-reactLoad the document stylesheet once — Inter, every design token as a CSS custom property, and the brand themes:
import '@globalpayments-private/gpds-pattern-web/uds.css';How a pattern is configured
Every pattern follows the same three rules.
1. Providers, not props. The pattern owns the workflow; you plug in the
systems it talks to. A DataProvider (react-admin's contract) and an
AuthProvider are plain objects. Which optional methods an adapter
implements is the configuration — implement deleteMany and list rows
become selectable, create and "New" appears, forgotPassword and the login
offers a reset. There are no show-* / enable-* switches, so a pattern can
never offer an action your backend cannot perform.
2. One aggregate config. If a value can be an attribute (a heading, a
page size, a mode), it is one. Everything that cannot — providers, columns,
sections, copy, the control strategy — lives in exactly one config object,
which also accepts a JSON string for the serialisable parts:
interface UdsListConfig {
data?: DataProvider; // defaults to the surrounding admin's
columns: FieldDef[];
filters?: FilterDef[];
filterTabs?: FilterTabsDef;
sort?: SortPayload;
permanentFilter?: Record<string, unknown>;
export?: false | { filename?: string };
control?: UdsListControlStrategy;
labels?: Partial<UdsListLabels>;
}3. Customise behaviour at checkpoints, not with knobs. config.control is
an interceptor over every decision the workflow makes. Each hook receives the
decision's context and next, the pattern's own behaviour; omit a hook to
keep the default. A hook that only observes calls next() and cannot change
the journey; one that diverts returns its own outcome; one that adjusts hands
next a modified context.
list.config = {
data,
columns,
control: {
// Observe: safe by construction.
query: (ctx, next) => (analytics.track('list.query', ctx.params), next()),
// Divert: open a drawer instead of routing.
rowClick: (ctx) => openDrawer(ctx.record),
},
};
form.config = {
sections,
control: {
// Adjust: derive a field on the way through the pattern's own save.
submit: (ctx, next) => next({ ...ctx, values: { ...ctx.values, name: fullName(ctx.values) } }),
},
};| Pattern | Checkpoints |
| ------------- | ------------------------------------------------------------ |
| admin | route, logout |
| login | submit, navigate, failure, complete |
| list | query, rowClick, create, remove, export, failure |
| dashboard | query, drill, failure |
| record-form | submit, complete, remove, cancel, failure |
| record-show | edit, failure |
Copy is overridable through config.labels (defaults are exported as
DEFAULT_*_LABELS). Styling is through the --uds-* custom properties only;
the patterns expose no ::parts, so accessibility and visual guardrails stay
the design system's.
Usage
React — an admin portal
import {
localAuthProvider,
localStorageDataProvider,
type UdsAdminConfig,
} from '@globalpayments-private/gpds-pattern-web';
import { UdsPatternAdmin } from '@globalpayments-private/gpds-pattern-web-react';
const config: UdsAdminConfig = {
data: myDataProvider,
auth: myAuthProvider,
resources: [customers, companies],
customRoutes: [{ path: '/settings', menu: { label: 'Settings', icon: 'settings' } }],
};
export function App() {
const [route, setRoute] = useState<RouteChange | null>(null);
return (
<UdsPatternAdmin
appTitle="Back office"
dashboard
config={config}
onUdsRouteChange={(e) => setRoute(e.detail)}
>
{route?.kind === 'dashboard' && <Dashboard />}
{route?.route === '/settings' && <Settings />}
</UdsPatternAdmin>
);
}React — a pattern on its own
Every pattern works standalone, with nothing but its config; inside
uds-pattern-admin it joins the admin's context instead (shared toasts,
theme, resource registry and cache).
<UdsPatternList
resource="customers"
heading="Customers"
config={{
data: myDataProvider,
columns,
filters: [{ type: 'search' }],
control: { rowClick: (ctx) => open(ctx.record) },
}}
/>Vanilla JS
import '@globalpayments-private/gpds-pattern-web/components/uds-pattern-login';
const login = document.querySelector('uds-pattern-login');
login.config = { auth: myAuthProvider };
login.addEventListener('udsLoginSuccess', (e) => start(e.detail));Vue / Angular
<UdsPatternList resource="customers" :config="config" @udsListRowClick="(e) => open(e.detail)" />import { DIRECTIVES } from '@globalpayments-private/gpds-pattern-web-angular';
// template: <uds-pattern-list resource="customers" [config]="config"></uds-pattern-list>Resources (admin)
uds-pattern-admin takes resources as data. Each page of a resource is the
configuration of the pattern that renders it, forwarded whole — anything a
pattern accepts standalone it accepts here:
const customers: ResourceDefinition = {
name: 'customers',
icon: 'users',
group: 'CRM',
recordRepresentation: 'name',
list: { rowClick: 'show', columns, filters, filterTabs }, // UdsListConfig + title / perPage / rowClick
create: { sections, defaultValues, redirect: 'show' }, // UdsRecordFormConfig + redirect
edit: { sections, control: { submit: deriveName } }, // UdsRecordFormConfig
show: { profile, sections }, // UdsRecordShowConfig
};Routes: #/:resource, #/:resource/create, #/:resource/:id,
#/:resource/:id/show. Dashboard and custom routes render the default slot;
udsRouteChange says which.
- Column / field types:
text,email,number,currency,date,boolean,chip,avatar,reference, orrender(record). - Input types:
text,email,tel,url,password,number,date,textarea,select,reference,boolean,spacer. - Validators:
required,email,minValue,maxValue,minLength,maxLength, or any(value, values) => string | undefined.
Dashboards and visualizations
uds-pattern-dashboard is the reporting journey: read aggregates, draw them,
and take the user from any figure to the records behind it. Widgets are data —
what to measure and which visualization draws it — so the same widget can
be a KPI today and a chart tomorrow.
const config: UdsDashboardConfig = {
widgets: [
{
id: 'pipeline',
title: 'Open pipeline',
viz: 'kpi',
format: 'currency',
query: { resource: 'deals', measure: { fn: 'sum', field: 'amount' }, filter: { stage: openStages } },
},
{
id: 'deals-by-month',
title: 'Deals by close month',
viz: 'bar',
query: {
resource: 'deals',
measure: { fn: 'sum', field: 'amount' },
groupBy: { field: 'close_date', bucket: 'month' },
series: [
{ key: 'won', label: 'Won', filter: { stage: 'won' } },
{ key: 'lost', label: 'Lost', filter: { stage: 'lost' } },
],
},
},
],
};- Aggregation is the provider's job.
DataProvider.aggregate(resource, { measure, filter, groupBy })is optional. Implement it to aggregate server-side; without it the pattern reads every matching record throughgetListand reduces them itself, so totals are never silently truncated to a page.groupBytakes a field (withchoicesfor order and labels) or a datebucket(day,week,month,quarter,year; gaps are filled).seriesare the same measure under extra filters;comparereads a previous period for deltas. Anything else goes in a widget'sload, which returns the sameUdsWidgetData. - Drill-down carries the slice. Activating a widget, a bar, a point or a
slice emits
udsDashboardDrilland, insideuds-pattern-admin, opens the resource's list filtered to exactly that slice (?filter=). Standalone, or to go elsewhere, intercept thedrillcheckpoint. - Visualizations are functions you can bring. Built-ins are
kpi,bar(stacked or grouped, either orientation),line(optionallyarea) anddonut. Register your own — or replace a built-in — underconfig.visualizations:
type UdsVisualization<O> = (host: HTMLElement, ctx: UdsVizContext<O>) => Cleanup | Promise<Cleanup>;
const sparkbars = defineVisualization<{ color?: string }>((host, { data, options, format, drill }) => {
// Draw into `host` with DOM calls, any chart library, or a framework root.
// `data` is already aggregated; `drill(point)` runs the drill-down workflow.
return () => host.replaceChildren();
});A visualization is called with an element the widget owns, whenever the
widget's data or options change; its cleanup runs before the next call and on
removal. Return a promise to lazy-load a heavy chart library: the card keeps
its skeleton until it settles. The host is inside the pattern's shadow root, so
page CSS does not reach it but --uds-* tokens do, and each series arrives
with its palette colour already resolved (data.series[i].color). Each widget
loads, fails and retries on its own, and re-reads when its resource changes
(getAdminStore().invalidate).
Runtime helpers
memoryDataProvider(seed),localStorageDataProvider(seed)andlocalAuthProvider(users)— for demos and tests only.notify(message),getAdminStore()— toasts, theme (setTheme('worldpay')) and cache invalidation (invalidate('deals')) from host code.navigate,updateQuery,readLocation— the hash router the patterns use.registerIcons({ Rocket })— add Lucide icons foriconnames.
Architecture
Each pattern's component class holds only props, state, events and
derivations. Behaviour lives in slimmers (components/<tag>/slimmers/),
markup in renderer slimmers (slimmers/renderers/), derivation in a
data-only view model with a separate handlers object
(view-model/), and pure logic (validation, route resolution) in plain
modules. Contracts live in src/providers/. See
src/slimmer/README.md; the slimmer runtime relies on
a patched @stencil/core (patches/ at the workspace root).
Development
From the workspace root: npm run build:core, npm test, npm run dev
(the pattern index, with every sandbox app under demos/sandboxes/).
