読み方のヒント
矢印ボタン(または ← → キー)でページを移動できます。
共通の部品は、多くの場所で使うため、props を足したくなる場面がよくあります。
| よくない例 | 何が困るか | よい例 |
|---|---|---|
color="#3d8049" のように色を受け取る | トークンから外れた色が増える | variant で決まった種類だけを選ぶ |
isReserveButton のように、機能の名前の props | 共通の部品が、予約の機能を知る | 予約の側で、Button を使った部品を作る |
marginTop を受け取る | 部品の外の余白を、部品が決めることになる | 並べる側の CSS で余白を決める |
部品の外の余白(ほかの部品との間隔)は、並べる側が決めます。部品の中の余白は、部品が決めます。こうしておくと、同じボタンを、どの画面にも同じ形で置けます。
予約の機能に特有のボタンは、予約の機能の中で、共通の部品を使って作ります。
// src/features/reservations/components/SubmitReservationButton.tsx
import { Button } from "@/shared/ui/Button";
export const SubmitReservationButton = ({ isPending }: { isPending: boolean }) => (
<Button type="submit" disabled={isPending}>
{isPending ? "送っています…" : "予約する"}
</Button>
);
type TextFieldProps = ComponentPropsWithoutRef<"input"> & { label: string; error?: string | undefined; }; と書きます。中では、id を使って <label htmlFor> と結び付け、error があるときに aria-invalid と aria-describedby を付けます。
8 / 17