@wavv/ui 2.3.2 → 2.3.3

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.
@@ -1,10 +1,10 @@
1
- import type { ReactNode } from 'react';
2
- import { type DropZoneProps } from 'react-aria-components';
1
+ import { type DropZoneProps, type FileTriggerProps } from 'react-aria-components';
3
2
  import type { MarginPadding, WidthHeight } from './types';
4
3
  type Props = {
5
- children?: ReactNode;
6
4
  /** The label to display inside the drop zone */
7
5
  label?: string;
6
+ /** Whether to show the file names in the drop zone */
7
+ showFileNames?: boolean;
8
8
  /** Whether the drop target is disabled. If true, the drop target will not accept any drops. */
9
9
  disabled?: DropZoneProps['isDisabled'];
10
10
  className?: DropZoneProps['className'];
@@ -18,6 +18,11 @@ type Props = {
18
18
  onHoverChange?: DropZoneProps['onHoverChange'];
19
19
  onHoverStart?: DropZoneProps['onHoverStart'];
20
20
  onHoverEnd?: DropZoneProps['onHoverEnd'];
21
- } & MarginPadding & WidthHeight & Omit<DropZoneProps, 'isDisabled' | 'children'>;
22
- declare const DropZone: ({ children, label, disabled, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
21
+ acceptedFileTypes?: FileTriggerProps['acceptedFileTypes'];
22
+ allowsMultiple?: FileTriggerProps['allowsMultiple'];
23
+ defaultCamera?: FileTriggerProps['defaultCamera'];
24
+ acceptDirectory?: FileTriggerProps['acceptDirectory'];
25
+ onSelect?: FileTriggerProps['onSelect'];
26
+ } & MarginPadding & WidthHeight & Omit<DropZoneProps, 'isDisabled' | 'children'> & Omit<FileTriggerProps, 'children'>;
27
+ declare const DropZone: ({ label, showFileNames, disabled, acceptedFileTypes, allowsMultiple, defaultCamera, acceptDirectory, onDrop, onSelect, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
23
28
  export default DropZone;
@@ -1,18 +1,57 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import styled from "@emotion/styled";
3
+ import { useState } from "react";
3
4
  import { DropZone, Text } from "react-aria-components";
5
+ import matchesFileTypes from "../utils/matchesFileTypes.js";
6
+ import Ellipsis from "./Ellipsis.js";
7
+ import FileTrigger from "./FileTrigger.js";
4
8
  import { marginProps, paddingProps, widthHeightProps } from "./helpers/styledProps.js";
5
- const DropZone_DropZone = ({ children, label = 'Drop here', disabled, ...rest })=>/*#__PURE__*/ jsxs(StyledDropZone, {
9
+ const DropZone_DropZone = ({ label = 'Drop here', showFileNames = true, disabled, acceptedFileTypes, allowsMultiple, defaultCamera, acceptDirectory, onDrop, onSelect, ...rest })=>{
10
+ const [displayFiles, setDisplayFiles] = useState('');
11
+ const showFileTrigger = !!acceptedFileTypes || !!allowsMultiple || !!defaultCamera || !!acceptDirectory || !!onSelect || showFileNames;
12
+ const handleFileDrop = (event)=>{
13
+ let files = event.items.filter((file)=>'file' === file.kind);
14
+ if (acceptedFileTypes && acceptedFileTypes.length > 0) files = files.filter((file)=>matchesFileTypes(file, acceptedFileTypes));
15
+ if (!allowsMultiple && files.length > 1) files = files.slice(0, 1);
16
+ const fileNames = files.map(({ name })=>name).join(', ');
17
+ setDisplayFiles(fileNames);
18
+ if (onDrop) onDrop(event);
19
+ };
20
+ const handleFileSelect = (selected)=>{
21
+ if (!selected) return;
22
+ const files = Array.from(selected);
23
+ const fileNames = files.map(({ name })=>name).join(', ');
24
+ setDisplayFiles(fileNames);
25
+ if (onSelect) onSelect(selected);
26
+ };
27
+ return /*#__PURE__*/ jsxs(StyledDropZone, {
6
28
  isDisabled: disabled,
29
+ onDrop: showFileTrigger ? handleFileDrop : onDrop,
7
30
  ...rest,
8
31
  children: [
9
32
  /*#__PURE__*/ jsx(StyledText, {
10
33
  slot: "label",
11
34
  children: label
12
35
  }),
13
- children
36
+ showFileTrigger && /*#__PURE__*/ jsx(SeparatorText, {
37
+ children: "or"
38
+ }),
39
+ showFileTrigger && /*#__PURE__*/ jsx(FileTrigger, {
40
+ acceptedFileTypes: acceptedFileTypes,
41
+ allowsMultiple: allowsMultiple,
42
+ defaultCamera: defaultCamera,
43
+ acceptDirectory: acceptDirectory,
44
+ onSelect: handleFileSelect
45
+ }),
46
+ displayFiles && showFileNames && /*#__PURE__*/ jsx(FilesContainer, {
47
+ title: displayFiles,
48
+ children: /*#__PURE__*/ jsx(Ellipsis, {
49
+ children: displayFiles
50
+ })
51
+ })
14
52
  ]
15
53
  });
54
+ };
16
55
  const StyledDropZone = styled(DropZone)(({ theme })=>({
17
56
  display: 'flex',
18
57
  flexDirection: 'column',
@@ -47,7 +86,22 @@ const StyledDropZone = styled(DropZone)(({ theme })=>({
47
86
  }), widthHeightProps, marginProps, paddingProps);
48
87
  const StyledText = styled(Text)(({ theme })=>({
49
88
  fontSize: theme.font.size.md,
50
- fontWeight: theme.font.weight.medium
89
+ fontWeight: theme.font.weight.medium,
90
+ lineHeight: '14px',
91
+ textAlign: 'center'
92
+ }));
93
+ const SeparatorText = styled(Text)(({ theme })=>({
94
+ fontSize: theme.font.size.md,
95
+ color: theme.scale6,
96
+ lineHeight: '14px'
97
+ }));
98
+ const FilesContainer = styled.div(({ theme })=>({
99
+ display: 'flex',
100
+ alignItems: 'center',
101
+ justifyContent: 'center',
102
+ fontSize: theme.font.size.sm,
103
+ color: theme.scale6,
104
+ width: '100%'
51
105
  }));
52
106
  const components_DropZone = DropZone_DropZone;
53
107
  export { components_DropZone as default };
package/build/index.d.ts CHANGED
@@ -90,3 +90,4 @@ export { default as formatDate } from './utils/formatDate';
90
90
  export { default as formatNumber } from './utils/formatNumber';
91
91
  export { default as numberWithCommas } from './utils/numberWithCommas';
92
92
  export { createEditorContent, editorContentToText } from './components/Editor';
93
+ export { default as matchesFileTypes } from './utils/matchesFileTypes';
package/build/index.js CHANGED
@@ -79,4 +79,5 @@ import copyToClipboard from "./utils/copyToClipboard.js";
79
79
  import formatDate from "./utils/formatDate.js";
80
80
  import formatNumber from "./utils/formatNumber.js";
81
81
  import numberWithCommas from "./utils/numberWithCommas.js";
82
- export { Accordion, Audio, BarChart, Button, Calendar, Checkbox, Code, ComboBox, CommandMenu, DatePicker, DateRangePicker, DateRangeSelect, DocTable, Dot, DraftEditor, DropZone, Dropdown, DropdownMenu, DropdownSelect, Editor, Ellipsis, FileTrigger, Form, Grid, Icon, ImageViewer, InlineCode, InlineInput, InputHelpers as InputUtils, Label, LineChart, Menu, Message, MessageHr, Modal, MultiSelect, NumberInput, Pagination, PhoneInput, PieChart, Popover, PortalScope, Progress, Radio, RangeCalendar, ResetStyles, ScrollbarStyles, SearchInput, Select, Slider, Spinner, Table, Tabs, Tag, TextArea, TextInput, TimeInput, ToastStyles, Toggle, ToggleButton, ToggleButtonGroup, Tooltip, TransferList, Tree, UnstyledButton, colors, copyToClipboard, createEditorContent, darkScale, editorContentToText, formatDate, formatNumber, lightScale, marginProps, numberWithCommas, paddingProps, positionProps, theme, themeClasses, themeOptions, useConfirm, useCopy, useElementObserver, useEventListener, useOnClickOutside, usePrevious, useSelectAll, useWindowSize, widthHeightProps };
82
+ import matchesFileTypes from "./utils/matchesFileTypes.js";
83
+ export { Accordion, Audio, BarChart, Button, Calendar, Checkbox, Code, ComboBox, CommandMenu, DatePicker, DateRangePicker, DateRangeSelect, DocTable, Dot, DraftEditor, DropZone, Dropdown, DropdownMenu, DropdownSelect, Editor, Ellipsis, FileTrigger, Form, Grid, Icon, ImageViewer, InlineCode, InlineInput, InputHelpers as InputUtils, Label, LineChart, Menu, Message, MessageHr, Modal, MultiSelect, NumberInput, Pagination, PhoneInput, PieChart, Popover, PortalScope, Progress, Radio, RangeCalendar, ResetStyles, ScrollbarStyles, SearchInput, Select, Slider, Spinner, Table, Tabs, Tag, TextArea, TextInput, TimeInput, ToastStyles, Toggle, ToggleButton, ToggleButtonGroup, Tooltip, TransferList, Tree, UnstyledButton, colors, copyToClipboard, createEditorContent, darkScale, editorContentToText, formatDate, formatNumber, lightScale, marginProps, matchesFileTypes, numberWithCommas, paddingProps, positionProps, theme, themeClasses, themeOptions, useConfirm, useCopy, useElementObserver, useEventListener, useOnClickOutside, usePrevious, useSelectAll, useWindowSize, widthHeightProps };
@@ -0,0 +1,9 @@
1
+ import type { FileDropItem } from 'react-aria';
2
+ /**
3
+ * Checks if a file matches any of the accepted file types
4
+ * @param file - The file to check
5
+ * @param acceptedFileTypes - The accepted file types
6
+ * @returns True if the file matches any of the accepted file types, false otherwise
7
+ */
8
+ declare const matchesFileTypes: (file: FileDropItem, acceptedFileTypes?: readonly string[]) => boolean;
9
+ export default matchesFileTypes;
@@ -0,0 +1,16 @@
1
+ const matchesFileTypes = (file, acceptedFileTypes)=>{
2
+ if (!acceptedFileTypes || 0 === acceptedFileTypes.length) return true;
3
+ const fileType = file.type || '';
4
+ const fileName = file.name || '';
5
+ return acceptedFileTypes.some((acceptedType)=>{
6
+ if (acceptedType === fileType) return true;
7
+ if (acceptedType.endsWith('/*')) {
8
+ const baseType = acceptedType.slice(0, -2);
9
+ return fileType.startsWith(`${baseType}/`);
10
+ }
11
+ if (acceptedType.startsWith('.')) return fileName.toLowerCase().endsWith(acceptedType.toLowerCase());
12
+ return false;
13
+ });
14
+ };
15
+ const utils_matchesFileTypes = matchesFileTypes;
16
+ export { utils_matchesFileTypes as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavv/ui",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {