MCPcopy Create free account
hub / github.com/dailydotdev/apps / DragDropComponent

Function DragDropComponent

packages/shared/src/components/fields/DragDrop.tsx:142–328  ·  view source on GitHub ↗
({
  onFilesDrop,
  validation = {},
  errorMessages = {},
  disabled = false,
  className,
  state,
  inputRef,
  isCompactList,
  ctaSize,
  renderCta,
  isCopyBold,
  dragDropDescription = 'Drag & Drop your CV or',
  ctaLabelDesktop = 'Upload CV',
  ctaLabelMobile = 'Upload CV',
  uploadIcon,
  showRemove,
  fullClick = false,
}: DragDropProps)

Source from the content-addressed store, hash-verified

140 'relative flex flex-1 rounded-10 border border-dashed border-border-subtlest-secondary';
141
142function DragDropComponent({
143 onFilesDrop,
144 validation = {},
145 errorMessages = {},
146 disabled = false,
147 className,
148 state,
149 inputRef,
150 isCompactList,
151 ctaSize,
152 renderCta,
153 isCopyBold,
154 dragDropDescription = 'Drag & Drop your CV or',
155 ctaLabelDesktop = 'Upload CV',
156 ctaLabelMobile = 'Upload CV',
157 uploadIcon,
158 showRemove,
159 fullClick = false,
160}: DragDropProps): ReactElement {
161 const [filenames, setFilenames] = useState<string[]>([]);
162 const isLaptop = useViewSize(ViewSize.Laptop);
163 const { displayToast } = useToastNotification();
164 const isError = state === 'error';
165
166 const { validateFiles } = useFileValidation(validation, errorMessages);
167
168 const handleFiles = (files: FileList | null) => {
169 if (!files || files.length === 0) {
170 return;
171 }
172
173 const { validFiles, errors } = validateFiles(files);
174
175 if (errors.length > 0) {
176 const first = errors[0];
177 const fileName = first.file ? ` (${first.file.name})` : '';
178 displayToast(`${first.message}${fileName}`);
179 return;
180 }
181
182 setFilenames(validFiles.map((f) => f.name));
183 onFilesDrop(validFiles, errors.length > 0 ? errors : undefined);
184 };
185
186 const { input, openFileInput } = useFileInput({
187 inputRef,
188 onFiles: handleFiles,
189 accept: validation.acceptedTypes,
190 multiple: validation.multiple,
191 disabled,
192 });
193
194 const {
195 isDragOver,
196 isDragValid,
197 handleDragEnter,
198 handleDragOver,
199 handleDragLeave,

Callers

nothing calls this directly

Calls 6

useViewSizeFunction · 0.90
useToastNotificationFunction · 0.90
useFileValidationFunction · 0.90
useFileInputFunction · 0.90
useDragAndDropFunction · 0.90
removeFileFunction · 0.85

Tested by

no test coverage detected