kitzo 2.1.17 → 2.1.18
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 +1 -1
- package/dist/react/index.d.ts +2 -0
- package/dist/react/react.esm.js +46 -116
- package/dist/react/types/toast.d.ts +46 -0
- package/dist/react/types/tooltip.d.ts +32 -0
- package/package.json +2 -2
- package/dist/react/react.d.ts +0 -75
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ npm i kitzo
|
|
|
26
26
|
or
|
|
27
27
|
|
|
28
28
|
```javascript
|
|
29
|
-
<script src="https://cdn.jsdelivr.net/npm/kitzo@2.1.
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/kitzo@2.1.18/dist/kitzo.umd.min.js"></script>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
> Vanilla: Attach this script tag in the html head tag and you are good to go.
|
package/dist/react/react.esm.js
CHANGED
|
@@ -554,12 +554,23 @@ function ToastContainer(props) {
|
|
|
554
554
|
|
|
555
555
|
const tooltipStyles = `
|
|
556
556
|
.kitzo-react-tooltip-content-default-style {
|
|
557
|
-
font-family:
|
|
557
|
+
font-family:
|
|
558
|
+
system-ui,
|
|
559
|
+
-apple-system,
|
|
560
|
+
BlinkMacSystemFont,
|
|
561
|
+
'Segoe UI',
|
|
562
|
+
Roboto,
|
|
563
|
+
Oxygen,
|
|
564
|
+
Ubuntu,
|
|
565
|
+
Cantarell,
|
|
566
|
+
'Open Sans',
|
|
567
|
+
'Helvetica Neue',
|
|
568
|
+
sans-serif;
|
|
558
569
|
font-size: 0.875rem;
|
|
559
570
|
background-color: hsl(0, 0%, 15%);
|
|
560
571
|
color: hsl(0, 0%, 95%);
|
|
561
|
-
padding-block:
|
|
562
|
-
padding-inline:
|
|
572
|
+
padding-block: 0.25rem;
|
|
573
|
+
padding-inline: 0.5rem;
|
|
563
574
|
border-radius: 0.325rem;
|
|
564
575
|
|
|
565
576
|
@media (prefers-color-scheme: dark) {
|
|
@@ -569,8 +580,11 @@ const tooltipStyles = `
|
|
|
569
580
|
}
|
|
570
581
|
|
|
571
582
|
.kitzo-react-tooltip-wrapper {
|
|
572
|
-
transition-
|
|
573
|
-
|
|
583
|
+
--tooltip-transition-delay: calc(var(--delay) * 1ms);
|
|
584
|
+
will-change: transform, opacity;
|
|
585
|
+
transition:
|
|
586
|
+
transform 110ms var(--tooltip-transition-delay),
|
|
587
|
+
opacity 110ms var(--tooltip-transition-delay);
|
|
574
588
|
}
|
|
575
589
|
|
|
576
590
|
.kitzo-react-tooltip-wrapper.top {
|
|
@@ -578,8 +592,7 @@ const tooltipStyles = `
|
|
|
578
592
|
|
|
579
593
|
bottom: calc(var(--tooltip-offset) + 100%);
|
|
580
594
|
left: 50%;
|
|
581
|
-
|
|
582
|
-
scale: 0.7;
|
|
595
|
+
transform: translateX(-50%) translateY(0) scale(0.8);
|
|
583
596
|
opacity: 0;
|
|
584
597
|
transform-origin: bottom;
|
|
585
598
|
}
|
|
@@ -589,8 +602,7 @@ const tooltipStyles = `
|
|
|
589
602
|
|
|
590
603
|
left: calc(var(--tooltip-offset) + 100%);
|
|
591
604
|
top: 50%;
|
|
592
|
-
|
|
593
|
-
scale: 0.7;
|
|
605
|
+
transform: translateX(0) translateY(-50%) scale(0.8);
|
|
594
606
|
opacity: 0;
|
|
595
607
|
transform-origin: left;
|
|
596
608
|
}
|
|
@@ -600,8 +612,7 @@ const tooltipStyles = `
|
|
|
600
612
|
|
|
601
613
|
top: calc(var(--tooltip-offset) + 100%);
|
|
602
614
|
left: 50%;
|
|
603
|
-
|
|
604
|
-
scale: 0.7;
|
|
615
|
+
transform: translateX(-50%) translateY(0) scale(0.8);
|
|
605
616
|
opacity: 0;
|
|
606
617
|
transform-origin: top;
|
|
607
618
|
}
|
|
@@ -611,27 +622,26 @@ const tooltipStyles = `
|
|
|
611
622
|
|
|
612
623
|
right: calc(var(--tooltip-offset) + 100%);
|
|
613
624
|
top: 50%;
|
|
614
|
-
|
|
615
|
-
scale: 0.7;
|
|
625
|
+
transform: translateX(0) translateY(-50%) scale(0.8);
|
|
616
626
|
opacity: 0;
|
|
617
627
|
transform-origin: right;
|
|
618
628
|
}
|
|
619
629
|
|
|
620
630
|
.kitzo-react-tooltip-root:hover {
|
|
621
631
|
.kitzo-react-tooltip-wrapper.top {
|
|
622
|
-
|
|
632
|
+
transform: translateX(-50%) translateY(0) scale(1);
|
|
623
633
|
opacity: 1;
|
|
624
634
|
}
|
|
625
635
|
.kitzo-react-tooltip-wrapper.right {
|
|
626
|
-
|
|
636
|
+
transform: translateX(0) translateY(-50%) scale(1);
|
|
627
637
|
opacity: 1;
|
|
628
638
|
}
|
|
629
639
|
.kitzo-react-tooltip-wrapper.bottom {
|
|
630
|
-
|
|
640
|
+
transform: translateX(-50%) translateY(0) scale(1);
|
|
631
641
|
opacity: 1;
|
|
632
642
|
}
|
|
633
643
|
.kitzo-react-tooltip-wrapper.left {
|
|
634
|
-
|
|
644
|
+
transform: translateX(0) translateY(-50%) scale(1);
|
|
635
645
|
opacity: 1;
|
|
636
646
|
}
|
|
637
647
|
}
|
|
@@ -644,9 +654,9 @@ const tooltipStyles = `
|
|
|
644
654
|
document.head.appendChild(styleTag);
|
|
645
655
|
}
|
|
646
656
|
})();
|
|
657
|
+
const allowedPositions = ['top', 'right', 'bottom', 'left'];
|
|
647
658
|
function getPositionBasedClassName(position) {
|
|
648
659
|
let defaultClass = 'kitzo-react-tooltip-wrapper';
|
|
649
|
-
const allowedPositions = ['top', 'right', 'bottom', 'left'];
|
|
650
660
|
if (allowedPositions.includes(position)) {
|
|
651
661
|
return defaultClass + ' ' + position;
|
|
652
662
|
} else {
|
|
@@ -655,26 +665,29 @@ function getPositionBasedClassName(position) {
|
|
|
655
665
|
}
|
|
656
666
|
function Tooltip({
|
|
657
667
|
content = 'Tooltip',
|
|
658
|
-
|
|
659
|
-
offset = 8,
|
|
660
|
-
hideOnTouch = true,
|
|
668
|
+
tooltipOptions = {},
|
|
661
669
|
children
|
|
662
670
|
}) {
|
|
663
|
-
|
|
671
|
+
const {
|
|
672
|
+
position = 'top',
|
|
673
|
+
offset = 8,
|
|
674
|
+
hideOnTouch = true,
|
|
675
|
+
delay = 0
|
|
676
|
+
} = tooltipOptions ?? {};
|
|
677
|
+
const finalOptions = {
|
|
678
|
+
position: typeof position === 'string' ? position.trim().toLowerCase() : 'top',
|
|
679
|
+
offset: !isNaN(Number(offset)) ? Number(offset) : 8,
|
|
680
|
+
delay: !isNaN(Number(delay)) ? Number(delay) : 0,
|
|
681
|
+
hideOnTouch: typeof hideOnTouch === 'boolean' ? hideOnTouch : true
|
|
682
|
+
};
|
|
664
683
|
const isTouch = window.matchMedia('(pointer: coarse)').matches;
|
|
665
|
-
if (isTouch && hideOnTouch) return children;
|
|
666
|
-
|
|
667
|
-
// sanitize props
|
|
668
|
-
if (typeof position !== 'string') {
|
|
669
|
-
console.warn(`[kitzo/react]: Tooltip position ignored due to invalid data type.`);
|
|
670
|
-
position = 'top';
|
|
671
|
-
}
|
|
672
|
-
if (isNaN(Number(offset))) offset = 8;
|
|
684
|
+
if (isTouch && finalOptions.hideOnTouch) return children;
|
|
673
685
|
return /*#__PURE__*/React.createElement("div", {
|
|
674
686
|
style: {
|
|
675
687
|
position: 'relative',
|
|
676
688
|
width: 'fit-content',
|
|
677
|
-
'--offset': Math.max(0, offset)
|
|
689
|
+
'--offset': Math.max(0, finalOptions.offset),
|
|
690
|
+
'--delay': Math.max(0, finalOptions.delay)
|
|
678
691
|
},
|
|
679
692
|
className: "kitzo-react-tooltip-root"
|
|
680
693
|
}, children, /*#__PURE__*/React.createElement("div", {
|
|
@@ -684,93 +697,10 @@ function Tooltip({
|
|
|
684
697
|
pointerEvents: 'none'
|
|
685
698
|
},
|
|
686
699
|
tabIndex: -1,
|
|
687
|
-
className: getPositionBasedClassName(position
|
|
700
|
+
className: getPositionBasedClassName(finalOptions.position)
|
|
688
701
|
}, typeof content === 'string' || typeof content === 'number' ? /*#__PURE__*/React.createElement("div", {
|
|
689
702
|
className: "kitzo-react-tooltip-content-default-style"
|
|
690
703
|
}, content) : /*#__PURE__*/React.createElement(React.Fragment, null, content)));
|
|
691
704
|
}
|
|
692
705
|
|
|
693
|
-
|
|
694
|
-
if (!path || typeof path !== 'object' && typeof path !== 'string') {
|
|
695
|
-
throw new Error('kitzo/react: useScrollRestoration(path, ...) expect location object from the react useLocation hook or unique path string(location.pathname)');
|
|
696
|
-
}
|
|
697
|
-
if (!key || typeof key !== 'string' && typeof key !== 'number') {
|
|
698
|
-
throw new Error('kitzo/react: useScrollRestoration(..., key) expect unique string or number');
|
|
699
|
-
}
|
|
700
|
-
const pathname = typeof path === 'object' ? path.pathname : path;
|
|
701
|
-
const behavior = options?.behavior ? options.behavior : 'instant';
|
|
702
|
-
const delay = options?.delay ? isNaN(Number(options.delay)) ? 0 : Number(options.delay) : 0;
|
|
703
|
-
|
|
704
|
-
// hook management
|
|
705
|
-
const ref = useRef(null);
|
|
706
|
-
const history = useRef(new Map());
|
|
707
|
-
|
|
708
|
-
// hook logic
|
|
709
|
-
useEffect(() => {
|
|
710
|
-
const element = ref.current;
|
|
711
|
-
const target = element || window;
|
|
712
|
-
const isWindow = target === window;
|
|
713
|
-
const mapKey = `${pathname}::${key}`;
|
|
714
|
-
const saved = history.current.get(mapKey);
|
|
715
|
-
const restore = () => {
|
|
716
|
-
if (!saved) return;
|
|
717
|
-
if (isWindow) {
|
|
718
|
-
window.scrollTo({
|
|
719
|
-
top: saved.top,
|
|
720
|
-
left: saved.left,
|
|
721
|
-
behavior
|
|
722
|
-
});
|
|
723
|
-
} else if (element) {
|
|
724
|
-
element.scrollTo({
|
|
725
|
-
top: saved.top,
|
|
726
|
-
left: saved.left,
|
|
727
|
-
behavior
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
if (saved) {
|
|
732
|
-
if (delay > 0) {
|
|
733
|
-
const timeoutId = setTimeout(restore, delay);
|
|
734
|
-
return () => clearTimeout(timeoutId);
|
|
735
|
-
} else {
|
|
736
|
-
restore();
|
|
737
|
-
}
|
|
738
|
-
} else {
|
|
739
|
-
if (isWindow) {
|
|
740
|
-
window.scrollTo({
|
|
741
|
-
top: 0,
|
|
742
|
-
left: 0,
|
|
743
|
-
behavior: 'auto'
|
|
744
|
-
});
|
|
745
|
-
} else if (element) {
|
|
746
|
-
element.scrollTo({
|
|
747
|
-
top: 0,
|
|
748
|
-
left: 0,
|
|
749
|
-
behavior: 'auto'
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
let timeoutId = null;
|
|
754
|
-
const save = () => {
|
|
755
|
-
clearTimeout(timeoutId);
|
|
756
|
-
timeoutId = setTimeout(() => {
|
|
757
|
-
const top = isWindow ? window.scrollY : element?.scrollTop ?? 0;
|
|
758
|
-
const left = isWindow ? window.scrollX : element?.scrollLeft ?? 0;
|
|
759
|
-
history.current.set(mapKey, {
|
|
760
|
-
top,
|
|
761
|
-
left
|
|
762
|
-
});
|
|
763
|
-
}, 50);
|
|
764
|
-
};
|
|
765
|
-
target.addEventListener('scroll', save, {
|
|
766
|
-
passive: true
|
|
767
|
-
});
|
|
768
|
-
return () => {
|
|
769
|
-
target.removeEventListener('scroll', save);
|
|
770
|
-
clearTimeout(timeoutId);
|
|
771
|
-
};
|
|
772
|
-
}, [pathname, key, behavior, delay]);
|
|
773
|
-
return ref;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
export { ToastContainer, Tooltip, toast, useScrollRestoration };
|
|
706
|
+
export { ToastContainer, Tooltip, toast };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ReactNode, CSSProperties, JSX } from 'react';
|
|
2
|
+
|
|
3
|
+
//! Toast API types declaration
|
|
4
|
+
type Positions =
|
|
5
|
+
| 'top-left'
|
|
6
|
+
| 'top-center'
|
|
7
|
+
| 'top-right'
|
|
8
|
+
| 'bottom-left'
|
|
9
|
+
| 'bottom-center'
|
|
10
|
+
| 'bottom-right';
|
|
11
|
+
|
|
12
|
+
type ToastOptions = {
|
|
13
|
+
position?: Positions;
|
|
14
|
+
duration?: number;
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
showIcon?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type CustomContent = string | ReactNode | ((dismiss: () => void) => ReactNode);
|
|
20
|
+
|
|
21
|
+
type ToastAPI = {
|
|
22
|
+
(text: string, options?: ToastOptions): void;
|
|
23
|
+
|
|
24
|
+
success(text: string, options?: ToastOptions): void;
|
|
25
|
+
|
|
26
|
+
error(text: string, options?: ToastOptions): void;
|
|
27
|
+
|
|
28
|
+
promise<T>(
|
|
29
|
+
callback: Promise<T>,
|
|
30
|
+
msgs: {
|
|
31
|
+
loading: string;
|
|
32
|
+
success: string | ((res: T) => string | Promise<string>);
|
|
33
|
+
error: string | ((err: any) => string | Promise<string>);
|
|
34
|
+
},
|
|
35
|
+
options?: ToastOptions,
|
|
36
|
+
): void;
|
|
37
|
+
|
|
38
|
+
custom(
|
|
39
|
+
content: CustomContent,
|
|
40
|
+
options?: { duration?: number; exitDelay?: number; position?: Positions },
|
|
41
|
+
): void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export declare const toast: ToastAPI;
|
|
45
|
+
|
|
46
|
+
export declare function ToastContainer(props: { position?: Positions; gap?: number }): JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JSX, PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type TooltipOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Default position: 'top'
|
|
6
|
+
*/
|
|
7
|
+
position?: 'top' | 'right' | 'bottom' | 'left';
|
|
8
|
+
/**
|
|
9
|
+
* Default offset: 8
|
|
10
|
+
*/
|
|
11
|
+
offset?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Default delay: 0
|
|
14
|
+
*/
|
|
15
|
+
delay?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Default hideOnTouch: true
|
|
18
|
+
*/
|
|
19
|
+
hideOnTouch?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type TooltipCoreProps = {
|
|
23
|
+
/**
|
|
24
|
+
* content is necessary
|
|
25
|
+
*/
|
|
26
|
+
content: ReactNode;
|
|
27
|
+
tooltipOptions?: TooltipOptions;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type TooltipProps = PropsWithChildren<TooltipCoreProps>;
|
|
31
|
+
|
|
32
|
+
export declare function Tooltip(props: TooltipProps): JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kitzo",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.18",
|
|
4
4
|
"description": "A lightweight JavaScript & React UI micro-library.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/vanilla/vanilla.umd.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"require": "./dist/vanilla/vanilla.umd.js"
|
|
12
12
|
},
|
|
13
13
|
"./react": {
|
|
14
|
-
"types": "./dist/react/
|
|
14
|
+
"types": "./dist/react/index.d.ts",
|
|
15
15
|
"import": "./dist/react/react.esm.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
package/dist/react/react.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { ReactNode, CSSProperties, JSX, PropsWithChildren, RefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
//! Toast API types declaration
|
|
4
|
-
export type Positions =
|
|
5
|
-
| 'top-left'
|
|
6
|
-
| 'top-center'
|
|
7
|
-
| 'top-right'
|
|
8
|
-
| 'bottom-left'
|
|
9
|
-
| 'bottom-center'
|
|
10
|
-
| 'bottom-right';
|
|
11
|
-
|
|
12
|
-
export interface ToastOptions {
|
|
13
|
-
position?: Positions;
|
|
14
|
-
duration?: number;
|
|
15
|
-
style?: CSSProperties;
|
|
16
|
-
showIcon?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type CustomContent = string | ReactNode | ((dismiss: () => void) => ReactNode);
|
|
20
|
-
|
|
21
|
-
export interface ToastAPI {
|
|
22
|
-
(text?: string, options?: ToastOptions): void;
|
|
23
|
-
|
|
24
|
-
success(text?: string, options?: ToastOptions): void;
|
|
25
|
-
|
|
26
|
-
error(text?: string, options?: ToastOptions): void;
|
|
27
|
-
|
|
28
|
-
promise<T>(
|
|
29
|
-
callback: Promise<T>,
|
|
30
|
-
msgs?: {
|
|
31
|
-
loading?: string;
|
|
32
|
-
success?: string | ((res: T) => string | Promise<string>);
|
|
33
|
-
error?: string | ((err: any) => string | Promise<string>);
|
|
34
|
-
},
|
|
35
|
-
options?: ToastOptions,
|
|
36
|
-
): void;
|
|
37
|
-
|
|
38
|
-
custom(
|
|
39
|
-
content: CustomContent,
|
|
40
|
-
options?: { duration?: number; exitDelay?: number; position?: Positions },
|
|
41
|
-
): void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export declare const toast: ToastAPI;
|
|
45
|
-
|
|
46
|
-
export declare function ToastContainer(props: { position?: Positions; gap?: number }): JSX.Element;
|
|
47
|
-
|
|
48
|
-
//! Tooltip API types declaration
|
|
49
|
-
export interface TooltipCoreProps {
|
|
50
|
-
content: string | ReactNode;
|
|
51
|
-
position?: 'top' | 'right' | 'bottom' | 'left';
|
|
52
|
-
offset?: number;
|
|
53
|
-
hideOnTouch?: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type TooltipProps = PropsWithChildren<TooltipCoreProps>;
|
|
57
|
-
|
|
58
|
-
export declare function Tooltip(props: TooltipProps): JSX.Element;
|
|
59
|
-
|
|
60
|
-
//! useScrollRestoration hook types declaration
|
|
61
|
-
type ScrollHookOptions = {
|
|
62
|
-
behavior?: 'auto' | 'smooth' | 'instant';
|
|
63
|
-
delay?: number;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
type LocationLike = {
|
|
67
|
-
pathname: string;
|
|
68
|
-
[key: string]: any;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export declare function useScrollRestoration<T extends HTMLElement = HTMLDivElement>(
|
|
72
|
-
path: LocationLike | string,
|
|
73
|
-
key: string | number,
|
|
74
|
-
options?: ScrollHookOptions,
|
|
75
|
-
): RefObject<T | null>;
|