mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 16:46:00 +00:00
added auth strategies form + add ability to disable strategies
This commit is contained in:
@@ -30,8 +30,9 @@ const fieldErrorBoundary =
|
||||
</Pre>
|
||||
);
|
||||
|
||||
const FieldImpl = ({ name, onChange, placeholder, ...props }: FieldProps) => {
|
||||
const { path, setValue, required, schema, ...ctx } = useDerivedFieldContext(name);
|
||||
const FieldImpl = ({ name, onChange, placeholder, required: _required, ...props }: FieldProps) => {
|
||||
const { path, setValue, schema, ...ctx } = useDerivedFieldContext(name);
|
||||
const required = typeof _required === "boolean" ? _required : ctx.required;
|
||||
//console.log("Field", { name, path, schema });
|
||||
if (!isTypeSchema(schema))
|
||||
return (
|
||||
|
||||
@@ -14,7 +14,7 @@ import { getLabel } from "./utils";
|
||||
|
||||
export type FieldwrapperProps = {
|
||||
name: string;
|
||||
label?: string | false;
|
||||
label?: string | ReactNode | false;
|
||||
required?: boolean;
|
||||
schema?: JsonSchema;
|
||||
debug?: object | boolean;
|
||||
|
||||
@@ -35,7 +35,7 @@ import {
|
||||
prefixPointer
|
||||
} from "./utils";
|
||||
|
||||
type JSONSchema = Exclude<$JSONSchema, boolean>;
|
||||
export type JSONSchema = Exclude<$JSONSchema, boolean>;
|
||||
type FormState<Data = any> = {
|
||||
dirty: boolean;
|
||||
submitting: boolean;
|
||||
@@ -238,6 +238,7 @@ export function FormContextOverride({
|
||||
...overrides,
|
||||
...additional
|
||||
};
|
||||
console.log("context", context);
|
||||
|
||||
return <FormContext.Provider value={context}>{children}</FormContext.Provider>;
|
||||
}
|
||||
@@ -287,10 +288,11 @@ export function useFormError(name: string, opt?: { strict?: boolean; debug?: boo
|
||||
}
|
||||
|
||||
export function useFormStateSelector<Data = any, Reduced = Data>(
|
||||
selector: (state: FormState<Data>) => Reduced
|
||||
selector: (state: FormState<Data>) => Reduced,
|
||||
deps: any[] = []
|
||||
): Reduced {
|
||||
const { _formStateAtom } = useFormContext();
|
||||
const selected = selectAtom(_formStateAtom, useCallback(selector, []), isEqual);
|
||||
const selected = selectAtom(_formStateAtom, useCallback(selector, deps), isEqual);
|
||||
return useAtom(selected)[0];
|
||||
}
|
||||
|
||||
@@ -306,14 +308,16 @@ export function useDerivedFieldContext<Data = any, Reduced = undefined>(
|
||||
path: string;
|
||||
},
|
||||
Reduced
|
||||
>
|
||||
>,
|
||||
_schema?: JSONSchema
|
||||
): FormContext<Data> & {
|
||||
value: Reduced;
|
||||
pointer: string;
|
||||
required: boolean;
|
||||
path: string;
|
||||
} {
|
||||
const { _formStateAtom, root, lib, schema, ...ctx } = useFormContext();
|
||||
const { _formStateAtom, root, lib, ...ctx } = useFormContext();
|
||||
const schema = _schema ?? ctx.schema;
|
||||
const selected = selectAtom(
|
||||
_formStateAtom,
|
||||
useCallback(
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import type { JSONSchema } from "json-schema-to-ts";
|
||||
import { isTypeSchema } from "ui/components/form/json-schema-form/utils";
|
||||
import { AnyOfField } from "./AnyOfField";
|
||||
import { Field } from "./Field";
|
||||
import { FieldWrapper, type FieldwrapperProps } from "./FieldWrapper";
|
||||
import { useDerivedFieldContext } from "./Form";
|
||||
import { type JSONSchema, useDerivedFieldContext } from "./Form";
|
||||
|
||||
export type ObjectFieldProps = {
|
||||
path?: string;
|
||||
@@ -12,7 +11,7 @@ export type ObjectFieldProps = {
|
||||
};
|
||||
|
||||
export const ObjectField = ({ path = "", label: _label, wrapperProps = {} }: ObjectFieldProps) => {
|
||||
const { schema } = useDerivedFieldContext(path);
|
||||
const { schema, ...ctx } = useDerivedFieldContext(path);
|
||||
if (!isTypeSchema(schema)) return `ObjectField "${path}": no schema`;
|
||||
const properties = Object.entries(schema.properties ?? {}) as [string, JSONSchema][];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user