@contember/create 2.0.0-beta.2 → 2.0.0-beta.4
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/grid.tsx +5 -6
- package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +38 -14
- package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +13 -10
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +22 -18
- package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +29 -26
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +5 -8
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +5 -6
- package/resources/templates/template-workspace/admin/lib/form/labels.tsx +8 -0
- package/resources/templates/template-workspace/admin/lib/layout/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout-boxed.tsx +184 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +80 -160
- package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +1 -0
- package/resources/templates/template-workspace/admin/lib/select/ui.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +6 -4
- package/resources/templates/template-workspace/admin/lib/ui/avatar.tsx +42 -0
- package/resources/templates/template-workspace/admin/lib/ui/collapsible.tsx +7 -5
- package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +18 -16
- package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +102 -74
- package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +16 -18
- package/resources/templates/template-workspace/admin/lib/ui/separator.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/ui/sidebar.tsx +560 -0
- package/resources/templates/template-workspace/admin/lib/ui/skeleton.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +4 -5
- package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +2 -3
- package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +1 -2
- package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +40 -6
- package/resources/templates/template-workspace/admin/lib/utils/use-mobile.ts +28 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { dataAttribute } from '@contember/utilities'
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot'
|
|
3
|
+
import { cva } from 'class-variance-authority'
|
|
1
4
|
import { ClassValue, clsx } from 'clsx'
|
|
2
5
|
import * as React from 'react'
|
|
3
6
|
import { ComponentType, ReactElement, ReactNode } from 'react'
|
|
4
|
-
import { Slot } from '@radix-ui/react-slot'
|
|
5
|
-
import { cva } from 'class-variance-authority'
|
|
6
7
|
import { twMerge } from 'tailwind-merge'
|
|
7
8
|
|
|
8
9
|
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T
|
|
@@ -16,32 +17,40 @@ type ConfigVariantsMulti<T extends ConfigSchema | undefined> = T extends ConfigS
|
|
|
16
17
|
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[] | undefined;
|
|
17
18
|
} : {}
|
|
18
19
|
|
|
20
|
+
type DataAttr<T extends ConfigSchema | undefined> = T extends ConfigSchema ? `data-${keyof T & string}` : never
|
|
21
|
+
type DataAttrValue = boolean | string | number | undefined | null
|
|
22
|
+
|
|
19
23
|
type Config<T extends ConfigSchema | undefined, El extends React.ElementType> = {
|
|
20
24
|
baseClass?: ClassValue
|
|
21
25
|
variants?: T
|
|
22
26
|
passVariantProps?: string[]
|
|
23
|
-
defaultProps?: Partial<React.ComponentProps<El
|
|
27
|
+
defaultProps?: Partial<React.ComponentProps<El> & {
|
|
28
|
+
[K in `data-${string}`]?: DataAttrValue
|
|
29
|
+
}>
|
|
24
30
|
defaultVariants?: ConfigVariants<T>
|
|
25
31
|
compoundVariants?: ((ConfigVariants<T> | ConfigVariantsMulti<T>) & { className?: string })[]
|
|
32
|
+
variantsAsDataAttrs?: (keyof ConfigVariants<T>)[]
|
|
26
33
|
displayName?: string
|
|
27
34
|
wrapOuter?: ComponentType<{ children?: ReactNode } & ConfigVariants<T>>
|
|
28
35
|
wrapInner?: ComponentType<{ children?: ReactNode } & ConfigVariants<T>>
|
|
29
36
|
beforeChildren?: ReactElement
|
|
30
37
|
afterChildren?: ReactElement
|
|
38
|
+
style?: React.CSSProperties
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export const uiconfig = <T extends ConfigSchema | undefined>(config: Config<T, ComponentType<{}>>) => config
|
|
34
42
|
|
|
35
43
|
export type NoInfer<T> = T & { [K in keyof T]: T[K] }
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
const falsyToString = (value: any) => typeof value === 'boolean' ? `${value}` : value === 0 ? '0' : value
|
|
46
|
+
export const uic = <El extends React.ElementType, Variants extends ConfigSchema | undefined = undefined>(Component: El, config: Config<Variants, NoInfer<El>>) => {
|
|
38
47
|
const cls = cva<any>(config?.baseClass as any, {
|
|
39
48
|
variants: config?.variants,
|
|
40
49
|
defaultVariants: config?.defaultVariants,
|
|
41
50
|
compoundVariants: config?.compoundVariants,
|
|
42
51
|
})
|
|
43
52
|
|
|
44
|
-
const component =
|
|
53
|
+
const component = React.forwardRef<React.ElementRef<El>, React.ComponentProps<El> & {
|
|
45
54
|
asChild?: boolean
|
|
46
55
|
children?: React.ReactNode
|
|
47
56
|
className?: string
|
|
@@ -53,15 +62,28 @@ export const uic = <El extends React.ElementType, Variants extends ConfigSchema
|
|
|
53
62
|
delete (rest as any)[key]
|
|
54
63
|
}
|
|
55
64
|
}
|
|
65
|
+
|
|
66
|
+
const dataAttrs: Partial<Record<DataAttr<Variants>, DataAttrValue>> = {}
|
|
67
|
+
if (config?.variantsAsDataAttrs && config.variants) {
|
|
68
|
+
for (const key of config.variantsAsDataAttrs) {
|
|
69
|
+
const keyAsString = key.toString()
|
|
70
|
+
const variantValue = rest[key as any] ?? falsyToString(config.defaultVariants?.[key])
|
|
71
|
+
|
|
72
|
+
dataAttrs[`data-${keyAsString}` as DataAttr<Variants>] = dataAttribute(variantValue)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
56
76
|
let Comp: React.ElementType = Component
|
|
57
77
|
if (props.asChild && typeof Component === 'string') {
|
|
58
78
|
Comp = Slot
|
|
59
79
|
delete (rest as any).asChild
|
|
60
80
|
}
|
|
81
|
+
|
|
61
82
|
let children = childrenBase
|
|
62
83
|
if (config?.wrapInner) {
|
|
63
84
|
children = React.createElement(config.wrapInner, props as any, children)
|
|
64
85
|
}
|
|
86
|
+
|
|
65
87
|
if (config?.beforeChildren || config?.afterChildren) {
|
|
66
88
|
children = <>
|
|
67
89
|
{config?.beforeChildren}
|
|
@@ -70,7 +92,19 @@ export const uic = <El extends React.ElementType, Variants extends ConfigSchema
|
|
|
70
92
|
</>
|
|
71
93
|
}
|
|
72
94
|
|
|
73
|
-
const
|
|
95
|
+
const style = config?.style ? { ...config.style, ...(rest.style || {}) } : rest.style
|
|
96
|
+
|
|
97
|
+
const innerEl =
|
|
98
|
+
<Comp
|
|
99
|
+
ref={ref}
|
|
100
|
+
className={twMerge(clsx(cls(props), classNameProp))}
|
|
101
|
+
{...(config.defaultProps ?? {})}
|
|
102
|
+
{...dataAttrs}
|
|
103
|
+
{...rest}
|
|
104
|
+
style={style}
|
|
105
|
+
>
|
|
106
|
+
{children}
|
|
107
|
+
</Comp>
|
|
74
108
|
return config?.wrapOuter ? React.createElement(config.wrapOuter, props as any, innerEl) : innerEl
|
|
75
109
|
})
|
|
76
110
|
component.displayName = config?.displayName
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const MOBILE_BREAKPOINT = 768
|
|
4
|
+
|
|
5
|
+
export const useIsMobile = () => {
|
|
6
|
+
const [isMobile, setIsMobile] = useState(() =>
|
|
7
|
+
typeof window !== 'undefined' ? window.innerWidth < MOBILE_BREAKPOINT : false,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (typeof window === 'undefined') return
|
|
12
|
+
|
|
13
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
|
14
|
+
const onChange = () => setIsMobile(mql.matches)
|
|
15
|
+
|
|
16
|
+
setIsMobile(mql.matches)
|
|
17
|
+
|
|
18
|
+
if (mql.addEventListener) {
|
|
19
|
+
mql.addEventListener('change', onChange)
|
|
20
|
+
return () => mql.removeEventListener('change', onChange)
|
|
21
|
+
} else {
|
|
22
|
+
mql.addListener(onChange)
|
|
23
|
+
return () => mql.removeListener(onChange)
|
|
24
|
+
}
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
return isMobile
|
|
28
|
+
}
|