|
| 1 | +declare module 'react-context-toolbox/forwardRef' { |
| 2 | + import * as React from 'react'; |
| 3 | + |
| 4 | + interface ForwardRefOptions<TProps> { |
| 5 | + displayName?: string; |
| 6 | + propTypes?: React.ValidationMap<TProps>; |
| 7 | + defaultProps?: Partial<TProps>; |
| 8 | + allowFallback?: boolean; |
| 9 | + } |
| 10 | + |
| 11 | + function forwardRef<TRef, TProps>( |
| 12 | + renderFn: ( |
| 13 | + props: TProps & { children?: React.ReactNode }, |
| 14 | + ref: React.Ref<TRef> | null, |
| 15 | + ) => React.ReactElement<any> | null, |
| 16 | + options?: ForwardRefOptions<TProps>, |
| 17 | + ): React.ForwardRefExoticComponent< |
| 18 | + React.PropsWithRef<TProps> & React.RefAttributes<TRef> |
| 19 | + >; |
| 20 | + |
| 21 | + export default forwardRef; |
| 22 | +} |
| 23 | + |
| 24 | +declare module 'react-context-toolbox/mapContextToProps' { |
| 25 | + import * as React from 'react'; |
| 26 | + |
| 27 | + type ElementType = React.ComponentType<any> | keyof JSX.IntrinsicElements; |
| 28 | + |
| 29 | + type Omit<T, U> = Pick<T, Exclude<keyof T, keyof U>>; |
| 30 | + |
| 31 | + type GetProps<C> = C extends React.ComponentType<infer P> ? P : never; |
| 32 | + |
| 33 | + interface ContextInjectedComponent<TComponent, TInjectedProps, TExtraProps> |
| 34 | + extends React.ForwardRefExoticComponent< |
| 35 | + Omit<GetProps<TComponent>, TInjectedProps> & TExtraProps |
| 36 | + > {} |
| 37 | + |
| 38 | + // Single Context |
| 39 | + function mapContextToProps<TComponent, TContext, TContextProps, TOwnProps>( |
| 40 | + context: React.Context<TContext>, |
| 41 | + mapToProps: (ctxValue: TContext, props: TOwnProps) => TContextProps, |
| 42 | + Component: TComponent, |
| 43 | + ): ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 44 | + function mapContextToProps<TContext, TContextProps, TOwnProps>( |
| 45 | + context: React.Context<TContext>, |
| 46 | + mapToProps: (ctxValue: TContext, props: TOwnProps) => TContextProps, |
| 47 | + ): <TComponent>( |
| 48 | + component: TComponent, |
| 49 | + ) => ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 50 | + |
| 51 | + function mapContextToProps<TComponent, TContext, TContextProps, TOwnProps>( |
| 52 | + context: [React.Context<TContext>], |
| 53 | + mapToProps: (ctxValue: TContext, props: TOwnProps) => TContextProps, |
| 54 | + Component: TComponent, |
| 55 | + ): ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 56 | + function mapContextToProps<TContext, TContextProps, TOwnProps>( |
| 57 | + context: [React.Context<TContext>], |
| 58 | + mapToProps: (ctxValue: TContext, props: TOwnProps) => TContextProps, |
| 59 | + ): <TComponent>( |
| 60 | + component: TComponent, |
| 61 | + ) => ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 62 | + |
| 63 | + // 2 Contexts |
| 64 | + function mapContextToProps< |
| 65 | + TComponent, |
| 66 | + TContext1, |
| 67 | + TContext2, |
| 68 | + TContextProps, |
| 69 | + TOwnProps |
| 70 | + >( |
| 71 | + context: [React.Context<TContext1>, React.Context<TContext2>], |
| 72 | + mapToProps: ( |
| 73 | + c1: TContext1, |
| 74 | + c2: TContext2, |
| 75 | + props: TOwnProps, |
| 76 | + ) => TContextProps, |
| 77 | + Component: TComponent, |
| 78 | + ): ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 79 | + function mapContextToProps<TContext1, TContext2, TContextProps, TOwnProps>( |
| 80 | + context: [React.Context<TContext1>, React.Context<TContext2>], |
| 81 | + mapToProps: ( |
| 82 | + c1: TContext1, |
| 83 | + c2: TContext2, |
| 84 | + props: TOwnProps, |
| 85 | + ) => TContextProps, |
| 86 | + ): <TComponent>( |
| 87 | + component: TComponent, |
| 88 | + ) => ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 89 | + |
| 90 | + // 3 Contexts |
| 91 | + function mapContextToProps< |
| 92 | + TComponent, |
| 93 | + TContext1, |
| 94 | + TContext2, |
| 95 | + TContext3, |
| 96 | + TContextProps, |
| 97 | + TOwnProps |
| 98 | + >( |
| 99 | + context: [ |
| 100 | + React.Context<TContext1>, |
| 101 | + React.Context<TContext2>, |
| 102 | + React.Context<TContext3> |
| 103 | + ], |
| 104 | + mapToProps: ( |
| 105 | + c1: TContext1, |
| 106 | + c2: TContext2, |
| 107 | + c3: TContext3, |
| 108 | + props: TOwnProps, |
| 109 | + ) => TContextProps, |
| 110 | + Component: TComponent, |
| 111 | + ): ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 112 | + function mapContextToProps< |
| 113 | + TContext1, |
| 114 | + TContext2, |
| 115 | + TContext3, |
| 116 | + TContextProps, |
| 117 | + TOwnProps |
| 118 | + >( |
| 119 | + context: [ |
| 120 | + React.Context<TContext1>, |
| 121 | + React.Context<TContext2>, |
| 122 | + React.Context<TContext3> |
| 123 | + ], |
| 124 | + mapToProps: ( |
| 125 | + c1: TContext1, |
| 126 | + c2: TContext2, |
| 127 | + c3: TContext3, |
| 128 | + props: TOwnProps, |
| 129 | + ) => TContextProps, |
| 130 | + ): <TComponent>( |
| 131 | + component: TComponent, |
| 132 | + ) => ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 133 | + |
| 134 | + // 4 Contexts |
| 135 | + function mapContextToProps< |
| 136 | + TComponent, |
| 137 | + TContext1, |
| 138 | + TContext2, |
| 139 | + TContext3, |
| 140 | + TContext4, |
| 141 | + TContextProps, |
| 142 | + TOwnProps |
| 143 | + >( |
| 144 | + context: [ |
| 145 | + React.Context<TContext1>, |
| 146 | + React.Context<TContext2>, |
| 147 | + React.Context<TContext3>, |
| 148 | + React.Context<TContext4> |
| 149 | + ], |
| 150 | + mapToProps: ( |
| 151 | + c1: TContext1, |
| 152 | + c2: TContext2, |
| 153 | + c3: TContext3, |
| 154 | + c4: TContext4, |
| 155 | + props: TOwnProps, |
| 156 | + ) => TContextProps, |
| 157 | + Component: TComponent, |
| 158 | + ): ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 159 | + function mapContextToProps< |
| 160 | + TContext1, |
| 161 | + TContext2, |
| 162 | + TContext3, |
| 163 | + TContext4, |
| 164 | + TContextProps, |
| 165 | + TOwnProps |
| 166 | + >( |
| 167 | + context: [ |
| 168 | + React.Context<TContext1>, |
| 169 | + React.Context<TContext2>, |
| 170 | + React.Context<TContext3>, |
| 171 | + React.Context<TContext4> |
| 172 | + ], |
| 173 | + mapToProps: ( |
| 174 | + c1: TContext1, |
| 175 | + c2: TContext2, |
| 176 | + c3: TContext3, |
| 177 | + c4: TContext4, |
| 178 | + props: TOwnProps, |
| 179 | + ) => TContextProps, |
| 180 | + ): <TComponent>( |
| 181 | + component: TComponent, |
| 182 | + ) => ContextInjectedComponent<TComponent, TContextProps, TOwnProps>; |
| 183 | + |
| 184 | + export default mapContextToProps; |
| 185 | +} |
0 commit comments