@sohanemon/utils 4.0.14 → 4.0.15

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.
@@ -1,3 +1,3 @@
1
- export { Icon as Iconify } from '@iconify/react';
2
- export { MediaWrapper } from './media-wrapper';
3
- export { ResponsiveIndicator, ResponsiveIndicator as TailwindIndicator, } from './responsive-indicator';
1
+ export { Icon as Iconify } from "@iconify/react";
2
+ export { MediaWrapper } from "./media-wrapper";
3
+ export { ResponsiveIndicator, ResponsiveIndicator as TailwindIndicator, } from "./responsive-indicator";
@@ -1,4 +1,4 @@
1
- 'use client';
2
- export { Icon as Iconify } from '@iconify/react';
3
- export { MediaWrapper } from './media-wrapper';
4
- export { ResponsiveIndicator, ResponsiveIndicator as TailwindIndicator, } from './responsive-indicator';
1
+ "use client";
2
+ export { Icon as Iconify } from "@iconify/react";
3
+ export { MediaWrapper } from "./media-wrapper";
4
+ export { ResponsiveIndicator, ResponsiveIndicator as TailwindIndicator, } from "./responsive-indicator";
@@ -1,10 +1,8 @@
1
- import * as React from 'react';
2
- type BreakPoints = 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'max-sm' | 'max-md' | 'max-lg' | 'max-xl' | 'max-2xl';
3
- type MediaWrapperProps = React.ComponentProps<'div'> & {
1
+ import * as React from "react";
2
+ type BreakPoints = "sm" | "md" | "lg" | "xl" | "2xl" | "max-sm" | "max-md" | "max-lg" | "max-xl" | "max-2xl";
3
+ type MediaWrapperProps = React.ComponentProps<"div"> & {
4
4
  breakpoint: BreakPoints;
5
5
  as?: React.ElementType;
6
- fallback?: React.ElementType;
7
- classNameFallback?: string;
8
6
  };
9
- export declare function MediaWrapper({ breakpoint, as, fallback, classNameFallback, className: classNameOriginal, ...props }: MediaWrapperProps): any;
7
+ export declare function MediaWrapper({ breakpoint, as, ...props }: MediaWrapperProps): any;
10
8
  export {};
@@ -1,14 +1,10 @@
1
- 'use client';
1
+ "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import * as React from 'react';
4
- import { useMediaQuery } from '../hooks';
5
- export function MediaWrapper({ breakpoint, as = 'div', fallback = React.Fragment, classNameFallback, className: classNameOriginal, ...props }) {
6
- const overMedia = useMediaQuery(breakpoint.split('-').pop());
7
- const isMax = breakpoint.startsWith('max');
8
- const useFallback = overMedia === isMax;
9
- // Conditionally determining which component to render,
10
- // and what className should be passed to it.
11
- const Wrapper = useFallback ? fallback : as;
12
- const className = useFallback ? classNameFallback : classNameOriginal;
13
- return _jsx(Wrapper, { className: className, ...props });
3
+ import * as React from "react";
4
+ import { useMediaQuery } from "../hooks";
5
+ export function MediaWrapper({ breakpoint, as = "div", ...props }) {
6
+ const overMedia = useMediaQuery(breakpoint.split("-").pop());
7
+ const isMax = breakpoint.startsWith("max");
8
+ const Wrapper = overMedia === isMax ? React.Fragment : as;
9
+ return _jsx(Wrapper, { ...props });
14
10
  }
@@ -1,2 +1,2 @@
1
- import * as React from 'react';
1
+ import * as React from "react";
2
2
  export declare const ResponsiveIndicator: React.FC;
@@ -1,6 +1,6 @@
1
- 'use client';
1
+ "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import * as React from 'react';
3
+ import * as React from "react";
4
4
  export const ResponsiveIndicator = () => {
5
5
  const [viewportWidth, setViewportWidth] = React.useState(window.innerWidth);
6
6
  const [position, setPosition] = React.useState(0); // State to manage button position
@@ -8,60 +8,60 @@ export const ResponsiveIndicator = () => {
8
8
  const handleResize = () => {
9
9
  setViewportWidth(window.innerWidth);
10
10
  };
11
- window.addEventListener('resize', handleResize);
11
+ window.addEventListener("resize", handleResize);
12
12
  return () => {
13
- window.removeEventListener('resize', handleResize);
13
+ window.removeEventListener("resize", handleResize);
14
14
  };
15
15
  }, []);
16
16
  // Function to handle button click
17
17
  const handleClick = () => {
18
18
  setPosition((prevPosition) => (prevPosition + 1) % 4); // Cycle through positions
19
19
  };
20
- let text = '';
20
+ let text = "";
21
21
  if (viewportWidth < 640) {
22
- text = 'xs';
22
+ text = "xs";
23
23
  }
24
24
  else if (viewportWidth >= 640 && viewportWidth < 768) {
25
- text = 'sm';
25
+ text = "sm";
26
26
  }
27
27
  else if (viewportWidth >= 768 && viewportWidth < 1024) {
28
- text = 'md';
28
+ text = "md";
29
29
  }
30
30
  else if (viewportWidth >= 1024 && viewportWidth < 1280) {
31
- text = 'lg';
31
+ text = "lg";
32
32
  }
33
33
  else if (viewportWidth >= 1280 && viewportWidth < 1536) {
34
- text = 'xl';
34
+ text = "xl";
35
35
  }
36
36
  else {
37
- text = '2xl';
37
+ text = "2xl";
38
38
  }
39
39
  // Define positions
40
40
  const positions = [
41
- { bottom: '2rem', left: '2rem' },
42
- { bottom: '2rem', right: '2rem' },
43
- { top: '2rem', right: '2rem' },
44
- { top: '2rem', left: '2rem' }, // Top left
41
+ { bottom: "2rem", left: "2rem" }, // Bottom left
42
+ { bottom: "2rem", right: "2rem" }, // Bottom right
43
+ { top: "2rem", right: "2rem" }, // Top right
44
+ { top: "2rem", left: "2rem" }, // Top left
45
45
  ];
46
46
  const buttonStyle = {
47
- position: 'fixed',
47
+ position: "fixed",
48
48
  zIndex: 50,
49
- display: 'grid',
50
- height: '2.5rem',
51
- width: '2.5rem',
52
- borderRadius: '50%',
53
- placeContent: 'center',
54
- backgroundColor: '#2d3748',
55
- fontFamily: 'Courier New, Courier, monospace',
56
- fontSize: '1rem',
57
- color: '#ffffff',
58
- border: '2px solid #4a5568',
59
- boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
60
- padding: '0.5rem',
61
- transition: 'all 0.2s ease-in-out',
49
+ display: "grid",
50
+ height: "2.5rem",
51
+ width: "2.5rem",
52
+ borderRadius: "50%",
53
+ placeContent: "center",
54
+ backgroundColor: "#2d3748",
55
+ fontFamily: "Courier New, Courier, monospace",
56
+ fontSize: "1rem",
57
+ color: "#ffffff",
58
+ border: "2px solid #4a5568",
59
+ boxShadow: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
60
+ padding: "0.5rem",
61
+ transition: "all 0.2s ease-in-out",
62
62
  ...positions[position], // Apply the current position
63
63
  };
64
- if (process.env.NODE_ENV === 'production')
64
+ if (process.env.NODE_ENV === "production")
65
65
  return null;
66
66
  return (_jsx("button", { type: "button", style: buttonStyle, onClick: handleClick, children: text }));
67
67
  };
@@ -1,6 +1,4 @@
1
1
  import { type ClassValue } from 'clsx';
2
- import type * as React from 'react';
3
2
  export declare function cn(...inputs: ClassValue[]): string;
4
3
  export declare function isNavActive(href: string, path: string): boolean;
5
4
  export declare function cleanSrc(src: string): string;
6
- export declare const scrollTo: (containerSelector: string | React.RefObject<HTMLDivElement>, to: 'top' | 'bottom') => void;
@@ -12,21 +12,3 @@ export function cleanSrc(src) {
12
12
  return src.replace('/public/', '/');
13
13
  return src;
14
14
  }
15
- export const scrollTo = (containerSelector, to) => {
16
- let container;
17
- if (typeof containerSelector === 'string') {
18
- container = document.querySelector(containerSelector);
19
- }
20
- else if (containerSelector.current) {
21
- container = containerSelector.current;
22
- }
23
- else {
24
- return;
25
- }
26
- if (container) {
27
- container.scrollTo({
28
- top: to === 'top' ? 0 : container.scrollHeight - container.clientHeight,
29
- behavior: 'smooth',
30
- });
31
- }
32
- };
@@ -1,6 +1,6 @@
1
- import { type Dispatch, type EffectCallback, type SetStateAction } from 'react';
1
+ import { type Dispatch, type EffectCallback, type SetStateAction } from "react";
2
2
  export declare const useClickOutside: (callback?: () => void) => any;
3
- export declare function useMediaQuery(tailwindBreakpoint: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | `(${string})`): any;
3
+ export declare function useMediaQuery(tailwindBreakpoint: "sm" | "md" | "lg" | "xl" | "2xl" | `(${string})`): any;
4
4
  export declare function useEffectOnce(effect: EffectCallback): void;
5
5
  export declare function useUpdateEffect(effect: EffectCallback, deps: any[]): void;
6
6
  export declare function useDebounce<T>(state: T, delay?: number): T;
@@ -1,6 +1,6 @@
1
- 'use client';
2
- import { useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
3
- export const useClickOutside = (callback = () => alert('clicked outside')) => {
1
+ "use client";
2
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
3
+ export const useClickOutside = (callback = () => alert("clicked outside")) => {
4
4
  const ref = useRef(null);
5
5
  const listener = (e) => {
6
6
  if (ref.current && !ref.current.contains(e.target)) {
@@ -8,11 +8,11 @@ export const useClickOutside = (callback = () => alert('clicked outside')) => {
8
8
  }
9
9
  };
10
10
  useEffect(() => {
11
- document.addEventListener('mousedown', listener);
12
- document.addEventListener('touchstart', listener);
11
+ document.addEventListener("mousedown", listener);
12
+ document.addEventListener("touchstart", listener);
13
13
  return () => {
14
- document.removeEventListener('mousedown', listener);
15
- document.removeEventListener('touchstart', listener);
14
+ document.removeEventListener("mousedown", listener);
15
+ document.removeEventListener("touchstart", listener);
16
16
  };
17
17
  });
18
18
  return ref;
@@ -20,22 +20,22 @@ export const useClickOutside = (callback = () => alert('clicked outside')) => {
20
20
  export function useMediaQuery(tailwindBreakpoint) {
21
21
  const parsedQuery = useMemo(() => {
22
22
  switch (tailwindBreakpoint) {
23
- case 'sm':
24
- return '(min-width: 640px)';
25
- case 'md':
26
- return '(min-width: 768px)';
27
- case 'lg':
28
- return '(min-width: 1024px)';
29
- case 'xl':
30
- return '(min-width: 1280px)';
31
- case '2xl':
32
- return '(min-width: 1536px)';
23
+ case "sm":
24
+ return "(min-width: 640px)";
25
+ case "md":
26
+ return "(min-width: 768px)";
27
+ case "lg":
28
+ return "(min-width: 1024px)";
29
+ case "xl":
30
+ return "(min-width: 1280px)";
31
+ case "2xl":
32
+ return "(min-width: 1536px)";
33
33
  default:
34
34
  return tailwindBreakpoint;
35
35
  }
36
36
  }, [tailwindBreakpoint]);
37
37
  const getMatches = (parsedQuery) => {
38
- if (typeof window !== 'undefined') {
38
+ if (typeof window !== "undefined") {
39
39
  return window.matchMedia(parsedQuery).matches;
40
40
  }
41
41
  return false;
@@ -47,9 +47,9 @@ export function useMediaQuery(tailwindBreakpoint) {
47
47
  useEffect(() => {
48
48
  const matchMedia = window.matchMedia(parsedQuery);
49
49
  handleChange();
50
- matchMedia.addEventListener('change', handleChange);
50
+ matchMedia.addEventListener("change", handleChange);
51
51
  return () => {
52
- matchMedia.removeEventListener('change', handleChange);
52
+ matchMedia.removeEventListener("change", handleChange);
53
53
  };
54
54
  // eslint-disable-next-line react-hooks/exhaustive-deps
55
55
  }, [parsedQuery]);
@@ -81,7 +81,7 @@ export function useDebounce(state, delay = 500) {
81
81
  }, [state, delay]);
82
82
  return debouncedState;
83
83
  }
84
- export const useIsomorphicEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
84
+ export const useIsomorphicEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
85
85
  export function useTimeout(callback, delay = 1000) {
86
86
  const savedCallback = useRef(callback);
87
87
  useIsomorphicEffect(() => {
@@ -114,7 +114,7 @@ export const useLocalStorage = (key, defaultValue) => {
114
114
  // Function to update the stored value in local storage and state
115
115
  const updateStoredValue = (valueOrFn) => {
116
116
  let newValue;
117
- if (typeof valueOrFn === 'function') {
117
+ if (typeof valueOrFn === "function") {
118
118
  const updateFunction = valueOrFn;
119
119
  newValue = updateFunction(storedValue);
120
120
  }
@@ -141,7 +141,7 @@ export const useUrlParams = (key, defaultValue) => {
141
141
  const updateValue = (newValue) => {
142
142
  const params = new URLSearchParams(window.location.search);
143
143
  params.set(key, String(newValue));
144
- window.history.pushState({}, '', `${window.location.pathname}?${params}`);
144
+ window.history.pushState({}, "", `${window.location.pathname}?${params}`);
145
145
  setValue(newValue);
146
146
  };
147
147
  return [value, updateValue];
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "4.0.14",
3
+ "version": "4.0.15",
4
4
  "description": "",
5
+ "type": "module",
5
6
  "source": "./src/index.ts",
6
7
  "main": "./dist/index.js",
7
8
  "types": "./dist/index.d.ts",
@@ -13,17 +14,22 @@
13
14
  },
14
15
  "typesVersions": {
15
16
  "*": {
16
- "hooks": ["dist/hooks/index.d.ts"],
17
- "components": ["dist/components/index.d.ts"]
17
+ "hooks": [
18
+ "dist/hooks/index.d.ts"
19
+ ],
20
+ "components": [
21
+ "dist/components/index.d.ts"
22
+ ]
18
23
  }
19
24
  },
20
- "files": ["dist", "README.md"],
21
- "scripts": {
22
- "build": "tsc",
23
- "build:watch": "tsc --watch",
24
- "export": "tsc && npm publish"
25
- },
26
- "keywords": ["utils", "cn"],
25
+ "files": [
26
+ "dist",
27
+ "README.md"
28
+ ],
29
+ "keywords": [
30
+ "utils",
31
+ "cn"
32
+ ],
27
33
  "author": "sohanemon",
28
34
  "license": "ISC",
29
35
  "devDependencies": {
@@ -34,5 +40,10 @@
34
40
  "clsx": "^2.0.0",
35
41
  "react": "^18.2.0",
36
42
  "tailwind-merge": "^1.14.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "build:watch": "tsc --watch",
47
+ "export": "tsc && npm publish"
37
48
  }
38
- }
49
+ }