@chem-po/react-web 0.0.51 → 0.0.53

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.
Files changed (127) hide show
  1. package/package.json +4 -5
  2. package/src/components/auth/SignIn.tsx +0 -43
  3. package/src/components/auth/index.ts +0 -1
  4. package/src/components/box/CollapseHorizontal.tsx +0 -19
  5. package/src/components/box/ContentBox.tsx +0 -17
  6. package/src/components/box/ExpandOnMount.tsx +0 -48
  7. package/src/components/box/Expandable.tsx +0 -96
  8. package/src/components/box/FullSizeContainer.tsx +0 -50
  9. package/src/components/box/MobileFrame/index.tsx +0 -146
  10. package/src/components/box/MobileFrame/styles.css +0 -35
  11. package/src/components/box/index.ts +0 -6
  12. package/src/components/button/DeleteButton.tsx +0 -178
  13. package/src/components/button/Toggle.tsx +0 -88
  14. package/src/components/button/ViewButton.tsx +0 -30
  15. package/src/components/button/index.ts +0 -3
  16. package/src/components/feed/FeedContentPane.tsx +0 -111
  17. package/src/components/feed/MediaFeed.tsx +0 -200
  18. package/src/components/feed/MediaFeedBackground.tsx +0 -127
  19. package/src/components/feed/MediaFeedRefresh.tsx +0 -78
  20. package/src/components/feed/MediaFeedSwipeUp.tsx +0 -35
  21. package/src/components/feed/constants.ts +0 -11
  22. package/src/components/feed/context.tsx +0 -19
  23. package/src/components/feed/hooks.ts +0 -290
  24. package/src/components/feed/index.ts +0 -2
  25. package/src/components/feed/types.ts +0 -50
  26. package/src/components/form/Condition.tsx +0 -26
  27. package/src/components/form/Field.tsx +0 -39
  28. package/src/components/form/Form.tsx +0 -428
  29. package/src/components/form/FormFooter.tsx +0 -90
  30. package/src/components/form/UploadProgress/index.tsx +0 -38
  31. package/src/components/form/UploadProgress/styles.css +0 -23
  32. package/src/components/form/index.ts +0 -4
  33. package/src/components/form/input/Editable.tsx +0 -155
  34. package/src/components/form/input/InputSlider.tsx +0 -76
  35. package/src/components/form/input/OptionalTag.tsx +0 -33
  36. package/src/components/form/input/StandaloneInput.tsx +0 -41
  37. package/src/components/form/input/boolean/index.tsx +0 -53
  38. package/src/components/form/input/color/index.tsx +0 -126
  39. package/src/components/form/input/date/index.tsx +0 -122
  40. package/src/components/form/input/datetime/index.tsx +0 -93
  41. package/src/components/form/input/file.tsx +0 -379
  42. package/src/components/form/input/hooks/index.ts +0 -2
  43. package/src/components/form/input/hooks/useInputImperativeHandle.ts +0 -16
  44. package/src/components/form/input/hooks/useInputStyles.ts +0 -125
  45. package/src/components/form/input/index.ts +0 -2
  46. package/src/components/form/input/input.css +0 -44
  47. package/src/components/form/input/input.tsx +0 -134
  48. package/src/components/form/input/multipleSelect/index.tsx +0 -89
  49. package/src/components/form/input/number/index.tsx +0 -87
  50. package/src/components/form/input/number/styles.css +0 -8
  51. package/src/components/form/input/select/index.tsx +0 -109
  52. package/src/components/form/input/shared/InputContainer.tsx +0 -13
  53. package/src/components/form/input/socialMedia/index.tsx +0 -165
  54. package/src/components/form/input/text/index.tsx +0 -78
  55. package/src/components/form/input/text/textarea.tsx +0 -43
  56. package/src/components/form/input/time/index.tsx +0 -33
  57. package/src/components/form/input/type.ts +0 -0
  58. package/src/components/form/input/types.ts +0 -4
  59. package/src/components/form/view/file.tsx +0 -36
  60. package/src/components/form/view/index.tsx +0 -52
  61. package/src/components/form/view/multipleSelect.tsx +0 -51
  62. package/src/components/form/view/select.tsx +0 -50
  63. package/src/components/form/view/types.ts +0 -11
  64. package/src/components/index.ts +0 -14
  65. package/src/components/list/Body/InfiniteScrollGridBody.tsx +0 -177
  66. package/src/components/list/Body/InfiniteScrollListBody.tsx +0 -114
  67. package/src/components/list/Body/ListBody.tsx +0 -24
  68. package/src/components/list/Body/PagedGridBody.tsx +0 -104
  69. package/src/components/list/Body/PagedListBody.tsx +0 -92
  70. package/src/components/list/Body/hooks.ts +0 -84
  71. package/src/components/list/DataList.tsx +0 -33
  72. package/src/components/list/ListContainer.tsx +0 -21
  73. package/src/components/list/ListContent.tsx +0 -54
  74. package/src/components/list/ListCreate.tsx +0 -57
  75. package/src/components/list/ListFilters.tsx +0 -182
  76. package/src/components/list/ListFooter.tsx +0 -458
  77. package/src/components/list/ListHeader.tsx +0 -180
  78. package/src/components/list/ListItem/ListCell.tsx +0 -49
  79. package/src/components/list/ListItem/ListRow.tsx +0 -44
  80. package/src/components/list/ListItemView.tsx +0 -53
  81. package/src/components/list/ListSort.tsx +0 -84
  82. package/src/components/list/NoItems.tsx +0 -33
  83. package/src/components/list/constants.ts +0 -1
  84. package/src/components/list/index.ts +0 -4
  85. package/src/components/list/types.ts +0 -26
  86. package/src/components/list/utils.ts +0 -63
  87. package/src/components/loading/CircularProgress.tsx +0 -12
  88. package/src/components/loading/Loading.tsx +0 -160
  89. package/src/components/loading/LoadingImage.tsx +0 -128
  90. package/src/components/loading/LoadingSwitch.tsx +0 -78
  91. package/src/components/loading/index.ts +0 -4
  92. package/src/components/media/PlayButton.tsx +0 -95
  93. package/src/components/media/index.ts +0 -1
  94. package/src/components/modal/DefaultModal.tsx +0 -18
  95. package/src/components/modal/DesktopModal.tsx +0 -16
  96. package/src/components/modal/ForceMobile.tsx +0 -7
  97. package/src/components/modal/MobileModal.tsx +0 -89
  98. package/src/components/modal/index.ts +0 -3
  99. package/src/components/modal/type.ts +0 -7
  100. package/src/components/nav/NavBar.tsx +0 -102
  101. package/src/components/nav/index.ts +0 -1
  102. package/src/components/overlay/ImageViewOverlay.tsx +0 -88
  103. package/src/components/overlay/MobileOverlay.tsx +0 -23
  104. package/src/components/overlay/index.ts +0 -2
  105. package/src/components/text/GradientText/index.tsx +0 -17
  106. package/src/components/text/GradientText/styles.css +0 -5
  107. package/src/components/text/NumberTicker.tsx +0 -28
  108. package/src/components/text/index.ts +0 -1
  109. package/src/components/theme/colorMode/DarkModeToggle.tsx +0 -40
  110. package/src/components/theme/colorMode/index.ts +0 -1
  111. package/src/components/theme/index.ts +0 -1
  112. package/src/components/view/ErrorView.tsx +0 -14
  113. package/src/components/view/RedirectView.tsx +0 -43
  114. package/src/components/view/index.ts +0 -2
  115. package/src/contexts/index.ts +0 -2
  116. package/src/contexts/theme.ts +0 -316
  117. package/src/contexts/view.tsx +0 -26
  118. package/src/custom.d.ts +0 -4
  119. package/src/hooks/index.ts +0 -1
  120. package/src/hooks/ui/index.ts +0 -1
  121. package/src/hooks/ui/useBorderColor.ts +0 -4
  122. package/src/index.ts +0 -5
  123. package/src/store/index.ts +0 -1
  124. package/src/store/usePlayer.ts +0 -75
  125. package/src/store/useScreen.ts +0 -22
  126. package/src/types/forms.ts +0 -5
  127. package/src/types/index.ts +0 -1
@@ -1,52 +0,0 @@
1
- import { Flex, Text } from '@chakra-ui/react'
2
-
3
- import { formatField } from '@chem-po/core'
4
- import { Field, FormatField } from '@chem-po/react'
5
- import React, { CSSProperties, useMemo } from 'react'
6
- import { FileFieldView } from './file'
7
- import { MultipleSelectFieldView } from './multipleSelect'
8
- import { SelectFieldView } from './select'
9
- import { FieldViewProps } from './types'
10
-
11
- const DefaultFieldView = <F extends Field>({ field, value, noLabel, style }: FieldViewProps<F>) => {
12
- const { placeholder } = field
13
-
14
- const formatted = useMemo(() => {
15
- const format = formatField[field._type] as FormatField<F>
16
- if (!format) return value
17
- return format(field, value)
18
- }, [value, field])
19
- return (
20
- <Flex align="center" style={style}>
21
- {noLabel ? null : (
22
- <Text pr={2} opacity={0.7} fontWeight={600}>
23
- {placeholder}
24
- </Text>
25
- )}
26
- <Text opacity={value !== undefined && value !== null ? 1 : 0.6}>{formatted ?? 'None'}</Text>
27
- </Flex>
28
- )
29
- }
30
-
31
- export const FieldView = ({
32
- field,
33
- value,
34
- noLabel,
35
- style,
36
- }: {
37
- field: Field
38
- value: any
39
- noLabel?: boolean
40
- style?: CSSProperties
41
- }) => {
42
- switch (field._type) {
43
- case 'select':
44
- return <SelectFieldView style={style} field={field} value={value} noLabel={noLabel} />
45
- case 'multipleSelect':
46
- return <MultipleSelectFieldView style={style} field={field} value={value} noLabel={noLabel} />
47
- case 'file':
48
- return <FileFieldView style={style} field={field} value={value} noLabel={noLabel} />
49
- default:
50
- return <DefaultFieldView style={style} field={field} value={value} noLabel={noLabel} />
51
- }
52
- }
@@ -1,51 +0,0 @@
1
- import { Box, Text } from '@chakra-ui/react'
2
-
3
- import { Flex, useColorMode } from '@chakra-ui/react'
4
- import { MultipleSelectField } from '@chem-po/react'
5
- import React, { useMemo } from 'react'
6
- import { useInputStyles } from '../input/hooks/useInputStyles'
7
- import { getRenderSelectedOptionText } from '../input/multipleSelect'
8
- import { FieldViewProps } from './types'
9
-
10
- export const MultipleSelectFieldView = <F extends MultipleSelectField>({
11
- field,
12
- value,
13
- noLabel,
14
- style,
15
- }: FieldViewProps<F>) => {
16
- const { placeholder, options } = field
17
- const { size, text } = useInputStyles(undefined, field.size)
18
- const selectedOptions = useMemo(
19
- () => options.filter(o => value?.includes(o.value)),
20
- [value, options],
21
- )
22
- const RenderSelectedOptionText = useMemo(
23
- () => getRenderSelectedOptionText(field, text),
24
- [field, text],
25
- )
26
- const { colorMode } = useColorMode()
27
- return (
28
- <Flex maxW="100%" flexFlow="row wrap" align="center" style={style}>
29
- {noLabel ? null : (
30
- <Text pr={2} opacity={0.7} fontWeight={600}>
31
- {placeholder}
32
- </Text>
33
- )}
34
- {selectedOptions.length ? (
35
- selectedOptions.map(o => (
36
- <Box key={o.value} p={0.5}>
37
- <RenderSelectedOptionText
38
- value={o.value}
39
- option={o}
40
- colorMode={colorMode}
41
- isSelected={true}
42
- size={size}
43
- />
44
- </Box>
45
- ))
46
- ) : (
47
- <Text opacity={0.6}>None</Text>
48
- )}
49
- </Flex>
50
- )
51
- }
@@ -1,50 +0,0 @@
1
- import { Flex, Text, useColorMode } from '@chakra-ui/react'
2
- import { SelectField } from '@chem-po/react'
3
- import React from 'react'
4
- import { useInputStyles } from '../input/hooks/useInputStyles'
5
- import { FieldViewProps } from './types'
6
-
7
- const stringifyValue = (value: any) => {
8
- if (typeof value === 'string') return value
9
- if (typeof value === 'number') return value.toString()
10
- if (typeof value === 'boolean') return value.toString()
11
- return JSON.stringify(value)
12
- }
13
- const DefaultRenderOption = (value: any) => {
14
- // TODO: maybe handle non-string values more gracefully
15
- return <Text>{stringifyValue(value)}</Text>
16
- }
17
-
18
- export const SelectFieldView = <F extends SelectField>({
19
- field,
20
- value,
21
- noLabel,
22
- style,
23
- size: propSize,
24
- }: FieldViewProps<F>) => {
25
- const { placeholder, renderOption: customRender } = field
26
- const { colorMode } = useColorMode()
27
- const { size } = useInputStyles(undefined, field.size, propSize)
28
- const selectedOption = field.options.find(o => o.value === value)
29
- const RenderOption = customRender ?? DefaultRenderOption
30
- return (
31
- <Flex align="center" style={style}>
32
- {noLabel ? null : (
33
- <Text pr={2} opacity={0.7} fontWeight={600}>
34
- {placeholder}
35
- </Text>
36
- )}
37
- {value && selectedOption ? (
38
- <RenderOption
39
- value={value}
40
- option={selectedOption}
41
- colorMode={colorMode}
42
- isSelected={true}
43
- size={size}
44
- />
45
- ) : (
46
- <Text>None</Text>
47
- )}
48
- </Flex>
49
- )
50
- }
@@ -1,11 +0,0 @@
1
- import { InputSize } from '@chem-po/core'
2
- import { Field } from '@chem-po/react'
3
- import { CSSProperties } from 'react'
4
-
5
- export interface FieldViewProps<F extends Field> {
6
- field: F
7
- value: F['defaultValue']
8
- noLabel?: boolean
9
- size?: InputSize
10
- style?: CSSProperties
11
- }
@@ -1,14 +0,0 @@
1
- export * from './auth'
2
- export * from './box'
3
- export * from './button'
4
- export * from './feed'
5
- export * from './form'
6
- export * from './list'
7
- export * from './loading'
8
- export * from './media'
9
- export * from './modal'
10
- export * from './nav'
11
- export * from './overlay'
12
- export * from './text'
13
- export * from './theme'
14
- export * from './view'
@@ -1,177 +0,0 @@
1
- import { useColorMode } from '@chakra-ui/react'
2
- import { AnyObject, WithId } from '@chem-po/core'
3
- import { ListGridOptions, useDataList, useFullSize, usePaginatedList } from '@chem-po/react'
4
- import React, { useCallback, useEffect, useMemo, useRef } from 'react'
5
- import {
6
- FixedSizeGrid,
7
- GridOnItemsRenderedProps,
8
- ListOnItemsRenderedProps,
9
- VariableSizeGrid,
10
- } from 'react-window'
11
- import InfiniteLoader from 'react-window-infinite-loader'
12
- import { GridItemProps, ListCell } from '../ListItem/ListCell'
13
- import { ListItemProps } from '../ListItem/ListRow'
14
- import { NoItemsRow } from '../NoItems'
15
- import { getIsDynamicSize } from '../utils'
16
- import { useGridDims } from './hooks'
17
-
18
- export const InfiniteScrollGridBody = <T extends AnyObject>({
19
- height,
20
- options,
21
- }: {
22
- height: number
23
- options: ListGridOptions<T>
24
- }) => {
25
- const {
26
- totalCount,
27
- data: { data: items },
28
- refetchItem,
29
- isItemLoaded,
30
- goNext: fetchMoreData,
31
- } = usePaginatedList<T>()
32
- const { list, onSelectItem, mobileLayout, query } = useDataList<T>()
33
- const { width } = useFullSize()
34
- const { numCols, numRows, rowHeight, colWidth } = useGridDims<T>(options, width)
35
- const { previewHeight, mobile } = list
36
- const { colorMode } = useColorMode()
37
- const itemData = useMemo<GridItemProps<T>>(
38
- () => ({
39
- list,
40
- items,
41
- mobileLayout,
42
- grid: options,
43
- colorMode,
44
- numCols,
45
- onSelect: (item: WithId<T>) => onSelectItem(item.id),
46
- refetch: refetchItem,
47
- }),
48
- [items, list, refetchItem, onSelectItem, mobileLayout, numCols, options, colorMode],
49
- )
50
-
51
- const varRef = useRef<VariableSizeGrid | null>(null)
52
-
53
- const itemHeight = useMemo(
54
- () => (mobileLayout ? (mobile?.previewHeight ?? previewHeight) : previewHeight),
55
- [mobile, previewHeight, mobileLayout],
56
- )
57
-
58
- useEffect(() => {
59
- const varGrid = varRef.current
60
- if (varGrid) {
61
- varGrid.resetAfterColumnIndex(0)
62
- varGrid.resetAfterRowIndex(0)
63
- }
64
- }, [query])
65
-
66
- const infiniteLoaderRef = useRef<InfiniteLoader>(null)
67
- useEffect(() => {
68
- if (infiniteLoaderRef.current) {
69
- infiniteLoaderRef.current.resetloadMoreItemsCache(true)
70
- }
71
- }, [totalCount])
72
-
73
- const isDynamicHeight = useMemo(() => getIsDynamicSize(itemHeight), [itemHeight])
74
-
75
- const itemKey = useCallback(
76
- ({
77
- columnIndex,
78
- rowIndex,
79
- data,
80
- }: {
81
- columnIndex: number
82
- rowIndex: number
83
- data: ListItemProps<T>
84
- }) => {
85
- const index = rowIndex * numCols + columnIndex
86
- return data.items[index]?.id || `${index}`
87
- },
88
- [numCols],
89
- )
90
-
91
- const onRendered = useCallback(
92
- (
93
- {
94
- overscanColumnStartIndex,
95
- overscanColumnStopIndex,
96
- overscanRowStartIndex,
97
- overscanRowStopIndex,
98
- visibleColumnStartIndex,
99
- visibleColumnStopIndex,
100
- visibleRowStartIndex,
101
- visibleRowStopIndex,
102
- }: GridOnItemsRenderedProps,
103
- onItemsRendered: (p: ListOnItemsRenderedProps) => void,
104
- ) => {
105
- const start = visibleRowStartIndex * numCols + visibleColumnStartIndex
106
- const stop = visibleRowStopIndex * numCols + visibleColumnStopIndex
107
- const overscanStart = overscanRowStartIndex * numCols + overscanColumnStartIndex
108
- const overscanStop = overscanRowStopIndex * numCols + overscanColumnStopIndex
109
- onItemsRendered({
110
- overscanStartIndex: overscanStart,
111
- overscanStopIndex: overscanStop,
112
- visibleStartIndex: start,
113
- visibleStopIndex: stop,
114
- })
115
- },
116
- [numCols],
117
- )
118
-
119
- if (!items.length) {
120
- return <NoItemsRow />
121
- }
122
-
123
- return isDynamicHeight ? (
124
- <InfiniteLoader
125
- isItemLoaded={isItemLoaded}
126
- ref={infiniteLoaderRef}
127
- itemCount={totalCount ?? 0}
128
- loadMoreItems={fetchMoreData}>
129
- {({ onItemsRendered, ref }) => (
130
- <VariableSizeGrid<GridItemProps<T>>
131
- height={height}
132
- width={width}
133
- rowCount={numRows}
134
- columnCount={numCols}
135
- rowHeight={rowHeight as (idx: number) => number}
136
- columnWidth={colWidth as (idx: number) => number}
137
- itemData={itemData}
138
- style={{ overflowX: 'hidden' }}
139
- itemKey={itemKey}
140
- onItemsRendered={i => onRendered(i, onItemsRendered)}
141
- ref={r => {
142
- ref(r)
143
- varRef.current = r
144
- }}>
145
- {ListCell}
146
- </VariableSizeGrid>
147
- )}
148
- </InfiniteLoader>
149
- ) : (
150
- <InfiniteLoader
151
- isItemLoaded={isItemLoaded}
152
- itemCount={totalCount ?? 0}
153
- ref={infiniteLoaderRef}
154
- loadMoreItems={fetchMoreData}>
155
- {({ onItemsRendered, ref }) => (
156
- <FixedSizeGrid<GridItemProps<T>>
157
- height={height}
158
- width={width}
159
- rowCount={numRows}
160
- columnCount={numCols}
161
- rowHeight={rowHeight as number}
162
- columnWidth={colWidth as number}
163
- itemData={itemData}
164
- onItemsRendered={i => onRendered(i, onItemsRendered)}
165
- style={{
166
- overflowX: 'hidden',
167
- }}
168
- ref={r => {
169
- ref(r)
170
- varRef.current = null
171
- }}>
172
- {ListCell}
173
- </FixedSizeGrid>
174
- )}
175
- </InfiniteLoader>
176
- )
177
- }
@@ -1,114 +0,0 @@
1
- import { useColorMode } from '@chakra-ui/react'
2
- import { AnyObject, WithId } from '@chem-po/core'
3
- import { useDataList, useFullSize, usePaginatedList } from '@chem-po/react'
4
- import React, { useCallback, useEffect, useMemo, useRef } from 'react'
5
- import { FixedSizeList, VariableSizeGrid, VariableSizeList } from 'react-window'
6
- import InfiniteLoader from 'react-window-infinite-loader'
7
- import { ListItemProps, ListRow } from '../ListItem/ListRow'
8
- import { NoItemsRow } from '../NoItems'
9
- import { getIsDynamicSize } from '../utils'
10
-
11
- export const InfiniteScrollListBody = ({ height }: { height: number }) => {
12
- const {
13
- totalCount,
14
- data: { data: items },
15
- refetchItem,
16
- isItemLoaded,
17
- goNext: fetchMoreData,
18
- } = usePaginatedList()
19
- const { list, onSelectItem, mobileLayout, query } = useDataList()
20
- const { previewHeight, mobile } = list
21
- const { colorMode } = useColorMode()
22
- const { width } = useFullSize()
23
- const itemData = useMemo<ListItemProps>(
24
- () => ({
25
- list,
26
- items,
27
- mobileLayout,
28
- colorMode,
29
- onSelect: (item: WithId<AnyObject>) => onSelectItem(item.id),
30
- refetch: refetchItem,
31
- }),
32
- [items, list, refetchItem, onSelectItem, mobileLayout, colorMode],
33
- )
34
-
35
- const varRef = useRef<VariableSizeGrid | null>(null)
36
- const itemHeight = useMemo(
37
- () => (mobileLayout ? (mobile?.previewHeight ?? previewHeight) : previewHeight),
38
- [mobile, previewHeight, mobileLayout],
39
- )
40
-
41
- const infiniteLoaderRef = useRef<InfiniteLoader>(null)
42
- useEffect(() => {
43
- if (infiniteLoaderRef.current) {
44
- infiniteLoaderRef.current.resetloadMoreItemsCache(true)
45
- }
46
- }, [totalCount])
47
-
48
- useEffect(() => {
49
- const varGrid = varRef.current
50
- if (varGrid) {
51
- varGrid.resetAfterRowIndex(0)
52
- varGrid.resetAfterColumnIndex(0)
53
- }
54
- }, [query])
55
-
56
- const getItemSize = useCallback(
57
- (index: number) => (typeof itemHeight === 'function' ? itemHeight(items[index]) : itemHeight),
58
- [items, itemHeight],
59
- )
60
-
61
- const isDynamicHeight = useMemo(() => getIsDynamicSize(itemHeight), [itemHeight])
62
-
63
- if (!items.length) {
64
- return <NoItemsRow />
65
- }
66
-
67
- return isDynamicHeight ? (
68
- <InfiniteLoader
69
- ref={infiniteLoaderRef}
70
- isItemLoaded={isItemLoaded}
71
- itemCount={totalCount ?? 0}
72
- loadMoreItems={fetchMoreData}>
73
- {({ onItemsRendered, ref }) => (
74
- <VariableSizeList<ListItemProps>
75
- height={height}
76
- width={width}
77
- itemSize={getItemSize}
78
- itemCount={totalCount ?? 0}
79
- itemData={itemData}
80
- style={{ overflowX: 'hidden' }}
81
- itemKey={index => items[index]?.id || `${index}`}
82
- onItemsRendered={i => {
83
- onItemsRendered(i)
84
- }}
85
- ref={ref}>
86
- {ListRow}
87
- </VariableSizeList>
88
- )}
89
- </InfiniteLoader>
90
- ) : (
91
- <InfiniteLoader
92
- ref={infiniteLoaderRef}
93
- isItemLoaded={isItemLoaded}
94
- itemCount={totalCount ?? 0}
95
- loadMoreItems={fetchMoreData}>
96
- {({ onItemsRendered, ref }) => (
97
- <FixedSizeList<ListItemProps>
98
- height={height}
99
- width={width}
100
- itemSize={itemHeight as number}
101
- itemCount={totalCount ?? 0}
102
- itemData={itemData}
103
- itemKey={index => items[index]?.id || `${index}`}
104
- style={{
105
- overflowX: 'hidden',
106
- }}
107
- onItemsRendered={onItemsRendered}
108
- ref={ref}>
109
- {ListRow}
110
- </FixedSizeList>
111
- )}
112
- </InfiniteLoader>
113
- )
114
- }
@@ -1,24 +0,0 @@
1
- import { useDataList } from '@chem-po/react'
2
- import React from 'react'
3
- import { InfiniteScrollGridBody } from './InfiniteScrollGridBody'
4
- import { InfiniteScrollListBody } from './InfiniteScrollListBody'
5
- import { PagedGridBody } from './PagedGridBody'
6
- import { PagedListBody } from './PagedListBody'
7
-
8
- export const ListBody = ({ height }: { height: number }) => {
9
- const { infiniteScroll, gridLayout, list } = useDataList()
10
- const { grid } = list
11
-
12
- if (gridLayout && grid) {
13
- return infiniteScroll ? (
14
- <InfiniteScrollGridBody options={grid} height={height} />
15
- ) : (
16
- <PagedGridBody options={grid} height={height} />
17
- )
18
- }
19
- return infiniteScroll ? (
20
- <InfiniteScrollListBody height={height} />
21
- ) : (
22
- <PagedListBody height={height} />
23
- )
24
- }
@@ -1,104 +0,0 @@
1
- import { useColorMode } from '@chakra-ui/react'
2
- import { AnyObject, BaseComponent, ItemPreviewProps, ListGridOptions } from '@chem-po/core'
3
- import { useDataList, useFullSize, usePaginatedList } from '@chem-po/react'
4
- import React, { memo, useEffect, useMemo, useRef } from 'react'
5
- import { FixedSizeGrid, VariableSizeGrid } from 'react-window'
6
- import { GridItemProps, ListCell } from '../ListItem/ListCell'
7
- import { NoItemsRow } from '../NoItems'
8
- import { getIsDynamicSize } from '../utils'
9
- import { useGridDims } from './hooks'
10
-
11
- const BasePagedGridBody = <
12
- T extends AnyObject,
13
- ItemPreviewComponent extends BaseComponent<ItemPreviewProps<T>>,
14
- >({
15
- height,
16
- options,
17
- }: {
18
- height: number
19
- options: ListGridOptions<T, ItemPreviewComponent>
20
- }) => {
21
- const { list, onSelectItem, mobileLayout, query } = useDataList<T>()
22
- const {
23
- data: { data: items },
24
- pageIndex,
25
- } = usePaginatedList<T>()
26
- const variableRef = useRef<VariableSizeGrid>(null)
27
- const fixedRef = useRef<FixedSizeGrid>(null)
28
- const { width } = useFullSize()
29
- const { numCols, numRows, rowHeight, colWidth } = useGridDims<T>(options, width)
30
- const { colorMode } = useColorMode()
31
- const itemData = useMemo<GridItemProps<T>>(
32
- () => ({
33
- list,
34
- items,
35
- numCols,
36
- onSelect: item => onSelectItem(item.id),
37
- mobileLayout,
38
- colorMode,
39
- grid: options,
40
- }),
41
- [items, list, onSelectItem, mobileLayout, numCols, options, colorMode],
42
- )
43
-
44
- useEffect(() => {
45
- const varGrid = variableRef.current
46
- if (varGrid) {
47
- varGrid.resetAfterColumnIndex(0)
48
- varGrid.resetAfterRowIndex(0)
49
- }
50
- }, [query])
51
-
52
- // scroll to top when page or query changes
53
- useEffect(() => {
54
- const varGrid = variableRef.current
55
- const fixGrid = fixedRef.current
56
- if (varGrid) {
57
- varGrid.scrollTo({ scrollLeft: 0, scrollTop: 0 })
58
- }
59
- if (fixGrid) {
60
- fixGrid.scrollTo({ scrollLeft: 0, scrollTop: 0 })
61
- }
62
- }, [pageIndex, query])
63
-
64
- const isDynamicHeight = useMemo(
65
- () => getIsDynamicSize(options.rowHeight) || getIsDynamicSize(options.columnWidth),
66
- [options],
67
- )
68
-
69
- if (!items.length) return <NoItemsRow />
70
-
71
- return isDynamicHeight ? (
72
- <VariableSizeGrid<GridItemProps<T>>
73
- ref={variableRef}
74
- height={height}
75
- width={width}
76
- rowCount={numRows}
77
- columnCount={numCols}
78
- rowHeight={rowHeight as (idx: number) => number}
79
- columnWidth={colWidth as (idx: number) => number}
80
- itemData={itemData}
81
- style={{
82
- overflowX: 'hidden',
83
- }}>
84
- {ListCell}
85
- </VariableSizeGrid>
86
- ) : (
87
- <FixedSizeGrid<GridItemProps<T>>
88
- height={height}
89
- ref={fixedRef}
90
- width={width}
91
- rowCount={numRows}
92
- columnCount={numCols}
93
- rowHeight={rowHeight as number}
94
- columnWidth={colWidth as number}
95
- itemData={itemData}
96
- style={{
97
- overflowX: 'hidden',
98
- }}>
99
- {ListCell}
100
- </FixedSizeGrid>
101
- )
102
- }
103
-
104
- export const PagedGridBody = memo(BasePagedGridBody) as typeof BasePagedGridBody
@@ -1,92 +0,0 @@
1
- import { useColorMode } from '@chakra-ui/react'
2
- import { useDataList, useFullSize, usePaginatedList } from '@chem-po/react'
3
- import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react'
4
- import { FixedSizeList, VariableSizeList } from 'react-window'
5
- import { ListItemProps, ListRow } from '../ListItem/ListRow'
6
- import { NoItemsRow } from '../NoItems'
7
- import { getIsDynamicSize } from '../utils'
8
-
9
- const BasePagedListBody = ({ height }: { height: number }) => {
10
- const { list, onSelectItem, mobileLayout, query } = useDataList()
11
- const {
12
- data: { data: items },
13
- pageIndex,
14
- } = usePaginatedList()
15
- const { width } = useFullSize()
16
- const { previewHeight, mobile } = list
17
- const varRef = useRef<VariableSizeList>(null)
18
- const fixedRef = useRef<FixedSizeList>(null)
19
- const { colorMode } = useColorMode()
20
- const itemData = useMemo<ListItemProps>(
21
- () => ({
22
- list,
23
- colorMode,
24
- items,
25
- onSelect: item => onSelectItem(item.id),
26
- mobileLayout,
27
- }),
28
- [items, list, onSelectItem, mobileLayout, colorMode],
29
- )
30
-
31
- const itemHeight = useMemo(
32
- () => (mobileLayout ? (mobile?.previewHeight ?? previewHeight) : previewHeight),
33
- [mobile, previewHeight, mobileLayout],
34
- )
35
-
36
- useEffect(() => {
37
- const varList = varRef.current
38
- if (varList) {
39
- varList.resetAfterIndex(0)
40
- }
41
- }, [query])
42
-
43
- // scroll to top when page or query changes
44
- useEffect(() => {
45
- const varList = varRef.current
46
- const fixList = fixedRef.current
47
- if (varList) {
48
- varList.scrollTo(0)
49
- }
50
- if (fixList) {
51
- fixList.scrollTo(0)
52
- }
53
- }, [query, pageIndex])
54
-
55
- const getItemSize = useCallback(
56
- (index: number) => (typeof itemHeight === 'function' ? itemHeight(items[index]) : itemHeight),
57
- [items, itemHeight],
58
- )
59
-
60
- const isDynamicHeight = useMemo(() => getIsDynamicSize(itemHeight), [itemHeight])
61
-
62
- if (!items.length) return <NoItemsRow />
63
- return isDynamicHeight ? (
64
- <FixedSizeList<ListItemProps>
65
- ref={fixedRef}
66
- height={height}
67
- width={width}
68
- itemSize={itemHeight as number}
69
- itemCount={items.length}
70
- itemData={itemData}
71
- style={{
72
- overflowX: 'hidden',
73
- }}>
74
- {ListRow}
75
- </FixedSizeList>
76
- ) : (
77
- <VariableSizeList<ListItemProps>
78
- ref={varRef}
79
- height={height}
80
- width={width}
81
- itemSize={getItemSize}
82
- itemCount={items.length}
83
- itemData={itemData}
84
- style={{
85
- overflowX: 'hidden',
86
- }}>
87
- {ListRow}
88
- </VariableSizeList>
89
- )
90
- }
91
-
92
- export const PagedListBody = memo(BasePagedListBody) as typeof BasePagedListBody