| 43 | ): void; |
| 44 | |
| 45 | export function disabled<TValue, TPathKind extends PathKind = PathKind.Root>( |
| 46 | path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, |
| 47 | configOrLogic?: |
| 48 | | {when?: string | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>} |
| 49 | | string |
| 50 | | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>, |
| 51 | ): void { |
| 52 | assertPathIsCurrent(path); |
| 53 | |
| 54 | const pathNode = FieldPathNode.unwrapFieldPath(path); |
| 55 | |
| 56 | let logic: string | LogicFn<TValue, boolean | string, TPathKind> | undefined; |
| 57 | if (typeof configOrLogic === 'function' || typeof configOrLogic === 'string') { |
| 58 | logic = configOrLogic; |
| 59 | } else { |
| 60 | logic = configOrLogic?.when; |
| 61 | } |
| 62 | |
| 63 | pathNode.builder.addDisabledReasonRule((ctx) => { |
| 64 | let result: boolean | string = true; |
| 65 | if (typeof logic === 'string') { |
| 66 | result = logic; |
| 67 | } else if (logic) { |
| 68 | result = logic(ctx as FieldContext<TValue, TPathKind>); |
| 69 | } |
| 70 | if (typeof result === 'string') { |
| 71 | return {fieldTree: ctx.fieldTree, message: result}; |
| 72 | } |
| 73 | return result ? {fieldTree: ctx.fieldTree} : undefined; |
| 74 | }); |
| 75 | } |