@tonycodes-ui/mortar 0.27.0 → 0.28.1

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/icons.d.ts CHANGED
@@ -17,6 +17,8 @@ export declare function Icon({ className, viewBox, fill, stroke, strokeWidth, de
17
17
  children: ReactNode;
18
18
  }): import("react").JSX.Element;
19
19
  export declare function ChevronDown(): import("react").JSX.Element;
20
+ /** Three horizontal dots: the "more actions" trigger of an icon-only menu. */
21
+ export declare function More(): import("react").JSX.Element;
20
22
  export declare function ChevronLeft(): import("react").JSX.Element;
21
23
  export declare function ChevronRight(): import("react").JSX.Element;
22
24
  /**
package/dist/icons.js CHANGED
@@ -13,6 +13,10 @@ function Stroke({ d, width, fill, join = true, }) {
13
13
  export function ChevronDown() {
14
14
  return (_jsx(Icon, { children: _jsx(Stroke, { d: "m6 8 4 4 4-4", width: "1.5" }) }));
15
15
  }
16
+ /** Three horizontal dots: the "more actions" trigger of an icon-only menu. */
17
+ export function More() {
18
+ return (_jsxs(Icon, { fill: "currentColor", children: [_jsx("circle", { cx: "4.5", cy: "10", r: "1.5" }), _jsx("circle", { cx: "10", cy: "10", r: "1.5" }), _jsx("circle", { cx: "15.5", cy: "10", r: "1.5" })] }));
19
+ }
16
20
  export function ChevronLeft() {
17
21
  return (_jsx(Icon, { children: _jsx(Stroke, { d: "m12 5-5 5 5 5", width: "1.75" }) }));
18
22
  }
@@ -185,8 +185,9 @@ export declare function Dropdown({ label, items, icon, iconOnly, variant, align,
185
185
  /** Trigger text, and its accessible name when iconOnly. */
186
186
  label: string;
187
187
  items: DropdownItem[];
188
- /** Trigger icon, e.g. a "more" ellipsis or an avatar. */
188
+ /** Trigger icon, e.g. an avatar. Icon-only triggers default to a "more" ellipsis. */
189
189
  icon?: ReactNode;
190
+ /** Show only the icon; `label` becomes the trigger's accessible name. */
190
191
  iconOnly?: boolean;
191
192
  variant?: "secondary" | "ghost";
192
193
  align?: "start" | "end";
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { KitLink } from "./navigation.js";
3
3
  import { Fragment, forwardRef, useEffect, useId, useLayoutEffect, useRef, useState, } from "react";
4
4
  import { DialogPanel, DialogTitle, Menu, MenuButton, MenuItems, MenuItem, MenuSection, MenuHeading, MenuSeparator, } from "@headlessui/react";
5
- import { ChevronDown, Close } from "./icons.js";
5
+ import { ChevronDown, Close, More } from "./icons.js";
6
6
  import { headingTag } from "./heading.js";
7
7
  import { DialogFrame, FieldFeedback, LinkContent, RequiredMark, Swatch, cx, componentRoot, useComponentName, focusAway, rovingIndex, useDomId, useField, } from "./internal.js";
8
8
  export const Button = forwardRef(function Button({ variant = "primary", loading = false, disabled, children, className, type = "button", size = "md", icon, iconPosition = "start", iconOnly = false, onClick, ...props }, ref) {
@@ -163,6 +163,8 @@ export function Modal({ open, onClose, title, children, actions, size = "md", cl
163
163
  return (_jsx(DialogFrame, { open: open, onClose: onClose, component: component, portal: portal, labelledBy: portal === "contained" ? titleId : undefined, children: _jsx("div", { className: "m-dialog-position", children: portal === "contained" ? (_jsx("div", { className: panelClass, "data-size": panelSize, onClick: (event) => event.stopPropagation(), children: body })) : (_jsx(DialogPanel, { className: panelClass, "data-size": panelSize, children: body })) }) }));
164
164
  }
165
165
  export function Dropdown({ label, items, icon, iconOnly = false, variant = "secondary", align = "end", header, className, }) {
166
+ // An icon-only trigger always has an icon, so it never falls back to its label text.
167
+ const triggerIcon = icon ?? (iconOnly ? _jsx(More, {}) : undefined);
166
168
  const groups = [];
167
169
  for (const item of items) {
168
170
  const last = groups[groups.length - 1];
@@ -175,7 +177,7 @@ export function Dropdown({ label, items, icon, iconOnly = false, variant = "seco
175
177
  const content = (_jsxs(_Fragment, { children: [item.icon && (_jsx("span", { className: "m-menu-icon", "aria-hidden": "true", children: item.icon })), item.description ? (_jsxs("span", { className: "m-menu-text", children: [_jsx("span", { children: item.label }), _jsx("small", { children: item.description })] })) : (item.label)] }));
176
178
  return (_jsx(MenuItem, { disabled: item.disabled, children: item.href ? (_jsx(KitLink, { href: item.href, className: item.danger ? "m-error" : "", children: content })) : (_jsx("button", { type: "button", className: item.danger ? "m-error" : "", onClick: item.onSelect, children: content })) }, item.label));
177
179
  };
178
- return (_jsxs(Menu, { children: [_jsxs(MenuButton, { ...componentRoot("Dropdown"), className: cx("m-button", `m-button-${variant}`, className), "aria-label": iconOnly && icon ? label : undefined, "data-icon-only": iconOnly && icon ? true : undefined, children: [icon && (_jsx("span", { className: "m-button-icon", "aria-hidden": "true", children: icon })), !(iconOnly && icon) && label, !(iconOnly && icon) && (_jsx("span", { className: "m-button-icon", "aria-hidden": "true", children: _jsx(ChevronDown, {}) }))] }), _jsxs(MenuItems, { anchor: `bottom ${align}`, className: "m-menu", children: [header && _jsx("div", { className: "m-menu-header", children: header }), groups.map((group, index) => group.section ? (_jsxs(Fragment, { children: [index > 0 && _jsx(MenuSeparator, { className: "m-menu-separator" }), _jsxs(MenuSection, { children: [_jsx(MenuHeading, { className: "m-menu-heading", children: group.section }), group.items.map(entry)] })] }, `${group.section}:${index}`)) : (_jsxs(Fragment, { children: [index > 0 && _jsx(MenuSeparator, { className: "m-menu-separator" }), group.items.map(entry)] }, `items:${index}`)))] })] }));
180
+ return (_jsxs(Menu, { children: [_jsxs(MenuButton, { ...componentRoot("Dropdown"), className: cx("m-button", `m-button-${variant}`, className), "aria-label": iconOnly ? label : undefined, "data-icon-only": iconOnly ? true : undefined, children: [triggerIcon && (_jsx("span", { className: "m-button-icon", "aria-hidden": "true", children: triggerIcon })), !iconOnly && label, !iconOnly && (_jsx("span", { className: "m-button-icon", "aria-hidden": "true", children: _jsx(ChevronDown, {}) }))] }), _jsxs(MenuItems, { anchor: `bottom ${align}`, className: "m-menu", children: [header && _jsx("div", { className: "m-menu-header", children: header }), groups.map((group, index) => group.section ? (_jsxs(Fragment, { children: [index > 0 && _jsx(MenuSeparator, { className: "m-menu-separator" }), _jsxs(MenuSection, { children: [_jsx(MenuHeading, { className: "m-menu-heading", children: group.section }), group.items.map(entry)] })] }, `${group.section}:${index}`)) : (_jsxs(Fragment, { children: [index > 0 && _jsx(MenuSeparator, { className: "m-menu-separator" }), group.items.map(entry)] }, `items:${index}`)))] })] }));
179
181
  }
180
182
  export function Notice({ title, children, tone = "neutral", announce = false, actions, onDismiss, dismissLabel, id, className, }) {
181
183
  const root = useRef(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonycodes-ui/mortar",
3
- "version": "0.27.0",
3
+ "version": "0.28.1",
4
4
  "description": "Mortar: a shared design foundation, application and marketing UI for React and Tailwind.",
5
5
  "keywords": [
6
6
  "react",
package/src/icons.tsx CHANGED
@@ -75,6 +75,17 @@ export function ChevronDown() {
75
75
  );
76
76
  }
77
77
 
78
+ /** Three horizontal dots: the "more actions" trigger of an icon-only menu. */
79
+ export function More() {
80
+ return (
81
+ <Icon fill="currentColor">
82
+ <circle cx="4.5" cy="10" r="1.5" />
83
+ <circle cx="10" cy="10" r="1.5" />
84
+ <circle cx="15.5" cy="10" r="1.5" />
85
+ </Icon>
86
+ );
87
+ }
88
+
78
89
  export function ChevronLeft() {
79
90
  return (
80
91
  <Icon>
@@ -24,7 +24,7 @@ import {
24
24
  MenuHeading,
25
25
  MenuSeparator,
26
26
  } from "@headlessui/react";
27
- import { ChevronDown, Close } from "./icons.js";
27
+ import { ChevronDown, Close, More } from "./icons.js";
28
28
  import { headingTag, type HeadingLevel } from "./heading.js";
29
29
  import {
30
30
  DialogFrame,
@@ -853,8 +853,9 @@ export function Dropdown({
853
853
  /** Trigger text, and its accessible name when iconOnly. */
854
854
  label: string;
855
855
  items: DropdownItem[];
856
- /** Trigger icon, e.g. a "more" ellipsis or an avatar. */
856
+ /** Trigger icon, e.g. an avatar. Icon-only triggers default to a "more" ellipsis. */
857
857
  icon?: ReactNode;
858
+ /** Show only the icon; `label` becomes the trigger's accessible name. */
858
859
  iconOnly?: boolean;
859
860
  variant?: "secondary" | "ghost";
860
861
  align?: "start" | "end";
@@ -863,6 +864,8 @@ export function Dropdown({
863
864
  /** On the trigger button. */
864
865
  className?: string;
865
866
  }) {
867
+ // An icon-only trigger always has an icon, so it never falls back to its label text.
868
+ const triggerIcon = icon ?? (iconOnly ? <More /> : undefined);
866
869
  const groups: { section?: string; items: DropdownItem[] }[] = [];
867
870
  for (const item of items) {
868
871
  const last = groups[groups.length - 1];
@@ -910,16 +913,16 @@ export function Dropdown({
910
913
  <MenuButton
911
914
  {...componentRoot("Dropdown")}
912
915
  className={cx("m-button", `m-button-${variant}`, className)}
913
- aria-label={iconOnly && icon ? label : undefined}
914
- data-icon-only={iconOnly && icon ? true : undefined}
916
+ aria-label={iconOnly ? label : undefined}
917
+ data-icon-only={iconOnly ? true : undefined}
915
918
  >
916
- {icon && (
919
+ {triggerIcon && (
917
920
  <span className="m-button-icon" aria-hidden="true">
918
- {icon}
921
+ {triggerIcon}
919
922
  </span>
920
923
  )}
921
- {!(iconOnly && icon) && label}
922
- {!(iconOnly && icon) && (
924
+ {!iconOnly && label}
925
+ {!iconOnly && (
923
926
  <span className="m-button-icon" aria-hidden="true">
924
927
  <ChevronDown />
925
928
  </span>