mongodb-chatbot-ui
Version:
UI React components for the MongoDB Chatbot Framework
362 lines (340 loc) • 14.1 kB
JavaScript
import l, { forwardRef as Le, useContext as rn } from "react";
import { W as v, m as i, e as g, R as D, j as on, o as k, ac as _e, i as ae, L as q, M as sn, w as re, F as X, b as A, d as Ce, l as z, p as c, B as W, aE as T } from "./index2.js";
import { G as He, k as ln, s as dn, w as cn, Q as un } from "./index4.js";
import { v as pn } from "./index10.js";
var E = "lg-form_field", f = { root: E, contentEnd: "".concat(E, "-content_end"), description: "".concat(E, "-description"), errorMessage: "".concat(E, "-error_message"), feedback: "".concat(E, "-feedback"), input: "".concat(E, "-input"), label: "".concat(E, "-label"), optional: "".concat(E, "-optional"), successMessage: "".concat(E, "-success_message") }, ie = { error: "This input needs your attention", success: "Success" };
function oe(e, t) {
var n = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var a = Object.getOwnPropertySymbols(e);
t && (a = a.filter(function(d) {
return Object.getOwnPropertyDescriptor(e, d).enumerable;
})), n.push.apply(n, a);
}
return n;
}
function R(e) {
for (var t = 1; t < arguments.length; t++) {
var n = arguments[t] != null ? arguments[t] : {};
t % 2 ? oe(Object(n), !0).forEach(function(a) {
p(e, a, n[a]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : oe(Object(n)).forEach(function(a) {
Object.defineProperty(e, a, Object.getOwnPropertyDescriptor(n, a));
});
}
return e;
}
function fn(e) {
var t = function(n, a) {
if (typeof n != "object" || !n)
return n;
var d = n[Symbol.toPrimitive];
if (d !== void 0) {
var b = d.call(n, a);
if (typeof b != "object")
return b;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return String(n);
}(e, "string");
return typeof t == "symbol" ? t : t + "";
}
function p(e, t, n) {
return (t = fn(t)) in e ? Object.defineProperty(e, t, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = n, e;
}
function S() {
return S = Object.assign ? Object.assign.bind() : function(e) {
for (var t = 1; t < arguments.length; t++) {
var n = arguments[t];
for (var a in n)
Object.prototype.hasOwnProperty.call(n, a) && (e[a] = n[a]);
}
return e;
}, S.apply(this, arguments);
}
function L(e, t) {
if (e == null)
return {};
var n, a, d = function(r, s) {
if (r == null)
return {};
var u, m, y = {}, h = Object.keys(r);
for (m = 0; m < h.length; m++)
u = h[m], s.indexOf(u) >= 0 || (y[u] = r[u]);
return y;
}(e, t);
if (Object.getOwnPropertySymbols) {
var b = Object.getOwnPropertySymbols(e);
for (a = 0; a < b.length; a++)
n = b[a], t.indexOf(n) >= 0 || Object.prototype.propertyIsEnumerable.call(e, n) && (d[n] = e[n]);
}
return d;
}
function o(e, t) {
return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } }));
}
var se, le, de, ce, ue, pe, fe, be, me, ge, x = { None: "none", Error: "error", Valid: "valid" }, bn = { disabled: !1, size: v.Default, state: x.None }, Ve = l.createContext(bn), mn = function(e) {
var t = e.value, n = e.children;
return l.createElement(Ve.Provider, { value: t }, n);
}, gn = function() {
return rn(Ve);
}, We = function(e) {
var t = e.baseFontSize, n = e.size;
return n === v.XSmall || n === v.Small ? i(se || (se = o([`
font-size: `, `px;
line-height: `, `px;
`])), z.body1.fontSize, z.body1.lineHeight) : n === v.Default ? i(le || (le = o([`
font-size: `, `px;
line-height: `, `px;
`])), t, z.body1.lineHeight) : n === v.Large ? i(de || (de = o([`
font-size: `, `px;
line-height: `, `px;
`])), z.large.fontSize, z.large.lineHeight) : void 0;
}, hn = function(e) {
return e === x.Error ? T.Error : e === x.Valid ? T.Success : T.Primary;
}, vn = i(ce || (ce = o([`
display: flex;
flex-direction: column;
`]))), xn = i(ue || (ue = o([`
margin-bottom: `, `px;
`])), g[100]), yn = i(pe || (pe = o([`
display: flex;
gap: `, `px;
`])), g[100]), wn = i(fe || (fe = o([`
padding-top: `, `px;
`])), g[100]), En = i(be || (be = o([`
opacity: 0;
`]))), kn = i(me || (me = o([`
display: flex;
justify-content: center;
align-items: center;
`]))), On = function(e) {
return i(ge || (ge = o([`
height: `, `px;
`])), e === v.Large ? z.large.lineHeight : z.body1.lineHeight);
}, zn = ["baseFontSize", "disabled", "errorMessage", "hideFeedback", "id", "size", "state", "successMessage"], Te = function(e) {
var t = e.baseFontSize, n = e.disabled, a = e.errorMessage, d = e.hideFeedback, b = d !== void 0 && d, r = e.id, s = e.size, u = e.state, m = e.successMessage, y = L(e, zn), h = Ce().theme, N = He(t), j = We({ baseFontSize: N, size: s }), w = u === x.Error, O = (w || u === x.Valid) && !n, $ = O ? { glyph: w ? "Warning" : "Checkmark", fill: c[h].icon[hn(u)].default, title: w ? "Error" : "Valid" } : void 0;
return l.createElement("div", S({ id: r, "data-lgid": f.feedback, "data-testid": f.feedback, className: k(yn, p(p({}, wn, O), En, b)), "aria-live": "polite", "aria-relevant": "all" }, y), O && l.createElement(l.Fragment, null, $ && l.createElement("div", { className: k(kn, On(s)) }, l.createElement(pn, S({}, $, { "aria-hidden": !0 }))), w ? l.createElement(cn, { "data-lgid": f.errorMessage, "data-testid": f.errorMessage, className: j }, a) : l.createElement(un, { "data-lgid": f.successMessage, "data-testid": f.successMessage, className: j }, m)));
};
Te.displayName = "FormFieldFeedback";
var he, ve, xe, ye, we, Ee, ke, Oe, ze, Ne, je, Fe, Se, Me, Pe, $e, Nn = ["label", "description", "state", "id", "disabled"], jn = ["label", "description", "children", "baseFontSize", "state", "size", "disabled", "errorMessage", "successMessage", "className", "darkMode", "optional", "id"], Fn = Le(function(e, t) {
var n = e.label, a = e.description, d = e.children, b = e.baseFontSize, r = e.state, s = r === void 0 ? x.None : r, u = e.size, m = u === void 0 ? v.Default : u, y = e.disabled, h = y !== void 0 && y, N = e.errorMessage, j = N === void 0 ? ie.error : N, w = e.successMessage, O = w === void 0 ? ie.success : w, $ = e.className, Xe = e.darkMode, Ae = e.optional, Re = e.id, B = L(e, jn), G = He(b), H = We({ baseFontSize: G, size: m }), M = function(F) {
var V, Q = F.label, Ue = F.description, J = F.state, K = F.id, U = F.disabled, P = L(F, Nn), Y = D({ prefix: f.label }), Z = D({ prefix: f.description }), ee = D({ prefix: f.feedback }), Ye = D({ prefix: f.input }), ne = K ?? Ye, Ze = J === x.Error, en = J !== x.None, te = Q ? Y : P["aria-labelledby"], nn = Q || te ? void 0 : P["aria-label"], tn = "".concat(Ue ? Z : "", " ").concat(en ? ee : "").trim(), an = (V = P["aria-invalid"]) !== null && V !== void 0 ? V : Ze;
return { labelId: Y, descriptionId: Z, feedbackId: ee, inputId: ne, inputProps: { id: ne, "aria-labelledby": te, "aria-describedby": tn, "aria-label": nn, "aria-disabled": U, readOnly: P.readOnly ? P.readOnly : U, "aria-invalid": an } };
}(R({ label: n, description: a, state: s, id: Re, disabled: h }, B)), qe = M.labelId, Be = M.descriptionId, Ge = M.feedbackId, Qe = M.inputId, Je = M.inputProps, Ke = { baseFontSize: G, disabled: h, errorMessage: j, id: Ge, size: m, state: s, successMessage: O };
return l.createElement(on, { darkMode: Xe }, l.createElement(mn, { value: { disabled: h, size: m, state: s, inputProps: Je, optional: Ae } }, l.createElement("div", S({ className: k(H, $), ref: t }, B), l.createElement("div", { className: k(vn, p({}, xn, !(!n && !a))) }, n && l.createElement(ln, { "data-testid": f.label, className: H, htmlFor: Qe, id: qe, disabled: h }, n), a && l.createElement(dn, { "data-testid": f.description, className: H, id: Be, disabled: h }, a)), d, l.createElement(Te, Ke))));
});
Fn.displayName = "FormField";
var _ = _e("form-field-input"), C = _e("form-field-icon"), De = function(e) {
return "0 0 0 100px ".concat(e, " inset");
}, Sn = i(he || (he = o([`
display: flex;
align-items: center;
gap: `, `px;
font-size: inherit;
line-height: inherit;
font-family: `, `;
width: 100%;
height: 36px;
font-weight: `, `;
border: 1px solid;
z-index: 1;
outline: none;
border-radius: 6px;
transition: `, `ms ease-in-out;
transition-property: border-color, box-shadow;
z-index: 0;
& .`, ` {
font-family: `, `;
color: inherit;
background-color: inherit;
font-size: inherit;
line-height: inherit;
outline: none;
border: none;
}
& .`, ` svg,
& svg {
min-height: 16px;
min-width: 16px;
}
`])), g[1], ae.default, q.regular, sn.default, _, ae.default, C), Ie = function(e) {
return i(xe || (xe = o([`
@supports selector(:has(a, b)) {
&:focus-within:not(:has(.`, `:focus)) {
`, `
}
}
/* Fallback for when "has" is unsupported */
@supports not selector(:has(a, b)) {
&:focus-within {
`, `
}
}
`])), C, e, e);
}, Mn = p(p({}, A.Light, Ie(`
{
box-shadow: `.concat(re.light.input, `;
border-color: `).concat(X.white, `;
}
`))), A.Dark, Ie(`
{
box-shadow: `.concat(re.dark.input, `;
border-color: `).concat(X.gray.dark4, `;
}
`))), I = "&:has(button.".concat(C, ")"), Pn = p(p(p(p({}, v.XSmall, i(ye || (ye = o([`
height: 22px;
padding-inline: `, `px;
`, ` {
padding-inline-end: `, `px;
}
`])), g[200], I, g[100])), v.Small, i(we || (we = o([`
height: 28px;
padding-inline: `, `px;
`, ` {
padding-inline-end: `, `px;
}
`])), g[200], I, g[100])), v.Default, i(Ee || (Ee = o([`
height: 36px;
padding-inline: `, `px;
`, ` {
padding-inline-end: `, `px;
}
`])), g[300], I, g[150])), v.Large, i(ke || (ke = o([`
height: 48px;
padding-inline: `, `px;
`, ` {
padding-inline-end: `, `px;
}
`])), g[300], I, g[200])), $n = function(e) {
var t = e.disabled, n = e.size, a = e.state, d = e.theme, b = e.className;
return k(Sn, function(r) {
var s = r === A.Dark ? X.gray.dark4 : c.light.background.primary.default;
return i(ve || (ve = o([`
color: `, `;
background: `, `;
border: 1px solid;
& .`, ` {
&:-webkit-autofill {
color: `, `;
background: `, `;
-webkit-text-fill-color: `, `;
box-shadow: `, `;
}
&::placeholder {
font-weight: `, `;
color: `, `;
}
}
`])), c[r].text.primary.default, s, _, c[r].text.primary.default, s, c[r].text.primary.default, De(s), q.regular, c[r].text.placeholder.default);
}(d), Pn[n], p(p({}, k(function(r) {
var s = r.theme, u = r.state;
return p(p(p({}, x.Error, i(Oe || (Oe = o([`
border-color: `, `;
&:hover,
&:active {
&:not(:focus) {
box-shadow: `, `;
}
}
`])), c[s].border.error.default, W[s].red)), x.None, i(ze || (ze = o([`
border-color: `, `;
&:hover,
&:active {
&:not(:focus) {
box-shadow: `, `;
}
}
`])), c[s].border.primary.default, W[s].gray)), x.Valid, i(Ne || (Ne = o([`
border-color: `, `;
&:hover,
&:active {
&:not(:focus) {
box-shadow: `, `;
}
}
`])), c[s].border.success.default, W[s].green))[u];
}({ theme: d, state: a }), Mn[d]), !t), function(r) {
return i(je || (je = o([`
cursor: not-allowed;
color: `, `;
background-color: `, `;
border-color: `, `;
&:hover,
&:active {
&:not(:focus) {
box-shadow: inherit;
}
}
& .`, ` {
cursor: not-allowed;
pointer-events: none;
color: `, `;
&::placeholder {
color: inherit;
}
&:-webkit-autofill {
&,
&:hover,
&:focus {
appearance: none;
-webkit-text-fill-color: `, `;
box-shadow: `, `;
}
&:hover:not(:focus) {
box-shadow: inherit;
}
}
}
`])), c[r].text.disabled.default, c[r].background.disabled.default, c[r].border.disabled.default, _, c[r].text.disabled.default, c[r].text.disabled.hover, De(c[r].background.disabled.hover));
}(d), t), b);
}, Dn = i(Fe || (Fe = o([`
width: 100%;
`]))), In = function(e) {
return k(_, e);
}, Ln = i(Se || (Se = o([`
display: flex;
align-items: center;
gap: `, `px;
`])), g[100]), _n = function(e) {
return i(Me || (Me = o([`
color: `, `;
font-size: 12px;
line-height: 12px;
font-style: italic;
font-weight: `, `;
display: flex;
align-items: center;
> p {
margin: 0;
}
`])), c[e].text.secondary.default, q.regular);
}, Cn = function(e, t, n) {
return k(C, function(a) {
return i(Pe || (Pe = o([`
color: `, `;
`])), c[a].icon.secondary.default);
}(e), p({}, function(a) {
return i($e || ($e = o([`
color: `, `;
&:active,
&:hover {
color: `, `;
}
&:focus {
color: `, `;
}
`])), c[a].icon.disabled.default, c[a].icon.disabled.hover, c[a].icon.disabled.focus);
}(e), t), n);
}, Hn = ["contentEnd", "className", "children"], Vn = Le(function(e, t) {
var n = e.contentEnd, a = e.className, d = e.children, b = L(e, Hn), r = Ce().theme, s = gn(), u = s.disabled, m = s.size, y = s.state, h = s.inputProps, N = s.optional, j = l.cloneElement(d, R(R({}, h), {}, { className: In(d.props.className) })), w = y === x.None && !u && N, O = w || n;
return l.createElement("div", S({}, b, { ref: t, className: $n({ disabled: u, size: m ?? v.Default, state: y, theme: r, className: a }) }), l.createElement("div", { className: Dn }, j), O && l.createElement("div", { className: Ln }, w && l.createElement("div", { "data-lgid": f.optional, "data-testid": f.optional, className: _n(r) }, l.createElement("p", null, "Optional")), n && l.cloneElement(n, p(p({ className: Cn(r, u, n.props.className), disabled: u }, "data-lgid", f.contentEnd), "data-testid", f.contentEnd))));
});
Vn.displayName = "FormFieldInputWrapper";
export {
Vn as A,
x as K,
ie as P,
Fn as j,
Te as s
};