bsmnt 0.2.10 → 0.2.11

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.
Files changed (57) hide show
  1. package/dist/configs/skills.d.ts +27 -0
  2. package/dist/configs/skills.d.ts.map +1 -0
  3. package/dist/configs/skills.js +18 -0
  4. package/dist/configs/skills.js.map +1 -0
  5. package/dist/configs/skills.json +26 -0
  6. package/dist/helpers/add/hooks-config.d.ts.map +1 -1
  7. package/dist/helpers/add/hooks-config.js +0 -6
  8. package/dist/helpers/add/hooks-config.js.map +1 -1
  9. package/dist/helpers/create/setup-agent.d.ts.map +1 -1
  10. package/dist/helpers/create/setup-agent.js +15 -5
  11. package/dist/helpers/create/setup-agent.js.map +1 -1
  12. package/dist/helpers/integrate/merge-config.d.ts.map +1 -1
  13. package/dist/helpers/integrate/merge-config.js +1 -0
  14. package/dist/helpers/integrate/merge-config.js.map +1 -1
  15. package/dist/helpers/integrate/sanity/config.d.ts.map +1 -1
  16. package/dist/helpers/integrate/sanity/config.js +8 -2
  17. package/dist/helpers/integrate/sanity/config.js.map +1 -1
  18. package/dist/helpers/integrate/sanity/mergers/layout-merger.d.ts.map +1 -1
  19. package/dist/helpers/integrate/sanity/mergers/layout-merger.js +13 -12
  20. package/dist/helpers/integrate/sanity/mergers/layout-merger.js.map +1 -1
  21. package/dist/helpers/skills/index.d.ts +10 -0
  22. package/dist/helpers/skills/index.d.ts.map +1 -0
  23. package/dist/helpers/skills/index.js +136 -0
  24. package/dist/helpers/skills/index.js.map +1 -0
  25. package/dist/index.js +18 -0
  26. package/dist/index.js.map +1 -1
  27. package/package.json +3 -2
  28. package/src/helpers/integrate/sanity/files/app/api/blog/[slug]/route.ts +2 -1
  29. package/src/helpers/integrate/sanity/files/lib/integrations/sanity/confirm-publish-action.ts +31 -0
  30. package/src/helpers/integrate/sanity/files/lib/integrations/sanity/sanity.config.ts +17 -0
  31. package/src/helpers/integrate/sanity/files/lib/utils/json-ld.tsx +249 -0
  32. package/src/template-hooks/config.js +0 -6
  33. package/src/templates/next-default/app/layout.tsx +18 -0
  34. package/src/templates/next-default/lib/hooks/use-device-detection.ts +1 -1
  35. package/src/templates/next-default/lib/hooks/use-media-breakpoint.ts +1 -1
  36. package/src/templates/next-default/lib/hooks/use-media.ts +29 -0
  37. package/src/templates/next-default/lib/utils/json-ld.tsx +199 -0
  38. package/src/templates/next-default/package.json +1 -1
  39. package/src/templates/next-default/tsconfig.json +1 -0
  40. package/src/templates/next-experiments/app/layout.tsx +18 -0
  41. package/src/templates/next-experiments/lib/hooks/use-device-detection.ts +1 -1
  42. package/src/templates/next-experiments/lib/hooks/use-media-breakpoint.ts +1 -1
  43. package/src/templates/next-experiments/lib/hooks/use-media.ts +29 -0
  44. package/src/templates/next-experiments/lib/utils/json-ld.tsx +199 -0
  45. package/src/templates/next-experiments/package.json +1 -1
  46. package/src/templates/next-experiments/tsconfig.json +1 -0
  47. package/src/templates/next-webgl/app/layout.tsx +18 -0
  48. package/src/templates/next-webgl/lib/hooks/use-device-detection.ts +1 -1
  49. package/src/templates/next-webgl/lib/hooks/use-media-breakpoint.ts +1 -1
  50. package/src/templates/next-webgl/lib/hooks/use-media.ts +29 -0
  51. package/src/templates/next-webgl/lib/utils/json-ld.tsx +199 -0
  52. package/src/templates/next-webgl/package.json +1 -1
  53. package/src/templates/next-webgl/tsconfig.json +1 -0
  54. package/plugins/no-anchor-element.grit +0 -11
  55. package/plugins/no-relative-parent-imports.grit +0 -6
  56. package/plugins/no-unnecessary-forwardref.grit +0 -5
  57. package/src/template-hooks/use-media.ts +0 -33
@@ -0,0 +1,29 @@
1
+ import { useEffect, useState } from "react"
2
+
3
+ export function useMedia(mediaQuery: string, initialValue?: boolean) {
4
+ const [isVerified, setIsVerified] = useState<boolean | undefined>(initialValue)
5
+
6
+ useEffect(() => {
7
+ if (typeof window === "undefined" || !("matchMedia" in window)) {
8
+ console.warn("matchMedia is not supported by your current browser")
9
+ return
10
+ }
11
+ const mediaQueryList = window.matchMedia(mediaQuery)
12
+ const changeHandler = () => setIsVerified(!!mediaQueryList.matches)
13
+
14
+ changeHandler()
15
+ if (typeof mediaQueryList.addEventListener === "function") {
16
+ mediaQueryList.addEventListener("change", changeHandler)
17
+ return () => {
18
+ mediaQueryList.removeEventListener("change", changeHandler)
19
+ }
20
+ } else if (typeof mediaQueryList.addListener === "function") {
21
+ mediaQueryList.addListener(changeHandler)
22
+ return () => {
23
+ mediaQueryList.removeListener(changeHandler)
24
+ }
25
+ }
26
+ }, [mediaQuery])
27
+
28
+ return isVerified
29
+ }
@@ -0,0 +1,199 @@
1
+ import type {
2
+ Article,
3
+ BreadcrumbList,
4
+ Organization,
5
+ SearchAction,
6
+ Thing,
7
+ WebPage,
8
+ WebSite,
9
+ WithContext,
10
+ } from "schema-dts";
11
+
12
+ const APP_BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
13
+
14
+ function isAbsoluteUrl(value: string) {
15
+ return /^https?:\/\//.test(value);
16
+ }
17
+
18
+ function resolveUrl(value?: string) {
19
+ if (!value) return APP_BASE_URL;
20
+ if (isAbsoluteUrl(value)) return value;
21
+ if (!APP_BASE_URL) return undefined;
22
+
23
+ return new URL(value, APP_BASE_URL).toString();
24
+ }
25
+
26
+ /* -------------------------------- Component ------------------------------- */
27
+
28
+ export function JsonLd<T extends Thing>({
29
+ data,
30
+ }: {
31
+ data: WithContext<T>;
32
+ }) {
33
+ return (
34
+ <script
35
+ type="application/ld+json"
36
+ dangerouslySetInnerHTML={{
37
+ __html: JSON.stringify(data).replace(/</g, "\\u003c"),
38
+ }}
39
+ />
40
+ );
41
+ }
42
+
43
+ /* -------------------------------- Generators ------------------------------ */
44
+
45
+ interface WebSiteJsonLdOptions {
46
+ name: string;
47
+ url?: string;
48
+ description?: string;
49
+ /** URL to site-wide search (e.g. "/search?q={search_term_string}") */
50
+ searchUrl?: string;
51
+ }
52
+
53
+ export function generateWebSiteJsonLd(
54
+ options: WebSiteJsonLdOptions
55
+ ): WithContext<WebSite> {
56
+ const { name, url, description, searchUrl } = options;
57
+ const resolvedUrl = resolveUrl(url);
58
+ const resolvedSearchUrl = resolveUrl(searchUrl);
59
+
60
+ return {
61
+ "@context": "https://schema.org",
62
+ "@type": "WebSite",
63
+ name,
64
+ ...(resolvedUrl && { url: resolvedUrl }),
65
+ ...(description && { description }),
66
+ ...(resolvedSearchUrl && {
67
+ potentialAction: {
68
+ "@type": "SearchAction",
69
+ target: resolvedSearchUrl,
70
+ "query-input": "required name=search_term_string",
71
+ } as SearchAction & { "query-input": string },
72
+ }),
73
+ };
74
+ }
75
+
76
+ interface OrganizationJsonLdOptions {
77
+ name: string;
78
+ url?: string;
79
+ logo?: string;
80
+ description?: string;
81
+ sameAs?: string[];
82
+ }
83
+
84
+ export function generateOrganizationJsonLd(
85
+ options: OrganizationJsonLdOptions
86
+ ): WithContext<Organization> {
87
+ const { name, url, logo, description, sameAs } = options;
88
+ const resolvedUrl = resolveUrl(url);
89
+ const resolvedLogo = resolveUrl(logo);
90
+
91
+ return {
92
+ "@context": "https://schema.org",
93
+ "@type": "Organization",
94
+ name,
95
+ ...(resolvedUrl && { url: resolvedUrl }),
96
+ ...(resolvedLogo && { logo: resolvedLogo }),
97
+ ...(description && { description }),
98
+ ...(sameAs && { sameAs }),
99
+ };
100
+ }
101
+
102
+ interface WebPageJsonLdOptions {
103
+ title: string;
104
+ url?: string;
105
+ description?: string;
106
+ image?: string;
107
+ datePublished?: string;
108
+ dateModified?: string;
109
+ }
110
+
111
+ export function generateWebPageJsonLd(
112
+ options: WebPageJsonLdOptions
113
+ ): WithContext<WebPage> {
114
+ const { title, url, description, image, datePublished, dateModified } =
115
+ options;
116
+ const resolvedUrl = resolveUrl(url);
117
+ const resolvedImage = resolveUrl(image);
118
+
119
+ return {
120
+ "@context": "https://schema.org",
121
+ "@type": "WebPage",
122
+ name: title,
123
+ ...(resolvedUrl && { url: resolvedUrl }),
124
+ ...(description && { description }),
125
+ ...(resolvedImage && { image: resolvedImage }),
126
+ ...(datePublished && { datePublished }),
127
+ ...(dateModified && { dateModified }),
128
+ };
129
+ }
130
+
131
+ interface ArticleJsonLdOptions {
132
+ title: string;
133
+ url?: string;
134
+ description?: string;
135
+ image?: string;
136
+ datePublished?: string;
137
+ dateModified?: string;
138
+ authorName?: string;
139
+ authorUrl?: string;
140
+ }
141
+
142
+ export function generateArticleJsonLd(
143
+ options: ArticleJsonLdOptions
144
+ ): WithContext<Article> {
145
+ const {
146
+ title,
147
+ url,
148
+ description,
149
+ image,
150
+ datePublished,
151
+ dateModified,
152
+ authorName,
153
+ authorUrl,
154
+ } = options;
155
+ const resolvedUrl = resolveUrl(url);
156
+ const resolvedImage = resolveUrl(image);
157
+
158
+ return {
159
+ "@context": "https://schema.org",
160
+ "@type": "Article",
161
+ headline: title,
162
+ ...(resolvedUrl && { url: resolvedUrl }),
163
+ ...(description && { description }),
164
+ ...(resolvedImage && { image: resolvedImage }),
165
+ ...(datePublished && { datePublished }),
166
+ ...(dateModified && { dateModified }),
167
+ ...(authorName && {
168
+ author: {
169
+ "@type": "Person",
170
+ name: authorName,
171
+ ...(authorUrl && { url: authorUrl }),
172
+ },
173
+ }),
174
+ };
175
+ }
176
+
177
+ interface BreadcrumbItem {
178
+ name: string;
179
+ url: string;
180
+ }
181
+
182
+ export function generateBreadcrumbJsonLd(
183
+ items: BreadcrumbItem[]
184
+ ): WithContext<BreadcrumbList> {
185
+ return {
186
+ "@context": "https://schema.org",
187
+ "@type": "BreadcrumbList",
188
+ itemListElement: items.map((item, index) => {
189
+ const resolvedItemUrl = resolveUrl(item.url);
190
+
191
+ return {
192
+ "@type": "ListItem",
193
+ position: index + 1,
194
+ name: item.name,
195
+ ...(resolvedItemUrl && { item: resolvedItemUrl }),
196
+ };
197
+ }),
198
+ };
199
+ }
@@ -28,7 +28,6 @@
28
28
  "next": "^16",
29
29
  "react": "^19",
30
30
  "react-dom": "^19",
31
- "react-use": "^17.6.0",
32
31
  "tailwind-merge": "^3.4.0",
33
32
  "three": "^0.182.0",
34
33
  "zod": "^4.3.6"
@@ -46,6 +45,7 @@
46
45
  "babel-plugin-react-compiler": "1.0.0",
47
46
  "cross-env": "^10.1.0",
48
47
  "postcss-preset-env": "^10.6.1",
48
+ "schema-dts": "^2.0.0",
49
49
  "tailwindcss": "^4",
50
50
  "typescript": "^5"
51
51
  },
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2023",
4
4
  "lib": ["ES2023", "DOM", "DOM.Iterable"],
5
+ "types": ["bun"],
5
6
  "allowJs": true,
6
7
  "skipLibCheck": true,
7
8
  "strict": true,
@@ -6,6 +6,11 @@ import { fontsVariable } from "@/lib/styles/fonts";
6
6
  import AppData from "@/package.json";
7
7
  import "@/lib/styles/index.css";
8
8
  import { cn } from "@/lib/styles/cn";
9
+ import {
10
+ JsonLd,
11
+ generateWebSiteJsonLd,
12
+ generateOrganizationJsonLd,
13
+ } from "@/lib/utils/json-ld";
9
14
 
10
15
  const APP_NAME = AppData.name;
11
16
  const APP_DEFAULT_TITLE = "Basement Starter";
@@ -86,6 +91,19 @@ export default async function Layout({ children }: PropsWithChildren) {
86
91
  suppressHydrationWarning
87
92
  >
88
93
  <body>
94
+ <JsonLd
95
+ data={generateWebSiteJsonLd({
96
+ name: APP_DEFAULT_TITLE,
97
+ description: APP_DESCRIPTION,
98
+ })}
99
+ />
100
+ <JsonLd
101
+ data={generateOrganizationJsonLd({
102
+ name: APP_NAME,
103
+ logo: "/opengraph-image.jpg",
104
+ })}
105
+ />
106
+
89
107
  {/* Skip link for keyboard navigation accessibility */}
90
108
  <Suspense fallback={null}>
91
109
  <Link
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from "react"
2
- import { useMedia } from "react-use"
2
+ import { useMedia } from "./use-media"
3
3
 
4
4
  const MOBILE_BREAKPOINT = 640
5
5
 
@@ -1,4 +1,4 @@
1
- import { useMedia } from "react-use"
1
+ import { useMedia } from "./use-media"
2
2
 
3
3
  const BREAKPOINTS = {
4
4
  "desktop-large": 1920,
@@ -0,0 +1,29 @@
1
+ import { useEffect, useState } from "react"
2
+
3
+ export function useMedia(mediaQuery: string, initialValue?: boolean) {
4
+ const [isVerified, setIsVerified] = useState<boolean | undefined>(initialValue)
5
+
6
+ useEffect(() => {
7
+ if (typeof window === "undefined" || !("matchMedia" in window)) {
8
+ console.warn("matchMedia is not supported by your current browser")
9
+ return
10
+ }
11
+ const mediaQueryList = window.matchMedia(mediaQuery)
12
+ const changeHandler = () => setIsVerified(!!mediaQueryList.matches)
13
+
14
+ changeHandler()
15
+ if (typeof mediaQueryList.addEventListener === "function") {
16
+ mediaQueryList.addEventListener("change", changeHandler)
17
+ return () => {
18
+ mediaQueryList.removeEventListener("change", changeHandler)
19
+ }
20
+ } else if (typeof mediaQueryList.addListener === "function") {
21
+ mediaQueryList.addListener(changeHandler)
22
+ return () => {
23
+ mediaQueryList.removeListener(changeHandler)
24
+ }
25
+ }
26
+ }, [mediaQuery])
27
+
28
+ return isVerified
29
+ }
@@ -0,0 +1,199 @@
1
+ import type {
2
+ Article,
3
+ BreadcrumbList,
4
+ Organization,
5
+ SearchAction,
6
+ Thing,
7
+ WebPage,
8
+ WebSite,
9
+ WithContext,
10
+ } from "schema-dts";
11
+
12
+ const APP_BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
13
+
14
+ function isAbsoluteUrl(value: string) {
15
+ return /^https?:\/\//.test(value);
16
+ }
17
+
18
+ function resolveUrl(value?: string) {
19
+ if (!value) return APP_BASE_URL;
20
+ if (isAbsoluteUrl(value)) return value;
21
+ if (!APP_BASE_URL) return undefined;
22
+
23
+ return new URL(value, APP_BASE_URL).toString();
24
+ }
25
+
26
+ /* -------------------------------- Component ------------------------------- */
27
+
28
+ export function JsonLd<T extends Thing>({
29
+ data,
30
+ }: {
31
+ data: WithContext<T>;
32
+ }) {
33
+ return (
34
+ <script
35
+ type="application/ld+json"
36
+ dangerouslySetInnerHTML={{
37
+ __html: JSON.stringify(data).replace(/</g, "\\u003c"),
38
+ }}
39
+ />
40
+ );
41
+ }
42
+
43
+ /* -------------------------------- Generators ------------------------------ */
44
+
45
+ interface WebSiteJsonLdOptions {
46
+ name: string;
47
+ url?: string;
48
+ description?: string;
49
+ /** URL to site-wide search (e.g. "/search?q={search_term_string}") */
50
+ searchUrl?: string;
51
+ }
52
+
53
+ export function generateWebSiteJsonLd(
54
+ options: WebSiteJsonLdOptions
55
+ ): WithContext<WebSite> {
56
+ const { name, url, description, searchUrl } = options;
57
+ const resolvedUrl = resolveUrl(url);
58
+ const resolvedSearchUrl = resolveUrl(searchUrl);
59
+
60
+ return {
61
+ "@context": "https://schema.org",
62
+ "@type": "WebSite",
63
+ name,
64
+ ...(resolvedUrl && { url: resolvedUrl }),
65
+ ...(description && { description }),
66
+ ...(resolvedSearchUrl && {
67
+ potentialAction: {
68
+ "@type": "SearchAction",
69
+ target: resolvedSearchUrl,
70
+ "query-input": "required name=search_term_string",
71
+ } as SearchAction & { "query-input": string },
72
+ }),
73
+ };
74
+ }
75
+
76
+ interface OrganizationJsonLdOptions {
77
+ name: string;
78
+ url?: string;
79
+ logo?: string;
80
+ description?: string;
81
+ sameAs?: string[];
82
+ }
83
+
84
+ export function generateOrganizationJsonLd(
85
+ options: OrganizationJsonLdOptions
86
+ ): WithContext<Organization> {
87
+ const { name, url, logo, description, sameAs } = options;
88
+ const resolvedUrl = resolveUrl(url);
89
+ const resolvedLogo = resolveUrl(logo);
90
+
91
+ return {
92
+ "@context": "https://schema.org",
93
+ "@type": "Organization",
94
+ name,
95
+ ...(resolvedUrl && { url: resolvedUrl }),
96
+ ...(resolvedLogo && { logo: resolvedLogo }),
97
+ ...(description && { description }),
98
+ ...(sameAs && { sameAs }),
99
+ };
100
+ }
101
+
102
+ interface WebPageJsonLdOptions {
103
+ title: string;
104
+ url?: string;
105
+ description?: string;
106
+ image?: string;
107
+ datePublished?: string;
108
+ dateModified?: string;
109
+ }
110
+
111
+ export function generateWebPageJsonLd(
112
+ options: WebPageJsonLdOptions
113
+ ): WithContext<WebPage> {
114
+ const { title, url, description, image, datePublished, dateModified } =
115
+ options;
116
+ const resolvedUrl = resolveUrl(url);
117
+ const resolvedImage = resolveUrl(image);
118
+
119
+ return {
120
+ "@context": "https://schema.org",
121
+ "@type": "WebPage",
122
+ name: title,
123
+ ...(resolvedUrl && { url: resolvedUrl }),
124
+ ...(description && { description }),
125
+ ...(resolvedImage && { image: resolvedImage }),
126
+ ...(datePublished && { datePublished }),
127
+ ...(dateModified && { dateModified }),
128
+ };
129
+ }
130
+
131
+ interface ArticleJsonLdOptions {
132
+ title: string;
133
+ url?: string;
134
+ description?: string;
135
+ image?: string;
136
+ datePublished?: string;
137
+ dateModified?: string;
138
+ authorName?: string;
139
+ authorUrl?: string;
140
+ }
141
+
142
+ export function generateArticleJsonLd(
143
+ options: ArticleJsonLdOptions
144
+ ): WithContext<Article> {
145
+ const {
146
+ title,
147
+ url,
148
+ description,
149
+ image,
150
+ datePublished,
151
+ dateModified,
152
+ authorName,
153
+ authorUrl,
154
+ } = options;
155
+ const resolvedUrl = resolveUrl(url);
156
+ const resolvedImage = resolveUrl(image);
157
+
158
+ return {
159
+ "@context": "https://schema.org",
160
+ "@type": "Article",
161
+ headline: title,
162
+ ...(resolvedUrl && { url: resolvedUrl }),
163
+ ...(description && { description }),
164
+ ...(resolvedImage && { image: resolvedImage }),
165
+ ...(datePublished && { datePublished }),
166
+ ...(dateModified && { dateModified }),
167
+ ...(authorName && {
168
+ author: {
169
+ "@type": "Person",
170
+ name: authorName,
171
+ ...(authorUrl && { url: authorUrl }),
172
+ },
173
+ }),
174
+ };
175
+ }
176
+
177
+ interface BreadcrumbItem {
178
+ name: string;
179
+ url: string;
180
+ }
181
+
182
+ export function generateBreadcrumbJsonLd(
183
+ items: BreadcrumbItem[]
184
+ ): WithContext<BreadcrumbList> {
185
+ return {
186
+ "@context": "https://schema.org",
187
+ "@type": "BreadcrumbList",
188
+ itemListElement: items.map((item, index) => {
189
+ const resolvedItemUrl = resolveUrl(item.url);
190
+
191
+ return {
192
+ "@type": "ListItem",
193
+ position: index + 1,
194
+ name: item.name,
195
+ ...(resolvedItemUrl && { item: resolvedItemUrl }),
196
+ };
197
+ }),
198
+ };
199
+ }
@@ -28,7 +28,6 @@
28
28
  "next": "^16",
29
29
  "react": "^19",
30
30
  "react-dom": "^19",
31
- "react-use": "^17.6.0",
32
31
  "tailwind-merge": "^3.4.0",
33
32
  "three": "^0.182.0",
34
33
  "zod": "^4.3.6"
@@ -47,6 +46,7 @@
47
46
  "babel-plugin-react-compiler": "1.0.0",
48
47
  "cross-env": "^10.1.0",
49
48
  "postcss-preset-env": "^10.6.1",
49
+ "schema-dts": "^2.0.0",
50
50
  "tailwindcss": "^4",
51
51
  "typescript": "^5"
52
52
  },
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2023",
4
4
  "lib": ["ES2023", "DOM", "DOM.Iterable"],
5
+ "types": ["bun"],
5
6
  "allowJs": true,
6
7
  "skipLibCheck": true,
7
8
  "strict": true,
@@ -1,11 +0,0 @@
1
- language js
2
-
3
- `<a $attrs>$content</a>` as $anchor where {
4
- ! $anchor <: within `if ($condition) { return ($jsx) }` where {
5
- $condition <: contains or {
6
- `isExternal`,
7
- `isExternalSSR`
8
- }
9
- } ,
10
- register_diagnostic(span=$anchor, message="Use custom Link component instead of <a> element. The Link component handles both internal and external links automatically.", severity="error")
11
- }
@@ -1,6 +0,0 @@
1
- language js
2
-
3
- `import $imports from $source` as $import where {
4
- $source <: r"['\"]\.\.\/\.\.\/.*['\"]",
5
- register_diagnostic(span=$import, message="Use alias imports (~/dir/) instead of deep relative imports (../../). Single level imports (../) are allowed for colocated files.", severity="error")
6
- }
@@ -1,5 +0,0 @@
1
- language js
2
-
3
- `forwardRef($func)` as $ref where {
4
- register_diagnostic(span=$ref, message="forwardRef is unnecessary in React 19 with the compiler", severity="warning")
5
- }
@@ -1,33 +0,0 @@
1
- import * as React from "react";
2
-
3
- import { isApiSupported } from "@/utils";
4
-
5
- export const useMedia = (mediaQuery: string, initialValue?: boolean) => {
6
- const [isVerified, setIsVerified] = React.useState<boolean | undefined>(
7
- initialValue,
8
- );
9
-
10
- React.useEffect(() => {
11
- if (!isApiSupported("matchMedia")) {
12
- console.warn("matchMedia is not supported by your current browser");
13
- return;
14
- }
15
- const mediaQueryList = window.matchMedia(mediaQuery);
16
- const changeHandler = () => setIsVerified(!!mediaQueryList.matches);
17
-
18
- changeHandler();
19
- if (typeof mediaQueryList.addEventListener === "function") {
20
- mediaQueryList.addEventListener("change", changeHandler);
21
- return () => {
22
- mediaQueryList.removeEventListener("change", changeHandler);
23
- };
24
- } else if (typeof mediaQueryList.addListener === "function") {
25
- mediaQueryList.addListener(changeHandler);
26
- return () => {
27
- mediaQueryList.removeListener(changeHandler);
28
- };
29
- }
30
- }, [mediaQuery]);
31
-
32
- return isVerified;
33
- };