1
1
import * as React from "react" ;
2
2
3
- import TextField from "@mui/material/TextField " ;
4
- import Autocomplete from "@mui/material/Autocomplete " ;
5
- import InputAdornment from "@mui/material/InputAdornment " ;
3
+ import { ActionButton , IChooseSlot , IField , useAsyncValue , useOnePayload , useOneState , useSinglerunAction } from "react-declarative " ;
4
+ import { MANTINE_CONFIG } from "../../config " ;
5
+ import { TextInput } from "@mantine/core " ;
6
6
7
- import { ActionButton , IChooseSlot , IField , useAsyncValue , useOnePayload , useOneState , useReloadTrigger , useSinglerunAction } from "react-declarative" ;
8
-
9
- const EMPTY_ARRAY : any [ ] = [ ] ;
7
+ const LOADING_LABEL = "Loading" ;
10
8
11
9
/**
12
10
* Retrieves the processed input value based on the provided parameters.
@@ -59,10 +57,8 @@ export const Choose = ({
59
57
disabled,
60
58
readonly,
61
59
description = "" ,
62
- outlined = false ,
63
60
title = "" ,
64
61
placeholder = "Not chosen" ,
65
- labelShrink = true ,
66
62
dirty,
67
63
loading : upperLoading ,
68
64
inputRef,
@@ -73,14 +69,12 @@ export const Choose = ({
73
69
const payload = useOnePayload ( ) ;
74
70
const { object } = useOneState ( ) ;
75
71
76
- const { doReload, reloadTrigger } = useReloadTrigger ( ) ;
77
-
78
72
/**
79
73
* Represents the value of an input.
80
74
*
81
75
* @typedef inputValue
82
76
*/
83
- const [ inputValue , { loading : currentLoading } ] = useAsyncValue (
77
+ const [ inputValue , { loading : currentLoading } ] = useAsyncValue (
84
78
async ( ) => {
85
79
return await getInputValue ( value , tr , object , payload ) ;
86
80
} ,
@@ -95,7 +89,7 @@ export const Choose = ({
95
89
* @param event - The click event object.
96
90
* @returns
97
91
*/
98
- const { execute : handleClick , loading : chooseLoading } = useSinglerunAction (
92
+ const { execute : handleClick , loading : chooseLoading } = useSinglerunAction (
99
93
async ( ) => {
100
94
if ( value ) {
101
95
onChange ( null ) ;
@@ -115,79 +109,45 @@ export const Choose = ({
115
109
const loading = upperLoading || currentLoading || chooseLoading ;
116
110
117
111
return (
118
- < Autocomplete
119
- key = { `${ reloadTrigger } -${ inputValue } ` }
120
- fullWidth
121
- multiple = { Array . isArray ( inputValue ) }
122
- disableClearable
123
- disabled = { disabled }
124
- loading = { loading }
125
- value = { inputValue || null }
126
- options = { EMPTY_ARRAY }
127
- onChange = { ( ) => null }
128
- freeSolo
112
+ < TextInput
113
+ { ...MANTINE_CONFIG }
129
114
readOnly
130
- renderInput = { ( params ) => (
131
- < TextField
132
- { ...params }
133
- value = { params . inputProps . value }
134
- variant = { outlined ? "outlined" : "standard" }
135
- helperText = { ( dirty && ( invalid || incorrect ) ) || description }
136
- error = { dirty && ( invalid !== null || incorrect !== null ) }
115
+ ref = { inputRef }
116
+ label = { title }
117
+ error = { ( dirty && ( invalid || incorrect ) ) }
118
+ description = { description }
119
+ rightSection = { (
120
+ < ActionButton
137
121
sx = { {
138
- flex : 1 ,
139
- ...( ! outlined && {
140
- position : "relative" ,
141
- mt : 1 ,
142
- "& .MuiFormHelperText-root" : {
143
- position : "absolute" ,
144
- top : "100%" ,
145
- } ,
146
- } ) ,
122
+ pointerEvents : readonly ? "none" : "all" ,
123
+ mr : 1 ,
147
124
} }
148
- inputRef = { inputRef }
149
- onClick = { ( e ) => {
150
- e . currentTarget ?. blur ( ) ;
151
- if ( ! value ) {
152
- handleClick ( ) ;
153
- }
154
- doReload ( ) ;
125
+ disabled = { loading || disabled }
126
+ variant = "outlined"
127
+ size = "small"
128
+ color = { value ? "secondary" : "primary" }
129
+ onClick = { async ( ) => {
130
+ await handleClick ( ) ;
155
131
} }
156
- InputProps = { {
157
- ...params . InputProps ,
158
- readOnly : true ,
159
- placeholder,
160
- endAdornment : loading ? (
161
- params . InputProps . endAdornment
162
- ) : (
163
- < InputAdornment sx = { { position : "relative" } } position = "end" >
164
- < ActionButton
165
- sx = { {
166
- pointerEvents : readonly ? "none" : "all" ,
167
- mb : outlined ? undefined : 0.5 ,
168
- } }
169
- disabled = { loading || disabled }
170
- variant = "outlined"
171
- size = "small"
172
- color = { value ? "secondary" : "primary" }
173
- onClick = { async ( ) => {
174
- await handleClick ( ) ;
175
- } }
176
- >
177
- { value && "Deselect" }
178
- { ! value && "Choose" }
179
- </ ActionButton >
180
- </ InputAdornment >
181
- ) ,
182
- } }
183
- InputLabelProps = { {
184
- ...params . InputLabelProps ,
185
- shrink : labelShrink || undefined ,
186
- } }
187
- placeholder = { placeholder }
188
- label = { title }
189
- />
132
+ >
133
+ { value && "Deselect" }
134
+ { ! value && "Choose" }
135
+ </ ActionButton >
190
136
) }
137
+ rightSectionProps = { {
138
+ style : {
139
+ width : 'auto' ,
140
+ }
141
+ } }
142
+ value = { loading ? LOADING_LABEL : String ( inputValue || "" ) }
143
+ placeholder = { placeholder }
144
+ onClick = { ( e ) => {
145
+ e . currentTarget ?. blur ( ) ;
146
+ if ( ! value ) {
147
+ handleClick ( ) ;
148
+ }
149
+ } }
150
+ disabled = { disabled }
191
151
/>
192
152
) ;
193
153
} ;
0 commit comments