@carbon/react 1.31.0-rc.0 → 1.31.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.
Files changed (45) hide show
  1. package/es/components/AspectRatio/AspectRatio.d.ts +67 -0
  2. package/es/components/AspectRatio/AspectRatio.js +2 -2
  3. package/es/components/AspectRatio/index.d.ts +7 -0
  4. package/es/components/DataTable/DataTable.js +8 -2
  5. package/es/components/DataTable/Table.d.ts +6 -1
  6. package/es/components/DataTable/Table.js +78 -3
  7. package/es/components/DataTable/TableHeader.js +2 -1
  8. package/es/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
  9. package/es/components/ExpandableSearch/ExpandableSearch.js +6 -2
  10. package/es/components/Link/Link.d.ts +53 -0
  11. package/es/components/Link/Link.js +4 -3
  12. package/es/components/Link/index.d.ts +9 -0
  13. package/es/components/RadioButtonGroup/RadioButtonGroup.js +0 -1
  14. package/es/components/Search/Search.d.ts +4 -0
  15. package/es/components/Search/Search.js +8 -2
  16. package/es/components/Select/Select.d.ts +1 -1
  17. package/es/components/UIShell/HeaderMenuItem.d.ts +22 -0
  18. package/es/components/UIShell/HeaderMenuItem.js +4 -3
  19. package/es/components/UIShell/HeaderPanel.js +3 -11
  20. package/es/components/UIShell/Link.d.ts +48 -0
  21. package/es/components/UIShell/Link.js +30 -19
  22. package/es/index.js +2 -2
  23. package/lib/components/AspectRatio/AspectRatio.d.ts +67 -0
  24. package/lib/components/AspectRatio/AspectRatio.js +2 -2
  25. package/lib/components/AspectRatio/index.d.ts +7 -0
  26. package/lib/components/DataTable/DataTable.js +8 -2
  27. package/lib/components/DataTable/Table.d.ts +6 -1
  28. package/lib/components/DataTable/Table.js +78 -2
  29. package/lib/components/DataTable/TableHeader.js +2 -1
  30. package/lib/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
  31. package/lib/components/ExpandableSearch/ExpandableSearch.js +6 -2
  32. package/lib/components/Link/Link.d.ts +53 -0
  33. package/lib/components/Link/Link.js +4 -3
  34. package/lib/components/Link/index.d.ts +9 -0
  35. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +0 -1
  36. package/lib/components/Search/Search.d.ts +4 -0
  37. package/lib/components/Search/Search.js +8 -2
  38. package/lib/components/Select/Select.d.ts +1 -1
  39. package/lib/components/UIShell/HeaderMenuItem.d.ts +22 -0
  40. package/lib/components/UIShell/HeaderMenuItem.js +3 -2
  41. package/lib/components/UIShell/HeaderPanel.js +3 -11
  42. package/lib/components/UIShell/Link.d.ts +48 -0
  43. package/lib/components/UIShell/Link.js +29 -18
  44. package/lib/index.js +4 -4
  45. package/package.json +10 -9
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import PropTypes from 'prop-types';
8
+ import { PropsWithChildren, ReactHTML } from 'react';
9
+ interface AspectRatioProps {
10
+ /**
11
+ * Provide a custom component or string to be rendered as
12
+ * the outermost node of the component. This is useful if you want
13
+ * to deviate from the default `div` tag, where you could specify
14
+ * `section` or `article` instead.
15
+ *
16
+ * ```jsx
17
+ * <AspectRatio as="article">My content</AspectRatio>
18
+ * ```
19
+ */
20
+ as?: keyof ReactHTML;
21
+ /**
22
+ * Specify a class name for the outermost node
23
+ * of the component.
24
+ */
25
+ className?: string;
26
+ /**
27
+ * Specify the ratio to be used by the aspect ratio
28
+ * container. This will determine what aspect ratio your content
29
+ * will be displayed in.
30
+ */
31
+ ratio?: '1x1' | '2x3' | '3x2' | '3x4' | '4x3' | '1x2' | '2x1' | '9x16' | '16x9';
32
+ }
33
+ /**
34
+ * The AspectRatio component provides a `ratio` prop that will be used to
35
+ * specify the aspect ratio that the children you provide will be displayed in.
36
+ * This is often useful alongside our grid components, or for media assets like
37
+ * images or videos.
38
+ */
39
+ declare const AspectRatio: {
40
+ ({ as: BaseComponent, className: containerClassName, children, ratio, ...rest }: PropsWithChildren<AspectRatioProps>): JSX.Element;
41
+ propTypes: {
42
+ /**
43
+ * Provide a custom component or string to be rendered as the outermost node
44
+ * of the component. This is useful if you want to deviate from the default
45
+ * `div` tag, where you could specify `section` or `article` instead.
46
+ *
47
+ * ```jsx
48
+ * <AspectRatio as="article">My content</AspectRatio>
49
+ * ```
50
+ */
51
+ as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
52
+ /**
53
+ * Specify the content that will be placed in the aspect ratio
54
+ */
55
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
56
+ /**
57
+ * Specify a class name for the outermost node of the component
58
+ */
59
+ className: PropTypes.Requireable<string>;
60
+ /**
61
+ * Specify the ratio to be used by the aspect ratio container. This will
62
+ * determine what aspect ratio your content will be displayed in.
63
+ */
64
+ ratio: PropTypes.Requireable<string>;
65
+ };
66
+ };
67
+ export default AspectRatio;
@@ -17,7 +17,7 @@ import { usePrefix } from '../../internal/usePrefix.js';
17
17
  * This is often useful alongside our grid components, or for media assets like
18
18
  * images or videos.
19
19
  */
20
- function AspectRatio(_ref) {
20
+ const AspectRatio = _ref => {
21
21
  let {
22
22
  as: BaseComponent = 'div',
23
23
  className: containerClassName,
@@ -30,7 +30,7 @@ function AspectRatio(_ref) {
30
30
  return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({
31
31
  className: className
32
32
  }, rest), children);
33
- }
33
+ };
34
34
  AspectRatio.propTypes = {
35
35
  /**
36
36
  * Provide a custom component or string to be rendered as the outermost node
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export { default as AspectRatio } from './AspectRatio';
@@ -234,7 +234,8 @@ class DataTable extends React__default.Component {
234
234
  isSortable,
235
235
  useStaticWidth,
236
236
  stickyHeader,
237
- overflowMenuOnHover
237
+ overflowMenuOnHover,
238
+ experimentalAutoAlign
238
239
  } = this.props;
239
240
  return {
240
241
  useZebraStyles,
@@ -242,7 +243,8 @@ class DataTable extends React__default.Component {
242
243
  isSortable,
243
244
  useStaticWidth,
244
245
  stickyHeader,
245
- overflowMenuOnHover
246
+ overflowMenuOnHover,
247
+ experimentalAutoAlign
246
248
  };
247
249
  });
248
250
  _defineProperty(this, "getTableContainerProps", () => {
@@ -621,6 +623,10 @@ class DataTable extends React__default.Component {
621
623
  }
622
624
  }
623
625
  _defineProperty(DataTable, "propTypes", {
626
+ /**
627
+ * Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
628
+ */
629
+ experimentalAutoAlign: PropTypes.bool,
624
630
  /**
625
631
  * Optional hook to manually control filtering of the rows from the
626
632
  * TableToolbarSearch component
@@ -7,6 +7,7 @@
7
7
  import { PropsWithChildren } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  interface TableProps {
10
+ experimentalAutoAlign?: boolean;
10
11
  className?: string;
11
12
  /**
12
13
  * `false` If true, will apply sorting styles
@@ -34,13 +35,17 @@ interface TableProps {
34
35
  useZebraStyles?: boolean;
35
36
  }
36
37
  export declare const Table: {
37
- ({ className, children, useZebraStyles, size, isSortable, useStaticWidth, stickyHeader, overflowMenuOnHover, ...other }: PropsWithChildren<TableProps>): JSX.Element;
38
+ ({ className, children, useZebraStyles, size, isSortable, useStaticWidth, stickyHeader, overflowMenuOnHover, experimentalAutoAlign, ...other }: PropsWithChildren<TableProps>): JSX.Element;
38
39
  propTypes: {
39
40
  /**
40
41
  * Pass in the children that will be rendered within the Table
41
42
  */
42
43
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
43
44
  className: PropTypes.Requireable<string>;
45
+ /**
46
+ * Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
47
+ */
48
+ experimentalAutoAlign: PropTypes.Requireable<boolean>;
44
49
  /**
45
50
  * `false` If true, will apply sorting styles
46
51
  */
@@ -6,22 +6,53 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useContext } from 'react';
9
+ import React__default, { useContext, useRef, useCallback, useLayoutEffect } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
+ import debounce from 'lodash.debounce';
12
13
  import { usePrefix } from '../../internal/usePrefix.js';
13
14
  import { TableContext } from './TableContext.js';
15
+ import { useWindowEvent } from '../../internal/useEvent.js';
14
16
 
17
+ const isElementWrappingContent = (element, context) => {
18
+ if (element.children.length > 0) {
19
+ return false;
20
+ }
21
+ const computedStyles = window.getComputedStyle(element);
22
+ context.font = computedStyles.font ? computedStyles.font : `${computedStyles.fontSize}" "${computedStyles.fontFamily}`;
23
+ const measuredText = context?.measureText(element.textContent ?? '');
24
+ let textWidth = measuredText.width ?? 0;
25
+ // account for letter spacing
26
+ const letterSpacing = computedStyles.letterSpacing?.split('px');
27
+ if (letterSpacing && letterSpacing.length && !isNaN(Number(letterSpacing[0]))) {
28
+ textWidth += Number(letterSpacing[0]) * (element.textContent?.length ?? 0);
29
+ }
30
+ // account for padding
31
+ const paddingLeft = computedStyles.paddingLeft?.split('px');
32
+ if (paddingLeft && paddingLeft.length && !isNaN(Number(paddingLeft[0]))) {
33
+ textWidth += Number(paddingLeft[0]);
34
+ }
35
+ const paddingRight = computedStyles.paddingLeft?.split('px');
36
+ if (paddingRight && paddingRight.length && !isNaN(Number(paddingRight[0]))) {
37
+ textWidth += Number(paddingRight[0]);
38
+ }
39
+ // if measured textWidth is larger than the cell's width, then the content is being wrapped
40
+ if (textWidth > element.getBoundingClientRect().width) {
41
+ return true;
42
+ }
43
+ return false;
44
+ };
15
45
  const Table = _ref => {
16
46
  let {
17
47
  className,
18
48
  children,
19
49
  useZebraStyles,
20
- size,
50
+ size = 'lg',
21
51
  isSortable = false,
22
52
  useStaticWidth,
23
53
  stickyHeader,
24
54
  overflowMenuOnHover = true,
55
+ experimentalAutoAlign = false,
25
56
  ...other
26
57
  } = _ref;
27
58
  const {
@@ -29,6 +60,7 @@ const Table = _ref => {
29
60
  descriptionId
30
61
  } = useContext(TableContext);
31
62
  const prefix = usePrefix();
63
+ const tableRef = useRef(null);
32
64
  const componentClass = cx(`${prefix}--data-table`, className, {
33
65
  [`${prefix}--data-table--${size}`]: size,
34
66
  [`${prefix}--data-table--sort`]: isSortable,
@@ -37,13 +69,52 @@ const Table = _ref => {
37
69
  [`${prefix}--data-table--sticky-header`]: stickyHeader,
38
70
  [`${prefix}--data-table--visible-overflow-menu`]: !overflowMenuOnHover
39
71
  });
72
+ const toggleTableBodyAlignmentClass = useCallback(function () {
73
+ let alignTop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
74
+ alignTop ? tableRef.current?.classList.add(`${prefix}--data-table--top-aligned-body`) : tableRef.current?.classList.remove(`${prefix}--data-table--top-aligned-body`);
75
+ }, [prefix]);
76
+ const toggleTableHeaderAlignmentClass = useCallback(function () {
77
+ let alignTop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
78
+ alignTop ? tableRef.current?.classList.add(`${prefix}--data-table--top-aligned-header`) : tableRef.current?.classList.remove(`${prefix}--data-table--top-aligned-header`);
79
+ }, [prefix]);
80
+ const setTableAlignment = useCallback(() => {
81
+ if (experimentalAutoAlign) {
82
+ const canvas = document.createElement('canvas');
83
+ const context = canvas.getContext('2d');
84
+ if (tableRef.current && context) {
85
+ const isBodyMultiline = Array.from(tableRef.current.querySelectorAll('td')).some(td => isElementWrappingContent(td, context));
86
+ const isHeaderMultiline = Array.from(tableRef.current.querySelectorAll('th')).some(th => {
87
+ const label = th.querySelector(`.${prefix}--table-header-label`);
88
+ return label && isElementWrappingContent(label, context);
89
+ });
90
+ toggleTableBodyAlignmentClass(isBodyMultiline);
91
+ toggleTableHeaderAlignmentClass(isHeaderMultiline);
92
+ }
93
+ } else {
94
+ toggleTableBodyAlignmentClass(false);
95
+ toggleTableHeaderAlignmentClass(false);
96
+ }
97
+ }, [experimentalAutoAlign, toggleTableBodyAlignmentClass, toggleTableHeaderAlignmentClass, prefix]);
98
+ const debouncedSetTableAlignment = debounce(setTableAlignment, 100);
99
+ useWindowEvent('resize', debouncedSetTableAlignment);
100
+
101
+ // recalculate table alignment once fonts have loaded
102
+ if (document?.fonts?.status && document.fonts.status !== 'loaded') {
103
+ document.fonts.ready.then(() => {
104
+ setTableAlignment();
105
+ });
106
+ }
107
+ useLayoutEffect(() => {
108
+ setTableAlignment();
109
+ }, [setTableAlignment, size]);
40
110
  const table = /*#__PURE__*/React__default.createElement("div", {
41
111
  className: `${prefix}--data-table-content`
42
112
  }, /*#__PURE__*/React__default.createElement("table", _extends({
43
113
  "aria-labelledby": titleId,
44
114
  "aria-describedby": descriptionId
45
115
  }, other, {
46
- className: componentClass
116
+ className: componentClass,
117
+ ref: tableRef
47
118
  }), children));
48
119
  return stickyHeader ? /*#__PURE__*/React__default.createElement("section", {
49
120
  className: `${prefix}--data-table_inner-container`
@@ -55,6 +126,10 @@ Table.propTypes = {
55
126
  */
56
127
  children: PropTypes.node,
57
128
  className: PropTypes.string,
129
+ /**
130
+ * Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
131
+ */
132
+ experimentalAutoAlign: PropTypes.bool,
58
133
  /**
59
134
  * `false` If true, will apply sorting styles
60
135
  */
@@ -80,10 +80,11 @@ const TableHeader = /*#__PURE__*/React__default.forwardRef(function TableHeader(
80
80
  isSortHeader,
81
81
  sortStates
82
82
  });
83
+ const headerClasses = cx(headerClassName, `${prefix}--table-sort__header`);
83
84
  return /*#__PURE__*/React__default.createElement("th", {
84
85
  id: id,
85
86
  "aria-sort": ariaSort,
86
- className: headerClassName,
87
+ className: headerClasses,
87
88
  colSpan: colSpan,
88
89
  ref: ref,
89
90
  scope: scope
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import { type SearchProps } from '../Search';
9
- declare function ExpandableSearch({ onBlur, onChange, onExpand, onFocus, ...props }: SearchProps): JSX.Element;
9
+ declare function ExpandableSearch({ onBlur, onChange, onExpand, onFocus, defaultValue, isExpanded, ...props }: SearchProps): JSX.Element;
10
10
  declare namespace ExpandableSearch {
11
11
  var propTypes: React.WeakValidationMap<SearchProps & React.RefAttributes<HTMLInputElement>> | undefined;
12
12
  var displayName: string;
@@ -19,10 +19,12 @@ function ExpandableSearch(_ref) {
19
19
  onChange,
20
20
  onExpand,
21
21
  onFocus,
22
+ defaultValue,
23
+ isExpanded,
22
24
  ...props
23
25
  } = _ref;
24
- const [expanded, setExpanded] = useState(false);
25
- const [hasContent, setHasContent] = useState(false);
26
+ const [expanded, setExpanded] = useState(isExpanded || false);
27
+ const [hasContent, setHasContent] = useState(defaultValue ? true : false);
26
28
  const searchRef = useRef(null);
27
29
  const prefix = usePrefix();
28
30
  function handleFocus() {
@@ -46,6 +48,8 @@ function ExpandableSearch(_ref) {
46
48
  [`${prefix}--search--expanded`]: expanded
47
49
  }, props.className);
48
50
  return /*#__PURE__*/React__default.createElement(Search, _extends({}, props, {
51
+ defaultValue: defaultValue,
52
+ isExpanded: expanded,
49
53
  ref: searchRef,
50
54
  className: classes,
51
55
  onFocus: composeEventHandlers([onFocus, handleFocus]),
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React, { AriaAttributes, ComponentType, HTMLAttributeAnchorTarget } from 'react';
8
+ interface LinkProps {
9
+ /**
10
+ * @description Indicates the element that represents the
11
+ * current item within a container or set of related
12
+ * elements.
13
+ */
14
+ 'aria-current'?: AriaAttributes['aria-current'];
15
+ /**
16
+ * @description Provide a custom className to be applied to
17
+ * the containing `<a>` node.
18
+ */
19
+ className?: string;
20
+ /**
21
+ * @description Specify if the control should be disabled, or not.
22
+ */
23
+ disabled?: boolean;
24
+ /**
25
+ * @description Provide the `href` attribute for the `<a>` node.
26
+ */
27
+ href?: string;
28
+ /**
29
+ * @description Specify whether you want the inline version of this control.
30
+ */
31
+ inline?: boolean;
32
+ /**
33
+ * @description Optional prop to render an icon next to the link.
34
+ * Can be a React component class
35
+ */
36
+ renderIcon?: ComponentType;
37
+ /**
38
+ * Specify the size of the Link. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
39
+ */
40
+ size?: 'sm' | 'md' | 'lg';
41
+ /**
42
+ * @description Specify the target attribute for the `<a>` node.
43
+ */
44
+ target?: HTMLAttributeAnchorTarget;
45
+ /**
46
+ * Specify whether you want the link to receive visited styles after the link has been clicked
47
+ */
48
+ visited?: boolean;
49
+ }
50
+ declare const Link: React.ForwardRefExoticComponent<LinkProps & {
51
+ children?: React.ReactNode;
52
+ } & React.RefAttributes<HTMLAnchorElement>>;
53
+ export default Link;
@@ -21,6 +21,7 @@ const Link = /*#__PURE__*/React__default.forwardRef(function Link(_ref, ref) {
21
21
  visited = false,
22
22
  renderIcon: Icon,
23
23
  size,
24
+ target,
24
25
  ...rest
25
26
  } = _ref;
26
27
  const prefix = usePrefix();
@@ -30,7 +31,7 @@ const Link = /*#__PURE__*/React__default.forwardRef(function Link(_ref, ref) {
30
31
  [`${prefix}--link--visited`]: visited,
31
32
  [`${prefix}--link--${size}`]: size
32
33
  });
33
- const rel = rest.target === '_blank' ? 'noopener' : null;
34
+ const rel = target === '_blank' ? 'noopener' : undefined;
34
35
  const linkProps = {
35
36
  className,
36
37
  rel
@@ -76,6 +77,7 @@ Link.propTypes = {
76
77
  * Optional prop to render an icon next to the link.
77
78
  * Can be a React component class
78
79
  */
80
+ // @ts-expect-error - PropTypes are unable to cover this case.
79
81
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
80
82
  /**
81
83
  * Specify the size of the Link. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
@@ -86,6 +88,5 @@ Link.propTypes = {
86
88
  */
87
89
  visited: PropTypes.bool
88
90
  };
89
- var Link$1 = Link;
90
91
 
91
- export { Link$1 as default };
92
+ export { Link as default };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import Link from './Link';
8
+ export default Link;
9
+ export { Link };
@@ -106,7 +106,6 @@ const RadioButtonGroup = /*#__PURE__*/React__default.forwardRef((props, ref) =>
106
106
  className: fieldsetClasses,
107
107
  disabled: disabled,
108
108
  "data-invalid": invalid ? true : undefined,
109
- "aria-readonly": readOnly,
110
109
  "aria-describedby": showHelper && helperText ? helperId : undefined
111
110
  }, rest), legendText && /*#__PURE__*/React__default.createElement(Legend, {
112
111
  className: `${prefix}--label`
@@ -28,6 +28,10 @@ export interface SearchProps extends InputPropsBase {
28
28
  * Specify whether the `<input>` should be disabled
29
29
  */
30
30
  disabled?: boolean;
31
+ /**
32
+ * Specify whether or not ExpandableSearch should render expanded or not
33
+ */
34
+ isExpanded?: boolean;
31
35
  /**
32
36
  * Specify a custom `id` for the input
33
37
  */
@@ -29,6 +29,7 @@ const Search = /*#__PURE__*/React__default.forwardRef(function Search(_ref, forw
29
29
  closeButtonLabelText = 'Clear search input',
30
30
  defaultValue,
31
31
  disabled,
32
+ isExpanded = true,
32
33
  id,
33
34
  labelText,
34
35
  // @ts-expect-error: deprecated prop
@@ -45,6 +46,7 @@ const Search = /*#__PURE__*/React__default.forwardRef(function Search(_ref, forw
45
46
  value,
46
47
  ...rest
47
48
  } = _ref;
49
+ const hasPropValue = value || defaultValue ? true : false;
48
50
  const prefix = usePrefix();
49
51
  const {
50
52
  isFluid
@@ -54,7 +56,7 @@ const Search = /*#__PURE__*/React__default.forwardRef(function Search(_ref, forw
54
56
  const inputId = useId('search-input');
55
57
  const uniqueId = id || inputId;
56
58
  const searchId = `${uniqueId}-search`;
57
- const [hasContent, setHasContent] = useState(value || defaultValue || false);
59
+ const [hasContent, setHasContent] = useState(hasPropValue || false);
58
60
  const [prevValue, setPrevValue] = useState(value);
59
61
  const searchClasses = cx({
60
62
  [`${prefix}--search`]: true,
@@ -67,7 +69,7 @@ const Search = /*#__PURE__*/React__default.forwardRef(function Search(_ref, forw
67
69
  }, className);
68
70
  const clearClasses = cx({
69
71
  [`${prefix}--search-close`]: true,
70
- [`${prefix}--search-close--hidden`]: !hasContent
72
+ [`${prefix}--search-close--hidden`]: !hasContent || !isExpanded
71
73
  });
72
74
  if (value !== prevValue) {
73
75
  setHasContent(!!value);
@@ -162,6 +164,10 @@ Search.propTypes = {
162
164
  * Specify a custom `id` for the input
163
165
  */
164
166
  id: PropTypes.string,
167
+ /**
168
+ * Specify whether or not ExpandableSearch should render expanded or not
169
+ */
170
+ isExpanded: PropTypes.bool,
165
171
  /**
166
172
  * Provide the label text for the Search icon
167
173
  */
@@ -85,5 +85,5 @@ interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, ExcludedAttr
85
85
  */
86
86
  warnText?: ReactNode;
87
87
  }
88
- declare const Select: React.ForwardRefExoticComponent<Pick<SelectProps, "value" | "children" | "className" | "disabled" | "size" | "form" | "slot" | "style" | "title" | "dir" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoFocus" | "autoComplete" | "multiple" | "key" | "id" | "onAnimationEnd" | "aria-controls" | "aria-expanded" | "onClick" | "onKeyDown" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "inline" | "invalid" | "name" | "readOnly" | "required" | "labelText" | "helperText" | "invalidText" | "hideLabel" | "warn" | "warnText" | "light" | "noLabel"> & React.RefAttributes<HTMLSelectElement>>;
88
+ declare const Select: React.ForwardRefExoticComponent<Pick<SelectProps, "value" | "children" | "className" | "disabled" | "size" | "form" | "slot" | "style" | "title" | "dir" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoFocus" | "autoComplete" | "multiple" | "key" | "id" | "onAnimationEnd" | "aria-controls" | "aria-expanded" | "onClick" | "onKeyDown" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "inline" | "name" | "readOnly" | "required" | "invalid" | "labelText" | "helperText" | "invalidText" | "hideLabel" | "warn" | "warnText" | "light" | "noLabel"> & React.RefAttributes<HTMLSelectElement>>;
89
89
  export default Select;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React, { type ComponentProps, type ReactNode, ElementType } from 'react';
8
+ import { LinkProps } from './Link';
9
+ type HeaderMenuItemProps<E extends ElementType> = LinkProps<E> & {
10
+ className?: string | undefined;
11
+ isActive?: boolean | undefined;
12
+ isCurrentPage?: boolean | undefined;
13
+ 'aria-current'?: string | undefined;
14
+ children: ReactNode;
15
+ role?: ComponentProps<'li'>['role'];
16
+ tabIndex?: number | undefined;
17
+ };
18
+ declare const HeaderMenuItem: (<E extends React.ElementType<any> = "a">(props: HeaderMenuItemProps<E>) => JSX.Element) & {
19
+ displayName?: string | undefined;
20
+ propTypes?: React.WeakValidationMap<HeaderMenuItemProps<any>> | undefined;
21
+ };
22
+ export default HeaderMenuItem;
@@ -7,13 +7,13 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default from 'react';
10
+ import React__default, { forwardRef } from 'react';
11
11
  import cx from 'classnames';
12
12
  import Link, { LinkPropTypes } from './Link.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
  import deprecate from '../../prop-types/deprecate.js';
15
15
 
16
- const HeaderMenuItem = /*#__PURE__*/React__default.forwardRef(function HeaderMenuItem(_ref, ref) {
16
+ function HeaderMenuItemRenderFunction(_ref, ref) {
17
17
  let {
18
18
  className,
19
19
  isActive,
@@ -45,7 +45,8 @@ const HeaderMenuItem = /*#__PURE__*/React__default.forwardRef(function HeaderMen
45
45
  }), /*#__PURE__*/React__default.createElement("span", {
46
46
  className: `${prefix}--text-truncate--end`
47
47
  }, children)));
48
- });
48
+ }
49
+ const HeaderMenuItem = /*#__PURE__*/forwardRef(HeaderMenuItemRenderFunction);
49
50
  HeaderMenuItem.displayName = 'HeaderMenuItem';
50
51
  HeaderMenuItem.propTypes = {
51
52
  /**
@@ -9,38 +9,30 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
9
9
  import React__default from 'react';
10
10
  import cx from 'classnames';
11
11
  import PropTypes from 'prop-types';
12
- import { AriaLabelPropType } from '../../prop-types/AriaPropTypes.js';
13
12
  import { usePrefix } from '../../internal/usePrefix.js';
14
13
 
15
14
  const HeaderPanel = /*#__PURE__*/React__default.forwardRef(function HeaderPanel(_ref, ref) {
16
15
  let {
17
- 'aria-label': ariaLabel,
18
- 'aria-labelledby': ariaLabelledBy,
19
16
  children,
20
17
  className: customClassName,
21
18
  expanded,
22
19
  ...other
23
20
  } = _ref;
24
21
  const prefix = usePrefix();
25
- const accessibilityLabel = {
26
- 'aria-label': ariaLabel,
27
- 'aria-labelledby': ariaLabelledBy
28
- };
29
22
  const className = cx(`${prefix}--header-panel`, {
30
23
  [`${prefix}--header-panel--expanded`]: expanded,
31
24
  [customClassName]: !!customClassName
32
25
  });
33
26
  return /*#__PURE__*/React__default.createElement("div", _extends({}, other, {
34
- className: className
35
- }, accessibilityLabel, {
27
+ className: className,
36
28
  ref: ref
37
29
  }), children);
38
30
  });
39
31
  HeaderPanel.propTypes = {
40
32
  /**
41
- * Required props for accessibility label on the underlying menu
33
+ * The content that will render inside of the `HeaderPanel`
42
34
  */
43
- ...AriaLabelPropType,
35
+ children: PropTypes.node,
44
36
  /**
45
37
  * Optionally provide a custom class to apply to the underlying `<li>` node
46
38
  */