@snups/rjsf-utils
Version:
Utility functions for @snups/rjsf-core
16 lines (15 loc) • 1.16 kB
TypeScript
import { RJSFSchema, EnumOptionsType, StrictRJSFSchema, FormContextType, UiSchema } from './types.js';
/** Gets the list of options from the `schema`. If the schema has an enum list, then those enum values are returned. The
* label will be the same as the `value`.
*
* If the schema has a `oneOf` or `anyOf`, then the value is the list of either:
* - The `const` values from the schema if present
* - If the schema has a discriminator and the label using either the `schema.title` or the value. If a `uiSchema` is
* provided, and it has the `ui:enumNames` matched with `enum` or it has an associated `oneOf` or `anyOf` with a list of
* objects containing `ui:title` then the UI schema values will replace the values from the schema.
*
* @param schema - The schema from which to extract the options list
* @param [uiSchema] - The optional uiSchema from which to get alternate labels for the options
* @returns - The list of options from the schema
*/
export default function optionsList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: S, uiSchema?: UiSchema<T, S, F>): EnumOptionsType<S>[] | undefined;