UNPKG

@cgi-learning-hub/ui

Version:

@cgi-learning-hub/ui is an open-source React component library that implements UI for HUB's features

467 lines (466 loc) 12.7 kB
import * as Q from "react"; import { P as o } from "./index-B9vkf41S.js"; import { F as S, G as X, H as Y } from "./generateUtilityClasses-B_xKAflz.js"; import { u as F } from "./usePreviousProps-ByGlbpJ6.js"; import { m as w } from "./memoTheme-C-PaH-Cy.js"; import { c as rr } from "./createSimplePaletteValueFilter-B7--0ryQ.js"; import { u as j } from "./useSlot-BSkdRaZr.js"; import { jsxs as or, jsx as ar } from "react/jsx-runtime"; import { u as tr, s as N, c as nr } from "./DefaultPropsProvider-BrmlvPWg.js"; import { c as n } from "./capitalize-BHEX83JQ.js"; function er(a) { const { badgeContent: r, invisible: t = !1, max: e = 99, showZero: l = !1 } = a, f = F({ badgeContent: r, max: e }); let c = t; t === !1 && r === 0 && !l && (c = !0); const { badgeContent: i, max: p = e } = c ? f : a, m = i && Number(i) > p ? `${p}+` : i; return { badgeContent: i, invisible: c, max: p, displayValue: m }; } function ir(a) { return X("MuiBadge", a); } const s = S("MuiBadge", [ "root", "badge", "dot", "standard", "anchorOriginTopRight", "anchorOriginBottomRight", "anchorOriginTopLeft", "anchorOriginBottomLeft", "invisible", "colorError", "colorInfo", "colorPrimary", "colorSecondary", "colorSuccess", "colorWarning", "overlapRectangular", "overlapCircular", // TODO: v6 remove the overlap value from these class keys "anchorOriginTopLeftCircular", "anchorOriginTopLeftRectangular", "anchorOriginTopRightCircular", "anchorOriginTopRightRectangular", "anchorOriginBottomLeftCircular", "anchorOriginBottomLeftRectangular", "anchorOriginBottomRightCircular", "anchorOriginBottomRightRectangular" ]), h = 10, v = 4, sr = (a) => { const { color: r, anchorOrigin: t, invisible: e, overlap: l, variant: f, classes: c = {} } = a, i = { root: ["root"], badge: ["badge", f, e && "invisible", `anchorOrigin${n(t.vertical)}${n(t.horizontal)}`, `anchorOrigin${n(t.vertical)}${n(t.horizontal)}${n(l)}`, `overlap${n(l)}`, r !== "default" && `color${n(r)}`] }; return nr(i, ir, c); }, lr = N("span", { name: "MuiBadge", slot: "Root" })({ position: "relative", display: "inline-flex", // For correct alignment with the text. verticalAlign: "middle", flexShrink: 0 }), cr = N("span", { name: "MuiBadge", slot: "Badge", overridesResolver: (a, r) => { const { ownerState: t } = a; return [r.badge, r[t.variant], r[`anchorOrigin${n(t.anchorOrigin.vertical)}${n(t.anchorOrigin.horizontal)}${n(t.overlap)}`], t.color !== "default" && r[`color${n(t.color)}`], t.invisible && r.invisible]; } })(w(({ theme: a }) => ({ display: "flex", flexDirection: "row", flexWrap: "wrap", justifyContent: "center", alignContent: "center", alignItems: "center", position: "absolute", boxSizing: "border-box", fontFamily: a.typography.fontFamily, fontWeight: a.typography.fontWeightMedium, fontSize: a.typography.pxToRem(12), minWidth: h * 2, lineHeight: 1, padding: "0 6px", height: h * 2, borderRadius: h, zIndex: 1, // Render the badge on top of potential ripples. transition: a.transitions.create("transform", { easing: a.transitions.easing.easeInOut, duration: a.transitions.duration.enteringScreen }), variants: [...Object.entries(a.palette).filter(rr(["contrastText"])).map(([r]) => ({ props: { color: r }, style: { backgroundColor: (a.vars || a).palette[r].main, color: (a.vars || a).palette[r].contrastText } })), { props: { variant: "dot" }, style: { borderRadius: v, height: v * 2, minWidth: v * 2, padding: 0 } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "top" && r.anchorOrigin.horizontal === "right" && r.overlap === "rectangular", style: { top: 0, right: 0, transform: "scale(1) translate(50%, -50%)", transformOrigin: "100% 0%", [`&.${s.invisible}`]: { transform: "scale(0) translate(50%, -50%)" } } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "bottom" && r.anchorOrigin.horizontal === "right" && r.overlap === "rectangular", style: { bottom: 0, right: 0, transform: "scale(1) translate(50%, 50%)", transformOrigin: "100% 100%", [`&.${s.invisible}`]: { transform: "scale(0) translate(50%, 50%)" } } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "top" && r.anchorOrigin.horizontal === "left" && r.overlap === "rectangular", style: { top: 0, left: 0, transform: "scale(1) translate(-50%, -50%)", transformOrigin: "0% 0%", [`&.${s.invisible}`]: { transform: "scale(0) translate(-50%, -50%)" } } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "bottom" && r.anchorOrigin.horizontal === "left" && r.overlap === "rectangular", style: { bottom: 0, left: 0, transform: "scale(1) translate(-50%, 50%)", transformOrigin: "0% 100%", [`&.${s.invisible}`]: { transform: "scale(0) translate(-50%, 50%)" } } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "top" && r.anchorOrigin.horizontal === "right" && r.overlap === "circular", style: { top: "14%", right: "14%", transform: "scale(1) translate(50%, -50%)", transformOrigin: "100% 0%", [`&.${s.invisible}`]: { transform: "scale(0) translate(50%, -50%)" } } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "bottom" && r.anchorOrigin.horizontal === "right" && r.overlap === "circular", style: { bottom: "14%", right: "14%", transform: "scale(1) translate(50%, 50%)", transformOrigin: "100% 100%", [`&.${s.invisible}`]: { transform: "scale(0) translate(50%, 50%)" } } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "top" && r.anchorOrigin.horizontal === "left" && r.overlap === "circular", style: { top: "14%", left: "14%", transform: "scale(1) translate(-50%, -50%)", transformOrigin: "0% 0%", [`&.${s.invisible}`]: { transform: "scale(0) translate(-50%, -50%)" } } }, { props: ({ ownerState: r }) => r.anchorOrigin.vertical === "bottom" && r.anchorOrigin.horizontal === "left" && r.overlap === "circular", style: { bottom: "14%", left: "14%", transform: "scale(1) translate(-50%, 50%)", transformOrigin: "0% 100%", [`&.${s.invisible}`]: { transform: "scale(0) translate(-50%, 50%)" } } }, { props: { invisible: !0 }, style: { transition: a.transitions.create("transform", { easing: a.transitions.easing.easeInOut, duration: a.transitions.duration.leavingScreen }) } }] }))); function D(a) { return { vertical: (a == null ? void 0 : a.vertical) ?? "top", horizontal: (a == null ? void 0 : a.horizontal) ?? "right" }; } const pr = /* @__PURE__ */ Q.forwardRef(function(r, t) { const e = tr({ props: r, name: "MuiBadge" }), { anchorOrigin: l, className: f, classes: c, component: i, components: p = {}, componentsProps: m = {}, children: I, overlap: O = "rectangular", color: y = "default", invisible: A = !1, max: L = 99, badgeContent: T, slots: g, slotProps: d, showZero: x = !1, variant: u = "standard", ...M } = e, { badgeContent: P, invisible: U, max: V, displayValue: W } = er({ max: L, invisible: A, badgeContent: T, showZero: x }), k = F({ anchorOrigin: D(l), color: y, overlap: O, variant: u, badgeContent: T }), R = U || P == null && u !== "dot", { color: H = y, overlap: E = O, anchorOrigin: Z, variant: C = u } = R ? k : e, _ = D(Z), B = C !== "dot" ? W : void 0, b = { ...e, badgeContent: P, invisible: R, max: V, displayValue: B, showZero: x, anchorOrigin: _, color: H, overlap: E, variant: C }, $ = sr(b), z = { slots: { root: (g == null ? void 0 : g.root) ?? p.Root, badge: (g == null ? void 0 : g.badge) ?? p.Badge }, slotProps: { root: (d == null ? void 0 : d.root) ?? m.root, badge: (d == null ? void 0 : d.badge) ?? m.badge } }, [G, q] = j("root", { elementType: lr, externalForwardedProps: { ...z, ...M }, ownerState: b, className: Y($.root, f), ref: t, additionalProps: { as: i } }), [J, K] = j("badge", { elementType: cr, externalForwardedProps: z, ownerState: b, className: $.badge }); return /* @__PURE__ */ or(G, { ...q, children: [I, /* @__PURE__ */ ar(J, { ...K, children: B })] }); }); process.env.NODE_ENV !== "production" && (pr.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the d.ts file and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * The anchor of the badge. * @default { * vertical: 'top', * horizontal: 'right', * } */ anchorOrigin: o.shape({ horizontal: o.oneOf(["left", "right"]), vertical: o.oneOf(["bottom", "top"]) }), /** * The content rendered within the badge. */ badgeContent: o.node, /** * The badge will be added relative to this node. */ children: o.node, /** * Override or extend the styles applied to the component. */ classes: o.object, /** * @ignore */ className: o.string, /** * The color of the component. * It supports both default and custom theme colors, which can be added as shown in the * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors). * @default 'default' */ color: o.oneOfType([o.oneOf(["default", "primary", "secondary", "error", "info", "success", "warning"]), o.string]), /** * The component used for the root node. * Either a string to use a HTML element or a component. */ component: o.elementType, /** * The components used for each slot inside. * * @deprecated use the `slots` prop instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details. * * @default {} */ components: o.shape({ Badge: o.elementType, Root: o.elementType }), /** * The extra props for the slot components. * You can override the existing props or add new ones. * * @deprecated use the `slotProps` prop instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details. * * @default {} */ componentsProps: o.shape({ badge: o.oneOfType([o.func, o.object]), root: o.oneOfType([o.func, o.object]) }), /** * If `true`, the badge is invisible. * @default false */ invisible: o.bool, /** * Max count to show. * @default 99 */ max: o.number, /** * Wrapped shape the badge should overlap. * @default 'rectangular' */ overlap: o.oneOf(["circular", "rectangular"]), /** * Controls whether the badge is hidden when `badgeContent` is zero. * @default false */ showZero: o.bool, /** * The props used for each slot inside. * @default {} */ slotProps: o.shape({ badge: o.oneOfType([o.func, o.object]), root: o.oneOfType([o.func, o.object]) }), /** * The components used for each slot inside. * @default {} */ slots: o.shape({ badge: o.elementType, root: o.elementType }), /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: o.oneOfType([o.arrayOf(o.oneOfType([o.func, o.object, o.bool])), o.func, o.object]), /** * The variant to use. * @default 'standard' */ variant: o.oneOfType([o.oneOf(["dot", "standard"]), o.string]) }); export { pr as B, s as b, ir as g };