25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

187 satır
5.9 KiB

  1. import {
  2. Grid, TextField, Stack
  3. } from '@mui/material';
  4. import Combo from "./Combo";
  5. export const notNullFieldLabel = (label) => {
  6. return (<>{label}<span style={{ "color": "red" }}>*</span></>)
  7. }
  8. export const getDateField = ({ label, valueName, form, disabled }) => {
  9. return <Grid container alignItems={"center"}>
  10. <Grid item xs={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  11. {label}
  12. </Grid>
  13. <Grid item xs={12} md={6} lg={6}>
  14. {initField({
  15. type: "date",
  16. valueName: valueName,
  17. form: form,
  18. disabled: disabled
  19. })}
  20. </Grid>
  21. </Grid>;
  22. }
  23. export const getTextField = ({ label, valueName, form, disabled }) => {
  24. return <Grid container alignItems={"center"}>
  25. <Grid item xs={12} md={3} lg={3}
  26. sx={{ display: 'flex', alignItems: 'center' }}>
  27. {label}
  28. </Grid>
  29. <Grid item xs={12} md={6} lg={6}>
  30. {initField({
  31. type: "text",
  32. valueName: valueName,
  33. form: form,
  34. disabled: disabled
  35. })}
  36. </Grid>
  37. </Grid>;
  38. }
  39. export const getTextArea = ({ label, valueName, form, disabled, inputProps, ...props }) => {
  40. return <Grid container alignItems={"center"}>
  41. <Grid item xs={12} md={3} lg={3}
  42. sx={{ display: 'flex', alignItems: 'center' }}>
  43. {label}
  44. </Grid>
  45. <Grid item xs={12} md={6} lg={6}>
  46. {initField({
  47. type: "text",
  48. valueName: valueName,
  49. form: form,
  50. disabled: disabled,
  51. multiline: true,
  52. row: 10,
  53. minRows: 4,
  54. maxRows: 4,
  55. inputProps: inputProps,
  56. props
  57. })}
  58. </Grid>
  59. </Grid>;
  60. }
  61. export const getPhoneField = ({ label, valueName, form, disabled }) => {
  62. form.handleChange = (event) => {
  63. const value = event.target.value;
  64. const name = event.target.name;
  65. if (value.match(/[^0-9]/)) {
  66. return event.preventDefault();
  67. }
  68. if (valueName.code === name) form.setFieldValue(valueName.code, value)
  69. if (valueName.num === name) form.setFieldValue(valueName.num, value)
  70. }
  71. return <Grid container alignItems={"center"}>
  72. <Grid item xs={12} md={3} lg={3}
  73. sx={{ display: 'flex', alignItems: 'center' }}>
  74. {label}
  75. </Grid>
  76. <Grid item xs={12} md={6} lg={6}>
  77. <Stack direction="row">
  78. {initField({
  79. type: "tel",
  80. valueName: valueName.code,
  81. form: form,
  82. disabled: disabled,
  83. width: '25%'
  84. })}
  85. {initField({
  86. type: "tel",
  87. valueName: valueName.num,
  88. form: form,
  89. disabled: disabled
  90. })}
  91. </Stack>
  92. </Grid>
  93. </Grid>;
  94. }
  95. export const getAddressField = ({ label, valueName, form, disabled }) => {
  96. return <Grid container alignItems={"top"}>
  97. <Grid item xs={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'top' }}>
  98. <Grid item lg={12} sx={{ alignItems: 'center' }}>{label}</Grid>
  99. </Grid>
  100. <Grid item xs={12} md={6} lg={6}>
  101. <Grid item lg={12}>
  102. {initField({
  103. type: "text",
  104. valueName: valueName[0],
  105. form: form,
  106. disabled: disabled
  107. })}
  108. </Grid>
  109. <Grid item lg={12}>
  110. {initField({
  111. type: "text",
  112. valueName: valueName[1],
  113. form: form,
  114. disabled: disabled
  115. })}
  116. </Grid>
  117. <Grid item lg={12}>
  118. {initField({
  119. type: "text",
  120. valueName: valueName[2],
  121. form: form,
  122. disabled: disabled
  123. })}
  124. </Grid>
  125. </Grid>
  126. </Grid>;
  127. }
  128. export const getComboField = ({ label, dataList, valueName, form, disabled, getOptionLabel, onInputChange, onChange, filterOptions, ...props }) => {
  129. return <Grid container alignItems={"center"}>
  130. <Grid item xs={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  131. {label}
  132. </Grid>
  133. <Grid item xs={12} md={6} lg={6}>
  134. <Combo
  135. valueName={valueName}
  136. disabled={disabled}
  137. dataList={dataList}
  138. form={form}
  139. filterOptions={filterOptions}
  140. getOptionLabel={getOptionLabel}
  141. onInputChange={onInputChange}
  142. onChange={onChange}
  143. {...props}
  144. />
  145. </Grid>
  146. </Grid>;
  147. }
  148. export const initField = ({ type, valueName, form, disabled, multiline, placeholder, inputProps, width, ...props }) => {
  149. let err = Boolean(form.errors[valueName]);
  150. return <TextField
  151. fullWidth
  152. multiline={multiline}
  153. id={valueName}
  154. name={valueName}
  155. type={type}
  156. placeholder={placeholder}
  157. inputProps={inputProps}
  158. error={err}
  159. helperText={form.errors[valueName] ? form.errors[valueName] : ''}
  160. onChange={form.handleChange}
  161. value={form.values[valueName]}
  162. disabled={disabled}
  163. sx={{
  164. "& .MuiInputBase-input.Mui-disabled": {
  165. WebkitTextFillColor: "#000000",
  166. background: "#f8f8f8",
  167. },
  168. width: width ? width : '100%'
  169. }}
  170. {...props}
  171. />
  172. }