@openg2p/registry-widgets 0.2.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,9 +16,14 @@ The Registry UI Widget Library is a layered, extensible system that enables you
16
16
  - ✅ **Data Sources** (static, API, schema reference)
17
17
  - ✅ **Formatting** (dates, currency, phone numbers, numbers)
18
18
  - ✅ **Widget Registry** system for extensible plugin architecture
19
- - ✅ **19+ Pre-built Widgets** ready to use
19
+ - ✅ **20 Pre-built Widgets** ready to use (including HeaderSection)
20
20
  - ✅ **Internationalization** support via i18next
21
21
  - ✅ **Tailwind CSS** ready (unstyled base, you provide styles)
22
+ - ✅ **Multi-mode Section Rendering** (RegistryView, CRView, IntakeForm)
23
+ - ✅ **Geo Hierarchy Cascading Dropdowns** for location-based fields
24
+ - ✅ **Section Builder** with visual and JSON editor for UI schemas
25
+ - ✅ **Form Handle API** for host-driven validation and submission
26
+ - ✅ **Dirty Tracking** with unsaved changes detection per section
22
27
 
23
28
  ## Installation
24
29
 
@@ -77,7 +82,7 @@ The library follows a layered architecture that separates concerns and enables e
77
82
 
78
83
  ┌─────────────────────────────────────────┐
79
84
  │ Widget Components Layer │
80
- │ (19+ Pre-built Widgets)
85
+ │ (20 Pre-built Widgets)
81
86
  └─────────────────────────────────────────┘
82
87
 
83
88
  ┌─────────────────────────────────────────┐
@@ -102,7 +107,7 @@ The library follows a layered architecture that separates concerns and enables e
102
107
 
103
108
  **Widget Registry Layer** - A plugin system that maintains a catalog of available widgets. When a widget is requested by name, the registry looks it up and returns the corresponding React component. This enables dynamic widget loading and easy extensibility - new widgets can be registered without modifying core library code.
104
109
 
105
- **Widget Components Layer** - The actual React components that render UI elements (text inputs, selects, tables, etc.). These are the 19+ pre-built widgets that come with the library. Each widget is a React component that receives configuration and renders the appropriate UI. Custom widgets can be added by registering them in the registry.
110
+ **Widget Components Layer** - The actual React components that render UI elements (text inputs, selects, tables, etc.). These are the 20 pre-built widgets that come with the library. Each widget is a React component that receives configuration and renders the appropriate UI. Custom widgets can be added by registering them in the registry.
106
111
 
107
112
  **Core Hooks Layer** - React hooks that provide all the business logic for widgets. The `useBaseWidget` hook handles state management, validation, conditional logic, data source loading, and formatting. The `useWidgetTranslation` hook provides internationalization support. Widget components use these hooks to get values, errors, visibility states, and change handlers without directly interacting with Redux or utilities.
108
113
 
@@ -224,25 +229,92 @@ Support for multiple validation strategies:
224
229
 
225
230
  ## Available Widgets
226
231
 
227
- The library includes 19+ pre-built widgets:
232
+ The library includes 20 pre-built widgets:
228
233
 
229
234
  - **Input Widgets**: TextInput, TextArea, NumberInput, CurrencyInput, DateInput, DateTimeInput, PhoneInput, FileInput
230
235
  - **Selection Widgets**: Select, Radio, Checkbox, Boolean
231
236
  - **Layout Widgets**: Array, IterableAccordion
232
237
  - **Display Widgets**: Display, Profile
233
238
  - **Table Widgets**: Table, SimpleTable
239
+ - **Section Widgets**: HeaderSection
234
240
 
235
- > 📚 **Widget documentation coming soon!** Detailed guides for each widget will be available in our tutorial pages.
241
+ ### HeaderSection Widget
242
+
243
+ A full-width header card designed for registry record views. Displays a profile image, record name, functional ID, status badge, and audit metadata (created by / approved by) in a responsive two-column layout. Supports editable status and status-reason fields with data source-driven dropdowns, customisable label overrides via i18n, and configurable status-colour mapping.
244
+
245
+ ```json
246
+ {
247
+ "widget": "header-section",
248
+ "widget-type": "group",
249
+ "widget-id": "registry-header",
250
+ "widget-data-path": {
251
+ "image": "record_image_storage_id",
252
+ "name": "record_name",
253
+ "functionalId": "functional_record_id",
254
+ "status": "record_status"
255
+ }
256
+ }
257
+ ```
258
+
259
+ ## Section Modes
260
+
261
+ `SectionsContainer` supports three display modes via the `mode` prop:
262
+
263
+ ### RegistryView (default)
264
+
265
+ Standard registry display. Sections render in a CSS Grid layout with an inline **Edit Details** button. Only one section can be in edit mode at a time; editing a section opens it as a portal-based overlay with save/cancel controls.
266
+
267
+ ### CRView (Change Request View)
268
+
269
+ Read-only comparison view for change requests. Sections display **Created by** / **Approved by** metadata and support `changeRequestType` labels (`"new"` / `"old"`) for side-by-side comparison.
270
+
271
+ ### IntakeForm
272
+
273
+ Accordion-based registration form. Sections expand and collapse, with **Prev** / **Next** navigation buttons. Supports `isDraft` mode (editable vs read-only), per-section validation on save, and status badges (**Saved** / **Modified and not saved**).
274
+
275
+ ## Form Handle API
276
+
277
+ `SectionsContainer` exposes a `SectionsFormHandle` via the `onFormReady` callback, enabling host applications to drive form submission externally:
278
+
279
+ ```tsx
280
+ <SectionsContainer
281
+ sections={sections}
282
+ mode="IntakeForm"
283
+ onFormReady={(handle) => {
284
+ // handle.validate() – validate all sections, returns boolean
285
+ // handle.getFormData() – raw store data (no validation)
286
+ // handle.validateAndGetData() – validate then return SectionChanges[]
287
+ // handle.getStructuredData() – get records and files without validation
288
+ }}
289
+ />
290
+ ```
291
+
292
+ ## Geo Hierarchy Cascading Dropdowns
293
+
294
+ The `useGeoWidgetCascade` hook and `geoHierarchyBuilder` utility provide cascading dropdown functionality for geographic location fields (e.g. Country > State > City). Changes in a parent level automatically reload and reset child dropdowns via the widget event bus.
295
+
296
+ ## Section Builder
297
+
298
+ A visual UI schema editor shipped as `SectionBuilder`, with sub-components:
299
+
300
+ - **JSONEditorPanel** — Live JSON editor (powered by `json-edit-react`) for direct schema manipulation
301
+ - **VisualBuilderPanel** — Drag-and-drop visual layout editor
302
+ - **SectionTree** — Tree view of the section/panel/widget hierarchy
303
+ - **PropertyEditor** — Contextual property panel for the selected node
236
304
 
237
305
  ## Examples
238
306
 
239
307
  See the `examples/` directory for comprehensive examples demonstrating:
240
308
 
241
- - Basic widget usage
242
- - Layout widgets
243
- - Schema internationalization
244
- - Comparison views
245
- - And more...
309
+ - Basic widget usage (`usage-example.tsx`)
310
+ - Layout widgets (`LayoutWidgets.tsx`)
311
+ - Schema internationalization (`schema-i18n-example.tsx`)
312
+ - Comparison views (`comparison-view-example.tsx`)
313
+ - Section rendering modes (`section-renderer-example.tsx`)
314
+ - Intake form flow (`intake-form-example.tsx`)
315
+ - Header section widget (`header-section-example.tsx`)
316
+ - Section builder (`section-builder-example.tsx`)
317
+ - JSON editor standalone (`jsoneditor-standalone-example.tsx`)
246
318
 
247
319
  ## API Reference
248
320
 
@@ -280,10 +352,36 @@ Registry for managing widget components.
280
352
 
281
353
  ### Components
282
354
 
283
- - `SectionsContainer` - Container for rendering sections
284
- - `SectionRenderer` - Renders individual sections
355
+ - `SectionsContainer` - Container for rendering sections with mode support (RegistryView, CRView, IntakeForm)
356
+ - `SectionRenderer` - Renders individual sections with edit mode, dirty tracking, and accordion support
285
357
  - `PanelRenderer` - Renders panels within sections
286
358
  - `FilePreviewModal` - Modal for file preview
359
+ - `SectionBuilder` - Visual UI schema editor
360
+ - `JSONEditorPanel` - JSON editor for UI schemas
361
+ - `VisualBuilderPanel` - Visual layout builder
362
+ - `SectionTree` - Tree view of section hierarchy
363
+ - `PropertyEditor` - Property editor for selected nodes
364
+
365
+ ### Hooks
366
+
367
+ - `useBaseWidget` - Core hook for widget state, validation, conditional logic, and formatting
368
+ - `useWidgetTranslation` - i18n hook for widget labels and messages
369
+ - `useWidgetEventBus` - Pub/sub event bus for inter-widget communication
370
+ - `useWidgetCascade` - Cascading dropdown behaviour between linked widgets
371
+ - `useGeoWidgetCascade` - Geo hierarchy cascading for location-based dropdowns
372
+
373
+ ### Utilities
374
+
375
+ - `pathUtils` - Dot-notation path read/write for nested data structures
376
+ - `validation` - Built-in, regex, and Zod validation
377
+ - `formatting` - Date, currency, phone, number, and text formatting
378
+ - `conditions` - Conditional show/hide and enable/disable evaluation
379
+ - `dataSource` - Static, API, and schema reference data loading
380
+ - `geoHierarchy` - Geo hierarchy builder for location cascades
381
+ - `sectionValidate` - Section-level validation across all widgets
382
+ - `buildSectionChanges` - Build change payloads from section data
383
+ - `schemaNamespace` - Namespace section configs for multi-instance rendering
384
+ - `schemaTranslation` - Translate UI schemas, widget configs, and panel configs
287
385
 
288
386
  ## Contributing
289
387
 
@@ -0,0 +1,19 @@
1
+ import { resolveTheme } from '../theme';
2
+ export type ResolvedTheme = ReturnType<typeof resolveTheme>;
3
+ export declare const ThemeContext: import("react").Context<Required<{
4
+ colors: Required<import("../theme").WidgetThemeColors>;
5
+ section: Required<import("../theme").WidgetThemeSection>;
6
+ panel: Required<import("../theme").WidgetThemePanel>;
7
+ button: Required<import("../theme").WidgetThemeButton>;
8
+ widget: Required<import("../theme").WidgetThemeWidget>;
9
+ }>>;
10
+ /**
11
+ * Access the resolved widget theme from any component inside `<WidgetProvider>`.
12
+ *
13
+ * ```tsx
14
+ * const theme = useWidgetTheme();
15
+ * // theme.colors.primary, theme.section.dividerColor, etc.
16
+ * ```
17
+ */
18
+ export declare function useWidgetTheme(): ResolvedTheme;
19
+ //# sourceMappingURL=useWidgetTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWidgetTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useWidgetTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,YAAY,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAE5D,eAAO,MAAM,YAAY;;;;;;GAA6C,CAAC;AAEvE;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,aAAa,CAE9C"}
@@ -0,0 +1,101 @@
1
+ import React from 'react';
2
+ /**
3
+ * Theme color tokens for the widget library.
4
+ * All properties are optional — omitted values fall back to built-in defaults.
5
+ */
6
+ export interface WidgetThemeColors {
7
+ /** Main brand colour (default: #F2BA1A — gold) */
8
+ primary?: string;
9
+ /** Darker brand accent (default: #ED7C22 — orange) */
10
+ primaryDark?: string;
11
+ /** Light brand tint for backgrounds (default: #F3E6BC) */
12
+ primaryLight?: string;
13
+ /** Secondary accent used in edit-mode borders (default: #FD8C3E) */
14
+ primaryAccent?: string;
15
+ /** Standard border colour (default: #D1D5DB) */
16
+ border?: string;
17
+ /** Lighter border colour (default: #E5E7EB) */
18
+ borderLight?: string;
19
+ /** Default background (default: #FFFFFF) */
20
+ background?: string;
21
+ /** Alternate/muted background (default: #F3F4F6) */
22
+ backgroundAlt?: string;
23
+ /** Primary text colour (default: #000000) */
24
+ text?: string;
25
+ /** Secondary / muted text colour (default: #6B7280) */
26
+ textMuted?: string;
27
+ /** Success green (default: #16A34A) */
28
+ success?: string;
29
+ /** Success dark green (default: #047857) */
30
+ successDark?: string;
31
+ /** Error / danger red (default: #B91C1C) */
32
+ error?: string;
33
+ /** Warning amber (default: #F59E0B) */
34
+ warning?: string;
35
+ /** Info / link blue (default: #2563EB) */
36
+ info?: string;
37
+ }
38
+ export interface WidgetThemeSection {
39
+ borderRadius?: string;
40
+ borderColor?: string;
41
+ backgroundColor?: string;
42
+ titleColor?: string;
43
+ /** Horizontal-rule / divider colour between panels (default: primary) */
44
+ dividerColor?: string;
45
+ }
46
+ export interface WidgetThemePanel {
47
+ /** Vertical divider colour between side-by-side panels */
48
+ dividerColor?: string;
49
+ backgroundColor?: string;
50
+ }
51
+ export interface WidgetThemeButton {
52
+ primaryBg?: string;
53
+ primaryColor?: string;
54
+ primaryBorder?: string;
55
+ secondaryBg?: string;
56
+ secondaryColor?: string;
57
+ secondaryBorder?: string;
58
+ borderRadius?: string;
59
+ }
60
+ export interface WidgetThemeWidget {
61
+ labelColor?: string;
62
+ inputBorderColor?: string;
63
+ inputFocusBorderColor?: string;
64
+ inputBackground?: string;
65
+ errorColor?: string;
66
+ helpTextColor?: string;
67
+ }
68
+ /**
69
+ * Top-level theme object accepted by `<WidgetProvider theme={…}>`.
70
+ * Every field is optional — only supply what you want to override.
71
+ */
72
+ export interface WidgetTheme {
73
+ colors?: WidgetThemeColors;
74
+ section?: WidgetThemeSection;
75
+ panel?: WidgetThemePanel;
76
+ button?: WidgetThemeButton;
77
+ widget?: WidgetThemeWidget;
78
+ }
79
+ /**
80
+ * Built-in default values (matches the original hardcoded colours).
81
+ */
82
+ export declare const defaultTheme: Required<{
83
+ colors: Required<WidgetThemeColors>;
84
+ section: Required<WidgetThemeSection>;
85
+ panel: Required<WidgetThemePanel>;
86
+ button: Required<WidgetThemeButton>;
87
+ widget: Required<WidgetThemeWidget>;
88
+ }>;
89
+ /**
90
+ * Merge a user-supplied (partial) theme with the built-in defaults.
91
+ */
92
+ export declare function resolveTheme(theme?: WidgetTheme): typeof defaultTheme;
93
+ /**
94
+ * Convert a resolved theme into a flat Record of CSS custom properties.
95
+ * These are set on the provider wrapper element so every descendant can
96
+ * reference them with `var(--owt-…)`.
97
+ *
98
+ * Prefix: `--owt-` (OpenG2P Widget Theme).
99
+ */
100
+ export declare function themeToCSSVariables(resolved: ReturnType<typeof resolveTheme>): React.CSSProperties;
101
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,WAAW,C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M,CAAC,EAAE,iBAAiB,CAAC;IAC3B,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC;IAClC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACpC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IACtC,KAAK,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAClC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACpC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;CACrC,CA8CA,CAAC;AAEF;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,YAAY,CASrE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,GACxC,KAAK,CAAC,aAAa,CA2CrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openg2p/registry-widgets",
3
- "version": "0.2.1",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "description": "Complete React widget library with generic form widgets, data binding, validation, and conditional logic",
6
6
  "main": "dist/index.js",