File tree Expand file tree Collapse file tree 2 files changed +78
-13
lines changed
docs/dev-notes/2025-11-02/make-button-group-responsive
src/lib/components/TaskTables Expand file tree Collapse file tree 2 files changed +78
-13
lines changed Original file line number Diff line number Diff line change 1+ # Button Group のレスポンシブ化
2+
3+ ## 問題
4+
5+ 640px未満の画面でボタングループの文字が縦に潰れてしまう
6+
7+ ## 解決方法
8+
9+ Tailwind CSSのレスポンシブクラスを使用してボタンの折り返しと配置を実装
10+
11+ ## コード変更
12+
13+ ### 修正前
14+
15+ ``` svelte
16+ <ButtonGroup class="m-4 contents-center">
17+ ```
18+
19+ ### 修正後
20+
21+ ``` svelte
22+ <div class="flex justify-center m-4">
23+ <ButtonGroup class="flex flex-wrap justify-start gap-1">
24+ {#each Object.entries(contestTableProviderGroups) as [type, config]}
25+ <Button
26+ onclick={() => updateActiveContestType(type as ContestTableProviderGroups)}
27+ class={`rounded-lg ${activeContestType === (type as ContestTableProviderGroups)
28+ ? 'active-button-class text-primary-700 dark:!text-primary-500'
29+ : ''}`}
30+ aria-label={config.getMetadata().ariaLabel}
31+ >
32+ {config.getMetadata().buttonLabel}
33+ </Button>
34+ {/each}
35+ </ButtonGroup>
36+ </div>
37+ ```
38+
39+ ## 使用クラス一覧
40+
41+ | クラス | 役割 |
42+ | ---------------- | ------------------------------------------- |
43+ | ` flex ` | Flexboxコンテナを有効化 |
44+ | ` flex-wrap ` | 画面幅に応じてボタンを折り返す |
45+ | ` justify-center ` | ボタングループ全体を水平中央揃え(外側div) |
46+ | ` justify-start ` | ボタン自体を左寄せ(ButtonGroup内) |
47+ | ` gap-1 ` | ボタン間のスペーシング(0.25rem) |
48+ | ` rounded ` | ボタンの角に丸みを付与 |
49+
50+ ## 参考資料
51+
52+ - [ Tailwind CSS - Flex Wrap] ( https://tailwindcss.com/docs/flex-wrap )
53+ - [ Tailwind CSS - Justify Content] ( https://tailwindcss.com/docs/justify-content )
54+ - [ Tailwind CSS - Gap] ( https://tailwindcss.com/docs/gap )
55+ - [ Tailwind CSS - Border Radius] ( https://tailwindcss.com/docs/border-radius )
56+
57+ ## 使用ライブラリ
58+
59+ - Tailwind CSS
60+ - Flowbite
61+ - svelte-5-ui-lib
Original file line number Diff line number Diff line change 171171
172172<!-- See: -->
173173<!-- https://flowbite-svelte.com/docs/components/button-group -->
174- <ButtonGroup class =" m-4 contents-center" >
175- {#each Object .entries (contestTableProviderGroups ) as [type, config]}
176- <Button
177- onclick ={() => updateActiveContestType (type as ContestTableProviderGroups )}
178- class ={activeContestType === (type as ContestTableProviderGroups )
179- ? ' active-button-class text-primary-700 dark:!text-primary-500'
180- : ' ' }
181- aria-label ={config .getMetadata ().ariaLabel }
182- >
183- {config .getMetadata ().buttonLabel }
184- </Button >
185- {/each }
186- </ButtonGroup >
174+ <div class =" flex justify-center m-4" >
175+ <ButtonGroup class =" flex flex-wrap justify-start gap-1" >
176+ {#each Object .entries (contestTableProviderGroups ) as [type, config]}
177+ <Button
178+ onclick ={() => updateActiveContestType (type as ContestTableProviderGroups )}
179+ class ={` rounded-lg ${
180+ activeContestType === (type as ContestTableProviderGroups )
181+ ? ' active-button-class text-primary-700 dark:!text-primary-500'
182+ : ' '
183+ } ` }
184+ aria-label ={config .getMetadata ().ariaLabel }
185+ >
186+ {config .getMetadata ().buttonLabel }
187+ </Button >
188+ {/each }
189+ </ButtonGroup >
190+ </div >
187191
188192<!-- TODO: ページネーションを実装 -->
189193<!-- See: -->
You can’t perform that action at this time.
0 commit comments