@campxdev/react-blueprint 0.1.17 → 0.1.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/react-blueprint",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "main": "./export.ts",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -2,10 +2,11 @@ import {
2
2
  Box,
3
3
  Autocomplete as MuiAutocomplete,
4
4
  Paper,
5
+ PaperProps,
5
6
  TextField,
6
7
  } from "@mui/material";
7
8
  import axios from "axios";
8
- import { useReducer } from "react";
9
+ import { useReducer, useRef } from "react";
9
10
  import { campxAxios } from "../../../utils/campxAxios";
10
11
  import { Typography } from "../../Typography/Typography";
11
12
  import { LabelWrapper } from "../LabelWrapper/LabelWrapper";
@@ -35,6 +36,7 @@ enum SingleSelectActionsTypes {
35
36
  LOAD_INTERNAL_OPTIONS_END = "load_internal_options_end",
36
37
  SET_NETWORK_ERROR = "set_network_error",
37
38
  SET_INTERNAL_OPTIONS = "set_internal_options",
39
+ APPEND_INTERNAL_OPTIONS = "append_internal_options",
38
40
  }
39
41
  const singleSelectReducer = (
40
42
  state: any,
@@ -66,11 +68,25 @@ const singleSelectReducer = (
66
68
  loadingInternalOptions: false,
67
69
  };
68
70
  }
71
+ case SingleSelectActionsTypes.APPEND_INTERNAL_OPTIONS: {
72
+ return {
73
+ ...state,
74
+ internalOptions: [...state.internalOptions, ...stateChanges.newOptions],
75
+ loadingInternalOptions: false,
76
+ };
77
+ }
69
78
  default:
70
79
  return { ...state, ...stateChanges };
71
80
  }
72
81
  };
73
82
 
83
+ const PaperComponent = (props: PaperProps, loadingInternalOptions: boolean) => (
84
+ <Paper {...props}>
85
+ {props.children}
86
+ <FetchingOptionsLoader loading={loadingInternalOptions} />
87
+ </Paper>
88
+ );
89
+
74
90
  export const SingleSelect = ({
75
91
  options,
76
92
  optionsApiEndPoint,
@@ -84,6 +100,7 @@ export const SingleSelect = ({
84
100
  internalOptions: options ?? [],
85
101
  });
86
102
  const { open, loadingInternalOptions, internalOptions } = state;
103
+ const listboxRef = useRef(null);
87
104
 
88
105
  const internalAxios = useCampxAxios ? campxAxios : axios;
89
106
 
@@ -124,20 +141,37 @@ export const SingleSelect = ({
124
141
  }
125
142
  };
126
143
 
144
+ const handleScroll = async (event: any) => {
145
+ const listboxNode = event.currentTarget;
146
+
147
+ console.log(
148
+ listboxNode.scrollTop + listboxNode.clientHeight,
149
+ listboxNode.scrollHeight
150
+ );
151
+ if (
152
+ listboxNode.scrollTop + listboxNode.clientHeight >=
153
+ listboxNode.scrollHeight - 100
154
+ ) {
155
+ console.log("dispatched");
156
+ dispatch({
157
+ actionType: SingleSelectActionsTypes.APPEND_INTERNAL_OPTIONS,
158
+ stateChanges: {
159
+ newOptions: internalOptions,
160
+ },
161
+ });
162
+ }
163
+ };
164
+
127
165
  return (
128
166
  <MuiAutocomplete
129
167
  open={open}
168
+ autoHighlight={true}
130
169
  renderInput={(params) => (
131
170
  <LabelWrapper label={label} required={required}>
132
171
  <TextField {...params} />
133
172
  </LabelWrapper>
134
173
  )}
135
- PaperComponent={(props) => (
136
- <Paper {...props}>
137
- {props.children}
138
- <FetchingOptionsLoader loading={loadingInternalOptions} />
139
- </Paper>
140
- )}
174
+ PaperComponent={(props) => PaperComponent(props, loadingInternalOptions)}
141
175
  renderOption={(props, option: any) => {
142
176
  return (
143
177
  <Box component="li" {...props}>
@@ -148,6 +182,10 @@ export const SingleSelect = ({
148
182
  </Box>
149
183
  );
150
184
  }}
185
+ ListboxProps={{
186
+ onScroll: handleScroll,
187
+ ref: listboxRef,
188
+ }}
151
189
  onOpen={handleOpen}
152
190
  onClose={() => {
153
191
  dispatch({
package/types/theme.d.ts CHANGED
@@ -25,9 +25,51 @@ declare module "@mui/material/styles" {
25
25
  main: string;
26
26
  };
27
27
  grey: {
28
- main: string,
29
- }
28
+ main: string;
29
+ };
30
+ };
31
+ }
32
+ interface CustomThemeOptions extends MuiThemeOptions {
33
+ borders: {
34
+ grayLight: string;
35
+ primary: string;
36
+ };
37
+ palette: {
38
+ secondary?: {
39
+ main?: string;
40
+ light?: string;
41
+ dark?: string;
42
+ };
43
+ primary?: {
44
+ dark?: string;
45
+ main?: string;
46
+ light?: string;
47
+ lighter?: string;
48
+ };
49
+ common?: {
50
+ black?: string;
51
+ white?: string;
52
+ green?: string;
53
+ yellow?: string;
54
+ blue?: string;
55
+ };
56
+ highlight: {
57
+ main: string;
58
+ };
59
+ grey: {
60
+ main: string;
61
+ };
62
+ error?: {
63
+ main?: string;
64
+ };
65
+ text?: {
66
+ primary?: string;
67
+ secondary?: string;
68
+ disabled?: string;
69
+ };
30
70
  };
71
+ components?: Components<Omit<Theme, "components">>;
72
+ typography?: TypographyOptions | ((palette: Palette) => TypographyOptions);
31
73
  }
32
74
  export function createTheme(options?: CustomThemeOptions): CustomTheme;
33
75
  }