@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,72 @@
1
+ import isEqual from 'lodash/isEqual';
2
+ import React from 'react';
3
+ import {
4
+ ControlProps,
5
+ OwnPropsOfEnum,
6
+ and,
7
+ isEnumControl,
8
+ optionIs,
9
+ rankWith,
10
+ } from '@jsonforms/core';
11
+ import {
12
+ RadioGroup,
13
+ RadioGroupItem,
14
+ } from '@jsonforms-react-shadcn-ui/radio-group';
15
+ import { InputShell, makeId } from './InputControl';
16
+
17
+ export const ShadcnRadioGroupControl = (
18
+ props: ControlProps & OwnPropsOfEnum,
19
+ ) => {
20
+ if (!props.visible) return null;
21
+ const id = makeId(props.path, props.label);
22
+ const options = props.options ?? [];
23
+ const selected = options.findIndex((option) =>
24
+ isEqual(option.value, props.data),
25
+ );
26
+ const orientation =
27
+ (props.uischema.options?.vertical ??
28
+ props.config?.jsonformsExtended?.radio?.vertical ??
29
+ false) === true
30
+ ? 'vertical'
31
+ : 'horizontal';
32
+ return (
33
+ <InputShell
34
+ {...props}
35
+ id={id}
36
+ label={props.label}
37
+ required={props.required}
38
+ description={props.description}
39
+ errors={props.errors}
40
+ >
41
+ <RadioGroup
42
+ id={id}
43
+ aria-label={props.label}
44
+ orientation={orientation}
45
+ className={
46
+ orientation === 'horizontal' ? 'flex flex-wrap gap-4' : undefined
47
+ }
48
+ value={selected < 0 ? '' : `option-${selected}`}
49
+ disabled={!props.enabled || props.readonly}
50
+ onValueChange={(token) => {
51
+ const option = options[Number(token.replace('option-', ''))];
52
+ if (option) props.handleChange(props.path, option.value);
53
+ }}
54
+ >
55
+ {options.map((option, index) => (
56
+ <label
57
+ key={index}
58
+ className='flex items-center gap-2'
59
+ htmlFor={`${id}-${index}`}
60
+ >
61
+ <RadioGroupItem id={`${id}-${index}`} value={`option-${index}`} />
62
+ {option.label}
63
+ </label>
64
+ ))}
65
+ </RadioGroup>
66
+ </InputShell>
67
+ );
68
+ };
69
+ export const radioGroupControlTester = rankWith(
70
+ 20,
71
+ and(isEnumControl, optionIs('format', 'radio')),
72
+ );
@@ -0,0 +1,77 @@
1
+ import React from 'react';
2
+ import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
3
+ import { ControlProps, isRangeControl, rankWith } from '@jsonforms/core';
4
+ import { Slider } from '@jsonforms-react-shadcn-ui/slider';
5
+ import { InputShell, makeId } from './InputControl';
6
+
7
+ export const ShadcnSliderControl = (props: ControlProps) => {
8
+ const t = useI18n();
9
+ if (!props.visible) return null;
10
+ const id = makeId(props.path, props.label);
11
+ const min = props.schema.minimum ?? 0;
12
+ const max = props.schema.maximum ?? 100;
13
+ const value =
14
+ typeof props.data === 'number' && Number.isFinite(props.data)
15
+ ? props.data
16
+ : undefined;
17
+ const position =
18
+ max > min
19
+ ? Math.max(0, Math.min(100, (((value ?? min) - min) / (max - min)) * 100))
20
+ : 0;
21
+ return (
22
+ <InputShell
23
+ {...props}
24
+ id={id}
25
+ label={props.label}
26
+ required={props.required}
27
+ description={props.description}
28
+ errors={props.errors}
29
+ >
30
+ <div className='flex items-end gap-3'>
31
+ <span
32
+ className='text-sm text-muted-foreground tabular-nums'
33
+ data-slider-min
34
+ >
35
+ {min}
36
+ </span>
37
+ <div className='relative min-w-0 flex-1 pt-9 pb-2'>
38
+ {value !== undefined && (
39
+ <output
40
+ htmlFor={id}
41
+ data-slider-value
42
+ className='absolute top-0 -translate-x-1/2 rounded border bg-background px-2 py-0.5 text-xs tabular-nums shadow-sm'
43
+ style={{ left: `${position}%` }}
44
+ >
45
+ {value}
46
+ </output>
47
+ )}
48
+ <Slider
49
+ id={id}
50
+ aria-label={props.label}
51
+ aria-valuetext={
52
+ value === undefined ? t('control.notSet') : undefined
53
+ }
54
+ min={min}
55
+ max={max}
56
+ step={props.schema.multipleOf ?? 1}
57
+ value={[value ?? min]}
58
+ disabled={!props.enabled || props.readonly}
59
+ onValueChange={([value]) =>
60
+ props.handleChange(
61
+ props.path,
62
+ props.schema.type === 'integer' ? Math.trunc(value) : value,
63
+ )
64
+ }
65
+ />
66
+ </div>
67
+ <span
68
+ className='text-sm text-muted-foreground tabular-nums'
69
+ data-slider-max
70
+ >
71
+ {max}
72
+ </span>
73
+ </div>
74
+ </InputShell>
75
+ );
76
+ };
77
+ export const sliderControlTester = rankWith(4, isRangeControl);
@@ -0,0 +1,50 @@
1
+ import {
2
+ ControlProps,
3
+ isStringControl,
4
+ RankedTester,
5
+ rankWith,
6
+ } from '@jsonforms/core';
7
+ import React from 'react';
8
+ import {
9
+ ShadcnInputControl,
10
+ InputShell,
11
+ makeId,
12
+ toStringValue,
13
+ } from './InputControl';
14
+ import { Textarea } from '@jsonforms-react-shadcn-ui/textarea';
15
+
16
+ export const ShadcnTextControl = (props: ControlProps) => {
17
+ if (!props.visible) return null;
18
+ if (!props.uischema.options?.multi) {
19
+ return <ShadcnInputControl {...props} type='text' />;
20
+ }
21
+ const id = makeId(props.path, props.label);
22
+ return (
23
+ <InputShell
24
+ {...props}
25
+ id={id}
26
+ label={props.label}
27
+ required={props.required}
28
+ description={props.description}
29
+ errors={props.errors}
30
+ >
31
+ <Textarea
32
+ id={id}
33
+ maxLength={
34
+ (props.uischema.options?.restrict ?? props.config?.restrict)
35
+ ? props.schema.maxLength
36
+ : undefined
37
+ }
38
+ value={toStringValue(props.data)}
39
+ disabled={!props.enabled || props.readonly}
40
+ aria-invalid={Boolean(props.errors)}
41
+ aria-describedby={props.errors ? `${id}-errors` : undefined}
42
+ onChange={(event) =>
43
+ props.handleChange(props.path, event.currentTarget.value || undefined)
44
+ }
45
+ />
46
+ </InputShell>
47
+ );
48
+ };
49
+
50
+ export const textControlTester: RankedTester = rankWith(1, isStringControl);
@@ -0,0 +1,135 @@
1
+ import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
2
+ import { useTemporalControl } from '../util/useTemporalControl';
3
+ import {
4
+ ControlProps,
5
+ isTimeControl,
6
+ RankedTester,
7
+ rankWith,
8
+ } from '@jsonforms/core';
9
+ import { Clock3, X } from 'lucide-react';
10
+ import React from 'react';
11
+ import { TimePicker } from '../components/TimePicker';
12
+ import { Button } from '@jsonforms-react-shadcn-ui/button';
13
+ import {
14
+ Popover,
15
+ PopoverContent,
16
+ PopoverTrigger,
17
+ } from '@jsonforms-react-shadcn-ui/popover';
18
+ import { formatTimeValue, parseTimeValue } from '../util/dateTime';
19
+ import { InputShell, makeId } from './InputControl';
20
+
21
+ export const ShadcnTimeControl = (props: ControlProps) => {
22
+ const text = useI18n();
23
+ const {
24
+ data,
25
+ description,
26
+ enabled,
27
+ errors,
28
+ handleChange,
29
+ label,
30
+ path,
31
+ required,
32
+ uischema,
33
+ visible,
34
+ } = props;
35
+ const temporal = useTemporalControl(props, 'time');
36
+ const [open, setOpen] = React.useState(false);
37
+
38
+ if (!visible) return null;
39
+
40
+ const id = makeId(path, label);
41
+ const { selectedTime: selected, ampm, useSeconds, placeholder } = temporal;
42
+
43
+ return (
44
+ <InputShell
45
+ {...props}
46
+ id={id}
47
+ label={label}
48
+ required={required}
49
+ description={description}
50
+ errors={errors}
51
+ >
52
+ <div className='group relative w-full'>
53
+ <Popover open={open} onOpenChange={setOpen}>
54
+ <PopoverTrigger asChild>
55
+ <Button
56
+ id={id}
57
+ type='button'
58
+ variant='outline'
59
+ disabled={!enabled || props.readonly}
60
+ autoFocus={uischema.options?.focus === true}
61
+ aria-invalid={!!errors}
62
+ className='w-full justify-start pr-10 text-left font-normal data-[empty=true]:text-muted-foreground'
63
+ data-empty={!selected}
64
+ >
65
+ <Clock3 className='h-4 w-4' />
66
+ {selected
67
+ ? temporal.displayText
68
+ : typeof data === 'string' && data
69
+ ? data
70
+ : placeholder}
71
+ </Button>
72
+ </PopoverTrigger>
73
+ <PopoverContent align='start' className='w-auto p-4'>
74
+ <TimePicker
75
+ value={
76
+ selected
77
+ ? formatTimeValue(selected, true)
78
+ : typeof data === 'string'
79
+ ? data
80
+ : undefined
81
+ }
82
+ useSeconds={useSeconds}
83
+ showHours={temporal.showHours}
84
+ showMinutes={temporal.showMinutes}
85
+ ampm={ampm}
86
+ disabled={!enabled || props.readonly}
87
+ isAllowed={(time) =>
88
+ temporal.allowed(
89
+ new Date(2000, 0, 1, time.hours, time.minutes, time.seconds),
90
+ )
91
+ }
92
+ onChange={(value) => {
93
+ const time = parseTimeValue(value);
94
+ if (time) {
95
+ const date = new Date(
96
+ 2000,
97
+ 0,
98
+ 1,
99
+ time.hours,
100
+ time.minutes,
101
+ time.seconds,
102
+ );
103
+ temporal.commit(date);
104
+ }
105
+ }}
106
+ />
107
+ <div className='mt-3 flex justify-end'>
108
+ <Button type='button' size='sm' onClick={() => setOpen(false)}>
109
+ {text('control.done')}
110
+ </Button>
111
+ </div>
112
+ </PopoverContent>
113
+ </Popover>
114
+ {selected &&
115
+ enabled &&
116
+ !props.readonly &&
117
+ (uischema.options?.clearable ?? props.config?.clearable ?? true) ? (
118
+ <Button
119
+ type='button'
120
+ variant='ghost'
121
+ size='icon'
122
+ className='absolute end-1 top-1 h-8 w-8 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100'
123
+ aria-label={text('temporal.clearTime')}
124
+ title={text('temporal.clearTime')}
125
+ onClick={() => handleChange(path, undefined)}
126
+ >
127
+ <X className='h-4 w-4' />
128
+ </Button>
129
+ ) : null}
130
+ </div>
131
+ </InputShell>
132
+ );
133
+ };
134
+
135
+ export const timeControlTester: RankedTester = rankWith(4, isTimeControl);
@@ -0,0 +1,19 @@
1
+ export * from './BooleanControl';
2
+ export * from './DateControl';
3
+ export * from './DateTimeControl';
4
+ export * from './EnumControl';
5
+ export * from './InputControl';
6
+ export * from './IntegerControl';
7
+ export * from './NumberControl';
8
+ export * from './TextControl';
9
+ export * from './TimeControl';
10
+
11
+ export * from './OneOfEnumControl';
12
+
13
+ export * from './BooleanToggleControl';
14
+ export * from './RadioGroupControl';
15
+ export * from './SliderControl';
16
+
17
+ export * from './AnyOfStringOrEnumControl';
18
+
19
+ export * from './PasswordControl';
package/src/index.tsx ADDED
@@ -0,0 +1,10 @@
1
+ export * from './renderers';
2
+ export * from './components';
3
+
4
+ export { RowDetailFrame, RowDetailEditButton } from './complex/RowDetailFrame';
5
+
6
+ export { ErrorIndicator } from './complex/ErrorIndicator';
7
+
8
+ export { ArrayPanelToggle } from './complex/ArrayPanelToggle';
9
+
10
+ export { useConfirmation } from './complex/mixed/useConfirmation';
@@ -0,0 +1,248 @@
1
+ import { ContainerValidationIndicator } from './ValidationIndicator';
2
+ import {
3
+ Categorization,
4
+ Category,
5
+ LayoutProps,
6
+ and,
7
+ categorizationHasCategory,
8
+ deriveLabelForUISchemaElement,
9
+ optionIs,
10
+ rankWith,
11
+ uiTypeIs,
12
+ } from '@jsonforms/core';
13
+ import { JsonFormsDispatch, useJsonForms } from '@jsonforms/react';
14
+ import React, { useId } from 'react';
15
+ import { ChevronDown } from 'lucide-react';
16
+ import {
17
+ categoryKey,
18
+ useCategorySelection,
19
+ } from '@chobantonov/jsonforms-react-renderer-common/layout/categoryState';
20
+ import { useGroupState } from '@chobantonov/jsonforms-react-renderer-common/layout/groupState';
21
+ import { useContainerValidation } from '@chobantonov/jsonforms-react-renderer-common/validation/validationIndicator';
22
+ import {
23
+ useI18n,
24
+ useTranslator,
25
+ } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
26
+ import { Button } from '@jsonforms-react-shadcn-ui/button';
27
+ import {
28
+ Tabs,
29
+ TabsContent,
30
+ TabsList,
31
+ TabsTrigger,
32
+ } from '@jsonforms-react-shadcn-ui/tabs';
33
+
34
+ const Indicators = ({
35
+ category,
36
+ path,
37
+ config,
38
+ }: {
39
+ category: Category;
40
+ path: string;
41
+ config: any;
42
+ }) => {
43
+ const group = useGroupState(category, path, config);
44
+ const validation = useContainerValidation(category, path, config, false);
45
+ const t = useI18n();
46
+ return (
47
+ <span className='inline-flex items-center gap-1'>
48
+ {validation.show && (
49
+ <ContainerValidationIndicator count={validation.count} />
50
+ )}
51
+ {group.hasData && (
52
+ <span
53
+ role='img'
54
+ aria-label={t('group.dataIndicator')}
55
+ title={t('group.dataIndicator')}
56
+ data-category-data-indicator
57
+ >
58
+ ●
59
+ </span>
60
+ )}
61
+ </span>
62
+ );
63
+ };
64
+
65
+ /** All presentations share identity, visibility and initial-selection rules. */
66
+ export const ShadcnCategorizationLayout = (props: LayoutProps) => {
67
+ const ctx = useJsonForms();
68
+ const t = useTranslator();
69
+ const text = useI18n();
70
+ const baseId = useId();
71
+ const categorization = props.uischema as Categorization;
72
+ const variant = categorization.options?.variant;
73
+ const options = { ...props.config, ...categorization.options };
74
+ const { categories, active, select, close } = useCategorySelection(
75
+ categorization,
76
+ ctx.core?.data,
77
+ ctx.core?.ajv,
78
+ props.config,
79
+ undefined,
80
+ variant === 'accordion',
81
+ props.path,
82
+ );
83
+ if (!props.visible || categories.length === 0) return null;
84
+ const key = (category: Category, index: number) =>
85
+ categoryKey(category, index);
86
+ const label = (category: Category) =>
87
+ deriveLabelForUISchemaElement(category, t);
88
+ const panel = (category: Category) => (
89
+ <JsonFormsDispatch
90
+ schema={props.schema}
91
+ uischema={{ ...category, type: 'VerticalLayout' }}
92
+ path={props.path}
93
+ enabled={props.enabled}
94
+ renderers={props.renderers}
95
+ cells={props.cells}
96
+ />
97
+ );
98
+ const indicators = (category: Category) => (
99
+ <Indicators category={category} path={props.path} config={props.config} />
100
+ );
101
+
102
+ if (variant === 'accordion')
103
+ return (
104
+ <div className='shadcn-jsonforms-categorization space-y-1'>
105
+ {categories.map((category, index) => {
106
+ const categoryId = `${baseId}-${encodeURIComponent(
107
+ key(category, index),
108
+ )}`;
109
+ const expanded = index === active;
110
+ return (
111
+ <div key={key(category, index)} className='border-b'>
112
+ <h3>
113
+ <Button
114
+ type='button'
115
+ variant='ghost'
116
+ className='h-auto w-full justify-between py-4 text-left'
117
+ id={`${categoryId}-header`}
118
+ aria-expanded={expanded}
119
+ aria-controls={`${categoryId}-panel`}
120
+ onClick={() => (expanded ? close() : select(index))}
121
+ >
122
+ <span>{label(category)}</span>
123
+ <span className='ml-auto flex items-center gap-2'>
124
+ {indicators(category)}
125
+ <ChevronDown
126
+ aria-hidden='true'
127
+ className={expanded ? 'h-4 w-4 rotate-180' : 'h-4 w-4'}
128
+ />
129
+ </span>
130
+ </Button>
131
+ </h3>
132
+ <div
133
+ id={`${categoryId}-panel`}
134
+ role='region'
135
+ aria-labelledby={`${categoryId}-header`}
136
+ hidden={!expanded}
137
+ className='pb-4'
138
+ >
139
+ {panel(category)}
140
+ </div>
141
+ </div>
142
+ );
143
+ })}
144
+ </div>
145
+ );
146
+
147
+ if (variant === 'stepper')
148
+ return (
149
+ <div className='shadcn-jsonforms-categorization space-y-4'>
150
+ <ol
151
+ className={
152
+ options.vertical ? 'flex flex-col gap-2' : 'flex flex-wrap gap-2'
153
+ }
154
+ >
155
+ {categories.map((category, index) => (
156
+ <li key={key(category, index)}>
157
+ <Button
158
+ type='button'
159
+ variant={index === active ? 'default' : 'outline'}
160
+ aria-current={index === active ? 'step' : undefined}
161
+ aria-controls={`${baseId}-step-${index}`}
162
+ id={`${baseId}-step-heading-${index}`}
163
+ onClick={() => select(index)}
164
+ >
165
+ <span aria-hidden='true'>{index + 1}.</span>
166
+ {label(category)}
167
+ {indicators(category)}
168
+ </Button>
169
+ </li>
170
+ ))}
171
+ </ol>
172
+ {categories.map((category, index) => (
173
+ <div
174
+ key={key(category, index)}
175
+ id={`${baseId}-step-${index}`}
176
+ role='region'
177
+ aria-labelledby={`${baseId}-step-heading-${index}`}
178
+ hidden={index !== active}
179
+ >
180
+ {panel(category)}
181
+ </div>
182
+ ))}
183
+ {options.showNavButtons && (
184
+ <div className='flex justify-end gap-2'>
185
+ <Button
186
+ type='button'
187
+ variant='outline'
188
+ disabled={active <= 0}
189
+ onClick={() => select(active - 1)}
190
+ >
191
+ {text('categorization.previous')}
192
+ </Button>
193
+ <Button
194
+ type='button'
195
+ disabled={active < 0 || active >= categories.length - 1}
196
+ onClick={() => select(active + 1)}
197
+ >
198
+ {text('categorization.next')}
199
+ </Button>
200
+ </div>
201
+ )}
202
+ </div>
203
+ );
204
+
205
+ return (
206
+ <Tabs
207
+ className='shadcn-jsonforms-categorization'
208
+ value={String(active)}
209
+ onValueChange={(value) => select(Number(value))}
210
+ >
211
+ <TabsList>
212
+ {categories.map((category, index) => (
213
+ <TabsTrigger key={key(category, index)} value={String(index)}>
214
+ {label(category)}
215
+ {indicators(category)}
216
+ </TabsTrigger>
217
+ ))}
218
+ </TabsList>
219
+ {categories.map((category, index) => (
220
+ <TabsContent
221
+ key={key(category, index)}
222
+ value={String(index)}
223
+ forceMount
224
+ hidden={index !== active}
225
+ >
226
+ {panel(category)}
227
+ </TabsContent>
228
+ ))}
229
+ </Tabs>
230
+ );
231
+ };
232
+ export const categorizationTester = rankWith(1, uiTypeIs('Categorization'));
233
+ export const categorizationAccordionTester = rankWith(
234
+ 3,
235
+ and(
236
+ uiTypeIs('Categorization'),
237
+ categorizationHasCategory,
238
+ optionIs('variant', 'accordion'),
239
+ ),
240
+ );
241
+ export const categorizationStepperTester = rankWith(
242
+ 2,
243
+ and(
244
+ uiTypeIs('Categorization'),
245
+ categorizationHasCategory,
246
+ optionIs('variant', 'stepper'),
247
+ ),
248
+ );