@openzeppelin/ui-components 2.1.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.1.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, {
@@ -2042,8 +2046,9 @@ function WizardStepper(props) {
2042
2046
  * @param props - The props for the WizardNavigation component.
2043
2047
  * @returns A React node representing the navigation component.
2044
2048
  */
2045
- function WizardNavigation({ isFirstStep, isLastStep, canProceed = true, onPrevious, onNext, onCancel, extraActions, nextLabel = "Next", lastStepLabel = "Finish", showLastStepPrimary = true, className }) {
2049
+ function WizardNavigation({ isFirstStep, isLastStep, canProceed = true, onPrevious, onNext, onCancel, extraActions, nextLabel = "Next", lastStepLabel = "Finish", onLastStepSecondary, lastStepSecondaryLabel, lastStepSecondaryDisabled, showLastStepPrimary = true, className }) {
2046
2050
  const showPrimary = !isLastStep || showLastStepPrimary;
2051
+ const showSecondary = isLastStep && lastStepSecondaryLabel != null && lastStepSecondaryLabel !== "" && onLastStepSecondary != null;
2047
2052
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2048
2053
  className: (0, _openzeppelin_ui_utils.cn)("flex items-center justify-between", className),
2049
2054
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -2063,13 +2068,24 @@ function WizardNavigation({ isFirstStep, isLastStep, canProceed = true, onPrevio
2063
2068
  })]
2064
2069
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2065
2070
  className: "flex gap-2",
2066
- children: [extraActions, showPrimary && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
2067
- type: "button",
2068
- onClick: onNext,
2069
- disabled: !canProceed,
2070
- className: "gap-2",
2071
- children: [isLastStep ? lastStepLabel : nextLabel, !isLastStep && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRight, { className: "size-4" })]
2072
- })]
2071
+ children: [
2072
+ extraActions,
2073
+ showSecondary && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
2074
+ type: "button",
2075
+ variant: "outline",
2076
+ onClick: onLastStepSecondary,
2077
+ disabled: lastStepSecondaryDisabled ?? false,
2078
+ className: "gap-2",
2079
+ children: lastStepSecondaryLabel
2080
+ }),
2081
+ showPrimary && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
2082
+ type: "button",
2083
+ onClick: onNext,
2084
+ disabled: !canProceed,
2085
+ className: "gap-2",
2086
+ children: [isLastStep ? lastStepLabel : nextLabel, !isLastStep && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRight, { className: "size-4" })]
2087
+ })
2088
+ ]
2073
2089
  })]
2074
2090
  });
2075
2091
  }
@@ -2299,7 +2315,7 @@ function isScrollableNavigationKey(event) {
2299
2315
 
2300
2316
  //#endregion
2301
2317
  //#region src/components/ui/wizard/WizardLayout.tsx
2302
- function PagedLayout({ steps, currentStepIndex, furthestStepIndex: furthestStepIndexProp, onStepChange, onComplete, onLastStepPrimary, onCancel, nextLabel, lastStepLabel, hideLastStepPrimary, navActions, header, variant, className }) {
2318
+ function PagedLayout({ steps, currentStepIndex, furthestStepIndex: furthestStepIndexProp, onStepChange, onComplete, onLastStepPrimary, onCancel, nextLabel, lastStepLabel, onLastStepSecondary, lastStepSecondaryLabel, lastStepSecondaryDisabled, hideLastStepPrimary, navActions, header, variant, className }) {
2303
2319
  const safeIndex = getSafeStepIndex(steps.length, currentStepIndex);
2304
2320
  const resolvedFurthestStepIndex = useFurthestStepIndex(safeIndex, furthestStepIndexProp);
2305
2321
  if (steps.length === 0) return null;
@@ -2333,6 +2349,9 @@ function PagedLayout({ steps, currentStepIndex, furthestStepIndex: furthestStepI
2333
2349
  extraActions: navActions,
2334
2350
  nextLabel,
2335
2351
  lastStepLabel,
2352
+ onLastStepSecondary,
2353
+ lastStepSecondaryLabel,
2354
+ lastStepSecondaryDisabled,
2336
2355
  showLastStepPrimary: !hideLastStepPrimary
2337
2356
  })
2338
2357
  })
@@ -2383,7 +2402,7 @@ function PagedLayout({ steps, currentStepIndex, furthestStepIndex: furthestStepI
2383
2402
  })]
2384
2403
  });
2385
2404
  }
2386
- function ScrollableLayout({ steps, currentStepIndex, onStepChange, header, onComplete, hideScrollableCompleteButton, scrollableCompleteLabel, scrollPadding, className }) {
2405
+ function ScrollableLayout({ steps, currentStepIndex, onStepChange, header, onComplete, hideScrollableCompleteButton, scrollableCompleteLabel, onScrollableSecondary, scrollableSecondaryLabel, scrollableSecondaryDisabled, scrollPadding, className }) {
2387
2406
  const instanceId = (0, react.useId)();
2388
2407
  const scrollRef = (0, react.useRef)(null);
2389
2408
  const sectionId = (0, react.useCallback)((stepId) => `wizard-section-${instanceId}-${stepId}`, [instanceId]);
@@ -2397,6 +2416,9 @@ function ScrollableLayout({ steps, currentStepIndex, onStepChange, header, onCom
2397
2416
  });
2398
2417
  if (steps.length === 0) return null;
2399
2418
  const stepDefs = toStepDefs(steps, activeIndex);
2419
+ const showScrollableSecondary = onScrollableSecondary != null && scrollableSecondaryLabel != null && scrollableSecondaryLabel !== "";
2420
+ const showScrollablePrimary = onComplete != null && !hideScrollableCompleteButton;
2421
+ const showScrollableFooter = showScrollableSecondary || showScrollablePrimary;
2400
2422
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2401
2423
  className: (0, _openzeppelin_ui_utils.cn)("flex h-full gap-6", className),
2402
2424
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -2422,13 +2444,19 @@ function ScrollableLayout({ steps, currentStepIndex, onStepChange, header, onCom
2422
2444
  children: step.component
2423
2445
  }, step.id))
2424
2446
  }),
2425
- onComplete && !hideScrollableCompleteButton && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2426
- className: "flex justify-end pt-8",
2427
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
2447
+ showScrollableFooter && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2448
+ className: "flex justify-end gap-2 pt-8",
2449
+ children: [showScrollableSecondary && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
2450
+ type: "button",
2451
+ variant: "outline",
2452
+ onClick: onScrollableSecondary,
2453
+ disabled: scrollableSecondaryDisabled ?? false,
2454
+ children: scrollableSecondaryLabel
2455
+ }), showScrollablePrimary && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
2428
2456
  type: "button",
2429
2457
  onClick: onComplete,
2430
2458
  children: scrollableCompleteLabel ?? "Finish"
2431
- })
2459
+ })]
2432
2460
  })
2433
2461
  ]
2434
2462
  })]
@@ -2462,6 +2490,9 @@ function WizardLayout(props) {
2462
2490
  onComplete: rest.onComplete,
2463
2491
  hideScrollableCompleteButton: rest.hideScrollableCompleteButton,
2464
2492
  scrollableCompleteLabel: rest.scrollableCompleteLabel,
2493
+ onScrollableSecondary: rest.onScrollableSecondary,
2494
+ scrollableSecondaryLabel: rest.scrollableSecondaryLabel,
2495
+ scrollableSecondaryDisabled: rest.scrollableSecondaryDisabled,
2465
2496
  scrollPadding: rest.scrollPadding,
2466
2497
  className: rest.className
2467
2498
  });