@backstage/ui 0.13.0-next.1 → 0.13.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.
- package/CHANGELOG.md +282 -0
- package/dist/analytics/getNodeText.esm.js +21 -0
- package/dist/analytics/getNodeText.esm.js.map +1 -0
- package/dist/analytics/useAnalytics.esm.js +26 -0
- package/dist/analytics/useAnalytics.esm.js.map +1 -0
- package/dist/components/Accordion/Accordion.module.css.esm.js +2 -2
- package/dist/components/Accordion/definition.esm.js +1 -0
- package/dist/components/Accordion/definition.esm.js.map +1 -1
- package/dist/components/Alert/definition.esm.js +1 -0
- package/dist/components/Alert/definition.esm.js.map +1 -1
- package/dist/components/Avatar/definition.esm.js +1 -0
- package/dist/components/Avatar/definition.esm.js.map +1 -1
- package/dist/components/Box/definition.esm.js +1 -0
- package/dist/components/Box/definition.esm.js.map +1 -1
- package/dist/components/Button/Button.module.css.esm.js +2 -2
- package/dist/components/Button/definition.esm.js +1 -0
- package/dist/components/Button/definition.esm.js.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.module.css.esm.js +2 -2
- package/dist/components/ButtonIcon/definition.esm.js +1 -0
- package/dist/components/ButtonIcon/definition.esm.js.map +1 -1
- package/dist/components/ButtonLink/ButtonLink.esm.js +12 -4
- package/dist/components/ButtonLink/ButtonLink.esm.js.map +1 -1
- package/dist/components/ButtonLink/ButtonLink.module.css.esm.js +2 -2
- package/dist/components/ButtonLink/definition.esm.js +3 -0
- package/dist/components/ButtonLink/definition.esm.js.map +1 -1
- package/dist/components/Card/Card.esm.js +66 -5
- package/dist/components/Card/Card.esm.js.map +1 -1
- package/dist/components/Card/Card.module.css.esm.js +2 -2
- package/dist/components/Card/definition.esm.js +10 -2
- package/dist/components/Card/definition.esm.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.esm.js +12 -3
- package/dist/components/Checkbox/Checkbox.esm.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.module.css.esm.js +2 -2
- package/dist/components/Checkbox/definition.esm.js +1 -2
- package/dist/components/Checkbox/definition.esm.js.map +1 -1
- package/dist/components/Container/Container.module.css.esm.js +2 -2
- package/dist/components/Container/definition.esm.js +1 -0
- package/dist/components/Container/definition.esm.js.map +1 -1
- package/dist/components/Dialog/Dialog.esm.js +3 -1
- package/dist/components/Dialog/Dialog.esm.js.map +1 -1
- package/dist/components/Dialog/Dialog.module.css.esm.js +2 -2
- package/dist/components/Dialog/definition.esm.js +1 -0
- package/dist/components/Dialog/definition.esm.js.map +1 -1
- package/dist/components/FieldError/definition.esm.js +1 -0
- package/dist/components/FieldError/definition.esm.js.map +1 -1
- package/dist/components/FieldLabel/definition.esm.js +1 -0
- package/dist/components/FieldLabel/definition.esm.js.map +1 -1
- package/dist/components/Flex/Flex.esm.js +2 -1
- package/dist/components/Flex/Flex.esm.js.map +1 -1
- package/dist/components/Flex/definition.esm.js +1 -0
- package/dist/components/Flex/definition.esm.js.map +1 -1
- package/dist/components/FullPage/definition.esm.js +1 -0
- package/dist/components/FullPage/definition.esm.js.map +1 -1
- package/dist/components/Grid/Grid.esm.js +4 -2
- package/dist/components/Grid/Grid.esm.js.map +1 -1
- package/dist/components/Grid/definition.esm.js +1 -0
- package/dist/components/Grid/definition.esm.js.map +1 -1
- package/dist/components/{HeaderPage/HeaderPage.esm.js → Header/Header.esm.js} +6 -5
- package/dist/components/Header/Header.esm.js.map +1 -0
- package/dist/components/Header/Header.module.css.esm.js +8 -0
- package/dist/components/Header/Header.module.css.esm.js.map +1 -0
- package/dist/components/{HeaderPage → Header}/definition.esm.js +10 -8
- package/dist/components/Header/definition.esm.js.map +1 -0
- package/dist/components/Link/Link.esm.js +11 -3
- package/dist/components/Link/Link.esm.js.map +1 -1
- package/dist/components/Link/definition.esm.js +3 -0
- package/dist/components/Link/definition.esm.js.map +1 -1
- package/dist/components/List/List.esm.js +70 -0
- package/dist/components/List/List.esm.js.map +1 -0
- package/dist/components/List/List.module.css.esm.js +8 -0
- package/dist/components/List/List.module.css.esm.js.map +1 -0
- package/dist/components/List/definition.esm.js +44 -0
- package/dist/components/List/definition.esm.js.map +1 -0
- package/dist/components/Menu/Menu.esm.js +24 -9
- package/dist/components/Menu/Menu.esm.js.map +1 -1
- package/dist/components/Menu/Menu.module.css.esm.js +2 -2
- package/dist/components/Menu/definition.esm.js +3 -0
- package/dist/components/Menu/definition.esm.js.map +1 -1
- package/dist/components/PasswordField/definition.esm.js +1 -0
- package/dist/components/PasswordField/definition.esm.js.map +1 -1
- package/dist/components/PluginHeader/PluginHeader.esm.js +40 -8
- package/dist/components/PluginHeader/PluginHeader.esm.js.map +1 -1
- package/dist/components/PluginHeader/PluginHeader.module.css.esm.js +2 -2
- package/dist/components/PluginHeader/definition.esm.js +1 -0
- package/dist/components/PluginHeader/definition.esm.js.map +1 -1
- package/dist/components/Popover/definition.esm.js +1 -0
- package/dist/components/Popover/definition.esm.js.map +1 -1
- package/dist/components/RadioGroup/definition.esm.js +1 -0
- package/dist/components/RadioGroup/definition.esm.js.map +1 -1
- package/dist/components/SearchAutocomplete/SearchAutocomplete.esm.js +164 -0
- package/dist/components/SearchAutocomplete/SearchAutocomplete.esm.js.map +1 -0
- package/dist/components/SearchAutocomplete/SearchAutocomplete.module.css.esm.js +8 -0
- package/dist/components/SearchAutocomplete/SearchAutocomplete.module.css.esm.js.map +1 -0
- package/dist/components/SearchAutocomplete/definition.esm.js +52 -0
- package/dist/components/SearchAutocomplete/definition.esm.js.map +1 -0
- package/dist/components/SearchField/SearchField.module.css.esm.js +2 -2
- package/dist/components/SearchField/definition.esm.js +2 -0
- package/dist/components/SearchField/definition.esm.js.map +1 -1
- package/dist/components/Select/Select.module.css.esm.js +2 -2
- package/dist/components/Select/SelectTrigger.esm.js +5 -2
- package/dist/components/Select/SelectTrigger.esm.js.map +1 -1
- package/dist/components/Select/definition.esm.js +2 -0
- package/dist/components/Select/definition.esm.js.map +1 -1
- package/dist/components/Skeleton/definition.esm.js +1 -0
- package/dist/components/Skeleton/definition.esm.js.map +1 -1
- package/dist/components/Switch/definition.esm.js +1 -0
- package/dist/components/Switch/definition.esm.js.map +1 -1
- package/dist/components/Table/Table.module.css.esm.js +2 -2
- package/dist/components/Table/components/Column.esm.js +1 -1
- package/dist/components/Table/components/Column.esm.js.map +1 -1
- package/dist/components/Table/components/Row.esm.js +34 -9
- package/dist/components/Table/components/Row.esm.js.map +1 -1
- package/dist/components/Table/components/Table.esm.js +80 -67
- package/dist/components/Table/components/Table.esm.js.map +1 -1
- package/dist/components/Table/components/TableBodySkeleton.esm.js +33 -0
- package/dist/components/Table/components/TableBodySkeleton.esm.js.map +1 -0
- package/dist/components/Table/components/TableHeader.esm.js +2 -2
- package/dist/components/Table/components/TableHeader.esm.js.map +1 -1
- package/dist/components/Table/components/TableRoot.esm.js +1 -1
- package/dist/components/Table/components/TableRoot.esm.js.map +1 -1
- package/dist/components/Table/definition.esm.js +19 -3
- package/dist/components/Table/definition.esm.js.map +1 -1
- package/dist/components/Table/hooks/useCompletePagination.esm.js +14 -6
- package/dist/components/Table/hooks/useCompletePagination.esm.js.map +1 -1
- package/dist/components/TablePagination/definition.esm.js +1 -0
- package/dist/components/TablePagination/definition.esm.js.map +1 -1
- package/dist/components/Tabs/Tabs.esm.js +22 -8
- package/dist/components/Tabs/Tabs.esm.js.map +1 -1
- package/dist/components/Tabs/definition.esm.js +4 -1
- package/dist/components/Tabs/definition.esm.js.map +1 -1
- package/dist/components/TagGroup/TagGroup.esm.js +16 -6
- package/dist/components/TagGroup/TagGroup.esm.js.map +1 -1
- package/dist/components/TagGroup/definition.esm.js +3 -0
- package/dist/components/TagGroup/definition.esm.js.map +1 -1
- package/dist/components/Text/definition.esm.js +1 -0
- package/dist/components/Text/definition.esm.js.map +1 -1
- package/dist/components/TextField/TextField.module.css.esm.js +2 -2
- package/dist/components/TextField/definition.esm.js +2 -0
- package/dist/components/TextField/definition.esm.js.map +1 -1
- package/dist/components/ToggleButton/definition.esm.js +1 -0
- package/dist/components/ToggleButton/definition.esm.js.map +1 -1
- package/dist/components/ToggleButtonGroup/ToggleButtonGroup.module.css.esm.js +2 -2
- package/dist/components/ToggleButtonGroup/definition.esm.js +1 -0
- package/dist/components/ToggleButtonGroup/definition.esm.js.map +1 -1
- package/dist/components/Tooltip/definition.esm.js +1 -0
- package/dist/components/Tooltip/definition.esm.js.map +1 -1
- package/dist/components/VisuallyHidden/definition.esm.js +1 -0
- package/dist/components/VisuallyHidden/definition.esm.js.map +1 -1
- package/dist/css/styles.css +4 -3
- package/dist/hooks/useDefinition/defineComponent.esm.js.map +1 -1
- package/dist/hooks/useDefinition/useDefinition.esm.js +8 -1
- package/dist/hooks/useDefinition/useDefinition.esm.js.map +1 -1
- package/dist/index.d.ts +512 -42
- package/dist/index.esm.js +9 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/provider/BUIProvider.esm.js +28 -0
- package/dist/provider/BUIProvider.esm.js.map +1 -0
- package/dist/utils/{isExternalLink.esm.js → linkUtils.esm.js} +5 -2
- package/dist/utils/linkUtils.esm.js.map +1 -0
- package/package.json +4 -4
- package/dist/components/HeaderPage/HeaderPage.esm.js.map +0 -1
- package/dist/components/HeaderPage/HeaderPage.module.css.esm.js +0 -8
- package/dist/components/HeaderPage/HeaderPage.module.css.esm.js.map +0 -1
- package/dist/components/HeaderPage/definition.esm.js.map +0 -1
- package/dist/components/InternalLinkProvider/InternalLinkProvider.esm.js +0 -55
- package/dist/components/InternalLinkProvider/InternalLinkProvider.esm.js.map +0 -1
- package/dist/utils/isExternalLink.esm.js.map +0 -1
|
@@ -4,31 +4,56 @@ import { Checkbox } from '../../Checkbox/Checkbox.esm.js';
|
|
|
4
4
|
import { useDefinition } from '../../../hooks/useDefinition/useDefinition.esm.js';
|
|
5
5
|
import '../../Checkbox/Checkbox.module.css.esm.js';
|
|
6
6
|
import { RowDefinition } from '../definition.esm.js';
|
|
7
|
-
import { isExternalLink } from '../../../utils/
|
|
8
|
-
import { InternalLinkProvider } from '../../InternalLinkProvider/InternalLinkProvider.esm.js';
|
|
7
|
+
import { isExternalLink } from '../../../utils/linkUtils.esm.js';
|
|
9
8
|
import clsx from 'clsx';
|
|
10
9
|
import { Flex } from '../../Flex/Flex.esm.js';
|
|
11
10
|
import '../../Flex/Flex.module.css.esm.js';
|
|
12
11
|
|
|
13
12
|
function Row(props) {
|
|
14
|
-
const { ownProps, restProps } = useDefinition(
|
|
13
|
+
const { ownProps, restProps, dataAttributes, analytics } = useDefinition(
|
|
14
|
+
RowDefinition,
|
|
15
|
+
props
|
|
16
|
+
);
|
|
15
17
|
const { classes, columns, children, href } = ownProps;
|
|
16
|
-
const
|
|
18
|
+
const isExternal = isExternalLink(href);
|
|
19
|
+
const hasInternalHref = !!href && !isExternal;
|
|
20
|
+
const hasExternalHref = !!href && isExternal;
|
|
21
|
+
const hasInteraction = !!restProps.onAction || !!href;
|
|
22
|
+
const effectiveTarget = hasExternalHref ? "_blank" : restProps.target;
|
|
23
|
+
const effectiveRel = effectiveTarget === "_blank" ? [
|
|
24
|
+
.../* @__PURE__ */ new Set([
|
|
25
|
+
"noopener",
|
|
26
|
+
"noreferrer",
|
|
27
|
+
...restProps.rel?.split(/\s+/).filter(Boolean) ?? []
|
|
28
|
+
])
|
|
29
|
+
].join(" ") : restProps.rel;
|
|
30
|
+
const handlePress = hasInteraction ? () => {
|
|
31
|
+
restProps.onAction?.();
|
|
32
|
+
if (href) {
|
|
33
|
+
analytics.captureEvent("click", href, {
|
|
34
|
+
attributes: { to: String(href) }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
} : void 0;
|
|
17
38
|
let { selectionBehavior, selectionMode } = useTableOptions();
|
|
18
39
|
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
19
|
-
selectionBehavior === "toggle" && selectionMode === "multiple" && /* @__PURE__ */ jsx(Cell, { className: clsx(classes.cell, classes.cellSelection), children: /* @__PURE__ */ jsx(Flex, { justify: "center", align: "center", children: /* @__PURE__ */ jsx(Checkbox, { slot: "selection",
|
|
40
|
+
selectionBehavior === "toggle" && selectionMode === "multiple" && /* @__PURE__ */ jsx(Cell, { className: clsx(classes.cell, classes.cellSelection), children: /* @__PURE__ */ jsx(Flex, { justify: "center", align: "center", children: /* @__PURE__ */ jsx(Checkbox, { slot: "selection", "aria-label": "Select row" }) }) }),
|
|
20
41
|
/* @__PURE__ */ jsx(Collection, { items: columns, children })
|
|
21
42
|
] });
|
|
22
|
-
return /* @__PURE__ */ jsx(
|
|
43
|
+
return /* @__PURE__ */ jsx(
|
|
23
44
|
Row$1,
|
|
24
45
|
{
|
|
25
46
|
href,
|
|
26
|
-
className: classes.root,
|
|
27
|
-
"data-react-aria-pressable": hasInternalHref ? "true" : void 0,
|
|
28
47
|
...restProps,
|
|
48
|
+
...dataAttributes,
|
|
49
|
+
target: effectiveTarget,
|
|
50
|
+
rel: effectiveRel,
|
|
51
|
+
className: clsx(classes.root, restProps.className),
|
|
52
|
+
"data-react-aria-pressable": hasInternalHref ? "true" : void 0,
|
|
53
|
+
onAction: handlePress,
|
|
29
54
|
children: content
|
|
30
55
|
}
|
|
31
|
-
)
|
|
56
|
+
);
|
|
32
57
|
}
|
|
33
58
|
|
|
34
59
|
export { Row };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Row.esm.js","sources":["../../../../src/components/Table/components/Row.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Row as ReactAriaRow,\n useTableOptions,\n Cell as ReactAriaCell,\n Collection,\n} from 'react-aria-components';\nimport { Checkbox } from '../../Checkbox';\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { RowDefinition } from '../definition';\nimport type { RowProps } from '../types';\nimport { isExternalLink } from '../../../utils/
|
|
1
|
+
{"version":3,"file":"Row.esm.js","sources":["../../../../src/components/Table/components/Row.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Row as ReactAriaRow,\n useTableOptions,\n Cell as ReactAriaCell,\n Collection,\n} from 'react-aria-components';\nimport { Checkbox } from '../../Checkbox';\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { RowDefinition } from '../definition';\nimport type { RowProps } from '../types';\nimport { isExternalLink } from '../../../utils/linkUtils';\nimport clsx from 'clsx';\nimport { Flex } from '../../Flex';\n\n/** @public */\nexport function Row<T extends object>(props: RowProps<T>) {\n const { ownProps, restProps, dataAttributes, analytics } = useDefinition(\n RowDefinition,\n props,\n );\n const { classes, columns, children, href } = ownProps;\n const isExternal = isExternalLink(href);\n const hasInternalHref = !!href && !isExternal;\n const hasExternalHref = !!href && isExternal;\n const hasInteraction = !!restProps.onAction || !!href;\n\n // Derive the effective target, defaulting to _blank for external links.\n const effectiveTarget = hasExternalHref ? '_blank' : restProps.target;\n // Always include noopener noreferrer when target=_blank, merging any\n // consumer-provided rel tokens to avoid reverse-tabnabbing risk.\n const effectiveRel =\n effectiveTarget === '_blank'\n ? [\n ...new Set([\n 'noopener',\n 'noreferrer',\n ...(restProps.rel?.split(/\\s+/).filter(Boolean) ?? []),\n ]),\n ].join(' ')\n : restProps.rel;\n\n const handlePress = hasInteraction\n ? () => {\n restProps.onAction?.();\n if (href) {\n analytics.captureEvent('click', href, {\n attributes: { to: String(href) },\n });\n }\n }\n : undefined;\n\n let { selectionBehavior, selectionMode } = useTableOptions();\n\n const content = (\n <>\n {selectionBehavior === 'toggle' && selectionMode === 'multiple' && (\n <ReactAriaCell className={clsx(classes.cell, classes.cellSelection)}>\n <Flex justify=\"center\" align=\"center\">\n <Checkbox slot=\"selection\" aria-label=\"Select row\" />\n </Flex>\n </ReactAriaCell>\n )}\n <Collection items={columns}>{children}</Collection>\n </>\n );\n\n return (\n <ReactAriaRow\n href={href}\n {...restProps}\n {...dataAttributes}\n target={effectiveTarget}\n rel={effectiveRel}\n className={clsx(classes.root, restProps.className)}\n data-react-aria-pressable={hasInternalHref ? 'true' : undefined}\n onAction={handlePress}\n >\n {content}\n </ReactAriaRow>\n );\n}\n"],"names":["ReactAriaCell","ReactAriaRow"],"mappings":";;;;;;;;;;;AA+BO,SAAS,IAAsB,KAAA,EAAoB;AACxD,EAAA,MAAM,EAAE,QAAA,EAAU,SAAA,EAAW,cAAA,EAAgB,WAAU,GAAI,aAAA;AAAA,IACzD,aAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,QAAA,EAAU,MAAK,GAAI,QAAA;AAC7C,EAAA,MAAM,UAAA,GAAa,eAAe,IAAI,CAAA;AACtC,EAAA,MAAM,eAAA,GAAkB,CAAC,CAAC,IAAA,IAAQ,CAAC,UAAA;AACnC,EAAA,MAAM,eAAA,GAAkB,CAAC,CAAC,IAAA,IAAQ,UAAA;AAClC,EAAA,MAAM,iBAAiB,CAAC,CAAC,SAAA,CAAU,QAAA,IAAY,CAAC,CAAC,IAAA;AAGjD,EAAA,MAAM,eAAA,GAAkB,eAAA,GAAkB,QAAA,GAAW,SAAA,CAAU,MAAA;AAG/D,EAAA,MAAM,YAAA,GACJ,oBAAoB,QAAA,GAChB;AAAA,IACE,uBAAO,GAAA,CAAI;AAAA,MACT,UAAA;AAAA,MACA,YAAA;AAAA,MAC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;AAAA,MACL,SAAA,EAAW,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAM,UAAU,SAAS,CAAA;AAAA,MACjD,2BAAA,EAA2B,kBAAkB,MAAA,GAAS,MAAA;AAAA,MACtD,QAAA,EAAU,WAAA;AAAA,MAET,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ;;;;"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { useId } from 'react-aria';
|
|
3
|
-
import { ResizableTableContainer } from 'react-aria-components';
|
|
3
|
+
import { ResizableTableContainer, Virtualizer } from 'react-aria-components';
|
|
4
|
+
import { TableLayout } from '@react-stately/layout';
|
|
5
|
+
import { useDefinition } from '../../../hooks/useDefinition/useDefinition.esm.js';
|
|
6
|
+
import { TableWrapperDefinition } from '../definition.esm.js';
|
|
4
7
|
import { TableRoot } from './TableRoot.esm.js';
|
|
5
8
|
import { TableHeader } from './TableHeader.esm.js';
|
|
6
9
|
import { TableBody } from './TableBody.esm.js';
|
|
7
10
|
import { Row } from './Row.esm.js';
|
|
8
11
|
import { Column } from './Column.esm.js';
|
|
9
12
|
import { TablePagination } from '../../TablePagination/TablePagination.esm.js';
|
|
10
|
-
import 'clsx';
|
|
11
|
-
import '../../../hooks/useBreakpoint.esm.js';
|
|
12
|
-
import '../../../hooks/useBg.esm.js';
|
|
13
|
-
import '../../../hooks/useDefinition/helpers.esm.js';
|
|
14
13
|
import '../../TablePagination/TablePagination.module.css.esm.js';
|
|
15
14
|
import { useMemo } from 'react';
|
|
16
15
|
import { VisuallyHidden } from '../../VisuallyHidden/VisuallyHidden.esm.js';
|
|
17
16
|
import '../../VisuallyHidden/VisuallyHidden.module.css.esm.js';
|
|
18
17
|
import { Flex } from '../../Flex/Flex.esm.js';
|
|
19
18
|
import '../../Flex/Flex.module.css.esm.js';
|
|
19
|
+
import { TableBodySkeleton } from './TableBodySkeleton.esm.js';
|
|
20
20
|
|
|
21
21
|
function isRowRenderFn(rowConfig) {
|
|
22
22
|
return typeof rowConfig === "function";
|
|
@@ -38,7 +38,10 @@ function useDisabledRows({
|
|
|
38
38
|
}, /* @__PURE__ */ new Set());
|
|
39
39
|
}, [data, rowConfig]);
|
|
40
40
|
}
|
|
41
|
-
function useLiveRegionLabel(pagination, isStale, hasData) {
|
|
41
|
+
function useLiveRegionLabel(pagination, isStale, isLoading, hasData) {
|
|
42
|
+
if (isLoading) {
|
|
43
|
+
return "Loading table data.";
|
|
44
|
+
}
|
|
42
45
|
if (!hasData || pagination.type === "none") {
|
|
43
46
|
return "";
|
|
44
47
|
}
|
|
@@ -68,8 +71,12 @@ function Table({
|
|
|
68
71
|
selection,
|
|
69
72
|
emptyState,
|
|
70
73
|
className,
|
|
71
|
-
style
|
|
74
|
+
style,
|
|
75
|
+
virtualized
|
|
72
76
|
}) {
|
|
77
|
+
const {
|
|
78
|
+
ownProps: { classes }
|
|
79
|
+
} = useDefinition(TableWrapperDefinition, { className });
|
|
73
80
|
const liveRegionId = useId();
|
|
74
81
|
const visibleColumns = useMemo(
|
|
75
82
|
() => columnConfig.filter((col) => !col.isHidden),
|
|
@@ -82,11 +89,9 @@ function Table({
|
|
|
82
89
|
behavior: selectionBehavior,
|
|
83
90
|
onSelectionChange
|
|
84
91
|
} = selection || {};
|
|
85
|
-
|
|
86
|
-
return /* @__PURE__ */ jsx("div", { className, style, children: "Loading..." });
|
|
87
|
-
}
|
|
92
|
+
const isInitialLoading = loading && !data;
|
|
88
93
|
if (error) {
|
|
89
|
-
return /* @__PURE__ */ jsxs("div", { className, style, children: [
|
|
94
|
+
return /* @__PURE__ */ jsxs("div", { className: classes.root, style, children: [
|
|
90
95
|
"Error: ",
|
|
91
96
|
error.message
|
|
92
97
|
] });
|
|
@@ -94,70 +99,78 @@ function Table({
|
|
|
94
99
|
const liveRegionLabel = useLiveRegionLabel(
|
|
95
100
|
pagination,
|
|
96
101
|
isStale,
|
|
102
|
+
isInitialLoading,
|
|
97
103
|
data !== void 0
|
|
98
104
|
);
|
|
99
105
|
const manualColumnSizing = columnConfig.some(
|
|
100
106
|
(col) => col.width != null || col.minWidth != null || col.maxWidth != null || col.defaultWidth != null
|
|
101
107
|
);
|
|
102
|
-
const wrapResizable = manualColumnSizing ? (elem) => /* @__PURE__ */ jsx(ResizableTableContainer, { children: elem }) : (elem) => /* @__PURE__ */ jsx(Fragment, { children: elem });
|
|
103
|
-
|
|
108
|
+
const wrapResizable = manualColumnSizing ? (elem) => /* @__PURE__ */ jsx(ResizableTableContainer, { className: classes.resizableContainer, children: elem }) : (elem) => /* @__PURE__ */ jsx(Fragment, { children: elem });
|
|
109
|
+
const layoutOptions = typeof virtualized === "object" ? virtualized : void 0;
|
|
110
|
+
const wrapVirtualized = (elem) => virtualized ? /* @__PURE__ */ jsx(Virtualizer, { layout: TableLayout, layoutOptions, children: elem }) : elem;
|
|
111
|
+
return /* @__PURE__ */ jsxs("div", { className: classes.root, style, children: [
|
|
104
112
|
/* @__PURE__ */ jsx(VisuallyHidden, { "aria-live": "polite", id: liveRegionId, children: liveRegionLabel }),
|
|
105
113
|
wrapResizable(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
id: String(item.id),
|
|
150
|
-
columns: visibleColumns,
|
|
151
|
-
href: rowConfig?.getHref?.(item),
|
|
152
|
-
onAction: rowConfig?.onClick ? () => rowConfig?.onClick?.(item) : void 0,
|
|
153
|
-
children: (column) => column.cell(item)
|
|
114
|
+
wrapVirtualized(
|
|
115
|
+
/* @__PURE__ */ jsxs(
|
|
116
|
+
TableRoot,
|
|
117
|
+
{
|
|
118
|
+
...isInitialLoading ? {} : {
|
|
119
|
+
selectionMode,
|
|
120
|
+
selectionBehavior,
|
|
121
|
+
selectedKeys,
|
|
122
|
+
onSelectionChange
|
|
123
|
+
},
|
|
124
|
+
sortDescriptor: sort?.descriptor ?? void 0,
|
|
125
|
+
onSortChange: sort?.onSortChange,
|
|
126
|
+
disabledKeys: disabledRows,
|
|
127
|
+
stale: isStale,
|
|
128
|
+
loading: isInitialLoading,
|
|
129
|
+
"aria-describedby": liveRegionId,
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsx(TableHeader, { columns: visibleColumns, children: (column) => column.header ? column.header() : /* @__PURE__ */ jsx(
|
|
132
|
+
Column,
|
|
133
|
+
{
|
|
134
|
+
id: column.id,
|
|
135
|
+
isRowHeader: column.isRowHeader,
|
|
136
|
+
allowsSorting: column.isSortable,
|
|
137
|
+
width: column.width,
|
|
138
|
+
defaultWidth: column.defaultWidth,
|
|
139
|
+
minWidth: column.minWidth,
|
|
140
|
+
maxWidth: column.maxWidth,
|
|
141
|
+
children: column.label
|
|
142
|
+
}
|
|
143
|
+
) }),
|
|
144
|
+
isInitialLoading ? /* @__PURE__ */ jsx(TableBodySkeleton, { columns: visibleColumns }) : /* @__PURE__ */ jsx(
|
|
145
|
+
TableBody,
|
|
146
|
+
{
|
|
147
|
+
items: data,
|
|
148
|
+
dependencies: [visibleColumns],
|
|
149
|
+
renderEmptyState: emptyState ? () => /* @__PURE__ */ jsx(Flex, { p: "3", children: emptyState }) : void 0,
|
|
150
|
+
children: (item) => {
|
|
151
|
+
const itemIndex = data?.indexOf(item) ?? -1;
|
|
152
|
+
if (isRowRenderFn(rowConfig)) {
|
|
153
|
+
return rowConfig({
|
|
154
|
+
item,
|
|
155
|
+
index: itemIndex
|
|
156
|
+
});
|
|
154
157
|
}
|
|
155
|
-
|
|
158
|
+
return /* @__PURE__ */ jsx(
|
|
159
|
+
Row,
|
|
160
|
+
{
|
|
161
|
+
id: String(item.id),
|
|
162
|
+
columns: visibleColumns,
|
|
163
|
+
href: rowConfig?.getHref?.(item),
|
|
164
|
+
onAction: rowConfig?.onClick ? () => rowConfig?.onClick?.(item) : void 0,
|
|
165
|
+
children: (column) => column.cell(item)
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
156
169
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
170
|
+
)
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
)
|
|
161
174
|
)
|
|
162
175
|
),
|
|
163
176
|
pagination.type === "page" && /* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.esm.js","sources":["../../../../src/components/Table/components/Table.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useId } from 'react-aria';\nimport { type Key, ResizableTableContainer } from 'react-aria-components';\nimport { TableRoot } from './TableRoot';\nimport { TableHeader } from './TableHeader';\nimport { TableBody } from './TableBody';\nimport { Row } from './Row';\nimport { Column } from './Column';\nimport { TablePagination } from '../../TablePagination';\nimport type {\n TableProps,\n TableItem,\n RowConfig,\n RowRenderFn,\n TablePaginationType,\n} from '../types';\nimport { useMemo } from 'react';\nimport { VisuallyHidden } from '../../VisuallyHidden';\nimport { Flex } from '../../Flex';\n\nfunction isRowRenderFn<T extends TableItem>(\n rowConfig: RowConfig<T> | RowRenderFn<T> | undefined,\n): rowConfig is RowRenderFn<T> {\n return typeof rowConfig === 'function';\n}\n\nfunction useDisabledRows<T extends TableItem>({\n data,\n rowConfig,\n}: Pick<TableProps<T>, 'data' | 'rowConfig'>): Set<Key> | undefined {\n return useMemo(() => {\n if (!data || typeof rowConfig === 'function' || !rowConfig?.getIsDisabled) {\n return;\n }\n\n return data.reduce<Set<Key>>((set, item) => {\n const isDisabled = rowConfig.getIsDisabled?.(item);\n if (isDisabled) {\n set.add(String(item.id));\n }\n return set;\n }, new Set<Key>());\n }, [data, rowConfig]);\n}\n\nfunction useLiveRegionLabel(\n pagination: TablePaginationType,\n isStale: boolean,\n hasData: boolean,\n): string {\n if (!hasData || pagination.type === 'none') {\n return '';\n }\n\n const { pageSize, offset, totalCount, getLabel } = pagination;\n\n if (isStale) {\n return 'Loading table data.';\n }\n\n let liveRegionLabel = 'Table page loaded. ';\n\n if (getLabel) {\n liveRegionLabel += getLabel({ pageSize, offset, totalCount });\n } else if (offset !== undefined) {\n const fromCount = offset + 1;\n const toCount = Math.min(offset + pageSize, totalCount ?? 0);\n liveRegionLabel += `Showing ${fromCount} to ${toCount} of ${totalCount}`;\n }\n return liveRegionLabel;\n}\n\n/** @public */\nexport function Table<T extends TableItem>({\n columnConfig,\n data,\n loading = false,\n isStale = false,\n error,\n pagination,\n sort,\n rowConfig,\n selection,\n emptyState,\n className,\n style,\n}: TableProps<T>) {\n const liveRegionId = useId();\n\n const visibleColumns = useMemo(\n () => columnConfig.filter(col => !col.isHidden),\n [columnConfig],\n );\n const disabledRows = useDisabledRows({ data, rowConfig });\n\n const {\n mode: selectionMode,\n selected: selectedKeys,\n behavior: selectionBehavior,\n onSelectionChange,\n } = selection || {};\n\n if (loading && !data) {\n return (\n <div className={className} style={style}>\n Loading...\n </div>\n );\n }\n\n if (error) {\n return (\n <div className={className} style={style}>\n Error: {error.message}\n </div>\n );\n }\n\n const liveRegionLabel = useLiveRegionLabel(\n pagination,\n isStale,\n data !== undefined,\n );\n\n const manualColumnSizing = columnConfig.some(\n col =>\n col.width != null ||\n col.minWidth != null ||\n col.maxWidth != null ||\n col.defaultWidth != null,\n );\n\n const wrapResizable = manualColumnSizing\n ? (elem: React.ReactNode) => (\n <ResizableTableContainer>{elem}</ResizableTableContainer>\n )\n : (elem: React.ReactNode) => <>{elem}</>;\n\n return (\n <div className={className} style={style}>\n <VisuallyHidden aria-live=\"polite\" id={liveRegionId}>\n {liveRegionLabel}\n </VisuallyHidden>\n {wrapResizable(\n <TableRoot\n selectionMode={selectionMode}\n selectionBehavior={selectionBehavior}\n selectedKeys={selectedKeys}\n onSelectionChange={onSelectionChange}\n sortDescriptor={sort?.descriptor ?? undefined}\n onSortChange={sort?.onSortChange}\n disabledKeys={disabledRows}\n stale={isStale}\n aria-describedby={liveRegionId}\n >\n <TableHeader columns={visibleColumns}>\n {column =>\n column.header ? (\n column.header()\n ) : (\n <Column\n id={column.id}\n isRowHeader={column.isRowHeader}\n allowsSorting={column.isSortable}\n width={column.width}\n defaultWidth={column.defaultWidth}\n minWidth={column.minWidth}\n maxWidth={column.maxWidth}\n >\n {column.label}\n </Column>\n )\n }\n </TableHeader>\n <TableBody\n items={data}\n dependencies={[visibleColumns]}\n renderEmptyState={\n emptyState ? () => <Flex p=\"3\">{emptyState}</Flex> : undefined\n }\n >\n {item => {\n const itemIndex = data?.indexOf(item) ?? -1;\n\n if (isRowRenderFn(rowConfig)) {\n return rowConfig({\n item,\n index: itemIndex,\n });\n }\n\n return (\n <Row\n id={String(item.id)}\n columns={visibleColumns}\n href={rowConfig?.getHref?.(item)}\n onAction={\n rowConfig?.onClick\n ? () => rowConfig?.onClick?.(item)\n : undefined\n }\n >\n {column => column.cell(item)}\n </Row>\n );\n }}\n </TableBody>\n </TableRoot>,\n )}\n {pagination.type === 'page' && (\n <TablePagination\n pageSize={pagination.pageSize}\n pageSizeOptions={pagination.pageSizeOptions}\n offset={pagination.offset}\n totalCount={pagination.totalCount}\n hasNextPage={pagination.hasNextPage}\n hasPreviousPage={pagination.hasPreviousPage}\n onNextPage={pagination.onNextPage}\n onPreviousPage={pagination.onPreviousPage}\n onPageSizeChange={pagination.onPageSizeChange}\n showPageSizeOptions={pagination.showPageSizeOptions}\n getLabel={pagination.getLabel}\n />\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAmCA,SAAS,cACP,SAAA,EAC6B;AAC7B,EAAA,OAAO,OAAO,SAAA,KAAc,UAAA;AAC9B;AAEA,SAAS,eAAA,CAAqC;AAAA,EAC5C,IAAA;AAAA,EACA;AACF,CAAA,EAAoE;AAClE,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,cAAc,UAAA,IAAc,CAAC,WAAW,aAAA,EAAe;AACzE,MAAA;AAAA,IACF;AAEA,IAAA,OAAO,IAAA,CAAK,MAAA,CAAiB,CAAC,GAAA,EAAK,IAAA,KAAS;AAC1C,MAAA,MAAM,UAAA,GAAa,SAAA,CAAU,aAAA,GAAgB,IAAI,CAAA;AACjD,MAAA,IAAI,UAAA,EAAY;AACd,QAAA,GAAA,CAAI,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,EAAE,CAAC,CAAA;AAAA,MACzB;AACA,MAAA,OAAO,GAAA;AAAA,IACT,CAAA,kBAAG,IAAI,GAAA,EAAU,CAAA;AAAA,EACnB,CAAA,EAAG,CAAC,IAAA,EAAM,SAAS,CAAC,CAAA;AACtB;AAEA,SAAS,kBAAA,CACP,UAAA,EACA,OAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,CAAC,OAAA,IAAW,UAAA,CAAW,IAAA,KAAS,MAAA,EAAQ;AAC1C,IAAA,OAAO,EAAA;AAAA,EAC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A,EAAO;AAAA,qBACR,CAAA;AAAA,kBACH;AAEA,kBAAA,uBACE,GAAA;AAAA,oBAAC,GAAA;AAAA,oBAAA;AAAA,sBACC,EAAA,EAAI,MAAA,CAAO,IAAA,CAAK,EAAE,CAAA;AAAA,sBAClB,OAAA,EAAS,cAAA;AAAA,sBACT,IAAA,EAAM,SAAA,EAAW,OAAA,GAAU,IAAI,CAAA;AAAA,sBAC/B,UACE,SAAA,EAAW,OAAA,GACP,MAAM,SAAA,EAAW,OAAA,GAAU,IAAI,CAAA,GAC/B,MAAA;AAAA,sBAGL,QAAA,EAAA,CAAA,MAAA,KAAU,MAAA,CAAO,IAAA,CAAK,IAAI;AAAA;AAAA,mBAC7B;AAAA,gBAEJ;AAAA;AAAA;AACF;AAAA;AAAA;AACF,KACF;AAAA,IACC,UAAA,CAAW,SAAS,MAAA,oBACnB,GAAA;AAAA,MAAC,eAAA;AAAA,MAAA;AAAA,QACC,UAAU,UAAA,CAAW,QAAA;AAAA,QACrB,iBAAiB,UAAA,CAAW,eAAA;AAAA,QAC5B,QAAQ,UAAA,CAAW,MAAA;AAAA,QACnB,YAAY,UAAA,CAAW,UAAA;AAAA,QACvB,aAAa,UAAA,CAAW,WAAA;AAAA,QACxB,iBAAiB,UAAA,CAAW,eAAA;AAAA,QAC5B,YAAY,UAAA,CAAW,UAAA;AAAA,QACvB,gBAAgB,UAAA,CAAW,cAAA;AAAA,QAC3B,kBAAkB,UAAA,CAAW,gBAAA;AAAA,QAC7B,qBAAqB,UAAA,CAAW,mBAAA;AAAA,QAChC,UAAU,UAAA,CAAW;AAAA;AAAA;AACvB,GAAA,EAEJ,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"Table.esm.js","sources":["../../../../src/components/Table/components/Table.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useId } from 'react-aria';\nimport {\n type Key,\n ResizableTableContainer,\n Virtualizer,\n} from 'react-aria-components';\nimport { TableLayout } from '@react-stately/layout';\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { TableWrapperDefinition } from '../definition';\nimport { TableRoot } from './TableRoot';\nimport { TableHeader } from './TableHeader';\nimport { TableBody } from './TableBody';\nimport { Row } from './Row';\nimport { Column } from './Column';\nimport { TablePagination } from '../../TablePagination';\nimport type {\n TableProps,\n TableItem,\n RowConfig,\n RowRenderFn,\n TablePaginationType,\n} from '../types';\nimport { useMemo } from 'react';\nimport { VisuallyHidden } from '../../VisuallyHidden';\nimport { Flex } from '../../Flex';\nimport { TableBodySkeleton } from './TableBodySkeleton';\n\nfunction isRowRenderFn<T extends TableItem>(\n rowConfig: RowConfig<T> | RowRenderFn<T> | undefined,\n): rowConfig is RowRenderFn<T> {\n return typeof rowConfig === 'function';\n}\n\nfunction useDisabledRows<T extends TableItem>({\n data,\n rowConfig,\n}: Pick<TableProps<T>, 'data' | 'rowConfig'>): Set<Key> | undefined {\n return useMemo(() => {\n if (!data || typeof rowConfig === 'function' || !rowConfig?.getIsDisabled) {\n return;\n }\n\n return data.reduce<Set<Key>>((set, item) => {\n const isDisabled = rowConfig.getIsDisabled?.(item);\n if (isDisabled) {\n set.add(String(item.id));\n }\n return set;\n }, new Set<Key>());\n }, [data, rowConfig]);\n}\n\nfunction useLiveRegionLabel(\n pagination: TablePaginationType,\n isStale: boolean,\n isLoading: boolean,\n hasData: boolean,\n): string {\n if (isLoading) {\n return 'Loading table data.';\n }\n\n if (!hasData || pagination.type === 'none') {\n return '';\n }\n\n const { pageSize, offset, totalCount, getLabel } = pagination;\n\n if (isStale) {\n return 'Loading table data.';\n }\n\n let liveRegionLabel = 'Table page loaded. ';\n\n if (getLabel) {\n liveRegionLabel += getLabel({ pageSize, offset, totalCount });\n } else if (offset !== undefined) {\n const fromCount = offset + 1;\n const toCount = Math.min(offset + pageSize, totalCount ?? 0);\n liveRegionLabel += `Showing ${fromCount} to ${toCount} of ${totalCount}`;\n }\n return liveRegionLabel;\n}\n\n/** @public */\nexport function Table<T extends TableItem>({\n columnConfig,\n data,\n loading = false,\n isStale = false,\n error,\n pagination,\n sort,\n rowConfig,\n selection,\n emptyState,\n className,\n style,\n virtualized,\n}: TableProps<T>) {\n const {\n ownProps: { classes },\n } = useDefinition(TableWrapperDefinition, { className });\n const liveRegionId = useId();\n\n const visibleColumns = useMemo(\n () => columnConfig.filter(col => !col.isHidden),\n [columnConfig],\n );\n const disabledRows = useDisabledRows({ data, rowConfig });\n\n const {\n mode: selectionMode,\n selected: selectedKeys,\n behavior: selectionBehavior,\n onSelectionChange,\n } = selection || {};\n\n const isInitialLoading = loading && !data;\n\n if (error) {\n return (\n <div className={classes.root} style={style}>\n Error: {error.message}\n </div>\n );\n }\n\n const liveRegionLabel = useLiveRegionLabel(\n pagination,\n isStale,\n isInitialLoading,\n data !== undefined,\n );\n\n const manualColumnSizing = columnConfig.some(\n col =>\n col.width != null ||\n col.minWidth != null ||\n col.maxWidth != null ||\n col.defaultWidth != null,\n );\n\n const wrapResizable = manualColumnSizing\n ? (elem: React.ReactNode) => (\n <ResizableTableContainer className={classes.resizableContainer}>\n {elem}\n </ResizableTableContainer>\n )\n : (elem: React.ReactNode) => <>{elem}</>;\n\n const layoutOptions =\n typeof virtualized === 'object' ? virtualized : undefined;\n\n const wrapVirtualized = (elem: React.ReactNode) =>\n virtualized ? (\n <Virtualizer layout={TableLayout} layoutOptions={layoutOptions}>\n {elem}\n </Virtualizer>\n ) : (\n elem\n );\n\n return (\n <div className={classes.root} style={style}>\n <VisuallyHidden aria-live=\"polite\" id={liveRegionId}>\n {liveRegionLabel}\n </VisuallyHidden>\n {wrapResizable(\n wrapVirtualized(\n <TableRoot\n {...(isInitialLoading\n ? {}\n : {\n selectionMode,\n selectionBehavior,\n selectedKeys,\n onSelectionChange,\n })}\n sortDescriptor={sort?.descriptor ?? undefined}\n onSortChange={sort?.onSortChange}\n disabledKeys={disabledRows}\n stale={isStale}\n loading={isInitialLoading}\n aria-describedby={liveRegionId}\n >\n <TableHeader columns={visibleColumns}>\n {column =>\n column.header ? (\n column.header()\n ) : (\n <Column\n id={column.id}\n isRowHeader={column.isRowHeader}\n allowsSorting={column.isSortable}\n width={column.width}\n defaultWidth={column.defaultWidth}\n minWidth={column.minWidth}\n maxWidth={column.maxWidth}\n >\n {column.label}\n </Column>\n )\n }\n </TableHeader>\n {isInitialLoading ? (\n <TableBodySkeleton columns={visibleColumns} />\n ) : (\n <TableBody\n items={data}\n dependencies={[visibleColumns]}\n renderEmptyState={\n emptyState ? () => <Flex p=\"3\">{emptyState}</Flex> : undefined\n }\n >\n {item => {\n const itemIndex = data?.indexOf(item) ?? -1;\n\n if (isRowRenderFn(rowConfig)) {\n return rowConfig({\n item,\n index: itemIndex,\n });\n }\n\n return (\n <Row\n id={String(item.id)}\n columns={visibleColumns}\n href={rowConfig?.getHref?.(item)}\n onAction={\n rowConfig?.onClick\n ? () => rowConfig?.onClick?.(item)\n : undefined\n }\n >\n {column => column.cell(item)}\n </Row>\n );\n }}\n </TableBody>\n )}\n </TableRoot>,\n ),\n )}\n {pagination.type === 'page' && (\n <TablePagination\n pageSize={pagination.pageSize}\n pageSizeOptions={pagination.pageSizeOptions}\n offset={pagination.offset}\n totalCount={pagination.totalCount}\n hasNextPage={pagination.hasNextPage}\n hasPreviousPage={pagination.hasPreviousPage}\n onNextPage={pagination.onNextPage}\n onPreviousPage={pagination.onPreviousPage}\n onPageSizeChange={pagination.onPageSizeChange}\n showPageSizeOptions={pagination.showPageSizeOptions}\n getLabel={pagination.getLabel}\n />\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { TableBody } from './TableBody.esm.js';
|
|
3
|
+
import { Row } from './Row.esm.js';
|
|
4
|
+
import { Cell } from './Cell.esm.js';
|
|
5
|
+
import { Skeleton } from '../../Skeleton/Skeleton.esm.js';
|
|
6
|
+
import 'clsx';
|
|
7
|
+
import '../../../hooks/useBreakpoint.esm.js';
|
|
8
|
+
import '../../../hooks/useBg.esm.js';
|
|
9
|
+
import '../../../hooks/useDefinition/helpers.esm.js';
|
|
10
|
+
import '../../../analytics/useAnalytics.esm.js';
|
|
11
|
+
import '../../Skeleton/Skeleton.module.css.esm.js';
|
|
12
|
+
|
|
13
|
+
const SKELETON_ROW_COUNT = 5;
|
|
14
|
+
const SKELETON_WIDTHS = ["75%", "50%", "60%", "45%", "70%"];
|
|
15
|
+
const skeletonItems = Array.from({ length: SKELETON_ROW_COUNT }, (_, i) => ({
|
|
16
|
+
id: `skeleton-${i}`
|
|
17
|
+
}));
|
|
18
|
+
function TableBodySkeleton({
|
|
19
|
+
columns
|
|
20
|
+
}) {
|
|
21
|
+
return /* @__PURE__ */ jsx(TableBody, { items: skeletonItems, dependencies: [columns], children: (item) => {
|
|
22
|
+
const rowIndex = Number(item.id.split("-")[1]);
|
|
23
|
+
return /* @__PURE__ */ jsx(Row, { id: item.id, columns, children: (column) => /* @__PURE__ */ jsx(Cell, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(
|
|
24
|
+
Skeleton,
|
|
25
|
+
{
|
|
26
|
+
width: SKELETON_WIDTHS[(rowIndex + columns.indexOf(column)) % SKELETON_WIDTHS.length]
|
|
27
|
+
}
|
|
28
|
+
) }, column.id) });
|
|
29
|
+
} });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { TableBodySkeleton };
|
|
33
|
+
//# sourceMappingURL=TableBodySkeleton.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableBodySkeleton.esm.js","sources":["../../../../src/components/Table/components/TableBodySkeleton.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TableBody } from './TableBody';\nimport { Row } from './Row';\nimport { Cell } from './Cell';\nimport { Skeleton } from '../../Skeleton';\nimport type { ColumnConfig, TableItem } from '../types';\n\nconst SKELETON_ROW_COUNT = 5;\nconst SKELETON_WIDTHS = ['75%', '50%', '60%', '45%', '70%'];\n\nconst skeletonItems = Array.from({ length: SKELETON_ROW_COUNT }, (_, i) => ({\n id: `skeleton-${i}`,\n}));\n\n/** @internal */\nexport function TableBodySkeleton<T extends TableItem>({\n columns,\n}: {\n columns: readonly ColumnConfig<T>[];\n}) {\n return (\n <TableBody items={skeletonItems} dependencies={[columns]}>\n {item => {\n const rowIndex = Number(item.id.split('-')[1]);\n return (\n <Row id={item.id} columns={columns}>\n {column => (\n <Cell key={column.id} aria-hidden=\"true\">\n <Skeleton\n width={\n SKELETON_WIDTHS[\n (rowIndex + columns.indexOf(column)) %\n SKELETON_WIDTHS.length\n ]\n }\n />\n </Cell>\n )}\n </Row>\n );\n }}\n </TableBody>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAsBA,MAAM,kBAAA,GAAqB,CAAA;AAC3B,MAAM,kBAAkB,CAAC,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,OAAO,KAAK,CAAA;AAE1D,MAAM,aAAA,GAAgB,MAAM,IAAA,CAAK,EAAE,QAAQ,kBAAA,EAAmB,EAAG,CAAC,CAAA,EAAG,CAAA,MAAO;AAAA,EAC1E,EAAA,EAAI,YAAY,CAAC,CAAA;AACnB,CAAA,CAAE,CAAA;AAGK,SAAS,iBAAA,CAAuC;AAAA,EACrD;AACF,CAAA,EAEG;AACD,EAAA,uBACE,GAAA,CAAC,aAAU,KAAA,EAAO,aAAA,EAAe,cAAc,CAAC,OAAO,GACpD,QAAA,EAAA,CAAA,IAAA,KAAQ;AACP,IAAA,MAAM,QAAA,GAAW,OAAO,IAAA,CAAK,EAAA,CAAG,MAAM,GAAG,CAAA,CAAE,CAAC,CAAC,CAAA;AAC7C,IAAA,uBACE,GAAA,CAAC,GAAA,EAAA,EAAI,EAAA,EAAI,IAAA,CAAK,EAAA,EAAI,SACf,QAAA,EAAA,CAAA,MAAA,qBACC,GAAA,CAAC,IAAA,EAAA,EAAqB,aAAA,EAAY,MAAA,EAChC,QAAA,kBAAA,GAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,KAAA,EACE,iBACG,QAAA,GAAW,OAAA,CAAQ,QAAQ,MAAM,CAAA,IAChC,gBAAgB,MACpB;AAAA;AAAA,KAEJ,EAAA,EARS,MAAA,CAAO,EASlB,CAAA,EAEJ,CAAA;AAAA,EAEJ,CAAA,EACF,CAAA;AAEJ;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsxs, jsx
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useTableOptions, TableHeader as TableHeader$1, Collection } from 'react-aria-components';
|
|
3
3
|
import { Checkbox } from '../../Checkbox/Checkbox.esm.js';
|
|
4
4
|
import { useDefinition } from '../../../hooks/useDefinition/useDefinition.esm.js';
|
|
@@ -20,7 +20,7 @@ const TableHeader = (props) => {
|
|
|
20
20
|
minWidth: 40,
|
|
21
21
|
maxWidth: 40,
|
|
22
22
|
className: classes.headSelection,
|
|
23
|
-
children: /* @__PURE__ */ jsx(Flex, { justify: "center", align: "center", children: /* @__PURE__ */ jsx(Checkbox, { slot: "selection",
|
|
23
|
+
children: /* @__PURE__ */ jsx(Flex, { justify: "center", align: "center", "aria-label": "Row selection", children: /* @__PURE__ */ jsx(Checkbox, { slot: "selection", "aria-label": "Select all" }) })
|
|
24
24
|
}
|
|
25
25
|
),
|
|
26
26
|
/* @__PURE__ */ jsx(Collection, { items: columns, children })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableHeader.esm.js","sources":["../../../../src/components/Table/components/TableHeader.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n TableHeader as ReactAriaTableHeader,\n Collection,\n useTableOptions,\n} from 'react-aria-components';\nimport { Checkbox } from '../../Checkbox';\nimport { Column } from './Column';\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { TableHeaderDefinition } from '../definition';\nimport type { TableHeaderProps } from '../types';\nimport { Flex } from '../../Flex';\n\n/** @public */\nexport const TableHeader = <T extends object>(props: TableHeaderProps<T>) => {\n let { selectionBehavior, selectionMode } = useTableOptions();\n\n const { ownProps, restProps } = useDefinition(TableHeaderDefinition, props);\n const { classes, columns, children } = ownProps;\n\n return (\n <ReactAriaTableHeader className={classes.root} {...restProps}>\n {selectionBehavior === 'toggle' && selectionMode === 'multiple' && (\n <Column\n width={40}\n minWidth={40}\n maxWidth={40}\n className={classes.headSelection}\n >\n <Flex justify=\"center\" align=\"center\">\n <Checkbox slot=\"selection\"
|
|
1
|
+
{"version":3,"file":"TableHeader.esm.js","sources":["../../../../src/components/Table/components/TableHeader.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n TableHeader as ReactAriaTableHeader,\n Collection,\n useTableOptions,\n} from 'react-aria-components';\nimport { Checkbox } from '../../Checkbox';\nimport { Column } from './Column';\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { TableHeaderDefinition } from '../definition';\nimport type { TableHeaderProps } from '../types';\nimport { Flex } from '../../Flex';\n\n/** @public */\nexport const TableHeader = <T extends object>(props: TableHeaderProps<T>) => {\n let { selectionBehavior, selectionMode } = useTableOptions();\n\n const { ownProps, restProps } = useDefinition(TableHeaderDefinition, props);\n const { classes, columns, children } = ownProps;\n\n return (\n <ReactAriaTableHeader className={classes.root} {...restProps}>\n {selectionBehavior === 'toggle' && selectionMode === 'multiple' && (\n <Column\n width={40}\n minWidth={40}\n maxWidth={40}\n className={classes.headSelection}\n >\n <Flex justify=\"center\" align=\"center\" aria-label=\"Row selection\">\n <Checkbox slot=\"selection\" aria-label=\"Select all\" />\n </Flex>\n </Column>\n )}\n <Collection items={columns}>{children}</Collection>\n </ReactAriaTableHeader>\n );\n};\n"],"names":["ReactAriaTableHeader"],"mappings":";;;;;;;;;;AA6BO,MAAM,WAAA,GAAc,CAAmB,KAAA,KAA+B;AAC3E,EAAA,IAAI,EAAE,iBAAA,EAAmB,aAAA,EAAc,GAAI,eAAA,EAAgB;AAE3D,EAAA,MAAM,EAAE,QAAA,EAAU,SAAA,EAAU,GAAI,aAAA,CAAc,uBAAuB,KAAK,CAAA;AAC1E,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,QAAA,EAAS,GAAI,QAAA;AAEvC,EAAA,4BACGA,aAAA,EAAA,EAAqB,SAAA,EAAW,OAAA,CAAQ,IAAA,EAAO,GAAG,SAAA,EAChD,QAAA,EAAA;AAAA,IAAA,iBAAA,KAAsB,QAAA,IAAY,kBAAkB,UAAA,oBACnD,GAAA;AAAA,MAAC,MAAA;AAAA,MAAA;AAAA,QACC,KAAA,EAAO,EAAA;AAAA,QACP,QAAA,EAAU,EAAA;AAAA,QACV,QAAA,EAAU,EAAA;AAAA,QACV,WAAW,OAAA,CAAQ,aAAA;AAAA,QAEnB,QAAA,kBAAA,GAAA,CAAC,IAAA,EAAA,EAAK,OAAA,EAAQ,QAAA,EAAS,OAAM,QAAA,EAAS,YAAA,EAAW,eAAA,EAC/C,QAAA,kBAAA,GAAA,CAAC,QAAA,EAAA,EAAS,IAAA,EAAK,WAAA,EAAY,YAAA,EAAW,cAAa,CAAA,EACrD;AAAA;AAAA,KACF;AAAA,oBAEF,GAAA,CAAC,UAAA,EAAA,EAAW,KAAA,EAAO,OAAA,EAAU,QAAA,EAAS;AAAA,GAAA,EACxC,CAAA;AAEJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableRoot.esm.js","sources":["../../../../src/components/Table/components/TableRoot.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { TableDefinition } from '../definition';\nimport { Table as ReactAriaTable } from 'react-aria-components';\nimport { TableRootProps } from '../types';\n\n/** @public */\nexport const TableRoot = (props: TableRootProps) => {\n const { ownProps, restProps, dataAttributes } = useDefinition(\n TableDefinition,\n props,\n );\n\n return (\n <ReactAriaTable\n className={ownProps.classes.root}\n aria-label=\"Data table\"\n aria-busy={ownProps.stale}\n {...dataAttributes}\n {...restProps}\n />\n );\n};\n"],"names":["ReactAriaTable"],"mappings":";;;;;AAsBO,MAAM,SAAA,GAAY,CAAC,KAAA,KAA0B;AAClD,EAAA,MAAM,EAAE,QAAA,EAAU,SAAA,EAAW,cAAA,EAAe,GAAI,aAAA;AAAA,IAC9C,eAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,uBACE,GAAA;AAAA,IAACA,KAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,SAAS,OAAA,CAAQ,IAAA;AAAA,MAC5B,YAAA,EAAW,YAAA;AAAA,MACX,
|
|
1
|
+
{"version":3,"file":"TableRoot.esm.js","sources":["../../../../src/components/Table/components/TableRoot.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { TableDefinition } from '../definition';\nimport { Table as ReactAriaTable } from 'react-aria-components';\nimport { TableRootProps } from '../types';\n\n/** @public */\nexport const TableRoot = (props: TableRootProps) => {\n const { ownProps, restProps, dataAttributes } = useDefinition(\n TableDefinition,\n props,\n );\n\n return (\n <ReactAriaTable\n className={ownProps.classes.root}\n aria-label=\"Data table\"\n aria-busy={ownProps.stale || ownProps.loading}\n {...dataAttributes}\n {...restProps}\n />\n );\n};\n"],"names":["ReactAriaTable"],"mappings":";;;;;AAsBO,MAAM,SAAA,GAAY,CAAC,KAAA,KAA0B;AAClD,EAAA,MAAM,EAAE,QAAA,EAAU,SAAA,EAAW,cAAA,EAAe,GAAI,aAAA;AAAA,IAC9C,eAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,uBACE,GAAA;AAAA,IAACA,KAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,SAAS,OAAA,CAAQ,IAAA;AAAA,MAC5B,YAAA,EAAW,YAAA;AAAA,MACX,WAAA,EAAW,QAAA,CAAS,KAAA,IAAS,QAAA,CAAS,OAAA;AAAA,MACrC,GAAG,cAAA;AAAA,MACH,GAAG;AAAA;AAAA,GACN;AAEJ;;;;"}
|
|
@@ -3,16 +3,28 @@ import 'clsx';
|
|
|
3
3
|
import '../../hooks/useBreakpoint.esm.js';
|
|
4
4
|
import '../../hooks/useBg.esm.js';
|
|
5
5
|
import '../../hooks/useDefinition/helpers.esm.js';
|
|
6
|
+
import '../../analytics/useAnalytics.esm.js';
|
|
6
7
|
import { defineComponent } from '../../hooks/useDefinition/defineComponent.esm.js';
|
|
7
8
|
import styles from './Table.module.css.esm.js';
|
|
8
9
|
|
|
10
|
+
const TableWrapperDefinition = defineComponent()({
|
|
11
|
+
styles,
|
|
12
|
+
classNames: {
|
|
13
|
+
root: "bui-TableWrapper",
|
|
14
|
+
resizableContainer: "bui-TableResizableContainer"
|
|
15
|
+
},
|
|
16
|
+
propDefs: {
|
|
17
|
+
className: {}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
9
20
|
const TableDefinition = defineComponent()({
|
|
10
21
|
styles,
|
|
11
22
|
classNames: {
|
|
12
23
|
root: "bui-Table"
|
|
13
24
|
},
|
|
14
25
|
propDefs: {
|
|
15
|
-
stale: { dataAttribute: true }
|
|
26
|
+
stale: { dataAttribute: true },
|
|
27
|
+
loading: { dataAttribute: true }
|
|
16
28
|
}
|
|
17
29
|
});
|
|
18
30
|
const TableHeaderDefinition = defineComponent()({
|
|
@@ -35,6 +47,8 @@ const TableBodyDefinition = defineComponent()({
|
|
|
35
47
|
});
|
|
36
48
|
const RowDefinition = defineComponent()({
|
|
37
49
|
styles,
|
|
50
|
+
analytics: true,
|
|
51
|
+
bg: "consumer",
|
|
38
52
|
classNames: {
|
|
39
53
|
root: "bui-TableRow",
|
|
40
54
|
cell: "bui-TableCell",
|
|
@@ -43,7 +57,8 @@ const RowDefinition = defineComponent()({
|
|
|
43
57
|
propDefs: {
|
|
44
58
|
columns: {},
|
|
45
59
|
children: {},
|
|
46
|
-
href: {}
|
|
60
|
+
href: {},
|
|
61
|
+
noTrack: {}
|
|
47
62
|
}
|
|
48
63
|
});
|
|
49
64
|
const ColumnDefinition = defineComponent()({
|
|
@@ -51,6 +66,7 @@ const ColumnDefinition = defineComponent()({
|
|
|
51
66
|
classNames: {
|
|
52
67
|
root: "bui-TableHead",
|
|
53
68
|
headContent: "bui-TableHeadContent",
|
|
69
|
+
headLabel: "bui-TableHeadLabel",
|
|
54
70
|
headSortButton: "bui-TableHeadSortButton"
|
|
55
71
|
},
|
|
56
72
|
propDefs: {
|
|
@@ -101,5 +117,5 @@ const CellProfileDefinition = defineComponent()({
|
|
|
101
117
|
}
|
|
102
118
|
});
|
|
103
119
|
|
|
104
|
-
export { CellDefinition, CellProfileDefinition, CellTextDefinition, ColumnDefinition, RowDefinition, TableBodyDefinition, TableDefinition, TableHeaderDefinition };
|
|
120
|
+
export { CellDefinition, CellProfileDefinition, CellTextDefinition, ColumnDefinition, RowDefinition, TableBodyDefinition, TableDefinition, TableHeaderDefinition, TableWrapperDefinition };
|
|
105
121
|
//# sourceMappingURL=definition.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.esm.js","sources":["../../../src/components/Table/definition.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { defineComponent } from '../../hooks/useDefinition';\nimport type {\n TableRootOwnProps,\n TableHeaderOwnProps,\n TableBodyOwnProps,\n RowOwnProps,\n ColumnOwnProps,\n CellOwnProps,\n CellTextOwnProps,\n CellProfileOwnProps,\n} from './types';\nimport styles from './Table.module.css';\n\n/**\n * Component definition for Table\n * @public\n */\nexport const TableDefinition = defineComponent<TableRootOwnProps>()({\n styles,\n classNames: {\n root: 'bui-Table',\n },\n propDefs: {\n stale: { dataAttribute: true },\n },\n});\n\n/**\n * Component definition for TableHeader\n * @internal\n */\nexport const TableHeaderDefinition = defineComponent<TableHeaderOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHeader',\n headSelection: 'bui-TableHeadSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n },\n});\n\n/**\n * Component definition for TableBody\n * @internal\n */\nexport const TableBodyDefinition = defineComponent<TableBodyOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableBody',\n },\n propDefs: {},\n});\n\n/**\n * Component definition for Row\n * @internal\n */\nexport const RowDefinition = defineComponent<RowOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableRow',\n cell: 'bui-TableCell',\n cellSelection: 'bui-TableCellSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n href: {},\n },\n});\n\n/**\n * Component definition for Column\n * @internal\n */\nexport const ColumnDefinition = defineComponent<ColumnOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHead',\n headContent: 'bui-TableHeadContent',\n headSortButton: 'bui-TableHeadSortButton',\n },\n propDefs: {\n children: {},\n className: {},\n },\n});\n\n/**\n * Component definition for Cell\n * @internal\n */\nexport const CellDefinition = defineComponent<CellOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n },\n propDefs: {\n className: {},\n },\n});\n\n/**\n * Component definition for CellText\n * @internal\n */\nexport const CellTextDefinition = defineComponent<CellTextOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n cellIcon: 'bui-TableCellIcon',\n },\n propDefs: {\n title: {},\n description: {},\n color: { default: 'primary' },\n leadingIcon: {},\n href: {},\n className: {},\n },\n});\n\n/**\n * Component definition for CellProfile\n * @internal\n */\nexport const CellProfileDefinition = defineComponent<CellProfileOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n },\n propDefs: {\n src: {},\n name: {},\n href: {},\n description: {},\n color: { default: 'primary' },\n className: {},\n },\n});\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definition.esm.js","sources":["../../../src/components/Table/definition.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { defineComponent } from '../../hooks/useDefinition';\nimport type {\n TableRootOwnProps,\n TableHeaderOwnProps,\n TableBodyOwnProps,\n RowOwnProps,\n ColumnOwnProps,\n CellOwnProps,\n CellTextOwnProps,\n CellProfileOwnProps,\n} from './types';\nimport styles from './Table.module.css';\n\n/** @internal */\nexport const TableWrapperDefinition = defineComponent<{\n className?: string;\n}>()({\n styles,\n classNames: {\n root: 'bui-TableWrapper',\n resizableContainer: 'bui-TableResizableContainer',\n },\n propDefs: {\n className: {},\n },\n});\n\n/**\n * Component definition for Table\n * @public\n */\nexport const TableDefinition = defineComponent<TableRootOwnProps>()({\n styles,\n classNames: {\n root: 'bui-Table',\n },\n propDefs: {\n stale: { dataAttribute: true },\n loading: { dataAttribute: true },\n },\n});\n\n/**\n * Component definition for TableHeader\n * @internal\n */\nexport const TableHeaderDefinition = defineComponent<TableHeaderOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHeader',\n headSelection: 'bui-TableHeadSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n },\n});\n\n/**\n * Component definition for TableBody\n * @internal\n */\nexport const TableBodyDefinition = defineComponent<TableBodyOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableBody',\n },\n propDefs: {},\n});\n\n/**\n * Component definition for Row\n * @internal\n */\nexport const RowDefinition = defineComponent<RowOwnProps>()({\n styles,\n analytics: true,\n bg: 'consumer',\n classNames: {\n root: 'bui-TableRow',\n cell: 'bui-TableCell',\n cellSelection: 'bui-TableCellSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n href: {},\n noTrack: {},\n },\n});\n\n/**\n * Component definition for Column\n * @internal\n */\nexport const ColumnDefinition = defineComponent<ColumnOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHead',\n headContent: 'bui-TableHeadContent',\n headLabel: 'bui-TableHeadLabel',\n headSortButton: 'bui-TableHeadSortButton',\n },\n propDefs: {\n children: {},\n className: {},\n },\n});\n\n/**\n * Component definition for Cell\n * @internal\n */\nexport const CellDefinition = defineComponent<CellOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n },\n propDefs: {\n className: {},\n },\n});\n\n/**\n * Component definition for CellText\n * @internal\n */\nexport const CellTextDefinition = defineComponent<CellTextOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n cellIcon: 'bui-TableCellIcon',\n },\n propDefs: {\n title: {},\n description: {},\n color: { default: 'primary' },\n leadingIcon: {},\n href: {},\n className: {},\n },\n});\n\n/**\n * Component definition for CellProfile\n * @internal\n */\nexport const CellProfileDefinition = defineComponent<CellProfileOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n },\n propDefs: {\n src: {},\n name: {},\n href: {},\n description: {},\n color: { default: 'primary' },\n className: {},\n },\n});\n"],"names":[],"mappings":";;;;;;;;;AA8BO,MAAM,sBAAA,GAAyB,iBAEnC,CAAE;AAAA,EACH,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,kBAAA;AAAA,IACN,kBAAA,EAAoB;AAAA,GACtB;AAAA,EACA,QAAA,EAAU;AAAA,IACR,WAAW;AAAC;AAEhB,CAAC;AAMM,MAAM,eAAA,GAAkB,iBAAmC,CAAE;AAAA,EAClE,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM;AAAA,GACR;AAAA,EACA,QAAA,EAAU;AAAA,IACR,KAAA,EAAO,EAAE,aAAA,EAAe,IAAA,EAAK;AAAA,IAC7B,OAAA,EAAS,EAAE,aAAA,EAAe,IAAA;AAAK;AAEnC,CAAC;AAMM,MAAM,qBAAA,GAAwB,iBAAqC,CAAE;AAAA,EAC1E,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,iBAAA;AAAA,IACN,aAAA,EAAe;AAAA,GACjB;AAAA,EACA,QAAA,EAAU;AAAA,IACR,SAAS,EAAC;AAAA,IACV,UAAU;AAAC;AAEf,CAAC;AAMM,MAAM,mBAAA,GAAsB,iBAAmC,CAAE;AAAA,EACtE,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM;AAAA,GACR;AAAA,EACA,UAAU;AACZ,CAAC;AAMM,MAAM,aAAA,GAAgB,iBAA6B,CAAE;AAAA,EAC1D,MAAA;AAAA,EACA,SAAA,EAAW,IAAA;AAAA,EACX,EAAA,EAAI,UAAA;AAAA,EACJ,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,cAAA;AAAA,IACN,IAAA,EAAM,eAAA;AAAA,IAC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;AAAA,IACR,KAAK,EAAC;AAAA,IACN,MAAM,EAAC;AAAA,IACP,MAAM,EAAC;AAAA,IACP,aAAa,EAAC;AAAA,IACd,KAAA,EAAO,EAAE,OAAA,EAAS,SAAA,EAAU;AAAA,IAC5B,WAAW;AAAC;AAEhB,CAAC;;;;"}
|
|
@@ -11,11 +11,12 @@ function useCompletePagination(options, query) {
|
|
|
11
11
|
filterFn,
|
|
12
12
|
searchFn
|
|
13
13
|
} = options;
|
|
14
|
+
const hasGetData = "getData" in options;
|
|
14
15
|
const { initialOffset = 0 } = paginationOptions;
|
|
15
16
|
const defaultPageSize = getEffectivePageSize(paginationOptions);
|
|
16
17
|
const getData = useStableCallback(getDataProp);
|
|
17
18
|
const { sort, filter, search } = query;
|
|
18
|
-
const [items, setItems] = useState(
|
|
19
|
+
const [items, setItems] = useState(void 0);
|
|
19
20
|
const [isLoading, setIsLoading] = useState(!data);
|
|
20
21
|
const [error, setError] = useState(void 0);
|
|
21
22
|
const [loadCount, setLoadCount] = useState(0);
|
|
@@ -23,6 +24,10 @@ function useCompletePagination(options, query) {
|
|
|
23
24
|
const [pageSize, setPageSize] = useState(defaultPageSize);
|
|
24
25
|
useEffect(() => {
|
|
25
26
|
if (data) {
|
|
27
|
+
setIsLoading(false);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!hasGetData) {
|
|
26
31
|
return;
|
|
27
32
|
}
|
|
28
33
|
let cancelled = false;
|
|
@@ -31,9 +36,9 @@ function useCompletePagination(options, query) {
|
|
|
31
36
|
(async () => {
|
|
32
37
|
try {
|
|
33
38
|
const result = getData();
|
|
34
|
-
const
|
|
39
|
+
const resolvedData = result instanceof Promise ? await result : result;
|
|
35
40
|
if (!cancelled) {
|
|
36
|
-
setItems(
|
|
41
|
+
setItems(resolvedData);
|
|
37
42
|
setIsLoading(false);
|
|
38
43
|
}
|
|
39
44
|
} catch (err) {
|
|
@@ -46,7 +51,7 @@ function useCompletePagination(options, query) {
|
|
|
46
51
|
return () => {
|
|
47
52
|
cancelled = true;
|
|
48
53
|
};
|
|
49
|
-
}, [data, getData, loadCount]);
|
|
54
|
+
}, [data, getData, hasGetData, loadCount]);
|
|
50
55
|
const prevQueryRef = useRef(query);
|
|
51
56
|
useEffect(() => {
|
|
52
57
|
if (prevQueryRef.current !== query) {
|
|
@@ -56,6 +61,9 @@ function useCompletePagination(options, query) {
|
|
|
56
61
|
}, [query]);
|
|
57
62
|
const resolvedItems = useMemo(() => data ?? items, [data, items]);
|
|
58
63
|
const processedData = useMemo(() => {
|
|
64
|
+
if (!resolvedItems) {
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
59
67
|
let result = [...resolvedItems];
|
|
60
68
|
if (filter !== void 0 && filterFn) {
|
|
61
69
|
result = filterFn(result, filter);
|
|
@@ -68,9 +76,9 @@ function useCompletePagination(options, query) {
|
|
|
68
76
|
}
|
|
69
77
|
return result;
|
|
70
78
|
}, [resolvedItems, sort, filter, search, filterFn, searchFn, sortFn]);
|
|
71
|
-
const totalCount = processedData
|
|
79
|
+
const totalCount = processedData?.length ?? 0;
|
|
72
80
|
const paginatedData = useMemo(
|
|
73
|
-
() => processedData
|
|
81
|
+
() => processedData?.slice(offset, offset + pageSize),
|
|
74
82
|
[processedData, offset, pageSize]
|
|
75
83
|
);
|
|
76
84
|
const hasNextPage = offset + pageSize < totalCount;
|