feat: add useToggle hook and refactor useDisclosure on it#2822
Merged
Conversation
boolean / 任意値の循環をトグルするカスタムフック useToggle を追加し、 useDisclosure を useToggle ベースの薄いラッパーに置き換えた。 - useToggle: 引数なし or boolean / readonly 配列を受け取り、`[value, toggle]` を返す。 - 配列モードでは const ジェネリクスで要素型を維持し、toggle() で循環・toggle(value) で特定値セット - 空配列・範囲外 initialValue は invariant で throw - 単体テスト・型テスト (test-d.ts)・Storybook stories を追加 - useDisclosure を useToggle ベースに変更し、テストを公開 API ベースで書き直し Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
useToggleを追加useDisclosureをuseToggleベースの薄いラッパーへリファクタ*.test-d.ts) ・Storybook stories を整備useToggle の API
```ts
// boolean モード
const [on, toggle] = useToggle(); // 初期 false
const [on, toggle] = useToggle(true); // 初期 true
toggle(); // 反転
toggle(true); // 特定値セット
// 配列モード (任意値の循環)
const [theme, toggle] = useToggle(['light', 'dark', 'system']);
const [theme, toggle] = useToggle(['light', 'dark', 'system'], 'dark'); // 初期値
toggle(); // 次へ循環 (末尾→先頭)
toggle('dark'); // 特定値セット
```
useDisclosure の変更
Test plan
🤖 Generated with Claude Code