@geee-be/react-utils 1.1.5 → 1.1.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @geee-be/react-utils
2
2
 
3
+ ## 1.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 3ca7ee9: feat: add ClientOnly component for client-side rendering
8
+
9
+ ## 1.1.6
10
+
11
+ ### Patch Changes
12
+
13
+ - 8011d1e: Add Collapsible, DropdownMenu, Separator, Sheet, Sidebar from shadcn
14
+
3
15
  ## 1.1.5
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,8 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useIsClient } from '../hooks';
3
+ export const ClientOnly = ({ children, serverFallback }) => {
4
+ const isClient = useIsClient();
5
+ if (isClient)
6
+ return _jsx(_Fragment, { children: serverFallback });
7
+ return _jsx(_Fragment, { children: children });
8
+ };
@@ -1,2 +1,3 @@
1
+ export { ClientOnly } from './client-only.js';
1
2
  export * from './ripple.js';
2
3
  export * from './sub-component.js';
@@ -1,4 +1,5 @@
1
1
  export * from './use-broadcast-channel.js';
2
2
  export * from './use-history-state.js';
3
3
  export * from './use-is-client.js';
4
+ export * from './use-is-mobile.js';
4
5
  export * from './use-local-state.js';
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ const MOBILE_BREAKPOINT = 768;
3
+ export function useIsMobile() {
4
+ const [isMobile, setIsMobile] = React.useState(undefined);
5
+ React.useEffect(() => {
6
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
7
+ const onChange = () => {
8
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
9
+ };
10
+ mql.addEventListener('change', onChange);
11
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
12
+ return () => mql.removeEventListener('change', onChange);
13
+ }, []);
14
+ return !!isMobile;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geee-be/react-utils",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -0,0 +1,12 @@
1
+ import type { FC, PropsWithChildren, ReactNode } from 'react';
2
+ import { useIsClient } from '../hooks';
3
+
4
+ interface Props extends PropsWithChildren {
5
+ serverFallback?: ReactNode;
6
+ }
7
+
8
+ export const ClientOnly: FC<Props> = ({ children, serverFallback }) => {
9
+ const isClient = useIsClient();
10
+ if (isClient) return <>{serverFallback}</>;
11
+ return <>{children}</>;
12
+ };
@@ -1,2 +1,3 @@
1
+ export { ClientOnly } from './client-only.js';
1
2
  export * from './ripple.js';
2
3
  export * from './sub-component.js';
@@ -1,4 +1,5 @@
1
1
  export * from './use-broadcast-channel.js';
2
2
  export * from './use-history-state.js';
3
3
  export * from './use-is-client.js';
4
+ export * from './use-is-mobile.js';
4
5
  export * from './use-local-state.js';
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+
3
+ const MOBILE_BREAKPOINT = 768;
4
+
5
+ export function useIsMobile() {
6
+ const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
7
+ undefined,
8
+ );
9
+
10
+ React.useEffect(() => {
11
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
12
+ const onChange = () => {
13
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
14
+ };
15
+ mql.addEventListener('change', onChange);
16
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
17
+ return () => mql.removeEventListener('change', onChange);
18
+ }, []);
19
+
20
+ return !!isMobile;
21
+ }