@box/blueprint-web 6.39.4 → 6.40.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.
@@ -3,7 +3,7 @@ export declare const SearchInput: import("react").ForwardRefExoticComponent<Omit
3
3
  /**
4
4
  * Styled wrapper over an icon button.
5
5
  */
6
- ActionButton: import("react").ForwardRefExoticComponent<Omit<import("../..").IconButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
6
+ ActionButton: import("react").ForwardRefExoticComponent<Omit<import("./types").SearchInputActionButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
7
7
  Controlled: import("react").ForwardRefExoticComponent<Omit<import("./search-input-controlled").SearchInputControlledProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
8
8
  };
9
9
  export type { SearchInputActionButtonProps, SearchInputProps } from './types';
@@ -1,2 +1,3 @@
1
1
  /// <reference types="react" />
2
- export declare const SearchInputActionButton: import("react").ForwardRefExoticComponent<Omit<import("../primitives/icon-button").IconButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
2
+ import { type SearchInputActionButtonProps } from './types';
3
+ export declare const SearchInputActionButton: import("react").ForwardRefExoticComponent<Omit<SearchInputActionButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -1,7 +1,8 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import clsx from 'clsx';
3
- import { forwardRef } from 'react';
3
+ import { forwardRef, useMemo } from 'react';
4
4
  import { IconButton } from '../primitives/icon-button/icon-button.js';
5
+ import { Tooltip } from '../tooltip/tooltip.js';
5
6
  import styles from './search.module.js';
6
7
 
7
8
  const SearchInputActionButton = /*#__PURE__*/forwardRef(function SearchInputActionButton(props, forwardedRef) {
@@ -10,16 +11,26 @@ const SearchInputActionButton = /*#__PURE__*/forwardRef(function SearchInputActi
10
11
  className,
11
12
  onClick,
12
13
  icon,
14
+ searchInputActionButtonTooltip,
13
15
  ...rest
14
16
  } = props;
15
- return jsx(IconButton, {
17
+ // Memoize the props for IconButton
18
+ const iconButtonProps = useMemo(() => ({
16
19
  ...rest,
17
20
  ref: forwardedRef,
18
- "aria-label": ariaLabel,
21
+ 'aria-label': ariaLabel,
19
22
  className: clsx(styles.actionButton, className),
20
- icon: icon,
21
- // <button> onclick fires for clicks and Space/Enter key when focused.
22
- onClick: onClick
23
+ icon,
24
+ onClick
25
+ }), [ariaLabel, className, forwardedRef, icon, onClick, rest]);
26
+ return searchInputActionButtonTooltip ? jsx(Tooltip, {
27
+ "aria-hidden": true,
28
+ content: searchInputActionButtonTooltip,
29
+ children: jsx(IconButton, {
30
+ ...iconButtonProps
31
+ })
32
+ }) : jsx(IconButton, {
33
+ ...iconButtonProps
23
34
  });
24
35
  });
25
36
 
@@ -1,9 +1,10 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { Search } from '@box/blueprint-web-assets/icons/Fill';
3
- import { IconIconOnLightSecondary, IconCtaIcon } from '@box/blueprint-web-assets/tokens/tokens';
3
+ import { IconCtaIcon, IconIconOnLightSecondary } from '@box/blueprint-web-assets/tokens/tokens';
4
4
  import clsx from 'clsx';
5
- import { forwardRef, Children } from 'react';
5
+ import { forwardRef, Children, useMemo } from 'react';
6
6
  import { IconButton } from '../../primitives/icon-button/icon-button.js';
7
+ import { Tooltip } from '../../tooltip/tooltip.js';
7
8
  import { switchCase } from '../../utils/switchCase.js';
8
9
  import { AccessibleXMarkGlobal, AccessibleXMark } from '../search-input.js';
9
10
  import styles from '../search.module.js';
@@ -21,6 +22,7 @@ const SearchInputControlled = /*#__PURE__*/forwardRef((props, forwardedRef) => {
21
22
  searchIconAriaLabel,
22
23
  searchInputAriaLabel,
23
24
  searchInputClearAriaLabel,
25
+ searchInputClearButtonTooltip,
24
26
  value,
25
27
  variant,
26
28
  ...rest
@@ -43,6 +45,15 @@ const SearchInputControlled = /*#__PURE__*/forwardRef((props, forwardedRef) => {
43
45
  };
44
46
  const isGlobal = variant === 'global';
45
47
  const showActionButton = Children.count(children) > 0;
48
+ // Memoize the props for ClearButton
49
+ const clearButtonProps = useMemo(() => ({
50
+ 'aria-label': searchInputClearAriaLabel,
51
+ className: clsx(styles.clearSearchIcon, isGlobal && styles.global, isGlobal && !showActionButton && styles.withoutActionButton),
52
+ color: IconCtaIcon,
53
+ icon: isGlobal ? AccessibleXMarkGlobal : AccessibleXMark,
54
+ onClick: onClearInput,
55
+ size: 'x-small'
56
+ }), [isGlobal, onClearInput, searchInputClearAriaLabel, showActionButton]);
46
57
  return jsxs("div", {
47
58
  className: clsx(styles.search, className),
48
59
  children: [jsx(Search, {
@@ -65,14 +76,15 @@ const SearchInputControlled = /*#__PURE__*/forwardRef((props, forwardedRef) => {
65
76
  placeholder: placeholder,
66
77
  type: "search",
67
78
  value: value
68
- }), !!value && jsx(IconButton, {
69
- "aria-label": searchInputClearAriaLabel,
70
- className: clsx(styles.clearSearchIcon, isGlobal && styles.global, isGlobal && !showActionButton && styles.withoutActionButton),
71
- color: IconCtaIcon,
72
- icon: isGlobal ? AccessibleXMarkGlobal : AccessibleXMark,
73
- onClick: onClearInput,
74
- size: "x-small"
75
- }), isGlobal && showActionButton && children]
79
+ }), !!value && (searchInputClearButtonTooltip ? jsx(Tooltip, {
80
+ "aria-hidden": true,
81
+ content: searchInputClearButtonTooltip,
82
+ children: jsx(IconButton, {
83
+ ...clearButtonProps
84
+ })
85
+ }) : jsx(IconButton, {
86
+ ...clearButtonProps
87
+ })), isGlobal && showActionButton && children]
76
88
  });
77
89
  });
78
90
 
@@ -9,6 +9,10 @@ export interface SearchInputControlledProps extends Omit<SearchInputProps, 'defa
9
9
  * Handler that is called when clear button is clicked or escape key is pressed when input is focused
10
10
  */
11
11
  onClearInput: () => void;
12
+ /**
13
+ * Optional prop to add a tooltip to the clear button with passed string as a content.
14
+ */
15
+ searchInputClearButtonTooltip?: string;
12
16
  /**
13
17
  * Value for controlled search input.
14
18
  *
@@ -49,4 +49,6 @@ export interface SearchInputProps extends Omit<React.ComponentPropsWithRef<'inpu
49
49
  */
50
50
  variant?: 'in-context' | 'global';
51
51
  }
52
- export type SearchInputActionButtonProps = IconButtonProps;
52
+ export type SearchInputActionButtonProps = IconButtonProps & {
53
+ searchInputActionButtonTooltip?: string;
54
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/blueprint-web",
3
- "version": "6.39.4",
3
+ "version": "6.40.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -57,7 +57,7 @@
57
57
  "devDependencies": {
58
58
  "@box/storybook-utils": "^0.0.7"
59
59
  },
60
- "gitHead": "b1a4e21e02e9e622b8169665c5aedc4ca32d2b6e",
60
+ "gitHead": "7093fb899e5f046913702cb36e11fb0a55e5cb17",
61
61
  "module": "lib-esm/index.js",
62
62
  "main": "lib-esm/index.js",
63
63
  "exports": {