@behivetech/molecules.file-dropzone 0.0.0-stage → 0.2.2

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.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # FileDropzone
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TODO: Add component description.
4
+
5
+ ## Usage
6
+
7
+ ```jsx
8
+ import { FileDropzone } from "@behivetech/molecules.file-dropzone";
9
+
10
+ <FileDropzone>Content</FileDropzone>;
11
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
34
+ var require_classnames = __commonJS({
35
+ "../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports2, module2) {
36
+ "use strict";
37
+ (function() {
38
+ "use strict";
39
+ var hasOwn = {}.hasOwnProperty;
40
+ function classNames() {
41
+ var classes = "";
42
+ for (var i = 0; i < arguments.length; i++) {
43
+ var arg = arguments[i];
44
+ if (arg) {
45
+ classes = appendClass(classes, parseValue(arg));
46
+ }
47
+ }
48
+ return classes;
49
+ }
50
+ function parseValue(arg) {
51
+ if (typeof arg === "string" || typeof arg === "number") {
52
+ return arg;
53
+ }
54
+ if (typeof arg !== "object") {
55
+ return "";
56
+ }
57
+ if (Array.isArray(arg)) {
58
+ return classNames.apply(null, arg);
59
+ }
60
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
61
+ return arg.toString();
62
+ }
63
+ var classes = "";
64
+ for (var key in arg) {
65
+ if (hasOwn.call(arg, key) && arg[key]) {
66
+ classes = appendClass(classes, key);
67
+ }
68
+ }
69
+ return classes;
70
+ }
71
+ function appendClass(value, newClass) {
72
+ if (!newClass) {
73
+ return value;
74
+ }
75
+ if (value) {
76
+ return value + " " + newClass;
77
+ }
78
+ return value + newClass;
79
+ }
80
+ if (typeof module2 !== "undefined" && module2.exports) {
81
+ classNames.default = classNames;
82
+ module2.exports = classNames;
83
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
84
+ define("classnames", [], function() {
85
+ return classNames;
86
+ });
87
+ } else {
88
+ window.classNames = classNames;
89
+ }
90
+ })();
91
+ }
92
+ });
93
+
94
+ // index.ts
95
+ var index_exports = {};
96
+ __export(index_exports, {
97
+ FileDropzone: () => FileDropzone
98
+ });
99
+ module.exports = __toCommonJS(index_exports);
100
+
101
+ // file-dropzone.tsx
102
+ var import_react = require("react");
103
+
104
+ // ../../../../packages/registry/class-names/dist/index.js
105
+ var import_classnames = __toESM(require_classnames(), 1);
106
+ var getClassName = ({
107
+ className,
108
+ modifiers = {},
109
+ rootClass,
110
+ styles = {}
111
+ }) => {
112
+ function getModifiers() {
113
+ const updatedModifiers = {};
114
+ const modifierKeys = Object.keys(modifiers);
115
+ if (modifierKeys.length) {
116
+ modifierKeys.forEach((modKey) => {
117
+ const classKey = `${rootClass}--${modKey}`;
118
+ const newClassName = styles[classKey] || classKey;
119
+ updatedModifiers[newClassName] = modifiers[modKey] ?? false;
120
+ });
121
+ }
122
+ return updatedModifiers;
123
+ }
124
+ function getChildClass(childClassName) {
125
+ const classKey = `${rootClass}__${childClassName}`;
126
+ return styles[classKey] || classKey;
127
+ }
128
+ function getRootStyles() {
129
+ return (0, import_classnames.default)(
130
+ className,
131
+ {
132
+ ...getModifiers()
133
+ },
134
+ styles[rootClass] || rootClass
135
+ );
136
+ }
137
+ return [getRootStyles(), getChildClass];
138
+ };
139
+
140
+ // file-dropzone.module.scss
141
+ var file_dropzone_module_default = {
142
+ "BHT__FileDropzone": "BHT__FileDropzone",
143
+ "BHT__FileDropzone--dragging": "BHT__FileDropzone--dragging"
144
+ };
145
+
146
+ // file-dropzone.tsx
147
+ var import_jsx_runtime = require("react/jsx-runtime");
148
+ var FileDropzone = ({
149
+ onFiles,
150
+ accept,
151
+ multiple = true,
152
+ label = "Drag and drop files here, or click to browse",
153
+ className
154
+ }) => {
155
+ const [isDragging, setIsDragging] = (0, import_react.useState)(false);
156
+ const inputRef = (0, import_react.useRef)(null);
157
+ const [rootClass] = getClassName({
158
+ className,
159
+ rootClass: "BHT__FileDropzone",
160
+ modifiers: { dragging: isDragging },
161
+ styles: file_dropzone_module_default
162
+ });
163
+ const handleDragOver = (event) => {
164
+ event.preventDefault();
165
+ setIsDragging(true);
166
+ };
167
+ const handleDragLeave = (event) => {
168
+ event.preventDefault();
169
+ setIsDragging(false);
170
+ };
171
+ const handleDrop = (event) => {
172
+ event.preventDefault();
173
+ setIsDragging(false);
174
+ onFiles(Array.from(event.dataTransfer.files));
175
+ };
176
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
177
+ "div",
178
+ {
179
+ className: rootClass,
180
+ role: "button",
181
+ tabIndex: 0,
182
+ onClick: () => inputRef.current?.click(),
183
+ onKeyDown: (event) => {
184
+ if (event.key === "Enter" || event.key === " ") {
185
+ event.preventDefault();
186
+ inputRef.current?.click();
187
+ }
188
+ },
189
+ onDragOver: handleDragOver,
190
+ onDragLeave: handleDragLeave,
191
+ onDrop: handleDrop,
192
+ children: [
193
+ label,
194
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
195
+ "input",
196
+ {
197
+ ref: inputRef,
198
+ type: "file",
199
+ accept,
200
+ multiple,
201
+ hidden: true,
202
+ onChange: (event) => {
203
+ if (event.target.files) onFiles(Array.from(event.target.files));
204
+ event.target.value = "";
205
+ }
206
+ }
207
+ )
208
+ ]
209
+ }
210
+ );
211
+ };
212
+ // Annotate the CommonJS export names for ESM import in node:
213
+ 0 && (module.exports = {
214
+ FileDropzone
215
+ });
216
+ /*! Bundled license information:
217
+
218
+ classnames/index.js:
219
+ (*!
220
+ Copyright (c) 2018 Jed Watson.
221
+ Licensed under the MIT License (MIT), see
222
+ http://jedwatson.github.io/classnames
223
+ *)
224
+ */
package/dist/index.css ADDED
@@ -0,0 +1,53 @@
1
+ /* esbuild-sass-plugin:css-chunkfile-dropzone.module.scss */
2
+ .BHT__FileDropzone {
3
+ position: relative;
4
+ isolation: isolate;
5
+ display: flex;
6
+ align-items: center;
7
+ justify-content: center;
8
+ text-align: center;
9
+ min-height: 8rem;
10
+ padding: var(--spacing-6, 1.5rem);
11
+ border: 2px dashed var(--md-sys-color-outline, var(--color-border-strong));
12
+ border-radius: var(--md-sys-shape-corner-medium, 12px);
13
+ color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
14
+ font-family: var(--md-sys-typescale-body-medium-font, var(--font-body));
15
+ font-size: var(--md-sys-typescale-body-medium-size, 0.875rem);
16
+ font-weight: var(--md-sys-typescale-body-medium-weight, 400);
17
+ line-height: var(--md-sys-typescale-body-medium-line-height, 1.25rem);
18
+ letter-spacing: var(--md-sys-typescale-body-medium-tracking, 0.0179em);
19
+ cursor: pointer;
20
+ transition: border-color var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard, ease);
21
+ }
22
+ .BHT__FileDropzone::after {
23
+ content: "";
24
+ position: absolute;
25
+ inset: 0;
26
+ border-radius: inherit;
27
+ background: currentColor;
28
+ opacity: 0;
29
+ pointer-events: none;
30
+ transition: opacity var(--md-sys-motion-duration-short-2, 100ms) var(--md-sys-motion-easing-standard, ease);
31
+ }
32
+ .BHT__FileDropzone:hover {
33
+ border-color: var(--md-sys-color-primary, var(--color-primary));
34
+ }
35
+ .BHT__FileDropzone:hover::after {
36
+ opacity: var(--md-sys-state-hover-opacity, 0.08);
37
+ }
38
+ .BHT__FileDropzone:focus-visible {
39
+ outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
40
+ outline-offset: 2px;
41
+ }
42
+ .BHT__FileDropzone:focus-visible::after {
43
+ opacity: var(--md-sys-state-focus-opacity, 0.1);
44
+ }
45
+ .BHT__FileDropzone:active::after {
46
+ opacity: var(--md-sys-state-pressed-opacity, 0.1);
47
+ }
48
+ .BHT__FileDropzone--dragging.BHT__FileDropzone {
49
+ border-color: var(--md-sys-color-primary, var(--color-primary));
50
+ }
51
+ .BHT__FileDropzone--dragging.BHT__FileDropzone::after {
52
+ opacity: var(--md-sys-state-dragged-opacity, 0.16);
53
+ }
@@ -0,0 +1,23 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface FileDropzoneProps {
5
+ /** Called with the chosen files, from either a drop or the click-to-browse fallback */
6
+ onFiles: (files: File[]) => void;
7
+ /** Native `accept` attribute passed to the underlying file input, e.g. "image/*,application/pdf" */
8
+ accept?: string;
9
+ /** Whether more than one file can be selected at once; defaults to true */
10
+ multiple?: boolean;
11
+ /** Prompt content; defaults to a generic drag-and-drop message */
12
+ label?: ReactNode;
13
+ /** Additional class names to merge with the component root element */
14
+ className?: string;
15
+ }
16
+ /**
17
+ * A drag-and-drop target with a click-to-browse fallback. Reports the chosen `File`
18
+ * objects via `onFiles` — no upload, preview, or validation logic; that's the
19
+ * consumer's concern.
20
+ */
21
+ declare const FileDropzone: ({ onFiles, accept, multiple, label, className, }: FileDropzoneProps) => react.JSX.Element;
22
+
23
+ export { FileDropzone, type FileDropzoneProps };
package/dist/index.js ADDED
@@ -0,0 +1,210 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
28
+ var require_classnames = __commonJS({
29
+ "../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
30
+ "use strict";
31
+ (function() {
32
+ "use strict";
33
+ var hasOwn = {}.hasOwnProperty;
34
+ function classNames() {
35
+ var classes = "";
36
+ for (var i = 0; i < arguments.length; i++) {
37
+ var arg = arguments[i];
38
+ if (arg) {
39
+ classes = appendClass(classes, parseValue(arg));
40
+ }
41
+ }
42
+ return classes;
43
+ }
44
+ function parseValue(arg) {
45
+ if (typeof arg === "string" || typeof arg === "number") {
46
+ return arg;
47
+ }
48
+ if (typeof arg !== "object") {
49
+ return "";
50
+ }
51
+ if (Array.isArray(arg)) {
52
+ return classNames.apply(null, arg);
53
+ }
54
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
55
+ return arg.toString();
56
+ }
57
+ var classes = "";
58
+ for (var key in arg) {
59
+ if (hasOwn.call(arg, key) && arg[key]) {
60
+ classes = appendClass(classes, key);
61
+ }
62
+ }
63
+ return classes;
64
+ }
65
+ function appendClass(value, newClass) {
66
+ if (!newClass) {
67
+ return value;
68
+ }
69
+ if (value) {
70
+ return value + " " + newClass;
71
+ }
72
+ return value + newClass;
73
+ }
74
+ if (typeof module !== "undefined" && module.exports) {
75
+ classNames.default = classNames;
76
+ module.exports = classNames;
77
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
78
+ define("classnames", [], function() {
79
+ return classNames;
80
+ });
81
+ } else {
82
+ window.classNames = classNames;
83
+ }
84
+ })();
85
+ }
86
+ });
87
+
88
+ // file-dropzone.tsx
89
+ import { useRef, useState } from "react";
90
+
91
+ // ../../../../packages/registry/class-names/dist/index.js
92
+ var import_classnames = __toESM(require_classnames(), 1);
93
+ var getClassName = ({
94
+ className,
95
+ modifiers = {},
96
+ rootClass,
97
+ styles = {}
98
+ }) => {
99
+ function getModifiers() {
100
+ const updatedModifiers = {};
101
+ const modifierKeys = Object.keys(modifiers);
102
+ if (modifierKeys.length) {
103
+ modifierKeys.forEach((modKey) => {
104
+ const classKey = `${rootClass}--${modKey}`;
105
+ const newClassName = styles[classKey] || classKey;
106
+ updatedModifiers[newClassName] = modifiers[modKey] ?? false;
107
+ });
108
+ }
109
+ return updatedModifiers;
110
+ }
111
+ function getChildClass(childClassName) {
112
+ const classKey = `${rootClass}__${childClassName}`;
113
+ return styles[classKey] || classKey;
114
+ }
115
+ function getRootStyles() {
116
+ return (0, import_classnames.default)(
117
+ className,
118
+ {
119
+ ...getModifiers()
120
+ },
121
+ styles[rootClass] || rootClass
122
+ );
123
+ }
124
+ return [getRootStyles(), getChildClass];
125
+ };
126
+
127
+ // file-dropzone.module.scss
128
+ var file_dropzone_module_default = {
129
+ "BHT__FileDropzone": "BHT__FileDropzone",
130
+ "BHT__FileDropzone--dragging": "BHT__FileDropzone--dragging"
131
+ };
132
+
133
+ // file-dropzone.tsx
134
+ import { jsx, jsxs } from "react/jsx-runtime";
135
+ var FileDropzone = ({
136
+ onFiles,
137
+ accept,
138
+ multiple = true,
139
+ label = "Drag and drop files here, or click to browse",
140
+ className
141
+ }) => {
142
+ const [isDragging, setIsDragging] = useState(false);
143
+ const inputRef = useRef(null);
144
+ const [rootClass] = getClassName({
145
+ className,
146
+ rootClass: "BHT__FileDropzone",
147
+ modifiers: { dragging: isDragging },
148
+ styles: file_dropzone_module_default
149
+ });
150
+ const handleDragOver = (event) => {
151
+ event.preventDefault();
152
+ setIsDragging(true);
153
+ };
154
+ const handleDragLeave = (event) => {
155
+ event.preventDefault();
156
+ setIsDragging(false);
157
+ };
158
+ const handleDrop = (event) => {
159
+ event.preventDefault();
160
+ setIsDragging(false);
161
+ onFiles(Array.from(event.dataTransfer.files));
162
+ };
163
+ return /* @__PURE__ */ jsxs(
164
+ "div",
165
+ {
166
+ className: rootClass,
167
+ role: "button",
168
+ tabIndex: 0,
169
+ onClick: () => inputRef.current?.click(),
170
+ onKeyDown: (event) => {
171
+ if (event.key === "Enter" || event.key === " ") {
172
+ event.preventDefault();
173
+ inputRef.current?.click();
174
+ }
175
+ },
176
+ onDragOver: handleDragOver,
177
+ onDragLeave: handleDragLeave,
178
+ onDrop: handleDrop,
179
+ children: [
180
+ label,
181
+ /* @__PURE__ */ jsx(
182
+ "input",
183
+ {
184
+ ref: inputRef,
185
+ type: "file",
186
+ accept,
187
+ multiple,
188
+ hidden: true,
189
+ onChange: (event) => {
190
+ if (event.target.files) onFiles(Array.from(event.target.files));
191
+ event.target.value = "";
192
+ }
193
+ }
194
+ )
195
+ ]
196
+ }
197
+ );
198
+ };
199
+ export {
200
+ FileDropzone
201
+ };
202
+ /*! Bundled license information:
203
+
204
+ classnames/index.js:
205
+ (*!
206
+ Copyright (c) 2018 Jed Watson.
207
+ Licensed under the MIT License (MIT), see
208
+ http://jedwatson.github.io/classnames
209
+ *)
210
+ */
package/docs.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
3
+ "version": 2,
4
+ "generatedAt": "2026-10-20T05:49:24.484Z",
5
+ "docs": [
6
+ {
7
+ "displayName": "FileDropzone",
8
+ "description": "A drag-and-drop target with a click-to-browse fallback. Reports the chosen `File`\nobjects via `onFiles` — no upload, preview, or validation logic; that's the\nconsumer's concern.",
9
+ "extendsNative": false,
10
+ "props": [
11
+ {
12
+ "name": "onFiles",
13
+ "type": "(files: File[]) => void",
14
+ "required": true,
15
+ "defaultValue": null,
16
+ "description": "Called with the chosen files, from either a drop or the click-to-browse fallback"
17
+ },
18
+ {
19
+ "name": "accept",
20
+ "type": "string",
21
+ "required": false,
22
+ "defaultValue": null,
23
+ "description": "Native `accept` attribute passed to the underlying file input, e.g. \"image/*,application/pdf\""
24
+ },
25
+ {
26
+ "name": "className",
27
+ "type": "string",
28
+ "required": false,
29
+ "defaultValue": null,
30
+ "description": "Additional class names to merge with the component root element"
31
+ },
32
+ {
33
+ "name": "label",
34
+ "type": "ReactNode",
35
+ "required": false,
36
+ "defaultValue": "Drag and drop files here, or click to browse",
37
+ "description": "Prompt content; defaults to a generic drag-and-drop message"
38
+ },
39
+ {
40
+ "name": "multiple",
41
+ "type": "boolean",
42
+ "required": false,
43
+ "defaultValue": "true",
44
+ "description": "Whether more than one file can be selected at once; defaults to true"
45
+ }
46
+ ]
47
+ }
48
+ ],
49
+ "functions": []
50
+ }
@@ -0,0 +1,23 @@
1
+ import { useState } from "react";
2
+ import { FileDropzone } from "./file-dropzone.js";
3
+
4
+ export const BasicFileDropzone = () => {
5
+ const [names, setNames] = useState<string[]>([]);
6
+
7
+ return (
8
+ <>
9
+ <FileDropzone
10
+ onFiles={(files) => setNames(files.map((file) => file.name))}
11
+ />
12
+ {names.length > 0 && <p>Chosen: {names.join(", ")}</p>}
13
+ </>
14
+ );
15
+ };
16
+
17
+ export const ImagesOnlyFileDropzone = () => (
18
+ <FileDropzone
19
+ onFiles={(files) => console.log(files)}
20
+ accept="image/*"
21
+ label="Drop images here"
22
+ />
23
+ );
@@ -0,0 +1,69 @@
1
+ // Drop target. MD3 has no dropzone component, so it borrows the outlined
2
+ // container (dashed `outline` border, medium corner) and expresses hover and
3
+ // drag-over through the standard state layer instead of a fixed background.
4
+
5
+ .BHT__FileDropzone {
6
+ // `isolation` keeps the state layer's stacking context local to the zone.
7
+ position: relative;
8
+ isolation: isolate;
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ text-align: center;
13
+ min-height: 8rem;
14
+ padding: var(--spacing-6, 1.5rem);
15
+ border: 2px dashed var(--md-sys-color-outline, var(--color-border-strong));
16
+ border-radius: var(--md-sys-shape-corner-medium, 12px);
17
+ color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
18
+ font-family: var(--md-sys-typescale-body-medium-font, var(--font-body));
19
+ font-size: var(--md-sys-typescale-body-medium-size, 0.875rem);
20
+ font-weight: var(--md-sys-typescale-body-medium-weight, 400);
21
+ line-height: var(--md-sys-typescale-body-medium-line-height, 1.25rem);
22
+ letter-spacing: var(--md-sys-typescale-body-medium-tracking, 0.0179em);
23
+ cursor: pointer;
24
+ transition: border-color var(--md-sys-motion-duration-short-3, 150ms)
25
+ var(--md-sys-motion-easing-standard, ease);
26
+
27
+ &::after {
28
+ content: "";
29
+ position: absolute;
30
+ inset: 0;
31
+ border-radius: inherit;
32
+ background: currentColor;
33
+ opacity: 0;
34
+ pointer-events: none;
35
+ transition: opacity var(--md-sys-motion-duration-short-2, 100ms)
36
+ var(--md-sys-motion-easing-standard, ease);
37
+ }
38
+
39
+ &:hover {
40
+ border-color: var(--md-sys-color-primary, var(--color-primary));
41
+ }
42
+
43
+ &:hover::after {
44
+ opacity: var(--md-sys-state-hover-opacity, 0.08);
45
+ }
46
+
47
+ &:focus-visible {
48
+ outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
49
+ outline-offset: 2px;
50
+ }
51
+
52
+ &:focus-visible::after {
53
+ opacity: var(--md-sys-state-focus-opacity, 0.1);
54
+ }
55
+
56
+ &:active::after {
57
+ opacity: var(--md-sys-state-pressed-opacity, 0.1);
58
+ }
59
+
60
+ &--dragging {
61
+ &.BHT__FileDropzone {
62
+ border-color: var(--md-sys-color-primary, var(--color-primary));
63
+
64
+ &::after {
65
+ opacity: var(--md-sys-state-dragged-opacity, 0.16);
66
+ }
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,86 @@
1
+ import { useRef, useState, type DragEvent, type ReactNode } from "react";
2
+ import { getClassName } from "@bht-component-registry/class-names";
3
+ import styles from "./file-dropzone.module.scss";
4
+
5
+ export interface FileDropzoneProps {
6
+ /** Called with the chosen files, from either a drop or the click-to-browse fallback */
7
+ onFiles: (files: File[]) => void;
8
+ /** Native `accept` attribute passed to the underlying file input, e.g. "image/*,application/pdf" */
9
+ accept?: string;
10
+ /** Whether more than one file can be selected at once; defaults to true */
11
+ multiple?: boolean;
12
+ /** Prompt content; defaults to a generic drag-and-drop message */
13
+ label?: ReactNode;
14
+ /** Additional class names to merge with the component root element */
15
+ className?: string;
16
+ }
17
+
18
+ /**
19
+ * A drag-and-drop target with a click-to-browse fallback. Reports the chosen `File`
20
+ * objects via `onFiles` — no upload, preview, or validation logic; that's the
21
+ * consumer's concern.
22
+ */
23
+ export const FileDropzone = ({
24
+ onFiles,
25
+ accept,
26
+ multiple = true,
27
+ label = "Drag and drop files here, or click to browse",
28
+ className,
29
+ }: FileDropzoneProps) => {
30
+ const [isDragging, setIsDragging] = useState(false);
31
+ const inputRef = useRef<HTMLInputElement>(null);
32
+
33
+ const [rootClass] = getClassName({
34
+ className,
35
+ rootClass: "BHT__FileDropzone",
36
+ modifiers: { dragging: isDragging },
37
+ styles,
38
+ });
39
+
40
+ const handleDragOver = (event: DragEvent<HTMLDivElement>) => {
41
+ event.preventDefault();
42
+ setIsDragging(true);
43
+ };
44
+
45
+ const handleDragLeave = (event: DragEvent<HTMLDivElement>) => {
46
+ event.preventDefault();
47
+ setIsDragging(false);
48
+ };
49
+
50
+ const handleDrop = (event: DragEvent<HTMLDivElement>) => {
51
+ event.preventDefault();
52
+ setIsDragging(false);
53
+ onFiles(Array.from(event.dataTransfer.files));
54
+ };
55
+
56
+ return (
57
+ <div
58
+ className={rootClass}
59
+ role="button"
60
+ tabIndex={0}
61
+ onClick={() => inputRef.current?.click()}
62
+ onKeyDown={(event) => {
63
+ if (event.key === "Enter" || event.key === " ") {
64
+ event.preventDefault();
65
+ inputRef.current?.click();
66
+ }
67
+ }}
68
+ onDragOver={handleDragOver}
69
+ onDragLeave={handleDragLeave}
70
+ onDrop={handleDrop}
71
+ >
72
+ {label}
73
+ <input
74
+ ref={inputRef}
75
+ type="file"
76
+ accept={accept}
77
+ multiple={multiple}
78
+ hidden
79
+ onChange={(event) => {
80
+ if (event.target.files) onFiles(Array.from(event.target.files));
81
+ event.target.value = "";
82
+ }}
83
+ />
84
+ </div>
85
+ );
86
+ };
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { FileDropzone } from "./file-dropzone.js";
2
+ export type { FileDropzoneProps } from "./file-dropzone.js";
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@behivetech/molecules.file-dropzone",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.2",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "private": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "./styles.css": "./dist/index.css"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "index.ts",
19
+ "file-dropzone.tsx",
20
+ "file-dropzone.module.scss",
21
+ "*.example.tsx",
22
+ "docs.json"
23
+ ],
24
+ "registry": {
25
+ "status": "stable",
26
+ "tags": []
27
+ },
28
+ "peerDependencies": {
29
+ "react": "^19.2.7",
30
+ "react-dom": "^19.2.7"
31
+ },
32
+ "devDependencies": {
33
+ "@types/react": "19.2.17",
34
+ "@types/react-dom": "19.2.3",
35
+ "eslint": "^9.39.5",
36
+ "tsup": "^8.5.1",
37
+ "typescript": "^6.0.3",
38
+ "vitest": "^4.1.10",
39
+ "@bht-component-registry/env": "0.1.0",
40
+ "@bht-component-registry/class-names": "0.0.6"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/behivetech/bht-galaxy.git",
45
+ "directory": "registry/behivetech/molecules/file-dropzone"
46
+ },
47
+ "publishConfig": {
48
+ "registry": "https://registry.npmjs.org",
49
+ "access": "public",
50
+ "provenance": true
51
+ },
52
+ "scripts": {
53
+ "build": "tsup && bht-registry-docgen",
54
+ "dev": "tsup --watch",
55
+ "lint": "eslint . --max-warnings 0",
56
+ "check-types": "tsc --noEmit",
57
+ "test": "vitest run"
58
+ }
6
59
  }