This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use client'; | |
import { useLayoutEffect, useRef, useSyncExternalStore, useCallback } from 'react'; | |
/** | |
* selectタグの幅を動的に計算するカスタムフックです。 | |
* デフォルトではoptionタグにある最長のテキストに基づいて幅を計算しますが、これを上書きします。 | |
* @param selectRef - selectタグへの参照 | |
* @param currentValue - 現在選択されている値 | |
* @returns 計算された幅(ピクセル単位)または null(SSR時) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextConfig } from 'next'; | |
const nextConfig: NextConfig = { | |
async headers() { | |
return [ | |
{ | |
source: '/(.*)', | |
headers: [ | |
// frame-ancestors:他のドメインで自分たちのサイトをiframeで読み込むのを禁止させることで、iframeを使ったクリックジャッキングを防ぎます | |
// https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import DOMPurify from 'isomorphic-dompurify'; | |
/** | |
* ユーザー投稿コンテンツをサニタイズし、安全にレンダリングする。 | |
* | |
* @param {string | null | undefined} content - サニタイズおよびレンダリングするコンテンツ | |
* @returns {React.ReactNode} サニタイズされ、レンダリング可能なコンテンツ | |
* | |
* @example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
typescript: true, // .tsxファイルを生成する | |
memo: true, // Reactのメモ化を有効にする | |
jsxRuntime: 'automatic', // Reactの明示的なインポートをしない | |
filenameCase: 'kebab', // ファイル名をkebab-caseにする | |
index: false, // index.tsxファイルを生成しない | |
svgoConfig: { | |
plugins: [ | |
{ | |
name: 'preset-default', // 標準的なプリセットを使用する |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* w記述子で生成する画像サイズパターン | |
* https://nextjs.org/docs/pages/api-reference/components/image#advanced | |
*/ | |
export const srcSetSizes = [16, 32, 48, 64, 96, 128, 256, 384, 640, 750, 828, 1010]; | |
/** | |
* 画像の初期設定値 | |
*/ | |
export const DEFAULT_IMAGE_QUALITY = 90; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { usePathname, useSearchParams } from 'next/navigation'; | |
import { useCallback, useEffect, useRef, useMemo } from 'react'; | |
type ScrollIntoViewOptions = { | |
behavior?: ScrollBehavior; | |
block?: ScrollLogicalPosition; | |
inline?: ScrollLogicalPosition; | |
}; | |
interface UseLinkScrollOptions { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useCallback, useRef } from 'react'; | |
// ブラウザ環境かどうかを判定する | |
const isBrowser = typeof window !== 'undefined'; | |
// iOSデバイスかどうかを判定する | |
const isIosDevice = | |
isBrowser && | |
window.navigator && | |
window.navigator.platform && |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useCallback, useRef, useState } from 'react'; | |
/** | |
* 開閉処理以外のオプション設定。 | |
*/ | |
type ModalOptions = { | |
/** Escキーでモーダルを閉じるかどうか @default true */ | |
closeOnEsc?: boolean; | |
/** フォーカストラップを有効にするかどうか @default true */ | |
enableFocusTrap?: boolean; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 任意の引数を受け取る関数型 | |
type AnyFunction = (...args: any[]) => any; | |
// スロットル制御された関数の型 | |
type ThrottledFunction<T extends AnyFunction> = { | |
(...args: Parameters<T>): void; | |
cancel: () => void; | |
}; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* メディアクエリの一致状態を監視するカスタムフックです。 | |
* @param mediaQuery メディアクエリ文字列(例: '(min-width: 768px)') | |
* @returns boolean - メディアクエリに一致する場合はtrue、それ以外はfalse | |
*/ | |
export function useMediaQuery(mediaQuery: string): boolean { | |
// サーバーサイドでは初期値を`false`として、クライアントサイドでは結果を返す | |
const getInitialValue = () => | |
typeof window !== 'undefined' | |
? window.matchMedia(mediaQuery).matches |
NewerOlder