@moderneinc/design-system-components 7.8.0 → 7.9.0-next.869ab7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -773,6 +773,7 @@ function ModBreadcrumbs({ children, className }) {
773
773
  );
774
774
  }
775
775
 
776
+ const LABEL_LINE_HEIGHT = 20;
776
777
  const StyledButton = styles.styled(Button, {
777
778
  shouldForwardProp: (prop) => prop !== "buttonVariant" && prop !== "buttonSize"
778
779
  })(({ theme, buttonVariant: variant, buttonSize: size }) => {
@@ -789,24 +790,30 @@ const StyledButton = styles.styled(Button, {
789
790
  }
790
791
  };
791
792
  const sizeStyles = sizeConfig[size];
793
+ const paddingY = (sizeStyles.height - LABEL_LINE_HEIGHT) / 2 - 1;
792
794
  const paddingX = variant === "tertiary" ? 0 : sizeStyles.paddingX;
793
795
  const spinnerSize = size === "small" ? designSystemTokens.iconSize.md : designSystemTokens.iconSize.xl;
794
796
  const disabled = `&.${Button.buttonClasses.disabled}:not(.${Button.buttonClasses.loading})`;
795
797
  const baseStyles = {
796
- height: sizeStyles.height,
797
- padding: `0 ${paddingX}px`,
798
+ // A label that wraps grows the button instead of spilling out of it; fit-content, not auto, so a
799
+ // flex row doesn't stretch it to the row's tallest item
800
+ minHeight: sizeStyles.height,
801
+ height: "fit-content",
802
+ padding: `${paddingY}px ${paddingX}px`,
798
803
  fontFamily: "inherit",
799
804
  fontSize: sizeStyles.fontSize,
800
805
  fontWeight: designSystemTokens.typography.fontWeight.semiBold,
801
806
  letterSpacing: "inherit",
802
807
  lineHeight: "1.25rem",
808
+ textAlign: "center",
803
809
  borderRadius: designSystemTokens.borderRadius.button,
804
810
  textTransform: "none",
805
811
  transition: theme.transitions.create(["background-color", "border-color", "color"], {
806
812
  duration: theme.transitions.duration.short
807
813
  }),
808
814
  position: "relative",
809
- minWidth: "fit-content",
815
+ // Shrinks in a tight row down to its longest word, then wraps
816
+ minWidth: "min-content",
810
817
  gap: designSystemTokens.spacing.spacing_1,
811
818
  ...touchTarget(theme),
812
819
  // `gap` spaces the icons; MUI's slot margins would add to it
@@ -6492,6 +6499,121 @@ const ModSkeleton = ({
6492
6499
  };
6493
6500
  ModSkeleton.displayName = "ModSkeleton";
6494
6501
 
6502
+ const Group = styles.styled("div", {
6503
+ shouldForwardProp: (prop) => prop !== "splitVariant"
6504
+ })(({ theme, splitVariant }) => ({
6505
+ display: "inline-flex",
6506
+ // Both halves match the taller one when the label wraps
6507
+ [`& > .${Button.buttonClasses.root}`]: {
6508
+ height: "auto"
6509
+ },
6510
+ [`& > .${Button.buttonClasses.root}:first-of-type`]: {
6511
+ borderStartEndRadius: 0,
6512
+ borderEndEndRadius: 0
6513
+ },
6514
+ [`& > .${Button.buttonClasses.root}:last-of-type`]: {
6515
+ borderStartStartRadius: 0,
6516
+ borderEndStartRadius: 0,
6517
+ paddingInline: designSystemTokens.spacing.spacing_1,
6518
+ ...splitVariant === "secondary" ? { marginInlineStart: -1 } : (
6519
+ // The label's own colour, so the line reads on every fill, theme and disabled state
6520
+ { borderInlineStart: "1px solid color-mix(in srgb, currentColor 40%, transparent)" }
6521
+ )
6522
+ },
6523
+ // The toggle is narrower than its 44px touch target; grow it away from the main button, not over it
6524
+ [`& > .${Button.buttonClasses.root}:last-of-type::after`]: {
6525
+ [theme.breakpoints.down("md")]: {
6526
+ left: 0,
6527
+ transform: "translateY(-50%)"
6528
+ }
6529
+ },
6530
+ // The focus outline sits outside the button, so the other half would paint over it
6531
+ [`& > .${Button.buttonClasses.focusVisible}`]: {
6532
+ zIndex: 1
6533
+ }
6534
+ }));
6535
+ function ModSplitButton({
6536
+ options,
6537
+ value,
6538
+ defaultValue,
6539
+ onSelect,
6540
+ onValueChange,
6541
+ variant = "primary",
6542
+ size = "medium",
6543
+ disabled,
6544
+ menuLabel = "More options",
6545
+ ...rest
6546
+ }) {
6547
+ const groupRef = react.useRef(null);
6548
+ const menuId = react.useId();
6549
+ const [open, setOpen] = react.useState(false);
6550
+ const [internalValue, setInternalValue] = react.useState(defaultValue ?? options[0]?.value);
6551
+ const current = options.find((option) => option.value === (value ?? internalValue)) ?? options[0];
6552
+ if (!current) {
6553
+ return null;
6554
+ }
6555
+ const pick = (option) => {
6556
+ setOpen(false);
6557
+ if (option !== current.value) {
6558
+ setInternalValue(option);
6559
+ onValueChange?.(option);
6560
+ }
6561
+ onSelect(option);
6562
+ };
6563
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6564
+ /* @__PURE__ */ jsxRuntime.jsxs(Group, { role: "group", ...rest, ref: groupRef, splitVariant: variant, children: [
6565
+ /* @__PURE__ */ jsxRuntime.jsx(
6566
+ ModButton,
6567
+ {
6568
+ variant,
6569
+ size,
6570
+ disabled: disabled || current.disabled,
6571
+ startIcon: current.icon,
6572
+ onClick: () => onSelect(current.value),
6573
+ children: current.label
6574
+ }
6575
+ ),
6576
+ /* @__PURE__ */ jsxRuntime.jsx(
6577
+ ModButton,
6578
+ {
6579
+ variant,
6580
+ size,
6581
+ disabled,
6582
+ "aria-label": menuLabel,
6583
+ "aria-haspopup": "menu",
6584
+ "aria-expanded": open || void 0,
6585
+ "aria-controls": open ? menuId : void 0,
6586
+ onClick: () => setOpen(true),
6587
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { size: designSystemTokens.iconSize.md })
6588
+ }
6589
+ )
6590
+ ] }),
6591
+ /* @__PURE__ */ jsxRuntime.jsx(
6592
+ ModMenu,
6593
+ {
6594
+ id: menuId,
6595
+ open,
6596
+ anchorEl: groupRef.current,
6597
+ onClose: () => setOpen(false),
6598
+ anchorOrigin: { vertical: "bottom", horizontal: "right" },
6599
+ transformOrigin: { vertical: "top", horizontal: "right" },
6600
+ children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
6601
+ ModMenuItem,
6602
+ {
6603
+ icon: option.icon,
6604
+ selected: option.value === current.value,
6605
+ disabled: option.disabled,
6606
+ onClick: () => pick(option.value),
6607
+ children: option.label
6608
+ },
6609
+ option.value
6610
+ ))
6611
+ }
6612
+ )
6613
+ ] });
6614
+ }
6615
+ ModSplitButton.displayName = "ModSplitButton";
6616
+
6495
6617
  const sizePaddingY = {
6496
6618
  small: designSystemTokens.spacing.spacing_3_4,
6497
6619
  medium: designSystemTokens.spacing.spacing_1_1_2
@@ -7597,6 +7719,7 @@ exports.ModSelectField = ModSelectField;
7597
7719
  exports.ModSelectOption = ModMenuItem;
7598
7720
  exports.ModSideNav = ModSideNav;
7599
7721
  exports.ModSkeleton = ModSkeleton;
7722
+ exports.ModSplitButton = ModSplitButton;
7600
7723
  exports.ModStatusBadgeCell = ModStatusBadgeCell;
7601
7724
  exports.ModStatusCell = ModStatusCell;
7602
7725
  exports.ModTab = ModTab;