@spaced-out/ui-design-system 0.3.38 → 0.3.39-beta.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/.cspell/custom-words.txt +4 -0
- package/.github/workflows/publish_to_npm.yml +32 -4
- package/CHANGELOG.md +14 -0
- package/dts-generator/.editorconfig +10 -0
- package/dts-generator/.gitattributes +4 -0
- package/dts-generator/README.md +63 -0
- package/dts-generator/convert.js +101 -0
- package/dts-generator/package.json +16 -0
- package/gulpfile.js +20 -1
- package/lib/components/Avatar/Avatar.d.ts +264 -0
- package/lib/components/Avatar/index.d.ts +1 -0
- package/lib/components/AvatarGroup/AvatarGroup.d.ts +161 -0
- package/lib/components/AvatarGroup/index.d.ts +1 -0
- package/lib/components/Badge/Badge.d.ts +138 -0
- package/lib/components/Badge/index.d.ts +1 -0
- package/lib/components/Banner/Banner.d.ts +52 -0
- package/lib/components/Banner/index.d.ts +1 -0
- package/lib/components/Breadcrumbs/BreadcrumbLink/BreadcrumbLink.d.ts +50 -0
- package/lib/components/Breadcrumbs/BreadcrumbLink/index.d.ts +1 -0
- package/lib/components/Breadcrumbs/Breadcrumbs.d.ts +64 -0
- package/lib/components/Breadcrumbs/index.d.ts +2 -0
- package/lib/components/Button/Button.d.ts +288 -0
- package/lib/components/Button/index.d.ts +14 -0
- package/lib/components/ButtonDropdown/ButtonDropdown.d.ts +192 -0
- package/lib/components/ButtonDropdown/SimpleButtonDropdown.d.ts +148 -0
- package/lib/components/ButtonDropdown/index.d.ts +2 -0
- package/lib/components/ButtonTabs/ButtonTab/ButtonTab.d.ts +82 -0
- package/lib/components/ButtonTabs/ButtonTab/index.d.ts +1 -0
- package/lib/components/ButtonTabs/ButtonTabDropdown.d.ts +118 -0
- package/lib/components/ButtonTabs/ButtonTabs.d.ts +113 -0
- package/lib/components/ButtonTabs/index.d.ts +2 -0
- package/lib/components/Card/Card.d.ts +163 -0
- package/lib/components/Card/index.d.ts +1 -0
- package/lib/components/Charts/ChartTooltip/index.d.ts +10 -0
- package/lib/components/Charts/ChartWrapper/ChartWrapper.d.ts +184 -0
- package/lib/components/Charts/ChartWrapper/index.d.ts +1 -0
- package/lib/components/Charts/ColumnChart/ColumnChart.d.ts +111 -0
- package/lib/components/Charts/ColumnChart/index.d.ts +1 -0
- package/lib/components/Charts/DonutChart/DonutChart.d.ts +142 -0
- package/lib/components/Charts/DonutChart/index.d.ts +1 -0
- package/lib/components/Charts/FunnelChart/FunnelChart.d.ts +99 -0
- package/lib/components/Charts/FunnelChart/index.d.ts +1 -0
- package/lib/components/Charts/LineChart/LineChart.d.ts +97 -0
- package/lib/components/Charts/LineChart/index.d.ts +1 -0
- package/lib/components/Charts/SpiderChart/SpiderChart.d.ts +95 -0
- package/lib/components/Charts/SpiderChart/index.d.ts +1 -0
- package/lib/components/Charts/index.d.ts +7 -0
- package/lib/components/ChatBubble/ChatBubble.d.ts +203 -0
- package/lib/components/ChatBubble/index.d.ts +1 -0
- package/lib/components/Checkbox/Checkbox.d.ts +165 -0
- package/lib/components/Checkbox/CheckboxGroup.d.ts +113 -0
- package/lib/components/Checkbox/index.d.ts +2 -0
- package/lib/components/Chip/Chip.d.ts +181 -0
- package/lib/components/Chip/index.d.ts +2 -0
- package/lib/components/CircularLoader/CircularLoader.d.ts +56 -0
- package/lib/components/CircularLoader/index.d.ts +1 -0
- package/lib/components/CollapsibleCard/CollapsibleCard.d.ts +134 -0
- package/lib/components/CollapsibleCard/index.d.ts +1 -0
- package/lib/components/Combobox/Combobox.d.ts +292 -0
- package/lib/components/Combobox/helper.d.ts +205 -0
- package/lib/components/Combobox/index.d.ts +1 -0
- package/lib/components/ConditionalWrapper/ConditionalWrapper.d.ts +12 -0
- package/lib/components/ConditionalWrapper/index.d.ts +1 -0
- package/lib/components/DateRangePicker/Calendar.d.ts +119 -0
- package/lib/components/DateRangePicker/DateRangePicker.d.ts +196 -0
- package/lib/components/DateRangePicker/DateRangeWrapper.d.ts +311 -0
- package/lib/components/DateRangePicker/Day.d.ts +70 -0
- package/lib/components/DateRangePicker/index.d.ts +1 -0
- package/lib/components/Dialog/Dialog.d.ts +208 -0
- package/lib/components/Dialog/index.d.ts +1 -0
- package/lib/components/Disclaimer/Disclaimer.d.ts +32 -0
- package/lib/components/Disclaimer/index.d.ts +1 -0
- package/lib/components/Dropdown/Dropdown.d.ts +145 -0
- package/lib/components/Dropdown/SimpleDropdown.d.ts +142 -0
- package/lib/components/Dropdown/index.d.ts +2 -0
- package/lib/components/EmptyState/EmptyImages/CalendarEmptyImage.d.ts +108 -0
- package/lib/components/EmptyState/EmptyImages/ChartEmptyImage.d.ts +194 -0
- package/lib/components/EmptyState/EmptyImages/DataEmptyImage.d.ts +116 -0
- package/lib/components/EmptyState/EmptyImages/FileEmptyImage.d.ts +133 -0
- package/lib/components/EmptyState/EmptyImages/MessageEmptyImage.d.ts +64 -0
- package/lib/components/EmptyState/EmptyImages/UploadEmptyImage.d.ts +67 -0
- package/lib/components/EmptyState/EmptyImages/index.d.ts +6 -0
- package/lib/components/EmptyState/EmptyState.d.ts +82 -0
- package/lib/components/EmptyState/index.d.ts +1 -0
- package/lib/components/ErrorMessage/ErrorImages/ForbiddenImage.d.ts +85 -0
- package/lib/components/ErrorMessage/ErrorImages/NotFoundImage.d.ts +117 -0
- package/lib/components/ErrorMessage/ErrorImages/ServerErrorImage.d.ts +237 -0
- package/lib/components/ErrorMessage/ErrorImages/UnauthorizedImage.d.ts +73 -0
- package/lib/components/ErrorMessage/ErrorImages/index.d.ts +4 -0
- package/lib/components/ErrorMessage/ErrorMessage.d.ts +86 -0
- package/lib/components/ErrorMessage/index.d.ts +1 -0
- package/lib/components/FileUpload/FileBlock/FileBlock.d.ts +137 -0
- package/lib/components/FileUpload/FileBlock/index.d.ts +1 -0
- package/lib/components/FileUpload/FileUpload.d.ts +190 -0
- package/lib/components/FileUpload/index.d.ts +2 -0
- package/lib/components/FocusManager/FocusManager.d.ts +52 -0
- package/lib/components/FocusManager/index.d.ts +1 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/FocusManagerWithArrowKeyNavigation.d.ts +137 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/index.d.ts +1 -0
- package/lib/components/FormTitleWrapper/FormTitleWrapper.d.ts +62 -0
- package/lib/components/FormTitleWrapper/index.d.ts +1 -0
- package/lib/components/Grid/Grid.d.ts +104 -0
- package/lib/components/Grid/index.d.ts +1 -0
- package/lib/components/Icon/ClickableIcon.d.ts +101 -0
- package/lib/components/Icon/Icon.d.ts +71 -0
- package/lib/components/Icon/Icon.docs.d.ts +138 -0
- package/lib/components/Icon/SemanticIcon.d.ts +42 -0
- package/lib/components/Icon/index.d.ts +3 -0
- package/lib/components/InContextAlert/InContextAlert.d.ts +210 -0
- package/lib/components/InContextAlert/index.d.ts +1 -0
- package/lib/components/InlineDropdown/InlineDropdown.d.ts +146 -0
- package/lib/components/InlineDropdown/SimpleInlineDropdown.d.ts +145 -0
- package/lib/components/InlineDropdown/index.d.ts +2 -0
- package/lib/components/Input/Input.d.ts +327 -0
- package/lib/components/Input/index.d.ts +1 -0
- package/lib/components/KPIBox/KPIBox.d.ts +89 -0
- package/lib/components/KPIBox/index.d.ts +1 -0
- package/lib/components/LinearLoader/LinearLoader.d.ts +44 -0
- package/lib/components/LinearLoader/index.d.ts +1 -0
- package/lib/components/Link/Link.d.ts +225 -0
- package/lib/components/Link/index.d.ts +1 -0
- package/lib/components/Menu/Menu.d.ts +379 -0
- package/lib/components/Menu/MenuOptionButton.d.ts +199 -0
- package/lib/components/Menu/index.d.ts +2 -0
- package/lib/components/Modal/Modal.d.ts +354 -0
- package/lib/components/Modal/index.d.ts +14 -0
- package/lib/components/Notification/Notification.d.ts +147 -0
- package/lib/components/Notification/index.d.ts +1 -0
- package/lib/components/OptionButton/OptionButton.d.ts +150 -0
- package/lib/components/OptionButton/SimpleOptionButton.d.ts +150 -0
- package/lib/components/OptionButton/index.d.ts +2 -0
- package/lib/components/PageTitle/PageTitle.d.ts +256 -0
- package/lib/components/PageTitle/index.d.ts +1 -0
- package/lib/components/Pagination/Pagination.d.ts +144 -0
- package/lib/components/Pagination/PaginationItem.d.ts +136 -0
- package/lib/components/Pagination/index.d.ts +1 -0
- package/lib/components/Panel/Panel.d.ts +168 -0
- package/lib/components/Panel/index.d.ts +9 -0
- package/lib/components/ProgressDonut/ProgressDonut.d.ts +102 -0
- package/lib/components/ProgressDonut/index.d.ts +1 -0
- package/lib/components/PromptChip/PromptChip.d.ts +167 -0
- package/lib/components/PromptChip/index.d.ts +1 -0
- package/lib/components/PromptInput/PromptInput.d.ts +189 -0
- package/lib/components/PromptInput/index.d.ts +1 -0
- package/lib/components/RadioButton/RadioButton.d.ts +132 -0
- package/lib/components/RadioButton/RadioGroup.d.ts +88 -0
- package/lib/components/RadioButton/index.d.ts +2 -0
- package/lib/components/RadioTile/RadioTile.d.ts +109 -0
- package/lib/components/RadioTile/index.d.ts +1 -0
- package/lib/components/RangeSlider/RangeSlider.d.ts +207 -0
- package/lib/components/RangeSlider/index.d.ts +1 -0
- package/lib/components/Rating/Rating.d.ts +131 -0
- package/lib/components/Rating/index.d.ts +1 -0
- package/lib/components/ScoreBar/ScoreBar.d.ts +122 -0
- package/lib/components/ScoreBar/index.d.ts +1 -0
- package/lib/components/SearchInput/SearchInput.d.ts +79 -0
- package/lib/components/SearchInput/index.d.ts +2 -0
- package/lib/components/Separator/Separator.d.ts +51 -0
- package/lib/components/Separator/index.d.ts +1 -0
- package/lib/components/Shimmer/Shimmer.d.ts +131 -0
- package/lib/components/Shimmer/index.d.ts +1 -0
- package/lib/components/SideMenuLink/SideMenuLink.d.ts +336 -0
- package/lib/components/SideMenuLink/index.d.ts +1 -0
- package/lib/components/StatusIndicator/StatusIndicator.d.ts +60 -0
- package/lib/components/StatusIndicator/index.d.ts +1 -0
- package/lib/components/Stepper/Step/Step.d.ts +119 -0
- package/lib/components/Stepper/Step/StepContent.d.ts +35 -0
- package/lib/components/Stepper/Step/StepLabel.d.ts +35 -0
- package/lib/components/Stepper/Step/index.d.ts +3 -0
- package/lib/components/Stepper/Stepper.d.ts +60 -0
- package/lib/components/Stepper/index.d.ts +2 -0
- package/lib/components/StickyBar/StickyBar.d.ts +55 -0
- package/lib/components/StickyBar/index.d.ts +1 -0
- package/lib/components/SubMenu/SubMenu.d.ts +89 -0
- package/lib/components/SubMenu/SubMenuGroup.d.ts +156 -0
- package/lib/components/SubMenu/SubMenuItem.d.ts +161 -0
- package/lib/components/SubMenu/SubMenuLink.d.ts +81 -0
- package/lib/components/SubMenu/index.d.ts +4 -0
- package/lib/components/Table/Cell.d.ts +107 -0
- package/lib/components/Table/DefaultRow.d.ts +144 -0
- package/lib/components/Table/DefaultTableHeader.d.ts +236 -0
- package/lib/components/Table/StaticTable.d.ts +198 -0
- package/lib/components/Table/Table.d.ts +113 -0
- package/lib/components/Table/Table.docs.d.ts +532 -0
- package/lib/components/Table/TableActionBar.d.ts +48 -0
- package/lib/components/Table/TableBottomBar.d.ts +20 -0
- package/lib/components/Table/TableTopBar.d.ts +20 -0
- package/lib/components/Table/dummyTableData.d.ts +2189 -0
- package/lib/components/Table/hooks.d.ts +98 -0
- package/lib/components/Table/index.d.ts +8 -0
- package/lib/components/Tabs/Tab/Tab.d.ts +146 -0
- package/lib/components/Tabs/Tab/index.d.ts +1 -0
- package/lib/components/Tabs/TabList/TabDropdown.d.ts +100 -0
- package/lib/components/Tabs/TabList/TabList.d.ts +157 -0
- package/lib/components/Tabs/TabList/index.d.ts +1 -0
- package/lib/components/Tabs/index.d.ts +2 -0
- package/lib/components/Text/Text.d.ts +1021 -0
- package/lib/components/Text/index.d.ts +30 -0
- package/lib/components/TextTile/TextTile.d.ts +40 -0
- package/lib/components/TextTile/index.d.ts +1 -0
- package/lib/components/Textarea/Textarea.d.ts +132 -0
- package/lib/components/Textarea/index.d.ts +2 -0
- package/lib/components/Timeline/Timeline.d.ts +40 -0
- package/lib/components/Timeline/TimelineItem/TimelineItem.d.ts +121 -0
- package/lib/components/Timeline/TimelineItem/index.d.ts +1 -0
- package/lib/components/Timeline/index.d.ts +2 -0
- package/lib/components/Toast/Toast.d.ts +248 -0
- package/lib/components/Toast/ToastContainer.d.ts +140 -0
- package/lib/components/Toast/ToastManager.d.ts +58 -0
- package/lib/components/Toast/index.d.ts +10 -0
- package/lib/components/Toggle/Toggle.d.ts +111 -0
- package/lib/components/Toggle/index.d.ts +1 -0
- package/lib/components/TokenListInput/TokenListInput.d.ts +333 -0
- package/lib/components/TokenListInput/TokenValueChips.d.ts +64 -0
- package/lib/components/TokenListInput/index.d.ts +1 -0
- package/lib/components/Tooltip/Tooltip.d.ts +186 -0
- package/lib/components/Tooltip/index.d.ts +1 -0
- package/lib/components/Truncate/Truncate.d.ts +87 -0
- package/lib/components/Truncate/index.d.ts +2 -0
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.d.ts +95 -0
- package/lib/components/TruncatedTextWithTooltip/index.d.ts +1 -0
- package/lib/components/Typeahead/SimpleTypeahead.d.ts +141 -0
- package/lib/components/Typeahead/Typeahead.d.ts +217 -0
- package/lib/components/Typeahead/index.d.ts +2 -0
- package/lib/components/WeekdayPicker/WeekdayPicker.d.ts +242 -0
- package/lib/components/WeekdayPicker/index.d.ts +1 -0
- package/lib/components/index.d.ts +71 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/useArbitraryOptionAddition/index.d.ts +1 -0
- package/lib/hooks/useArbitraryOptionAddition/useArbitraryOptionAddition.d.ts +124 -0
- package/lib/hooks/useCopyToClipboard/index.d.ts +1 -0
- package/lib/hooks/useCopyToClipboard/useCopyToClipboard.d.ts +27 -0
- package/lib/hooks/useFileUpload/index.d.ts +1 -0
- package/lib/hooks/useFileUpload/useFileUpload.d.ts +342 -0
- package/lib/hooks/useFilteredOptions/index.d.ts +1 -0
- package/lib/hooks/useFilteredOptions/useFilteredOptions.d.ts +87 -0
- package/lib/hooks/useInputState/index.d.ts +1 -0
- package/lib/hooks/useInputState/useInputState.d.ts +22 -0
- package/lib/hooks/useLockedBody/index.d.ts +1 -0
- package/lib/hooks/useLockedBody/useLockedBody.d.ts +46 -0
- package/lib/hooks/useModal/index.d.ts +1 -0
- package/lib/hooks/useModal/useModal.d.ts +32 -0
- package/lib/hooks/useMountTransition/index.d.ts +24 -0
- package/lib/hooks/usePagination/index.d.ts +1 -0
- package/lib/hooks/usePagination/usePagination.d.ts +140 -0
- package/lib/hooks/useToastPortal/index.d.ts +1 -0
- package/lib/hooks/useToastPortal/useToastPortal.d.ts +31 -0
- package/lib/hooks/useToggle/index.d.ts +1 -0
- package/lib/hooks/useToggle/useToggle.d.ts +11 -0
- package/lib/hooks/useWindowSize/index.d.ts +1 -0
- package/lib/hooks/useWindowSize/useWindowSize.d.ts +28 -0
- package/lib/index.d.ts +5 -0
- package/lib/styles/index.d.ts +267 -0
- package/lib/styles/variables/_border.d.ts +12 -0
- package/lib/styles/variables/_color.d.ts +104 -0
- package/lib/styles/variables/_elevation.d.ts +7 -0
- package/lib/styles/variables/_font.d.ts +30 -0
- package/lib/styles/variables/_motion.d.ts +6 -0
- package/lib/styles/variables/_opacity.d.ts +15 -0
- package/lib/styles/variables/_shadow.d.ts +24 -0
- package/lib/styles/variables/_size.d.ts +57 -0
- package/lib/styles/variables/_space.d.ts +12 -0
- package/lib/types/charts.d.ts +225 -0
- package/lib/types/common.d.ts +10 -0
- package/lib/types/date-range-picker.d.ts +17 -0
- package/lib/types/date-range-picker.js.flow +2 -3
- package/lib/types/index.d.ts +6 -0
- package/lib/types/menu.d.ts +13 -0
- package/lib/types/toast.d.ts +32 -0
- package/lib/types/typography.d.ts +17 -0
- package/lib/utils/array/are-arrays-equal.d.ts +11 -0
- package/lib/utils/array/index.d.ts +1 -0
- package/lib/utils/charts/charts.d.ts +102 -0
- package/lib/utils/charts/columnChart.d.ts +51 -0
- package/lib/utils/charts/donutChart.d.ts +116 -0
- package/lib/utils/charts/funnelChart.d.ts +94 -0
- package/lib/utils/charts/helpers.d.ts +44 -0
- package/lib/utils/charts/index.d.ts +7 -0
- package/lib/utils/charts/lineChart.d.ts +44 -0
- package/lib/utils/charts/spiderChart.d.ts +46 -0
- package/lib/utils/charts/typography.d.ts +42 -0
- package/lib/utils/classify/index.d.ts +27 -0
- package/lib/utils/click-away/click-away.d.ts +194 -0
- package/lib/utils/click-away/index.d.ts +1 -0
- package/lib/utils/date-range-picker/date-range-picker.d.ts +391 -0
- package/lib/utils/date-range-picker/index.d.ts +2 -0
- package/lib/utils/date-range-picker/timezones.d.ts +262 -0
- package/lib/utils/dom/dom.d.ts +245 -0
- package/lib/utils/dom/index.d.ts +1 -0
- package/lib/utils/helpers/helpers.d.ts +48 -0
- package/lib/utils/helpers/index.d.ts +1 -0
- package/lib/utils/index.d.ts +14 -0
- package/lib/utils/makeClassNameComponent/index.d.ts +1 -0
- package/lib/utils/makeClassNameComponent/makeClassNameComponent.d.ts +73 -0
- package/lib/utils/menu/index.d.ts +1 -0
- package/lib/utils/merge-refs/index.d.ts +1 -0
- package/lib/utils/merge-refs/merge-refs.d.ts +15 -0
- package/lib/utils/rating/index.d.ts +1 -0
- package/lib/utils/rating/rating.d.ts +31 -0
- package/lib/utils/score-bar/index.d.ts +1 -0
- package/lib/utils/score-bar/score-bar.d.ts +54 -0
- package/lib/utils/string/index.d.ts +1 -0
- package/lib/utils/string/string.d.ts +30 -0
- package/lib/utils/token-list-input/token-list-input.d.ts +32 -0
- package/lib/utils/tokens/index.d.ts +1 -0
- package/lib/utils/tokens/tokens.d.ts +230 -0
- package/package.json +5 -5
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import formatDistance from 'date-fns/formatDistance';
|
|
3
|
+
import parseISO from 'date-fns/parseISO';
|
|
4
|
+
import {classify} from '../../utils/classify';
|
|
5
|
+
import type {ClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
6
|
+
import {makeClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
7
|
+
import {Avatar} from '../Avatar';
|
|
8
|
+
import {BodyMedium, BodySmall, TEXT_COLORS} from '../Text';
|
|
9
|
+
import css from './Table.module.css';
|
|
10
|
+
type CellsProps = {
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
className?: string | null | undefined;
|
|
13
|
+
truncatedText?: React.ReactNode;
|
|
14
|
+
onClick?:
|
|
15
|
+
| ((arg0: React.SyntheticEvent<HTMLElement>) => unknown)
|
|
16
|
+
| null
|
|
17
|
+
| undefined;
|
|
18
|
+
};
|
|
19
|
+
export const Cells = ({
|
|
20
|
+
children,
|
|
21
|
+
className,
|
|
22
|
+
...rest
|
|
23
|
+
}: CellsProps): React.ReactElement<'div'> => (
|
|
24
|
+
<div className={classify(css.row, className)} {...rest}>
|
|
25
|
+
{children}
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
export const Cell = ({
|
|
29
|
+
children,
|
|
30
|
+
className,
|
|
31
|
+
}: CellsProps): React.ReactElement<'div'> => (
|
|
32
|
+
<div className={classify(css.cell, className)}>{children}</div>
|
|
33
|
+
);
|
|
34
|
+
export const BasicSingleCell: ClassNameComponent<'td'> = makeClassNameComponent(
|
|
35
|
+
css.defaultSingleCell,
|
|
36
|
+
'td',
|
|
37
|
+
);
|
|
38
|
+
export const BasicDoubleCell: ClassNameComponent<'td'> = makeClassNameComponent(
|
|
39
|
+
css.defaultDoubleCell,
|
|
40
|
+
'td',
|
|
41
|
+
);
|
|
42
|
+
export const PaddedContentCell: ClassNameComponent<'td'> =
|
|
43
|
+
makeClassNameComponent(css.singleContentCell, 'td');
|
|
44
|
+
export const PaddedDoubleContentCell: ClassNameComponent<'td'> =
|
|
45
|
+
makeClassNameComponent(css.doubleContentCell, 'td');
|
|
46
|
+
export const SingleCell = ({
|
|
47
|
+
title,
|
|
48
|
+
className,
|
|
49
|
+
}: {
|
|
50
|
+
title: string;
|
|
51
|
+
icon?: React.ReactNode;
|
|
52
|
+
className?: string;
|
|
53
|
+
}): React.ReactNode => (
|
|
54
|
+
<PaddedContentCell className={className}>
|
|
55
|
+
<BodyMedium className={css.paddedTitleBlock}>{title}</BodyMedium>
|
|
56
|
+
</PaddedContentCell>
|
|
57
|
+
);
|
|
58
|
+
export const DoubleCell = ({
|
|
59
|
+
title,
|
|
60
|
+
subtitle,
|
|
61
|
+
className,
|
|
62
|
+
}: {
|
|
63
|
+
title: React.ReactNode;
|
|
64
|
+
subtitle?: React.ReactNode;
|
|
65
|
+
className?: string;
|
|
66
|
+
}): React.ReactNode => (
|
|
67
|
+
<PaddedDoubleContentCell className={className}>
|
|
68
|
+
<div className={css.paddedTitleBlock}>
|
|
69
|
+
<BodyMedium className={css.doubleTitle}>{title}</BodyMedium>
|
|
70
|
+
<BodySmall color={TEXT_COLORS.tertiary} className={css.doubleSubtitle}>
|
|
71
|
+
{subtitle ?? ''}
|
|
72
|
+
</BodySmall>
|
|
73
|
+
</div>
|
|
74
|
+
</PaddedDoubleContentCell>
|
|
75
|
+
);
|
|
76
|
+
export const DateCell = ({
|
|
77
|
+
date,
|
|
78
|
+
className,
|
|
79
|
+
}: {
|
|
80
|
+
date: string | Date;
|
|
81
|
+
className?: string;
|
|
82
|
+
}): React.ReactNode => {
|
|
83
|
+
const parsedDate: Date = typeof date === 'object' ? date : parseISO(date);
|
|
84
|
+
return (
|
|
85
|
+
<DoubleCell
|
|
86
|
+
title={`${parsedDate.getMonth() + 1} / ${
|
|
87
|
+
parsedDate.getDate() + 1
|
|
88
|
+
} / ${parsedDate.getFullYear()}`}
|
|
89
|
+
subtitle={`${formatDistance(parsedDate, new Date())} ago`}
|
|
90
|
+
className={className}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
export const Monogram = ({initials}: {initials: string}): React.ReactNode => (
|
|
95
|
+
<Avatar size="small" text={initials} />
|
|
96
|
+
);
|
|
97
|
+
export const MonogramCell = ({
|
|
98
|
+
initials,
|
|
99
|
+
className,
|
|
100
|
+
}: {
|
|
101
|
+
initials: string;
|
|
102
|
+
className?: string;
|
|
103
|
+
}): React.ReactNode => (
|
|
104
|
+
<PaddedContentCell className={className}>
|
|
105
|
+
<Monogram initials={initials} />
|
|
106
|
+
</PaddedContentCell>
|
|
107
|
+
);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {$ReadOnly} from 'utility-types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import classify from '../../utils/classify';
|
|
4
|
+
import type {ClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
5
|
+
import {makeClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
6
|
+
import {Checkbox} from '../Checkbox';
|
|
7
|
+
import {CircularLoader} from '../CircularLoader';
|
|
8
|
+
import {BodyLarge, TEXT_COLORS} from '../Text';
|
|
9
|
+
import {PaddedContentCell, SingleCell} from './Cell';
|
|
10
|
+
import type {GenericHeaderItems} from './DefaultTableHeader';
|
|
11
|
+
import type {GenericObject} from './Table';
|
|
12
|
+
import css from './Table.module.css';
|
|
13
|
+
type ClassNames = $ReadOnly<{
|
|
14
|
+
tableRow?: string;
|
|
15
|
+
checkbox?: string;
|
|
16
|
+
}>;
|
|
17
|
+
// When using a custom Row prop, you need to create a component that looks like
|
|
18
|
+
// MyRow = (props: TableRowProps<Entries, Extras>): React.Node => {...}
|
|
19
|
+
// otherwise flow will complain.
|
|
20
|
+
// Note that b/c extras is often optional, you will need to explicitly include
|
|
21
|
+
// `invariant(extras, 'extras exists');` in order to pull values out of
|
|
22
|
+
// extras (flow will remind you that it is of type `U | void`)
|
|
23
|
+
export type TableRowProps<T, U> = {
|
|
24
|
+
data: T;
|
|
25
|
+
extras?: U;
|
|
26
|
+
sortedKeys?: string[];
|
|
27
|
+
headers?: GenericHeaderItems<T, U>;
|
|
28
|
+
selected?: boolean;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type TableRow<T, U> = React.ComponentType<TableRowProps<T, U>>;
|
|
32
|
+
export const BasicRow: ClassNameComponent<'tr'> = makeClassNameComponent(
|
|
33
|
+
css.defaultRow,
|
|
34
|
+
'tr',
|
|
35
|
+
);
|
|
36
|
+
type EmptyRowProps = {
|
|
37
|
+
emptyText?: React.ReactNode;
|
|
38
|
+
isLoading?: boolean;
|
|
39
|
+
headersLength: number;
|
|
40
|
+
customLoader?: React.ReactNode;
|
|
41
|
+
};
|
|
42
|
+
export const EmptyRow = ({
|
|
43
|
+
isLoading,
|
|
44
|
+
emptyText,
|
|
45
|
+
headersLength = 0,
|
|
46
|
+
customLoader,
|
|
47
|
+
}: EmptyRowProps): React.ReactElement<'tr'> => (
|
|
48
|
+
<tr>
|
|
49
|
+
<td colSpan={headersLength}>
|
|
50
|
+
<div className={css.emptyRow}>
|
|
51
|
+
{isLoading ? (
|
|
52
|
+
customLoader ? (
|
|
53
|
+
customLoader
|
|
54
|
+
) : (
|
|
55
|
+
<div className={css.defaultLoader}>
|
|
56
|
+
{' '}
|
|
57
|
+
<CircularLoader colorToken="colorFillPrimary" size="large" />
|
|
58
|
+
</div>
|
|
59
|
+
)
|
|
60
|
+
) : (
|
|
61
|
+
emptyText || (
|
|
62
|
+
<BodyLarge
|
|
63
|
+
color={TEXT_COLORS.secondary}
|
|
64
|
+
className={css.defaultEmptyText}
|
|
65
|
+
>
|
|
66
|
+
Nothing to display here.
|
|
67
|
+
</BodyLarge>
|
|
68
|
+
)
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
</td>
|
|
72
|
+
</tr>
|
|
73
|
+
);
|
|
74
|
+
// This is a fallback row we use to render a table when
|
|
75
|
+
// initially stubbing out a design, the idea is you just avoid
|
|
76
|
+
// passing in a Row component and instead let this render out
|
|
77
|
+
// all the fields in the header in the short term
|
|
78
|
+
//
|
|
79
|
+
// Using the default row has the benefit that mismatches between
|
|
80
|
+
// header and entries _will_ error out even though there are the
|
|
81
|
+
// suppressions below
|
|
82
|
+
export function DefaultRow<T extends GenericObject, U extends GenericObject>({
|
|
83
|
+
data,
|
|
84
|
+
extras,
|
|
85
|
+
headers,
|
|
86
|
+
selected,
|
|
87
|
+
onSelect,
|
|
88
|
+
classNames,
|
|
89
|
+
disabled,
|
|
90
|
+
}: {
|
|
91
|
+
data: T;
|
|
92
|
+
extras?: U;
|
|
93
|
+
headers: GenericHeaderItems<T, U>;
|
|
94
|
+
selected?: boolean;
|
|
95
|
+
// value dependent on checkbox checked value
|
|
96
|
+
onSelect?: (arg0: {value: string; checked: boolean}) => unknown;
|
|
97
|
+
classNames?: ClassNames;
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
}): React.ReactNode {
|
|
100
|
+
return (
|
|
101
|
+
<BasicRow
|
|
102
|
+
className={classify(
|
|
103
|
+
selected ? css.defaultSelectedBodyRow : css.defaultBodyRow,
|
|
104
|
+
classNames?.tableRow,
|
|
105
|
+
)}
|
|
106
|
+
>
|
|
107
|
+
{selected != null && (
|
|
108
|
+
<PaddedContentCell
|
|
109
|
+
className={classify(css.checkbox, classNames?.checkbox)}
|
|
110
|
+
>
|
|
111
|
+
<Checkbox
|
|
112
|
+
checked={selected ? true : false}
|
|
113
|
+
onChange={onSelect}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
ariaLabel="Select row"
|
|
116
|
+
/>
|
|
117
|
+
</PaddedContentCell>
|
|
118
|
+
)}
|
|
119
|
+
{headers.map((item, index) => {
|
|
120
|
+
const {key, render: Renderer, className: cellClassName, sticky} = item;
|
|
121
|
+
const value = data[key];
|
|
122
|
+
return Renderer ? (
|
|
123
|
+
<Renderer // eslint-disable-next-line react/no-array-index-key
|
|
124
|
+
key={index}
|
|
125
|
+
data={data}
|
|
126
|
+
extras={extras}
|
|
127
|
+
selected={selected}
|
|
128
|
+
className={classify({
|
|
129
|
+
[css.stickyCell]: sticky,
|
|
130
|
+
})}
|
|
131
|
+
/>
|
|
132
|
+
) : (
|
|
133
|
+
<SingleCell // eslint-disable-next-line react/no-array-index-key
|
|
134
|
+
key={index}
|
|
135
|
+
title={String(value)}
|
|
136
|
+
className={classify(cellClassName, {
|
|
137
|
+
[css.stickyCell]: sticky,
|
|
138
|
+
})}
|
|
139
|
+
/>
|
|
140
|
+
);
|
|
141
|
+
})}
|
|
142
|
+
</BasicRow>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import {$Keys} from 'utility-types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import type {ColorTypes} from '../../types/typography';
|
|
4
|
+
import classify from '../../utils/classify';
|
|
5
|
+
import type {ClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
6
|
+
import {makeClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
7
|
+
import {Checkbox} from '../Checkbox';
|
|
8
|
+
import {Icon} from '../Icon';
|
|
9
|
+
import {SubTitleExtraSmall, TEXT_COLORS} from '../Text';
|
|
10
|
+
import {BasicRow} from './DefaultRow';
|
|
11
|
+
import type {SortDirection} from './hooks';
|
|
12
|
+
import type {GenericObject} from './Table';
|
|
13
|
+
import css from './Table.module.css';
|
|
14
|
+
export type GenericHeaderItem<
|
|
15
|
+
T extends GenericObject,
|
|
16
|
+
U extends GenericObject,
|
|
17
|
+
> = {
|
|
18
|
+
label: React.ReactNode;
|
|
19
|
+
key: $Keys<T>;
|
|
20
|
+
className?: string;
|
|
21
|
+
filterIcon?: React.ReactNode;
|
|
22
|
+
filtered?: boolean;
|
|
23
|
+
subtext?: string;
|
|
24
|
+
sortable?: boolean;
|
|
25
|
+
headerIconClassName?: string;
|
|
26
|
+
sticky?: boolean;
|
|
27
|
+
render?: React.ComponentType<{
|
|
28
|
+
data: T;
|
|
29
|
+
extras?: U;
|
|
30
|
+
className?: string;
|
|
31
|
+
selected?: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
export type GenericHeaderItems<T, U> = GenericHeaderItem<T, U>[];
|
|
35
|
+
export const BasicHeadCell: ClassNameComponent<'th'> = makeClassNameComponent(
|
|
36
|
+
css.defaultHeaderCell,
|
|
37
|
+
'th',
|
|
38
|
+
);
|
|
39
|
+
export const BasicTableHead: ClassNameComponent<'thead'> =
|
|
40
|
+
makeClassNameComponent(css.defaultTableHead, 'thead');
|
|
41
|
+
export type TableHeaderProps<T, U> = {
|
|
42
|
+
className?: string;
|
|
43
|
+
tableHeaderClassName?: string;
|
|
44
|
+
sortable?: boolean;
|
|
45
|
+
columns: GenericHeaderItems<T, U>;
|
|
46
|
+
handleSortClick?: (sortKey: $Keys<T>) => unknown;
|
|
47
|
+
sortKey?: $Keys<T>;
|
|
48
|
+
sortDirection?: SortDirection;
|
|
49
|
+
checked?: 'true' | 'false' | 'mixed';
|
|
50
|
+
handleCheckboxClick?: (arg0: {value: string; checked: boolean}) => unknown;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
stickyHeader?: boolean;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const SortIcon = ({
|
|
56
|
+
sortDirection,
|
|
57
|
+
color,
|
|
58
|
+
className,
|
|
59
|
+
}: {
|
|
60
|
+
sortDirection: SortDirection;
|
|
61
|
+
className: string;
|
|
62
|
+
color: ColorTypes;
|
|
63
|
+
}) => {
|
|
64
|
+
if (sortDirection === 'original') {
|
|
65
|
+
return (
|
|
66
|
+
<Icon
|
|
67
|
+
color={color}
|
|
68
|
+
name="caret-down"
|
|
69
|
+
size="small"
|
|
70
|
+
type="solid"
|
|
71
|
+
className={className}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
} else if (sortDirection === 'asc') {
|
|
75
|
+
return (
|
|
76
|
+
<Icon
|
|
77
|
+
color={color}
|
|
78
|
+
name="arrow-up"
|
|
79
|
+
size="small"
|
|
80
|
+
type="regular"
|
|
81
|
+
className={className}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
} else if (sortDirection === 'desc') {
|
|
85
|
+
return (
|
|
86
|
+
<Icon
|
|
87
|
+
color={color}
|
|
88
|
+
name="arrow-down"
|
|
89
|
+
size="small"
|
|
90
|
+
type="regular"
|
|
91
|
+
className={className}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export function DefaultTableHeader<
|
|
98
|
+
T extends GenericObject,
|
|
99
|
+
U extends GenericObject,
|
|
100
|
+
>(props: TableHeaderProps<T, U>): React.ReactNode {
|
|
101
|
+
const {
|
|
102
|
+
className,
|
|
103
|
+
sortable = false,
|
|
104
|
+
columns,
|
|
105
|
+
handleSortClick,
|
|
106
|
+
sortKey,
|
|
107
|
+
sortDirection = 'original',
|
|
108
|
+
handleCheckboxClick,
|
|
109
|
+
checked,
|
|
110
|
+
disabled,
|
|
111
|
+
stickyHeader,
|
|
112
|
+
} = props;
|
|
113
|
+
|
|
114
|
+
const tableHeaderCells = () => (
|
|
115
|
+
<>
|
|
116
|
+
{columns.map((columnData, index) => {
|
|
117
|
+
const {
|
|
118
|
+
key,
|
|
119
|
+
label,
|
|
120
|
+
subtext,
|
|
121
|
+
filterIcon,
|
|
122
|
+
filtered,
|
|
123
|
+
className,
|
|
124
|
+
sticky,
|
|
125
|
+
sortable: columnSortable = false,
|
|
126
|
+
} = columnData;
|
|
127
|
+
let headerClassName;
|
|
128
|
+
const filterable = Boolean(filterIcon);
|
|
129
|
+
|
|
130
|
+
if ((sortable && columnSortable) || filterable) {
|
|
131
|
+
headerClassName = classify(
|
|
132
|
+
css.defaultHeaderCellSortable,
|
|
133
|
+
{
|
|
134
|
+
[css.filtered]: filtered,
|
|
135
|
+
[css.stickyHeaderCell]: sticky,
|
|
136
|
+
},
|
|
137
|
+
css[sortDirection],
|
|
138
|
+
className,
|
|
139
|
+
);
|
|
140
|
+
} else {
|
|
141
|
+
headerClassName = classify(className, {
|
|
142
|
+
[css.stickyHeaderCell]: sticky,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const headCellClickHandler = () => {
|
|
147
|
+
if (sortable && columnSortable && handleSortClick) {
|
|
148
|
+
handleSortClick(key);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
let columnSortDirection = 'original';
|
|
153
|
+
|
|
154
|
+
if (sortKey === key) {
|
|
155
|
+
columnSortDirection = sortDirection;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<BasicHeadCell
|
|
160
|
+
className={classify(
|
|
161
|
+
{
|
|
162
|
+
[css.selectedHeader]:
|
|
163
|
+
sortKey === key && columnSortDirection !== 'original',
|
|
164
|
+
},
|
|
165
|
+
headerClassName,
|
|
166
|
+
)} // eslint-disable-next-line react/no-array-index-key
|
|
167
|
+
key={index}
|
|
168
|
+
scope="col"
|
|
169
|
+
onClick={headCellClickHandler}
|
|
170
|
+
>
|
|
171
|
+
<div className={classify(css.labelContents)}>
|
|
172
|
+
<div className={css.labelContainer}>
|
|
173
|
+
<SubTitleExtraSmall
|
|
174
|
+
color={TEXT_COLORS.secondary}
|
|
175
|
+
className={classify({
|
|
176
|
+
[css.selectedHeader]:
|
|
177
|
+
sortKey === key && columnSortDirection !== 'original',
|
|
178
|
+
})}
|
|
179
|
+
>
|
|
180
|
+
{label}
|
|
181
|
+
</SubTitleExtraSmall>
|
|
182
|
+
<span className={css.headerSubtext}>{subtext && subtext}</span>
|
|
183
|
+
</div>
|
|
184
|
+
{(sortable || filterIcon != null) && (
|
|
185
|
+
<div className={css.headerIconContainer}>
|
|
186
|
+
{columnSortable && (
|
|
187
|
+
<SortIcon
|
|
188
|
+
color={TEXT_COLORS.secondary}
|
|
189
|
+
className={classify(css.sortArrow, {
|
|
190
|
+
[css.selectedSortArrow]: sortKey === key,
|
|
191
|
+
})}
|
|
192
|
+
sortDirection={columnSortDirection}
|
|
193
|
+
/>
|
|
194
|
+
)}
|
|
195
|
+
{filterIcon != null && (
|
|
196
|
+
<div className={css.filterIcon}>{filterIcon}</div>
|
|
197
|
+
)}
|
|
198
|
+
</div>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
</BasicHeadCell>
|
|
202
|
+
);
|
|
203
|
+
})}
|
|
204
|
+
</>
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<BasicTableHead
|
|
209
|
+
className={classify(
|
|
210
|
+
css.tableHeaderSortable,
|
|
211
|
+
{
|
|
212
|
+
[css.stickyHeader]: stickyHeader,
|
|
213
|
+
},
|
|
214
|
+
className,
|
|
215
|
+
)}
|
|
216
|
+
>
|
|
217
|
+
<BasicRow className={css.defaultHeaderRow}>
|
|
218
|
+
{handleCheckboxClick && (
|
|
219
|
+
<BasicHeadCell scope="col">
|
|
220
|
+
<div className={css.checkbox}>
|
|
221
|
+
<Checkbox
|
|
222
|
+
value="all"
|
|
223
|
+
checked={checked === 'true' ? true : false}
|
|
224
|
+
indeterminate={checked === 'mixed'}
|
|
225
|
+
onChange={handleCheckboxClick}
|
|
226
|
+
disabled={disabled}
|
|
227
|
+
ariaLabel="Select all rows"
|
|
228
|
+
/>
|
|
229
|
+
</div>
|
|
230
|
+
</BasicHeadCell>
|
|
231
|
+
)}
|
|
232
|
+
{tableHeaderCells()}
|
|
233
|
+
</BasicRow>
|
|
234
|
+
</BasicTableHead>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import get from 'lodash/get';
|
|
3
|
+
import xor from 'lodash/xor';
|
|
4
|
+
import {useWindowSize} from '../../hooks/useWindowSize';
|
|
5
|
+
import {sizeFluid} from '../../styles/variables/_size';
|
|
6
|
+
import {classify} from '../../utils/classify';
|
|
7
|
+
import type {ClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
8
|
+
import {makeClassNameComponent} from '../../utils/makeClassNameComponent';
|
|
9
|
+
import {DefaultRow, EmptyRow} from './DefaultRow';
|
|
10
|
+
import {DefaultTableHeader} from './DefaultTableHeader';
|
|
11
|
+
import type {SortDirection} from './hooks';
|
|
12
|
+
import type {GenericObject, TableProps} from './Table';
|
|
13
|
+
import css from './Table.module.css';
|
|
14
|
+
export const BasicTable: ClassNameComponent<'table'> = makeClassNameComponent(
|
|
15
|
+
css.defaultTable,
|
|
16
|
+
'table',
|
|
17
|
+
);
|
|
18
|
+
export const BasicTableBody: ClassNameComponent<'tbody'> =
|
|
19
|
+
makeClassNameComponent(css.defaultTableBody, 'tbody');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A Static Default Table.
|
|
23
|
+
*
|
|
24
|
+
* Our
|
|
25
|
+
*/
|
|
26
|
+
export function StaticTable<
|
|
27
|
+
Data extends GenericObject,
|
|
28
|
+
Extras extends GenericObject,
|
|
29
|
+
>(
|
|
30
|
+
props: TableProps<Data, Extras> & {
|
|
31
|
+
handleSortClick?: (sortKey: string) => unknown;
|
|
32
|
+
sortKey?: string;
|
|
33
|
+
sortDirection?: SortDirection;
|
|
34
|
+
rowKeys?: string[];
|
|
35
|
+
},
|
|
36
|
+
): React.ReactNode {
|
|
37
|
+
const {
|
|
38
|
+
classNames,
|
|
39
|
+
className,
|
|
40
|
+
TableRow,
|
|
41
|
+
entries,
|
|
42
|
+
extras,
|
|
43
|
+
rowKeys,
|
|
44
|
+
headers,
|
|
45
|
+
showHeader = true,
|
|
46
|
+
tableHeaderClassName,
|
|
47
|
+
sortable,
|
|
48
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
49
|
+
defaultSortKey,
|
|
50
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
51
|
+
defaultSortDirection = 'original',
|
|
52
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
53
|
+
onSort,
|
|
54
|
+
handleSortClick,
|
|
55
|
+
sortKey,
|
|
56
|
+
sortDirection,
|
|
57
|
+
selectedKeys,
|
|
58
|
+
onSelect,
|
|
59
|
+
isLoading,
|
|
60
|
+
idName = 'id',
|
|
61
|
+
emptyText,
|
|
62
|
+
disabled,
|
|
63
|
+
customLoader,
|
|
64
|
+
borderRadius,
|
|
65
|
+
stickyHeader,
|
|
66
|
+
} = props;
|
|
67
|
+
// this is a fallback and honestly probably doesn't need the
|
|
68
|
+
// memo'ing
|
|
69
|
+
const mappedKeys = React.useMemo(
|
|
70
|
+
() => rowKeys ?? entries.map((e) => get(e, idName)),
|
|
71
|
+
[entries, idName, rowKeys],
|
|
72
|
+
);
|
|
73
|
+
const tableRef = React.useRef(null);
|
|
74
|
+
const {width} = useWindowSize();
|
|
75
|
+
const [tableWidth, setTableWidth] = React.useState();
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
if (tableRef.current) {
|
|
78
|
+
setTableWidth(tableRef.current.offsetWidth);
|
|
79
|
+
}
|
|
80
|
+
}, [width]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* this function is also used to decide weather to show checkbox in header or not. so it's value is undefined incase selectedKeys is not there.
|
|
84
|
+
*/
|
|
85
|
+
const handleHeaderCheckboxClick = selectedKeys
|
|
86
|
+
? ({checked}: {value: string; checked: boolean}) => {
|
|
87
|
+
let selectedRowIds = [];
|
|
88
|
+
|
|
89
|
+
if (selectedKeys) {
|
|
90
|
+
if (checked === true) {
|
|
91
|
+
selectedRowIds = entries.map((singleRowObj) =>
|
|
92
|
+
get(singleRowObj, idName),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
onSelect?.(selectedRowIds);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
: undefined;
|
|
100
|
+
return (
|
|
101
|
+
<div
|
|
102
|
+
className={classify(css.tableContainer, classNames?.wrapper)}
|
|
103
|
+
data-id="table-wrap"
|
|
104
|
+
ref={tableRef}
|
|
105
|
+
style={{
|
|
106
|
+
'--border-radius': borderRadius,
|
|
107
|
+
'--table-width': tableWidth ? `${tableWidth}px` : sizeFluid,
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<BasicTable
|
|
111
|
+
data-id="basic-table"
|
|
112
|
+
className={classify(
|
|
113
|
+
className,
|
|
114
|
+
{
|
|
115
|
+
[css.fullHeightTable]:
|
|
116
|
+
isLoading || (!entries.length && !!emptyText),
|
|
117
|
+
},
|
|
118
|
+
classNames?.table,
|
|
119
|
+
)}
|
|
120
|
+
>
|
|
121
|
+
{showHeader && (
|
|
122
|
+
<DefaultTableHeader
|
|
123
|
+
className={classify(tableHeaderClassName, classNames?.tableHeader)}
|
|
124
|
+
sortable={sortable}
|
|
125
|
+
columns={headers}
|
|
126
|
+
handleSortClick={handleSortClick}
|
|
127
|
+
sortKey={sortKey}
|
|
128
|
+
sortDirection={sortDirection}
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
handleCheckboxClick={handleHeaderCheckboxClick}
|
|
131
|
+
stickyHeader={stickyHeader}
|
|
132
|
+
checked={
|
|
133
|
+
selectedKeys == null || selectedKeys.length === 0
|
|
134
|
+
? 'false'
|
|
135
|
+
: selectedKeys.length < entries.length
|
|
136
|
+
? 'mixed'
|
|
137
|
+
: 'true'
|
|
138
|
+
}
|
|
139
|
+
/>
|
|
140
|
+
)}
|
|
141
|
+
|
|
142
|
+
<BasicTableBody className={classNames?.tableBody}>
|
|
143
|
+
{isLoading || !entries.length ? (
|
|
144
|
+
<EmptyRow
|
|
145
|
+
isLoading={isLoading}
|
|
146
|
+
emptyText={emptyText}
|
|
147
|
+
headersLength={
|
|
148
|
+
handleHeaderCheckboxClick ? headers.length + 1 : headers.length
|
|
149
|
+
}
|
|
150
|
+
customLoader={customLoader}
|
|
151
|
+
/>
|
|
152
|
+
) : (
|
|
153
|
+
mappedKeys.map((key) => {
|
|
154
|
+
const data = entries.find((e) => get(e, idName) === key);
|
|
155
|
+
|
|
156
|
+
if (data == null) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
data as Data;
|
|
161
|
+
const selected =
|
|
162
|
+
selectedKeys?.includes(get(data, idName)) ?? undefined;
|
|
163
|
+
return TableRow ? (
|
|
164
|
+
<TableRow
|
|
165
|
+
key={key}
|
|
166
|
+
data={data}
|
|
167
|
+
headers={headers} // extras and rowKeys are both 'optional'
|
|
168
|
+
extras={extras}
|
|
169
|
+
sortedKeys={rowKeys ?? mappedKeys}
|
|
170
|
+
selected={selected}
|
|
171
|
+
disabled={disabled}
|
|
172
|
+
/>
|
|
173
|
+
) : (
|
|
174
|
+
<DefaultRow
|
|
175
|
+
key={key}
|
|
176
|
+
data={data}
|
|
177
|
+
extras={extras}
|
|
178
|
+
headers={headers}
|
|
179
|
+
selected={selected}
|
|
180
|
+
onSelect={
|
|
181
|
+
selectedKeys != null
|
|
182
|
+
? (_v) => onSelect?.(xor(selectedKeys ?? [], [key]))
|
|
183
|
+
: undefined
|
|
184
|
+
}
|
|
185
|
+
disabled={disabled}
|
|
186
|
+
classNames={{
|
|
187
|
+
tableRow: classNames?.tableRow,
|
|
188
|
+
checkbox: classNames?.checkbox,
|
|
189
|
+
}}
|
|
190
|
+
/>
|
|
191
|
+
);
|
|
192
|
+
})
|
|
193
|
+
)}
|
|
194
|
+
</BasicTableBody>
|
|
195
|
+
</BasicTable>
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|