@rjsf/semantic-ui
Version:
Semantic UI theme, fields and widgets for react-jsonschema-form
67 lines • 2.85 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { getUiOptions, } from '@rjsf/utils';
/**
* Extract props meant for semantic UI components from props that are
* passed to Widgets, Templates and Fields.
* @param {Object} params
* @param {Object?} params.formContext
* @param {Object?} params.uiSchema
* @param {Object?} params.options
* @param {Object?} params.defaultSchemaProps
* @param {Object?} params.defaultContextProps
* @returns {any}
*/
export function getSemanticProps({ formContext = {}, uiSchema = {}, options = {}, defaultSchemaProps = { fluid: true, inverted: false }, defaultContextProps = {}, }) {
const formContextProps = formContext.semantic;
const schemaProps = getUiOptions(uiSchema).semantic;
const optionProps = options.semantic;
// formContext props should overide other props
return Object.assign({}, { ...defaultSchemaProps }, { ...defaultContextProps }, schemaProps, optionProps, formContextProps);
}
/**
* Extract error props meant for semantic UI components from props that are
* passed to Widgets, Templates and Fields.
* @param {Object} params
* @param {Object?} params.formContext
* @param {Object?} params.uiSchema
* @param {Object?} params.defaultProps
* @returns {any}
*/
export function getSemanticErrorProps({ formContext = {}, uiSchema = {}, options = {}, defaultProps = { size: 'small', pointing: 'above' }, }) {
const formContextProps = formContext.semantic && formContext.semantic.errorOptions;
const semanticOptions = getUiOptions(uiSchema).semantic;
const schemaProps = semanticOptions && semanticOptions.errorOptions;
const optionProps = options.semantic && options.semantic.errorOptions;
return Object.assign({}, { ...defaultProps }, schemaProps, optionProps, formContextProps);
}
/**
* Combine multiple strings containing class names into a single string,
* removing duplicates. E.g.
* cleanClassNames('bar', 'baz bar', 'x y ', undefined)
* // 'bar baz x y'
* @param {Array} classNameArr
* @param {Array} omit
* @returns {string}
*/
export function cleanClassNames(classNameArr, omit = []) {
// Split each arg on whitespace, and add it to an array. Skip false-y args
// like "" and undefined.
const classList = classNameArr
.filter(Boolean)
.reduce((previous, current) => previous.concat(current.trim().split(/\s+/)), []);
// Remove any class names from omit, and make the rest unique before
// returning them as a string
return [...new Set(classList.filter((cn) => !omit.includes(cn)))].join(' ');
}
/**
*
* @param {boolean} wrap
* @param Component
* @param {Object} props
* @returns {*}
* @constructor
*/
export function MaybeWrap({ wrap, component: Component = 'div', ...props }) {
return wrap ? _jsx(Component, { ...props }) : props.children;
}
//# sourceMappingURL=util.js.map