@carbon/react 1.31.0-rc.0 → 1.31.1
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/es/components/AspectRatio/AspectRatio.d.ts +67 -0
- package/es/components/AspectRatio/AspectRatio.js +2 -2
- package/es/components/AspectRatio/index.d.ts +7 -0
- package/es/components/DataTable/DataTable.js +8 -2
- package/es/components/DataTable/Table.d.ts +6 -1
- package/es/components/DataTable/Table.js +78 -3
- package/es/components/DataTable/TableHeader.js +2 -1
- package/es/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
- package/es/components/ExpandableSearch/ExpandableSearch.js +6 -2
- package/es/components/Link/Link.d.ts +53 -0
- package/es/components/Link/Link.js +4 -3
- package/es/components/Link/index.d.ts +9 -0
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +0 -1
- package/es/components/Search/Search.d.ts +4 -0
- package/es/components/Search/Search.js +8 -2
- package/es/components/Select/Select.d.ts +1 -1
- package/es/components/UIShell/HeaderMenuItem.d.ts +22 -0
- package/es/components/UIShell/HeaderMenuItem.js +4 -3
- package/es/components/UIShell/HeaderPanel.js +3 -11
- package/es/components/UIShell/Link.d.ts +48 -0
- package/es/components/UIShell/Link.js +30 -19
- package/es/index.js +2 -2
- package/lib/components/AspectRatio/AspectRatio.d.ts +67 -0
- package/lib/components/AspectRatio/AspectRatio.js +2 -2
- package/lib/components/AspectRatio/index.d.ts +7 -0
- package/lib/components/DataTable/DataTable.js +8 -2
- package/lib/components/DataTable/Table.d.ts +6 -1
- package/lib/components/DataTable/Table.js +78 -2
- package/lib/components/DataTable/TableHeader.js +2 -1
- package/lib/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
- package/lib/components/ExpandableSearch/ExpandableSearch.js +6 -2
- package/lib/components/Link/Link.d.ts +53 -0
- package/lib/components/Link/Link.js +4 -3
- package/lib/components/Link/index.d.ts +9 -0
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +0 -1
- package/lib/components/Search/Search.d.ts +4 -0
- package/lib/components/Search/Search.js +8 -2
- package/lib/components/Select/Select.d.ts +1 -1
- package/lib/components/UIShell/HeaderMenuItem.d.ts +22 -0
- package/lib/components/UIShell/HeaderMenuItem.js +3 -2
- package/lib/components/UIShell/HeaderPanel.js +3 -11
- package/lib/components/UIShell/Link.d.ts +48 -0
- package/lib/components/UIShell/Link.js +29 -18
- package/lib/index.js +4 -4
- package/package.json +9 -9
|
@@ -0,0 +1,48 @@
|
|
|
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 React, { type ElementType, type Ref } from 'react';
|
|
9
|
+
import { type PolymorphicProps } from '../../types/common';
|
|
10
|
+
type LinkBaseProps<E extends ElementType> = {
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `as` instead
|
|
13
|
+
*/
|
|
14
|
+
element?: E | undefined;
|
|
15
|
+
ref?: Ref<E>;
|
|
16
|
+
};
|
|
17
|
+
export type LinkProps<E extends ElementType> = PolymorphicProps<E, LinkBaseProps<E>>;
|
|
18
|
+
/**
|
|
19
|
+
* Link is a custom component that allows us to supporting rendering elements
|
|
20
|
+
* other than `a` in our markup. The goal is to allow users to support passing
|
|
21
|
+
* in their own components to support use-cases like `react-router` or
|
|
22
|
+
* `@reach/router`
|
|
23
|
+
*/
|
|
24
|
+
declare const Link: (<E extends React.ElementType<any> = "a">(props: LinkProps<E>) => JSX.Element) & {
|
|
25
|
+
displayName?: string | undefined;
|
|
26
|
+
propTypes?: React.WeakValidationMap<LinkProps<any>> | undefined;
|
|
27
|
+
};
|
|
28
|
+
declare const LinkPropTypes: {
|
|
29
|
+
/**
|
|
30
|
+
* Provide a custom element or component to render the top-level node for the
|
|
31
|
+
* component.
|
|
32
|
+
*/
|
|
33
|
+
as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
|
|
34
|
+
/**
|
|
35
|
+
* The base element to use to build the link. Defaults to `a`, can also accept
|
|
36
|
+
* alternative tag names or custom components like `Link` from `react-router`.
|
|
37
|
+
* @deprecated Use `as` instead
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
element: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
41
|
+
/**
|
|
42
|
+
* Property to indicate if the side nav container is open (or not). Use to
|
|
43
|
+
* keep local state and styling in step with the SideNav expansion state.
|
|
44
|
+
*/
|
|
45
|
+
isSideNavExpanded: PropTypes.Requireable<boolean>;
|
|
46
|
+
};
|
|
47
|
+
export { LinkPropTypes };
|
|
48
|
+
export default Link;
|
|
@@ -5,8 +5,27 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
8
9
|
import PropTypes from 'prop-types';
|
|
9
|
-
import React__default from 'react';
|
|
10
|
+
import React__default, { forwardRef } from 'react';
|
|
11
|
+
import deprecate from '../../prop-types/deprecate.js';
|
|
12
|
+
|
|
13
|
+
// Note: Maybe we should use `as` instead of `element`? `as` appears to be
|
|
14
|
+
// standard and is used in other places in this project.
|
|
15
|
+
function LinkRenderFunction(_ref, ref) {
|
|
16
|
+
let {
|
|
17
|
+
element,
|
|
18
|
+
as: BaseComponent,
|
|
19
|
+
// Captured here to prevent it from being passed into the created element.
|
|
20
|
+
// See https://github.com/carbon-design-system/carbon/issues/3970
|
|
21
|
+
isSideNavExpanded: _isSideNavExpanded,
|
|
22
|
+
...rest
|
|
23
|
+
} = _ref;
|
|
24
|
+
const BaseComponentAsAny = BaseComponent ?? element ?? 'a';
|
|
25
|
+
return /*#__PURE__*/React__default.createElement(BaseComponentAsAny, _extends({
|
|
26
|
+
ref: ref
|
|
27
|
+
}, rest));
|
|
28
|
+
}
|
|
10
29
|
|
|
11
30
|
/**
|
|
12
31
|
* Link is a custom component that allows us to supporting rendering elements
|
|
@@ -14,24 +33,20 @@ import React__default from 'react';
|
|
|
14
33
|
* in their own components to support use-cases like `react-router` or
|
|
15
34
|
* `@reach/router`
|
|
16
35
|
*/
|
|
17
|
-
const Link = /*#__PURE__*/
|
|
18
|
-
const {
|
|
19
|
-
element,
|
|
20
|
-
isSideNavExpanded,
|
|
21
|
-
// eslint-disable-line no-unused-vars
|
|
22
|
-
...rest
|
|
23
|
-
} = props;
|
|
24
|
-
return /*#__PURE__*/React__default.createElement(element, {
|
|
25
|
-
...rest,
|
|
26
|
-
ref
|
|
27
|
-
});
|
|
28
|
-
});
|
|
36
|
+
const Link = /*#__PURE__*/forwardRef(LinkRenderFunction);
|
|
29
37
|
const LinkPropTypes = {
|
|
38
|
+
/**
|
|
39
|
+
* Provide a custom element or component to render the top-level node for the
|
|
40
|
+
* component.
|
|
41
|
+
*/
|
|
42
|
+
as: PropTypes.elementType,
|
|
30
43
|
/**
|
|
31
44
|
* The base element to use to build the link. Defaults to `a`, can also accept
|
|
32
45
|
* alternative tag names or custom components like `Link` from `react-router`.
|
|
46
|
+
* @deprecated Use `as` instead
|
|
47
|
+
*
|
|
33
48
|
*/
|
|
34
|
-
element: PropTypes.elementType,
|
|
49
|
+
element: deprecate(PropTypes.elementType, 'The `element` prop for `Link` has been deprecated. Please use `as` ' + 'instead. This will be removed in the next major release.'),
|
|
35
50
|
/**
|
|
36
51
|
* Property to indicate if the side nav container is open (or not). Use to
|
|
37
52
|
* keep local state and styling in step with the SideNav expansion state.
|
|
@@ -40,9 +55,5 @@ const LinkPropTypes = {
|
|
|
40
55
|
};
|
|
41
56
|
Link.displayName = 'Link';
|
|
42
57
|
Link.propTypes = LinkPropTypes;
|
|
43
|
-
Link.defaultProps = {
|
|
44
|
-
element: 'a'
|
|
45
|
-
};
|
|
46
|
-
var Link$1 = Link;
|
|
47
58
|
|
|
48
|
-
export { LinkPropTypes, Link
|
|
59
|
+
export { LinkPropTypes, Link as default };
|
package/es/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import './feature-flags.js';
|
|
9
|
+
export { default as AspectRatio } from './components/AspectRatio/AspectRatio.js';
|
|
9
10
|
export { default as Checkbox } from './components/Checkbox/Checkbox.js';
|
|
10
11
|
export { default as CheckboxSkeleton } from './components/Checkbox/Checkbox.Skeleton.js';
|
|
11
12
|
export { ClassPrefix } from './components/ClassPrefix/index.js';
|
|
@@ -27,6 +28,7 @@ export { default as Column } from './components/Grid/Column.js';
|
|
|
27
28
|
export { ColumnHang } from './components/Grid/ColumnHang.js';
|
|
28
29
|
export { default as IconSkeleton } from './components/Icon/Icon.Skeleton.js';
|
|
29
30
|
export { IdPrefix } from './components/IdPrefix/index.js';
|
|
31
|
+
export { default as Link } from './components/Link/Link.js';
|
|
30
32
|
export { default as ListItem } from './components/ListItem/ListItem.js';
|
|
31
33
|
export { MenuButton } from './components/MenuButton/index.js';
|
|
32
34
|
export { default as OrderedList } from './components/OrderedList/OrderedList.js';
|
|
@@ -69,7 +71,6 @@ export { default as unstable_Pagination } from './components/Pagination/experime
|
|
|
69
71
|
export { default as AccordionItem } from './components/Accordion/AccordionItem.js';
|
|
70
72
|
export { default as AccordionSkeleton } from './components/Accordion/Accordion.Skeleton.js';
|
|
71
73
|
export { default as Accordion } from './components/Accordion/Accordion.js';
|
|
72
|
-
export { default as AspectRatio } from './components/AspectRatio/AspectRatio.js';
|
|
73
74
|
export { default as BreadcrumbSkeleton } from './components/Breadcrumb/Breadcrumb.Skeleton.js';
|
|
74
75
|
export { default as CheckboxGroup } from './components/CheckboxGroup/CheckboxGroup.js';
|
|
75
76
|
export { default as CodeSnippetSkeleton } from './components/CodeSnippet/CodeSnippet.Skeleton.js';
|
|
@@ -164,7 +165,6 @@ export { default as DatePickerInput } from './components/DatePickerInput/DatePic
|
|
|
164
165
|
export { ErrorBoundaryContext } from './components/ErrorBoundary/ErrorBoundaryContext.js';
|
|
165
166
|
export { default as FilterableMultiSelect } from './components/MultiSelect/FilterableMultiSelect.js';
|
|
166
167
|
export { default as FormGroup } from './components/FormGroup/FormGroup.js';
|
|
167
|
-
export { default as Link } from './components/Link/Link.js';
|
|
168
168
|
export { Menu } from './components/Menu/Menu.js';
|
|
169
169
|
export { MenuItem, MenuItemDivider, MenuItemGroup, MenuItemRadioGroup, MenuItemSelectable } from './components/Menu/MenuItem.js';
|
|
170
170
|
export { default as Modal } from './components/Modal/Modal.js';
|
|
@@ -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;
|
|
@@ -27,7 +27,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
27
27
|
* This is often useful alongside our grid components, or for media assets like
|
|
28
28
|
* images or videos.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
const AspectRatio = _ref => {
|
|
31
31
|
let {
|
|
32
32
|
as: BaseComponent = 'div',
|
|
33
33
|
className: containerClassName,
|
|
@@ -40,7 +40,7 @@ function AspectRatio(_ref) {
|
|
|
40
40
|
return /*#__PURE__*/React__default["default"].createElement(BaseComponent, _rollupPluginBabelHelpers["extends"]({
|
|
41
41
|
className: className
|
|
42
42
|
}, rest), children);
|
|
43
|
-
}
|
|
43
|
+
};
|
|
44
44
|
AspectRatio.propTypes = {
|
|
45
45
|
/**
|
|
46
46
|
* Provide a custom component or string to be rendered as the outermost node
|
|
@@ -244,7 +244,8 @@ class DataTable extends React__default["default"].Component {
|
|
|
244
244
|
isSortable,
|
|
245
245
|
useStaticWidth,
|
|
246
246
|
stickyHeader,
|
|
247
|
-
overflowMenuOnHover
|
|
247
|
+
overflowMenuOnHover,
|
|
248
|
+
experimentalAutoAlign
|
|
248
249
|
} = this.props;
|
|
249
250
|
return {
|
|
250
251
|
useZebraStyles,
|
|
@@ -252,7 +253,8 @@ class DataTable extends React__default["default"].Component {
|
|
|
252
253
|
isSortable,
|
|
253
254
|
useStaticWidth,
|
|
254
255
|
stickyHeader,
|
|
255
|
-
overflowMenuOnHover
|
|
256
|
+
overflowMenuOnHover,
|
|
257
|
+
experimentalAutoAlign
|
|
256
258
|
};
|
|
257
259
|
});
|
|
258
260
|
_rollupPluginBabelHelpers.defineProperty(this, "getTableContainerProps", () => {
|
|
@@ -631,6 +633,10 @@ class DataTable extends React__default["default"].Component {
|
|
|
631
633
|
}
|
|
632
634
|
}
|
|
633
635
|
_rollupPluginBabelHelpers.defineProperty(DataTable, "propTypes", {
|
|
636
|
+
/**
|
|
637
|
+
* 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
|
|
638
|
+
*/
|
|
639
|
+
experimentalAutoAlign: PropTypes__default["default"].bool,
|
|
634
640
|
/**
|
|
635
641
|
* Optional hook to manually control filtering of the rows from the
|
|
636
642
|
* 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
|
*/
|
|
@@ -13,25 +13,57 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
|
|
|
13
13
|
var React = require('react');
|
|
14
14
|
var PropTypes = require('prop-types');
|
|
15
15
|
var cx = require('classnames');
|
|
16
|
+
var debounce = require('lodash.debounce');
|
|
16
17
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
17
18
|
var TableContext = require('./TableContext.js');
|
|
19
|
+
var useEvent = require('../../internal/useEvent.js');
|
|
18
20
|
|
|
19
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
22
|
|
|
21
23
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
22
24
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
23
25
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
26
|
+
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
24
27
|
|
|
28
|
+
const isElementWrappingContent = (element, context) => {
|
|
29
|
+
if (element.children.length > 0) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const computedStyles = window.getComputedStyle(element);
|
|
33
|
+
context.font = computedStyles.font ? computedStyles.font : `${computedStyles.fontSize}" "${computedStyles.fontFamily}`;
|
|
34
|
+
const measuredText = context?.measureText(element.textContent ?? '');
|
|
35
|
+
let textWidth = measuredText.width ?? 0;
|
|
36
|
+
// account for letter spacing
|
|
37
|
+
const letterSpacing = computedStyles.letterSpacing?.split('px');
|
|
38
|
+
if (letterSpacing && letterSpacing.length && !isNaN(Number(letterSpacing[0]))) {
|
|
39
|
+
textWidth += Number(letterSpacing[0]) * (element.textContent?.length ?? 0);
|
|
40
|
+
}
|
|
41
|
+
// account for padding
|
|
42
|
+
const paddingLeft = computedStyles.paddingLeft?.split('px');
|
|
43
|
+
if (paddingLeft && paddingLeft.length && !isNaN(Number(paddingLeft[0]))) {
|
|
44
|
+
textWidth += Number(paddingLeft[0]);
|
|
45
|
+
}
|
|
46
|
+
const paddingRight = computedStyles.paddingLeft?.split('px');
|
|
47
|
+
if (paddingRight && paddingRight.length && !isNaN(Number(paddingRight[0]))) {
|
|
48
|
+
textWidth += Number(paddingRight[0]);
|
|
49
|
+
}
|
|
50
|
+
// if measured textWidth is larger than the cell's width, then the content is being wrapped
|
|
51
|
+
if (textWidth > element.getBoundingClientRect().width) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
25
56
|
const Table = _ref => {
|
|
26
57
|
let {
|
|
27
58
|
className,
|
|
28
59
|
children,
|
|
29
60
|
useZebraStyles,
|
|
30
|
-
size,
|
|
61
|
+
size = 'lg',
|
|
31
62
|
isSortable = false,
|
|
32
63
|
useStaticWidth,
|
|
33
64
|
stickyHeader,
|
|
34
65
|
overflowMenuOnHover = true,
|
|
66
|
+
experimentalAutoAlign = false,
|
|
35
67
|
...other
|
|
36
68
|
} = _ref;
|
|
37
69
|
const {
|
|
@@ -39,6 +71,7 @@ const Table = _ref => {
|
|
|
39
71
|
descriptionId
|
|
40
72
|
} = React.useContext(TableContext.TableContext);
|
|
41
73
|
const prefix = usePrefix.usePrefix();
|
|
74
|
+
const tableRef = React.useRef(null);
|
|
42
75
|
const componentClass = cx__default["default"](`${prefix}--data-table`, className, {
|
|
43
76
|
[`${prefix}--data-table--${size}`]: size,
|
|
44
77
|
[`${prefix}--data-table--sort`]: isSortable,
|
|
@@ -47,13 +80,52 @@ const Table = _ref => {
|
|
|
47
80
|
[`${prefix}--data-table--sticky-header`]: stickyHeader,
|
|
48
81
|
[`${prefix}--data-table--visible-overflow-menu`]: !overflowMenuOnHover
|
|
49
82
|
});
|
|
83
|
+
const toggleTableBodyAlignmentClass = React.useCallback(function () {
|
|
84
|
+
let alignTop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
85
|
+
alignTop ? tableRef.current?.classList.add(`${prefix}--data-table--top-aligned-body`) : tableRef.current?.classList.remove(`${prefix}--data-table--top-aligned-body`);
|
|
86
|
+
}, [prefix]);
|
|
87
|
+
const toggleTableHeaderAlignmentClass = React.useCallback(function () {
|
|
88
|
+
let alignTop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
89
|
+
alignTop ? tableRef.current?.classList.add(`${prefix}--data-table--top-aligned-header`) : tableRef.current?.classList.remove(`${prefix}--data-table--top-aligned-header`);
|
|
90
|
+
}, [prefix]);
|
|
91
|
+
const setTableAlignment = React.useCallback(() => {
|
|
92
|
+
if (experimentalAutoAlign) {
|
|
93
|
+
const canvas = document.createElement('canvas');
|
|
94
|
+
const context = canvas.getContext('2d');
|
|
95
|
+
if (tableRef.current && context) {
|
|
96
|
+
const isBodyMultiline = Array.from(tableRef.current.querySelectorAll('td')).some(td => isElementWrappingContent(td, context));
|
|
97
|
+
const isHeaderMultiline = Array.from(tableRef.current.querySelectorAll('th')).some(th => {
|
|
98
|
+
const label = th.querySelector(`.${prefix}--table-header-label`);
|
|
99
|
+
return label && isElementWrappingContent(label, context);
|
|
100
|
+
});
|
|
101
|
+
toggleTableBodyAlignmentClass(isBodyMultiline);
|
|
102
|
+
toggleTableHeaderAlignmentClass(isHeaderMultiline);
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
toggleTableBodyAlignmentClass(false);
|
|
106
|
+
toggleTableHeaderAlignmentClass(false);
|
|
107
|
+
}
|
|
108
|
+
}, [experimentalAutoAlign, toggleTableBodyAlignmentClass, toggleTableHeaderAlignmentClass, prefix]);
|
|
109
|
+
const debouncedSetTableAlignment = debounce__default["default"](setTableAlignment, 100);
|
|
110
|
+
useEvent.useWindowEvent('resize', debouncedSetTableAlignment);
|
|
111
|
+
|
|
112
|
+
// recalculate table alignment once fonts have loaded
|
|
113
|
+
if (document?.fonts?.status && document.fonts.status !== 'loaded') {
|
|
114
|
+
document.fonts.ready.then(() => {
|
|
115
|
+
setTableAlignment();
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
React.useLayoutEffect(() => {
|
|
119
|
+
setTableAlignment();
|
|
120
|
+
}, [setTableAlignment, size]);
|
|
50
121
|
const table = /*#__PURE__*/React__default["default"].createElement("div", {
|
|
51
122
|
className: `${prefix}--data-table-content`
|
|
52
123
|
}, /*#__PURE__*/React__default["default"].createElement("table", _rollupPluginBabelHelpers["extends"]({
|
|
53
124
|
"aria-labelledby": titleId,
|
|
54
125
|
"aria-describedby": descriptionId
|
|
55
126
|
}, other, {
|
|
56
|
-
className: componentClass
|
|
127
|
+
className: componentClass,
|
|
128
|
+
ref: tableRef
|
|
57
129
|
}), children));
|
|
58
130
|
return stickyHeader ? /*#__PURE__*/React__default["default"].createElement("section", {
|
|
59
131
|
className: `${prefix}--data-table_inner-container`
|
|
@@ -65,6 +137,10 @@ Table.propTypes = {
|
|
|
65
137
|
*/
|
|
66
138
|
children: PropTypes__default["default"].node,
|
|
67
139
|
className: PropTypes__default["default"].string,
|
|
140
|
+
/**
|
|
141
|
+
* 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
|
|
142
|
+
*/
|
|
143
|
+
experimentalAutoAlign: PropTypes__default["default"].bool,
|
|
68
144
|
/**
|
|
69
145
|
* `false` If true, will apply sorting styles
|
|
70
146
|
*/
|
|
@@ -90,10 +90,11 @@ const TableHeader = /*#__PURE__*/React__default["default"].forwardRef(function T
|
|
|
90
90
|
isSortHeader,
|
|
91
91
|
sortStates: sortStates.sortStates
|
|
92
92
|
});
|
|
93
|
+
const headerClasses = cx__default["default"](headerClassName, `${prefix}--table-sort__header`);
|
|
93
94
|
return /*#__PURE__*/React__default["default"].createElement("th", {
|
|
94
95
|
id: id,
|
|
95
96
|
"aria-sort": ariaSort,
|
|
96
|
-
className:
|
|
97
|
+
className: headerClasses,
|
|
97
98
|
colSpan: colSpan,
|
|
98
99
|
ref: ref,
|
|
99
100
|
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;
|
|
@@ -28,10 +28,12 @@ function ExpandableSearch(_ref) {
|
|
|
28
28
|
onChange,
|
|
29
29
|
onExpand,
|
|
30
30
|
onFocus,
|
|
31
|
+
defaultValue,
|
|
32
|
+
isExpanded,
|
|
31
33
|
...props
|
|
32
34
|
} = _ref;
|
|
33
|
-
const [expanded, setExpanded] = React.useState(false);
|
|
34
|
-
const [hasContent, setHasContent] = React.useState(false);
|
|
35
|
+
const [expanded, setExpanded] = React.useState(isExpanded || false);
|
|
36
|
+
const [hasContent, setHasContent] = React.useState(defaultValue ? true : false);
|
|
35
37
|
const searchRef = React.useRef(null);
|
|
36
38
|
const prefix = usePrefix.usePrefix();
|
|
37
39
|
function handleFocus() {
|
|
@@ -55,6 +57,8 @@ function ExpandableSearch(_ref) {
|
|
|
55
57
|
[`${prefix}--search--expanded`]: expanded
|
|
56
58
|
}, props.className);
|
|
57
59
|
return /*#__PURE__*/React__default["default"].createElement(Search["default"], _rollupPluginBabelHelpers["extends"]({}, props, {
|
|
60
|
+
defaultValue: defaultValue,
|
|
61
|
+
isExpanded: expanded,
|
|
58
62
|
ref: searchRef,
|
|
59
63
|
className: classes,
|
|
60
64
|
onFocus: events.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;
|
|
@@ -31,6 +31,7 @@ const Link = /*#__PURE__*/React__default["default"].forwardRef(function Link(_re
|
|
|
31
31
|
visited = false,
|
|
32
32
|
renderIcon: Icon,
|
|
33
33
|
size,
|
|
34
|
+
target,
|
|
34
35
|
...rest
|
|
35
36
|
} = _ref;
|
|
36
37
|
const prefix = usePrefix.usePrefix();
|
|
@@ -40,7 +41,7 @@ const Link = /*#__PURE__*/React__default["default"].forwardRef(function Link(_re
|
|
|
40
41
|
[`${prefix}--link--visited`]: visited,
|
|
41
42
|
[`${prefix}--link--${size}`]: size
|
|
42
43
|
});
|
|
43
|
-
const rel =
|
|
44
|
+
const rel = target === '_blank' ? 'noopener' : undefined;
|
|
44
45
|
const linkProps = {
|
|
45
46
|
className,
|
|
46
47
|
rel
|
|
@@ -86,6 +87,7 @@ Link.propTypes = {
|
|
|
86
87
|
* Optional prop to render an icon next to the link.
|
|
87
88
|
* Can be a React component class
|
|
88
89
|
*/
|
|
90
|
+
// @ts-expect-error - PropTypes are unable to cover this case.
|
|
89
91
|
renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]),
|
|
90
92
|
/**
|
|
91
93
|
* Specify the size of the Link. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
|
|
@@ -96,6 +98,5 @@ Link.propTypes = {
|
|
|
96
98
|
*/
|
|
97
99
|
visited: PropTypes__default["default"].bool
|
|
98
100
|
};
|
|
99
|
-
var Link$1 = Link;
|
|
100
101
|
|
|
101
|
-
exports["default"] = Link
|
|
102
|
+
exports["default"] = Link;
|
|
@@ -116,7 +116,6 @@ const RadioButtonGroup = /*#__PURE__*/React__default["default"].forwardRef((prop
|
|
|
116
116
|
className: fieldsetClasses,
|
|
117
117
|
disabled: disabled,
|
|
118
118
|
"data-invalid": invalid ? true : undefined,
|
|
119
|
-
"aria-readonly": readOnly,
|
|
120
119
|
"aria-describedby": showHelper && helperText ? helperId : undefined
|
|
121
120
|
}, rest), legendText && /*#__PURE__*/React__default["default"].createElement(index.Legend, {
|
|
122
121
|
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
|
*/
|
|
@@ -39,6 +39,7 @@ const Search = /*#__PURE__*/React__default["default"].forwardRef(function Search
|
|
|
39
39
|
closeButtonLabelText = 'Clear search input',
|
|
40
40
|
defaultValue,
|
|
41
41
|
disabled,
|
|
42
|
+
isExpanded = true,
|
|
42
43
|
id,
|
|
43
44
|
labelText,
|
|
44
45
|
// @ts-expect-error: deprecated prop
|
|
@@ -55,6 +56,7 @@ const Search = /*#__PURE__*/React__default["default"].forwardRef(function Search
|
|
|
55
56
|
value,
|
|
56
57
|
...rest
|
|
57
58
|
} = _ref;
|
|
59
|
+
const hasPropValue = value || defaultValue ? true : false;
|
|
58
60
|
const prefix = usePrefix.usePrefix();
|
|
59
61
|
const {
|
|
60
62
|
isFluid
|
|
@@ -64,7 +66,7 @@ const Search = /*#__PURE__*/React__default["default"].forwardRef(function Search
|
|
|
64
66
|
const inputId = useId.useId('search-input');
|
|
65
67
|
const uniqueId = id || inputId;
|
|
66
68
|
const searchId = `${uniqueId}-search`;
|
|
67
|
-
const [hasContent, setHasContent] = React.useState(
|
|
69
|
+
const [hasContent, setHasContent] = React.useState(hasPropValue || false);
|
|
68
70
|
const [prevValue, setPrevValue] = React.useState(value);
|
|
69
71
|
const searchClasses = cx__default["default"]({
|
|
70
72
|
[`${prefix}--search`]: true,
|
|
@@ -77,7 +79,7 @@ const Search = /*#__PURE__*/React__default["default"].forwardRef(function Search
|
|
|
77
79
|
}, className);
|
|
78
80
|
const clearClasses = cx__default["default"]({
|
|
79
81
|
[`${prefix}--search-close`]: true,
|
|
80
|
-
[`${prefix}--search-close--hidden`]: !hasContent
|
|
82
|
+
[`${prefix}--search-close--hidden`]: !hasContent || !isExpanded
|
|
81
83
|
});
|
|
82
84
|
if (value !== prevValue) {
|
|
83
85
|
setHasContent(!!value);
|
|
@@ -172,6 +174,10 @@ Search.propTypes = {
|
|
|
172
174
|
* Specify a custom `id` for the input
|
|
173
175
|
*/
|
|
174
176
|
id: PropTypes__default["default"].string,
|
|
177
|
+
/**
|
|
178
|
+
* Specify whether or not ExpandableSearch should render expanded or not
|
|
179
|
+
*/
|
|
180
|
+
isExpanded: PropTypes__default["default"].bool,
|
|
175
181
|
/**
|
|
176
182
|
* Provide the label text for the Search icon
|
|
177
183
|
*/
|