kitzo 2.1.16 → 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 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.16/dist/kitzo.umd.min.js"></script>
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.
@@ -0,0 +1,2 @@
1
+ export * from './types/toast';
2
+ export * from './types/tooltip';
@@ -554,12 +554,23 @@ function ToastContainer(props) {
554
554
 
555
555
  const tooltipStyles = `
556
556
  .kitzo-react-tooltip-content-default-style {
557
- font-family: sans-serif;
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: 6px;
562
- padding-inline: 10px;
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-duration: 120ms, 50ms;
573
- transition-property: scale opacity;
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
- translate: -50% 0;
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
- translate: 0 -50%;
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
- translate: -50% 0;
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
- translate: 0 -50%;
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
- scale: 1;
632
+ transform: translateX(-50%) translateY(0) scale(1);
623
633
  opacity: 1;
624
634
  }
625
635
  .kitzo-react-tooltip-wrapper.right {
626
- scale: 1;
636
+ transform: translateX(0) translateY(-50%) scale(1);
627
637
  opacity: 1;
628
638
  }
629
639
  .kitzo-react-tooltip-wrapper.bottom {
630
- scale: 1;
640
+ transform: translateX(-50%) translateY(0) scale(1);
631
641
  opacity: 1;
632
642
  }
633
643
  .kitzo-react-tooltip-wrapper.left {
634
- scale: 1;
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
- position = '',
659
- offset = 8,
660
- hideOnTouch = true,
668
+ tooltipOptions = {},
661
669
  children
662
670
  }) {
663
- if (typeof hideOnTouch !== 'boolean') hideOnTouch = true;
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.trim().toLowerCase())
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
- function useScrollRestoration(path, key, options = {}) {
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,62 +1,73 @@
1
- {
2
- "name": "kitzo",
3
- "version": "2.1.16",
4
- "description": "A lightweight JavaScript UI micro-library.",
5
- "type": "module",
6
- "main": "./dist/kitzo.umd.js",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/kitzo.esm.js",
10
- "require": "./dist/kitzo.umd.js",
11
- "types": "./dist/kitzo.d.ts"
12
- },
13
- "./react": {
14
- "import": "./dist/react.esm.js",
15
- "types": "./dist/react.d.ts"
16
- }
17
- },
18
- "files": [
19
- "dist"
20
- ],
21
- "scripts": {
22
- "dev": "vite",
23
- "build": "rollup -c",
24
- "preview": "vite preview"
25
- },
26
- "keywords": [
27
- "tooltip",
28
- "ripple",
29
- "copy-button",
30
- "micro-library",
31
- "modular",
32
- "ui",
33
- "javascript",
34
- "react",
35
- "kitzo"
36
- ],
37
- "author": "Riyad",
38
- "license": "MIT",
39
- "repository": {
40
- "type": "git",
41
- "url": "https://github.com/riyad-96/kitzo"
42
- },
43
- "homepage": "https://github.com/riyad-96/kitzo#readme",
44
- "devDependencies": {
45
- "@babel/core": "^7.28.4",
46
- "@babel/preset-react": "^7.27.1",
47
- "@rollup/plugin-babel": "^6.0.4",
48
- "@rollup/plugin-commonjs": "^28.0.6",
49
- "@rollup/plugin-node-resolve": "^16.0.1",
50
- "@types/react": "^19.2.6",
51
- "@vitejs/plugin-react": "^5.0.4",
52
- "prettier": "^3.6.2",
53
- "react": "^19.1.1",
54
- "react-dom": "^19.1.1",
55
- "rollup": "^4.46.2",
56
- "vite": "^7.0.4"
57
- },
58
- "peerDependencies": {
59
- "react": ">=17",
60
- "react-dom": ">=17"
61
- }
62
- }
1
+ {
2
+ "name": "kitzo",
3
+ "version": "2.1.18",
4
+ "description": "A lightweight JavaScript & React UI micro-library.",
5
+ "type": "module",
6
+ "main": "./dist/vanilla/vanilla.umd.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/vanilla/vanilla.d.ts",
10
+ "import": "./dist/vanilla/vanilla.esm.js",
11
+ "require": "./dist/vanilla/vanilla.umd.js"
12
+ },
13
+ "./react": {
14
+ "types": "./dist/react/index.d.ts",
15
+ "import": "./dist/react/react.esm.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "dev": "vite",
23
+ "build": "rollup -c",
24
+ "build-test": "vite buil",
25
+ "lint": "eslint .",
26
+ "preview": "vite preview"
27
+ },
28
+ "keywords": [
29
+ "tooltip",
30
+ "ripple",
31
+ "copy-button",
32
+ "micro-library",
33
+ "modular",
34
+ "ui",
35
+ "javascript",
36
+ "react",
37
+ "kitzo"
38
+ ],
39
+ "author": "Riyad",
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/riyad-96/kitzo"
44
+ },
45
+ "homepage": "https://github.com/riyad-96/kitzo#readme",
46
+ "devDependencies": {
47
+ "@babel/core": "^7.28.5",
48
+ "@babel/preset-react": "^7.28.5",
49
+ "@eslint/js": "^9.39.1",
50
+ "@rollup/plugin-babel": "^6.1.0",
51
+ "@rollup/plugin-commonjs": "^29.0.0",
52
+ "@rollup/plugin-node-resolve": "^16.0.3",
53
+ "@tailwindcss/vite": "^4.1.17",
54
+ "@types/react": "^19.2.5",
55
+ "@types/react-dom": "^19.2.3",
56
+ "@vitejs/plugin-react": "^5.1.1",
57
+ "eslint": "^9.39.1",
58
+ "eslint-plugin-react-hooks": "^7.0.1",
59
+ "eslint-plugin-react-refresh": "^0.4.24",
60
+ "globals": "^16.5.0",
61
+ "prettier": "^3.6.2",
62
+ "prettier-plugin-tailwindcss": "^0.7.1",
63
+ "react": "^19.2.0",
64
+ "react-dom": "^19.2.0",
65
+ "react-router-dom": "^7.9.6",
66
+ "tailwindcss": "^4.1.17",
67
+ "vite": "^7.2.4"
68
+ },
69
+ "peerDependencies": {
70
+ "react": ">=19",
71
+ "react-dom": ">=19"
72
+ }
73
+ }
package/dist/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>;
File without changes
File without changes
File without changes