Skip to content

Commit 6228a68

Browse files
authored
Merge pull request #2782 from AtCoder-NoviSteps/#2781
chore(ui): Make button group responsive in task table (#2781)
2 parents 43751dc + 2c1e1f7 commit 6228a68

File tree

2 files changed

+84
-13
lines changed

2 files changed

+84
-13
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 shadow-none">
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-lg` | ボタンの角に丸みを付与 |
49+
| `shadow-none` | デフォルトシャドウを削除 |
50+
51+
## 注記
52+
53+
`ButtonGroup`コンポーネントのデフォルトスタイルにシャドウが含まれているため、`shadow-none`クラスを追加してそれらを打ち消す必要があります。
54+
55+
## 参考資料
56+
57+
- [Tailwind CSS - Flex Wrap](https://tailwindcss.com/docs/flex-wrap)
58+
- [Tailwind CSS - Justify Content](https://tailwindcss.com/docs/justify-content)
59+
- [Tailwind CSS - Gap](https://tailwindcss.com/docs/gap)
60+
- [Tailwind CSS - Border Radius](https://tailwindcss.com/docs/border-radius)
61+
- [Tailwind CSS - Box Shadow](https://tailwindcss.com/docs/box-shadow)
62+
63+
## 使用ライブラリ
64+
65+
- Tailwind CSS
66+
- Flowbite
67+
- svelte-5-ui-lib

src/lib/components/TaskTables/TaskTable.svelte

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,23 @@
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 shadow-none">
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: -->

0 commit comments

Comments
 (0)