@schandlergarcia/sf-web-components 1.7.0 → 1.8.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.
Files changed (114) hide show
  1. package/dist/components/library/cards/ActionList.d.ts +10 -10
  2. package/dist/components/library/cards/ActionList.js +2 -3
  3. package/dist/components/library/cards/ActionList.js.map +1 -1
  4. package/dist/components/library/cards/ActivityCard.d.ts +18 -5
  5. package/dist/components/library/cards/ActivityCard.js +3 -4
  6. package/dist/components/library/cards/ActivityCard.js.map +1 -1
  7. package/dist/components/library/cards/BaseCard.d.ts +30 -24
  8. package/dist/components/library/cards/BaseCard.js +2 -3
  9. package/dist/components/library/cards/BaseCard.js.map +1 -1
  10. package/dist/components/library/cards/CalloutCard.d.ts +11 -9
  11. package/dist/components/library/cards/CalloutCard.js +2 -3
  12. package/dist/components/library/cards/CalloutCard.js.map +1 -1
  13. package/dist/components/library/cards/ChartCard.d.ts +29 -17
  14. package/dist/components/library/cards/ChartCard.js +13 -14
  15. package/dist/components/library/cards/ChartCard.js.map +1 -1
  16. package/dist/components/library/cards/FeedPanel.d.ts +12 -11
  17. package/dist/components/library/cards/FeedPanel.js +3 -4
  18. package/dist/components/library/cards/FeedPanel.js.map +1 -1
  19. package/dist/components/library/cards/ListCard.d.ts +33 -20
  20. package/dist/components/library/cards/ListCard.js +35 -35
  21. package/dist/components/library/cards/ListCard.js.map +1 -1
  22. package/dist/components/library/cards/MetricCard.d.ts +23 -17
  23. package/dist/components/library/cards/MetricCard.js +10 -11
  24. package/dist/components/library/cards/MetricCard.js.map +1 -1
  25. package/dist/components/library/cards/MetricsStrip.d.ts +11 -11
  26. package/dist/components/library/cards/MetricsStrip.js +1 -1
  27. package/dist/components/library/cards/MetricsStrip.js.map +1 -1
  28. package/dist/components/library/cards/SectionCard.d.ts +17 -12
  29. package/dist/components/library/cards/SectionCard.js +18 -19
  30. package/dist/components/library/cards/SectionCard.js.map +1 -1
  31. package/dist/components/library/cards/SemanticMetricCard.d.ts +15 -20
  32. package/dist/components/library/cards/SemanticMetricCardWithLoading.d.ts +8 -7
  33. package/dist/components/library/cards/SemanticTableCard.d.ts +13 -18
  34. package/dist/components/library/cards/SemanticTableCardWithLoading.d.ts +8 -7
  35. package/dist/components/library/cards/StatusCard.d.ts +29 -15
  36. package/dist/components/library/cards/StatusCard.js +16 -17
  37. package/dist/components/library/cards/StatusCard.js.map +1 -1
  38. package/dist/components/library/cards/TableCard.d.ts +40 -23
  39. package/dist/components/library/cards/TableCard.js +59 -59
  40. package/dist/components/library/cards/TableCard.js.map +1 -1
  41. package/dist/components/library/cards/WidgetCard.d.ts +19 -11
  42. package/dist/components/library/cards/WidgetCard.js.map +1 -1
  43. package/dist/components/library/charts/D3Chart.d.ts +23 -16
  44. package/dist/components/library/charts/D3Chart.js.map +1 -1
  45. package/dist/components/library/charts/D3ChartTemplates.d.ts +33 -3
  46. package/dist/components/library/charts/D3ChartTemplates.js +7 -7
  47. package/dist/components/library/charts/D3ChartTemplates.js.map +1 -1
  48. package/dist/components/library/charts/GeoMap.d.ts +81 -18
  49. package/dist/components/library/charts/GeoMap.js +28 -26
  50. package/dist/components/library/charts/GeoMap.js.map +1 -1
  51. package/dist/components/library/filters/FilterBar.d.ts +18 -8
  52. package/dist/components/library/filters/FilterBar.js +2 -3
  53. package/dist/components/library/filters/FilterBar.js.map +1 -1
  54. package/dist/components/library/filters/SearchFilter.d.ts +7 -6
  55. package/dist/components/library/filters/SearchFilter.js +2 -3
  56. package/dist/components/library/filters/SearchFilter.js.map +1 -1
  57. package/dist/components/library/filters/SelectFilter.d.ts +13 -7
  58. package/dist/components/library/filters/SelectFilter.js +2 -3
  59. package/dist/components/library/filters/SelectFilter.js.map +1 -1
  60. package/dist/components/library/filters/ToggleFilter.d.ts +7 -5
  61. package/dist/components/library/filters/ToggleFilter.js +2 -3
  62. package/dist/components/library/filters/ToggleFilter.js.map +1 -1
  63. package/dist/components/library/forms/FormField.d.ts +10 -8
  64. package/dist/components/library/forms/FormField.js +3 -4
  65. package/dist/components/library/forms/FormField.js.map +1 -1
  66. package/dist/components/library/forms/FormModal.d.ts +23 -14
  67. package/dist/components/library/forms/FormModal.js.map +1 -1
  68. package/dist/components/library/forms/FormRenderer.d.ts +29 -9
  69. package/dist/components/library/forms/FormRenderer.js +6 -7
  70. package/dist/components/library/forms/FormRenderer.js.map +1 -1
  71. package/dist/components/library/forms/FormSection.d.ts +10 -8
  72. package/dist/components/library/forms/FormSection.js +2 -3
  73. package/dist/components/library/forms/FormSection.js.map +1 -1
  74. package/dist/components/library/forms/index.d.ts +5 -0
  75. package/dist/components/library/forms/useFormState.d.ts +23 -15
  76. package/dist/components/library/forms/useFormState.js +53 -47
  77. package/dist/components/library/forms/useFormState.js.map +1 -1
  78. package/dist/components/library/layout/PageContainer.d.ts +6 -4
  79. package/dist/components/library/layout/PageContainer.js +4 -5
  80. package/dist/components/library/layout/PageContainer.js.map +1 -1
  81. package/package.json +4 -1
  82. package/src/components/library/cards/{ActionList.jsx → ActionList.tsx} +13 -9
  83. package/src/components/library/cards/{ActivityCard.jsx → ActivityCard.tsx} +33 -4
  84. package/src/components/library/cards/{BaseCard.jsx → BaseCard.tsx} +33 -6
  85. package/src/components/library/cards/{CalloutCard.jsx → CalloutCard.tsx} +12 -10
  86. package/src/components/library/cards/{ChartCard.jsx → ChartCard.tsx} +32 -6
  87. package/src/components/library/cards/{FeedPanel.jsx → FeedPanel.tsx} +13 -2
  88. package/src/components/library/cards/{ListCard.jsx → ListCard.tsx} +43 -7
  89. package/src/components/library/cards/{MetricCard.jsx → MetricCard.tsx} +25 -6
  90. package/src/components/library/cards/{MetricsStrip.jsx → MetricsStrip.tsx} +22 -12
  91. package/src/components/library/cards/{SectionCard.jsx → SectionCard.tsx} +27 -8
  92. package/src/components/library/cards/{SemanticMetricCard.jsx → SemanticMetricCard.tsx} +17 -5
  93. package/src/components/library/cards/{SemanticMetricCardWithLoading.jsx → SemanticMetricCardWithLoading.tsx} +9 -3
  94. package/src/components/library/cards/{SemanticTableCard.jsx → SemanticTableCard.tsx} +14 -3
  95. package/src/components/library/cards/{SemanticTableCardWithLoading.jsx → SemanticTableCardWithLoading.tsx} +9 -5
  96. package/src/components/library/cards/{StatusCard.jsx → StatusCard.tsx} +61 -12
  97. package/src/components/library/cards/{TableCard.jsx → TableCard.tsx} +51 -12
  98. package/src/components/library/cards/{WidgetCard.jsx → WidgetCard.tsx} +28 -5
  99. package/src/components/library/charts/{D3Chart.jsx → D3Chart.tsx} +27 -7
  100. package/src/components/library/charts/{D3ChartTemplates.jsx → D3ChartTemplates.tsx} +60 -28
  101. package/src/components/library/charts/{GeoMap.jsx → GeoMap.tsx} +106 -17
  102. package/src/components/library/filters/{FilterBar.jsx → FilterBar.tsx} +21 -11
  103. package/src/components/library/filters/{SearchFilter.jsx → SearchFilter.tsx} +8 -2
  104. package/src/components/library/filters/{SelectFilter.jsx → SelectFilter.tsx} +15 -8
  105. package/src/components/library/filters/{ToggleFilter.jsx → ToggleFilter.tsx} +7 -6
  106. package/src/components/library/forms/{FormField.jsx → FormField.tsx} +91 -45
  107. package/src/components/library/forms/{FormModal.jsx → FormModal.tsx} +21 -20
  108. package/src/components/library/forms/{FormRenderer.jsx → FormRenderer.tsx} +32 -10
  109. package/src/components/library/forms/{FormSection.jsx → FormSection.tsx} +13 -7
  110. package/src/components/library/forms/index.tsx +11 -0
  111. package/src/components/library/forms/{useFormState.jsx → useFormState.tsx} +43 -23
  112. package/src/components/library/layout/{PageContainer.jsx → PageContainer.tsx} +6 -3
  113. package/src/components/library/forms/index.jsx +0 -5
  114. /package/src/components/library/filters/{index.jsx → index.ts} +0 -0
@@ -1,9 +1,12 @@
1
1
  import React, { useMemo, useRef, useEffect, useState, useCallback } from "react";
2
2
  import * as d3 from "d3";
3
3
  import { feature } from "topojson-client";
4
+ import type { Topology, GeometryCollection } from "topojson-specification";
4
5
  import world from "world-atlas/land-110m.json";
5
6
 
6
- const land = feature(world, world.objects.land);
7
+ const land = feature(world as unknown as Topology<{ land: GeometryCollection }>, (world.objects.land as unknown) as GeometryCollection);
8
+
9
+ type ProjectionType = "naturalEarth" | "mercator" | "equirectangular";
7
10
 
8
11
  const PROJECTIONS = {
9
12
  naturalEarth: d3.geoNaturalEarth1,
@@ -11,7 +14,30 @@ const PROJECTIONS = {
11
14
  equirectangular: d3.geoEquirectangular,
12
15
  };
13
16
 
14
- const THEMES = {
17
+ interface Theme {
18
+ bg: string;
19
+ bgGradient: [string, string];
20
+ land: string;
21
+ landStroke: string;
22
+ sphere: string;
23
+ graticule: string;
24
+ graticuleOpacity: number;
25
+ markerActive: string;
26
+ markerInactive: string;
27
+ label: string;
28
+ labelInactive: string;
29
+ arc: string;
30
+ arcHighlight: string;
31
+ arcDanger: string;
32
+ dot: string;
33
+ dotDanger: string;
34
+ overlayFill: string;
35
+ overlayStroke: string;
36
+ }
37
+
38
+ type ThemeName = "dark" | "light";
39
+
40
+ const THEMES: Record<ThemeName, Theme> = {
15
41
  dark: {
16
42
  bg: "#050b15",
17
43
  bgGradient: ["#0a1628", "#050b15"],
@@ -54,11 +80,72 @@ const THEMES = {
54
80
  },
55
81
  };
56
82
 
57
- function buildProjection(type, width, height) {
83
+ function buildProjection(type: ProjectionType, width: number, height: number): d3.GeoProjection {
58
84
  const factory = PROJECTIONS[type] ?? PROJECTIONS.naturalEarth;
59
85
  return factory().fitSize([width, height], { type: "Sphere" });
60
86
  }
61
87
 
88
+ export interface Marker {
89
+ id: string;
90
+ lon: number;
91
+ lat: number;
92
+ label?: string | false;
93
+ active?: boolean;
94
+ }
95
+
96
+ export interface Arc {
97
+ id: string;
98
+ from: [number, number];
99
+ to: [number, number];
100
+ danger?: boolean;
101
+ color?: string;
102
+ dotColor?: string;
103
+ progress?: number;
104
+ _path?: string | null;
105
+ }
106
+
107
+ export interface Overlay {
108
+ id: string;
109
+ center: [number, number];
110
+ radius?: number;
111
+ fill?: string;
112
+ stroke?: string;
113
+ }
114
+
115
+ export interface InitialBounds {
116
+ sw: [number, number];
117
+ ne: [number, number];
118
+ padding?: number;
119
+ }
120
+
121
+ interface ChildrenFunctionProps {
122
+ proj: d3.GeoProjection;
123
+ pathGen: d3.GeoPath;
124
+ theme: Theme;
125
+ width: number;
126
+ height: number;
127
+ transform: d3.ZoomTransform;
128
+ }
129
+
130
+ export interface GeoMapProps {
131
+ width?: number;
132
+ height?: number;
133
+ projection?: ProjectionType;
134
+ theme?: ThemeName;
135
+ markers?: Marker[];
136
+ arcs?: Arc[];
137
+ overlays?: Overlay[];
138
+ selectedId?: string | null;
139
+ onArcClick?: (arc: Arc) => void;
140
+ onMarkerClick?: (marker: Marker) => void;
141
+ zoomable?: boolean;
142
+ minZoom?: number;
143
+ maxZoom?: number;
144
+ initialBounds?: InitialBounds | null;
145
+ className?: string;
146
+ children?: React.ReactNode | ((props: ChildrenFunctionProps) => React.ReactNode);
147
+ }
148
+
62
149
  export default function GeoMap({
63
150
  width = 960,
64
151
  height = 480,
@@ -76,11 +163,11 @@ export default function GeoMap({
76
163
  initialBounds = null,
77
164
  className = "",
78
165
  children,
79
- }) {
166
+ }: GeoMapProps): React.ReactElement {
80
167
  const t = THEMES[theme] ?? THEMES.dark;
81
- const svgRef = useRef(null);
82
- const [transform, setTransform] = useState(d3.zoomIdentity);
83
- const zoomRef = useRef(null);
168
+ const svgRef = useRef<SVGSVGElement>(null);
169
+ const [transform, setTransform] = useState<d3.ZoomTransform>(d3.zoomIdentity);
170
+ const zoomRef = useRef<d3.ZoomBehavior<SVGSVGElement, unknown> | null>(null);
84
171
 
85
172
  const { proj, pathGen, graticulePath, spherePath, landPath } = useMemo(() => {
86
173
  const proj = buildProjection(projType, width, height);
@@ -98,12 +185,14 @@ export default function GeoMap({
98
185
  useEffect(() => {
99
186
  if (!zoomable || !svgRef.current) return;
100
187
  const svg = d3.select(svgRef.current);
101
- const zoom = d3.zoom()
188
+ const zoom = d3.zoom<SVGSVGElement, unknown>()
102
189
  .scaleExtent([minZoom, maxZoom])
103
- .on("zoom", (e) => setTransform(e.transform));
190
+ .on("zoom", (e: d3.D3ZoomEvent<SVGSVGElement, unknown>) => setTransform(e.transform));
104
191
  zoomRef.current = zoom;
105
192
  svg.call(zoom);
106
- return () => svg.on(".zoom", null);
193
+ return () => {
194
+ svg.on(".zoom", null);
195
+ };
107
196
  }, [zoomable, minZoom, maxZoom]);
108
197
 
109
198
  // Apply initial zoom to fit bounds (markers/region) on mount
@@ -144,15 +233,15 @@ export default function GeoMap({
144
233
  const isZoomed = transform.k !== 1 || transform.x !== 0 || transform.y !== 0;
145
234
 
146
235
  const arcPaths = useMemo(() => {
147
- const cache = {};
236
+ const cache: Record<string, string | null> = {};
148
237
  arcs.forEach(a => {
149
238
  const key = `${a.from[0]},${a.from[1]}-${a.to[0]},${a.to[1]}`;
150
239
  if (cache[key]) { a._path = cache[key]; return; }
151
240
  const interp = d3.geoInterpolate(a.from, a.to);
152
- const pts = [];
241
+ const pts: [number, number][] = [];
153
242
  for (let i = 0; i <= 1; i += 0.02) {
154
243
  const p = proj(interp(i));
155
- if (p) pts.push(p);
244
+ if (p) pts.push(p as [number, number]);
156
245
  }
157
246
  const path = pts.length > 1 ? d3.line()(pts) : null;
158
247
  cache[key] = path;
@@ -162,7 +251,7 @@ export default function GeoMap({
162
251
  }, [arcs, proj]);
163
252
 
164
253
  const activeMarkerIds = useMemo(() => {
165
- const s = new Set();
254
+ const s = new Set<string>();
166
255
  markers.forEach(m => { if (m.active) s.add(m.id); });
167
256
  return s;
168
257
  }, [markers]);
@@ -194,9 +283,9 @@ export default function GeoMap({
194
283
 
195
284
  {/* Zoomable content group */}
196
285
  <g transform={txStr}>
197
- <path d={spherePath} fill="none" stroke={t.sphere} strokeWidth={0.8 * invScale} />
198
- <path d={landPath} fill={t.land} stroke={t.landStroke} strokeWidth={0.4 * invScale} />
199
- <path d={graticulePath} fill="none" stroke={t.graticule} strokeWidth={0.3 * invScale} opacity={t.graticuleOpacity} />
286
+ <path d={spherePath ?? undefined} fill="none" stroke={t.sphere} strokeWidth={0.8 * invScale} />
287
+ <path d={landPath ?? undefined} fill={t.land} stroke={t.landStroke} strokeWidth={0.4 * invScale} />
288
+ <path d={graticulePath ?? undefined} fill="none" stroke={t.graticule} strokeWidth={0.3 * invScale} opacity={t.graticuleOpacity} />
200
289
 
201
290
  {/* Overlay zones (disruptions, weather) */}
202
291
  {overlays.map(o => {
@@ -1,19 +1,29 @@
1
- import React from "react";
2
1
  import SearchFilter from "./SearchFilter";
3
- import SelectFilter from "./SelectFilter";
2
+ import SelectFilter, { SelectOption } from "./SelectFilter";
4
3
  import ToggleFilter from "./ToggleFilter";
5
- import { FunnelIcon, XMarkIcon } from "@heroicons/react/24/outline";
4
+ import { XMarkIcon } from "@heroicons/react/24/outline";
5
+
6
+ export interface FilterDefinition {
7
+ id: string;
8
+ type: "search" | "select" | "toggle";
9
+ label?: string;
10
+ placeholder?: string;
11
+ options?: (string | SelectOption)[];
12
+ className?: string;
13
+ }
14
+
15
+ export interface FilterBarProps {
16
+ filters?: FilterDefinition[];
17
+ values?: Record<string, any>;
18
+ onChange?: (filterId: string, value: any) => void;
19
+ onReset?: () => void;
20
+ activeCount?: number;
21
+ layout?: "inline" | "stacked";
22
+ }
6
23
 
7
24
  /**
8
25
  * Renders a row of filter controls from a definitions array.
9
26
  * Pairs with usePageFilters hook for state management.
10
- *
11
- * @param {Array} filters — filter definitions [{ id, type, ... }]
12
- * @param {Object} values — current filter values keyed by filter id
13
- * @param {Function} onChange — (filterId, value) => void
14
- * @param {Function} onReset — () => void
15
- * @param {number} activeCount — number of active filters (for badge)
16
- * @param {string} layout — "inline" (default) or "stacked"
17
27
  */
18
28
  export default function FilterBar({
19
29
  filters = [],
@@ -22,7 +32,7 @@ export default function FilterBar({
22
32
  onReset,
23
33
  activeCount = 0,
24
34
  layout = "inline",
25
- }) {
35
+ }: FilterBarProps) {
26
36
  if (!filters.length) return null;
27
37
 
28
38
  const isStacked = layout === "stacked";
@@ -1,12 +1,18 @@
1
- import React from "react";
2
1
  import { MagnifyingGlassIcon, XMarkIcon } from "@heroicons/react/24/outline";
3
2
 
3
+ export interface SearchFilterProps {
4
+ value?: string;
5
+ onChange?: (value: string) => void;
6
+ placeholder?: string;
7
+ className?: string;
8
+ }
9
+
4
10
  export default function SearchFilter({
5
11
  value = "",
6
12
  onChange,
7
13
  placeholder = "Search…",
8
14
  className = "",
9
- }) {
15
+ }: SearchFilterProps) {
10
16
  return (
11
17
  <div className={["relative", className].filter(Boolean).join(" ")}>
12
18
  <MagnifyingGlassIcon
@@ -1,14 +1,21 @@
1
- import React from "react";
2
1
  import { ChevronDownIcon } from "@heroicons/react/24/outline";
3
2
 
3
+ export interface SelectOption {
4
+ value: string;
5
+ label: string;
6
+ }
7
+
8
+ export interface SelectFilterProps {
9
+ value?: string;
10
+ onChange?: (value: string) => void;
11
+ options?: (string | SelectOption)[];
12
+ label?: string;
13
+ placeholder?: string;
14
+ className?: string;
15
+ }
16
+
4
17
  /**
5
18
  * Dropdown select filter.
6
- *
7
- * @param {string} value — current selected value
8
- * @param {Function} onChange — (value) => void
9
- * @param {Array} options — [{ value, label }] or ["string", ...]
10
- * @param {string} label — visible label
11
- * @param {string} placeholder — placeholder when no value selected
12
19
  */
13
20
  export default function SelectFilter({
14
21
  value = "all",
@@ -17,7 +24,7 @@ export default function SelectFilter({
17
24
  label,
18
25
  placeholder,
19
26
  className = "",
20
- }) {
27
+ }: SelectFilterProps) {
21
28
  const normalizedOptions = options.map((opt) =>
22
29
  typeof opt === "string" ? { value: opt, label: opt } : opt
23
30
  );
@@ -1,18 +1,19 @@
1
- import React from "react";
1
+ export interface ToggleFilterProps {
2
+ value?: boolean;
3
+ onChange?: (value: boolean) => void;
4
+ label?: string;
5
+ className?: string;
6
+ }
2
7
 
3
8
  /**
4
9
  * Toggle switch filter.
5
- *
6
- * @param {boolean} value — current on/off state
7
- * @param {Function} onChange — (boolean) => void
8
- * @param {string} label — visible label
9
10
  */
10
11
  export default function ToggleFilter({
11
12
  value = false,
12
13
  onChange,
13
14
  label,
14
15
  className = "",
15
- }) {
16
+ }: ToggleFilterProps) {
16
17
  return (
17
18
  <label
18
19
  className={[
@@ -1,5 +1,6 @@
1
- import React from "react";
1
+ import * as React from "react";
2
2
  import { ChevronDownIcon } from "@heroicons/react/24/outline";
3
+ import type { FormField as FormFieldType } from "./FormRenderer";
3
4
 
4
5
  const INPUT_BASE =
5
6
  "h-10 w-full rounded-lg border border-slate-200 bg-white px-3 text-sm text-slate-900 shadow-sm placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-50 dark:placeholder:text-slate-500 dark:focus:ring-offset-slate-950";
@@ -7,11 +8,17 @@ const INPUT_BASE =
7
8
  const INPUT_ERROR =
8
9
  "border-red-300 focus:ring-red-500 dark:border-red-700 dark:focus:ring-red-500";
9
10
 
10
- function cx(...classes) {
11
+ function cx(...classes: (string | boolean | undefined)[]): string {
11
12
  return classes.filter(Boolean).join(" ");
12
13
  }
13
14
 
14
- function FieldLabel({ label, required, htmlFor }) {
15
+ interface FieldLabelProps {
16
+ label?: string;
17
+ required?: boolean;
18
+ htmlFor: string;
19
+ }
20
+
21
+ function FieldLabel({ label, required, htmlFor }: FieldLabelProps) {
15
22
  if (!label) return null;
16
23
  return (
17
24
  <label htmlFor={htmlFor} className="block text-sm font-medium text-slate-700 dark:text-slate-200">
@@ -21,20 +28,36 @@ function FieldLabel({ label, required, htmlFor }) {
21
28
  );
22
29
  }
23
30
 
24
- function FieldError({ error }) {
31
+ interface FieldErrorProps {
32
+ error?: string;
33
+ }
34
+
35
+ function FieldError({ error }: FieldErrorProps) {
25
36
  if (!error) return null;
26
37
  return <p className="text-xs text-red-600 dark:text-red-400">{error}</p>;
27
38
  }
28
39
 
29
- function FieldDescription({ description }) {
40
+ interface FieldDescriptionProps {
41
+ description?: string;
42
+ }
43
+
44
+ function FieldDescription({ description }: FieldDescriptionProps) {
30
45
  if (!description) return null;
31
46
  return <p className="text-xs text-slate-500 dark:text-slate-400">{description}</p>;
32
47
  }
33
48
 
34
49
  // ─── Individual field renderers ───
35
50
 
36
- function TextField({ field, value, onChange, onBlur, error }) {
37
- const inputType = field.inputType ?? field.type;
51
+ interface FieldRendererProps {
52
+ field: FormFieldType & Record<string, unknown>;
53
+ value: unknown;
54
+ onChange: (value: unknown) => void;
55
+ onBlur: () => void;
56
+ error?: boolean;
57
+ }
58
+
59
+ function TextField({ field, value, onChange, onBlur, error }: FieldRendererProps) {
60
+ const inputType = (field.inputType as string | undefined) ?? field.type;
38
61
  const type = { text: "text", email: "email", url: "url", number: "number", date: "date" }[inputType] ?? "text";
39
62
 
40
63
  return (
@@ -42,32 +65,32 @@ function TextField({ field, value, onChange, onBlur, error }) {
42
65
  id={field.id}
43
66
  name={field.id}
44
67
  type={type}
45
- value={value ?? ""}
68
+ value={(value as string | number) ?? ""}
46
69
  onChange={(e) => onChange(field.type === "number" ? e.target.value : e.target.value)}
47
70
  onBlur={onBlur}
48
- placeholder={field.placeholder}
49
- disabled={field.disabled}
50
- readOnly={field.readOnly}
51
- min={field.min}
52
- max={field.max}
53
- step={field.step}
71
+ placeholder={field.placeholder as string | undefined}
72
+ disabled={field.disabled as boolean | undefined}
73
+ readOnly={field.readOnly as boolean | undefined}
74
+ min={field.min as number | undefined}
75
+ max={field.max as number | undefined}
76
+ step={field.step as number | undefined}
54
77
  className={cx(INPUT_BASE, error && INPUT_ERROR)}
55
78
  />
56
79
  );
57
80
  }
58
81
 
59
- function TextareaField({ field, value, onChange, onBlur, error }) {
82
+ function TextareaField({ field, value, onChange, onBlur, error }: FieldRendererProps) {
60
83
  return (
61
84
  <textarea
62
85
  id={field.id}
63
86
  name={field.id}
64
- value={value ?? ""}
87
+ value={(value as string) ?? ""}
65
88
  onChange={(e) => onChange(e.target.value)}
66
89
  onBlur={onBlur}
67
- placeholder={field.placeholder}
68
- disabled={field.disabled}
69
- readOnly={field.readOnly}
70
- rows={field.rows ?? 3}
90
+ placeholder={field.placeholder as string | undefined}
91
+ disabled={field.disabled as boolean | undefined}
92
+ readOnly={field.readOnly as boolean | undefined}
93
+ rows={(field.rows as number | undefined) ?? 3}
71
94
  className={cx(
72
95
  "w-full rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900 shadow-sm placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-50 dark:placeholder:text-slate-500 dark:focus:ring-offset-slate-950",
73
96
  error && INPUT_ERROR
@@ -76,8 +99,13 @@ function TextareaField({ field, value, onChange, onBlur, error }) {
76
99
  );
77
100
  }
78
101
 
79
- function SelectField({ field, value, onChange, onBlur, error }) {
80
- const options = (field.options ?? []).map((opt) =>
102
+ interface SelectOption {
103
+ value: string;
104
+ label: string;
105
+ }
106
+
107
+ function SelectField({ field, value, onChange, onBlur, error }: FieldRendererProps) {
108
+ const options = ((field.options as (string | SelectOption)[] | undefined) ?? []).map((opt) =>
81
109
  typeof opt === "string" ? { value: opt, label: opt } : opt
82
110
  );
83
111
 
@@ -86,17 +114,17 @@ function SelectField({ field, value, onChange, onBlur, error }) {
86
114
  <select
87
115
  id={field.id}
88
116
  name={field.id}
89
- value={value ?? ""}
117
+ value={(value as string) ?? ""}
90
118
  onChange={(e) => onChange(e.target.value)}
91
119
  onBlur={onBlur}
92
- disabled={field.disabled}
120
+ disabled={field.disabled as boolean | undefined}
93
121
  className={cx(
94
122
  "h-10 w-full appearance-none rounded-lg border border-slate-200 bg-white py-0 pl-3 pr-9 text-sm font-medium text-slate-700 shadow-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-200 dark:focus:ring-offset-slate-950",
95
123
  error && INPUT_ERROR
96
124
  )}
97
125
  >
98
126
  {field.placeholder ? (
99
- <option value="">{field.placeholder}</option>
127
+ <option value="">{field.placeholder as string}</option>
100
128
  ) : null}
101
129
  {options.map((opt) => (
102
130
  <option key={opt.value} value={opt.value}>
@@ -112,11 +140,16 @@ function SelectField({ field, value, onChange, onBlur, error }) {
112
140
  );
113
141
  }
114
142
 
115
- function RadioField({ field, value, onChange }) {
116
- const options = (field.options ?? []).map((opt) =>
143
+ interface RadioOption extends SelectOption {
144
+ description?: string;
145
+ disabled?: boolean;
146
+ }
147
+
148
+ function RadioField({ field, value, onChange }: FieldRendererProps) {
149
+ const options = ((field.options as (string | RadioOption)[] | undefined) ?? []).map((opt) =>
117
150
  typeof opt === "string" ? { value: opt, label: opt } : opt
118
151
  );
119
- const layout = field.layout ?? (options.length <= 4 ? "horizontal" : "vertical");
152
+ const layout = (field.layout as string | undefined) ?? (options.length <= 4 ? "horizontal" : "vertical");
120
153
 
121
154
  return (
122
155
  <div
@@ -138,7 +171,7 @@ function RadioField({ field, value, onChange }) {
138
171
  value={opt.value}
139
172
  checked={value === opt.value}
140
173
  onChange={() => onChange(opt.value)}
141
- disabled={field.disabled || opt.disabled}
174
+ disabled={(field.disabled as boolean | undefined) || opt.disabled}
142
175
  className="h-4 w-4 border-slate-300 text-brand-600 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-800"
143
176
  />
144
177
  {opt.label}
@@ -151,7 +184,7 @@ function RadioField({ field, value, onChange }) {
151
184
  );
152
185
  }
153
186
 
154
- function CheckboxField({ field, value, onChange }) {
187
+ function CheckboxField({ field, value, onChange }: FieldRendererProps) {
155
188
  return (
156
189
  <label className="inline-flex cursor-pointer items-center gap-2.5 text-sm text-slate-700 dark:text-slate-200">
157
190
  <input
@@ -160,22 +193,26 @@ function CheckboxField({ field, value, onChange }) {
160
193
  name={field.id}
161
194
  checked={Boolean(value)}
162
195
  onChange={(e) => onChange(e.target.checked)}
163
- disabled={field.disabled}
196
+ disabled={field.disabled as boolean | undefined}
164
197
  className="h-4 w-4 rounded border-slate-300 text-brand-600 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-800"
165
198
  />
166
- {field.checkboxLabel ?? field.label}
199
+ {(field.checkboxLabel as string | undefined) ?? field.label}
167
200
  </label>
168
201
  );
169
202
  }
170
203
 
171
- function CheckboxGroupField({ field, value, onChange }) {
204
+ interface CheckboxOption extends SelectOption {
205
+ disabled?: boolean;
206
+ }
207
+
208
+ function CheckboxGroupField({ field, value, onChange }: FieldRendererProps) {
172
209
  const selected = Array.isArray(value) ? value : [];
173
- const options = (field.options ?? []).map((opt) =>
210
+ const options = ((field.options as (string | CheckboxOption)[] | undefined) ?? []).map((opt) =>
174
211
  typeof opt === "string" ? { value: opt, label: opt } : opt
175
212
  );
176
- const layout = field.layout ?? (options.length <= 4 ? "horizontal" : "vertical");
213
+ const layout = (field.layout as string | undefined) ?? (options.length <= 4 ? "horizontal" : "vertical");
177
214
 
178
- function toggleValue(optValue) {
215
+ function toggleValue(optValue: string) {
179
216
  const next = selected.includes(optValue)
180
217
  ? selected.filter((v) => v !== optValue)
181
218
  : [...selected, optValue];
@@ -198,7 +235,7 @@ function CheckboxGroupField({ field, value, onChange }) {
198
235
  type="checkbox"
199
236
  checked={selected.includes(opt.value)}
200
237
  onChange={() => toggleValue(opt.value)}
201
- disabled={field.disabled || opt.disabled}
238
+ disabled={(field.disabled as boolean | undefined) || opt.disabled}
202
239
  className="h-4 w-4 rounded border-slate-300 text-brand-600 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-800"
203
240
  />
204
241
  {opt.label}
@@ -208,7 +245,7 @@ function CheckboxGroupField({ field, value, onChange }) {
208
245
  );
209
246
  }
210
247
 
211
- function ToggleField({ field, value, onChange }) {
248
+ function ToggleField({ field, value, onChange }: FieldRendererProps) {
212
249
  const checked = Boolean(value);
213
250
 
214
251
  return (
@@ -218,7 +255,7 @@ function ToggleField({ field, value, onChange }) {
218
255
  role="switch"
219
256
  aria-checked={checked}
220
257
  onClick={() => onChange(!checked)}
221
- disabled={field.disabled}
258
+ disabled={field.disabled as boolean | undefined}
222
259
  className={cx(
223
260
  "relative inline-flex h-6 w-11 shrink-0 rounded-full border-2 border-transparent transition-colors focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2 dark:focus:ring-offset-slate-950",
224
261
  checked ? "bg-brand-500" : "bg-slate-200 dark:bg-slate-700",
@@ -234,7 +271,7 @@ function ToggleField({ field, value, onChange }) {
234
271
  />
235
272
  </button>
236
273
  {field.toggleLabel ? (
237
- <span className="text-sm text-slate-700 dark:text-slate-200">{field.toggleLabel}</span>
274
+ <span className="text-sm text-slate-700 dark:text-slate-200">{field.toggleLabel as string}</span>
238
275
  ) : null}
239
276
  </div>
240
277
  );
@@ -242,7 +279,7 @@ function ToggleField({ field, value, onChange }) {
242
279
 
243
280
  // ─── Main FormField ───
244
281
 
245
- const FIELD_RENDERERS = {
282
+ const FIELD_RENDERERS: Record<string, React.ComponentType<FieldRendererProps>> = {
246
283
  text: TextField,
247
284
  email: TextField,
248
285
  url: TextField,
@@ -256,11 +293,20 @@ const FIELD_RENDERERS = {
256
293
  toggle: ToggleField,
257
294
  };
258
295
 
296
+ export interface FormFieldProps {
297
+ field: FormFieldType & Record<string, unknown>;
298
+ value: unknown;
299
+ error?: string;
300
+ touched?: boolean;
301
+ onChange: (value: unknown) => void;
302
+ onBlur: () => void;
303
+ }
304
+
259
305
  /**
260
306
  * Renders a single form field with label, description, error message,
261
307
  * and the appropriate input type.
262
308
  */
263
- export default function FormField({ field, value, error, touched, onChange, onBlur }) {
309
+ export default function FormField({ field, value, error, touched, onChange, onBlur }: FormFieldProps) {
264
310
  const Renderer = FIELD_RENDERERS[field.type];
265
311
  if (!Renderer) return null;
266
312
 
@@ -273,17 +319,17 @@ export default function FormField({ field, value, error, touched, onChange, onBl
273
319
  <FieldLabel label={field.label} required={field.required} htmlFor={field.id} />
274
320
  ) : null}
275
321
  {field.description && field.type !== "toggle" ? (
276
- <FieldDescription description={field.description} />
322
+ <FieldDescription description={field.description as string} />
277
323
  ) : null}
278
324
  <Renderer
279
325
  field={field}
280
326
  value={value}
281
327
  onChange={onChange}
282
328
  onBlur={onBlur}
283
- error={showError}
329
+ error={Boolean(showError)}
284
330
  />
285
331
  {field.type === "toggle" && field.description ? (
286
- <FieldDescription description={field.description} />
332
+ <FieldDescription description={field.description as string} />
287
333
  ) : null}
288
334
  {showError ? <FieldError error={error} /> : null}
289
335
  </div>