Download react-page/packages/editor/src/ui/uniform-mui/DateField.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-page/packages/editor/src/ui/uniform-mui/DateField.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-page/packages/editor/src/ui/uniform-mui/DateField.tsx
-
curl -L -o DateField.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-page/packages/editor/src/ui/uniform-mui/DateField.tsx
1.79 kB
| import type { TextFieldProps } from '@mui/material/TextField'; | |
| import TextField from '@mui/material/TextField'; | |
| import React from 'react'; | |
| import type { FieldProps } from 'uniforms'; | |
| import { connectField, filterDOMProps } from 'uniforms'; | |
| /* istanbul ignore next */ | |
| const DateConstructor = (typeof global === 'object' ? global : window).Date; | |
| const dateFormat = (value?: Date) => value && value.toISOString().slice(0, -8); | |
| const dateParse = (timestamp: number, onChange: DateFieldProps['onChange']) => { | |
| const date = new DateConstructor(timestamp); | |
| if (date.getFullYear() < 10000) { | |
| onChange(date); | |
| } else if (isNaN(timestamp)) { | |
| onChange(undefined); | |
| } | |
| }; | |
| export type DateFieldProps = FieldProps< | |
| Date, | |
| TextFieldProps, | |
| { labelProps?: Record<string, string> } | |
| >; | |
| function Date({ | |
| disabled, | |
| error, | |
| errorMessage, | |
| helperText, | |
| InputLabelProps, | |
| inputRef, | |
| label, | |
| labelProps, | |
| name, | |
| onChange, | |
| placeholder, | |
| readOnly, | |
| showInlineError, | |
| value, | |
| ...props | |
| }: DateFieldProps) { | |
| return ( | |
| <TextField | |
| disabled={disabled} | |
| error={!!error} | |
| fullWidth | |
| helperText={(error && showInlineError && errorMessage) || helperText} | |
| label={label} | |
| InputLabelProps={{ shrink: true, ...labelProps, ...InputLabelProps }} | |
| inputProps={{ readOnly, ...props.inputProps }} | |
| margin="dense" | |
| name={name} | |
| onChange={(event) => | |
| // FIXME: `valueAsNumber` is not available in `EventTarget`. | |
| disabled || dateParse((event.target as any).valueAsNumber, onChange) | |
| } | |
| placeholder={placeholder} | |
| ref={inputRef} | |
| type="datetime-local" | |
| value={dateFormat(value) ?? ''} | |
| {...filterDOMProps(props)} | |
| /> | |
| ); | |
| } | |
| export default connectField<DateFieldProps>(Date, { kind: 'leaf' }); | |