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