@bbki.ng/components 1.5.5 → 1.5.6

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { EventHandler, ReactElement, CSSProperties, FunctionComponent } from 'react';
1
+ import React, { EventHandler, ReactElement, CSSProperties, Ref, ReactNode, FunctionComponent } from 'react';
2
2
  import { LinkProps as LinkProps$1 } from 'react-router-dom';
3
3
 
4
4
  declare type ArticleProps = {
@@ -123,8 +123,18 @@ declare type SkeletonProps = {
123
123
  };
124
124
  declare const Skeleton: (props: SkeletonProps) => JSX.Element;
125
125
 
126
+ interface ImagePreviewerProps {
127
+ className?: string;
128
+ visible: boolean;
129
+ imageRef: Ref<HTMLImageElement>;
130
+ imageSrc: string;
131
+ imageSize: {
132
+ width: number;
133
+ height: number;
134
+ };
135
+ }
126
136
  interface ImageDropProps<T> {
127
- uploader: (file: File, img: HTMLImageElement) => Promise<T>;
137
+ uploader: (file: File, img?: HTMLImageElement) => Promise<T>;
128
138
  onDrop?: (events: Event, file: File) => void;
129
139
  onUploadFinish?: (result: T) => void;
130
140
  waitTimeAfterFinish?: number;
@@ -133,7 +143,14 @@ interface ImageDropProps<T> {
133
143
  dropAreaStyle?: CSSStyleDeclaration;
134
144
  placeholder?: any;
135
145
  className?: string;
146
+ ghost?: boolean;
147
+ children?: (props: ImagePreviewerProps) => ReactNode;
136
148
  }
137
149
  declare const DropImage: FunctionComponent<ImageDropProps<any>>;
138
150
 
139
- export { Article, ArticleProps, Breadcrumb, BreadcrumbProps, Button, ButtonProps, ButtonType, DropImage, ImageDropProps, Link, LinkColor, LinkProps, Logo, LogoProps, Nav, NavProps, Page, Panel, PanelProps, PathObj, PopConfirm, PopConfirmProps, Skeleton, SkeletonColor, SkeletonProps, Table, TableProps, Tag, TagProps, Tags };
151
+ declare type BLinkDotProps = {
152
+ className?: string;
153
+ };
154
+ declare const BlinkDot: (props: BLinkDotProps) => JSX.Element;
155
+
156
+ export { Article, ArticleProps, BLinkDotProps, BlinkDot, Breadcrumb, BreadcrumbProps, Button, ButtonProps, ButtonType, DropImage, ImageDropProps, ImagePreviewerProps, Link, LinkColor, LinkProps, Logo, LogoProps, Nav, NavProps, Page, Panel, PanelProps, PathObj, PopConfirm, PopConfirmProps, Skeleton, SkeletonColor, SkeletonProps, Table, TableProps, Tag, TagProps, Tags };
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
59
59
  var src_exports = {};
60
60
  __export(src_exports, {
61
61
  Article: () => Article,
62
+ BlinkDot: () => BlinkDot,
62
63
  Breadcrumb: () => Breadcrumb,
63
64
  Button: () => Button,
64
65
  ButtonType: () => ButtonType,
@@ -455,6 +456,96 @@ var useDropImage = (params) => {
455
456
  };
456
457
 
457
458
  // src/drop-image/DropImage.tsx
459
+ var ImagePreviewer = (props) => {
460
+ const {
461
+ visible: showImagePreviewer,
462
+ imageRef,
463
+ imageSize,
464
+ imageSrc,
465
+ className
466
+ } = props;
467
+ return /* @__PURE__ */ import_react13.default.createElement("img", {
468
+ className: (0, import_classnames6.default)(className, "max-w-[100%]", "h-[auto]", "duration-300", "transition-opacity", "opacity-100", {
469
+ "opacity-0": !showImagePreviewer,
470
+ "!m-0": !showImagePreviewer,
471
+ "!p-0": !showImagePreviewer
472
+ }),
473
+ ref: imageRef,
474
+ src: imageSrc,
475
+ width: imageSize.width,
476
+ height: imageSize.height
477
+ });
478
+ };
479
+ var GhostDropImage = (props) => {
480
+ const {
481
+ onDrop = noop,
482
+ onUploadFinish = noop,
483
+ uploader,
484
+ waitTimeAfterFinish = 2e3,
485
+ className = "",
486
+ children,
487
+ placeholder
488
+ } = props;
489
+ const [coverVisible, setCoverVisible] = (0, import_react14.useState)(false);
490
+ const [imageVisible, setImageVisible] = (0, import_react14.useState)(false);
491
+ const handleDocDragEnter = (0, import_react13.useCallback)(() => {
492
+ setCoverVisible(true);
493
+ }, []);
494
+ const {
495
+ handleDragLeave,
496
+ handleDragOver,
497
+ handleDrop,
498
+ imageRef,
499
+ imageSize,
500
+ imageSrc,
501
+ reset
502
+ } = useDropImage({
503
+ onImageLoad: () => {
504
+ setImageVisible(true);
505
+ },
506
+ onDrop: async (e, file) => {
507
+ onDrop(e, file);
508
+ setCoverVisible(false);
509
+ const result = await uploader(file);
510
+ await wait(waitTimeAfterFinish);
511
+ onUploadFinish(result);
512
+ setImageVisible(false);
513
+ reset();
514
+ }
515
+ });
516
+ (0, import_react13.useEffect)(() => {
517
+ document.addEventListener("dragenter", handleDocDragEnter);
518
+ return () => {
519
+ document.removeEventListener("dragenter", handleDocDragEnter);
520
+ };
521
+ }, []);
522
+ const coverCls = (0, import_classnames6.default)("fixed", "top-0", "left-0", "h-full", "w-full", {
523
+ "lqip-blur": coverVisible,
524
+ "z-[999]": coverVisible,
525
+ block: coverVisible,
526
+ hidden: !coverVisible
527
+ });
528
+ return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement("div", {
529
+ className: coverCls,
530
+ onDragLeave: () => {
531
+ handleDragLeave();
532
+ setCoverVisible(false);
533
+ },
534
+ onDragOver: handleDragOver,
535
+ onDrop: handleDrop
536
+ }), !imageVisible && placeholder, children ? children({
537
+ visible: imageVisible,
538
+ imageRef,
539
+ imageSize,
540
+ imageSrc
541
+ }) : /* @__PURE__ */ import_react13.default.createElement(ImagePreviewer, {
542
+ className,
543
+ visible: imageVisible,
544
+ imageRef,
545
+ imageSrc,
546
+ imageSize
547
+ }));
548
+ };
458
549
  var DropImage = (props) => {
459
550
  const {
460
551
  uploader,
@@ -465,11 +556,16 @@ var DropImage = (props) => {
465
556
  placeholder = "",
466
557
  className = "",
467
558
  onUploadFinish = noop,
559
+ ghost,
560
+ children,
468
561
  dropAreaStyle = {
469
562
  width: 300,
470
563
  height: 300
471
564
  }
472
565
  } = props;
566
+ if (ghost) {
567
+ return /* @__PURE__ */ import_react13.default.createElement(GhostDropImage, __spreadValues({}, props));
568
+ }
473
569
  const [showImagePreviewer, setShowImagePreviewer] = (0, import_react14.useState)(false);
474
570
  const {
475
571
  handleDragLeave,
@@ -508,20 +604,35 @@ var DropImage = (props) => {
508
604
  onDragOver: handleDragOver,
509
605
  onDrop: handleDrop,
510
606
  style: getDropAreaStyle()
511
- }, /* @__PURE__ */ import_react13.default.createElement("img", {
512
- className: (0, import_classnames6.default)("max-w-[100%]", "h-[auto]", "duration-300", "transition-opacity", "opacity-100", {
513
- "opacity-0": !showImagePreviewer
514
- }),
515
- ref: imageRef,
516
- src: imageSrc,
517
- width: imageSize.width,
518
- height: imageSize.height
607
+ }, children ? children({
608
+ visible: showImagePreviewer,
609
+ imageRef,
610
+ imageSize,
611
+ imageSrc
612
+ }) : /* @__PURE__ */ import_react13.default.createElement(ImagePreviewer, {
613
+ visible: showImagePreviewer,
614
+ imageRef,
615
+ imageSrc,
616
+ imageSize
519
617
  }), !imageSrc && placeholder);
520
618
  };
619
+
620
+ // src/blink-dot/BlinkDot.tsx
621
+ var import_classnames7 = __toESM(require("classnames"));
622
+ var import_react15 = __toESM(require("react"));
623
+ var BlinkDot = (props) => {
624
+ const { className } = props;
625
+ return /* @__PURE__ */ import_react15.default.createElement("span", {
626
+ className: (0, import_classnames7.default)("inline-flex h-2 w-2 justify-center items-center relative", className)
627
+ }, /* @__PURE__ */ import_react15.default.createElement("span", {
628
+ className: "animate-ping-fast absolute inline-flex h-full w-full rounded-full bg-red-600"
629
+ }));
630
+ };
521
631
  module.exports = __toCommonJS(src_exports);
522
632
  // Annotate the CommonJS export names for ESM import in node:
523
633
  0 && (module.exports = {
524
634
  Article,
635
+ BlinkDot,
525
636
  Breadcrumb,
526
637
  Button,
527
638
  ButtonType,
package/dist/index.mjs CHANGED
@@ -305,7 +305,10 @@ var Skeleton = (props) => {
305
305
 
306
306
  // src/drop-image/DropImage.tsx
307
307
  import cls from "classnames";
308
- import React13 from "react";
308
+ import React13, {
309
+ useEffect as useEffect2,
310
+ useCallback as useCallback2
311
+ } from "react";
309
312
  import { useState as useState3 } from "react";
310
313
 
311
314
  // src/drop-image/utils.ts
@@ -408,6 +411,96 @@ var useDropImage = (params) => {
408
411
  };
409
412
 
410
413
  // src/drop-image/DropImage.tsx
414
+ var ImagePreviewer = (props) => {
415
+ const {
416
+ visible: showImagePreviewer,
417
+ imageRef,
418
+ imageSize,
419
+ imageSrc,
420
+ className
421
+ } = props;
422
+ return /* @__PURE__ */ React13.createElement("img", {
423
+ className: cls(className, "max-w-[100%]", "h-[auto]", "duration-300", "transition-opacity", "opacity-100", {
424
+ "opacity-0": !showImagePreviewer,
425
+ "!m-0": !showImagePreviewer,
426
+ "!p-0": !showImagePreviewer
427
+ }),
428
+ ref: imageRef,
429
+ src: imageSrc,
430
+ width: imageSize.width,
431
+ height: imageSize.height
432
+ });
433
+ };
434
+ var GhostDropImage = (props) => {
435
+ const {
436
+ onDrop = noop,
437
+ onUploadFinish = noop,
438
+ uploader,
439
+ waitTimeAfterFinish = 2e3,
440
+ className = "",
441
+ children,
442
+ placeholder
443
+ } = props;
444
+ const [coverVisible, setCoverVisible] = useState3(false);
445
+ const [imageVisible, setImageVisible] = useState3(false);
446
+ const handleDocDragEnter = useCallback2(() => {
447
+ setCoverVisible(true);
448
+ }, []);
449
+ const {
450
+ handleDragLeave,
451
+ handleDragOver,
452
+ handleDrop,
453
+ imageRef,
454
+ imageSize,
455
+ imageSrc,
456
+ reset
457
+ } = useDropImage({
458
+ onImageLoad: () => {
459
+ setImageVisible(true);
460
+ },
461
+ onDrop: async (e, file) => {
462
+ onDrop(e, file);
463
+ setCoverVisible(false);
464
+ const result = await uploader(file);
465
+ await wait(waitTimeAfterFinish);
466
+ onUploadFinish(result);
467
+ setImageVisible(false);
468
+ reset();
469
+ }
470
+ });
471
+ useEffect2(() => {
472
+ document.addEventListener("dragenter", handleDocDragEnter);
473
+ return () => {
474
+ document.removeEventListener("dragenter", handleDocDragEnter);
475
+ };
476
+ }, []);
477
+ const coverCls = cls("fixed", "top-0", "left-0", "h-full", "w-full", {
478
+ "lqip-blur": coverVisible,
479
+ "z-[999]": coverVisible,
480
+ block: coverVisible,
481
+ hidden: !coverVisible
482
+ });
483
+ return /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement("div", {
484
+ className: coverCls,
485
+ onDragLeave: () => {
486
+ handleDragLeave();
487
+ setCoverVisible(false);
488
+ },
489
+ onDragOver: handleDragOver,
490
+ onDrop: handleDrop
491
+ }), !imageVisible && placeholder, children ? children({
492
+ visible: imageVisible,
493
+ imageRef,
494
+ imageSize,
495
+ imageSrc
496
+ }) : /* @__PURE__ */ React13.createElement(ImagePreviewer, {
497
+ className,
498
+ visible: imageVisible,
499
+ imageRef,
500
+ imageSrc,
501
+ imageSize
502
+ }));
503
+ };
411
504
  var DropImage = (props) => {
412
505
  const {
413
506
  uploader,
@@ -418,11 +511,16 @@ var DropImage = (props) => {
418
511
  placeholder = "",
419
512
  className = "",
420
513
  onUploadFinish = noop,
514
+ ghost,
515
+ children,
421
516
  dropAreaStyle = {
422
517
  width: 300,
423
518
  height: 300
424
519
  }
425
520
  } = props;
521
+ if (ghost) {
522
+ return /* @__PURE__ */ React13.createElement(GhostDropImage, __spreadValues({}, props));
523
+ }
426
524
  const [showImagePreviewer, setShowImagePreviewer] = useState3(false);
427
525
  const {
428
526
  handleDragLeave,
@@ -461,18 +559,33 @@ var DropImage = (props) => {
461
559
  onDragOver: handleDragOver,
462
560
  onDrop: handleDrop,
463
561
  style: getDropAreaStyle()
464
- }, /* @__PURE__ */ React13.createElement("img", {
465
- className: cls("max-w-[100%]", "h-[auto]", "duration-300", "transition-opacity", "opacity-100", {
466
- "opacity-0": !showImagePreviewer
467
- }),
468
- ref: imageRef,
469
- src: imageSrc,
470
- width: imageSize.width,
471
- height: imageSize.height
562
+ }, children ? children({
563
+ visible: showImagePreviewer,
564
+ imageRef,
565
+ imageSize,
566
+ imageSrc
567
+ }) : /* @__PURE__ */ React13.createElement(ImagePreviewer, {
568
+ visible: showImagePreviewer,
569
+ imageRef,
570
+ imageSrc,
571
+ imageSize
472
572
  }), !imageSrc && placeholder);
473
573
  };
574
+
575
+ // src/blink-dot/BlinkDot.tsx
576
+ import classNames6 from "classnames";
577
+ import React14 from "react";
578
+ var BlinkDot = (props) => {
579
+ const { className } = props;
580
+ return /* @__PURE__ */ React14.createElement("span", {
581
+ className: classNames6("inline-flex h-2 w-2 justify-center items-center relative", className)
582
+ }, /* @__PURE__ */ React14.createElement("span", {
583
+ className: "animate-ping-fast absolute inline-flex h-full w-full rounded-full bg-red-600"
584
+ }));
585
+ };
474
586
  export {
475
587
  Article,
588
+ BlinkDot,
476
589
  Breadcrumb,
477
590
  Button,
478
591
  ButtonType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/components",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",