@moderneinc/design-system-components 7.8.0-next.c8bbf3 → 7.9.0-next.227c6c

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
@@ -6492,6 +6492,117 @@ const ModSkeleton = ({
6492
6492
  };
6493
6493
  ModSkeleton.displayName = "ModSkeleton";
6494
6494
 
6495
+ const Group = styles.styled("div", {
6496
+ shouldForwardProp: (prop) => prop !== "splitVariant"
6497
+ })(({ theme, splitVariant }) => ({
6498
+ display: "inline-flex",
6499
+ [`& > .${Button.buttonClasses.root}:first-of-type`]: {
6500
+ borderStartEndRadius: 0,
6501
+ borderEndEndRadius: 0
6502
+ },
6503
+ [`& > .${Button.buttonClasses.root}:last-of-type`]: {
6504
+ borderStartStartRadius: 0,
6505
+ borderEndStartRadius: 0,
6506
+ paddingInline: designSystemTokens.spacing.spacing_1,
6507
+ ...splitVariant === "secondary" ? { marginInlineStart: -1 } : (
6508
+ // The label's own colour, so the line reads on every fill, theme and disabled state
6509
+ { borderInlineStart: "1px solid color-mix(in srgb, currentColor 40%, transparent)" }
6510
+ )
6511
+ },
6512
+ // The toggle is narrower than its 44px touch target; grow it away from the main button, not over it
6513
+ [`& > .${Button.buttonClasses.root}:last-of-type::after`]: {
6514
+ [theme.breakpoints.down("md")]: {
6515
+ left: 0,
6516
+ transform: "translateY(-50%)"
6517
+ }
6518
+ },
6519
+ // The focus outline sits outside the button, so the other half would paint over it
6520
+ [`& > .${Button.buttonClasses.focusVisible}`]: {
6521
+ zIndex: 1
6522
+ }
6523
+ }));
6524
+ function ModSplitButton({
6525
+ options,
6526
+ value,
6527
+ defaultValue,
6528
+ onSelect,
6529
+ onValueChange,
6530
+ variant = "primary",
6531
+ size = "medium",
6532
+ disabled,
6533
+ menuLabel = "More options",
6534
+ ...rest
6535
+ }) {
6536
+ const groupRef = react.useRef(null);
6537
+ const menuId = react.useId();
6538
+ const [open, setOpen] = react.useState(false);
6539
+ const [internalValue, setInternalValue] = react.useState(defaultValue ?? options[0]?.value);
6540
+ const current = options.find((option) => option.value === (value ?? internalValue)) ?? options[0];
6541
+ if (!current) {
6542
+ return null;
6543
+ }
6544
+ const pick = (option) => {
6545
+ setOpen(false);
6546
+ if (option !== current.value) {
6547
+ setInternalValue(option);
6548
+ onValueChange?.(option);
6549
+ }
6550
+ onSelect(option);
6551
+ };
6552
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6553
+ /* @__PURE__ */ jsxRuntime.jsxs(Group, { role: "group", ...rest, ref: groupRef, splitVariant: variant, children: [
6554
+ /* @__PURE__ */ jsxRuntime.jsx(
6555
+ ModButton,
6556
+ {
6557
+ variant,
6558
+ size,
6559
+ disabled: disabled || current.disabled,
6560
+ startIcon: current.icon,
6561
+ onClick: () => onSelect(current.value),
6562
+ children: current.label
6563
+ }
6564
+ ),
6565
+ /* @__PURE__ */ jsxRuntime.jsx(
6566
+ ModButton,
6567
+ {
6568
+ variant,
6569
+ size,
6570
+ disabled,
6571
+ "aria-label": menuLabel,
6572
+ "aria-haspopup": "menu",
6573
+ "aria-expanded": open || void 0,
6574
+ "aria-controls": open ? menuId : void 0,
6575
+ onClick: () => setOpen(true),
6576
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { size: designSystemTokens.iconSize.md })
6577
+ }
6578
+ )
6579
+ ] }),
6580
+ /* @__PURE__ */ jsxRuntime.jsx(
6581
+ ModMenu,
6582
+ {
6583
+ id: menuId,
6584
+ open,
6585
+ anchorEl: groupRef.current,
6586
+ onClose: () => setOpen(false),
6587
+ anchorOrigin: { vertical: "bottom", horizontal: "right" },
6588
+ transformOrigin: { vertical: "top", horizontal: "right" },
6589
+ children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
6590
+ ModMenuItem,
6591
+ {
6592
+ icon: option.icon,
6593
+ selected: option.value === current.value,
6594
+ disabled: option.disabled,
6595
+ onClick: () => pick(option.value),
6596
+ children: option.label
6597
+ },
6598
+ option.value
6599
+ ))
6600
+ }
6601
+ )
6602
+ ] });
6603
+ }
6604
+ ModSplitButton.displayName = "ModSplitButton";
6605
+
6495
6606
  const sizePaddingY = {
6496
6607
  small: designSystemTokens.spacing.spacing_3_4,
6497
6608
  medium: designSystemTokens.spacing.spacing_1_1_2
@@ -7597,6 +7708,7 @@ exports.ModSelectField = ModSelectField;
7597
7708
  exports.ModSelectOption = ModMenuItem;
7598
7709
  exports.ModSideNav = ModSideNav;
7599
7710
  exports.ModSkeleton = ModSkeleton;
7711
+ exports.ModSplitButton = ModSplitButton;
7600
7712
  exports.ModStatusBadgeCell = ModStatusBadgeCell;
7601
7713
  exports.ModStatusCell = ModStatusCell;
7602
7714
  exports.ModTab = ModTab;