@cryptlex/web-components 5.1.1 → 5.2.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.
- package/lib/components/data-table/data-table-filter.tsx +220 -0
- package/lib/components/data-table/data-table.tsx +593 -0
- package/lib/components/data-table/table-commons.tsx +233 -0
- package/lib/components/inputs/checkbox.tsx +72 -0
- package/lib/components/inputs/date-picker.tsx +130 -0
- package/lib/components/inputs/datefield.tsx +109 -0
- package/lib/components/inputs/field.tsx +106 -0
- package/lib/components/inputs/id-search.tsx +83 -0
- package/lib/components/inputs/input-otp.tsx +63 -0
- package/lib/components/inputs/multi-select.tsx +62 -0
- package/lib/components/inputs/numberfield.tsx +110 -0
- package/lib/components/inputs/searchfield.tsx +87 -0
- package/lib/components/inputs/select-options.tsx +303 -0
- package/lib/components/inputs/select.tsx +140 -0
- package/lib/components/inputs/textfield.tsx +96 -0
- package/lib/components/key-value-card/key-value-card.tsx +115 -0
- package/lib/components/ui/alert.tsx +32 -0
- package/lib/components/ui/avatar.tsx +22 -0
- package/lib/components/ui/badge.tsx +19 -0
- package/lib/components/ui/breadcrumbs.tsx +104 -0
- package/lib/components/ui/button.tsx +66 -0
- package/lib/components/ui/calendar.tsx +220 -0
- package/lib/components/ui/card.tsx +58 -0
- package/lib/components/ui/dialog.tsx +172 -0
- package/lib/components/ui/disclosure.tsx +113 -0
- package/lib/components/ui/list-box.tsx +86 -0
- package/lib/components/ui/loader.tsx +10 -0
- package/lib/components/ui/menu.tsx +168 -0
- package/lib/components/ui/popover.tsx +37 -0
- package/lib/components/ui/sidebar.tsx +552 -0
- package/lib/components/ui/skeleton.tsx +7 -0
- package/lib/components/ui/sonner.tsx +26 -0
- package/lib/components/ui/table.tsx +79 -0
- package/lib/components/ui/tabs.tsx +82 -0
- package/lib/components/ui/timeline.tsx +52 -0
- package/lib/components/ui/tooltip.tsx +30 -0
- package/lib/tokens.scss +89 -0
- package/lib/utils/form-context.tsx +7 -0
- package/lib/utils/form-hook.tsx +33 -0
- package/lib/utils/primitives.ts +68 -0
- package/lib/utils/resource-names.tsx +245 -0
- package/lib/utils/use-mobile.tsx +21 -0
- package/package.json +28 -38
- package/dist/components/data-table/data-table-filter.es.js +0 -132
- package/dist/components/data-table/data-table-filter.es.js.map +0 -1
- package/dist/components/data-table/data-table.es.js +0 -412
- package/dist/components/data-table/data-table.es.js.map +0 -1
- package/dist/components/data-table/table-commons.es.js +0 -136
- package/dist/components/data-table/table-commons.es.js.map +0 -1
- package/dist/components/inputs/checkbox.es.js +0 -61
- package/dist/components/inputs/checkbox.es.js.map +0 -1
- package/dist/components/inputs/date-picker.es.js +0 -124
- package/dist/components/inputs/date-picker.es.js.map +0 -1
- package/dist/components/inputs/datefield.es.js +0 -90
- package/dist/components/inputs/datefield.es.js.map +0 -1
- package/dist/components/inputs/field.es.js +0 -91
- package/dist/components/inputs/field.es.js.map +0 -1
- package/dist/components/inputs/id-search.es.js +0 -61
- package/dist/components/inputs/id-search.es.js.map +0 -1
- package/dist/components/inputs/input-otp.es.js +0 -60
- package/dist/components/inputs/input-otp.es.js.map +0 -1
- package/dist/components/inputs/multi-select.es.js +0 -47
- package/dist/components/inputs/multi-select.es.js.map +0 -1
- package/dist/components/inputs/numberfield.es.js +0 -101
- package/dist/components/inputs/numberfield.es.js.map +0 -1
- package/dist/components/inputs/searchfield.es.js +0 -80
- package/dist/components/inputs/searchfield.es.js.map +0 -1
- package/dist/components/inputs/select-options.es.js +0 -286
- package/dist/components/inputs/select-options.es.js.map +0 -1
- package/dist/components/inputs/select.es.js +0 -113
- package/dist/components/inputs/select.es.js.map +0 -1
- package/dist/components/inputs/textfield.es.js +0 -86
- package/dist/components/inputs/textfield.es.js.map +0 -1
- package/dist/components/key-value-card/key-value-card.es.js +0 -53
- package/dist/components/key-value-card/key-value-card.es.js.map +0 -1
- package/dist/components/ui/alert.es.js +0 -29
- package/dist/components/ui/alert.es.js.map +0 -1
- package/dist/components/ui/avatar.es.js +0 -19
- package/dist/components/ui/avatar.es.js.map +0 -1
- package/dist/components/ui/badge.es.js +0 -19
- package/dist/components/ui/badge.es.js.map +0 -1
- package/dist/components/ui/breadcrumbs.es.js +0 -104
- package/dist/components/ui/breadcrumbs.es.js.map +0 -1
- package/dist/components/ui/button.es.js +0 -58
- package/dist/components/ui/button.es.js.map +0 -1
- package/dist/components/ui/calendar.es.js +0 -163
- package/dist/components/ui/calendar.es.js.map +0 -1
- package/dist/components/ui/card.es.js +0 -53
- package/dist/components/ui/card.es.js.map +0 -1
- package/dist/components/ui/dialog.es.js +0 -156
- package/dist/components/ui/dialog.es.js.map +0 -1
- package/dist/components/ui/disclosure.es.js +0 -90
- package/dist/components/ui/disclosure.es.js.map +0 -1
- package/dist/components/ui/list-box.es.js +0 -76
- package/dist/components/ui/list-box.es.js.map +0 -1
- package/dist/components/ui/loader.es.js +0 -10
- package/dist/components/ui/loader.es.js.map +0 -1
- package/dist/components/ui/menu.es.js +0 -129
- package/dist/components/ui/menu.es.js.map +0 -1
- package/dist/components/ui/popover.es.js +0 -32
- package/dist/components/ui/popover.es.js.map +0 -1
- package/dist/components/ui/sidebar.es.js +0 -456
- package/dist/components/ui/sidebar.es.js.map +0 -1
- package/dist/components/ui/skeleton.es.js +0 -9
- package/dist/components/ui/skeleton.es.js.map +0 -1
- package/dist/components/ui/sonner.es.js +0 -24
- package/dist/components/ui/sonner.es.js.map +0 -1
- package/dist/components/ui/table.es.js +0 -88
- package/dist/components/ui/table.es.js.map +0 -1
- package/dist/components/ui/tabs.es.js +0 -83
- package/dist/components/ui/tabs.es.js.map +0 -1
- package/dist/components/ui/timeline.es.js +0 -46
- package/dist/components/ui/timeline.es.js.map +0 -1
- package/dist/components/ui/tooltip.es.js +0 -28
- package/dist/components/ui/tooltip.es.js.map +0 -1
- package/dist/index.es.d.ts +0 -861
- package/dist/index.es.js +0 -218
- package/dist/index.es.js.map +0 -1
- package/dist/utils/form-context.es.js +0 -8
- package/dist/utils/form-context.es.js.map +0 -1
- package/dist/utils/form-hook.es.js +0 -30
- package/dist/utils/form-hook.es.js.map +0 -1
- package/dist/utils/primitives.es.js +0 -31
- package/dist/utils/primitives.es.js.map +0 -1
- package/dist/utils/resource-names.es.js +0 -182
- package/dist/utils/resource-names.es.js.map +0 -1
- package/dist/utils/use-mobile.es.js +0 -17
- package/dist/utils/use-mobile.es.js.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Tab as AriaTab,
|
|
3
|
+
TabList as AriaTabList,
|
|
4
|
+
TabListProps as AriaTabListProps,
|
|
5
|
+
TabPanel as AriaTabPanel,
|
|
6
|
+
TabPanelProps as AriaTabPanelProps,
|
|
7
|
+
TabProps as AriaTabProps,
|
|
8
|
+
Tabs as AriaTabs,
|
|
9
|
+
TabsProps as AriaTabsProps,
|
|
10
|
+
composeRenderProps,
|
|
11
|
+
} from "react-aria-components"
|
|
12
|
+
|
|
13
|
+
import { cn } from "lib/utils/primitives"
|
|
14
|
+
|
|
15
|
+
export function Tabs({ className, ...props }: AriaTabsProps) {
|
|
16
|
+
return (
|
|
17
|
+
<AriaTabs
|
|
18
|
+
className={composeRenderProps(className, (className) =>
|
|
19
|
+
cn(
|
|
20
|
+
"group flex flex-col gap-2",
|
|
21
|
+
/* Orientation */
|
|
22
|
+
"data-[orientation=vertical]:flex-row",
|
|
23
|
+
className
|
|
24
|
+
)
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function TabList<T extends object>({
|
|
32
|
+
className,
|
|
33
|
+
...props
|
|
34
|
+
}: AriaTabListProps<T>) {
|
|
35
|
+
return (
|
|
36
|
+
<AriaTabList
|
|
37
|
+
className={composeRenderProps(className, (className) =>
|
|
38
|
+
cn(
|
|
39
|
+
"inline-flex items-center border-b text-muted-foreground",
|
|
40
|
+
/* Orientation */
|
|
41
|
+
"data-[orientation=vertical]:h-auto data-[orientation=vertical]:flex-col",
|
|
42
|
+
className
|
|
43
|
+
)
|
|
44
|
+
)}
|
|
45
|
+
{...props}
|
|
46
|
+
/>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function Tab({ className, ...props }: AriaTabProps) {
|
|
51
|
+
return (
|
|
52
|
+
<AriaTab
|
|
53
|
+
className={composeRenderProps(className, (className) =>
|
|
54
|
+
cn(
|
|
55
|
+
"btn btn-ghost leading-none text-accent h-input truncate inline-flex items-center px-3 body font-medium transition-all",
|
|
56
|
+
/* Selected */
|
|
57
|
+
"data-[selected]:bg-primary/20 data-[selected]:text-primary",
|
|
58
|
+
/* Orientation */
|
|
59
|
+
"group-data-[orientation=vertical]:w-full",
|
|
60
|
+
className
|
|
61
|
+
)
|
|
62
|
+
)}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function TabPanel({ className, ...props }: AriaTabPanelProps) {
|
|
69
|
+
return (
|
|
70
|
+
<AriaTabPanel
|
|
71
|
+
className={composeRenderProps(className, (className) =>
|
|
72
|
+
cn(
|
|
73
|
+
"ring-offset-background",
|
|
74
|
+
/* Focus Visible */
|
|
75
|
+
"focus-ring",
|
|
76
|
+
className
|
|
77
|
+
)
|
|
78
|
+
)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { cn } from "lib/utils/primitives";
|
|
3
|
+
import type { LucideIcon } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
export function Timeline({ className, ...props }: React.ComponentProps<'ol'>) {
|
|
6
|
+
return <ol className={cn("grid grid-col-1 gap-icon", className)} {...props} />
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function TimelineItem({ className, ...props }: React.ComponentProps<'li'> & {}) {
|
|
10
|
+
return (
|
|
11
|
+
<li className={cn("grid grid-cols-[4rem_2rem_1fr] grid-rows-subgrid list-none gap-icon", className)} {...props} />
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const timelineIconVariants = cva(
|
|
16
|
+
`p-1 rounded-full`,
|
|
17
|
+
{
|
|
18
|
+
variants: {
|
|
19
|
+
variant: {
|
|
20
|
+
destructive: "text-destructive-foreground bg-destructive",
|
|
21
|
+
success: "text-success-foreground bg-success",
|
|
22
|
+
muted: "text-muted-foreground bg-muted",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {
|
|
26
|
+
variant: "muted",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export function TimelineIcon({ icon: Icon, className, variant, ...props }: Omit<React.ComponentProps<'div'>, 'children'> & VariantProps<typeof timelineIconVariants> & {
|
|
32
|
+
icon: LucideIcon
|
|
33
|
+
}) {
|
|
34
|
+
return <div {...props} className="flex flex-col items-center gap-2">
|
|
35
|
+
<div className={cn(timelineIconVariants({ variant, className }))}>
|
|
36
|
+
<Icon className="size-icon " />
|
|
37
|
+
</div>
|
|
38
|
+
<div className="h-full w-[1px]" />
|
|
39
|
+
</div>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function TimelineDate({ className, date, dateFormatter, ...props }: Omit<React.ComponentProps<'time'>, 'dateTime' | 'children'> & {
|
|
43
|
+
date: Date
|
|
44
|
+
dateFormatter?: (d: Date) => string;
|
|
45
|
+
}) {
|
|
46
|
+
const defaultDateDisplay = `${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getFullYear()}`;
|
|
47
|
+
return <time {...props} dateTime={date.toISOString()} className={cn("font-mono leading-none text-muted", className)}>{dateFormatter ? dateFormatter(date) : defaultDateDisplay}</time>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function TimelineContent({ className, ...props }: React.ComponentProps<'section'>) {
|
|
51
|
+
return <section className={cn("", className)} {...props} />;
|
|
52
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Tooltip as AriaTooltip,
|
|
3
|
+
TooltipTrigger as AriaTooltipTrigger,
|
|
4
|
+
composeRenderProps,
|
|
5
|
+
type TooltipProps as AriaTooltipProps,
|
|
6
|
+
} from "react-aria-components"
|
|
7
|
+
|
|
8
|
+
import { cn } from "lib/utils/primitives"
|
|
9
|
+
|
|
10
|
+
const TooltipTrigger = AriaTooltipTrigger
|
|
11
|
+
const Tooltip = ({ className, offset = 4, ...props }: AriaTooltipProps) => (
|
|
12
|
+
<AriaTooltip
|
|
13
|
+
offset={offset}
|
|
14
|
+
className={composeRenderProps(className, (className) =>
|
|
15
|
+
cn(
|
|
16
|
+
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0",
|
|
17
|
+
/* Entering */
|
|
18
|
+
"data-[entering]:zoom-in-95",
|
|
19
|
+
/* Exiting */
|
|
20
|
+
"data-[exiting]:animate-out data-[exiting]:fade-out-0 data-[exiting]:zoom-out-95",
|
|
21
|
+
/* Placement */
|
|
22
|
+
"data-[placement=bottom]:slide-in-from-top-2 data-[placement=left]:slide-in-from-right-2 data-[placement=right]:slide-in-from-left-2 data-[placement=top]:slide-in-from-bottom-2",
|
|
23
|
+
className
|
|
24
|
+
)
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
export { Tooltip, TooltipTrigger }
|
package/lib/tokens.scss
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// This file is used to generate the tokens.css file in this project.
|
|
2
|
+
/// Since a single variable is used to determine most swatches and the ramps formulae are repetitive, we use Sass to generate these tokens.
|
|
3
|
+
@mixin generate-variables-for-hue($name, $value) {
|
|
4
|
+
--#{$name}-hue: #{$value};
|
|
5
|
+
|
|
6
|
+
--x#{$name}-1: oklch(0.99 0.01 var(--#{$name}-hue));
|
|
7
|
+
--x#{$name}-2: oklch(0.97 0.03 var(--#{$name}-hue));
|
|
8
|
+
--x#{$name}-3: oklch(0.9 0.04 var(--#{$name}-hue));
|
|
9
|
+
--x#{$name}-4: oklch(0.72 0.13 var(--#{$name}-hue));
|
|
10
|
+
--x#{$name}-5: oklch(0.67 0.13 var(--#{$name}-hue));
|
|
11
|
+
--x#{$name}-6: oklch(0.5 0.13 var(--#{$name}-hue));
|
|
12
|
+
--x#{$name}-7: oklch(0.35 0.13 var(--#{$name}-hue));
|
|
13
|
+
--x#{$name}-8: oklch(0.25 0.13 var(--#{$name}-hue));
|
|
14
|
+
--x#{$name}-9: oklch(0.2 0.09 var(--#{$name}-hue));
|
|
15
|
+
--x#{$name}-10: oklch(0.1 0.03 var(--#{$name}-hue));
|
|
16
|
+
|
|
17
|
+
--#{$name}-1: var(--x#{$name}-1);
|
|
18
|
+
--#{$name}-2: var(--x#{$name}-2);
|
|
19
|
+
--#{$name}-3: var(--x#{$name}-3);
|
|
20
|
+
--#{$name}-4: var(--x#{$name}-4);
|
|
21
|
+
--#{$name}-5: var(--x#{$name}-5);
|
|
22
|
+
--#{$name}-6: var(--x#{$name}-6);
|
|
23
|
+
--#{$name}-7: var(--x#{$name}-7);
|
|
24
|
+
--#{$name}-8: var(--x#{$name}-8);
|
|
25
|
+
--#{$name}-9: var(--x#{$name}-9);
|
|
26
|
+
--#{$name}-10: var(--x#{$name}-10);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Generates CSS variables using OKLCH for a Neutral palette.
|
|
30
|
+
@mixin generate-variables-for-neutral() {
|
|
31
|
+
--neutral-hue: var(--primary-hue);
|
|
32
|
+
--neutral-s: 0.0005;
|
|
33
|
+
|
|
34
|
+
--xneutral-1: oklch(0.985 var(--neutral-s) var(--neutral-hue));
|
|
35
|
+
--xneutral-2: oklch(0.97 var(--neutral-s) var(--neutral-hue));
|
|
36
|
+
--xneutral-3: oklch(0.95 var(--neutral-s) var(--neutral-hue));
|
|
37
|
+
--xneutral-4: oklch(0.87 var(--neutral-s) var(--neutral-hue));
|
|
38
|
+
--xneutral-5: oklch(0.708 var(--neutral-s) var(--neutral-hue));
|
|
39
|
+
--xneutral-6: oklch(0.556 var(--neutral-s) var(--neutral-hue));
|
|
40
|
+
--xneutral-7: oklch(0.439 var(--neutral-s) var(--neutral-hue));
|
|
41
|
+
--xneutral-8: oklch(0.29 var(--neutral-s) var(--neutral-hue));
|
|
42
|
+
--xneutral-9: oklch(0.269 var(--neutral-s) var(--neutral-hue));
|
|
43
|
+
--xneutral-10: oklch(0.205 var(--neutral-s) var(--neutral-hue));
|
|
44
|
+
|
|
45
|
+
--neutral-1: var(--xneutral-1);
|
|
46
|
+
--neutral-2: var(--xneutral-2);
|
|
47
|
+
--neutral-3: var(--xneutral-3);
|
|
48
|
+
--neutral-4: var(--xneutral-4);
|
|
49
|
+
--neutral-5: var(--xneutral-5);
|
|
50
|
+
--neutral-6: var(--xneutral-6);
|
|
51
|
+
--neutral-7: var(--xneutral-7);
|
|
52
|
+
--neutral-8: var(--xneutral-8);
|
|
53
|
+
--neutral-9: var(--xneutral-9);
|
|
54
|
+
--neutral-10: var(--xneutral-10);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Swap Swatch 1 & Swatch 10, Swatch 2 and Swatch 9, and so on.
|
|
58
|
+
@mixin generate-dark-mode($name) {
|
|
59
|
+
--#{$name}-1: var(--x#{$name}-10);
|
|
60
|
+
--#{$name}-2: var(--x#{$name}-9);
|
|
61
|
+
--#{$name}-3: var(--x#{$name}-8);
|
|
62
|
+
--#{$name}-4: var(--x#{$name}-7);
|
|
63
|
+
--#{$name}-5: var(--x#{$name}-6);
|
|
64
|
+
--#{$name}-6: var(--x#{$name}-5);
|
|
65
|
+
--#{$name}-7: var(--x#{$name}-4);
|
|
66
|
+
--#{$name}-8: var(--x#{$name}-3);
|
|
67
|
+
--#{$name}-9: var(--x#{$name}-2);
|
|
68
|
+
--#{$name}-10: var(--x#{$name}-1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*!
|
|
72
|
+
This CSS is generated by tokens.scss, do not modify directly.
|
|
73
|
+
Instead, compile the SCSS file again to create modifications.
|
|
74
|
+
*/
|
|
75
|
+
:root {
|
|
76
|
+
@include generate-variables-for-hue(primary, 240);
|
|
77
|
+
@include generate-variables-for-hue(secondary, calc(var(--primary-hue) + 30));
|
|
78
|
+
@include generate-variables-for-hue(destructive, calc(var(--primary-hue) - 230));
|
|
79
|
+
@include generate-variables-for-hue(success, calc(var(--primary-hue) - 90));
|
|
80
|
+
@include generate-variables-for-neutral();
|
|
81
|
+
|
|
82
|
+
@media (prefers-color-scheme: dark) {
|
|
83
|
+
@include generate-dark-mode(primary);
|
|
84
|
+
@include generate-dark-mode(secondary);
|
|
85
|
+
@include generate-dark-mode(destructive);
|
|
86
|
+
@include generate-dark-mode(success);
|
|
87
|
+
@include generate-dark-mode(neutral);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createFormHook, type FieldApi } from "@tanstack/react-form";
|
|
2
|
+
import { TfCheckbox } from "lib/components/inputs/checkbox";
|
|
3
|
+
import { TfMultiSelect } from "lib/components/inputs/multi-select";
|
|
4
|
+
import { TfNumberField } from "lib/components/inputs/numberfield";
|
|
5
|
+
import { TfSingleSelect } from "lib/components/inputs/select";
|
|
6
|
+
import { TfTextField } from "lib/components/inputs/textfield";
|
|
7
|
+
import { Button } from "lib/components/ui/button";
|
|
8
|
+
import { fieldContext, formContext } from "lib/utils/form-context";
|
|
9
|
+
|
|
10
|
+
export function getFieldErrorMessage(field: FieldApi<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>): string {
|
|
11
|
+
return field?.state.meta.errors.map((e) => e?.message).join(",")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Don't put this in the same file as form-context.tsx, this causes circular dependencies. */
|
|
15
|
+
|
|
16
|
+
/** TODO, lazy loading when fieldComponents are large */
|
|
17
|
+
/**
|
|
18
|
+
* Builder for form logic and user interfaces
|
|
19
|
+
*/
|
|
20
|
+
export const { useAppForm } = createFormHook({
|
|
21
|
+
fieldComponents: {
|
|
22
|
+
TfTextField,
|
|
23
|
+
TfNumberField,
|
|
24
|
+
TfMultiSelect,
|
|
25
|
+
TfSingleSelect,
|
|
26
|
+
TfCheckbox,
|
|
27
|
+
},
|
|
28
|
+
formComponents: {
|
|
29
|
+
Button,
|
|
30
|
+
},
|
|
31
|
+
fieldContext,
|
|
32
|
+
formContext,
|
|
33
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { clsx, type ClassValue } from "clsx";
|
|
2
|
+
|
|
3
|
+
/** Classnames */
|
|
4
|
+
export function cn(...inputs: ClassValue[]) {
|
|
5
|
+
return clsx(inputs);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This is the variable name representing the primary hue.
|
|
10
|
+
* Referenced in tokens.scss -> token.css
|
|
11
|
+
*/
|
|
12
|
+
const PRIMARY_HUE_PROPERTY = "--primary-hue";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export function getThemeHue() {
|
|
19
|
+
return document.documentElement.style.getPropertyValue(PRIMARY_HUE_PROPERTY);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param hue the hue value to set in the document style
|
|
24
|
+
*/
|
|
25
|
+
export function setThemeHue(hue: number) {
|
|
26
|
+
document.documentElement.style.setProperty(
|
|
27
|
+
PRIMARY_HUE_PROPERTY,
|
|
28
|
+
// In this case, it must be a number.
|
|
29
|
+
hue as unknown as string,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ACCESS_TOKEN = "AT";
|
|
34
|
+
const REFRESH_TOKEN = "RT";
|
|
35
|
+
export function logout() {
|
|
36
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
37
|
+
try {
|
|
38
|
+
localStorage.removeItem(REFRESH_TOKEN);
|
|
39
|
+
localStorage.removeItem(ACCESS_TOKEN);
|
|
40
|
+
window.location.replace("/auth/login");
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error("Logout failed:", error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type JwtDecode = {
|
|
48
|
+
aud: string;
|
|
49
|
+
email: string;
|
|
50
|
+
exp: number;
|
|
51
|
+
iat: number;
|
|
52
|
+
jti: string;
|
|
53
|
+
region: string;
|
|
54
|
+
role: string;
|
|
55
|
+
role_type: string;
|
|
56
|
+
scope: string[];
|
|
57
|
+
sub: string;
|
|
58
|
+
teat: number;
|
|
59
|
+
tenantid: string;
|
|
60
|
+
token_usage: string;
|
|
61
|
+
sadmin?: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type CtxPortals =
|
|
65
|
+
| "customer-portal"
|
|
66
|
+
| "system-portal"
|
|
67
|
+
| "reseller-portal"
|
|
68
|
+
| "admin-portal";
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import type { CtxPortals } from "lib/utils/primitives";
|
|
2
|
+
import { createContext, use } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param input camelCase
|
|
7
|
+
* @returns title case for the camelCase string
|
|
8
|
+
*/
|
|
9
|
+
export function convertToTitleCase(input: string): string {
|
|
10
|
+
return input
|
|
11
|
+
.replace(/([A-Z])/g, " $1") // Insert space before capital letters
|
|
12
|
+
.trim() // Remove any leading/trailing spaces
|
|
13
|
+
.split(" ") // Split into words
|
|
14
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize each word
|
|
15
|
+
.join(" "); // Join back into a single string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function pluralizeTimes(resourceName: string, count: number) {
|
|
19
|
+
if (count > 1) {
|
|
20
|
+
if (/y$/.test(resourceName)) {
|
|
21
|
+
if (resourceName === "Day") return "Days";
|
|
22
|
+
return resourceName.replace(/y$/, "ies");
|
|
23
|
+
}
|
|
24
|
+
return resourceName.concat("s");
|
|
25
|
+
}
|
|
26
|
+
return resourceName;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Converts a string from 'camelCase' to 'Title Case'
|
|
31
|
+
* @param input String to convert to `Title Case`
|
|
32
|
+
*/
|
|
33
|
+
export function convertCamelCaseToTitleCase(input: string) {
|
|
34
|
+
if (input) {
|
|
35
|
+
const spacedString = input.replace(/([A-Z])/g, " $1");
|
|
36
|
+
return spacedString
|
|
37
|
+
.charAt(0)
|
|
38
|
+
.toUpperCase()
|
|
39
|
+
.concat(spacedString.slice(1))
|
|
40
|
+
.replace(/\.[a-z]/, (substr: string) => {
|
|
41
|
+
return substr.replace(".", " ").toUpperCase();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return input;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Display names specific to customer and reseller portal
|
|
48
|
+
const OTHER_PORTALS_DISPLAY_NAME: Record<string, string> = {
|
|
49
|
+
"product.displayName": "Product",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** Resource Name should ALWAYS be in singular form */
|
|
53
|
+
export const RESOURCE_NAMES = [
|
|
54
|
+
"access-token",
|
|
55
|
+
"account",
|
|
56
|
+
"activation",
|
|
57
|
+
"activation-log",
|
|
58
|
+
"admin-role",
|
|
59
|
+
"audit-log",
|
|
60
|
+
"automated-email",
|
|
61
|
+
"automated-email-event-log",
|
|
62
|
+
"card",
|
|
63
|
+
"feature-flag",
|
|
64
|
+
"invoice",
|
|
65
|
+
"license",
|
|
66
|
+
"license-template",
|
|
67
|
+
"maintenance-policy",
|
|
68
|
+
"organization",
|
|
69
|
+
"plan",
|
|
70
|
+
"product",
|
|
71
|
+
"product-version",
|
|
72
|
+
"profile",
|
|
73
|
+
"release",
|
|
74
|
+
"release-channel",
|
|
75
|
+
"release-file",
|
|
76
|
+
"release-platform",
|
|
77
|
+
"report",
|
|
78
|
+
"role",
|
|
79
|
+
"role-claim",
|
|
80
|
+
"saml-configuration",
|
|
81
|
+
"segment",
|
|
82
|
+
"sending-domain",
|
|
83
|
+
"setting",
|
|
84
|
+
"tag",
|
|
85
|
+
"team-member",
|
|
86
|
+
"trial",
|
|
87
|
+
"trial-policy",
|
|
88
|
+
"user",
|
|
89
|
+
"user-group",
|
|
90
|
+
"webhook",
|
|
91
|
+
"webhook-event-log",
|
|
92
|
+
"webhook-trigger",
|
|
93
|
+
"reseller",
|
|
94
|
+
"oidc-configuration",
|
|
95
|
+
"organization-claim",
|
|
96
|
+
"reseller-claim",
|
|
97
|
+
] as const;
|
|
98
|
+
export type ResourceName = (typeof RESOURCE_NAMES)[number];
|
|
99
|
+
export const RESOURCE_DEFINITIONS: Record<ResourceName, string> = {
|
|
100
|
+
account: "Your organization account.",
|
|
101
|
+
product: "Products are the software products you want to license",
|
|
102
|
+
license:
|
|
103
|
+
"Licenses represent a purchase of your software. These can be linked to customers, and the license key is required to use the product.",
|
|
104
|
+
"access-token": "Access Tokens are used to authenticate your API requests.",
|
|
105
|
+
activation:
|
|
106
|
+
"Activations, also known as devices/machines/seats are the devices consuming licenses.",
|
|
107
|
+
"activation-log":
|
|
108
|
+
"Activation Log is a log entry of activation/deactivation of a particular license.",
|
|
109
|
+
trial:
|
|
110
|
+
"Trial/Trial Activation is a device that has activated a trial of your product.",
|
|
111
|
+
"audit-log": "Audit logs contain all the changes made to your account.",
|
|
112
|
+
"automated-email":
|
|
113
|
+
"Automated Email allow you to send marketing emails based on events on the linked product.",
|
|
114
|
+
"automated-email-event-log":
|
|
115
|
+
"Automated email event log is the log of all the automated email events for your product.",
|
|
116
|
+
card: "The payment card for your account.",
|
|
117
|
+
"feature-flag":
|
|
118
|
+
"Feature flags define features that make up tiers for your products.",
|
|
119
|
+
invoice: "",
|
|
120
|
+
"license-template":
|
|
121
|
+
"License templates are a blueprint for the licenses you create for your customers and prevent repetition when creating licenses.",
|
|
122
|
+
"maintenance-policy":
|
|
123
|
+
"Maintenance policies represent support contracts and can be linked to licenses.",
|
|
124
|
+
plan: "",
|
|
125
|
+
"product-version":
|
|
126
|
+
"Product Versions are sets of Feature Flags that define the tiers of your products.",
|
|
127
|
+
"release-channel": "Release channel is the release channel for your product.",
|
|
128
|
+
"release-file": "Release files are files within your created releases.",
|
|
129
|
+
"release-platform":
|
|
130
|
+
'Release Platforms differentiate the target platform for your release. Common platforms include "Windows", "macOS", and "Linux".',
|
|
131
|
+
release:
|
|
132
|
+
"Releases help you to manage different versions of your app, and secure distribute it to licensed users.",
|
|
133
|
+
report: "Analytics data for your account",
|
|
134
|
+
"role-claim": "",
|
|
135
|
+
role: "Roles define permissions for your team.",
|
|
136
|
+
"saml-configuration": "",
|
|
137
|
+
segment: "Sets of filters that can be saved to filter resources.",
|
|
138
|
+
"trial-policy":
|
|
139
|
+
"Trial policies are templates for creating trials for your products.",
|
|
140
|
+
"webhook-event-log":
|
|
141
|
+
"Webhook Event Logs are logs of events that have occured on webhooks.",
|
|
142
|
+
"webhook-trigger": "",
|
|
143
|
+
webhook:
|
|
144
|
+
"Webhooks are HTTP callbacks which are triggered by specific events.",
|
|
145
|
+
organization: "",
|
|
146
|
+
profile: "",
|
|
147
|
+
setting: "",
|
|
148
|
+
tag: "Tags allow you to manage your licenses and customers on the dashboard.",
|
|
149
|
+
"team-member": "Team members can access the account based on their roles.",
|
|
150
|
+
user: "A user refers to your customer whom you want to license your product.",
|
|
151
|
+
"sending-domain":
|
|
152
|
+
"Allows Cryptlex to send emails on your behalf using your From Email address",
|
|
153
|
+
"admin-role": "Roles that have type admin",
|
|
154
|
+
"user-group": "Groups of users that you can assign licenses to.",
|
|
155
|
+
reseller:
|
|
156
|
+
"Resellers allow you to delegate user management to third parties or partners",
|
|
157
|
+
"oidc-configuration": "",
|
|
158
|
+
"organization-claim": "",
|
|
159
|
+
"reseller-claim": "",
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const RESOURCE_DISPLAY_NAMES: Record<string, string> = {
|
|
163
|
+
id: "ID",
|
|
164
|
+
createdAt: "Creation Date",
|
|
165
|
+
scopes: "Permissions",
|
|
166
|
+
updatedAt: "Last Updated",
|
|
167
|
+
expiresAt: "Expiration Date",
|
|
168
|
+
lastSeenAt: "Last Seen",
|
|
169
|
+
os: "OS",
|
|
170
|
+
osVersion: "OS Version",
|
|
171
|
+
key: "License Key",
|
|
172
|
+
vmName: "VM Name",
|
|
173
|
+
container: "Container",
|
|
174
|
+
allowedIpRange: "Allowed IP Range",
|
|
175
|
+
allowedIpRanges: "Allowed IP Ranges",
|
|
176
|
+
allowedIpAddresses: "Allowed IP Addresses",
|
|
177
|
+
disallowedIpAddresses: "Disallowed IP Addresses",
|
|
178
|
+
allowVmActivation: "Allow VM Activation",
|
|
179
|
+
disableGeoLocation: "Disable Geolocation",
|
|
180
|
+
"user.id": "User ID",
|
|
181
|
+
userId: "User",
|
|
182
|
+
productId: "Product",
|
|
183
|
+
downloads: "Total Downloads",
|
|
184
|
+
claims: "Permissions",
|
|
185
|
+
googleSsoEnabled: "Google Login Enabled",
|
|
186
|
+
lastAttemptedAt: "Last Attempt Date",
|
|
187
|
+
url: "URL",
|
|
188
|
+
"trialPolicy.name": "Trial Policy Name",
|
|
189
|
+
"licensePolicy.name": "License Template Name",
|
|
190
|
+
licensePolicy: "License Template",
|
|
191
|
+
eventLog: "Audit Log",
|
|
192
|
+
cc: "CC Recepients",
|
|
193
|
+
bcc: "BCC Recepients",
|
|
194
|
+
ipAddress: "IP Address",
|
|
195
|
+
resellerId: "Reseller",
|
|
196
|
+
productVersionId: "Product Version",
|
|
197
|
+
releaseId: "Release",
|
|
198
|
+
maintenancePolicyId: "Maintenance Policy",
|
|
199
|
+
webhookId: "Webhook",
|
|
200
|
+
automatedEmailId: "Automated Email",
|
|
201
|
+
"location.countryName": "Country",
|
|
202
|
+
"location.ipAddress": "IP Address",
|
|
203
|
+
"location.countryCode": "Country",
|
|
204
|
+
organizationId: "Organization",
|
|
205
|
+
"address.country": "Country",
|
|
206
|
+
"address.addressLine1": "Address Line 1",
|
|
207
|
+
"address.addressLine2": "Address Line 2",
|
|
208
|
+
responseStatusCode: "HTTP Status Code",
|
|
209
|
+
resourceId: "Resource ID",
|
|
210
|
+
Sso: "SAML SSO 2.0",
|
|
211
|
+
"reseller.name": "Reseller",
|
|
212
|
+
sendingDomain: "Email Sending Domain",
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
function getResourceDisplayName(
|
|
216
|
+
resourceName: string,
|
|
217
|
+
portal: CtxPortals,
|
|
218
|
+
) {
|
|
219
|
+
if (portal !== "admin-portal" && resourceName in OTHER_PORTALS_DISPLAY_NAME) {
|
|
220
|
+
return OTHER_PORTALS_DISPLAY_NAME[resourceName];
|
|
221
|
+
} else if (resourceName in RESOURCE_DISPLAY_NAMES) {
|
|
222
|
+
return RESOURCE_DISPLAY_NAMES[resourceName];
|
|
223
|
+
} else {
|
|
224
|
+
return convertCamelCaseToTitleCase(resourceName);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const ProjectContext = createContext<CtxPortals>('admin-portal');
|
|
229
|
+
|
|
230
|
+
export function ProjectProvider({ projectName, children }: { projectName: CtxPortals; children: React.ReactNode; }) {
|
|
231
|
+
return (
|
|
232
|
+
<ProjectContext.Provider value={projectName}>
|
|
233
|
+
{children}
|
|
234
|
+
</ProjectContext.Provider>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function useProjectName(): CtxPortals {
|
|
239
|
+
return use(ProjectContext);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function useResourceFormatter(): (resourceName: string) => string {
|
|
243
|
+
const portal = useProjectName();
|
|
244
|
+
return (resourceName: string) => getResourceDisplayName(resourceName, portal);
|
|
245
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
const MOBILE_BREAKPOINT = 768;
|
|
4
|
+
|
|
5
|
+
export function useIsMobile() {
|
|
6
|
+
const [isMobile, setIsMobile] = useState<boolean | undefined>(
|
|
7
|
+
undefined,
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
12
|
+
const onChange = () => {
|
|
13
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
14
|
+
};
|
|
15
|
+
mql.addEventListener("change", onChange);
|
|
16
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
17
|
+
return () => mql.removeEventListener("change", onChange);
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
return !!isMobile;
|
|
21
|
+
}
|