@intility/bifrost-react
Version:
React library for Intility's design system, Bifrost.
118 lines (117 loc) • 2.83 kB
JavaScript
"use client";
import { c as _c } from "react-compiler-runtime";
import { forwardRef } from "react";
import classNames from "classnames";
import { faLock } from "@fortawesome/free-solid-svg-icons/faLock";
import Icon from "../Icon/Icon.js";
import useLocale from "../../hooks/useLocale.js";
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
/**
* Label element to be attached to a form input
*
* @see https://bifrost.intility.com/react/label
*
* @example
* <Label htmlFor="inputId">Name</Label>
*/
const Label = /*#__PURE__*/forwardRef((t0, ref) => {
const $ = _c(27);
let children;
let className;
let props;
let t1;
let t2;
let t3;
let t4;
if ($[0] !== t0) {
({
className,
children,
required: t1,
optional: t2,
disabled: t3,
readOnly: t4,
...props
} = t0);
$[0] = t0;
$[1] = children;
$[2] = className;
$[3] = props;
$[4] = t1;
$[5] = t2;
$[6] = t3;
$[7] = t4;
} else {
children = $[1];
className = $[2];
props = $[3];
t1 = $[4];
t2 = $[5];
t3 = $[6];
t4 = $[7];
}
const required = t1 === undefined ? false : t1;
const optional = t2 === undefined ? false : t2;
const disabled = t3 === undefined ? false : t3;
const readOnly = t4 === undefined ? false : t4;
const locale = useLocale();
let t5;
if ($[8] !== className || $[9] !== disabled) {
t5 = classNames(className, "bf-label", {
"bf-label-disabled": disabled
});
$[8] = className;
$[9] = disabled;
$[10] = t5;
} else {
t5 = $[10];
}
let t6;
if ($[11] !== children || $[12] !== disabled || $[13] !== locale || $[14] !== optional || $[15] !== required) {
t6 = (required || optional) && children && !disabled && /*#__PURE__*/_jsxs("span", {
className: "bf-label-required",
children: ["(", required ? locale.required : locale.optional, ")"]
});
$[11] = children;
$[12] = disabled;
$[13] = locale;
$[14] = optional;
$[15] = required;
$[16] = t6;
} else {
t6 = $[16];
}
let t7;
if ($[17] !== disabled || $[18] !== readOnly) {
t7 = (disabled || readOnly) && /*#__PURE__*/_jsx(Icon, {
icon: faLock,
className: "bf-input-disabled-icon"
});
$[17] = disabled;
$[18] = readOnly;
$[19] = t7;
} else {
t7 = $[19];
}
let t8;
if ($[20] !== children || $[21] !== props || $[22] !== ref || $[23] !== t5 || $[24] !== t6 || $[25] !== t7) {
t8 = /*#__PURE__*/_jsxs("label", {
...props,
ref: ref,
className: t5,
children: [children, t6, t7]
});
$[20] = children;
$[21] = props;
$[22] = ref;
$[23] = t5;
$[24] = t6;
$[25] = t7;
$[26] = t8;
} else {
t8 = $[26];
}
return t8;
});
Label.displayName = "Label";
export default Label;