1
1
import type { ReactElement , ReactNode } from 'react'
2
2
import React from 'react'
3
3
4
- import type { routes } from '@redwoodjs/router'
4
+ export type WrapperType < WTProps > = (
5
+ props : Omit < WTProps , 'wrap' | 'children' > & {
6
+ children : ReactNode
7
+ } ,
8
+ ) => ReactElement | null
5
9
6
- type SetProps < P > = ( P extends React . FC ? React . ComponentProps < P > : unknown ) & {
10
+ type SetProps < P > = P & {
7
11
/**
8
- * A react component that the children of the Set will be wrapped
9
- * in (typically a Layout component)
12
+ * P is the interface for the props that are forwarded to the wrapper
13
+ * components. TypeScript will most likely infer this for you, but if you
14
+ * need to you can specify it yourself in your JSX like so:
15
+ * <Set<{theme: string}> wrap={ThemableLayout} theme="dark">
10
16
*/
11
- wrap ?: P | P [ ]
17
+ wrap ?: WrapperType < P > | WrapperType < P > [ ]
12
18
/**
13
19
*`Routes` nested in a `<Set>` with `private` specified require
14
20
* authentication. When a user is not authenticated and attempts to visit
@@ -22,7 +28,7 @@ type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
22
28
*
23
29
* @deprecated Please use `<PrivateSet>` instead and specify this prop there
24
30
*/
25
- unauthenticated ?: keyof typeof routes
31
+ unauthenticated ?: string
26
32
/**
27
33
* Route is permitted when authenticated and user has any of the provided
28
34
* roles such as "admin" or ["admin", "editor"]
@@ -37,18 +43,22 @@ type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
37
43
}
38
44
39
45
/**
40
- * A set containing public `<Route />`s
46
+ * TypeScript will often infer the type of the props you can forward to the
47
+ * wrappers for you, but if you need to you can specify it yourself in your
48
+ * JSX like so:
49
+ * <Set<{theme: string}> wrap={ThemeableLayout} theme="dark">
41
50
*/
42
51
export function Set < WrapperProps > ( props : SetProps < WrapperProps > ) {
43
52
// @MARK : Virtual Component, this is actually never rendered
44
53
// See analyzeRoutes in utils.tsx, inside the isSetNode block
45
54
return < > { props . children } </ >
46
55
}
47
56
48
- type PrivateSetProps < P > = Omit < SetProps < P > , 'private' | 'unauthenticated' > & {
49
- /** The page name where a user will be redirected when not authenticated */
50
- unauthenticated : keyof typeof routes
51
- }
57
+ type PrivateSetProps < P > = P &
58
+ Omit < SetProps < P > , 'private' | 'unauthenticated' > & {
59
+ /** The page name where a user will be redirected when not authenticated */
60
+ unauthenticated : string
61
+ }
52
62
53
63
/** @deprecated Please use `<PrivateSet>` instead */
54
64
export function Private < WrapperProps > ( props : PrivateSetProps < WrapperProps > ) {
@@ -57,9 +67,6 @@ export function Private<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
57
67
return < > { props . children } </ >
58
68
}
59
69
60
- /**
61
- * A set containing private `<Route />`s that require authentication to access
62
- */
63
70
export function PrivateSet < WrapperProps > ( props : PrivateSetProps < WrapperProps > ) {
64
71
// @MARK Virtual Component, this is actually never rendered
65
72
// See analyzeRoutes in utils.tsx, inside the isSetNode block
0 commit comments