@carbon/react 1.93.0-rc.0 → 1.93.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.
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React, { useState, useRef, useCallback, useEffect } from 'react';
10
+ import React, { useState, useRef, useCallback } from 'react';
11
11
  import cx from 'classnames';
12
12
  import { useResizeObserver } from '../../internal/useResizeObserver.js';
13
13
  import { ChevronDown } from '@carbon/icons-react';
@@ -60,8 +60,6 @@ function CodeSnippet({
60
60
  const codeContentRef = useRef(null);
61
61
  const codeContainerRef = useRef(null);
62
62
  const innerCodeRef = useRef(null);
63
- const [hasLeftOverflow, setHasLeftOverflow] = useState(false);
64
- const [hasRightOverflow, setHasRightOverflow] = useState(false);
65
63
  const getCodeRef = useCallback(() => {
66
64
  if (type === 'single') {
67
65
  return codeContainerRef;
@@ -73,39 +71,13 @@ function CodeSnippet({
73
71
  }
74
72
  }, [type]);
75
73
  const prefix = usePrefix();
76
- const getCodeRefDimensions = useCallback(() => {
77
- const {
78
- clientWidth: codeClientWidth = 0,
79
- scrollLeft: codeScrollLeft = 0,
80
- scrollWidth: codeScrollWidth = 0
81
- } = getCodeRef().current || {};
82
- return {
83
- horizontalOverflow: codeScrollWidth > codeClientWidth,
84
- codeClientWidth,
85
- codeScrollWidth,
86
- codeScrollLeft
87
- };
88
- }, [getCodeRef]);
89
- const handleScroll = useCallback(() => {
90
- if (type === 'inline' || type === 'single' && !codeContainerRef?.current || type === 'multi' && !codeContentRef?.current) {
91
- return;
92
- }
93
- const {
94
- horizontalOverflow,
95
- codeClientWidth,
96
- codeScrollWidth,
97
- codeScrollLeft
98
- } = getCodeRefDimensions();
99
- setHasLeftOverflow(horizontalOverflow && !!codeScrollLeft);
100
- setHasRightOverflow(horizontalOverflow && codeScrollLeft + codeClientWidth !== codeScrollWidth);
101
- }, [type, getCodeRefDimensions]);
102
74
  useResizeObserver({
103
75
  ref: getCodeRef(),
104
76
  onResize: () => {
105
- if (codeContentRef?.current && type === 'multi') {
77
+ if (innerCodeRef?.current && type === 'multi') {
106
78
  const {
107
79
  height
108
- } = codeContentRef.current.getBoundingClientRect();
80
+ } = innerCodeRef.current.getBoundingClientRect();
109
81
  if (maxCollapsedNumberOfRows > 0 && (maxExpandedNumberOfRows <= 0 || maxExpandedNumberOfRows > maxCollapsedNumberOfRows) && height > maxCollapsedNumberOfRows * rowHeightInPixels) {
110
82
  setShouldShowMoreLessBtn(true);
111
83
  } else {
@@ -115,14 +87,8 @@ function CodeSnippet({
115
87
  setExpandedCode(false);
116
88
  }
117
89
  }
118
- if (codeContentRef?.current && type === 'multi' || codeContainerRef?.current && type === 'single') {
119
- handleScroll();
120
- }
121
90
  }
122
91
  });
123
- useEffect(() => {
124
- handleScroll();
125
- }, [handleScroll]);
126
92
  const handleCopyClick = evt => {
127
93
  if (copyText || innerCodeRef?.current) {
128
94
  copy(copyText ?? innerCodeRef?.current?.innerText ?? '');
@@ -137,8 +103,7 @@ function CodeSnippet({
137
103
  [`${prefix}--snippet--expand`]: expandedCode,
138
104
  [`${prefix}--snippet--light`]: light,
139
105
  [`${prefix}--snippet--no-copy`]: hideCopyButton,
140
- [`${prefix}--snippet--wraptext`]: wrapText,
141
- [`${prefix}--snippet--has-right-overflow`]: type == 'multi' && hasRightOverflow
106
+ [`${prefix}--snippet--wraptext`]: wrapText
142
107
  });
143
108
  const expandCodeBtnText = expandedCode ? showLessText : showMoreText;
144
109
  if (type === 'inline') {
@@ -196,18 +161,12 @@ function CodeSnippet({
196
161
  className: `${prefix}--snippet-container`,
197
162
  "aria-label": deprecatedAriaLabel || ariaLabel || 'code-snippet',
198
163
  "aria-readonly": type === 'single' || type === 'multi' ? true : undefined,
199
- "aria-multiline": type === 'multi' ? true : undefined,
200
- onScroll: type === 'single' && handleScroll || undefined
201
- }, containerStyle), /*#__PURE__*/React.createElement("pre", {
202
- ref: codeContentRef,
203
- onScroll: type === 'multi' && handleScroll || undefined
204
- }, /*#__PURE__*/React.createElement("code", {
164
+ "aria-multiline": type === 'multi' ? true : undefined
165
+ }, containerStyle), /*#__PURE__*/React.createElement("pre", _extends({
166
+ ref: codeContentRef
167
+ }, containerStyle), /*#__PURE__*/React.createElement("code", {
205
168
  ref: innerCodeRef
206
- }, children))), hasLeftOverflow && /*#__PURE__*/React.createElement("div", {
207
- className: `${prefix}--snippet__overflow-indicator--left`
208
- }), hasRightOverflow && type !== 'multi' && /*#__PURE__*/React.createElement("div", {
209
- className: `${prefix}--snippet__overflow-indicator--right`
210
- }), !hideCopyButton && /*#__PURE__*/React.createElement(CopyButton, {
169
+ }, children))), !hideCopyButton && /*#__PURE__*/React.createElement(CopyButton, {
211
170
  align: align,
212
171
  autoAlign: autoAlign,
213
172
  size: type === 'multi' ? 'sm' : 'md',
@@ -92,6 +92,7 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
92
92
  isExpanded: boolean;
93
93
  onExpand: (event: MouseEvent<HTMLButtonElement>) => void;
94
94
  [key: string]: unknown;
95
+ id: string;
95
96
  };
96
97
  getRowProps: (options: {
97
98
  onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
@@ -105,6 +106,7 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
105
106
  key: string;
106
107
  onExpand: (event: MouseEvent<HTMLButtonElement>) => void;
107
108
  [key: string]: unknown;
109
+ expandHeader: string;
108
110
  };
109
111
  getExpandedRowProps: (options: {
110
112
  row: DataTableRow<ColTypes>;
@@ -194,9 +194,10 @@ const DataTable = props => {
194
194
  ...rest,
195
195
  'aria-label': t(translationKey),
196
196
  // Provide a string of all expanded row IDs, separated by a space.
197
- 'aria-controls': rowIds.map(id => `expanded-row-${id}`).join(' '),
197
+ 'aria-controls': rowIds.map(id => `${getTablePrefix()}-expanded-row-${id}`).join(' '),
198
198
  isExpanded,
199
- onExpand: composeEventHandlers(handlers)
199
+ onExpand: composeEventHandlers(handlers),
200
+ id: `${getTablePrefix()}-expand`
200
201
  };
201
202
  };
202
203
 
@@ -228,9 +229,10 @@ const DataTable = props => {
228
229
  onExpand: composeEventHandlers([handleOnExpandRow(row.id), onClick]),
229
230
  isExpanded: row.isExpanded,
230
231
  'aria-label': t(translationKey),
231
- 'aria-controls': `expanded-row-${row.id}`,
232
+ 'aria-controls': `${getTablePrefix()}-expanded-row-${row.id}`,
232
233
  isSelected: row.isSelected,
233
- disabled: row.disabled
234
+ disabled: row.disabled,
235
+ expandHeader: `${getTablePrefix()}-expand`
234
236
  };
235
237
  };
236
238
  const getExpandedRowProps = ({
@@ -239,7 +241,7 @@ const DataTable = props => {
239
241
  }) => {
240
242
  return {
241
243
  ...rest,
242
- id: `expanded-row-${row.id}`
244
+ id: `${getTablePrefix()}-expanded-row-${row.id}`
243
245
  };
244
246
  };
245
247
 
@@ -33,6 +33,10 @@ export interface TableRowExpandInteropProps {
33
33
  * Specify if the row is selected.
34
34
  */
35
35
  isSelected?: boolean;
36
+ /**
37
+ * The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43
38
+ */
39
+ expandHeader?: string;
36
40
  }
37
41
  export interface TableExpandRowProps extends PropsWithChildren<Omit<HTMLAttributes<HTMLTableRowElement>, 'onClick'>>, Omit<TableRowExpandInteropProps, 'aria-label' | 'onExpand'> {
38
42
  /**
@@ -31,6 +31,8 @@ const TableRow = frFn((props, ref) => {
31
31
  isExpanded,
32
32
  // eslint-disable-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452
33
33
  isSelected,
34
+ expandHeader,
35
+ // eslint-disable-line @typescript-eslint/no-unused-vars
34
36
  ...cleanProps
35
37
  } = props;
36
38
  const prefix = usePrefix();
@@ -149,7 +149,8 @@ forwardRef) {
149
149
  fallbackAxisSideDirection: 'start',
150
150
  boundary: autoAlignBoundary
151
151
  }), arrow({
152
- element: caretRef
152
+ element: caretRef,
153
+ padding: 16
153
154
  }), autoAlign && hide()],
154
155
  whileElementsMounted: autoUpdate
155
156
  } : {}
@@ -64,8 +64,6 @@ function CodeSnippet({
64
64
  const codeContentRef = React.useRef(null);
65
65
  const codeContainerRef = React.useRef(null);
66
66
  const innerCodeRef = React.useRef(null);
67
- const [hasLeftOverflow, setHasLeftOverflow] = React.useState(false);
68
- const [hasRightOverflow, setHasRightOverflow] = React.useState(false);
69
67
  const getCodeRef = React.useCallback(() => {
70
68
  if (type === 'single') {
71
69
  return codeContainerRef;
@@ -77,39 +75,13 @@ function CodeSnippet({
77
75
  }
78
76
  }, [type]);
79
77
  const prefix = usePrefix.usePrefix();
80
- const getCodeRefDimensions = React.useCallback(() => {
81
- const {
82
- clientWidth: codeClientWidth = 0,
83
- scrollLeft: codeScrollLeft = 0,
84
- scrollWidth: codeScrollWidth = 0
85
- } = getCodeRef().current || {};
86
- return {
87
- horizontalOverflow: codeScrollWidth > codeClientWidth,
88
- codeClientWidth,
89
- codeScrollWidth,
90
- codeScrollLeft
91
- };
92
- }, [getCodeRef]);
93
- const handleScroll = React.useCallback(() => {
94
- if (type === 'inline' || type === 'single' && !codeContainerRef?.current || type === 'multi' && !codeContentRef?.current) {
95
- return;
96
- }
97
- const {
98
- horizontalOverflow,
99
- codeClientWidth,
100
- codeScrollWidth,
101
- codeScrollLeft
102
- } = getCodeRefDimensions();
103
- setHasLeftOverflow(horizontalOverflow && !!codeScrollLeft);
104
- setHasRightOverflow(horizontalOverflow && codeScrollLeft + codeClientWidth !== codeScrollWidth);
105
- }, [type, getCodeRefDimensions]);
106
78
  useResizeObserver.useResizeObserver({
107
79
  ref: getCodeRef(),
108
80
  onResize: () => {
109
- if (codeContentRef?.current && type === 'multi') {
81
+ if (innerCodeRef?.current && type === 'multi') {
110
82
  const {
111
83
  height
112
- } = codeContentRef.current.getBoundingClientRect();
84
+ } = innerCodeRef.current.getBoundingClientRect();
113
85
  if (maxCollapsedNumberOfRows > 0 && (maxExpandedNumberOfRows <= 0 || maxExpandedNumberOfRows > maxCollapsedNumberOfRows) && height > maxCollapsedNumberOfRows * rowHeightInPixels) {
114
86
  setShouldShowMoreLessBtn(true);
115
87
  } else {
@@ -119,14 +91,8 @@ function CodeSnippet({
119
91
  setExpandedCode(false);
120
92
  }
121
93
  }
122
- if (codeContentRef?.current && type === 'multi' || codeContainerRef?.current && type === 'single') {
123
- handleScroll();
124
- }
125
94
  }
126
95
  });
127
- React.useEffect(() => {
128
- handleScroll();
129
- }, [handleScroll]);
130
96
  const handleCopyClick = evt => {
131
97
  if (copyText || innerCodeRef?.current) {
132
98
  copy(copyText ?? innerCodeRef?.current?.innerText ?? '');
@@ -141,8 +107,7 @@ function CodeSnippet({
141
107
  [`${prefix}--snippet--expand`]: expandedCode,
142
108
  [`${prefix}--snippet--light`]: light,
143
109
  [`${prefix}--snippet--no-copy`]: hideCopyButton,
144
- [`${prefix}--snippet--wraptext`]: wrapText,
145
- [`${prefix}--snippet--has-right-overflow`]: type == 'multi' && hasRightOverflow
110
+ [`${prefix}--snippet--wraptext`]: wrapText
146
111
  });
147
112
  const expandCodeBtnText = expandedCode ? showLessText : showMoreText;
148
113
  if (type === 'inline') {
@@ -200,18 +165,12 @@ function CodeSnippet({
200
165
  className: `${prefix}--snippet-container`,
201
166
  "aria-label": deprecatedAriaLabel || ariaLabel || 'code-snippet',
202
167
  "aria-readonly": type === 'single' || type === 'multi' ? true : undefined,
203
- "aria-multiline": type === 'multi' ? true : undefined,
204
- onScroll: type === 'single' && handleScroll || undefined
205
- }, containerStyle), /*#__PURE__*/React.createElement("pre", {
206
- ref: codeContentRef,
207
- onScroll: type === 'multi' && handleScroll || undefined
208
- }, /*#__PURE__*/React.createElement("code", {
168
+ "aria-multiline": type === 'multi' ? true : undefined
169
+ }, containerStyle), /*#__PURE__*/React.createElement("pre", _rollupPluginBabelHelpers.extends({
170
+ ref: codeContentRef
171
+ }, containerStyle), /*#__PURE__*/React.createElement("code", {
209
172
  ref: innerCodeRef
210
- }, children))), hasLeftOverflow && /*#__PURE__*/React.createElement("div", {
211
- className: `${prefix}--snippet__overflow-indicator--left`
212
- }), hasRightOverflow && type !== 'multi' && /*#__PURE__*/React.createElement("div", {
213
- className: `${prefix}--snippet__overflow-indicator--right`
214
- }), !hideCopyButton && /*#__PURE__*/React.createElement(CopyButton.default, {
173
+ }, children))), !hideCopyButton && /*#__PURE__*/React.createElement(CopyButton.default, {
215
174
  align: align,
216
175
  autoAlign: autoAlign,
217
176
  size: type === 'multi' ? 'sm' : 'md',
@@ -92,6 +92,7 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
92
92
  isExpanded: boolean;
93
93
  onExpand: (event: MouseEvent<HTMLButtonElement>) => void;
94
94
  [key: string]: unknown;
95
+ id: string;
95
96
  };
96
97
  getRowProps: (options: {
97
98
  onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
@@ -105,6 +106,7 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
105
106
  key: string;
106
107
  onExpand: (event: MouseEvent<HTMLButtonElement>) => void;
107
108
  [key: string]: unknown;
109
+ expandHeader: string;
108
110
  };
109
111
  getExpandedRowProps: (options: {
110
112
  row: DataTableRow<ColTypes>;
@@ -196,9 +196,10 @@ const DataTable = props => {
196
196
  ...rest,
197
197
  'aria-label': t(translationKey),
198
198
  // Provide a string of all expanded row IDs, separated by a space.
199
- 'aria-controls': rowIds.map(id => `expanded-row-${id}`).join(' '),
199
+ 'aria-controls': rowIds.map(id => `${getTablePrefix()}-expanded-row-${id}`).join(' '),
200
200
  isExpanded,
201
- onExpand: events.composeEventHandlers(handlers)
201
+ onExpand: events.composeEventHandlers(handlers),
202
+ id: `${getTablePrefix()}-expand`
202
203
  };
203
204
  };
204
205
 
@@ -230,9 +231,10 @@ const DataTable = props => {
230
231
  onExpand: events.composeEventHandlers([handleOnExpandRow(row.id), onClick]),
231
232
  isExpanded: row.isExpanded,
232
233
  'aria-label': t(translationKey),
233
- 'aria-controls': `expanded-row-${row.id}`,
234
+ 'aria-controls': `${getTablePrefix()}-expanded-row-${row.id}`,
234
235
  isSelected: row.isSelected,
235
- disabled: row.disabled
236
+ disabled: row.disabled,
237
+ expandHeader: `${getTablePrefix()}-expand`
236
238
  };
237
239
  };
238
240
  const getExpandedRowProps = ({
@@ -241,7 +243,7 @@ const DataTable = props => {
241
243
  }) => {
242
244
  return {
243
245
  ...rest,
244
- id: `expanded-row-${row.id}`
246
+ id: `${getTablePrefix()}-expanded-row-${row.id}`
245
247
  };
246
248
  };
247
249
 
@@ -33,6 +33,10 @@ export interface TableRowExpandInteropProps {
33
33
  * Specify if the row is selected.
34
34
  */
35
35
  isSelected?: boolean;
36
+ /**
37
+ * The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43
38
+ */
39
+ expandHeader?: string;
36
40
  }
37
41
  export interface TableExpandRowProps extends PropsWithChildren<Omit<HTMLAttributes<HTMLTableRowElement>, 'onClick'>>, Omit<TableRowExpandInteropProps, 'aria-label' | 'onExpand'> {
38
42
  /**
@@ -35,6 +35,8 @@ const TableRow = frFn((props, ref) => {
35
35
  isExpanded,
36
36
  // eslint-disable-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452
37
37
  isSelected,
38
+ expandHeader,
39
+ // eslint-disable-line @typescript-eslint/no-unused-vars
38
40
  ...cleanProps
39
41
  } = props;
40
42
  const prefix = usePrefix.usePrefix();
@@ -151,7 +151,8 @@ forwardRef) {
151
151
  fallbackAxisSideDirection: 'start',
152
152
  boundary: autoAlignBoundary
153
153
  }), react.arrow({
154
- element: caretRef
154
+ element: caretRef,
155
+ padding: 16
155
156
  }), autoAlign && react.hide()],
156
157
  whileElementsMounted: react.autoUpdate
157
158
  } : {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/react",
3
3
  "description": "React components for the Carbon Design System",
4
- "version": "1.93.0-rc.0",
4
+ "version": "1.93.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -53,10 +53,10 @@
53
53
  "dependencies": {
54
54
  "@babel/runtime": "^7.27.3",
55
55
  "@carbon/feature-flags": "^0.31.0",
56
- "@carbon/icons-react": "^11.69.0-rc.0",
57
- "@carbon/layout": "^11.43.0-rc.0",
58
- "@carbon/styles": "^1.92.0-rc.0",
59
- "@carbon/utilities": "^0.11.0-rc.0",
56
+ "@carbon/icons-react": "^11.69.0",
57
+ "@carbon/layout": "^11.43.0",
58
+ "@carbon/styles": "^1.92.0",
59
+ "@carbon/utilities": "^0.11.0",
60
60
  "@floating-ui/react": "^0.27.4",
61
61
  "@ibm/telemetry-js": "^1.5.0",
62
62
  "classnames": "2.5.1",
@@ -80,7 +80,7 @@
80
80
  "@babel/preset-react": "^7.27.1",
81
81
  "@babel/preset-typescript": "^7.27.1",
82
82
  "@carbon/test-utils": "^10.38.0",
83
- "@carbon/themes": "^11.62.0-rc.0",
83
+ "@carbon/themes": "^11.62.0",
84
84
  "@figma/code-connect": "^1.3.5",
85
85
  "@rollup/plugin-babel": "^6.0.0",
86
86
  "@rollup/plugin-commonjs": "^28.0.3",
@@ -123,7 +123,7 @@
123
123
  "storybook": "^9.0.5",
124
124
  "stream-browserify": "^3.0.0",
125
125
  "style-loader": "^4.0.0",
126
- "typescript-config-carbon": "^0.8.0-rc.0",
126
+ "typescript-config-carbon": "^0.8.0",
127
127
  "use-sync-external-store": "^1.5.0",
128
128
  "webpack": "^5.65.0",
129
129
  "webpack-dev-server": "^5.0.0"
@@ -139,5 +139,5 @@
139
139
  "**/*.scss",
140
140
  "**/*.css"
141
141
  ],
142
- "gitHead": "0d9497f77c917c567c8be19157e3da42d7a02c04"
142
+ "gitHead": "c17cce753e36124e6e8e02daba97ae9d4decbcc3"
143
143
  }