@terreno/ui 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +203 -0
- package/README.md +160 -0
- package/dist/Accordion.d.ts +3 -0
- package/dist/Accordion.js +30 -0
- package/dist/Accordion.js.map +1 -0
- package/dist/ActionSheet.d.ts +169 -0
- package/dist/ActionSheet.js +637 -0
- package/dist/ActionSheet.js.map +1 -0
- package/dist/AddressField.d.ts +3 -0
- package/dist/AddressField.js +18 -0
- package/dist/AddressField.js.map +1 -0
- package/dist/Avatar.d.ts +3 -0
- package/dist/Avatar.js +189 -0
- package/dist/Avatar.js.map +1 -0
- package/dist/Badge.d.ts +3 -0
- package/dist/Badge.js +100 -0
- package/dist/Badge.js.map +1 -0
- package/dist/Banner.d.ts +4 -0
- package/dist/Banner.js +103 -0
- package/dist/Banner.js.map +1 -0
- package/dist/Body.d.ts +3 -0
- package/dist/Body.js +17 -0
- package/dist/Body.js.map +1 -0
- package/dist/BooleanField.d.ts +3 -0
- package/dist/BooleanField.js +89 -0
- package/dist/BooleanField.js.map +1 -0
- package/dist/Box.d.ts +3 -0
- package/dist/Box.js +289 -0
- package/dist/Box.js.map +1 -0
- package/dist/Button.d.ts +3 -0
- package/dist/Button.js +105 -0
- package/dist/Button.js.map +1 -0
- package/dist/Card.d.ts +2 -0
- package/dist/Card.js +18 -0
- package/dist/Card.js.map +1 -0
- package/dist/CheckBox.d.ts +3 -0
- package/dist/CheckBox.js +28 -0
- package/dist/CheckBox.js.map +1 -0
- package/dist/Common.d.ts +2325 -0
- package/dist/Common.js +47 -0
- package/dist/Common.js.map +1 -0
- package/dist/CommonIconTypes.d.ts +3 -0
- package/dist/CommonIconTypes.js +2 -0
- package/dist/CommonIconTypes.js.map +1 -0
- package/dist/Constants.d.ts +12685 -0
- package/dist/Constants.js +3310 -0
- package/dist/Constants.js.map +1 -0
- package/dist/CustomSelectField.d.ts +3 -0
- package/dist/CustomSelectField.js +59 -0
- package/dist/CustomSelectField.js.map +1 -0
- package/dist/DataTable.d.ts +3 -0
- package/dist/DataTable.js +190 -0
- package/dist/DataTable.js.map +1 -0
- package/dist/DateTimeActionSheet.d.ts +2 -0
- package/dist/DateTimeActionSheet.js +270 -0
- package/dist/DateTimeActionSheet.js.map +1 -0
- package/dist/DateTimeField.d.ts +3 -0
- package/dist/DateTimeField.js +514 -0
- package/dist/DateTimeField.js.map +1 -0
- package/dist/DateUtilities.d.ts +57 -0
- package/dist/DateUtilities.js +308 -0
- package/dist/DateUtilities.js.map +1 -0
- package/dist/DecimalRangeActionSheet.d.ts +6 -0
- package/dist/DecimalRangeActionSheet.js +45 -0
- package/dist/DecimalRangeActionSheet.js.map +1 -0
- package/dist/DismissButton.d.ts +3 -0
- package/dist/DismissButton.js +12 -0
- package/dist/DismissButton.js.map +1 -0
- package/dist/EmailField.d.ts +3 -0
- package/dist/EmailField.js +48 -0
- package/dist/EmailField.js.map +1 -0
- package/dist/EmojiSelector.d.ts +113 -0
- package/dist/EmojiSelector.js +322 -0
- package/dist/EmojiSelector.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +19 -0
- package/dist/ErrorBoundary.js +30 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/ErrorPage.d.ts +6 -0
- package/dist/ErrorPage.js +15 -0
- package/dist/ErrorPage.js.map +1 -0
- package/dist/Field.d.ts +3 -0
- package/dist/Field.js +80 -0
- package/dist/Field.js.map +1 -0
- package/dist/FlatList.d.ts +2 -0
- package/dist/FlatList.js +3 -0
- package/dist/FlatList.js.map +1 -0
- package/dist/Heading.d.ts +3 -0
- package/dist/Heading.js +43 -0
- package/dist/Heading.js.map +1 -0
- package/dist/HeightActionSheet.d.ts +11 -0
- package/dist/HeightActionSheet.js +46 -0
- package/dist/HeightActionSheet.js.map +1 -0
- package/dist/Hyperlink.d.ts +30 -0
- package/dist/Hyperlink.js +144 -0
- package/dist/Hyperlink.js.map +1 -0
- package/dist/Icon.d.ts +3 -0
- package/dist/Icon.js +15 -0
- package/dist/Icon.js.map +1 -0
- package/dist/IconButton.d.ts +3 -0
- package/dist/IconButton.js +111 -0
- package/dist/IconButton.js.map +1 -0
- package/dist/Image.d.ts +8 -0
- package/dist/Image.js +37 -0
- package/dist/Image.js.map +1 -0
- package/dist/ImageBackground.d.ts +10 -0
- package/dist/ImageBackground.js +9 -0
- package/dist/ImageBackground.js.map +1 -0
- package/dist/InfoModalIcon.d.ts +3 -0
- package/dist/InfoModalIcon.js +10 -0
- package/dist/InfoModalIcon.js.map +1 -0
- package/dist/InfoTooltipButton.d.ts +3 -0
- package/dist/InfoTooltipButton.js +6 -0
- package/dist/InfoTooltipButton.js.map +1 -0
- package/dist/Link.d.ts +3 -0
- package/dist/Link.js +10 -0
- package/dist/Link.js.map +1 -0
- package/dist/MarkdownView.d.ts +5 -0
- package/dist/MarkdownView.js +44 -0
- package/dist/MarkdownView.js.map +1 -0
- package/dist/MediaQuery.d.ts +4 -0
- package/dist/MediaQuery.js +52 -0
- package/dist/MediaQuery.js.map +1 -0
- package/dist/MobileAddressAutoComplete.d.ts +2 -0
- package/dist/MobileAddressAutoComplete.js +54 -0
- package/dist/MobileAddressAutoComplete.js.map +1 -0
- package/dist/Modal.d.ts +3 -0
- package/dist/Modal.js +127 -0
- package/dist/Modal.js.map +1 -0
- package/dist/ModalSheet.d.ts +6 -0
- package/dist/ModalSheet.js +42 -0
- package/dist/ModalSheet.js.map +1 -0
- package/dist/MultiselectField.d.ts +3 -0
- package/dist/MultiselectField.js +45 -0
- package/dist/MultiselectField.js.map +1 -0
- package/dist/NumberField.d.ts +3 -0
- package/dist/NumberField.js +60 -0
- package/dist/NumberField.js.map +1 -0
- package/dist/NumberPickerActionSheet.d.ts +7 -0
- package/dist/NumberPickerActionSheet.js +22 -0
- package/dist/NumberPickerActionSheet.js.map +1 -0
- package/dist/OpenAPIContext.d.ts +4 -0
- package/dist/OpenAPIContext.js +53 -0
- package/dist/OpenAPIContext.js.map +1 -0
- package/dist/Page.d.ts +7 -0
- package/dist/Page.js +24 -0
- package/dist/Page.js.map +1 -0
- package/dist/Pagination.d.ts +3 -0
- package/dist/Pagination.js +106 -0
- package/dist/Pagination.js.map +1 -0
- package/dist/PasswordField.d.ts +2 -0
- package/dist/PasswordField.js +6 -0
- package/dist/PasswordField.js.map +1 -0
- package/dist/Permissions.d.ts +2 -0
- package/dist/Permissions.js +35 -0
- package/dist/Permissions.js.map +1 -0
- package/dist/PhoneNumberField.d.ts +3 -0
- package/dist/PhoneNumberField.js +83 -0
- package/dist/PhoneNumberField.js.map +1 -0
- package/dist/PickerSelect.d.ts +46 -0
- package/dist/PickerSelect.js +306 -0
- package/dist/PickerSelect.js.map +1 -0
- package/dist/Radio.d.ts +3 -0
- package/dist/Radio.js +21 -0
- package/dist/Radio.js.map +1 -0
- package/dist/RadioField.d.ts +3 -0
- package/dist/RadioField.js +16 -0
- package/dist/RadioField.js.map +1 -0
- package/dist/ScrollView.d.ts +2 -0
- package/dist/ScrollView.js +3 -0
- package/dist/ScrollView.js.map +1 -0
- package/dist/SectionDivider.d.ts +2 -0
- package/dist/SectionDivider.js +12 -0
- package/dist/SectionDivider.js.map +1 -0
- package/dist/SegmentedControl.d.ts +3 -0
- package/dist/SegmentedControl.js +65 -0
- package/dist/SegmentedControl.js.map +1 -0
- package/dist/SelectBadge.d.ts +3 -0
- package/dist/SelectBadge.js +166 -0
- package/dist/SelectBadge.js.map +1 -0
- package/dist/SelectField.d.ts +3 -0
- package/dist/SelectField.js +16 -0
- package/dist/SelectField.js.map +1 -0
- package/dist/SideDrawer.d.ts +3 -0
- package/dist/SideDrawer.js +32 -0
- package/dist/SideDrawer.js.map +1 -0
- package/dist/Signature.d.ts +8 -0
- package/dist/Signature.js +21 -0
- package/dist/Signature.js.map +1 -0
- package/dist/Signature.native.d.ts +8 -0
- package/dist/Signature.native.js +26 -0
- package/dist/Signature.native.js.map +1 -0
- package/dist/SignatureField.d.ts +3 -0
- package/dist/SignatureField.js +42 -0
- package/dist/SignatureField.js.map +1 -0
- package/dist/Slider.d.ts +3 -0
- package/dist/Slider.js +78 -0
- package/dist/Slider.js.map +1 -0
- package/dist/Spinner.d.ts +3 -0
- package/dist/Spinner.js +33 -0
- package/dist/Spinner.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -0
- package/dist/SplitPage.js +139 -0
- package/dist/SplitPage.js.map +1 -0
- package/dist/SplitPage.native.d.ts +2 -0
- package/dist/SplitPage.native.js +75 -0
- package/dist/SplitPage.native.js.map +1 -0
- package/dist/TapToEdit.d.ts +4 -0
- package/dist/TapToEdit.js +170 -0
- package/dist/TapToEdit.js.map +1 -0
- package/dist/TerrenoProvider.d.ts +6 -0
- package/dist/TerrenoProvider.js +10 -0
- package/dist/TerrenoProvider.js.map +1 -0
- package/dist/Text.d.ts +3 -0
- package/dist/Text.js +95 -0
- package/dist/Text.js.map +1 -0
- package/dist/TextArea.d.ts +3 -0
- package/dist/TextArea.js +6 -0
- package/dist/TextArea.js.map +1 -0
- package/dist/TextField.d.ts +3 -0
- package/dist/TextField.js +144 -0
- package/dist/TextField.js.map +1 -0
- package/dist/TextFieldNumberActionSheet.d.ts +7 -0
- package/dist/TextFieldNumberActionSheet.js +20 -0
- package/dist/TextFieldNumberActionSheet.js.map +1 -0
- package/dist/Theme.d.ts +96 -0
- package/dist/Theme.js +213 -0
- package/dist/Theme.js.map +1 -0
- package/dist/TimezonePicker.d.ts +11 -0
- package/dist/TimezonePicker.js +27 -0
- package/dist/TimezonePicker.js.map +1 -0
- package/dist/Toast.d.ts +23 -0
- package/dist/Toast.js +157 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Tooltip.d.ts +3 -0
- package/dist/Tooltip.js +289 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/UnifiedAddressAutoComplete.d.ts +2 -0
- package/dist/UnifiedAddressAutoComplete.js +23 -0
- package/dist/UnifiedAddressAutoComplete.js.map +1 -0
- package/dist/Unifier.d.ts +43 -0
- package/dist/Unifier.js +154 -0
- package/dist/Unifier.js.map +1 -0
- package/dist/Utilities.d.ts +56 -0
- package/dist/Utilities.js +193 -0
- package/dist/Utilities.js.map +1 -0
- package/dist/WebAddressAutocomplete.d.ts +3 -0
- package/dist/WebAddressAutocomplete.js +61 -0
- package/dist/WebAddressAutocomplete.js.map +1 -0
- package/dist/fieldElements/FieldError.d.ts +6 -0
- package/dist/fieldElements/FieldError.js +9 -0
- package/dist/fieldElements/FieldError.js.map +1 -0
- package/dist/fieldElements/FieldHelperText.d.ts +6 -0
- package/dist/fieldElements/FieldHelperText.js +8 -0
- package/dist/fieldElements/FieldHelperText.js.map +1 -0
- package/dist/fieldElements/FieldTitle.d.ts +6 -0
- package/dist/fieldElements/FieldTitle.js +16 -0
- package/dist/fieldElements/FieldTitle.js.map +1 -0
- package/dist/fieldElements/index.d.ts +3 -0
- package/dist/fieldElements/index.js +4 -0
- package/dist/fieldElements/index.js.map +1 -0
- package/dist/icons/MobileIcon.d.ts +2 -0
- package/dist/icons/MobileIcon.js +18 -0
- package/dist/icons/MobileIcon.js.map +1 -0
- package/dist/icons/OfflineIcon.d.ts +2 -0
- package/dist/icons/OfflineIcon.js +18 -0
- package/dist/icons/OfflineIcon.js.map +1 -0
- package/dist/icons/OnlineIcon.d.ts +2 -0
- package/dist/icons/OnlineIcon.js +19 -0
- package/dist/icons/OnlineIcon.js.map +1 -0
- package/dist/icons/OutOfficeIcon.d.ts +2 -0
- package/dist/icons/OutOfficeIcon.js +18 -0
- package/dist/icons/OutOfficeIcon.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +5 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/index.d.ts +1328 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/dist/table/Table.d.ts +3 -0
- package/dist/table/Table.js +53 -0
- package/dist/table/Table.js.map +1 -0
- package/dist/table/TableBadge.d.ts +6 -0
- package/dist/table/TableBadge.js +23 -0
- package/dist/table/TableBadge.js.map +1 -0
- package/dist/table/TableBoolean.d.ts +6 -0
- package/dist/table/TableBoolean.js +37 -0
- package/dist/table/TableBoolean.js.map +1 -0
- package/dist/table/TableDate.d.ts +3 -0
- package/dist/table/TableDate.js +27 -0
- package/dist/table/TableDate.js.map +1 -0
- package/dist/table/TableHeader.d.ts +6 -0
- package/dist/table/TableHeader.js +10 -0
- package/dist/table/TableHeader.js.map +1 -0
- package/dist/table/TableHeaderCell.d.ts +6 -0
- package/dist/table/TableHeaderCell.js +54 -0
- package/dist/table/TableHeaderCell.js.map +1 -0
- package/dist/table/TableIconButton.d.ts +3 -0
- package/dist/table/TableIconButton.js +39 -0
- package/dist/table/TableIconButton.js.map +1 -0
- package/dist/table/TableNumber.d.ts +3 -0
- package/dist/table/TableNumber.js +18 -0
- package/dist/table/TableNumber.js.map +1 -0
- package/dist/table/TableRow.d.ts +6 -0
- package/dist/table/TableRow.js +22 -0
- package/dist/table/TableRow.js.map +1 -0
- package/dist/table/TableText.d.ts +3 -0
- package/dist/table/TableText.js +18 -0
- package/dist/table/TableText.js.map +1 -0
- package/dist/table/TableTitle.d.ts +3 -0
- package/dist/table/TableTitle.js +21 -0
- package/dist/table/TableTitle.js.map +1 -0
- package/dist/table/tableContext.d.ts +5 -0
- package/dist/table/tableContext.js +38 -0
- package/dist/table/tableContext.js.map +1 -0
- package/dist/useStoredState.d.ts +1 -0
- package/dist/useStoredState.js +49 -0
- package/dist/useStoredState.js.map +1 -0
- package/package.json +123 -0
- package/src/Accordion.test.tsx +104 -0
- package/src/Accordion.tsx +81 -0
- package/src/ActionSheet.tsx +881 -0
- package/src/AddressField.test.tsx +120 -0
- package/src/AddressField.tsx +122 -0
- package/src/Avatar.test.tsx +163 -0
- package/src/Avatar.tsx +298 -0
- package/src/Badge.test.tsx +116 -0
- package/src/Badge.tsx +136 -0
- package/src/Banner.tsx +200 -0
- package/src/Body.tsx +34 -0
- package/src/BooleanField.tsx +141 -0
- package/src/Box.test.tsx +662 -0
- package/src/Box.tsx +368 -0
- package/src/Button.tsx +196 -0
- package/src/Card.tsx +19 -0
- package/src/CheckBox.tsx +45 -0
- package/src/Common.ts +2787 -0
- package/src/CommonIconTypes.ts +2030 -0
- package/src/Constants.ts +3311 -0
- package/src/CustomSelectField.tsx +115 -0
- package/src/DataTable.tsx +674 -0
- package/src/DateTimeActionSheet.tsx +559 -0
- package/src/DateTimeField.test.tsx +393 -0
- package/src/DateTimeField.tsx +777 -0
- package/src/DateUtilities.test.ts +440 -0
- package/src/DateUtilities.tsx +370 -0
- package/src/DecimalRangeActionSheet.tsx +85 -0
- package/src/DismissButton.tsx +31 -0
- package/src/EmailField.tsx +66 -0
- package/src/EmojiSelector.test.tsx +61 -0
- package/src/EmojiSelector.tsx +510 -0
- package/src/ErrorBoundary.tsx +37 -0
- package/src/ErrorPage.tsx +41 -0
- package/src/Field.tsx +101 -0
- package/src/FlatList.tsx +2 -0
- package/src/Heading.tsx +66 -0
- package/src/HeightActionSheet.tsx +91 -0
- package/src/Hyperlink.tsx +179 -0
- package/src/Icon.tsx +36 -0
- package/src/IconButton.tsx +217 -0
- package/src/Image.tsx +51 -0
- package/src/ImageBackground.tsx +14 -0
- package/src/InfoModalIcon.tsx +42 -0
- package/src/InfoTooltipButton.tsx +16 -0
- package/src/Link.tsx +22 -0
- package/src/MarkdownView.tsx +67 -0
- package/src/MediaQuery.ts +46 -0
- package/src/MobileAddressAutoComplete.tsx +126 -0
- package/src/Modal.tsx +300 -0
- package/src/ModalSheet.tsx +58 -0
- package/src/MultiselectField.tsx +112 -0
- package/src/NumberField.tsx +67 -0
- package/src/NumberPickerActionSheet.tsx +51 -0
- package/src/OpenAPIContext.tsx +74 -0
- package/src/Page.tsx +105 -0
- package/src/Pagination.tsx +169 -0
- package/src/PasswordField.tsx +7 -0
- package/src/Permissions.ts +43 -0
- package/src/PhoneNumberField.tsx +109 -0
- package/src/PickerSelect.tsx +571 -0
- package/src/Radio.tsx +33 -0
- package/src/RadioField.tsx +43 -0
- package/src/ScrollView.tsx +2 -0
- package/src/SectionDivider.tsx +18 -0
- package/src/SegmentedControl.tsx +126 -0
- package/src/SelectBadge.tsx +280 -0
- package/src/SelectField.tsx +41 -0
- package/src/SideDrawer.tsx +56 -0
- package/src/Signature.native.tsx +57 -0
- package/src/Signature.tsx +44 -0
- package/src/SignatureField.tsx +92 -0
- package/src/Slider.tsx +199 -0
- package/src/Spinner.tsx +35 -0
- package/src/SplitPage.native.tsx +163 -0
- package/src/SplitPage.tsx +304 -0
- package/src/TapToEdit.tsx +292 -0
- package/src/TerrenoProvider.tsx +31 -0
- package/src/Text.tsx +123 -0
- package/src/TextArea.test.tsx +255 -0
- package/src/TextArea.tsx +8 -0
- package/src/TextField.test.tsx +487 -0
- package/src/TextField.tsx +260 -0
- package/src/TextFieldNumberActionSheet.tsx +46 -0
- package/src/Theme.tsx +248 -0
- package/src/TimezonePicker.tsx +45 -0
- package/src/Toast.tsx +234 -0
- package/src/Tooltip.tsx +407 -0
- package/src/UnifiedAddressAutoComplete.tsx +66 -0
- package/src/Unifier.ts +172 -0
- package/src/Utilities.tsx +329 -0
- package/src/WebAddressAutocomplete.tsx +84 -0
- package/src/__snapshots__/Accordion.test.tsx.snap +126 -0
- package/src/__snapshots__/AddressField.test.tsx.snap +1197 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +57 -0
- package/src/__snapshots__/Badge.test.tsx.snap +55 -0
- package/src/__snapshots__/Box.test.tsx.snap +162 -0
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +422 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +521 -0
- package/src/__snapshots__/TextField.test.tsx.snap +569 -0
- package/src/bunSetup.ts +1235 -0
- package/src/fieldElements/FieldError.tsx +24 -0
- package/src/fieldElements/FieldHelperText.tsx +20 -0
- package/src/fieldElements/FieldTitle.tsx +31 -0
- package/src/fieldElements/index.tsx +3 -0
- package/src/icons/MobileIcon.tsx +40 -0
- package/src/icons/OfflineIcon.tsx +37 -0
- package/src/icons/OnlineIcon.tsx +39 -0
- package/src/icons/OutOfficeIcon.tsx +36 -0
- package/src/icons/index.ts +4 -0
- package/src/index.tsx +1375 -0
- package/src/polyfill.d.ts +11 -0
- package/src/table/Table.tsx +109 -0
- package/src/table/TableBadge.tsx +46 -0
- package/src/table/TableBoolean.tsx +70 -0
- package/src/table/TableDate.tsx +38 -0
- package/src/table/TableHeader.tsx +20 -0
- package/src/table/TableHeaderCell.tsx +94 -0
- package/src/table/TableIconButton.tsx +61 -0
- package/src/table/TableNumber.tsx +29 -0
- package/src/table/TableRow.tsx +67 -0
- package/src/table/TableText.tsx +29 -0
- package/src/table/TableTitle.tsx +31 -0
- package/src/table/tableContext.tsx +67 -0
- package/src/test-utils.tsx +27 -0
- package/src/types/react-native-swiper-flatlist.d.ts +56 -0
- package/src/useStoredState.test.tsx +143 -0
- package/src/useStoredState.ts +56 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import {FontAwesome6} from "@expo/vector-icons";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import {type FC, useCallback, useMemo, useRef, useState} from "react";
|
|
4
|
+
import {
|
|
5
|
+
type NativeScrollEvent,
|
|
6
|
+
type NativeSyntheticEvent,
|
|
7
|
+
Pressable,
|
|
8
|
+
ScrollView,
|
|
9
|
+
View,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
import Markdown from "react-native-markdown-display";
|
|
12
|
+
|
|
13
|
+
import {Box} from "./Box";
|
|
14
|
+
import type {
|
|
15
|
+
ColumnSortInterface,
|
|
16
|
+
DataTableCellData,
|
|
17
|
+
DataTableCellProps,
|
|
18
|
+
DataTableColumn,
|
|
19
|
+
DataTableCustomComponentMap,
|
|
20
|
+
DataTableProps,
|
|
21
|
+
SurfaceColor,
|
|
22
|
+
} from "./Common";
|
|
23
|
+
import {Icon} from "./Icon";
|
|
24
|
+
import {InfoModalIcon} from "./InfoModalIcon";
|
|
25
|
+
import {Modal} from "./Modal";
|
|
26
|
+
import {Pagination} from "./Pagination";
|
|
27
|
+
import {Text} from "./Text";
|
|
28
|
+
import {useTheme} from "./Theme";
|
|
29
|
+
import {TableTitle} from "./table/TableTitle";
|
|
30
|
+
|
|
31
|
+
// TODO: Add permanent horizontal scroll bar so users with only a mouse can scroll left/right
|
|
32
|
+
// easily.
|
|
33
|
+
|
|
34
|
+
const TextCell: FC<{
|
|
35
|
+
cellData: {value: string; textSize?: "sm" | "md" | "lg"};
|
|
36
|
+
column: DataTableColumn;
|
|
37
|
+
}> = ({cellData}) => {
|
|
38
|
+
return (
|
|
39
|
+
<Box flex="grow" justifyContent="center" paddingX={2}>
|
|
40
|
+
<Text size={cellData.textSize || "md"}>{cellData.value}</Text>
|
|
41
|
+
</Box>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const CheckedCell: FC<{cellData: {value: boolean}; column: DataTableColumn}> = ({cellData}) => {
|
|
46
|
+
return (
|
|
47
|
+
<Box flex="grow" justifyContent="center" width="100%">
|
|
48
|
+
<Icon
|
|
49
|
+
color={cellData.value ? "success" : "secondaryDark"}
|
|
50
|
+
iconName={cellData.value ? "check" : "x"}
|
|
51
|
+
/>
|
|
52
|
+
</Box>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const DataTableCell: FC<DataTableCellProps> = ({
|
|
57
|
+
value,
|
|
58
|
+
columnDef,
|
|
59
|
+
colIndex,
|
|
60
|
+
isPinnedHorizontal,
|
|
61
|
+
pinnedColumns,
|
|
62
|
+
columnWidths,
|
|
63
|
+
customColumnComponentMap,
|
|
64
|
+
backgroundColor,
|
|
65
|
+
height,
|
|
66
|
+
textSize = "md",
|
|
67
|
+
}) => {
|
|
68
|
+
const {theme} = useTheme();
|
|
69
|
+
const isLastPinnedColumn = isPinnedHorizontal && colIndex === pinnedColumns - 1;
|
|
70
|
+
|
|
71
|
+
// Default to TextCell
|
|
72
|
+
let Component: React.ComponentType<{
|
|
73
|
+
column: DataTableColumn;
|
|
74
|
+
cellData: {value: any; highlight?: SurfaceColor};
|
|
75
|
+
}> = TextCell;
|
|
76
|
+
if (customColumnComponentMap?.[columnDef.columnType]) {
|
|
77
|
+
Component = customColumnComponentMap[columnDef.columnType];
|
|
78
|
+
} else if (columnDef.columnType === "boolean") {
|
|
79
|
+
Component = CheckedCell;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<View
|
|
84
|
+
style={{
|
|
85
|
+
backgroundColor,
|
|
86
|
+
borderBottomColor: theme.border.default,
|
|
87
|
+
borderBottomWidth: 1,
|
|
88
|
+
height,
|
|
89
|
+
justifyContent: "center",
|
|
90
|
+
overflow: "hidden",
|
|
91
|
+
padding: 16,
|
|
92
|
+
position: "relative",
|
|
93
|
+
width: columnDef.width,
|
|
94
|
+
zIndex: 1,
|
|
95
|
+
// For pinned columns: use absolute positioning to stay fixed while scrolling horizontally
|
|
96
|
+
...(isPinnedHorizontal && {
|
|
97
|
+
// Position each pinned column by summing widths of all previous columns
|
|
98
|
+
left: columnWidths.slice(0, colIndex).reduce((sum, width) => sum + width, 0),
|
|
99
|
+
position: "absolute",
|
|
100
|
+
// Higher z-index keeps pinned columns above scrollable ones, decreasing by column index
|
|
101
|
+
zIndex: 10 - colIndex,
|
|
102
|
+
}),
|
|
103
|
+
// Visual separator after last pinned column
|
|
104
|
+
...(isLastPinnedColumn && {
|
|
105
|
+
borderRightColor: theme.border.default,
|
|
106
|
+
borderRightWidth: 3,
|
|
107
|
+
}),
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<Component cellData={{...value, textSize}} column={columnDef} />
|
|
111
|
+
</View>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
interface DataTableRowProps {
|
|
116
|
+
rowData: DataTableCellData[];
|
|
117
|
+
rowIndex: number;
|
|
118
|
+
columns: DataTableColumn[];
|
|
119
|
+
pinnedColumns: number;
|
|
120
|
+
columnWidths: number[];
|
|
121
|
+
alternateRowBackground: boolean;
|
|
122
|
+
customColumnComponentMap?: DataTableCustomComponentMap;
|
|
123
|
+
rowHeight: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const DataTableRow: FC<DataTableRowProps> = ({
|
|
127
|
+
rowData,
|
|
128
|
+
rowIndex,
|
|
129
|
+
columns,
|
|
130
|
+
pinnedColumns,
|
|
131
|
+
columnWidths,
|
|
132
|
+
alternateRowBackground,
|
|
133
|
+
customColumnComponentMap,
|
|
134
|
+
rowHeight,
|
|
135
|
+
}) => {
|
|
136
|
+
const {theme} = useTheme();
|
|
137
|
+
const backgroundColor =
|
|
138
|
+
alternateRowBackground && rowIndex % 2 === 1 ? theme.surface.neutralLight : theme.surface.base;
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<View
|
|
142
|
+
style={{
|
|
143
|
+
borderBottomColor: theme.border.default,
|
|
144
|
+
borderBottomWidth: 1,
|
|
145
|
+
flexDirection: "row",
|
|
146
|
+
height: rowHeight,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{rowData.map((cell, colIndex) => (
|
|
150
|
+
<DataTableCell
|
|
151
|
+
backgroundColor={
|
|
152
|
+
cell.highlight ? theme.surface[cell.highlight as SurfaceColor] : backgroundColor
|
|
153
|
+
}
|
|
154
|
+
colIndex={colIndex}
|
|
155
|
+
columnDef={columns[colIndex]}
|
|
156
|
+
columnWidths={columnWidths}
|
|
157
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
158
|
+
height={rowHeight}
|
|
159
|
+
isPinnedHorizontal={colIndex < pinnedColumns}
|
|
160
|
+
key={colIndex}
|
|
161
|
+
pinnedColumns={pinnedColumns}
|
|
162
|
+
textSize={cell.textSize}
|
|
163
|
+
value={cell}
|
|
164
|
+
/>
|
|
165
|
+
))}
|
|
166
|
+
</View>
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
interface MoreButtonCellProps {
|
|
171
|
+
rowIndex: number;
|
|
172
|
+
alternateRowBackground: boolean;
|
|
173
|
+
onClick: (rowIndex: number) => void;
|
|
174
|
+
column: DataTableColumn;
|
|
175
|
+
rowHeight: number;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const MoreButtonCell: FC<MoreButtonCellProps> = ({
|
|
179
|
+
rowIndex,
|
|
180
|
+
alternateRowBackground,
|
|
181
|
+
onClick,
|
|
182
|
+
rowHeight,
|
|
183
|
+
}) => {
|
|
184
|
+
const {theme} = useTheme();
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<View
|
|
188
|
+
style={{
|
|
189
|
+
alignItems: "center",
|
|
190
|
+
backgroundColor:
|
|
191
|
+
alternateRowBackground && rowIndex % 2 === 1
|
|
192
|
+
? theme.surface.neutralLight
|
|
193
|
+
: theme.surface.base,
|
|
194
|
+
borderBottomColor: theme.border.default,
|
|
195
|
+
borderBottomWidth: 1,
|
|
196
|
+
height: rowHeight ?? 54,
|
|
197
|
+
justifyContent: "center",
|
|
198
|
+
width: 48,
|
|
199
|
+
}}
|
|
200
|
+
>
|
|
201
|
+
<Pressable
|
|
202
|
+
accessibilityHint="View details"
|
|
203
|
+
accessibilityLabel="Open modal"
|
|
204
|
+
accessibilityRole="button"
|
|
205
|
+
onPress={() => onClick(rowIndex)}
|
|
206
|
+
style={{
|
|
207
|
+
alignItems: "center",
|
|
208
|
+
backgroundColor:
|
|
209
|
+
alternateRowBackground && rowIndex % 2 === 1
|
|
210
|
+
? theme.surface.base
|
|
211
|
+
: theme.surface.neutralLight,
|
|
212
|
+
borderRadius: theme.radius.rounded,
|
|
213
|
+
height: 32,
|
|
214
|
+
justifyContent: "center",
|
|
215
|
+
width: 32,
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
<Icon color="secondaryDark" iconName="info" size="md" />
|
|
219
|
+
</Pressable>
|
|
220
|
+
</View>
|
|
221
|
+
);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
interface DataTableHeaderCellProps {
|
|
225
|
+
column: DataTableColumn;
|
|
226
|
+
index: number;
|
|
227
|
+
isPinnedHorizontal: boolean;
|
|
228
|
+
isPinnedRow?: boolean;
|
|
229
|
+
columnWidths: number[];
|
|
230
|
+
sortColumn?: ColumnSortInterface;
|
|
231
|
+
onSort: (index: number) => void;
|
|
232
|
+
rowHeight: number;
|
|
233
|
+
headerHeight?: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const DataTableHeaderCell: FC<DataTableHeaderCellProps> = ({
|
|
237
|
+
column,
|
|
238
|
+
index,
|
|
239
|
+
isPinnedHorizontal,
|
|
240
|
+
columnWidths,
|
|
241
|
+
sortColumn,
|
|
242
|
+
onSort,
|
|
243
|
+
rowHeight,
|
|
244
|
+
headerHeight,
|
|
245
|
+
}) => {
|
|
246
|
+
const {theme} = useTheme();
|
|
247
|
+
const sort = sortColumn?.column === index ? sortColumn.direction : undefined;
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<View
|
|
251
|
+
style={{
|
|
252
|
+
alignItems: "center",
|
|
253
|
+
backgroundColor: theme.surface.base,
|
|
254
|
+
borderBottomColor: theme.border.default,
|
|
255
|
+
borderBottomWidth: 1,
|
|
256
|
+
flexDirection: "row",
|
|
257
|
+
height: headerHeight ?? rowHeight,
|
|
258
|
+
justifyContent: "space-between",
|
|
259
|
+
padding: 16,
|
|
260
|
+
width: column.width,
|
|
261
|
+
...(isPinnedHorizontal && {
|
|
262
|
+
left: columnWidths.slice(0, index).reduce((sum, width) => sum + width, 0),
|
|
263
|
+
position: "absolute",
|
|
264
|
+
zIndex: 10 - index,
|
|
265
|
+
}),
|
|
266
|
+
}}
|
|
267
|
+
>
|
|
268
|
+
{Boolean(column.title) && <TableTitle align="left" title={column.title!} />}
|
|
269
|
+
<View style={{alignItems: "center", flexDirection: "row"}}>
|
|
270
|
+
{column.infoModalText && (
|
|
271
|
+
<InfoModalIcon infoModalChildren={<Markdown>{column.infoModalText}</Markdown>} />
|
|
272
|
+
)}
|
|
273
|
+
{column.sortable && (
|
|
274
|
+
<Pressable hitSlop={16} onPress={() => onSort(index)}>
|
|
275
|
+
<View
|
|
276
|
+
style={{
|
|
277
|
+
alignItems: "center",
|
|
278
|
+
backgroundColor: sort ? theme.surface.primary : theme.surface.neutralLight,
|
|
279
|
+
borderRadius: theme.radius.rounded,
|
|
280
|
+
height: 16,
|
|
281
|
+
justifyContent: "center",
|
|
282
|
+
marginLeft: 8,
|
|
283
|
+
width: 16,
|
|
284
|
+
}}
|
|
285
|
+
>
|
|
286
|
+
<FontAwesome6
|
|
287
|
+
color={theme.text.inverted}
|
|
288
|
+
name={
|
|
289
|
+
sort === "asc" ? "arrow-down" : sort === "desc" ? "arrow-up" : "arrows-up-down"
|
|
290
|
+
}
|
|
291
|
+
selectable={undefined}
|
|
292
|
+
size={10}
|
|
293
|
+
solid
|
|
294
|
+
/>
|
|
295
|
+
</View>
|
|
296
|
+
</Pressable>
|
|
297
|
+
)}
|
|
298
|
+
</View>
|
|
299
|
+
</View>
|
|
300
|
+
);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
interface DataTableHeaderProps {
|
|
304
|
+
columns: DataTableColumn[];
|
|
305
|
+
hasMoreContent: boolean;
|
|
306
|
+
pinnedColumns: number;
|
|
307
|
+
columnWidths: number[];
|
|
308
|
+
headerScrollRef: React.RefObject<ScrollView | null>;
|
|
309
|
+
sortColumn?: ColumnSortInterface;
|
|
310
|
+
onSort: (index: number) => void;
|
|
311
|
+
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>, isHeader: boolean) => void;
|
|
312
|
+
rowHeight: number;
|
|
313
|
+
headerHeight?: number;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const DataTableHeader: FC<DataTableHeaderProps> = ({
|
|
317
|
+
columns,
|
|
318
|
+
hasMoreContent,
|
|
319
|
+
pinnedColumns,
|
|
320
|
+
columnWidths,
|
|
321
|
+
headerScrollRef,
|
|
322
|
+
sortColumn,
|
|
323
|
+
onSort,
|
|
324
|
+
onScroll,
|
|
325
|
+
rowHeight,
|
|
326
|
+
headerHeight,
|
|
327
|
+
}) => {
|
|
328
|
+
const {theme} = useTheme();
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<View style={{flexDirection: "row", position: "relative"}}>
|
|
332
|
+
{/* Fixed-width container for "more" content button if present */}
|
|
333
|
+
{hasMoreContent && (
|
|
334
|
+
<View
|
|
335
|
+
style={{
|
|
336
|
+
backgroundColor: theme.surface.base,
|
|
337
|
+
borderBottomColor: theme.border.default,
|
|
338
|
+
borderBottomWidth: 1,
|
|
339
|
+
height: headerHeight ?? rowHeight,
|
|
340
|
+
width: 48,
|
|
341
|
+
zIndex: 11,
|
|
342
|
+
}}
|
|
343
|
+
/>
|
|
344
|
+
)}
|
|
345
|
+
|
|
346
|
+
{/* Container for pinned header columns - stays fixed during horizontal scroll */}
|
|
347
|
+
{pinnedColumns > 0 && (
|
|
348
|
+
<View
|
|
349
|
+
style={{
|
|
350
|
+
// Offset left position if there's a "more" content button
|
|
351
|
+
left: hasMoreContent ? 48 : 0,
|
|
352
|
+
position: "absolute",
|
|
353
|
+
top: 0,
|
|
354
|
+
zIndex: 10,
|
|
355
|
+
}}
|
|
356
|
+
>
|
|
357
|
+
{columns.slice(0, pinnedColumns).map((column, index) => (
|
|
358
|
+
<DataTableHeaderCell
|
|
359
|
+
column={column}
|
|
360
|
+
columnWidths={columnWidths}
|
|
361
|
+
headerHeight={headerHeight}
|
|
362
|
+
index={index}
|
|
363
|
+
isPinnedHorizontal
|
|
364
|
+
key={`pinned-header-${index}`}
|
|
365
|
+
onSort={onSort}
|
|
366
|
+
rowHeight={rowHeight}
|
|
367
|
+
sortColumn={sortColumn}
|
|
368
|
+
/>
|
|
369
|
+
))}
|
|
370
|
+
</View>
|
|
371
|
+
)}
|
|
372
|
+
|
|
373
|
+
{/* Scrollable container for non-pinned header columns */}
|
|
374
|
+
<ScrollView
|
|
375
|
+
horizontal
|
|
376
|
+
onScroll={(e) => onScroll(e, true)}
|
|
377
|
+
ref={headerScrollRef}
|
|
378
|
+
scrollEventThrottle={16}
|
|
379
|
+
showsHorizontalScrollIndicator={false}
|
|
380
|
+
style={{
|
|
381
|
+
// Offset scrollable area by total width of pinned columns
|
|
382
|
+
marginLeft: columnWidths.slice(0, pinnedColumns).reduce((sum, width) => sum + width, 0),
|
|
383
|
+
}}
|
|
384
|
+
>
|
|
385
|
+
{columns.slice(pinnedColumns).map((column, index) => (
|
|
386
|
+
<DataTableHeaderCell
|
|
387
|
+
column={column}
|
|
388
|
+
columnWidths={columnWidths}
|
|
389
|
+
headerHeight={headerHeight}
|
|
390
|
+
index={index + pinnedColumns}
|
|
391
|
+
isPinnedHorizontal={false}
|
|
392
|
+
key={`scrollable-header-${index + pinnedColumns}`}
|
|
393
|
+
onSort={onSort}
|
|
394
|
+
rowHeight={rowHeight}
|
|
395
|
+
sortColumn={sortColumn}
|
|
396
|
+
/>
|
|
397
|
+
))}
|
|
398
|
+
</ScrollView>
|
|
399
|
+
</View>
|
|
400
|
+
);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
interface DataTableContentProps {
|
|
404
|
+
data: any[][];
|
|
405
|
+
columns: DataTableColumn[];
|
|
406
|
+
pinnedColumns: number;
|
|
407
|
+
alternateRowBackground: boolean;
|
|
408
|
+
columnWidths: number[];
|
|
409
|
+
bodyScrollRef: React.RefObject<ScrollView | null>;
|
|
410
|
+
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>, isHeader: boolean) => void;
|
|
411
|
+
moreContentComponent?: React.ComponentType<{
|
|
412
|
+
column: DataTableColumn;
|
|
413
|
+
rowData: any[];
|
|
414
|
+
rowIndex: number;
|
|
415
|
+
}>;
|
|
416
|
+
// Extra props to pass to the more modal, one per row.
|
|
417
|
+
moreContentExtraData?: any[];
|
|
418
|
+
moreContentSize?: "sm" | "md" | "lg";
|
|
419
|
+
customColumnComponentMap?: DataTableCustomComponentMap;
|
|
420
|
+
rowHeight: number;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const DataTableContent: FC<DataTableContentProps> = ({
|
|
424
|
+
data,
|
|
425
|
+
columns,
|
|
426
|
+
pinnedColumns,
|
|
427
|
+
alternateRowBackground,
|
|
428
|
+
columnWidths,
|
|
429
|
+
bodyScrollRef,
|
|
430
|
+
onScroll,
|
|
431
|
+
customColumnComponentMap,
|
|
432
|
+
moreContentComponent: MoreContentContent,
|
|
433
|
+
moreContentExtraData,
|
|
434
|
+
moreContentSize = "md",
|
|
435
|
+
rowHeight,
|
|
436
|
+
}) => {
|
|
437
|
+
const [modalRow, setModalRow] = useState<number | null>(null);
|
|
438
|
+
const {theme} = useTheme();
|
|
439
|
+
|
|
440
|
+
return (
|
|
441
|
+
<>
|
|
442
|
+
<ScrollView style={{flex: 1}}>
|
|
443
|
+
<View
|
|
444
|
+
style={{
|
|
445
|
+
flexDirection: "row",
|
|
446
|
+
position: "relative",
|
|
447
|
+
}}
|
|
448
|
+
>
|
|
449
|
+
{/* Fixed-width container for "more" content button if present */}
|
|
450
|
+
{Boolean(MoreContentContent) && (
|
|
451
|
+
<View
|
|
452
|
+
style={{
|
|
453
|
+
backgroundColor: theme.surface.base,
|
|
454
|
+
left: 0,
|
|
455
|
+
position: "absolute",
|
|
456
|
+
top: 0,
|
|
457
|
+
width: 48,
|
|
458
|
+
zIndex: 1,
|
|
459
|
+
}}
|
|
460
|
+
>
|
|
461
|
+
{data.map((_, rowIndex) => (
|
|
462
|
+
<MoreButtonCell
|
|
463
|
+
alternateRowBackground={alternateRowBackground}
|
|
464
|
+
column={columns[0]}
|
|
465
|
+
key={`expand-${rowIndex}`}
|
|
466
|
+
onClick={setModalRow}
|
|
467
|
+
rowHeight={rowHeight}
|
|
468
|
+
rowIndex={rowIndex}
|
|
469
|
+
/>
|
|
470
|
+
))}
|
|
471
|
+
</View>
|
|
472
|
+
)}
|
|
473
|
+
|
|
474
|
+
{/* Container for pinned rows - stays fixed during horizontal scroll */}
|
|
475
|
+
{pinnedColumns > 0 && (
|
|
476
|
+
<View
|
|
477
|
+
style={{
|
|
478
|
+
left: MoreContentContent ? 48 : 0,
|
|
479
|
+
position: "absolute",
|
|
480
|
+
top: 0,
|
|
481
|
+
zIndex: 10,
|
|
482
|
+
}}
|
|
483
|
+
>
|
|
484
|
+
{data.map((row, rowIndex) => (
|
|
485
|
+
<DataTableRow
|
|
486
|
+
alternateRowBackground={alternateRowBackground}
|
|
487
|
+
columns={columns.slice(0, pinnedColumns)}
|
|
488
|
+
columnWidths={columnWidths}
|
|
489
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
490
|
+
key={`pinned-${rowIndex}`}
|
|
491
|
+
pinnedColumns={pinnedColumns}
|
|
492
|
+
rowData={row.slice(0, pinnedColumns)}
|
|
493
|
+
rowHeight={rowHeight}
|
|
494
|
+
rowIndex={rowIndex}
|
|
495
|
+
/>
|
|
496
|
+
))}
|
|
497
|
+
</View>
|
|
498
|
+
)}
|
|
499
|
+
|
|
500
|
+
{/* Scrollable container for non-pinned rows */}
|
|
501
|
+
<ScrollView
|
|
502
|
+
horizontal
|
|
503
|
+
onScroll={(e) => onScroll(e, false)}
|
|
504
|
+
ref={bodyScrollRef}
|
|
505
|
+
scrollEventThrottle={16}
|
|
506
|
+
showsHorizontalScrollIndicator
|
|
507
|
+
style={{
|
|
508
|
+
flex: 1,
|
|
509
|
+
marginLeft:
|
|
510
|
+
columnWidths.slice(0, pinnedColumns).reduce((sum, width) => sum + width, 0) +
|
|
511
|
+
(MoreContentContent ? 48 : 0),
|
|
512
|
+
}}
|
|
513
|
+
>
|
|
514
|
+
<View>
|
|
515
|
+
{data.map((row, rowIndex) => (
|
|
516
|
+
<DataTableRow
|
|
517
|
+
alternateRowBackground={alternateRowBackground}
|
|
518
|
+
columns={columns.slice(pinnedColumns)}
|
|
519
|
+
columnWidths={columnWidths}
|
|
520
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
521
|
+
key={`scrollable-${rowIndex}`}
|
|
522
|
+
pinnedColumns={0}
|
|
523
|
+
rowData={row.slice(pinnedColumns)}
|
|
524
|
+
rowHeight={rowHeight}
|
|
525
|
+
rowIndex={rowIndex}
|
|
526
|
+
/>
|
|
527
|
+
))}
|
|
528
|
+
</View>
|
|
529
|
+
</ScrollView>
|
|
530
|
+
</View>
|
|
531
|
+
</ScrollView>
|
|
532
|
+
|
|
533
|
+
{MoreContentContent && (
|
|
534
|
+
<Modal
|
|
535
|
+
onDismiss={() => setModalRow(null)}
|
|
536
|
+
size={moreContentSize}
|
|
537
|
+
visible={modalRow !== null}
|
|
538
|
+
>
|
|
539
|
+
<MoreContentContent
|
|
540
|
+
column={columns[0]}
|
|
541
|
+
rowData={data[modalRow!]}
|
|
542
|
+
rowIndex={modalRow!}
|
|
543
|
+
{...(moreContentExtraData?.[modalRow!] ?? {})}
|
|
544
|
+
/>
|
|
545
|
+
</Modal>
|
|
546
|
+
)}
|
|
547
|
+
</>
|
|
548
|
+
);
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
export const DataTable: FC<DataTableProps> = ({
|
|
552
|
+
data,
|
|
553
|
+
columns,
|
|
554
|
+
alternateRowBackground = true,
|
|
555
|
+
totalPages = 1,
|
|
556
|
+
page = 0,
|
|
557
|
+
setPage,
|
|
558
|
+
pinnedColumns = 0,
|
|
559
|
+
sortColumn,
|
|
560
|
+
setSortColumn,
|
|
561
|
+
moreContentComponent,
|
|
562
|
+
moreContentExtraData,
|
|
563
|
+
customColumnComponentMap,
|
|
564
|
+
rowHeight = 54,
|
|
565
|
+
headerHeight,
|
|
566
|
+
defaultTextSize = "md",
|
|
567
|
+
}) => {
|
|
568
|
+
const {theme} = useTheme();
|
|
569
|
+
const headerScrollRef = useRef<ScrollView>(null);
|
|
570
|
+
const bodyScrollRef = useRef<ScrollView>(null);
|
|
571
|
+
|
|
572
|
+
const columnWidths = useMemo(() => columns.map((col) => col.width), [columns]);
|
|
573
|
+
|
|
574
|
+
const handleScroll = useCallback(
|
|
575
|
+
(event: NativeSyntheticEvent<NativeScrollEvent>, isHeader: boolean) => {
|
|
576
|
+
const scrollX = event.nativeEvent.contentOffset.x;
|
|
577
|
+
if (isHeader && bodyScrollRef.current) {
|
|
578
|
+
bodyScrollRef.current.scrollTo({animated: false, x: scrollX});
|
|
579
|
+
} else if (!isHeader && headerScrollRef.current) {
|
|
580
|
+
headerScrollRef.current.scrollTo({animated: false, x: scrollX});
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
[]
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
const handleSort = useCallback(
|
|
587
|
+
(columnIndex: number) => {
|
|
588
|
+
if (!setSortColumn || !columns[columnIndex].sortable) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (sortColumn?.column === columnIndex) {
|
|
593
|
+
if (sortColumn.direction === "asc") {
|
|
594
|
+
setSortColumn({
|
|
595
|
+
column: columnIndex,
|
|
596
|
+
direction: "desc",
|
|
597
|
+
});
|
|
598
|
+
} else {
|
|
599
|
+
setSortColumn(undefined);
|
|
600
|
+
}
|
|
601
|
+
} else {
|
|
602
|
+
setSortColumn({
|
|
603
|
+
column: columnIndex,
|
|
604
|
+
direction: "asc",
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
[sortColumn, setSortColumn, columns]
|
|
609
|
+
);
|
|
610
|
+
|
|
611
|
+
const processedData = useMemo(() => {
|
|
612
|
+
return data.map((row) =>
|
|
613
|
+
row.map((cell) => ({
|
|
614
|
+
...cell,
|
|
615
|
+
textSize: cell.textSize || defaultTextSize,
|
|
616
|
+
}))
|
|
617
|
+
);
|
|
618
|
+
}, [data, defaultTextSize]);
|
|
619
|
+
|
|
620
|
+
return (
|
|
621
|
+
<View style={{display: "flex", flexDirection: "column", height: "100%"}}>
|
|
622
|
+
<View
|
|
623
|
+
style={{
|
|
624
|
+
borderColor: theme.border.default,
|
|
625
|
+
borderWidth: 1,
|
|
626
|
+
flex: 1,
|
|
627
|
+
height: "100%",
|
|
628
|
+
minHeight: 0,
|
|
629
|
+
}}
|
|
630
|
+
>
|
|
631
|
+
<DataTableHeader
|
|
632
|
+
columns={columns}
|
|
633
|
+
columnWidths={columnWidths}
|
|
634
|
+
hasMoreContent={Boolean(moreContentComponent)}
|
|
635
|
+
headerHeight={headerHeight}
|
|
636
|
+
headerScrollRef={headerScrollRef}
|
|
637
|
+
onScroll={handleScroll}
|
|
638
|
+
onSort={handleSort}
|
|
639
|
+
pinnedColumns={pinnedColumns}
|
|
640
|
+
rowHeight={rowHeight}
|
|
641
|
+
sortColumn={sortColumn}
|
|
642
|
+
/>
|
|
643
|
+
|
|
644
|
+
<View style={{flex: 1, minHeight: 0}}>
|
|
645
|
+
<DataTableContent
|
|
646
|
+
alternateRowBackground={alternateRowBackground}
|
|
647
|
+
bodyScrollRef={bodyScrollRef}
|
|
648
|
+
columns={columns}
|
|
649
|
+
columnWidths={columnWidths}
|
|
650
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
651
|
+
data={processedData}
|
|
652
|
+
moreContentComponent={moreContentComponent}
|
|
653
|
+
moreContentExtraData={moreContentExtraData}
|
|
654
|
+
onScroll={handleScroll}
|
|
655
|
+
pinnedColumns={pinnedColumns}
|
|
656
|
+
rowHeight={rowHeight}
|
|
657
|
+
/>
|
|
658
|
+
</View>
|
|
659
|
+
</View>
|
|
660
|
+
|
|
661
|
+
{Boolean(setPage && totalPages > 1) && (
|
|
662
|
+
<View
|
|
663
|
+
style={{
|
|
664
|
+
alignItems: "center",
|
|
665
|
+
height: 60,
|
|
666
|
+
padding: 16,
|
|
667
|
+
}}
|
|
668
|
+
>
|
|
669
|
+
<Pagination page={page} setPage={setPage!} totalPages={totalPages} />
|
|
670
|
+
</View>
|
|
671
|
+
)}
|
|
672
|
+
</View>
|
|
673
|
+
);
|
|
674
|
+
};
|