@contember/create 2.0.0-alpha.10 → 2.0.0-alpha.13
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/filters/enum.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +7 -1
- package/resources/templates/template-workspace/admin/lib/dict.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +5 -4
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +13 -10
- package/resources/templates/template-workspace/admin/lib/form/select.tsx +23 -10
- package/resources/templates/template-workspace/admin/lib/form/ui.tsx +10 -1
- package/resources/templates/template-workspace/admin/lib/select/select.tsx +15 -3
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +8 -6
- package/resources/templates/template-workspace/admin/lib/ui/input.tsx +0 -5
- package/resources/templates/template-workspace/admin/lib/ui/select.tsx +79 -0
- package/resources/templates/template-workspace/admin/package.json +1 -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.13",
|
|
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.13",
|
|
8
8
|
"chalk": "^4.1.2",
|
|
9
9
|
"download-tarball": "^2.0.0",
|
|
10
10
|
"fs-extra": "^11.1.1",
|
|
@@ -82,7 +82,7 @@ const DataGridEnumFilterSelectItem = ({ value, children, filterFactory }: {
|
|
|
82
82
|
const exclude = useCallback(() => setFilter('toggleExclude'), [setFilter])
|
|
83
83
|
const isIncluded = current === 'include'
|
|
84
84
|
|
|
85
|
-
const isExcluded = current
|
|
85
|
+
const isExcluded = current === 'exclude'
|
|
86
86
|
return (
|
|
87
87
|
<DataGridFilterSelectItemUI onExclude={exclude} onInclude={include} isExcluded={isExcluded} isIncluded={isIncluded}>
|
|
88
88
|
{children}
|
|
@@ -145,7 +145,7 @@ const DataGridRelationFilterSelectItem = forwardRef<HTMLButtonElement, {
|
|
|
145
145
|
const exclude = useCallback(() => setFilter('toggleExclude'), [setFilter])
|
|
146
146
|
|
|
147
147
|
const isIncluded = current === 'include'
|
|
148
|
-
const isExcluded = current
|
|
148
|
+
const isExcluded = current === 'exclude'
|
|
149
149
|
|
|
150
150
|
return (
|
|
151
151
|
<DataGridFilterSelectItemUI ref={ref} onExclude={exclude} onInclude={include} isExcluded={isExcluded} isIncluded={isIncluded} {...props}>
|
|
@@ -4,7 +4,7 @@ import { ReactNode } from 'react'
|
|
|
4
4
|
import { DataGridShowFiltersContext } from './filters/mobile'
|
|
5
5
|
import { DataGridToolbarUI } from './ui'
|
|
6
6
|
import { Button } from '../ui/button'
|
|
7
|
-
import { FilterIcon, SettingsIcon } from 'lucide-react'
|
|
7
|
+
import { FilterIcon, RefreshCcwIcon, SettingsIcon } from 'lucide-react'
|
|
8
8
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
|
9
9
|
import { DataGridLayoutSwitcher } from './layout-switcher'
|
|
10
10
|
import { DataGridPerPageSelector } from './pagination'
|
|
@@ -13,6 +13,7 @@ import { dataAttribute } from '@contember/utilities'
|
|
|
13
13
|
import { dict } from '../dict'
|
|
14
14
|
import { DataGridAutoExport } from './export'
|
|
15
15
|
import { DataGridToolbarVisibleElements } from './elements'
|
|
16
|
+
import { DataViewReloadTrigger } from '@contember/react-dataview'
|
|
16
17
|
|
|
17
18
|
export interface DataGridToolbarProps {
|
|
18
19
|
children?: ReactNode
|
|
@@ -51,6 +52,11 @@ export const DataGridToolbar = Component<DataGridToolbarProps>(({ children }) =>
|
|
|
51
52
|
</Popover>
|
|
52
53
|
|
|
53
54
|
<DataGridAutoExport />
|
|
55
|
+
<DataViewReloadTrigger>
|
|
56
|
+
<Button variant={'outline'} size={'sm'} className={'group gap-2'}>
|
|
57
|
+
<RefreshCcwIcon className={'w-4 h-4 group-data-[state=refreshing]:animate-spin '} />
|
|
58
|
+
</Button>
|
|
59
|
+
</DataViewReloadTrigger>
|
|
54
60
|
</div>
|
|
55
61
|
|
|
56
62
|
<div className="flex flex-1 flex-wrap gap-2">
|
|
@@ -10,14 +10,15 @@ export interface FormContainerProps {
|
|
|
10
10
|
description?: ReactNode
|
|
11
11
|
children: ReactNode
|
|
12
12
|
errors?: ReactNode
|
|
13
|
+
required?: boolean
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
export const StandaloneFormContainer = ({ children, description, label, errors }: FormContainerProps) => (
|
|
17
|
+
export const StandaloneFormContainer = ({ children, description, label, errors, required }: FormContainerProps) => (
|
|
17
18
|
<FormContainerUI>
|
|
18
19
|
<FormLabelWrapperUI>
|
|
19
20
|
{label &&
|
|
20
|
-
<FormLabelUI>
|
|
21
|
+
<FormLabelUI required={required}>
|
|
21
22
|
{label}
|
|
22
23
|
</FormLabelUI>
|
|
23
24
|
}
|
|
@@ -34,11 +35,11 @@ export const StandaloneFormContainer = ({ children, description, label, errors }
|
|
|
34
35
|
</FormContainerUI>
|
|
35
36
|
)
|
|
36
37
|
|
|
37
|
-
export const FormContainer = Component(({ children, description, label }: FormContainerProps) => (
|
|
38
|
+
export const FormContainer = Component(({ children, description, label, required }: FormContainerProps) => (
|
|
38
39
|
<FormContainerUI>
|
|
39
40
|
<FormLabelWrapperUI>
|
|
40
41
|
{label && <FormLabel>
|
|
41
|
-
<FormLabelUI>
|
|
42
|
+
<FormLabelUI required={required}>
|
|
42
43
|
{label}
|
|
43
44
|
</FormLabelUI>
|
|
44
45
|
</FormLabel>}
|
|
@@ -19,7 +19,7 @@ export type InputFieldProps =
|
|
|
19
19
|
|
|
20
20
|
export const InputField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue, required }: InputFieldProps) => (
|
|
21
21
|
<FormFieldScope field={field}>
|
|
22
|
-
<FormContainer description={description} label={label}>
|
|
22
|
+
<FormContainer description={description} label={label} required={required}>
|
|
23
23
|
<FormInput field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}>
|
|
24
24
|
<Input required={required} {...(inputProps ?? {})} className={cn('max-w-md', inputProps?.className)} />
|
|
25
25
|
</FormInput>
|
|
@@ -31,14 +31,15 @@ export type TextareaFieldProps =
|
|
|
31
31
|
& Omit<FormInputProps, 'children'>
|
|
32
32
|
& Omit<FormContainerProps, 'children'>
|
|
33
33
|
& {
|
|
34
|
+
required?: boolean
|
|
34
35
|
inputProps?: ComponentProps<typeof TextareaAutosize>
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export const TextareaField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue }: TextareaFieldProps) => (
|
|
38
|
+
export const TextareaField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue, required }: TextareaFieldProps) => (
|
|
38
39
|
<FormFieldScope field={field}>
|
|
39
|
-
<FormContainer description={description} label={label}>
|
|
40
|
+
<FormContainer description={description} label={label} required={required}>
|
|
40
41
|
<FormInput field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}>
|
|
41
|
-
<TextareaAutosize {...(inputProps ?? {})} className={cn('max-w-md', inputProps?.className)} />
|
|
42
|
+
<TextareaAutosize required={required} {...(inputProps ?? {})} className={cn('max-w-md', inputProps?.className)} />
|
|
42
43
|
</FormInput>
|
|
43
44
|
</FormContainer>
|
|
44
45
|
</FormFieldScope>
|
|
@@ -49,18 +50,19 @@ export type CheckboxFieldProps =
|
|
|
49
50
|
& Omit<FormCheckboxProps, 'children'>
|
|
50
51
|
& Omit<FormContainerProps, 'children'>
|
|
51
52
|
& {
|
|
53
|
+
required?: boolean
|
|
52
54
|
inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'>
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
export const CheckboxField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue }: CheckboxFieldProps) => (
|
|
57
|
+
export const CheckboxField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue, required }: CheckboxFieldProps) => (
|
|
56
58
|
<FormFieldScope field={field}>
|
|
57
59
|
<FormContainer description={description} label={undefined}>
|
|
58
60
|
<div className="flex gap-2 items-center">
|
|
59
61
|
<FormCheckbox field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}>
|
|
60
|
-
<CheckboxInput {...inputProps} />
|
|
62
|
+
<CheckboxInput required={required} {...inputProps} />
|
|
61
63
|
</FormCheckbox>
|
|
62
64
|
{label && <FormLabel>
|
|
63
|
-
<FormLabelUI>
|
|
65
|
+
<FormLabelUI required={required}>
|
|
64
66
|
{label}
|
|
65
67
|
</FormLabelUI>
|
|
66
68
|
</FormLabel>}
|
|
@@ -74,20 +76,21 @@ export type RadioEnumFieldProps =
|
|
|
74
76
|
& Omit<FormRadioItemProps, 'children' | 'value'>
|
|
75
77
|
& Omit<FormContainerProps, 'children'>
|
|
76
78
|
& {
|
|
79
|
+
required?: boolean
|
|
77
80
|
options: Record<string, ReactNode>
|
|
78
81
|
orientation?: 'horizontal' | 'vertical'
|
|
79
82
|
inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'>
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
export const RadioEnumField = Component<RadioEnumFieldProps>(({ field, label, description, options, inputProps, orientation, defaultValue, isNonbearing
|
|
85
|
+
export const RadioEnumField = Component<RadioEnumFieldProps>(({ field, label, description, options, inputProps, orientation, defaultValue, isNonbearing, required }) => {
|
|
83
86
|
return (
|
|
84
87
|
<FormFieldScope field={field}>
|
|
85
|
-
<FormContainer description={description} label={label}>
|
|
88
|
+
<FormContainer description={description} label={label} required={required}>
|
|
86
89
|
<div className={'flex flex-wrap gap-3 data-[orientation=vertical]:flex-col'} data-orientation={orientation ?? 'vertical'}>
|
|
87
90
|
{Object.entries(options).map(([value, label]) => (
|
|
88
91
|
<FormLabelUI className="flex gap-2 items-center font-normal" key={value}>
|
|
89
92
|
<FormRadioInput field={field} value={value} defaultValue={defaultValue} isNonbearing={isNonbearing}>
|
|
90
|
-
<RadioInput {...inputProps} />
|
|
93
|
+
<RadioInput required={required} {...inputProps} />
|
|
91
94
|
</FormRadioInput>
|
|
92
95
|
{label}
|
|
93
96
|
</FormLabelUI>
|
|
@@ -15,20 +15,22 @@ import {
|
|
|
15
15
|
import * as React from 'react'
|
|
16
16
|
import { FormContainer, FormContainerProps } from './container'
|
|
17
17
|
import { FormFieldScope, FormHasManyRelationScope, FormHasOneRelationScope, useFormFieldId } from '@contember/react-form'
|
|
18
|
-
import { Component, Field, SugaredRelativeSingleField, useField } from '@contember/interface'
|
|
18
|
+
import { Component, Field, SugaredRelativeSingleField, useEntity, useEntityBeforePersist, useField } from '@contember/interface'
|
|
19
19
|
import { Popover, PopoverTrigger } from '../ui/popover'
|
|
20
20
|
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
|
|
21
|
+
import { useCallback } from 'react'
|
|
22
|
+
import { dict } from '../dict'
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
export type SelectFieldProps =
|
|
24
26
|
& SelectInputProps
|
|
25
27
|
& Omit<FormContainerProps, 'children'>
|
|
26
28
|
|
|
27
|
-
export const SelectField = Component<SelectFieldProps>(({ field, label, description, children, options, queryField, placeholder, createNewForm, errors, initialSorting }) => {
|
|
29
|
+
export const SelectField = Component<SelectFieldProps>(({ field, label, description, children, options, queryField, placeholder, createNewForm, errors, initialSorting, required }) => {
|
|
28
30
|
return (
|
|
29
31
|
<FormHasOneRelationScope field={field}>
|
|
30
|
-
<FormContainer description={description} label={label} errors={errors}>
|
|
31
|
-
<SelectInput field={field} queryField={queryField} options={options} placeholder={placeholder} createNewForm={createNewForm} initialSorting={initialSorting}>
|
|
32
|
+
<FormContainer description={description} label={label} errors={errors} required={required}>
|
|
33
|
+
<SelectInput field={field} queryField={queryField} options={options} placeholder={placeholder} createNewForm={createNewForm} initialSorting={initialSorting} required={required}>
|
|
32
34
|
{children}
|
|
33
35
|
</SelectInput>
|
|
34
36
|
</FormContainer>
|
|
@@ -38,7 +40,7 @@ export const SelectField = Component<SelectFieldProps>(({ field, label, descript
|
|
|
38
40
|
|
|
39
41
|
export type MultiSelectFieldProps =
|
|
40
42
|
& MultiSelectInputProps
|
|
41
|
-
& Omit<FormContainerProps, 'children'>
|
|
43
|
+
& Omit<FormContainerProps, 'children' | 'required'>
|
|
42
44
|
|
|
43
45
|
export const MultiSelectField = Component<MultiSelectFieldProps>(({ field, label, description, children, options, queryField, placeholder, createNewForm, errors, initialSorting }) => {
|
|
44
46
|
return (
|
|
@@ -54,7 +56,7 @@ export const MultiSelectField = Component<MultiSelectFieldProps>(({ field, label
|
|
|
54
56
|
|
|
55
57
|
export type SortableMultiSelectFieldProps =
|
|
56
58
|
& SortableMultiSelectInputProps
|
|
57
|
-
& Omit<FormContainerProps, 'children'>
|
|
59
|
+
& Omit<FormContainerProps, 'children' | 'required'>
|
|
58
60
|
|
|
59
61
|
export const SortableMultiSelectField = Component<SortableMultiSelectFieldProps>(({ field, label, description, children, options, queryField, placeholder, sortableBy, connectAt, createNewForm, errors, initialSorting }) => {
|
|
60
62
|
return (
|
|
@@ -75,14 +77,15 @@ export type SelectEnumFieldProps =
|
|
|
75
77
|
options: Record<string, React.ReactNode>
|
|
76
78
|
placeholder?: React.ReactNode
|
|
77
79
|
defaultValue?: string
|
|
80
|
+
required?: boolean
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
export const SelectEnumField = Component<SelectEnumFieldProps>(
|
|
81
|
-
({ field, label, description, options, placeholder }) => {
|
|
84
|
+
({ field, label, description, options, placeholder, required }) => {
|
|
82
85
|
return (
|
|
83
86
|
<FormFieldScope field={field}>
|
|
84
|
-
<FormContainer description={description} label={label}>
|
|
85
|
-
<SelectEnumFieldInner field={field} options={options} placeholder={placeholder} />
|
|
87
|
+
<FormContainer description={description} label={label} required={required}>
|
|
88
|
+
<SelectEnumFieldInner field={field} options={options} placeholder={placeholder} required={required} />
|
|
86
89
|
</FormContainer>
|
|
87
90
|
</FormFieldScope>
|
|
88
91
|
)
|
|
@@ -91,9 +94,19 @@ export const SelectEnumField = Component<SelectEnumFieldProps>(
|
|
|
91
94
|
'SelectEnumField',
|
|
92
95
|
)
|
|
93
96
|
|
|
94
|
-
const SelectEnumFieldInner = ({ field, options, placeholder }: SelectEnumFieldProps) => {
|
|
97
|
+
const SelectEnumFieldInner = ({ field, options, placeholder, required }: SelectEnumFieldProps) => {
|
|
95
98
|
const [open, setOpen] = React.useState(false)
|
|
96
99
|
const fieldAccessor = useField<string>(field)
|
|
100
|
+
const fieldAccessorGetter = fieldAccessor.getAccessor
|
|
101
|
+
useEntityBeforePersist(useCallback(() => {
|
|
102
|
+
if (!required) {
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
const field = fieldAccessorGetter()
|
|
106
|
+
if (!field.value) {
|
|
107
|
+
field.addError(dict.errors.required)
|
|
108
|
+
}
|
|
109
|
+
}, [fieldAccessorGetter, required]))
|
|
97
110
|
const id = useFormFieldId()
|
|
98
111
|
return (
|
|
99
112
|
<Popover open={open} onOpenChange={setOpen}>
|
|
@@ -2,7 +2,7 @@ import { uic } from '../utils/uic'
|
|
|
2
2
|
import { Label } from '../ui/label'
|
|
3
3
|
|
|
4
4
|
export const FormLayout = uic('div', {
|
|
5
|
-
baseClass: 'flex flex-col gap-2
|
|
5
|
+
baseClass: 'flex flex-col gap-2 mx-4',
|
|
6
6
|
displayName: 'FormLayout',
|
|
7
7
|
})
|
|
8
8
|
|
|
@@ -22,6 +22,15 @@ export const FormLabelWrapperUI = uic('div', {
|
|
|
22
22
|
export const FormLabelUI = uic(Label, {
|
|
23
23
|
baseClass: 'text-left',
|
|
24
24
|
displayName: 'FormLabel',
|
|
25
|
+
variants: {
|
|
26
|
+
required: {
|
|
27
|
+
true: 'after:text-destructive after:content-[attr(data-required-content)] after:ml-1',
|
|
28
|
+
false: '',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
defaultProps: {
|
|
32
|
+
['data-required-content']: '*',
|
|
33
|
+
} as any,
|
|
25
34
|
})
|
|
26
35
|
export const FormContainerUI = uic('div', {
|
|
27
36
|
baseClass: 'flex flex-col gap-2 w-full',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
-
import { ReactNode } from 'react'
|
|
2
|
+
import { ReactNode, useCallback } from 'react'
|
|
3
3
|
import { Popover, PopoverTrigger } from '../ui/popover'
|
|
4
|
-
import { Component, SugaredQualifiedEntityList } from '@contember/interface'
|
|
4
|
+
import { Component, SugaredQualifiedEntityList, useEntity, useEntityBeforePersist } from '@contember/interface'
|
|
5
5
|
import { Button } from '../ui/button'
|
|
6
6
|
import { SugaredRelativeSingleEntity } from '@contember/interface'
|
|
7
7
|
import { ChevronDownIcon, XIcon } from 'lucide-react'
|
|
@@ -12,6 +12,7 @@ import { CreateEntityDialog } from './create-new'
|
|
|
12
12
|
import { SelectDefaultFilter } from './filter'
|
|
13
13
|
import { DataViewSortingDirections, DataViewUnionFilterFields } from '@contember/react-dataview'
|
|
14
14
|
import { useFormFieldId } from '@contember/react-form'
|
|
15
|
+
import { dict } from '../dict'
|
|
15
16
|
|
|
16
17
|
export type SelectInputProps =
|
|
17
18
|
& {
|
|
@@ -22,12 +23,23 @@ export type SelectInputProps =
|
|
|
22
23
|
createNewForm?: ReactNode
|
|
23
24
|
queryField?: DataViewUnionFilterFields
|
|
24
25
|
initialSorting?: DataViewSortingDirections
|
|
26
|
+
required?: boolean
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
export const SelectInput = Component<SelectInputProps>(({ field, queryField, options, children, placeholder, createNewForm, initialSorting }) => {
|
|
30
|
+
export const SelectInput = Component<SelectInputProps>(({ field, queryField, options, children, placeholder, createNewForm, initialSorting, required }) => {
|
|
29
31
|
const [open, setOpen] = React.useState(false)
|
|
30
32
|
const id = useFormFieldId()
|
|
33
|
+
const getEntity = useEntity().getAccessor
|
|
34
|
+
useEntityBeforePersist(useCallback(() => {
|
|
35
|
+
if (!required) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
const entity = getEntity().getEntity({ field })
|
|
39
|
+
if (!entity.existsOnServer && !entity.hasUnpersistedChanges) {
|
|
40
|
+
entity.addError(dict.errors.required)
|
|
41
|
+
}
|
|
42
|
+
}, [field, getEntity, required]))
|
|
31
43
|
|
|
32
44
|
return (
|
|
33
45
|
<Select field={field} onSelect={() => setOpen(false)} options={options}>
|
|
@@ -15,12 +15,14 @@ export const PasswordResetFormFields = ({ hasToken }: { hasToken?: boolean }) =>
|
|
|
15
15
|
form={form} messages={dict.tenant.passwordReset.errorMessages}
|
|
16
16
|
/>
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
{hasToken ? null : (
|
|
19
|
+
<TenantFormField
|
|
20
|
+
form={form} messages={dict.tenant.passwordReset.errorMessages} field="token"
|
|
21
|
+
type="text" required autoComplete="off"
|
|
22
|
+
>
|
|
23
|
+
{dict.tenant.passwordReset.token}
|
|
24
|
+
</TenantFormField>
|
|
25
|
+
)}
|
|
24
26
|
|
|
25
27
|
<TenantFormField
|
|
26
28
|
form={form} messages={dict.tenant.passwordReset.errorMessages} field="password"
|
|
@@ -24,11 +24,6 @@ export const Input = uic('input', {
|
|
|
24
24
|
displayName: 'Input',
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
export const Select = uic('select', {
|
|
28
|
-
baseClass: 'flex w-full h-10 rounded-md p-2 text-sm border border-input bg-background ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[invalid]:border-destructive data-[invalid]:ring-destructive',
|
|
29
|
-
displayName: 'Select',
|
|
30
|
-
})
|
|
31
|
-
|
|
32
27
|
export const InputLike = uic('div', {
|
|
33
28
|
baseClass: `
|
|
34
29
|
flex items-center min-h-10 w-full rounded-md border border-input bg-background p-2 text-sm ring-offset-background max-w-md
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as SelectPrimitive from '@radix-ui/react-select'
|
|
2
|
+
import { Check, ChevronDown, ChevronUp } from 'lucide-react'
|
|
3
|
+
import { uic } from '../utils'
|
|
4
|
+
|
|
5
|
+
export const Select = SelectPrimitive.Root
|
|
6
|
+
|
|
7
|
+
export const SelectGroup = SelectPrimitive.Group
|
|
8
|
+
|
|
9
|
+
export const SelectValue = SelectPrimitive.Value
|
|
10
|
+
|
|
11
|
+
export const SelectTrigger = uic(SelectPrimitive.Trigger, {
|
|
12
|
+
baseClass:
|
|
13
|
+
'flex gap-1 h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
|
|
14
|
+
afterChildren: (
|
|
15
|
+
<SelectPrimitive.Icon asChild>
|
|
16
|
+
<ChevronDown className="h-4 w-4 opacity-50" />
|
|
17
|
+
</SelectPrimitive.Icon>
|
|
18
|
+
),
|
|
19
|
+
displayName: SelectPrimitive.Trigger.displayName,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export const SelectScrollUpButton = uic(SelectPrimitive.ScrollUpButton, {
|
|
23
|
+
baseClass: 'flex cursor-default items-center justify-center py-1',
|
|
24
|
+
beforeChildren: <ChevronUp className="h-4 w-4" />,
|
|
25
|
+
displayName: SelectPrimitive.ScrollUpButton.displayName,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export const SelectScrollDownButton = uic(SelectPrimitive.ScrollDownButton, {
|
|
29
|
+
baseClass: 'flex cursor-default items-center justify-center py-1',
|
|
30
|
+
beforeChildren: <ChevronDown className="h-4 w-4" />,
|
|
31
|
+
displayName: SelectPrimitive.ScrollDownButton.displayName,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
export const SelectContent = uic(SelectPrimitive.Content, {
|
|
35
|
+
baseClass:
|
|
36
|
+
'relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
37
|
+
displayName: SelectPrimitive.Content.displayName,
|
|
38
|
+
variants: {
|
|
39
|
+
position: {
|
|
40
|
+
popper:
|
|
41
|
+
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
defaultVariants: {
|
|
45
|
+
position: 'popper',
|
|
46
|
+
},
|
|
47
|
+
wrapInner: ({ children }) => (
|
|
48
|
+
<>
|
|
49
|
+
<SelectScrollUpButton />
|
|
50
|
+
<SelectPrimitive.Viewport className="p-1 h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]">
|
|
51
|
+
{children}
|
|
52
|
+
</SelectPrimitive.Viewport>
|
|
53
|
+
<SelectScrollDownButton />
|
|
54
|
+
</>
|
|
55
|
+
),
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
export const SelectLabel = uic(SelectPrimitive.Label, {
|
|
59
|
+
baseClass: 'py-1.5 pl-8 pr-2 text-sm font-semibold',
|
|
60
|
+
displayName: SelectPrimitive.Label.displayName,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
export const SelectItem = uic(SelectPrimitive.Item, {
|
|
64
|
+
baseClass:
|
|
65
|
+
'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
66
|
+
beforeChildren: (
|
|
67
|
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
68
|
+
<SelectPrimitive.ItemIndicator>
|
|
69
|
+
<Check className="h-4 w-4" />
|
|
70
|
+
</SelectPrimitive.ItemIndicator>
|
|
71
|
+
</span>
|
|
72
|
+
),
|
|
73
|
+
displayName: SelectPrimitive.Item.displayName,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
export const SelectSeparator = uic(SelectPrimitive.Separator, {
|
|
77
|
+
baseClass: '-mx-1 my-1 h-px bg-muted',
|
|
78
|
+
displayName: SelectPrimitive.Separator.displayName,
|
|
79
|
+
})
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@radix-ui/react-toolbar": "^1.0.4",
|
|
53
53
|
"@radix-ui/react-tooltip": "^1.0.7",
|
|
54
54
|
"class-variance-authority": "^0.7.0",
|
|
55
|
-
"lucide-react": "^0.
|
|
55
|
+
"lucide-react": "^0.416.0",
|
|
56
56
|
"qrcode-generator": "^1.4.4",
|
|
57
57
|
"react": "^18.2.0",
|
|
58
58
|
"react-dom": "^18.2.0",
|