UNPKG

@asgardeo/react

Version:
107 lines (106 loc) 2.85 kB
/** * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import { FC, ReactElement } from 'react'; import { SelectOption } from '../primitives/Select/Select'; import { FieldType } from '@asgardeo/browser'; /** * Interface for field configuration. */ export interface FieldConfig { /** * The name of the field. */ name: string; /** * The field type. */ type: FieldType; /** * Display name for the field. */ label: string; /** * Whether the field is required. */ required: boolean; /** * Current value of the field. */ value: string; /** * Callback function when the field value changes. */ onChange: (value: string) => void; /** * Callback function when the field loses focus. */ onBlur?: () => void; /** * Whether the field is disabled. */ disabled?: boolean; /** * Error message to display. */ error?: string; /** * Additional CSS class name. */ className?: string; /** * Additional options for multi-valued fields. */ options?: SelectOption[]; /** * Whether the field has been touched/interacted with by the user. */ touched?: boolean; /** * Placeholder text for the field. */ placeholder?: string; } /** * Utility function to validate field values based on type */ export declare const validateFieldValue: (value: string, type: FieldType, required?: boolean, touched?: boolean) => string | null; /** * Factory function to create form fields based on the EmbeddedSignInFlowAuthenticatorParamType. * * @param config - The field configuration * @returns The appropriate React component for the field type * * @example * ```tsx * const field = createField({ * param: 'username', * type: EmbeddedSignInFlowAuthenticatorParamType.String, * label: 'Username', * confidential: false, * required: true, * value: '', * onChange: (value) => console.log(value) * }); * ``` */ export declare const createField: (config: FieldConfig) => ReactElement; /** * React component wrapper for the field factory. */ export declare const FieldFactory: FC<FieldConfig>; export default FieldFactory;