@box/blueprint-web 14.8.2 → 14.8.4

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.
@@ -5,12 +5,33 @@ export interface TooltipConfig {
5
5
  tooltipAriaLabel?: string;
6
6
  }
7
7
  export interface IconBadgeProps extends BadgeProps {
8
- /** The variant of the icon badge. */
9
- variant: 'file-audio' | 'file-bookmark' | 'file-box-app' | 'file-code' | 'file-default' | 'file-drawing' | 'file-excel' | 'file-hub' | 'file-illustrator' | 'file-indesign' | 'file-numbers' | 'file-photoshop' | 'file-powerpoint' | 'file-presentation' | 'file-slides' | 'file-spreadsheet' | 'file-text' | 'file-three-d' | 'file-vector' | 'file-word' | 'file-zip' | 'file-pdf' | 'file-docs' | 'file-sheets' | 'file-image' | 'file-canvas' | 'file-pages' | 'file-keynote' | 'file-boxnote' | 'file-video' | 'folder-external' | 'folder-shared' | 'action-relay' | 'action-mention' | 'action-task' | 'action-taskapproval' | 'action-annotation' | 'action-performed-completed' | 'action-performed-rejected' | 'collaborator-external' | 'collaborator-admin' | 'collaborator-coadmin' | 'content-pin' | 'content-collection' | 'content-offline' | 'content-progress' | 'content-syncing' | 'alert-error' | 'status-pending' | 'status-in-progress' | 'status-forwarded' | 'status-alert';
8
+ /**
9
+ * The variant of the icon badge.
10
+ *
11
+ * When `undefined`, no badge element is rendered but the wrapper stays in
12
+ * the DOM. This lets callers toggle the badge on/off without changing the
13
+ * children's parent element, which would otherwise cause React to unmount
14
+ * and remount the children.
15
+ *
16
+ * Useful when the wrapped child is stateful or expensive to re-initialize
17
+ * (e.g. an `<Avatar>` with a `src` that would be re-fetched, a `<video>`
18
+ * that would lose playback state, or an element that should keep focus).
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * <IconBadge
23
+ * size="large"
24
+ * variant={isAdmin ? 'collaborator-admin' : undefined}
25
+ * >
26
+ * <Avatar src={avatarUrl} ... />
27
+ * </IconBadge>
28
+ * ```
29
+ */
30
+ variant?: 'file-audio' | 'file-bookmark' | 'file-box-app' | 'file-code' | 'file-default' | 'file-drawing' | 'file-excel' | 'file-hub' | 'file-illustrator' | 'file-indesign' | 'file-numbers' | 'file-photoshop' | 'file-powerpoint' | 'file-presentation' | 'file-slides' | 'file-spreadsheet' | 'file-text' | 'file-three-d' | 'file-vector' | 'file-word' | 'file-zip' | 'file-pdf' | 'file-docs' | 'file-sheets' | 'file-image' | 'file-canvas' | 'file-pages' | 'file-keynote' | 'file-boxnote' | 'file-video' | 'folder-external' | 'folder-shared' | 'action-relay' | 'action-mention' | 'action-task' | 'action-taskapproval' | 'action-annotation' | 'action-performed-completed' | 'action-performed-rejected' | 'collaborator-external' | 'collaborator-admin' | 'collaborator-coadmin' | 'content-pin' | 'content-collection' | 'content-offline' | 'content-progress' | 'content-syncing' | 'alert-error' | 'status-pending' | 'status-in-progress' | 'status-forwarded' | 'status-alert';
10
31
  /** Whether to show the tooltip when hovering over the badge. */
11
32
  showTooltipOnBadge?: boolean;
12
33
  /** The configuration for the tooltip, required if showTooltipOnBadge is true. */
13
34
  tooltipConfig?: TooltipConfig;
14
35
  }
15
- export declare const IconBadgeVariants: Array<IconBadgeProps["variant"]>;
36
+ export declare const IconBadgeVariants: Array<NonNullable<IconBadgeProps["variant"]>>;
16
37
  export declare const IconBadge: (props: IconBadgeProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { Alert, ArrowRight, Ellipsis, ClockBadge, Loader, CheckmarkUnderline, Arrow, Pin, Star, GlobeBadge, XMark, Checkmark, Annotation, ApprovalTask, Task, EllipsisBubble, Relay, FolderShared, FolderExternal, FileZip, FileWord, FileVideo, FileVector, FileThreeD, FileText, FileSpreadsheet, FileSlides, FileSheets, FilePresentation, FilePowerpoint, FilePhotoshop, FilePdf, FilePages, FileNumbers, FileKeynote, FileIndesign, FileImage, FileIllustrator, Hubs, FileExcel, FileDrawing, FileDocs, FileDefault, Code, FileCanvas, FileBoxNote, BoxApps, FileBookmark, FileAudio } from '@box/blueprint-web-assets/icons/Fill';
3
3
  import { GrayWhite, SurfaceBadgeAlertSurface, SurfaceBadgeForwardSurface, SurfaceBadgeInprogressSurface, Orange100, SurfaceBadgeErrorSurface, SurfaceBadgeDefaultSurface, SurfaceBadgeProgressSurface, SurfaceBadgeOfflineSurface, Gray80, SurfaceBadgeCollectionSurface, SurfaceBadgePinSurface, SurfaceBadgeCoadminSurface, SurfaceBadgeAdminSurface, SurfaceBadgeExternalSurface, SurfaceBadgeRejectedSurface, SurfaceBadgeCompletedSurface, SurfaceBadgeAnnotationSurface, SurfaceBadgeTaskapprovalSurface, SurfaceBadgeTaskSurface, SurfaceBadgeMentionSurface, SurfaceBadgeRelaySurface, SurfaceBadgeFoldersharedSurface, SurfaceBadgeFolderexternalSurface, SurfaceBadgeZipSurface, SurfaceBadgeWordSurface, SurfaceBadgeVideoSurface, SurfaceBadgeVectorSurface, SurfaceBadgeThreeDSurface, SurfaceBadgeTextSurface, SurfaceBadgeSpreadsheetSurface, GrayBlack, SurfaceBadgeSlidesSurface, SurfaceBadgeSheetsSurface, SurfaceBadgePresentationSurface, SurfaceBadgePowerpointSurface, IconIconPhotoshop, SurfaceBadgePhotoshopSurface, SurfaceBadgePdfSurface, SurfaceBadgePagesSurface, SurfaceBadgeNumbersSurface, SurfaceBadgeKeynoteSurface, IconIconIndesign, SurfaceBadgeIndesignSurface, SurfaceBadgeImageSurface, IconIconIllustrator, SurfaceBadgeIllustratorSurface, SurfaceBadgeHubsSurface, SurfaceBadgeExcelSurface, SurfaceBadgeDrawingSurface, SurfaceBadgeDocsSurface, SurfaceBadgeCodeSurface, SurfaceBadgeCanvasSurface, Gray100, SurfaceBadgeBoxnoteSurface, SurfaceBadgeBoxappsSurface, SurfaceBadgeBookmarkSurface, SurfaceBadgeAudioSurface } from '@box/blueprint-web-assets/tokens/tokens';
4
4
  import clsx from 'clsx';
@@ -281,15 +281,7 @@ const badgeSizeToIconSize = {
281
281
  xlarge: '14px',
282
282
  xxlarge: '18px'
283
283
  };
284
- const IconBadge = props => {
285
- const {
286
- size,
287
- variant,
288
- children,
289
- offset,
290
- showTooltipOnBadge,
291
- tooltipConfig
292
- } = props;
284
+ const renderBadgeElement = (variant, size, offset, showTooltipOnBadge) => {
293
285
  const {
294
286
  backgroundColor,
295
287
  icon,
@@ -297,12 +289,7 @@ const IconBadge = props => {
297
289
  iconStyle
298
290
  } = badgeVariantToIconProps[variant];
299
291
  const iconSize = badgeSizeToIconSize[size];
300
- useSingleChildCheck(children);
301
- const offsetStyle = mapValues(offset, value => {
302
- const num = Number(value);
303
- return Number.isInteger(num) ? `${num - 1}px` : '0';
304
- });
305
- const badge = jsx(BaseBadge, {
292
+ return jsx(BaseBadge, {
306
293
  backgroundColor: backgroundColor,
307
294
  className: styles.iconBadge,
308
295
  offset: showTooltipOnBadge ? undefined : offset,
@@ -315,7 +302,27 @@ const IconBadge = props => {
315
302
  style: iconStyle || {}
316
303
  })
317
304
  });
318
- if (showTooltipOnBadge && tooltipConfig) {
305
+ };
306
+ const IconBadge = props => {
307
+ const {
308
+ size,
309
+ variant,
310
+ children,
311
+ offset,
312
+ showTooltipOnBadge,
313
+ tooltipConfig
314
+ } = props;
315
+ useSingleChildCheck(children);
316
+ const offsetStyle = mapValues(offset, value => {
317
+ const num = Number(value);
318
+ return Number.isInteger(num) ? `${num - 1}px` : '0';
319
+ });
320
+ // When `variant` is omitted, render the wrapper but no badge element.
321
+ // Keeping the wrapper stable lets callers toggle the badge on/off without
322
+ // remounting `children` (which would otherwise re-fetch images, reset
323
+ // videos, restart animations, lose focus, etc.).
324
+ const badge = variant ? renderBadgeElement(variant, size, offset, showTooltipOnBadge) : null;
325
+ if (badge && showTooltipOnBadge && tooltipConfig) {
319
326
  return jsxs("div", {
320
327
  className: styles.badgeContainer,
321
328
  children: [children, jsx(TooltipWrapper, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/blueprint-web",
3
- "version": "14.8.2",
3
+ "version": "14.8.4",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "publishConfig": {
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "@ariakit/react": "0.4.21",
49
49
  "@ariakit/react-core": "0.4.21",
50
- "@box/blueprint-web-assets": "^4.112.7",
50
+ "@box/blueprint-web-assets": "^4.112.9",
51
51
  "@internationalized/date": "^3.12.0",
52
52
  "@radix-ui/react-accordion": "1.1.2",
53
53
  "@radix-ui/react-checkbox": "1.0.4",
@@ -77,7 +77,7 @@
77
77
  "type-fest": "^3.2.0"
78
78
  },
79
79
  "devDependencies": {
80
- "@box/storybook-utils": "^0.17.34",
80
+ "@box/storybook-utils": "^0.17.36",
81
81
  "@figma/code-connect": "1.3.12",
82
82
  "@types/react": "^18.0.0",
83
83
  "@types/react-dom": "^18.0.0",