@cgi-learning-hub/ui
Version:
@cgi-learning-hub/ui is an open-source React component library that implements UI for HUB's features
662 lines (661 loc) • 18.5 kB
JavaScript
import * as b from "react";
import { P as t } from "./index-Sy88PpwE.js";
import { F as A, G as K, H as R, K as r, n as y } from "./identifier-PWESmBq6.js";
import { b as q, u as J, s as f, c as Q, r as X } from "./DefaultPropsProvider-DqazQPtr.js";
import { m as Y } from "./memoTheme-DAFDflPY.js";
import { c as Z } from "./createSimplePaletteValueFilter-B7--0ryQ.js";
import { jsxs as oo, jsx as d } from "react/jsx-runtime";
import { u as to } from "./useId-CK6Kn3Tn.js";
import { B as ao } from "./ButtonBase-6TF6t2SP.js";
import { C as no } from "./CircularProgress-DZuYTFz-.js";
function io(o) {
return K("MuiButton", o);
}
const p = A("MuiButton", ["root", "text", "textInherit", "textPrimary", "textSecondary", "textSuccess", "textError", "textInfo", "textWarning", "outlined", "outlinedInherit", "outlinedPrimary", "outlinedSecondary", "outlinedSuccess", "outlinedError", "outlinedInfo", "outlinedWarning", "contained", "containedInherit", "containedPrimary", "containedSecondary", "containedSuccess", "containedError", "containedInfo", "containedWarning", "disableElevation", "focusVisible", "disabled", "colorInherit", "colorPrimary", "colorSecondary", "colorSuccess", "colorError", "colorInfo", "colorWarning", "textSizeSmall", "textSizeMedium", "textSizeLarge", "outlinedSizeSmall", "outlinedSizeMedium", "outlinedSizeLarge", "containedSizeSmall", "containedSizeMedium", "containedSizeLarge", "sizeMedium", "sizeSmall", "sizeLarge", "fullWidth", "startIcon", "endIcon", "icon", "iconSizeSmall", "iconSizeMedium", "iconSizeLarge", "loading", "loadingWrapper", "loadingIconPlaceholder", "loadingIndicator", "loadingPositionCenter", "loadingPositionStart", "loadingPositionEnd"]), W = /* @__PURE__ */ b.createContext({});
process.env.NODE_ENV !== "production" && (W.displayName = "ButtonGroupContext");
const T = /* @__PURE__ */ b.createContext(void 0);
process.env.NODE_ENV !== "production" && (T.displayName = "ButtonGroupButtonContext");
const ro = (o) => {
const {
color: a,
disableElevation: n,
fullWidth: i,
size: c,
variant: u,
loading: g,
loadingPosition: z,
classes: x
} = o, S = {
root: ["root", g && "loading", u, `${u}${r(a)}`, `size${r(c)}`, `${u}Size${r(c)}`, `color${r(a)}`, n && "disableElevation", i && "fullWidth", g && `loadingPosition${r(z)}`],
startIcon: ["icon", "startIcon", `iconSize${r(c)}`],
endIcon: ["icon", "endIcon", `iconSize${r(c)}`],
loadingIndicator: ["loadingIndicator"],
loadingWrapper: ["loadingWrapper"]
}, I = Q(S, io, x);
return {
...x,
// forward the focused, disabled, etc. classes to the ButtonBase
...I
};
}, L = [{
props: {
size: "small"
},
style: {
"& > *:nth-of-type(1)": {
fontSize: 18
}
}
}, {
props: {
size: "medium"
},
style: {
"& > *:nth-of-type(1)": {
fontSize: 20
}
}
}, {
props: {
size: "large"
},
style: {
"& > *:nth-of-type(1)": {
fontSize: 22
}
}
}], eo = f(ao, {
shouldForwardProp: (o) => X(o) || o === "classes",
name: "MuiButton",
slot: "Root",
overridesResolver: (o, a) => {
const {
ownerState: n
} = o;
return [a.root, a[n.variant], a[`${n.variant}${r(n.color)}`], a[`size${r(n.size)}`], a[`${n.variant}Size${r(n.size)}`], n.color === "inherit" && a.colorInherit, n.disableElevation && a.disableElevation, n.fullWidth && a.fullWidth, n.loading && a.loading];
}
})(Y(({
theme: o
}) => {
const a = o.palette.mode === "light" ? o.palette.grey[300] : o.palette.grey[800], n = o.palette.mode === "light" ? o.palette.grey.A100 : o.palette.grey[700];
return {
...o.typography.button,
minWidth: 64,
padding: "6px 16px",
border: 0,
borderRadius: (o.vars || o).shape.borderRadius,
transition: o.transitions.create(["background-color", "box-shadow", "border-color", "color"], {
duration: o.transitions.duration.short
}),
"&:hover": {
textDecoration: "none"
},
[`&.${p.disabled}`]: {
color: (o.vars || o).palette.action.disabled
},
variants: [{
props: {
variant: "contained"
},
style: {
color: "var(--variant-containedColor)",
backgroundColor: "var(--variant-containedBg)",
boxShadow: (o.vars || o).shadows[2],
"&:hover": {
boxShadow: (o.vars || o).shadows[4],
// Reset on touch devices, it doesn't add specificity
"@media (hover: none)": {
boxShadow: (o.vars || o).shadows[2]
}
},
"&:active": {
boxShadow: (o.vars || o).shadows[8]
},
[`&.${p.focusVisible}`]: {
boxShadow: (o.vars || o).shadows[6]
},
[`&.${p.disabled}`]: {
color: (o.vars || o).palette.action.disabled,
boxShadow: (o.vars || o).shadows[0],
backgroundColor: (o.vars || o).palette.action.disabledBackground
}
}
}, {
props: {
variant: "outlined"
},
style: {
padding: "5px 15px",
border: "1px solid currentColor",
borderColor: "var(--variant-outlinedBorder, currentColor)",
backgroundColor: "var(--variant-outlinedBg)",
color: "var(--variant-outlinedColor)",
[`&.${p.disabled}`]: {
border: `1px solid ${(o.vars || o).palette.action.disabledBackground}`
}
}
}, {
props: {
variant: "text"
},
style: {
padding: "6px 8px",
color: "var(--variant-textColor)",
backgroundColor: "var(--variant-textBg)"
}
}, ...Object.entries(o.palette).filter(Z()).map(([i]) => ({
props: {
color: i
},
style: {
"--variant-textColor": (o.vars || o).palette[i].main,
"--variant-outlinedColor": (o.vars || o).palette[i].main,
"--variant-outlinedBorder": o.vars ? `rgba(${o.vars.palette[i].mainChannel} / 0.5)` : y(o.palette[i].main, 0.5),
"--variant-containedColor": (o.vars || o).palette[i].contrastText,
"--variant-containedBg": (o.vars || o).palette[i].main,
"@media (hover: hover)": {
"&:hover": {
"--variant-containedBg": (o.vars || o).palette[i].dark,
"--variant-textBg": o.vars ? `rgba(${o.vars.palette[i].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : y(o.palette[i].main, o.palette.action.hoverOpacity),
"--variant-outlinedBorder": (o.vars || o).palette[i].main,
"--variant-outlinedBg": o.vars ? `rgba(${o.vars.palette[i].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : y(o.palette[i].main, o.palette.action.hoverOpacity)
}
}
}
})), {
props: {
color: "inherit"
},
style: {
color: "inherit",
borderColor: "currentColor",
"--variant-containedBg": o.vars ? o.vars.palette.Button.inheritContainedBg : a,
"@media (hover: hover)": {
"&:hover": {
"--variant-containedBg": o.vars ? o.vars.palette.Button.inheritContainedHoverBg : n,
"--variant-textBg": o.vars ? `rgba(${o.vars.palette.text.primaryChannel} / ${o.vars.palette.action.hoverOpacity})` : y(o.palette.text.primary, o.palette.action.hoverOpacity),
"--variant-outlinedBg": o.vars ? `rgba(${o.vars.palette.text.primaryChannel} / ${o.vars.palette.action.hoverOpacity})` : y(o.palette.text.primary, o.palette.action.hoverOpacity)
}
}
}
}, {
props: {
size: "small",
variant: "text"
},
style: {
padding: "4px 5px",
fontSize: o.typography.pxToRem(13)
}
}, {
props: {
size: "large",
variant: "text"
},
style: {
padding: "8px 11px",
fontSize: o.typography.pxToRem(15)
}
}, {
props: {
size: "small",
variant: "outlined"
},
style: {
padding: "3px 9px",
fontSize: o.typography.pxToRem(13)
}
}, {
props: {
size: "large",
variant: "outlined"
},
style: {
padding: "7px 21px",
fontSize: o.typography.pxToRem(15)
}
}, {
props: {
size: "small",
variant: "contained"
},
style: {
padding: "4px 10px",
fontSize: o.typography.pxToRem(13)
}
}, {
props: {
size: "large",
variant: "contained"
},
style: {
padding: "8px 22px",
fontSize: o.typography.pxToRem(15)
}
}, {
props: {
disableElevation: !0
},
style: {
boxShadow: "none",
"&:hover": {
boxShadow: "none"
},
[`&.${p.focusVisible}`]: {
boxShadow: "none"
},
"&:active": {
boxShadow: "none"
},
[`&.${p.disabled}`]: {
boxShadow: "none"
}
}
}, {
props: {
fullWidth: !0
},
style: {
width: "100%"
}
}, {
props: {
loadingPosition: "center"
},
style: {
transition: o.transitions.create(["background-color", "box-shadow", "border-color"], {
duration: o.transitions.duration.short
}),
[`&.${p.loading}`]: {
color: "transparent"
}
}
}]
};
})), so = f("span", {
name: "MuiButton",
slot: "StartIcon",
overridesResolver: (o, a) => {
const {
ownerState: n
} = o;
return [a.startIcon, n.loading && a.startIconLoadingStart, a[`iconSize${r(n.size)}`]];
}
})(({
theme: o
}) => ({
display: "inherit",
marginRight: 8,
marginLeft: -4,
variants: [{
props: {
size: "small"
},
style: {
marginLeft: -2
}
}, {
props: {
loadingPosition: "start",
loading: !0
},
style: {
transition: o.transitions.create(["opacity"], {
duration: o.transitions.duration.short
}),
opacity: 0
}
}, {
props: {
loadingPosition: "start",
loading: !0,
fullWidth: !0
},
style: {
marginRight: -8
}
}, ...L]
})), lo = f("span", {
name: "MuiButton",
slot: "EndIcon",
overridesResolver: (o, a) => {
const {
ownerState: n
} = o;
return [a.endIcon, n.loading && a.endIconLoadingEnd, a[`iconSize${r(n.size)}`]];
}
})(({
theme: o
}) => ({
display: "inherit",
marginRight: -4,
marginLeft: 8,
variants: [{
props: {
size: "small"
},
style: {
marginRight: -2
}
}, {
props: {
loadingPosition: "end",
loading: !0
},
style: {
transition: o.transitions.create(["opacity"], {
duration: o.transitions.duration.short
}),
opacity: 0
}
}, {
props: {
loadingPosition: "end",
loading: !0,
fullWidth: !0
},
style: {
marginLeft: -8
}
}, ...L]
})), po = f("span", {
name: "MuiButton",
slot: "LoadingIndicator"
})(({
theme: o
}) => ({
display: "none",
position: "absolute",
visibility: "visible",
variants: [{
props: {
loading: !0
},
style: {
display: "flex"
}
}, {
props: {
loadingPosition: "start"
},
style: {
left: 14
}
}, {
props: {
loadingPosition: "start",
size: "small"
},
style: {
left: 10
}
}, {
props: {
variant: "text",
loadingPosition: "start"
},
style: {
left: 6
}
}, {
props: {
loadingPosition: "center"
},
style: {
left: "50%",
transform: "translate(-50%)",
color: (o.vars || o).palette.action.disabled
}
}, {
props: {
loadingPosition: "end"
},
style: {
right: 14
}
}, {
props: {
loadingPosition: "end",
size: "small"
},
style: {
right: 10
}
}, {
props: {
variant: "text",
loadingPosition: "end"
},
style: {
right: 6
}
}, {
props: {
loadingPosition: "start",
fullWidth: !0
},
style: {
position: "relative",
left: -10
}
}, {
props: {
loadingPosition: "end",
fullWidth: !0
},
style: {
position: "relative",
right: -10
}
}]
})), E = f("span", {
name: "MuiButton",
slot: "LoadingIconPlaceholder"
})({
display: "inline-block",
width: "1em",
height: "1em"
}), co = /* @__PURE__ */ b.forwardRef(function(a, n) {
const i = b.useContext(W), c = b.useContext(T), u = q(i, a), g = J({
props: u,
name: "MuiButton"
}), {
children: z,
color: x = "primary",
component: S = "button",
className: I,
disabled: C = !1,
disableElevation: M = !1,
disableFocusRipple: B = !1,
endIcon: m,
focusVisibleClassName: k,
fullWidth: V = !1,
id: P,
loading: s = null,
loadingIndicator: j,
loadingPosition: v = "center",
size: F = "medium",
startIcon: h,
type: w,
variant: G = "text",
...D
} = g, $ = to(P), O = j ?? /* @__PURE__ */ d(no, {
"aria-labelledby": $,
color: "inherit",
size: 16
}), l = {
...g,
color: x,
component: S,
disabled: C,
disableElevation: M,
disableFocusRipple: B,
fullWidth: V,
loading: s,
loadingIndicator: O,
loadingPosition: v,
size: F,
type: w,
variant: G
}, e = ro(l), U = (h || s && v === "start") && /* @__PURE__ */ d(so, {
className: e.startIcon,
ownerState: l,
children: h || /* @__PURE__ */ d(E, {
className: e.loadingIconPlaceholder,
ownerState: l
})
}), H = (m || s && v === "end") && /* @__PURE__ */ d(lo, {
className: e.endIcon,
ownerState: l,
children: m || /* @__PURE__ */ d(E, {
className: e.loadingIconPlaceholder,
ownerState: l
})
}), _ = c || "", N = typeof s == "boolean" ? (
// use plain HTML span to minimize the runtime overhead
/* @__PURE__ */ d("span", {
className: e.loadingWrapper,
style: {
display: "contents"
},
children: s && /* @__PURE__ */ d(po, {
className: e.loadingIndicator,
ownerState: l,
children: O
})
})
) : null;
return /* @__PURE__ */ oo(eo, {
ownerState: l,
className: R(i.className, e.root, I, _),
component: S,
disabled: C || s,
focusRipple: !B,
focusVisibleClassName: R(e.focusVisible, k),
ref: n,
type: w,
id: s ? $ : P,
...D,
classes: e,
children: [U, v !== "end" && N, z, v === "end" && N, H]
});
});
process.env.NODE_ENV !== "production" && (co.propTypes = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* The content of the component.
*/
children: t.node,
/**
* Override or extend the styles applied to the component.
*/
classes: t.object,
/**
* @ignore
*/
className: t.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 'primary'
*/
color: t.oneOfType([t.oneOf(["inherit", "primary", "secondary", "success", "error", "info", "warning"]), t.string]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: t.elementType,
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: t.bool,
/**
* If `true`, no elevation is used.
* @default false
*/
disableElevation: t.bool,
/**
* If `true`, the keyboard focus ripple is disabled.
* @default false
*/
disableFocusRipple: t.bool,
/**
* If `true`, the ripple effect is disabled.
*
* ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
* to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
* @default false
*/
disableRipple: t.bool,
/**
* Element placed after the children.
*/
endIcon: t.node,
/**
* @ignore
*/
focusVisibleClassName: t.string,
/**
* If `true`, the button will take up the full width of its container.
* @default false
*/
fullWidth: t.bool,
/**
* The URL to link to when the button is clicked.
* If defined, an `a` element will be used as the root node.
*/
href: t.string,
/**
* @ignore
*/
id: t.string,
/**
* If `true`, the loading indicator is visible and the button is disabled.
* If `true | false`, the loading wrapper is always rendered before the children to prevent [Google Translation Crash](https://github.com/mui/material-ui/issues/27853).
* @default null
*/
loading: t.bool,
/**
* Element placed before the children if the button is in loading state.
* The node should contain an element with `role="progressbar"` with an accessible name.
* By default, it renders a `CircularProgress` that is labeled by the button itself.
* @default <CircularProgress color="inherit" size={16} />
*/
loadingIndicator: t.node,
/**
* The loading indicator can be positioned on the start, end, or the center of the button.
* @default 'center'
*/
loadingPosition: t.oneOf(["center", "end", "start"]),
/**
* The size of the component.
* `small` is equivalent to the dense button styling.
* @default 'medium'
*/
size: t.oneOfType([t.oneOf(["small", "medium", "large"]), t.string]),
/**
* Element placed before the children.
*/
startIcon: t.node,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: t.oneOfType([t.arrayOf(t.oneOfType([t.func, t.object, t.bool])), t.func, t.object]),
/**
* @ignore
*/
type: t.oneOfType([t.oneOf(["button", "reset", "submit"]), t.string]),
/**
* The variant to use.
* @default 'text'
*/
variant: t.oneOfType([t.oneOf(["contained", "outlined", "text"]), t.string])
});
export {
co as B
};