@chobantonov/jsonforms-react-shadcn-renderers 0.0.0-stage → 0.1.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 (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -2
  3. package/lib/additional/LabelRenderer.d.ts +4 -0
  4. package/lib/additional/index.d.ts +1 -0
  5. package/lib/cells/BooleanCell.d.ts +3 -0
  6. package/lib/cells/Cell.d.ts +3 -0
  7. package/lib/cells/CompositeCell.d.ts +9 -0
  8. package/lib/cells/CompositeDetailDialog.d.ts +3 -0
  9. package/lib/cells/EnumCell.d.ts +3 -0
  10. package/lib/cells/NumberCell.d.ts +3 -0
  11. package/lib/cells/NumberFormatCell.d.ts +4 -0
  12. package/lib/cells/TextCell.d.ts +3 -0
  13. package/lib/cells/asCell.d.ts +12 -0
  14. package/lib/cells/index.d.ts +7 -0
  15. package/lib/complex/AdditionalProperties.d.ts +4 -0
  16. package/lib/complex/AnyOfRenderer.d.ts +7 -0
  17. package/lib/complex/ArrayChoicesControl.d.ts +6 -0
  18. package/lib/complex/ArrayControlRenderer.d.ts +4 -0
  19. package/lib/complex/ArrayPanelToggle.d.ts +6 -0
  20. package/lib/complex/CollectionPager.d.ts +5 -0
  21. package/lib/complex/CombinatorSwitchDialog.d.ts +8 -0
  22. package/lib/complex/DeleteDialog.d.ts +6 -0
  23. package/lib/complex/DetailDialogContent.d.ts +7 -0
  24. package/lib/complex/ErrorIndicator.d.ts +7 -0
  25. package/lib/complex/MixedRenderer.d.ts +6 -0
  26. package/lib/complex/ObjectRenderer.d.ts +3 -0
  27. package/lib/complex/OneOfRenderer.d.ts +5 -0
  28. package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
  29. package/lib/complex/RowDetailFrame.d.ts +16 -0
  30. package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
  31. package/lib/complex/TupleAdditionalItems.d.ts +4 -0
  32. package/lib/complex/TupleControlRenderer.d.ts +6 -0
  33. package/lib/complex/TupleField.d.ts +4 -0
  34. package/lib/complex/array/ArrayItemPanels.d.ts +18 -0
  35. package/lib/complex/array/ArrayItemViewProps.d.ts +11 -0
  36. package/lib/complex/array/ArrayListDetail.d.ts +9 -0
  37. package/lib/complex/array/ArrayTable.d.ts +21 -0
  38. package/lib/complex/index.d.ts +10 -0
  39. package/lib/complex/mixed/JsonTypeIcon.d.ts +5 -0
  40. package/lib/complex/mixed/MixedWidgets.d.ts +22 -0
  41. package/lib/complex/mixed/useConfirmation.d.ts +6 -0
  42. package/lib/components/ClearValueButton.d.ts +12 -0
  43. package/lib/components/ScrollRegion.d.ts +4 -0
  44. package/lib/components/TimePicker.d.ts +13 -0
  45. package/lib/components/index.d.ts +2 -0
  46. package/lib/controls/AnyOfStringOrEnumControl.d.ts +4 -0
  47. package/lib/controls/BooleanControl.d.ts +4 -0
  48. package/lib/controls/BooleanToggleControl.d.ts +4 -0
  49. package/lib/controls/ChoiceCards.d.ts +1 -0
  50. package/lib/controls/DateControl.d.ts +4 -0
  51. package/lib/controls/DateTimeControl.d.ts +4 -0
  52. package/lib/controls/EnumControl.d.ts +5 -0
  53. package/lib/controls/InputControl.d.ts +30 -0
  54. package/lib/controls/IntegerControl.d.ts +4 -0
  55. package/lib/controls/NumberControl.d.ts +4 -0
  56. package/lib/controls/OneOfEnumControl.d.ts +3 -0
  57. package/lib/controls/PasswordControl.d.ts +9 -0
  58. package/lib/controls/RadioGroupControl.d.ts +4 -0
  59. package/lib/controls/SliderControl.d.ts +4 -0
  60. package/lib/controls/TextControl.d.ts +4 -0
  61. package/lib/controls/TimeControl.d.ts +4 -0
  62. package/lib/controls/index.d.ts +15 -0
  63. package/lib/index.d.ts +6 -0
  64. package/lib/jsonforms-react-shadcn.cjs.js +3 -0
  65. package/lib/jsonforms-react-shadcn.cjs.js.map +1 -0
  66. package/lib/jsonforms-react-shadcn.esm.js +4040 -0
  67. package/lib/jsonforms-react-shadcn.esm.js.map +1 -0
  68. package/lib/layouts/CategorizationLayout.d.ts +7 -0
  69. package/lib/layouts/GroupLayout.d.ts +4 -0
  70. package/lib/layouts/HorizontalLayout.d.ts +4 -0
  71. package/lib/layouts/Layout.d.ts +5 -0
  72. package/lib/layouts/ValidationIndicator.d.ts +4 -0
  73. package/lib/layouts/VerticalLayout.d.ts +4 -0
  74. package/lib/layouts/index.d.ts +4 -0
  75. package/lib/renderers.d.ts +8 -0
  76. package/lib/util/dateTime.d.ts +12 -0
  77. package/lib/util/groupState.d.ts +1 -0
  78. package/lib/util/useTemporalControl.d.ts +28 -0
  79. package/package.json +86 -3
  80. package/src/additional/LabelRenderer.tsx +8 -0
  81. package/src/additional/index.ts +1 -0
  82. package/src/cells/BooleanCell.tsx +26 -0
  83. package/src/cells/Cell.tsx +101 -0
  84. package/src/cells/CompositeCell.tsx +275 -0
  85. package/src/cells/CompositeDetailDialog.tsx +79 -0
  86. package/src/cells/EnumCell.tsx +74 -0
  87. package/src/cells/NumberCell.tsx +51 -0
  88. package/src/cells/NumberFormatCell.tsx +47 -0
  89. package/src/cells/TextCell.tsx +40 -0
  90. package/src/cells/asCell.tsx +79 -0
  91. package/src/cells/index.ts +7 -0
  92. package/src/complex/AdditionalProperties.tsx +453 -0
  93. package/src/complex/AnyOfRenderer.tsx +341 -0
  94. package/src/complex/ArrayChoicesControl.tsx +303 -0
  95. package/src/complex/ArrayControlRenderer.tsx +400 -0
  96. package/src/complex/ArrayPanelToggle.tsx +33 -0
  97. package/src/complex/CollectionPager.tsx +76 -0
  98. package/src/complex/CombinatorSwitchDialog.tsx +43 -0
  99. package/src/complex/DeleteDialog.tsx +41 -0
  100. package/src/complex/DetailDialogContent.tsx +84 -0
  101. package/src/complex/ErrorIndicator.tsx +136 -0
  102. package/src/complex/MixedRenderer.tsx +262 -0
  103. package/src/complex/ObjectRenderer.tsx +43 -0
  104. package/src/complex/OneOfRenderer.tsx +14 -0
  105. package/src/complex/RecursiveTreeRenderer.tsx +20 -0
  106. package/src/complex/RowDetailFrame.tsx +158 -0
  107. package/src/complex/ScalarCompositionRenderer.tsx +14 -0
  108. package/src/complex/TupleAdditionalItems.tsx +94 -0
  109. package/src/complex/TupleControlRenderer.tsx +54 -0
  110. package/src/complex/TupleField.tsx +41 -0
  111. package/src/complex/array/ArrayItemPanels.tsx +217 -0
  112. package/src/complex/array/ArrayItemViewProps.ts +15 -0
  113. package/src/complex/array/ArrayListDetail.tsx +165 -0
  114. package/src/complex/array/ArrayTable.tsx +535 -0
  115. package/src/complex/index.ts +16 -0
  116. package/src/complex/mixed/JsonTypeIcon.tsx +41 -0
  117. package/src/complex/mixed/MixedWidgets.tsx +326 -0
  118. package/src/complex/mixed/useConfirmation.tsx +34 -0
  119. package/src/components/ClearValueButton.tsx +56 -0
  120. package/src/components/ScrollRegion.tsx +27 -0
  121. package/src/components/TimePicker.tsx +250 -0
  122. package/src/components/index.ts +2 -0
  123. package/src/controls/AnyOfStringOrEnumControl.tsx +44 -0
  124. package/src/controls/BooleanControl.tsx +67 -0
  125. package/src/controls/BooleanToggleControl.tsx +58 -0
  126. package/src/controls/ChoiceCards.tsx +9 -0
  127. package/src/controls/DateControl.tsx +240 -0
  128. package/src/controls/DateTimeControl.tsx +187 -0
  129. package/src/controls/EnumControl.tsx +159 -0
  130. package/src/controls/InputControl.tsx +258 -0
  131. package/src/controls/IntegerControl.tsx +14 -0
  132. package/src/controls/NumberControl.tsx +14 -0
  133. package/src/controls/OneOfEnumControl.tsx +13 -0
  134. package/src/controls/PasswordControl.tsx +216 -0
  135. package/src/controls/RadioGroupControl.tsx +72 -0
  136. package/src/controls/SliderControl.tsx +77 -0
  137. package/src/controls/TextControl.tsx +50 -0
  138. package/src/controls/TimeControl.tsx +135 -0
  139. package/src/controls/index.ts +19 -0
  140. package/src/index.tsx +10 -0
  141. package/src/layouts/CategorizationLayout.tsx +248 -0
  142. package/src/layouts/GroupLayout.tsx +210 -0
  143. package/src/layouts/HorizontalLayout.tsx +12 -0
  144. package/src/layouts/Layout.tsx +62 -0
  145. package/src/layouts/ValidationIndicator.tsx +40 -0
  146. package/src/layouts/VerticalLayout.tsx +12 -0
  147. package/src/layouts/index.ts +4 -0
  148. package/src/renderers.ts +225 -0
  149. package/src/styles.css +482 -0
  150. package/src/tailwind-theme.cjs +42 -0
  151. package/src/theme.css +43 -0
  152. package/src/util/dateTime.ts +80 -0
  153. package/src/util/groupState.ts +5 -0
  154. package/src/util/useTemporalControl.ts +160 -0
@@ -0,0 +1,326 @@
1
+ import {
2
+ useTranslator,
3
+ useI18n,
4
+ } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
5
+ import type { MixedTreeProps } from '@chobantonov/jsonforms-react-renderer-common/mixed/RecursiveTreeRenderer';
6
+ import { JsonTypeIcon } from './JsonTypeIcon';
7
+ import React, { useState } from 'react';
8
+ import { Button } from '@jsonforms-react-shadcn-ui/button';
9
+ import { Input } from '@jsonforms-react-shadcn-ui/input';
10
+ import {
11
+ Select,
12
+ SelectContent,
13
+ SelectItem,
14
+ SelectTrigger,
15
+ SelectValue,
16
+ } from '@jsonforms-react-shadcn-ui/select';
17
+ import {
18
+ Collapsible,
19
+ CollapsibleContent,
20
+ CollapsibleTrigger,
21
+ } from '@jsonforms-react-shadcn-ui/collapsible';
22
+ import {
23
+ TooltipProvider,
24
+ Tooltip,
25
+ TooltipContent,
26
+ TooltipTrigger,
27
+ } from '@jsonforms-react-shadcn-ui/tooltip';
28
+ import { ChevronRight, Pencil, Trash2, Eye, EyeOff, X } from 'lucide-react';
29
+ import {
30
+ MixedTreeNode,
31
+ mixedPathKey,
32
+ mixedTreeLabel,
33
+ } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedTree';
34
+
35
+ export const MixedNavigationContext = React.createContext<{
36
+ selectPath: (path: string) => void;
37
+ } | null>(null);
38
+ export const MixedTypeSelector = ({
39
+ clearable = true,
40
+ disabled,
41
+ error,
42
+ onChange,
43
+ types,
44
+ value,
45
+ }: {
46
+ clearable?: boolean;
47
+ disabled: boolean;
48
+ error?: string;
49
+ fullWidth?: boolean;
50
+ required?: boolean;
51
+ onChange: (value: string | undefined) => void;
52
+ types: string[];
53
+ value: string | null;
54
+ }) => {
55
+ const t = useI18n();
56
+ const translateType = useTranslator();
57
+ return (
58
+ <div className='min-w-0'>
59
+ <div className='group relative'>
60
+ <Select
61
+ disabled={disabled}
62
+ value={value ?? ''}
63
+ onValueChange={onChange}
64
+ >
65
+ <SelectTrigger
66
+ className={
67
+ clearable && value && !disabled
68
+ ? 'w-full pr-16 [&>svg]:absolute [&>svg]:right-3'
69
+ : 'w-full'
70
+ }
71
+ aria-label={t('mixed.typeLabel')}
72
+ aria-invalid={!!error}
73
+ >
74
+ <SelectValue placeholder={t('mixed.typePlaceholder')} />
75
+ </SelectTrigger>
76
+ <SelectContent>
77
+ {types.map((type) => (
78
+ <SelectItem
79
+ key={translateType(`mixed.type.${type}`, type)}
80
+ value={type}
81
+ >
82
+ {translateType(`mixed.type.${type}`, type)}
83
+ </SelectItem>
84
+ ))}
85
+ </SelectContent>
86
+ </Select>
87
+ {clearable && value && !disabled && (
88
+ <Button
89
+ type='button'
90
+ variant='ghost'
91
+ size='icon-sm'
92
+ disabled={disabled}
93
+ aria-label={t('mixed.clearType')}
94
+ title={t('mixed.clearType')}
95
+ className='absolute right-7 top-1/2 h-7 w-7 -translate-y-1/2 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 [@media(hover:none)]:opacity-100'
96
+ onPointerDown={(event) => event.preventDefault()}
97
+ onClick={(event) => {
98
+ event.stopPropagation();
99
+ onChange(undefined);
100
+ }}
101
+ >
102
+ <X aria-hidden='true' />
103
+ </Button>
104
+ )}
105
+ </div>
106
+ {error && (
107
+ <div role='alert' className='text-sm text-destructive'>
108
+ {error}
109
+ </div>
110
+ )}
111
+ </div>
112
+ );
113
+ };
114
+ export const NestedMixedNavigation = ({
115
+ label,
116
+ onView,
117
+ selector,
118
+ }: {
119
+ description?: string;
120
+ label?: string;
121
+ onView: () => void;
122
+ selector: React.ReactNode;
123
+ }) => {
124
+ const t = useI18n();
125
+ return (
126
+ <div className='space-y-1'>
127
+ {label && <div>{label}</div>}
128
+ <div className='flex items-center gap-2'>
129
+ {selector}
130
+ <Button
131
+ type='button'
132
+ variant='ghost'
133
+ size='icon-sm'
134
+ aria-label={t('mixed.view', { label: label || t('control.value') })}
135
+ onClick={onView}
136
+ >
137
+ <Eye aria-hidden='true' />
138
+ </Button>
139
+ </div>
140
+ </div>
141
+ );
142
+ };
143
+
144
+ export const MixedTree = (props: MixedTreeProps) => {
145
+ const t = useI18n();
146
+ const [search, setSearch] = useState('');
147
+ const [showPrimitives, setShowPrimitives] = useState(false);
148
+ const [renaming, setRenaming] = useState<MixedTreeNode>();
149
+ const [name, setName] = useState('');
150
+ const error = renaming ? props.validateRename(renaming, name) : undefined;
151
+ const commitRename = () => {
152
+ if (renaming && !error) {
153
+ props.onRename(renaming, name);
154
+ setRenaming(undefined);
155
+ }
156
+ };
157
+ const action = (
158
+ label: string,
159
+ icon: React.ReactNode,
160
+ onClick: () => void,
161
+ hover = false,
162
+ destructive = false,
163
+ ) => (
164
+ <Tooltip>
165
+ <TooltipTrigger asChild>
166
+ <Button
167
+ type='button'
168
+ variant={destructive ? 'destructive' : 'ghost'}
169
+ size='icon-sm'
170
+ aria-label={label}
171
+ className={
172
+ hover
173
+ ? 'shrink-0 opacity-0 group-hover/tree-row:opacity-100 group-focus-within/tree-row:opacity-100 [@media(hover:none)]:opacity-100'
174
+ : 'shrink-0'
175
+ }
176
+ onClick={onClick}
177
+ >
178
+ {icon}
179
+ </Button>
180
+ </TooltipTrigger>
181
+ <TooltipContent>{label}</TooltipContent>
182
+ </Tooltip>
183
+ );
184
+ const match = (node: MixedTreeNode): boolean =>
185
+ mixedTreeLabel(node).toLowerCase().includes(search.toLowerCase()) ||
186
+ node.children.some(match);
187
+ const render = (node: MixedTreeNode): React.ReactNode => {
188
+ const structured = node.type === 'object' || node.type === 'array';
189
+ const selected =
190
+ mixedPathKey(props.selectedPath) === mixedPathKey(node.path);
191
+ if (
192
+ search ? !match(node) : node.path.length && !structured && !showPrimitives
193
+ )
194
+ return null;
195
+ return (
196
+ <Collapsible
197
+ key={mixedPathKey(node.path)}
198
+ defaultOpen={props.domainTree && node.path.length === 0}
199
+ >
200
+ <div className='group/tree-row flex min-w-0 items-center gap-1'>
201
+ {node.children.length > 0 ? (
202
+ <CollapsibleTrigger
203
+ render={<Button type='button' variant='ghost' size='icon-sm' />}
204
+ className='size-8 shrink-0'
205
+ aria-label={t('mixed.expand', { label: mixedTreeLabel(node) })}
206
+ >
207
+ <ChevronRight aria-hidden='true' />
208
+ </CollapsibleTrigger>
209
+ ) : (
210
+ <span aria-hidden='true' className='size-8 shrink-0' />
211
+ )}
212
+ {renaming &&
213
+ mixedPathKey(renaming.path) === mixedPathKey(node.path) ? (
214
+ <div className='flex min-w-0 flex-1 items-start gap-2'>
215
+ <JsonTypeIcon type={node.type} active={selected} />
216
+ <div className='min-w-0 flex-1'>
217
+ <Input
218
+ autoFocus
219
+ aria-label={t('additionalProperties.namePlaceholder')}
220
+ value={name}
221
+ aria-invalid={!!error}
222
+ onChange={(event) => setName(event.target.value)}
223
+ onBlur={commitRename}
224
+ onKeyDown={(event) => {
225
+ if (event.key === 'Enter') {
226
+ event.preventDefault();
227
+ commitRename();
228
+ }
229
+ if (event.key === 'Escape') {
230
+ event.preventDefault();
231
+ setRenaming(undefined);
232
+ }
233
+ }}
234
+ />
235
+ {error && (
236
+ <p
237
+ role='alert'
238
+ className='text-sm text-destructive break-words'
239
+ >
240
+ {error}
241
+ </p>
242
+ )}
243
+ </div>
244
+ </div>
245
+ ) : (
246
+ <Button
247
+ type='button'
248
+ variant={selected ? 'secondary' : 'ghost'}
249
+ className='min-w-0 flex-1 justify-start'
250
+ data-recursive-node={
251
+ props.domainTree ? mixedPathKey(node.path) : undefined
252
+ }
253
+ aria-pressed={selected}
254
+ onClick={() => props.onSelect(node)}
255
+ >
256
+ <JsonTypeIcon type={node.type} active={selected} />
257
+ <span className='truncate'>
258
+ {node.path.length === 0 ? node.label : mixedTreeLabel(node)}
259
+ </span>
260
+ </Button>
261
+ )}
262
+ {props.renderIndicator?.(node)}
263
+ {!props.domainTree &&
264
+ node.path.length === 0 &&
265
+ action(
266
+ t(
267
+ showPrimitives
268
+ ? 'mixed.hidePrimitives'
269
+ : 'mixed.showPrimitives',
270
+ ),
271
+ showPrimitives ? (
272
+ <Eye aria-hidden='true' />
273
+ ) : (
274
+ <EyeOff aria-hidden='true' />
275
+ ),
276
+ () => setShowPrimitives(!showPrimitives),
277
+ )}
278
+ {props.canRename(node) &&
279
+ !renaming &&
280
+ action(
281
+ t('additionalProperties.renameNamed', {
282
+ name: mixedTreeLabel(node),
283
+ }),
284
+ <Pencil aria-hidden='true' />,
285
+ () => {
286
+ setRenaming(node);
287
+ setName(
288
+ props.domainTree
289
+ ? node.label
290
+ : String(node.path[node.path.length - 1]),
291
+ );
292
+ },
293
+ true,
294
+ )}
295
+ {props.canDelete(node) &&
296
+ !renaming &&
297
+ action(
298
+ t('additionalProperties.deleteNamed', {
299
+ name: mixedTreeLabel(node),
300
+ }),
301
+ <Trash2 aria-hidden='true' />,
302
+ () => props.onDelete(node),
303
+ true,
304
+ true,
305
+ )}
306
+ </div>
307
+ <CollapsibleContent keepMounted className='pl-3'>
308
+ {node.children.map(render)}
309
+ </CollapsibleContent>
310
+ </Collapsible>
311
+ );
312
+ };
313
+ return (
314
+ <TooltipProvider>
315
+ <div className='min-w-0 space-y-2 p-1'>
316
+ <Input
317
+ aria-label={t('mixed.searchLabel')}
318
+ placeholder={t('mixed.searchPlaceholder')}
319
+ value={search}
320
+ onChange={(event) => setSearch(event.target.value)}
321
+ />
322
+ <nav aria-label={t('mixed.treeLabel')}>{render(props.root)}</nav>
323
+ </div>
324
+ </TooltipProvider>
325
+ );
326
+ };
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { Button } from '@jsonforms-react-shadcn-ui/button';
3
+ import {
4
+ Dialog,
5
+ DialogContent,
6
+ DialogHeader,
7
+ DialogTitle,
8
+ DialogDescription,
9
+ DialogFooter,
10
+ } from '@jsonforms-react-shadcn-ui/dialog';
11
+ import { useConfirmationState } from '@chobantonov/jsonforms-react-renderer-common/interaction/useConfirmationState';
12
+
13
+ /** Presents the shared destructive-change policy with a shadcn dialog. */
14
+ export const useConfirmation = () => {
15
+ const { t, pending, request, close, confirm, title, message } =
16
+ useConfirmationState();
17
+ const dialog = pending ? (
18
+ <Dialog open onOpenChange={(open) => !open && close()}>
19
+ <DialogContent>
20
+ <DialogHeader>
21
+ <DialogTitle>{title}</DialogTitle>
22
+ <DialogDescription>{message}</DialogDescription>
23
+ </DialogHeader>
24
+ <DialogFooter>
25
+ <Button variant='outline' onClick={close}>
26
+ {t('confirm.decline')}
27
+ </Button>
28
+ <Button onClick={confirm}>{t('confirm.accept')}</Button>
29
+ </DialogFooter>
30
+ </DialogContent>
31
+ </Dialog>
32
+ ) : null;
33
+ return { request, dialog };
34
+ };
@@ -0,0 +1,56 @@
1
+ import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
2
+ import { X } from 'lucide-react';
3
+ import React from 'react';
4
+ import { Button } from '@jsonforms-react-shadcn-ui/button';
5
+
6
+ export interface ClearValueButtonProps {
7
+ clearable?: boolean;
8
+ adornmentAware?: boolean;
9
+ trailingControlSpace?: number;
10
+ data: unknown;
11
+ enabled: boolean;
12
+ onClear: () => void;
13
+ readonly?: boolean;
14
+ }
15
+
16
+ export const hasClearableValue = (data: unknown) =>
17
+ data !== undefined && data !== null && data !== '';
18
+
19
+ export const ClearValueButton = ({
20
+ clearable = true,
21
+ adornmentAware = true,
22
+ trailingControlSpace = 0,
23
+ data,
24
+ enabled,
25
+ onClear,
26
+ readonly,
27
+ }: ClearValueButtonProps) => {
28
+ const t = useI18n();
29
+ if (!clearable || !enabled || readonly || !hasClearableValue(data)) {
30
+ return null;
31
+ }
32
+
33
+ return (
34
+ <Button
35
+ aria-label={t('control.clearValue')}
36
+ className='absolute top-1/2 h-8 w-8 -translate-y-1/2 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100'
37
+ style={{
38
+ insetInlineEnd: adornmentAware
39
+ ? `calc(0.25rem + var(--jf-end-adornment-space, 0px) + ${trailingControlSpace}px)`
40
+ : '0.25rem',
41
+ }}
42
+ onClick={(event) => {
43
+ event.stopPropagation();
44
+ onClear();
45
+ }}
46
+ onMouseDown={(event) => event.preventDefault()}
47
+ onPointerDown={(event) => event.preventDefault()}
48
+ size='icon'
49
+ title={t('control.clearValue')}
50
+ type='button'
51
+ variant='ghost'
52
+ >
53
+ <X className='h-4 w-4' />
54
+ </Button>
55
+ );
56
+ };
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { ScrollArea, ScrollBar } from '@jsonforms-react-shadcn-ui/scroll-area';
3
+
4
+ /** The host supplies upstream themed scrollbars; both axes remain reachable. */
5
+ export const ScrollRegion = ({
6
+ children,
7
+ style,
8
+ className = '',
9
+ ...props
10
+ }: React.ComponentProps<typeof ScrollArea>) => (
11
+ <ScrollArea
12
+ {...props}
13
+ type='auto'
14
+ className={'shadcn-jsonforms-scroll-region ' + className}
15
+ style={{
16
+ display: 'flex',
17
+ flexDirection: 'column',
18
+ minWidth: 0,
19
+ minHeight: 0,
20
+ overflow: 'hidden',
21
+ ...style,
22
+ }}
23
+ >
24
+ {children}
25
+ <ScrollBar orientation='horizontal' />
26
+ </ScrollArea>
27
+ );
@@ -0,0 +1,250 @@
1
+ import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
2
+ import { ChevronDown, ChevronUp } from 'lucide-react';
3
+ import React from 'react';
4
+ import { Button } from '@jsonforms-react-shadcn-ui/button';
5
+ import { Input } from '@jsonforms-react-shadcn-ui/input';
6
+ import { TimeValue, formatTimeValue, parseTimeValue } from '../util/dateTime';
7
+
8
+ export type TimePickerProps = {
9
+ value?: string;
10
+ onChange: (value: string) => void;
11
+ useSeconds?: boolean;
12
+ showHours?: boolean;
13
+ showMinutes?: boolean;
14
+ ampm?: boolean;
15
+ disabled?: boolean;
16
+ isAllowed?: (time: TimeValue) => boolean;
17
+ };
18
+
19
+ type TimePart = 'hours' | 'minutes' | 'seconds';
20
+
21
+ const partActionKeys = {
22
+ hours: {
23
+ increase: 'temporal.increaseHours',
24
+ decrease: 'temporal.decreaseHours',
25
+ },
26
+ minutes: {
27
+ increase: 'temporal.increaseMinutes',
28
+ decrease: 'temporal.decreaseMinutes',
29
+ },
30
+ seconds: {
31
+ increase: 'temporal.increaseSeconds',
32
+ decrease: 'temporal.decreaseSeconds',
33
+ },
34
+ } as const;
35
+
36
+ const emptyTime: TimeValue = { hours: 0, minutes: 0, seconds: 0 };
37
+
38
+ const TimePartInput = ({
39
+ part,
40
+ label,
41
+ displayedValue,
42
+ onValueChange,
43
+ onStep,
44
+ ampm,
45
+ disabled,
46
+ time,
47
+ isAllowed,
48
+ }: {
49
+ part: TimePart;
50
+ label: string;
51
+ displayedValue?: number;
52
+ onValueChange: (value: number) => void;
53
+ onStep: (amount: number) => void;
54
+ ampm: boolean;
55
+ disabled: boolean;
56
+ time?: TimeValue;
57
+ isAllowed?: TimePickerProps['isAllowed'];
58
+ }) => {
59
+ const t = useI18n();
60
+ return (
61
+ <div className='flex flex-col items-center gap-1'>
62
+ <Button
63
+ type='button'
64
+ variant='ghost'
65
+ size='icon'
66
+ disabled={disabled}
67
+ aria-label={t(partActionKeys[part].increase)}
68
+ onClick={() => onStep(1)}
69
+ >
70
+ <ChevronUp className='h-4 w-4' />
71
+ </Button>
72
+ <Input
73
+ type='number'
74
+ inputMode='numeric'
75
+ className='h-12 w-16 appearance-none text-center text-xl font-semibold [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none'
76
+ value={displayedValue ?? ''}
77
+ placeholder='--'
78
+ min={ampm && part === 'hours' ? 1 : 0}
79
+ max={part === 'hours' ? (ampm ? 12 : 23) : 59}
80
+ disabled={disabled}
81
+ aria-label={label}
82
+ aria-invalid={time && isAllowed ? !isAllowed(time) : undefined}
83
+ onChange={(event) => {
84
+ if (event.currentTarget.value !== '') {
85
+ onValueChange(Number(event.currentTarget.value));
86
+ }
87
+ }}
88
+ />
89
+ <Button
90
+ type='button'
91
+ variant='ghost'
92
+ size='icon'
93
+ disabled={disabled}
94
+ aria-label={t(partActionKeys[part].decrease)}
95
+ onClick={() => onStep(-1)}
96
+ >
97
+ <ChevronDown className='h-4 w-4' />
98
+ </Button>
99
+ </div>
100
+ );
101
+ };
102
+
103
+ const TimePeriodButtons = ({
104
+ hours = 0,
105
+ disabled,
106
+ onChange,
107
+ }: {
108
+ hours?: number;
109
+ disabled: boolean;
110
+ onChange: (isPm: boolean) => void;
111
+ }) => {
112
+ const t = useI18n();
113
+ return (
114
+ <div className='ml-2 grid gap-1' aria-label={t('temporal.period')}>
115
+ <Button
116
+ type='button'
117
+ size='sm'
118
+ variant={hours < 12 ? 'default' : 'outline'}
119
+ disabled={disabled}
120
+ onClick={() => onChange(false)}
121
+ >
122
+ {t('temporal.am')}
123
+ </Button>
124
+ <Button
125
+ type='button'
126
+ size='sm'
127
+ variant={hours >= 12 ? 'default' : 'outline'}
128
+ disabled={disabled}
129
+ onClick={() => onChange(true)}
130
+ >
131
+ {t('temporal.pm')}
132
+ </Button>
133
+ </div>
134
+ );
135
+ };
136
+
137
+ const displayHour = (hours: number, ampm: boolean) =>
138
+ ampm ? hours % 12 || 12 : hours;
139
+
140
+ export const TimePicker = ({
141
+ value,
142
+ onChange,
143
+ useSeconds = false,
144
+ showHours = true,
145
+ showMinutes = true,
146
+ ampm = false,
147
+ disabled = false,
148
+ isAllowed,
149
+ }: TimePickerProps) => {
150
+ const t = useI18n();
151
+ const parsedValue = parseTimeValue(value);
152
+ const [time, setTime] = React.useState<TimeValue | undefined>(parsedValue);
153
+
154
+ const [previousValue, setPreviousValue] = React.useState(value);
155
+ if (previousValue !== value) {
156
+ setPreviousValue(value);
157
+ setTime(parsedValue);
158
+ }
159
+
160
+ const commit = (next: TimeValue) => {
161
+ setTime(next);
162
+ if (!isAllowed || isAllowed(next))
163
+ onChange(formatTimeValue(next, useSeconds));
164
+ };
165
+
166
+ const updatePart = (part: TimePart, value: number) => {
167
+ const current = time ?? emptyTime;
168
+ const maximum = part === 'hours' ? 23 : 59;
169
+ commit({ ...current, [part]: Math.max(0, Math.min(maximum, value)) });
170
+ };
171
+
172
+ const stepPart = (part: TimePart, amount: number) => {
173
+ const current = time ?? emptyTime;
174
+ const maximum = part === 'hours' ? 23 : 59;
175
+ const next = (current[part] + amount + maximum + 1) % (maximum + 1);
176
+ commit({ ...current, [part]: next });
177
+ };
178
+
179
+ const displayedHour = time ? displayHour(time.hours, ampm) : undefined;
180
+
181
+ const updateDisplayedHour = (hour: number) => {
182
+ if (!ampm) {
183
+ updatePart('hours', hour);
184
+ return;
185
+ }
186
+ const normalized = Math.max(1, Math.min(12, hour));
187
+ const isPm = (time?.hours ?? 0) >= 12;
188
+ updatePart('hours', (normalized % 12) + (isPm ? 12 : 0));
189
+ };
190
+
191
+ const setPeriod = (isPm: boolean) => {
192
+ const current = time ?? emptyTime;
193
+ const hours = (current.hours % 12) + (isPm ? 12 : 0);
194
+ commit({ ...current, hours });
195
+ };
196
+
197
+ const renderPart = (
198
+ part: TimePart,
199
+ label: string,
200
+ displayedValue: number | undefined,
201
+ onValueChange = (next: number) => updatePart(part, next),
202
+ ) => (
203
+ <TimePartInput
204
+ part={part}
205
+ label={label}
206
+ displayedValue={displayedValue}
207
+ onValueChange={onValueChange}
208
+ onStep={(amount) => stepPart(part, amount)}
209
+ ampm={ampm}
210
+ disabled={disabled}
211
+ time={time}
212
+ isAllowed={isAllowed}
213
+ />
214
+ );
215
+
216
+ return (
217
+ <div
218
+ className='flex items-center justify-center gap-2'
219
+ data-slot='time-picker'
220
+ >
221
+ {showHours &&
222
+ renderPart(
223
+ 'hours',
224
+ t('temporal.hours'),
225
+ displayedHour,
226
+ updateDisplayedHour,
227
+ )}
228
+ {showHours && showMinutes && (
229
+ <span className='select-none text-2xl font-semibold'>:</span>
230
+ )}
231
+ {showMinutes &&
232
+ renderPart('minutes', t('temporal.minutes'), time?.minutes)}
233
+ {useSeconds ? (
234
+ <>
235
+ {(showHours || showMinutes) && (
236
+ <span className='select-none text-2xl font-semibold'>:</span>
237
+ )}
238
+ {renderPart('seconds', t('temporal.seconds'), time?.seconds)}
239
+ </>
240
+ ) : null}
241
+ {ampm && showHours ? (
242
+ <TimePeriodButtons
243
+ hours={time?.hours}
244
+ disabled={disabled}
245
+ onChange={setPeriod}
246
+ />
247
+ ) : null}
248
+ </div>
249
+ );
250
+ };
@@ -0,0 +1,2 @@
1
+ export * from './TimePicker';
2
+ export * from './ClearValueButton';