@wavv/ui 2.3.1 → 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.
@@ -0,0 +1,28 @@
1
+ import { type DropZoneProps, type FileTriggerProps } from 'react-aria-components';
2
+ import type { MarginPadding, WidthHeight } from './types';
3
+ type Props = {
4
+ /** The label to display inside the drop zone */
5
+ label?: string;
6
+ /** Whether to show the file names in the drop zone */
7
+ showFileNames?: boolean;
8
+ /** Whether the drop target is disabled. If true, the drop target will not accept any drops. */
9
+ disabled?: DropZoneProps['isDisabled'];
10
+ className?: DropZoneProps['className'];
11
+ style?: DropZoneProps['style'];
12
+ onDrop?: DropZoneProps['onDrop'];
13
+ onDropEnter?: DropZoneProps['onDropEnter'];
14
+ onDropMove?: DropZoneProps['onDropMove'];
15
+ onDropExit?: DropZoneProps['onDropExit'];
16
+ onDropActivate?: DropZoneProps['onDropActivate'];
17
+ getDropOperation?: DropZoneProps['getDropOperation'];
18
+ onHoverChange?: DropZoneProps['onHoverChange'];
19
+ onHoverStart?: DropZoneProps['onHoverStart'];
20
+ onHoverEnd?: DropZoneProps['onHoverEnd'];
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;
28
+ export default DropZone;
@@ -0,0 +1,107 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import styled from "@emotion/styled";
3
+ import { useState } from "react";
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";
8
+ import { marginProps, paddingProps, widthHeightProps } from "./helpers/styledProps.js";
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, {
28
+ isDisabled: disabled,
29
+ onDrop: showFileTrigger ? handleFileDrop : onDrop,
30
+ ...rest,
31
+ children: [
32
+ /*#__PURE__*/ jsx(StyledText, {
33
+ slot: "label",
34
+ children: label
35
+ }),
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
+ })
52
+ ]
53
+ });
54
+ };
55
+ const StyledDropZone = styled(DropZone)(({ theme })=>({
56
+ display: 'flex',
57
+ flexDirection: 'column',
58
+ alignItems: 'center',
59
+ justifyContent: 'center',
60
+ gap: theme.size.sm,
61
+ padding: theme.size.md,
62
+ border: `1px dashed ${theme.scale4}`,
63
+ borderRadius: 8,
64
+ backgroundColor: 'transparent',
65
+ outline: 'none',
66
+ color: theme.scale10,
67
+ transition: 'background-color 0.2s ease, border-color 0.2s ease',
68
+ '&[data-focus-visible]': {
69
+ outline: `${theme.accent} solid 2px`,
70
+ outlineOffset: -1
71
+ },
72
+ '&[data-drop-target]': {
73
+ backgroundColor: theme.scale1,
74
+ borderColor: theme.color.brand
75
+ },
76
+ '&[data-disabled]': {
77
+ cursor: 'not-allowed',
78
+ backgroundColor: theme.scale0,
79
+ borderColor: theme.scale4,
80
+ opacity: 0.4,
81
+ userSelect: 'none',
82
+ '& > *': {
83
+ pointerEvents: 'none'
84
+ }
85
+ }
86
+ }), widthHeightProps, marginProps, paddingProps);
87
+ const StyledText = styled(Text)(({ theme })=>({
88
+ fontSize: theme.font.size.md,
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%'
105
+ }));
106
+ const components_DropZone = DropZone_DropZone;
107
+ export { components_DropZone as default };
@@ -0,0 +1,11 @@
1
+ import { type FileTriggerProps } from 'react-aria-components';
2
+ import type { Margin } from './types';
3
+ type Props = {
4
+ acceptedFileTypes?: FileTriggerProps['acceptedFileTypes'];
5
+ allowsMultiple?: FileTriggerProps['allowsMultiple'];
6
+ defaultCamera?: FileTriggerProps['defaultCamera'];
7
+ acceptDirectory?: FileTriggerProps['acceptDirectory'];
8
+ onSelect?: FileTriggerProps['onSelect'];
9
+ } & Margin & Omit<FileTriggerProps, 'children'>;
10
+ declare const FileTrigger: (props: Props) => import("react/jsx-runtime").JSX.Element;
11
+ export default FileTrigger;
@@ -0,0 +1,12 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { FileTrigger } from "react-aria-components";
3
+ import Button from "./Button/index.js";
4
+ const FileTrigger_FileTrigger = (props)=>/*#__PURE__*/ jsx(FileTrigger, {
5
+ ...props,
6
+ children: /*#__PURE__*/ jsx(Button, {
7
+ small: true,
8
+ children: "Select files"
9
+ })
10
+ });
11
+ const components_FileTrigger = FileTrigger_FileTrigger;
12
+ export { components_FileTrigger as default };
package/build/index.d.ts CHANGED
@@ -10,11 +10,13 @@ export { default as CommandMenu } from './components/CommandMenu';
10
10
  export { default as DocTable } from './components/DocTable';
11
11
  export { default as Dot } from './components/Dot';
12
12
  export { default as DraftEditor } from './components/DraftEditor';
13
+ export { default as DropZone } from './components/DropZone';
13
14
  export { default as Editor } from './components/Editor';
14
15
  export { default as DropdownMenu } from './components/DropdownMenu';
15
16
  export { default as DropdownSelect } from './components/DropdownSelect';
16
17
  export { default as Dropdown } from './components/Dropdown';
17
18
  export { default as Ellipsis } from './components/Ellipsis';
19
+ export { default as FileTrigger } from './components/FileTrigger';
18
20
  export { default as Form } from './components/Form';
19
21
  export { default as Grid } from './components/Grid';
20
22
  export { default as Icon } from './components/Icon';
@@ -88,3 +90,4 @@ export { default as formatDate } from './utils/formatDate';
88
90
  export { default as formatNumber } from './utils/formatNumber';
89
91
  export { default as numberWithCommas } from './utils/numberWithCommas';
90
92
  export { createEditorContent, editorContentToText } from './components/Editor';
93
+ export { default as matchesFileTypes } from './utils/matchesFileTypes';
package/build/index.js CHANGED
@@ -10,11 +10,13 @@ import CommandMenu from "./components/CommandMenu/index.js";
10
10
  import DocTable from "./components/DocTable.js";
11
11
  import Dot from "./components/Dot.js";
12
12
  import DraftEditor from "./components/DraftEditor.js";
13
+ import DropZone from "./components/DropZone.js";
13
14
  import Editor, { createEditorContent, editorContentToText } from "./components/Editor/index.js";
14
15
  import DropdownMenu from "./components/DropdownMenu.js";
15
16
  import DropdownSelect from "./components/DropdownSelect.js";
16
17
  import Dropdown from "./components/Dropdown.js";
17
18
  import Ellipsis from "./components/Ellipsis.js";
19
+ import FileTrigger from "./components/FileTrigger.js";
18
20
  import Form from "./components/Form.js";
19
21
  import Grid from "./components/Grid.js";
20
22
  import Icon from "./components/Icon/index.js";
@@ -77,4 +79,5 @@ import copyToClipboard from "./utils/copyToClipboard.js";
77
79
  import formatDate from "./utils/formatDate.js";
78
80
  import formatNumber from "./utils/formatNumber.js";
79
81
  import numberWithCommas from "./utils/numberWithCommas.js";
80
- export { Accordion, Audio, BarChart, Button, Calendar, Checkbox, Code, ComboBox, CommandMenu, DatePicker, DateRangePicker, DateRangeSelect, DocTable, Dot, DraftEditor, Dropdown, DropdownMenu, DropdownSelect, Editor, Ellipsis, 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.1",
3
+ "version": "2.3.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {