@openzeppelin/ui-components 2.2.0 → 2.3.0

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.cjs CHANGED
@@ -38,7 +38,7 @@ let sonner = require("sonner");
38
38
  let next_themes = require("next-themes");
39
39
 
40
40
  //#region src/version.ts
41
- const VERSION = "2.2.0";
41
+ const VERSION = "2.3.0";
42
42
 
43
43
  //#endregion
44
44
  //#region src/components/ui/accordion.tsx
@@ -190,15 +190,19 @@ function usePrefersHover() {
190
190
  *
191
191
  * // Inline variant (no chip background) — useful inside wallet bars
192
192
  * <AddressDisplay address="0x742d35Cc..." variant="inline" showTooltip showCopyButton />
193
+ *
194
+ * // Truncate only when an alias/label is present (full address when unlabeled)
195
+ * <AddressDisplay address="G..." truncateWhenLabeled />
193
196
  * ```
194
197
  */
195
- function AddressDisplay({ address, truncate = true, untruncateOnHover = false, startChars = 6, endChars = 4, showCopyButton = false, showCopyButtonOnHover = false, explorerUrl, label: labelProp, onLabelEdit: onLabelEditProp, networkId, disableLabel = false, showTooltip = false, variant = "chip", className, onPointerEnter, onPointerLeave, onMouseEnter, onMouseLeave, onClick, ...props }) {
198
+ function AddressDisplay({ address, truncate: truncateProp, truncateWhenLabeled = false, untruncateOnHover = false, startChars = 6, endChars = 4, showCopyButton = false, showCopyButtonOnHover = false, explorerUrl, label: labelProp, onLabelEdit: onLabelEditProp, networkId, disableLabel = false, showTooltip = false, variant = "chip", className, onPointerEnter, onPointerLeave, onMouseEnter, onMouseLeave, onClick, ...props }) {
196
199
  const [copied, setCopied] = react.useState(false);
197
200
  const [isHovered, setIsHovered] = react.useState(false);
198
201
  const copyTimeoutRef = react.useRef(null);
199
202
  const prefersHover = usePrefersHover();
200
203
  const resolver = react.useContext(AddressLabelContext);
201
204
  const resolvedLabel = disableLabel ? void 0 : labelProp ?? resolver?.resolveLabel(address, networkId);
205
+ const effectiveTruncate = truncateProp !== void 0 ? truncateProp : truncateWhenLabeled ? Boolean(resolvedLabel) : true;
202
206
  const contextEditHandler = react.useCallback(() => {
203
207
  resolver?.onEditLabel?.(address, networkId);
204
208
  }, [
@@ -207,10 +211,10 @@ function AddressDisplay({ address, truncate = true, untruncateOnHover = false, s
207
211
  networkId
208
212
  ]);
209
213
  const editHandler = disableLabel ? void 0 : onLabelEditProp ?? (resolver?.onEditLabel ? contextEditHandler : void 0);
210
- const canUntruncate = untruncateOnHover && truncate && !showTooltip;
211
- const showFullAddress = !truncate || canUntruncate && isHovered;
214
+ const canUntruncate = untruncateOnHover && effectiveTruncate && !showTooltip;
215
+ const showFullAddress = !effectiveTruncate || canUntruncate && isHovered;
212
216
  const displayAddress = showFullAddress ? address : (0, _openzeppelin_ui_utils.truncateMiddle)(address, startChars, endChars);
213
- const addressTextClassName = (0, _openzeppelin_ui_utils.cn)(!showFullAddress && "truncate", (showFullAddress || !truncate) && "break-all");
217
+ const addressTextClassName = (0, _openzeppelin_ui_utils.cn)(!showFullAddress && "truncate", (showFullAddress || !effectiveTruncate) && "break-all");
214
218
  const expandInteractionClassName = canUntruncate && !prefersHover ? "cursor-pointer" : void 0;
215
219
  const handlePointerEnter = (e) => {
216
220
  if (canUntruncate && prefersHover) setIsHovered(true);
@@ -272,7 +276,7 @@ function AddressDisplay({ address, truncate = true, untruncateOnHover = false, s
272
276
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Pencil, { className: "h-3.5 w-3.5" })
273
277
  })
274
278
  ] });
275
- const shouldShowTooltip = showTooltip && truncate;
279
+ const shouldShowTooltip = showTooltip && effectiveTruncate;
276
280
  const wrapWithTooltip = (content) => {
277
281
  if (!shouldShowTooltip) return content;
278
282
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipProvider, {