@contember/create 2.0.0-alpha.27 → 2.0.0-alpha.29
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/package.json +2 -2
- package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +24 -10
- package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +24 -23
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/defined.tsx +3 -3
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +51 -23
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +13 -4
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/labels.tsx +22 -0
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +42 -45
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +20 -2
- package/resources/templates/template-workspace/admin/lib/form/select.tsx +10 -3
- package/resources/templates/template-workspace/admin/lib/form/ui.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/form/upload-repeaters.tsx +43 -46
- package/resources/templates/template-workspace/admin/lib/form/upload.tsx +27 -30
- package/resources/templates/template-workspace/admin/lib/labels/enum-labels.ts +9 -0
- package/resources/templates/template-workspace/admin/lib/labels/field-labels.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/labels/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/ui/input.tsx +14 -5
- package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +9 -1
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/create",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": "dist/production/run.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@contember/cli-common": "2.0.0-alpha.
|
|
7
|
+
"@contember/cli-common": "2.0.0-alpha.29",
|
|
8
8
|
"chalk": "^5.3.0",
|
|
9
9
|
"fs-extra": "^11.2.0",
|
|
10
10
|
"js-yaml": "^4.1.0"
|
|
@@ -2,7 +2,17 @@ import * as React from 'react'
|
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
import { DataGridEnumFieldTooltip, DataGridHasManyTooltip, DataGridHasOneTooltip } from './filters'
|
|
4
4
|
import { DataGridTooltipLabel } from './ui'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Component,
|
|
7
|
+
Field,
|
|
8
|
+
FieldView,
|
|
9
|
+
HasMany,
|
|
10
|
+
HasOne,
|
|
11
|
+
SugaredRelativeEntityList,
|
|
12
|
+
SugaredRelativeSingleEntity,
|
|
13
|
+
SugaredRelativeSingleField,
|
|
14
|
+
} from '@contember/interface'
|
|
15
|
+
import { useEnumOptionsFormatter } from '../labels'
|
|
6
16
|
|
|
7
17
|
export type DataGridHasOneCellProps = {
|
|
8
18
|
field: SugaredRelativeSingleEntity['field']
|
|
@@ -47,18 +57,22 @@ export const DataGridHasManyCell = Component(({ field, filterName, children, too
|
|
|
47
57
|
export type DataGridEnumCellProps = {
|
|
48
58
|
field: SugaredRelativeSingleField['field']
|
|
49
59
|
filterName?: string
|
|
50
|
-
options
|
|
60
|
+
options?: Record<string, ReactNode>
|
|
51
61
|
tooltipActions?: ReactNode
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
export const DataGridEnumCell = Component(({ field, options, filterName, tooltipActions }: DataGridEnumCellProps) => {
|
|
65
|
+
const enumOptionsProvider = useEnumOptionsFormatter()
|
|
55
66
|
return (
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
<FieldView<string> field={field} render={it => {
|
|
68
|
+
const resolvedOptions = options ?? enumOptionsProvider(it.schema.enumName!)
|
|
69
|
+
return it.value ? (
|
|
70
|
+
<DataGridEnumFieldTooltip value={it.value} field={field} name={filterName} actions={tooltipActions}>
|
|
71
|
+
<DataGridTooltipLabel>
|
|
72
|
+
{resolvedOptions[it.value]}
|
|
73
|
+
</DataGridTooltipLabel>
|
|
74
|
+
</DataGridEnumFieldTooltip>
|
|
75
|
+
) : null
|
|
76
|
+
}} />
|
|
63
77
|
)
|
|
64
|
-
})
|
|
78
|
+
}, ({ field }) => <Field field={field} />, 'DataGridEnumCell')
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
DataViewTextFilter,
|
|
16
16
|
} from '@contember/react-dataview'
|
|
17
17
|
import { formatBoolean, formatDate, formatDateTime, formatNumber } from '../formatting'
|
|
18
|
-
import { DataGridEnumCell, DataGridHasManyCell,
|
|
18
|
+
import { DataGridEnumCell, DataGridHasManyCell, DataGridHasOneCell } from './cells'
|
|
19
19
|
import { cn } from '../utils'
|
|
20
20
|
import {
|
|
21
21
|
DataGridBooleanFilterControls,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from './filters'
|
|
29
29
|
import { CheckIcon, XIcon } from 'lucide-react'
|
|
30
30
|
import { DataGridIsDefinedFilterControls } from './filters/defined'
|
|
31
|
+
import { DataViewFieldLabel, DataViewHasManyLabel, DataViewHasOneLabel } from './labels'
|
|
31
32
|
|
|
32
33
|
export const DataGridActionColumn = Component<{ children: ReactNode }>(({ children }) => (
|
|
33
34
|
<DataGridColumnLeaf
|
|
@@ -39,7 +40,7 @@ export const DataGridActionColumn = Component<{ children: ReactNode }>(({ childr
|
|
|
39
40
|
|
|
40
41
|
export type DataGridTextColumnProps = {
|
|
41
42
|
field: string
|
|
42
|
-
header
|
|
43
|
+
header?: ReactNode
|
|
43
44
|
children?: ReactNode
|
|
44
45
|
format?: (value: string | null) => ReactNode
|
|
45
46
|
filter?: ReactNode
|
|
@@ -47,7 +48,7 @@ export type DataGridTextColumnProps = {
|
|
|
47
48
|
|
|
48
49
|
export const DataGridTextColumn = Component<DataGridTextColumnProps>(({ field, header, children, format, filter }) => (
|
|
49
50
|
<DataGridColumn
|
|
50
|
-
header={header}
|
|
51
|
+
header={header ?? <DataViewFieldLabel field={field}/>}
|
|
51
52
|
sortingField={field}
|
|
52
53
|
name={field}
|
|
53
54
|
children={children ?? <Field field={field} format={format} />}
|
|
@@ -60,7 +61,7 @@ export const DataGridTextColumn = Component<DataGridTextColumnProps>(({ field, h
|
|
|
60
61
|
|
|
61
62
|
export type DataGridBooleanColumnProps = {
|
|
62
63
|
field: string
|
|
63
|
-
header
|
|
64
|
+
header?: ReactNode
|
|
64
65
|
children?: ReactNode
|
|
65
66
|
format?: (value: boolean | null) => ReactNode
|
|
66
67
|
filter?: ReactNode
|
|
@@ -68,7 +69,7 @@ export type DataGridBooleanColumnProps = {
|
|
|
68
69
|
|
|
69
70
|
export const DataGridBooleanColumn = Component<DataGridBooleanColumnProps>(({ field, header, children, format, filter }) => (
|
|
70
71
|
<DataGridColumn
|
|
71
|
-
header={header}
|
|
72
|
+
header={header ?? <DataViewFieldLabel field={field} />}
|
|
72
73
|
sortingField={field}
|
|
73
74
|
name={field}
|
|
74
75
|
children={children ?? <Field field={field} format={format ?? formatBoolean} />}
|
|
@@ -83,7 +84,7 @@ export const DataGridBooleanColumn = Component<DataGridBooleanColumnProps>(({ fi
|
|
|
83
84
|
|
|
84
85
|
export type DataGridNumberColumnProps = {
|
|
85
86
|
field: string
|
|
86
|
-
header
|
|
87
|
+
header?: ReactNode
|
|
87
88
|
children?: ReactNode
|
|
88
89
|
format?: (value: number | null) => ReactNode
|
|
89
90
|
filter?: ReactNode
|
|
@@ -91,7 +92,7 @@ export type DataGridNumberColumnProps = {
|
|
|
91
92
|
|
|
92
93
|
export const DataGridNumberColumn = Component<DataGridNumberColumnProps>(({ field, header, children, format, filter }) => (
|
|
93
94
|
<DataGridColumn
|
|
94
|
-
header={header}
|
|
95
|
+
header={header ?? <DataViewFieldLabel field={field} />}
|
|
95
96
|
sortingField={field}
|
|
96
97
|
name={field}
|
|
97
98
|
children={children ?? <Field field={field} format={format ?? formatNumber} />}
|
|
@@ -106,7 +107,7 @@ export const DataGridNumberColumn = Component<DataGridNumberColumnProps>(({ fiel
|
|
|
106
107
|
|
|
107
108
|
export type DataGridDateColumnProps = {
|
|
108
109
|
field: string
|
|
109
|
-
header
|
|
110
|
+
header?: ReactNode
|
|
110
111
|
children?: ReactNode
|
|
111
112
|
format?: (value: string | null) => ReactNode
|
|
112
113
|
filter?: ReactNode
|
|
@@ -114,7 +115,7 @@ export type DataGridDateColumnProps = {
|
|
|
114
115
|
|
|
115
116
|
export const DataGridDateColumn = Component<DataGridDateColumnProps>(({ field, header, children, format, filter }) => (
|
|
116
117
|
<DataGridColumn
|
|
117
|
-
header={header}
|
|
118
|
+
header={header ?? <DataViewFieldLabel field={field} />}
|
|
118
119
|
sortingField={field}
|
|
119
120
|
name={field}
|
|
120
121
|
children={children ?? <Field field={field} format={format ?? formatDate} />}
|
|
@@ -130,7 +131,7 @@ export const DataGridDateColumn = Component<DataGridDateColumnProps>(({ field, h
|
|
|
130
131
|
|
|
131
132
|
export type DataGridDateTimeColumnProps = {
|
|
132
133
|
field: string
|
|
133
|
-
header
|
|
134
|
+
header?: ReactNode
|
|
134
135
|
children?: ReactNode
|
|
135
136
|
format?: (value: string | null) => ReactNode
|
|
136
137
|
filter?: ReactNode
|
|
@@ -138,7 +139,7 @@ export type DataGridDateTimeColumnProps = {
|
|
|
138
139
|
|
|
139
140
|
export const DataGridDateTimeColumn = Component<DataGridDateTimeColumnProps>(({ field, header, children, format, filter }) => (
|
|
140
141
|
<DataGridColumn
|
|
141
|
-
header={header}
|
|
142
|
+
header={header ?? <DataViewFieldLabel field={field} />}
|
|
142
143
|
sortingField={field}
|
|
143
144
|
name={field}
|
|
144
145
|
children={children ?? <Field field={field} format={format ?? formatDateTime} />}
|
|
@@ -154,8 +155,8 @@ export const DataGridDateTimeColumn = Component<DataGridDateTimeColumnProps>(({
|
|
|
154
155
|
|
|
155
156
|
export type DataGridEnumColumnProps = {
|
|
156
157
|
field: string
|
|
157
|
-
header
|
|
158
|
-
options
|
|
158
|
+
header?: ReactNode
|
|
159
|
+
options?: Record<string, ReactNode>
|
|
159
160
|
children?: ReactNode
|
|
160
161
|
filter?: ReactNode
|
|
161
162
|
tooltipActions?: ReactNode
|
|
@@ -163,7 +164,7 @@ export type DataGridEnumColumnProps = {
|
|
|
163
164
|
|
|
164
165
|
export const DataGridEnumColumn = Component<DataGridEnumColumnProps>(({ field, header, options, children, tooltipActions, filter }) => (<>
|
|
165
166
|
<DataGridColumn
|
|
166
|
-
header={header}
|
|
167
|
+
header={header ?? <DataViewFieldLabel field={field} />}
|
|
167
168
|
sortingField={field}
|
|
168
169
|
name={field}
|
|
169
170
|
children={children ?? <DataGridEnumCell field={field} options={options} tooltipActions={tooltipActions} />}
|
|
@@ -179,7 +180,7 @@ export const DataGridEnumColumn = Component<DataGridEnumColumnProps>(({ field, h
|
|
|
179
180
|
|
|
180
181
|
export type DataGridIsDefinedColumnProps = {
|
|
181
182
|
field: string
|
|
182
|
-
header
|
|
183
|
+
header?: ReactNode
|
|
183
184
|
children?: ReactNode
|
|
184
185
|
format?: (value: boolean) => ReactNode
|
|
185
186
|
filter?: ReactNode
|
|
@@ -188,7 +189,7 @@ export type DataGridIsDefinedColumnProps = {
|
|
|
188
189
|
|
|
189
190
|
export const DataGridIsDefinedColumn = Component<DataGridIsDefinedColumnProps>(({ field, header, children, format, filter, filterName }) => (
|
|
190
191
|
<DataGridColumn
|
|
191
|
-
header={header}
|
|
192
|
+
header={header ?? <DataViewFieldLabel field={field} />}
|
|
192
193
|
name={field}
|
|
193
194
|
children={children ?? <Field field={field} format={it => {
|
|
194
195
|
if (format) {
|
|
@@ -206,7 +207,7 @@ export const DataGridIsDefinedColumn = Component<DataGridIsDefinedColumnProps>((
|
|
|
206
207
|
|
|
207
208
|
export type DataGridUuidColumnProps = {
|
|
208
209
|
field: string
|
|
209
|
-
header
|
|
210
|
+
header?: ReactNode
|
|
210
211
|
children?: ReactNode
|
|
211
212
|
format?: (value: string | null) => ReactNode
|
|
212
213
|
}
|
|
@@ -214,7 +215,7 @@ export type DataGridUuidColumnProps = {
|
|
|
214
215
|
|
|
215
216
|
export const DataGridUuidColumn = Component<DataGridUuidColumnProps>(({ field, header, children, format }) => (
|
|
216
217
|
<DataGridColumn
|
|
217
|
-
header={header}
|
|
218
|
+
header={header ?? <DataViewFieldLabel field={field} />}
|
|
218
219
|
sortingField={field}
|
|
219
220
|
name={field}
|
|
220
221
|
children={children ?? <Field field={field} format={format} />}
|
|
@@ -225,14 +226,14 @@ export type DataGridHasOneColumnProps = {
|
|
|
225
226
|
field: SugaredRelativeSingleEntity['field']
|
|
226
227
|
filterName?: string
|
|
227
228
|
children: ReactNode
|
|
228
|
-
header
|
|
229
|
+
header?: ReactNode
|
|
229
230
|
filter?: ReactNode
|
|
230
231
|
tooltipActions?: ReactNode
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
export const DataGridHasOneColumn = Component<DataGridHasOneColumnProps>(({ field, header, children, filter, filterName, tooltipActions }) => (
|
|
234
235
|
<DataGridColumn
|
|
235
|
-
header={header}
|
|
236
|
+
header={header ?? <DataViewHasOneLabel field={field} />}
|
|
236
237
|
name={typeof field === 'string' ? field : undefined}
|
|
237
238
|
children={<DataGridHasOneCell field={field} filterName={filterName} tooltipActions={tooltipActions}>{children}</DataGridHasOneCell>}
|
|
238
239
|
filterName={filterName ?? (typeof field === 'string' ? field : undefined)}
|
|
@@ -255,14 +256,14 @@ export type DataGridHasManyColumnProps = {
|
|
|
255
256
|
field: SugaredRelativeEntityList['field']
|
|
256
257
|
filterName?: string
|
|
257
258
|
children: ReactNode
|
|
258
|
-
header
|
|
259
|
+
header?: ReactNode
|
|
259
260
|
filter?: ReactNode
|
|
260
261
|
tooltipActions?: ReactNode
|
|
261
262
|
}
|
|
262
263
|
|
|
263
264
|
export const DataGridHasManyColumn = Component<DataGridHasManyColumnProps>(({ field, header, children, filter, filterName, tooltipActions }) => (
|
|
264
265
|
<DataGridColumn
|
|
265
|
-
header={header}
|
|
266
|
+
header={header ?? <DataViewHasManyLabel field={field} />}
|
|
266
267
|
name={typeof field === 'string' ? field : undefined}
|
|
267
268
|
children={<DataGridHasManyCell field={field} filterName={filterName} tooltipActions={tooltipActions}>{children}</DataGridHasManyCell>}
|
|
268
269
|
filterName={filterName ?? (typeof field === 'string' ? field : undefined)}
|
|
@@ -317,7 +318,7 @@ export const DataGridColumn = Component<DataGridColumnProps>(({ children, header
|
|
|
317
318
|
})
|
|
318
319
|
|
|
319
320
|
export interface DataGridColumnLeafProps {
|
|
320
|
-
header
|
|
321
|
+
header?: ReactNode
|
|
321
322
|
cell: ReactNode
|
|
322
323
|
name?: string
|
|
323
324
|
}
|
|
@@ -9,6 +9,7 @@ import { Button } from '../../ui/button'
|
|
|
9
9
|
import { dict } from '../../dict'
|
|
10
10
|
import { Component } from '@contember/interface'
|
|
11
11
|
import { DataGridFilterMobileHiding } from './mobile'
|
|
12
|
+
import { DataViewFieldLabel } from '../labels'
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
type DataGridBooleanFilterProps =
|
|
@@ -21,7 +22,7 @@ export const DataGridBooleanFilter = Component(({ label, ...props }: DataGridBoo
|
|
|
21
22
|
<DataViewBooleanFilter {...props}>
|
|
22
23
|
<DataGridFilterMobileHiding>
|
|
23
24
|
<DataGridSingleFilterUI>
|
|
24
|
-
<DataGridBooleanFilterSelect label={label} />
|
|
25
|
+
<DataGridBooleanFilterSelect label={label ?? <DataViewFieldLabel field={props.field} />} />
|
|
25
26
|
<DataGridBooleanFilterList />
|
|
26
27
|
</DataGridSingleFilterUI>
|
|
27
28
|
</DataGridFilterMobileHiding>
|
|
@@ -12,6 +12,7 @@ import { DataGridFilterMobileHiding } from './mobile'
|
|
|
12
12
|
import { Button } from '../../ui/button'
|
|
13
13
|
import { Label } from '../../ui/label'
|
|
14
14
|
import { XIcon } from 'lucide-react'
|
|
15
|
+
import { DataViewFieldLabel } from '../labels'
|
|
15
16
|
|
|
16
17
|
export type DataGridDateFilterProps =
|
|
17
18
|
& Omit<DataViewDateFilterProps, 'children'>
|
|
@@ -24,7 +25,7 @@ export const DataGridDateFilter = Component(({ label, ranges, ...props }: DataGr
|
|
|
24
25
|
<DataViewDateFilter {...props}>
|
|
25
26
|
<DataGridFilterMobileHiding>
|
|
26
27
|
<DataGridSingleFilterUI>
|
|
27
|
-
<DataGridDateFilterSelect label={label} ranges={ranges} />
|
|
28
|
+
<DataGridDateFilterSelect label={label ?? <DataViewFieldLabel field={props.field} />} ranges={ranges} />
|
|
28
29
|
<DataGridDateFilterList />
|
|
29
30
|
</DataGridSingleFilterUI>
|
|
30
31
|
</DataGridFilterMobileHiding>
|
|
@@ -2,13 +2,13 @@ import * as React from 'react'
|
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
import { DataViewBooleanFilterProps, DataViewIsDefinedFilter, DataViewNullFilterTrigger } from '@contember/react-dataview'
|
|
4
4
|
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
5
|
-
import {
|
|
5
|
+
import { DataGridFilterSelectTriggerUI, DataGridSingleFilterUI } from '../ui'
|
|
6
6
|
import { dict } from '../../dict'
|
|
7
7
|
import { Component } from '@contember/interface'
|
|
8
8
|
import { DataGridFilterMobileHiding } from './mobile'
|
|
9
9
|
import { CheckIcon, XIcon } from 'lucide-react'
|
|
10
10
|
import { Button } from '../../ui/button'
|
|
11
|
-
import {
|
|
11
|
+
import { DataViewFieldLabel } from '../labels'
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
type DataGridIsDefinedFilterProps =
|
|
@@ -21,7 +21,7 @@ export const DataGridIsDefinedFilter = Component(({ label, ...props }: DataGridI
|
|
|
21
21
|
<DataViewIsDefinedFilter {...props}>
|
|
22
22
|
<DataGridFilterMobileHiding>
|
|
23
23
|
<DataGridSingleFilterUI>
|
|
24
|
-
<DataGridIsDefinedFilterSelect label={label} />
|
|
24
|
+
<DataGridIsDefinedFilterSelect label={label ?? <DataViewFieldLabel field={props.field} />} />
|
|
25
25
|
<DataGridIsDefinedFilterList />
|
|
26
26
|
</DataGridSingleFilterUI>
|
|
27
27
|
</DataGridFilterMobileHiding>
|
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { ReactNode, useCallback } from 'react'
|
|
3
3
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui/tooltip'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DataViewEnumFilter,
|
|
6
|
+
DataViewEnumFilterProps,
|
|
7
|
+
DataViewEnumFilterTrigger,
|
|
8
|
+
DataViewNullFilterTrigger,
|
|
9
|
+
UseDataViewEnumFilter,
|
|
10
|
+
useDataViewEnumFilterArgs,
|
|
11
|
+
useDataViewEnumFilterFactory,
|
|
12
|
+
useDataViewFilterName,
|
|
13
|
+
} from '@contember/react-dataview'
|
|
5
14
|
import { Component } from '@contember/interface'
|
|
6
15
|
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
7
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
DataGridActiveFilterUI,
|
|
18
|
+
DataGridExcludeActionButtonUI,
|
|
19
|
+
DataGridFilterActionButtonUI,
|
|
20
|
+
DataGridFilterSelectItemUI,
|
|
21
|
+
DataGridFilterSelectTriggerUI,
|
|
22
|
+
DataGridSingleFilterUI,
|
|
23
|
+
} from '../ui'
|
|
8
24
|
import { DataGridNullFilter } from './common'
|
|
9
25
|
import { dict } from '../../dict'
|
|
10
26
|
import { DataGridFilterMobileHiding } from './mobile'
|
|
27
|
+
import { useEnumOptionsFormatter } from '../../labels'
|
|
28
|
+
import { DataViewFieldLabel } from '../labels'
|
|
11
29
|
|
|
12
30
|
export type DataGridEnumFilterProps =
|
|
13
31
|
& Omit<DataViewEnumFilterProps, 'children'>
|
|
14
32
|
& {
|
|
15
|
-
options
|
|
33
|
+
options?: Record<string, ReactNode>
|
|
16
34
|
label?: ReactNode
|
|
17
35
|
}
|
|
18
36
|
|
|
@@ -21,7 +39,7 @@ export const DataGridEnumFilter = Component(({ options, label, ...props }: DataG
|
|
|
21
39
|
<DataViewEnumFilter {...props}>
|
|
22
40
|
<DataGridFilterMobileHiding>
|
|
23
41
|
<DataGridSingleFilterUI>
|
|
24
|
-
<DataGridEnumFilterSelect options={options} label={label} />
|
|
42
|
+
<DataGridEnumFilterSelect options={options} label={label ?? <DataViewFieldLabel field={props.field} />} />
|
|
25
43
|
<DataGridEnumFilterList options={options} />
|
|
26
44
|
</DataGridSingleFilterUI>
|
|
27
45
|
</DataGridFilterMobileHiding>
|
|
@@ -53,24 +71,27 @@ export const DataGridEnumFieldTooltip = ({ children, actions, value, ...props }:
|
|
|
53
71
|
|
|
54
72
|
|
|
55
73
|
export const DataGridEnumFilterList = ({ options }: {
|
|
56
|
-
options
|
|
57
|
-
}) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
options?: Record<string, ReactNode>
|
|
75
|
+
}) => {
|
|
76
|
+
const resolvedOptions = useEnumOptions(options)
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
{Object.entries(resolvedOptions).map(([value, label]) => (
|
|
80
|
+
<DataViewEnumFilterTrigger action={'unset'} value={value} key={value}>
|
|
81
|
+
<DataGridActiveFilterUI>
|
|
82
|
+
{label}
|
|
83
|
+
</DataGridActiveFilterUI>
|
|
84
|
+
</DataViewEnumFilterTrigger>
|
|
85
|
+
))}
|
|
86
|
+
|
|
87
|
+
<DataViewNullFilterTrigger action={'unset'}>
|
|
61
88
|
<DataGridActiveFilterUI>
|
|
62
|
-
{
|
|
89
|
+
<span className={'italic'}>{dict.datagrid.na}</span>
|
|
63
90
|
</DataGridActiveFilterUI>
|
|
64
|
-
</
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
<DataGridActiveFilterUI>
|
|
69
|
-
<span className={'italic'}>{dict.datagrid.na}</span>
|
|
70
|
-
</DataGridActiveFilterUI>
|
|
71
|
-
</DataViewNullFilterTrigger>
|
|
72
|
-
</>
|
|
73
|
-
)
|
|
91
|
+
</DataViewNullFilterTrigger>
|
|
92
|
+
</>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
74
95
|
const DataGridEnumFilterSelectItem = ({ value, children, filterFactory }: {
|
|
75
96
|
value: string
|
|
76
97
|
children: ReactNode
|
|
@@ -91,7 +112,7 @@ const DataGridEnumFilterSelectItem = ({ value, children, filterFactory }: {
|
|
|
91
112
|
|
|
92
113
|
}
|
|
93
114
|
export const DataGridEnumFilterSelect = ({ options, label }: {
|
|
94
|
-
options
|
|
115
|
+
options?: Record<string, ReactNode>
|
|
95
116
|
label?: ReactNode
|
|
96
117
|
}) => {
|
|
97
118
|
return (
|
|
@@ -107,12 +128,13 @@ export const DataGridEnumFilterSelect = ({ options, label }: {
|
|
|
107
128
|
}
|
|
108
129
|
|
|
109
130
|
export const DataGridEnumFilterControls = ({ options }: {
|
|
110
|
-
options
|
|
131
|
+
options?: Record<string, ReactNode>
|
|
111
132
|
}) => {
|
|
112
133
|
const filterFactory = useDataViewEnumFilterFactory(useDataViewFilterName())
|
|
134
|
+
const resolvedOptions = useEnumOptions(options)
|
|
113
135
|
return (
|
|
114
136
|
<div className={'relative flex flex-col gap-2'}>
|
|
115
|
-
{Object.entries(
|
|
137
|
+
{Object.entries(resolvedOptions).map(([value, label]) => (
|
|
116
138
|
<DataGridEnumFilterSelectItem value={value} key={value} filterFactory={filterFactory}>
|
|
117
139
|
{label}
|
|
118
140
|
</DataGridEnumFilterSelectItem>
|
|
@@ -121,3 +143,9 @@ export const DataGridEnumFilterControls = ({ options }: {
|
|
|
121
143
|
</div>
|
|
122
144
|
)
|
|
123
145
|
}
|
|
146
|
+
|
|
147
|
+
const useEnumOptions = (preferred: Record<string, ReactNode> | undefined): Record<string, ReactNode> => {
|
|
148
|
+
const enumOptionsProvider = useEnumOptionsFormatter()
|
|
149
|
+
const enumName = useDataViewEnumFilterArgs().enumName
|
|
150
|
+
return preferred ?? enumOptionsProvider(enumName)
|
|
151
|
+
}
|
|
@@ -18,6 +18,7 @@ import { formatNumber } from '../../formatting'
|
|
|
18
18
|
import { dict } from '../../dict'
|
|
19
19
|
import { Component } from '@contember/interface'
|
|
20
20
|
import { DataGridFilterMobileHiding } from './mobile'
|
|
21
|
+
import { DataViewFieldLabel } from '../labels'
|
|
21
22
|
|
|
22
23
|
export type DataGridNumberFilterProps =
|
|
23
24
|
& Omit<DataViewNumberFilterProps, 'children'>
|
|
@@ -29,7 +30,7 @@ export const DataGridNumberFilter = Component(({ label, ...props }: DataGridNumb
|
|
|
29
30
|
<DataViewNumberFilter {...props}>
|
|
30
31
|
<DataGridFilterMobileHiding>
|
|
31
32
|
<DataGridSingleFilterUI>
|
|
32
|
-
<DataGridNumberFilterSelect label={label} />
|
|
33
|
+
<DataGridNumberFilterSelect label={label ?? <DataViewFieldLabel field={props.field} />} />
|
|
33
34
|
<DataGridNumberFilterList />
|
|
34
35
|
</DataGridSingleFilterUI>
|
|
35
36
|
</DataGridFilterMobileHiding>
|
|
@@ -9,18 +9,27 @@ import {
|
|
|
9
9
|
DataViewNullFilterTrigger,
|
|
10
10
|
DataViewRelationFilterList,
|
|
11
11
|
DataViewRelationFilterOptions,
|
|
12
|
-
DataViewRelationFilterTrigger,
|
|
12
|
+
DataViewRelationFilterTrigger,
|
|
13
|
+
DataViewUnionFilterFields,
|
|
13
14
|
useDataViewFilterName,
|
|
14
15
|
useDataViewRelationFilterFactory,
|
|
15
16
|
UseDataViewRelationFilterResult,
|
|
16
17
|
} from '@contember/react-dataview'
|
|
17
18
|
import { Component, EntityId, StaticRender, useEntity } from '@contember/interface'
|
|
18
19
|
import { Popover, PopoverTrigger } from '../../ui/popover'
|
|
19
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
DataGridActiveFilterUI,
|
|
22
|
+
DataGridExcludeActionButtonUI,
|
|
23
|
+
DataGridFilterActionButtonUI,
|
|
24
|
+
DataGridFilterSelectItemUI,
|
|
25
|
+
DataGridFilterSelectTriggerUI,
|
|
26
|
+
DataGridSingleFilterUI,
|
|
27
|
+
} from '../ui'
|
|
20
28
|
import { DataGridNullFilter } from './common'
|
|
21
29
|
import { SelectDefaultFilter, SelectListInner, SelectPopoverContent } from '../../select'
|
|
22
30
|
import { dict } from '../../dict'
|
|
23
31
|
import { DataGridFilterMobileHiding } from './mobile'
|
|
32
|
+
import { DataViewHasManyLabel, DataViewHasOneLabel } from '../labels'
|
|
24
33
|
|
|
25
34
|
|
|
26
35
|
type DataGridRelationFilterInnerProps = {
|
|
@@ -35,7 +44,7 @@ export type DataGridHasOneFilterProps =
|
|
|
35
44
|
export const DataGridHasOneFilter = Component(({ label, children, ...props }: DataGridHasOneFilterProps) => (
|
|
36
45
|
<DataViewHasOneFilter {...props}>
|
|
37
46
|
<DataGridFilterMobileHiding>
|
|
38
|
-
<DataGridRelationFilterInner label={label}>
|
|
47
|
+
<DataGridRelationFilterInner label={label ?? <DataViewHasOneLabel field={props.field} />}>
|
|
39
48
|
{children}
|
|
40
49
|
</DataGridRelationFilterInner>
|
|
41
50
|
</DataGridFilterMobileHiding>
|
|
@@ -50,7 +59,7 @@ export type DataGridHasManyFilterProps =
|
|
|
50
59
|
export const DataGridHasManyFilter = Component(({ label, children, ...props }: DataGridHasManyFilterProps) => (
|
|
51
60
|
<DataViewHasManyFilter {...props} >
|
|
52
61
|
<DataGridFilterMobileHiding>
|
|
53
|
-
<DataGridRelationFilterInner label={label}>
|
|
62
|
+
<DataGridRelationFilterInner label={label ?? <DataViewHasManyLabel field={props.field} />}>
|
|
54
63
|
{children}
|
|
55
64
|
</DataGridRelationFilterInner>
|
|
56
65
|
</DataGridFilterMobileHiding>
|
|
@@ -24,6 +24,7 @@ import { DataGridNullFilter } from './common'
|
|
|
24
24
|
import { dict } from '../../dict'
|
|
25
25
|
import { Component } from '@contember/interface'
|
|
26
26
|
import { DataGridFilterMobileHiding } from './mobile'
|
|
27
|
+
import { DataViewFieldLabel } from '../labels'
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
export type DataGridTextFilterProps =
|
|
@@ -35,7 +36,7 @@ export type DataGridTextFilterProps =
|
|
|
35
36
|
export const DataGridTextFilter = Component(({ label, ...props }: DataGridTextFilterProps) => (
|
|
36
37
|
<DataViewTextFilter {...props}>
|
|
37
38
|
<DataGridFilterMobileHiding>
|
|
38
|
-
<DataGridTextFilterInner label={label} />
|
|
39
|
+
<DataGridTextFilterInner label={label ?? <DataViewFieldLabel field={props.field} />} />
|
|
39
40
|
</DataGridFilterMobileHiding>
|
|
40
41
|
</DataViewTextFilter>
|
|
41
42
|
))
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SugaredRelativeEntityList, SugaredRelativeSingleEntity, SugaredRelativeSingleField } from '@contember/interface'
|
|
2
|
+
import { useDataViewTargetFieldSchema, useDataViewTargetHasManySchema, useDataViewTargetHasOneSchema } from '@contember/react-dataview'
|
|
3
|
+
import { useFieldLabelFormatter } from '../labels'
|
|
4
|
+
|
|
5
|
+
export const DataViewFieldLabel = ({ field }: { field: SugaredRelativeSingleField['field'] }) => {
|
|
6
|
+
const { field: targetField, entity } = useDataViewTargetFieldSchema(field)
|
|
7
|
+
const formatter = useFieldLabelFormatter()
|
|
8
|
+
return <>{formatter(entity.name, targetField.name)}</>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export const DataViewHasOneLabel = ({ field }: { field: SugaredRelativeSingleEntity['field'] }) => {
|
|
13
|
+
const { field: targetField, entity } = useDataViewTargetHasOneSchema(field)
|
|
14
|
+
const formatter = useFieldLabelFormatter()
|
|
15
|
+
return <>{formatter(entity.name, targetField.name)}</>
|
|
16
|
+
}
|
|
17
|
+
export const DataViewHasManyLabel = ({ field }: { field: SugaredRelativeEntityList['field'] }) => {
|
|
18
|
+
const { field: targetField, entity } = useDataViewTargetHasManySchema(field)
|
|
19
|
+
const formatter = useFieldLabelFormatter()
|
|
20
|
+
return <>{formatter(entity.name, targetField.name)}</>
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -2,63 +2,60 @@ import * as React from 'react'
|
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
import { FormContainerUI, FormDescriptionUI, FormErrorUI, FormLabelUI, FormLabelWrapperUI } from './ui'
|
|
4
4
|
import { useErrorFormatter } from '../errors'
|
|
5
|
-
import { Component } from '@contember/interface'
|
|
6
|
-
import { FormError, FormLabel } from '@contember/react-form'
|
|
5
|
+
import { Component, ErrorAccessor } from '@contember/interface'
|
|
6
|
+
import { FormError, FormFieldStateProvider, FormLabel, useFormFieldState } from '@contember/react-form'
|
|
7
|
+
import { useFieldLabelFormatter } from '../labels'
|
|
7
8
|
|
|
8
9
|
export interface FormContainerProps {
|
|
9
10
|
label?: ReactNode
|
|
10
11
|
description?: ReactNode
|
|
11
12
|
children: ReactNode
|
|
12
|
-
errors?: ReactNode
|
|
13
|
+
errors?: ErrorAccessor.Error[] | ReactNode
|
|
13
14
|
required?: boolean
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
</FormLabelUI>
|
|
24
|
-
}
|
|
25
|
-
</FormLabelWrapperUI>
|
|
26
|
-
<div>
|
|
27
|
-
{children}
|
|
28
|
-
</div>
|
|
29
|
-
<div>
|
|
30
|
-
{description && <FormDescriptionUI>
|
|
31
|
-
{description}
|
|
32
|
-
</FormDescriptionUI>}
|
|
33
|
-
{errors}
|
|
34
|
-
</div>
|
|
35
|
-
</FormContainerUI>
|
|
36
|
-
)
|
|
18
|
+
export const FormContainer = Component(({ children, description, label, required, errors }: FormContainerProps) => {
|
|
19
|
+
const errorsNode = Array.isArray(errors) ? undefined : errors
|
|
20
|
+
const errorsList = Array.isArray(errors) ? errors : []
|
|
21
|
+
const state = useFormFieldState()
|
|
22
|
+
const fieldLabelFormatter = useFieldLabelFormatter()
|
|
23
|
+
label ??= state?.field ? fieldLabelFormatter(state.field.entityName, state.field.fieldName) : undefined
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
const inner = <>
|
|
26
|
+
<FormContainerUI>
|
|
27
|
+
<FormLabelWrapperUI>
|
|
28
|
+
{label && <FormLabel>
|
|
29
|
+
<FormLabelUI required={required}>
|
|
30
|
+
{label}
|
|
31
|
+
</FormLabelUI>
|
|
32
|
+
</FormLabel>}
|
|
33
|
+
</FormLabelWrapperUI>
|
|
34
|
+
<div>
|
|
35
|
+
{children}
|
|
36
|
+
</div>
|
|
37
|
+
<div>
|
|
38
|
+
{description && <FormDescriptionUI>
|
|
39
|
+
{description}
|
|
40
|
+
</FormDescriptionUI>}
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
<FormError formatter={useErrorFormatter()}>
|
|
43
|
+
<FormErrorUI />
|
|
44
|
+
</FormError>
|
|
45
|
+
{errorsNode}
|
|
46
|
+
</div>
|
|
47
|
+
</FormContainerUI>
|
|
48
|
+
</>
|
|
49
|
+
return state !== undefined
|
|
50
|
+
? inner
|
|
51
|
+
: <FormFieldStateProvider required={required} errors={errorsList} dirty={false}>{inner}</FormFieldStateProvider>
|
|
52
|
+
}, ({ children, label, description }) => <>
|
|
61
53
|
{label}
|
|
62
54
|
{children}
|
|
63
55
|
{description}
|
|
64
56
|
</>)
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated use `FormContainer` instead
|
|
60
|
+
*/
|
|
61
|
+
export const StandaloneFormContainer = FormContainer
|
|
@@ -4,9 +4,20 @@ import { CheckboxInput, Input, RadioInput } from '../ui/input'
|
|
|
4
4
|
import { cn } from '../utils'
|
|
5
5
|
import { TextareaAutosize } from '../ui/textarea'
|
|
6
6
|
import { FormLabelUI } from './ui'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
FormCheckbox,
|
|
9
|
+
FormCheckboxProps,
|
|
10
|
+
FormFieldScope,
|
|
11
|
+
FormInput,
|
|
12
|
+
FormInputProps,
|
|
13
|
+
FormLabel,
|
|
14
|
+
FormRadioInput,
|
|
15
|
+
FormRadioItemProps,
|
|
16
|
+
useFormFieldState,
|
|
17
|
+
} from '@contember/react-form'
|
|
8
18
|
import { FormContainer, FormContainerProps } from './container'
|
|
9
19
|
import { Component, Field } from '@contember/interface'
|
|
20
|
+
import { useEnumOptionsFormatter } from '../labels'
|
|
10
21
|
|
|
11
22
|
|
|
12
23
|
export type InputFieldProps =
|
|
@@ -77,7 +88,7 @@ export type RadioEnumFieldProps =
|
|
|
77
88
|
& Omit<FormContainerProps, 'children'>
|
|
78
89
|
& {
|
|
79
90
|
required?: boolean
|
|
80
|
-
options
|
|
91
|
+
options?: Record<string, ReactNode> | Array<{ value: null | string | number | boolean; label: React.ReactNode }>
|
|
81
92
|
orientation?: 'horizontal' | 'vertical'
|
|
82
93
|
inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'>
|
|
83
94
|
}
|
|
@@ -95,6 +106,13 @@ export const RadioEnumField = Component<RadioEnumFieldProps>(({ field, label, de
|
|
|
95
106
|
type RadioEnumFieldInnerProps = Pick<RadioEnumFieldProps, 'field' | 'options' | 'orientation' | 'inputProps' | 'defaultValue' | 'isNonbearing' | 'required'>
|
|
96
107
|
|
|
97
108
|
const RadioEnumFieldInner: React.FC<RadioEnumFieldInnerProps> = ({ field, inputProps, isNonbearing, required, options, orientation, defaultValue }) => {
|
|
109
|
+
const enumLabelsFormatter = useEnumOptionsFormatter()
|
|
110
|
+
const enumName = useFormFieldState()?.field?.enumName
|
|
111
|
+
options ??= enumName ? enumLabelsFormatter(enumName) : undefined
|
|
112
|
+
if (!options) {
|
|
113
|
+
throw new Error('RadioEnumField: options are required')
|
|
114
|
+
}
|
|
115
|
+
|
|
98
116
|
const normalizedOptions = React.useMemo(() => {
|
|
99
117
|
return Array.isArray(options) ? options : Object.entries(options).map(([value, label]) => ({ value, label }))
|
|
100
118
|
}, [options])
|
|
@@ -15,12 +15,12 @@ import {
|
|
|
15
15
|
import * as React from 'react'
|
|
16
16
|
import { useCallback, useMemo } from 'react'
|
|
17
17
|
import { FormContainer, FormContainerProps } from './container'
|
|
18
|
-
import { FormFieldScope, FormHasManyRelationScope, FormHasOneRelationScope, useFormFieldId } from '@contember/react-form'
|
|
18
|
+
import { FormFieldScope, FormHasManyRelationScope, FormHasOneRelationScope, useFormFieldId, useFormFieldState } from '@contember/react-form'
|
|
19
19
|
import { Component, Field, RecursionTerminator, SugaredRelativeSingleField, useEntityBeforePersist, useField } from '@contember/interface'
|
|
20
20
|
import { Popover, PopoverTrigger } from '../ui/popover'
|
|
21
21
|
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
|
|
22
22
|
import { dict } from '../dict'
|
|
23
|
-
|
|
23
|
+
import { useEnumOptionsFormatter } from '../labels'
|
|
24
24
|
|
|
25
25
|
export type SelectFieldProps =
|
|
26
26
|
& SelectInputProps
|
|
@@ -78,7 +78,7 @@ export type SelectEnumFieldProps =
|
|
|
78
78
|
& Omit<FormContainerProps, 'children'>
|
|
79
79
|
& {
|
|
80
80
|
field: SugaredRelativeSingleField['field']
|
|
81
|
-
options
|
|
81
|
+
options?: Record<string, React.ReactNode> | { value: null | string | number | boolean; label: React.ReactNode }[]
|
|
82
82
|
placeholder?: React.ReactNode
|
|
83
83
|
defaultValue?: string
|
|
84
84
|
required?: boolean
|
|
@@ -112,6 +112,12 @@ const SelectEnumFieldInner = ({ field, options, placeholder, required }: SelectE
|
|
|
112
112
|
}
|
|
113
113
|
}, [fieldAccessorGetter, required]))
|
|
114
114
|
const id = useFormFieldId()
|
|
115
|
+
const enumLabelsFormatter = useEnumOptionsFormatter()
|
|
116
|
+
const enumName = useFormFieldState()?.field?.enumName
|
|
117
|
+
options ??= enumName ? enumLabelsFormatter(enumName) : undefined
|
|
118
|
+
if (!options) {
|
|
119
|
+
throw new Error('SelectEnumFields: options are required')
|
|
120
|
+
}
|
|
115
121
|
const normalizedOptions = useMemo(() => {
|
|
116
122
|
return Array.isArray(options) ? options : Object.entries(options).map(([value, label]) => ({ value, label }))
|
|
117
123
|
}, [options])
|
|
@@ -119,6 +125,7 @@ const SelectEnumFieldInner = ({ field, options, placeholder, required }: SelectE
|
|
|
119
125
|
return normalizedOptions.find(it => it.value === fieldAccessor.value)
|
|
120
126
|
}, [fieldAccessor.value, normalizedOptions])
|
|
121
127
|
|
|
128
|
+
|
|
122
129
|
return (
|
|
123
130
|
<Popover open={open} onOpenChange={setOpen}>
|
|
124
131
|
<SelectInputWrapperUI>
|
|
@@ -20,7 +20,7 @@ export const FormLabelWrapperUI = uic('div', {
|
|
|
20
20
|
displayName: 'FormLabelWrapper',
|
|
21
21
|
})
|
|
22
22
|
export const FormLabelUI = uic(Label, {
|
|
23
|
-
baseClass: 'text-left',
|
|
23
|
+
baseClass: 'text-left data-[required]:after:text-destructive data-[required]:after:content-[attr(data-required-content)] after:ml-1',
|
|
24
24
|
displayName: 'FormLabel',
|
|
25
25
|
variants: {
|
|
26
26
|
required: {
|
|
@@ -17,7 +17,7 @@ import * as React from 'react'
|
|
|
17
17
|
import { ReactNode, useId, useMemo, useState } from 'react'
|
|
18
18
|
import { FormContainer, FormContainerProps } from './container'
|
|
19
19
|
import { Component } from '@contember/interface'
|
|
20
|
-
import { FormErrorContext, FormFieldIdContext } from '@contember/react-form'
|
|
20
|
+
import { FormErrorContext, FormFieldIdContext, FormFieldStateProvider } from '@contember/react-form'
|
|
21
21
|
import {
|
|
22
22
|
UploadedAnyView,
|
|
23
23
|
UploadedAudioView,
|
|
@@ -134,52 +134,49 @@ const FileRepeaterFieldInner = Component<FileRepeaterFieldInnerProps>(({
|
|
|
134
134
|
// entity,
|
|
135
135
|
// }) ?? []).flatMap(it => it.errors?.errors ?? [])
|
|
136
136
|
|
|
137
|
-
const id = useId()
|
|
138
137
|
return (
|
|
139
|
-
<
|
|
140
|
-
<
|
|
141
|
-
<
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
<
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
<
|
|
155
|
-
<
|
|
156
|
-
|
|
157
|
-
<
|
|
158
|
-
<
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
</FormErrorContext.Provider>
|
|
182
|
-
</FormFieldIdContext.Provider>
|
|
138
|
+
<FormFieldStateProvider>
|
|
139
|
+
<FormContainer description={description} label={label}>
|
|
140
|
+
<Repeater {...props} initialEntityCount={0}>
|
|
141
|
+
<UploaderRepeaterItemsWrapperUI>
|
|
142
|
+
|
|
143
|
+
<MultiUploader baseField={baseField} fileType={fileTypeWithUploader}>
|
|
144
|
+
<UploaderHasFile>
|
|
145
|
+
<UploaderProgress />
|
|
146
|
+
</UploaderHasFile>
|
|
147
|
+
<UploaderDropzone dropzonePlaceholder={dropzonePlaceholder} />
|
|
148
|
+
</MultiUploader>
|
|
149
|
+
|
|
150
|
+
<RepeaterSortable>
|
|
151
|
+
|
|
152
|
+
<RepeaterSortableEachItem>
|
|
153
|
+
<div className="flex">
|
|
154
|
+
<UploaderRepeaterDropIndicator position={'before'} />
|
|
155
|
+
<RepeaterSortableItemNode>
|
|
156
|
+
<UploaderRepeaterItemUI>
|
|
157
|
+
<RepeaterSortableItemActivator>
|
|
158
|
+
<UploaderRepeaterHandleUI />
|
|
159
|
+
</RepeaterSortableItemActivator>
|
|
160
|
+
{children}
|
|
161
|
+
</UploaderRepeaterItemUI>
|
|
162
|
+
</RepeaterSortableItemNode>
|
|
163
|
+
<UploaderRepeaterDropIndicator position={'after'} />
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
</RepeaterSortableEachItem>
|
|
168
|
+
|
|
169
|
+
<RepeaterSortableDragOverlay>
|
|
170
|
+
<UploaderRepeaterDragOverlayUI>
|
|
171
|
+
{children}
|
|
172
|
+
</UploaderRepeaterDragOverlayUI>
|
|
173
|
+
</RepeaterSortableDragOverlay>
|
|
174
|
+
|
|
175
|
+
</RepeaterSortable>
|
|
176
|
+
</UploaderRepeaterItemsWrapperUI>
|
|
177
|
+
</Repeater>
|
|
178
|
+
</FormContainer>
|
|
179
|
+
</FormFieldStateProvider>
|
|
183
180
|
)
|
|
184
181
|
}, ({ baseField, label, description, children, fileType, ...props }) => {
|
|
185
182
|
return <>
|
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
VideoFileTypeProps,
|
|
17
17
|
} from '@contember/react-uploader'
|
|
18
18
|
import * as React from 'react'
|
|
19
|
-
import { ReactNode,
|
|
19
|
+
import { ReactNode, useMemo, useState } from 'react'
|
|
20
20
|
import { FormContainer, FormContainerProps } from './container'
|
|
21
21
|
import { Component, DisconnectEntityTrigger, EntityView, useEntity } from '@contember/interface'
|
|
22
|
-
import {
|
|
22
|
+
import { FormFieldStateProvider } from '@contember/react-form'
|
|
23
23
|
import { UploadedAnyView, UploadedAudioView, UploadedImageView, UploadedVideoView, UploaderDropzone, UploaderItemUI } from '../upload'
|
|
24
24
|
import { UploaderProgress } from '../upload/upload-progress'
|
|
25
25
|
|
|
@@ -106,35 +106,32 @@ const UploadFieldInner = Component((({ baseField, label, description, children,
|
|
|
106
106
|
// entity,
|
|
107
107
|
// }) ?? []).flatMap(it => it.errors?.errors ?? [])
|
|
108
108
|
|
|
109
|
-
const id = useId()
|
|
110
109
|
return (
|
|
111
|
-
<
|
|
112
|
-
<
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<
|
|
117
|
-
<
|
|
118
|
-
<
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
</FormErrorContext.Provider>
|
|
137
|
-
</FormFieldIdContext.Provider>
|
|
110
|
+
<FormFieldStateProvider>
|
|
111
|
+
<FormContainer description={description} label={label}>
|
|
112
|
+
<div className="flex">
|
|
113
|
+
|
|
114
|
+
<Uploader baseField={baseField} fileType={fileTypeWithUploader}>
|
|
115
|
+
<UploaderBase baseField={baseField}>
|
|
116
|
+
<UploaderHasFile>
|
|
117
|
+
<UploaderProgress />
|
|
118
|
+
</UploaderHasFile>
|
|
119
|
+
</UploaderBase>
|
|
120
|
+
|
|
121
|
+
<UploaderItemUI>
|
|
122
|
+
<EntityView render={entity => {
|
|
123
|
+
entity = baseField ? entity.getEntity({ field: baseField }) : entity
|
|
124
|
+
if (entity.getField(urlField).value === null) {
|
|
125
|
+
return <UploaderDropzone inactiveOnUpload dropzonePlaceholder={dropzonePlaceholder} />
|
|
126
|
+
} else {
|
|
127
|
+
return children
|
|
128
|
+
}
|
|
129
|
+
}} />
|
|
130
|
+
</UploaderItemUI>
|
|
131
|
+
</Uploader>
|
|
132
|
+
</div>
|
|
133
|
+
</FormContainer>
|
|
134
|
+
</FormFieldStateProvider>
|
|
138
135
|
)
|
|
139
136
|
}), ({ fileType, children, baseField }) => {
|
|
140
137
|
return <>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SugaredRelativeSingleField, TreeNodeEnvironmentFactory, useEnvironment } from '@contember/interface'
|
|
2
|
+
import { createContext } from '@contember/react-utils'
|
|
3
|
+
import { ReactNode, useMemo } from 'react'
|
|
4
|
+
|
|
5
|
+
export type EnumOptionsFormatter = (enumName: string) => Record<string, ReactNode>
|
|
6
|
+
|
|
7
|
+
export const [, useEnumOptionsFormatter, EnumOptionsFormatterProvider] = createContext<EnumOptionsFormatter>('EnumOptionsFormatterContext', enumName => {
|
|
8
|
+
throw new Error('EnumOptionsFormatterProvider is not provided')
|
|
9
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext } from '@contember/react-utils'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
|
|
4
|
+
export type FieldLabelFormatter = (entityName: string, fieldName: string) => ReactNode | null
|
|
5
|
+
|
|
6
|
+
export const [, useFieldLabelFormatter, FieldLabelFormatterProvider] = createContext<FieldLabelFormatter>('FieldLabelContext', (entityName, fieldName) => null)
|
|
7
|
+
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { uic, uiconfig } from '../utils'
|
|
2
2
|
|
|
3
3
|
export const inputConfig = uiconfig({
|
|
4
|
-
baseClass:
|
|
4
|
+
baseClass: `
|
|
5
|
+
flex w-full bg-background
|
|
6
|
+
file:border-0 file:bg-transparent file:text-sm file:font-medium
|
|
7
|
+
placeholder:text-muted-foreground
|
|
8
|
+
focus-visible:outline-none
|
|
9
|
+
disabled:cursor-not-allowed disabled:opacity-50
|
|
10
|
+
read-only:bg-gray-100
|
|
11
|
+
` /*data-[dirty]:border-yellow-500 focus-visible:data-[dirty]:border-input*/ + `
|
|
12
|
+
data-[invalid]:border-destructive data-[invalid]:ring-destructive
|
|
13
|
+
`,
|
|
5
14
|
variants: {
|
|
6
|
-
variant: {
|
|
7
|
-
default: 'border border-input ring-offset-background focus-visible:ring-2 focus-visible:ring-ring',
|
|
8
|
-
ghost: 'border-none focus-visible:ring-transparent',
|
|
9
|
-
},
|
|
10
15
|
inputSize: {
|
|
11
16
|
default: 'h-10 rounded-md p-2 text-sm',
|
|
12
17
|
sm: 'h-8 rounded p-1 text-sm',
|
|
13
18
|
lg: 'h-12 rounded-lg p-3 text-lg',
|
|
14
19
|
},
|
|
20
|
+
variant: {
|
|
21
|
+
default: 'border border-input ring-offset-background focus-visible:ring-2 focus-visible:ring-ring',
|
|
22
|
+
ghost: 'border-transparent border-b focus-visible:ring-transparent rounded-none',
|
|
23
|
+
},
|
|
15
24
|
},
|
|
16
25
|
defaultVariants: {
|
|
17
26
|
variant: 'default',
|
|
@@ -3,7 +3,15 @@ import { uic } from '../utils'
|
|
|
3
3
|
import { ComponentProps, forwardRef, useRef } from 'react'
|
|
4
4
|
|
|
5
5
|
export const Textarea = uic('textarea', {
|
|
6
|
-
baseClass:
|
|
6
|
+
baseClass: `
|
|
7
|
+
w-full bg-background rounded-md border border-input px-3 py-2 text-sm shadow-sm
|
|
8
|
+
placeholder:text-muted-foreground
|
|
9
|
+
focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring
|
|
10
|
+
disabled:cursor-not-allowed disabled:opacity-50
|
|
11
|
+
read-only:bg-gray-100
|
|
12
|
+
` /*data-[dirty]:border-yellow-500 focus-visible:data-[dirty]:border-input*/ + `
|
|
13
|
+
data-[invalid]:border-destructive data-[invalid]:ring-destructive
|
|
14
|
+
`,
|
|
7
15
|
displayName: 'Textarea',
|
|
8
16
|
})
|
|
9
17
|
|