@behivetech/molecules.file-dropzone 1.0.0 → 1.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BEhive Tech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -11,3 +11,13 @@ import { FileDropzone } from "@behivetech/molecules.file-dropzone";
11
11
 
12
12
  <FileDropzone>Content</FileDropzone>;
13
13
  ```
14
+
15
+ ## On React Native
16
+
17
+ On a phone there is nothing to drop on, so the native `FileDropzone` is a button that opens the device's file picker through `expo-document-picker`, an optional peer dependency (`npx expo install expo-document-picker`). It keeps `accept`, `multiple` and `label`; `style` is `className` there.
18
+
19
+ - `onFiles` receives `PickedFile`s (`uri`, `name`, and `size` and `mimeType` when the platform says), not the web's `File` objects. Files are copied to the app's cache; read them from `uri`.
20
+ - `accept` takes MIME types only (`image/*,application/pdf`); the web's extensions (`.pdf`) are ignored, and with no MIME type the picker offers any file.
21
+ - Nothing is reported when the person cancels. A picker that fails to open or to read a file calls `onError`.
22
+ - Your `onPressIn`, `onPressOut`, `onHoverIn`, `onHoverOut`, `onFocus` and `onBlur` are called after the block's own, and a `hitSlop` you pass is the button's.
23
+ - The button is busy and ignores presses while the picker is open. The `label` is drawn inside a `Text`, and a text label names the button for a screen reader unless you pass an `accessibilityLabel`; the default prompt is "Tap to choose files".
package/dist/index.cjs CHANGED
@@ -27,13 +27,66 @@ module.exports = __toCommonJS(index_exports);
27
27
 
28
28
  // file-dropzone.tsx
29
29
  var import_react = require("react");
30
- var import_get_class_name = require("@behivetech/get-class-name");
30
+ var import_blocks2 = require("@behivetech/blocks.core");
31
31
 
32
- // file-dropzone.module.scss
33
- var file_dropzone_module_default = {
34
- "BHT__FileDropzone": "BHT__FileDropzone",
35
- "BHT__FileDropzone--dragging": "BHT__FileDropzone--dragging"
36
- };
32
+ // file-dropzone.block.ts
33
+ var import_blocks = require("@behivetech/blocks.core");
34
+ var import_tokens = require("@behivetech/blocks.core/tokens");
35
+ var { color, motion, shape, spacing, state, type } = import_tokens.tokens;
36
+ var fileDropzone = (0, import_blocks.defineBlock)("BHT__FileDropzone", {
37
+ a11y: { role: "button" },
38
+ position: "relative",
39
+ display: "flex",
40
+ alignItems: "center",
41
+ justifyContent: "center",
42
+ textAlign: "center",
43
+ minHeight: "8rem",
44
+ padding: spacing[6],
45
+ border: [2, "dashed", color.outline],
46
+ borderRadius: shape.cornerMedium,
47
+ color: color.onSurfaceVariant,
48
+ fontFamily: type.bodyMedium.font,
49
+ fontSize: type.bodyMedium.size,
50
+ fontWeight: type.bodyMedium.weight,
51
+ lineHeight: type.bodyMedium.lineHeight,
52
+ letterSpacing: type.bodyMedium.tracking,
53
+ native: { states: { pressed: { borderColor: color.primary } } },
54
+ states: {
55
+ hover: { borderColor: color.primary },
56
+ focusVisible: {
57
+ outlineWidth: 3,
58
+ outlineStyle: "solid",
59
+ outlineColor: color.secondary,
60
+ outlineOffset: 2
61
+ }
62
+ },
63
+ // Native only: the prompt's text, which takes the root's text properties as a child does.
64
+ children: { label: {} },
65
+ variants: {
66
+ dragging: {
67
+ borderColor: color.primary,
68
+ web: { "&::after": { opacity: state.draggedOpacity } }
69
+ }
70
+ },
71
+ web: {
72
+ isolation: "isolate",
73
+ cursor: "pointer",
74
+ transition: import_blocks.css`border-color ${motion.durationShort3} ${motion.easingStandard}`,
75
+ "&::after": {
76
+ content: '""',
77
+ position: "absolute",
78
+ inset: 0,
79
+ borderRadius: "inherit",
80
+ background: "currentColor",
81
+ opacity: 0,
82
+ pointerEvents: "none",
83
+ transition: import_blocks.css`opacity ${motion.durationShort2} ${motion.easingStandard}`
84
+ },
85
+ "&:hover::after": { opacity: state.hoverOpacity },
86
+ "&:focus-visible::after": { opacity: state.focusOpacity },
87
+ "&:active::after": { opacity: state.pressedOpacity }
88
+ }
89
+ });
37
90
 
38
91
  // file-dropzone.tsx
39
92
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -42,16 +95,16 @@ var FileDropzone = ({
42
95
  accept,
43
96
  multiple = true,
44
97
  label = "Drag and drop files here, or click to browse",
45
- className
98
+ className,
99
+ styles
46
100
  }) => {
47
101
  const [isDragging, setIsDragging] = (0, import_react.useState)(false);
48
102
  const inputRef = (0, import_react.useRef)(null);
49
- const [rootClass] = (0, import_get_class_name.getClassName)({
50
- className,
51
- rootClass: "BHT__FileDropzone",
52
- modifiers: { dragging: isDragging },
53
- styles: file_dropzone_module_default
54
- });
103
+ const [rootProps] = (0, import_blocks2.useBlock)(
104
+ fileDropzone,
105
+ { dragging: isDragging },
106
+ { className, styles }
107
+ );
55
108
  const handleDragOver = (event) => {
56
109
  event.preventDefault();
57
110
  setIsDragging(true);
@@ -68,7 +121,7 @@ var FileDropzone = ({
68
121
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
69
122
  "div",
70
123
  {
71
- className: rootClass,
124
+ ...rootProps,
72
125
  role: "button",
73
126
  tabIndex: 0,
74
127
  onClick: () => inputRef.current?.click(),
package/dist/index.css CHANGED
@@ -1,53 +1,57 @@
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);
1
+ /* file-dropzone.block.css */
2
+ @layer bht {
3
+ .BHT__FileDropzone {
4
+ position: relative;
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, #777777);
12
+ border-radius: var(--md-sys-shape-corner-medium, 12px);
13
+ color: var(--md-sys-color-on-surface-variant, #474747);
14
+ font-family: var( --md-sys-typescale-body-medium-font, "Inter", system-ui, -apple-system, sans-serif );
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
+ isolation: isolate;
20
+ cursor: pointer;
21
+ transition: border-color var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard, cubic-bezier(0.2, 0, 0, 1));
22
+ }
23
+ .BHT__FileDropzone:hover {
24
+ border-color: var(--md-sys-color-primary, #64558f);
25
+ }
26
+ .BHT__FileDropzone:focus-visible {
27
+ outline-width: 3px;
28
+ outline-style: solid;
29
+ outline-color: var(--md-sys-color-secondary, #615b71);
30
+ outline-offset: 2px;
31
+ }
32
+ .BHT__FileDropzone::after {
33
+ content: "";
34
+ position: absolute;
35
+ inset: 0;
36
+ border-radius: inherit;
37
+ background: currentColor;
38
+ opacity: 0;
39
+ pointer-events: none;
40
+ transition: opacity var(--md-sys-motion-duration-short-2, 100ms) var(--md-sys-motion-easing-standard, cubic-bezier(0.2, 0, 0, 1));
41
+ }
42
+ .BHT__FileDropzone:hover::after {
43
+ opacity: var(--md-sys-state-hover-opacity, 0.08);
44
+ }
45
+ .BHT__FileDropzone:focus-visible::after {
46
+ opacity: var(--md-sys-state-focus-opacity, 0.1);
47
+ }
48
+ .BHT__FileDropzone:active::after {
49
+ opacity: var(--md-sys-state-pressed-opacity, 0.1);
50
+ }
51
+ .BHT__FileDropzone--dragging.BHT__FileDropzone {
52
+ border-color: var(--md-sys-color-primary, #64558f);
53
+ }
54
+ .BHT__FileDropzone--dragging.BHT__FileDropzone::after {
55
+ opacity: var(--md-sys-state-dragged-opacity, 0.16);
56
+ }
53
57
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,83 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
+ import * as _behivetech_blocks_core from '@behivetech/blocks.core';
4
+ import { StylesFor } from '@behivetech/blocks.core';
5
+
6
+ declare const fileDropzone: _behivetech_blocks_core.Block<"BHT__FileDropzone", {
7
+ readonly a11y: {
8
+ readonly role: "button";
9
+ };
10
+ readonly position: "relative";
11
+ readonly display: "flex";
12
+ readonly alignItems: "center";
13
+ readonly justifyContent: "center";
14
+ readonly textAlign: "center";
15
+ readonly minHeight: "8rem";
16
+ readonly padding: _behivetech_blocks_core.Token<"length">;
17
+ readonly border: readonly [2, "dashed", _behivetech_blocks_core.Token<"color">];
18
+ readonly borderRadius: _behivetech_blocks_core.Token<"length">;
19
+ readonly color: _behivetech_blocks_core.Token<"color">;
20
+ readonly fontFamily: _behivetech_blocks_core.Token<"font">;
21
+ readonly fontSize: _behivetech_blocks_core.Token<"length">;
22
+ readonly fontWeight: _behivetech_blocks_core.Token<"weight">;
23
+ readonly lineHeight: _behivetech_blocks_core.Token<"length">;
24
+ readonly letterSpacing: _behivetech_blocks_core.Token<"tracking">;
25
+ readonly native: {
26
+ readonly states: {
27
+ readonly pressed: {
28
+ readonly borderColor: _behivetech_blocks_core.Token<"color">;
29
+ };
30
+ };
31
+ };
32
+ readonly states: {
33
+ readonly hover: {
34
+ readonly borderColor: _behivetech_blocks_core.Token<"color">;
35
+ };
36
+ readonly focusVisible: {
37
+ readonly outlineWidth: 3;
38
+ readonly outlineStyle: "solid";
39
+ readonly outlineColor: _behivetech_blocks_core.Token<"color">;
40
+ readonly outlineOffset: 2;
41
+ };
42
+ };
43
+ readonly children: {
44
+ readonly label: {};
45
+ };
46
+ readonly variants: {
47
+ readonly dragging: {
48
+ readonly borderColor: _behivetech_blocks_core.Token<"color">;
49
+ readonly web: {
50
+ readonly "&::after": {
51
+ readonly opacity: _behivetech_blocks_core.Token<"number">;
52
+ };
53
+ };
54
+ };
55
+ };
56
+ readonly web: {
57
+ readonly isolation: "isolate";
58
+ readonly cursor: "pointer";
59
+ readonly transition: _behivetech_blocks_core.CssValue;
60
+ readonly "&::after": {
61
+ readonly content: "\"\"";
62
+ readonly position: "absolute";
63
+ readonly inset: 0;
64
+ readonly borderRadius: "inherit";
65
+ readonly background: "currentColor";
66
+ readonly opacity: 0;
67
+ readonly pointerEvents: "none";
68
+ readonly transition: _behivetech_blocks_core.CssValue;
69
+ };
70
+ readonly "&:hover::after": {
71
+ readonly opacity: _behivetech_blocks_core.Token<"number">;
72
+ };
73
+ readonly "&:focus-visible::after": {
74
+ readonly opacity: _behivetech_blocks_core.Token<"number">;
75
+ };
76
+ readonly "&:active::after": {
77
+ readonly opacity: _behivetech_blocks_core.Token<"number">;
78
+ };
79
+ };
80
+ }>;
3
81
 
4
82
  interface FileDropzoneProps {
5
83
  /** Called with the chosen files, from either a drop or the click-to-browse fallback */
@@ -12,12 +90,14 @@ interface FileDropzoneProps {
12
90
  label?: ReactNode;
13
91
  /** Additional class names to merge with the component root element */
14
92
  className?: string;
93
+ /** An override block made with `defineBlock`, typed to this component's children and variants; it wins over the block's own styles. */
94
+ styles?: StylesFor<typeof fileDropzone>;
15
95
  }
16
96
  /**
17
97
  * A drag-and-drop target with a click-to-browse fallback. Reports the chosen `File`
18
98
  * objects via `onFiles` — no upload, preview, or validation logic; that's the
19
99
  * consumer's concern.
20
100
  */
21
- declare const FileDropzone: ({ onFiles, accept, multiple, label, className, }: FileDropzoneProps) => react.JSX.Element;
101
+ declare const FileDropzone: ({ onFiles, accept, multiple, label, className, styles, }: FileDropzoneProps) => react.JSX.Element;
22
102
 
23
103
  export { FileDropzone, type FileDropzoneProps };
package/dist/index.js CHANGED
@@ -2,13 +2,66 @@
2
2
 
3
3
  // file-dropzone.tsx
4
4
  import { useRef, useState } from "react";
5
- import { getClassName } from "@behivetech/get-class-name";
5
+ import { useBlock } from "@behivetech/blocks.core";
6
6
 
7
- // file-dropzone.module.scss
8
- var file_dropzone_module_default = {
9
- "BHT__FileDropzone": "BHT__FileDropzone",
10
- "BHT__FileDropzone--dragging": "BHT__FileDropzone--dragging"
11
- };
7
+ // file-dropzone.block.ts
8
+ import { css, defineBlock } from "@behivetech/blocks.core";
9
+ import { tokens } from "@behivetech/blocks.core/tokens";
10
+ var { color, motion, shape, spacing, state, type } = tokens;
11
+ var fileDropzone = defineBlock("BHT__FileDropzone", {
12
+ a11y: { role: "button" },
13
+ position: "relative",
14
+ display: "flex",
15
+ alignItems: "center",
16
+ justifyContent: "center",
17
+ textAlign: "center",
18
+ minHeight: "8rem",
19
+ padding: spacing[6],
20
+ border: [2, "dashed", color.outline],
21
+ borderRadius: shape.cornerMedium,
22
+ color: color.onSurfaceVariant,
23
+ fontFamily: type.bodyMedium.font,
24
+ fontSize: type.bodyMedium.size,
25
+ fontWeight: type.bodyMedium.weight,
26
+ lineHeight: type.bodyMedium.lineHeight,
27
+ letterSpacing: type.bodyMedium.tracking,
28
+ native: { states: { pressed: { borderColor: color.primary } } },
29
+ states: {
30
+ hover: { borderColor: color.primary },
31
+ focusVisible: {
32
+ outlineWidth: 3,
33
+ outlineStyle: "solid",
34
+ outlineColor: color.secondary,
35
+ outlineOffset: 2
36
+ }
37
+ },
38
+ // Native only: the prompt's text, which takes the root's text properties as a child does.
39
+ children: { label: {} },
40
+ variants: {
41
+ dragging: {
42
+ borderColor: color.primary,
43
+ web: { "&::after": { opacity: state.draggedOpacity } }
44
+ }
45
+ },
46
+ web: {
47
+ isolation: "isolate",
48
+ cursor: "pointer",
49
+ transition: css`border-color ${motion.durationShort3} ${motion.easingStandard}`,
50
+ "&::after": {
51
+ content: '""',
52
+ position: "absolute",
53
+ inset: 0,
54
+ borderRadius: "inherit",
55
+ background: "currentColor",
56
+ opacity: 0,
57
+ pointerEvents: "none",
58
+ transition: css`opacity ${motion.durationShort2} ${motion.easingStandard}`
59
+ },
60
+ "&:hover::after": { opacity: state.hoverOpacity },
61
+ "&:focus-visible::after": { opacity: state.focusOpacity },
62
+ "&:active::after": { opacity: state.pressedOpacity }
63
+ }
64
+ });
12
65
 
13
66
  // file-dropzone.tsx
14
67
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -17,16 +70,16 @@ var FileDropzone = ({
17
70
  accept,
18
71
  multiple = true,
19
72
  label = "Drag and drop files here, or click to browse",
20
- className
73
+ className,
74
+ styles
21
75
  }) => {
22
76
  const [isDragging, setIsDragging] = useState(false);
23
77
  const inputRef = useRef(null);
24
- const [rootClass] = getClassName({
25
- className,
26
- rootClass: "BHT__FileDropzone",
27
- modifiers: { dragging: isDragging },
28
- styles: file_dropzone_module_default
29
- });
78
+ const [rootProps] = useBlock(
79
+ fileDropzone,
80
+ { dragging: isDragging },
81
+ { className, styles }
82
+ );
30
83
  const handleDragOver = (event) => {
31
84
  event.preventDefault();
32
85
  setIsDragging(true);
@@ -43,7 +96,7 @@ var FileDropzone = ({
43
96
  return /* @__PURE__ */ jsxs(
44
97
  "div",
45
98
  {
46
- className: rootClass,
99
+ ...rootProps,
47
100
  role: "button",
48
101
  tabIndex: 0,
49
102
  onClick: () => inputRef.current?.click(),