@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
63 lines (62 loc) • 2.42 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import { __rest } from "tslib";
import { h } from "@stencil/core";
import KolFormFieldFc from "../../functional-components/FormField";
import { getRenderStates } from "../_helpers/getRenderStates";
function getFormFieldProps(state) {
const props = {
id: state._id,
disabled: state._disabled,
msg: state._msg,
hint: state._hint,
label: state._label,
hideLabel: state._hideLabel,
hideMsg: state._hideMsg,
touched: state._touched,
showBadge: ('_accessKey' in state && Boolean(state._accessKey)) || ('_shortKey' in state && Boolean(state._shortKey)),
};
if ('_required' in state) {
props.required = state._required;
}
if ('_readOnly' in state) {
props.readOnly = state._readOnly;
}
if ('_accessKey' in state) {
props.accessKey = state._accessKey;
}
if ('_shortKey' in state) {
props.shortKey = state._shortKey;
}
if ('_maxLength' in state) {
props.maxLength = state._maxLength;
}
if ('_currentLength' in state &&
typeof state._currentLength === 'number' &&
'_currentLengthDebounced' in state &&
typeof state._currentLengthDebounced === 'number') {
if ('_hasCounter' in state && state._hasCounter === true) {
props.counter = {
currentLength: state._currentLength,
currentLengthDebounced: state._currentLengthDebounced,
maxLength: state._maxLength,
maxLengthBehavior: state._maxLengthBehavior || 'hard',
};
}
}
if ('_variant' in state) {
props.variant = state._variant;
}
return props;
}
const FormFieldStateWrapper = (_a, children) => {
var { state } = _a, other = __rest(_a, ["state"]);
const { ariaDescribedBy: ariaDescribedByArray } = getRenderStates(state);
const isRadioVariant = other.component === 'fieldset' || ('_options' in state && '_orientation' in state);
const ariaDescribedBy = isRadioVariant && ariaDescribedByArray.length > 0 ? ariaDescribedByArray.join(' ') : undefined;
const baseProps = getFormFieldProps(state);
return (h(KolFormFieldFc, Object.assign({}, baseProps, other, { ariaDescribedBy: ariaDescribedBy }), children));
};
export default FormFieldStateWrapper;
//# sourceMappingURL=FormFieldStateWrapper.js.map