This file contains 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 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 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 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 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 |
This file contains 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 {string} selector 監視対象の要素を特定するCSSセレクタ | |
* @param {Object} options 監視オプション | |
* @param {string} options.scrollBasePosition スクロール量の基準位置を画面の上端('top')または下端('bottom')とするか | |
* @param {string} options.elementBasePosition 要素の基準位置を要素の上端('top')または下端('bottom')とするか | |
* @param {boolean} options.once 一度要素を通過したら監視を終了するかどうか | |
* @returns {boolean} true: スクロール量が要素の位置を超えた, false: まだ要素の位置まで到達していない | |
*/ |
This file contains 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 {number} timeoutSeconds スクロールが止まったと判定するまでの秒数(デフォルト: 3秒) | |
* @returns {boolean} スクロールの状態 | |
* - true: 一定時間スクロールが止まっている(指定秒数の間にスクロールなし) | |
* - false: スクロールが発生している(直近の指定秒数以内にスクロールあり) | |
*/ | |
export function useScrollStopped(timeoutSeconds: number = 3): boolean { | |
// 一定時間スクロールが止まっているかどうか |
This file contains 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
/** | |
* スクロール方向 | |
* 'up': ページトップ方向へのスクロール(ページを上に戻る) | |
* 'down': ページボトム方向へのスクロール(ページを下に進める) | |
* 'none': スクロールが発生していない状態 | |
*/ | |
type VerticalScrollDirection = 'up' | 'down' | 'none'; | |
/** | |
* スクロール方向を監視するhook |
This file contains 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 { RefObject, useRef, useEffect } from 'react'; | |
/** | |
* イベントタイプ | |
* - mousedown: マウスボタンを押したとき | |
* - click: マウスボタンを押して離したとき | |
* - touchstart: タッチしたとき | |
*/ | |
type EventType = 'mousedown' | 'click' | 'touchstart'; |
This file contains 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, useRef } from 'react'; | |
type RenderTimeOptions = { | |
/** | |
* 計測完了のトリガーとなる条件。 | |
* コンポーネント側でレンダリングを完了した状態を持たせて、それを設定する想定。 | |
*/ | |
completeTrigger: boolean; | |
/** | |
* 計測結果を区別するための識別子。 |
NewerOlder