0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【商品管理システムの開発】複数画像表示機能に更新

Posted at

コード

ProductList.tsx
{product.imageUrls && product.imageUrls.length > 0 && (

• product.imageUrls が存在していて、かつ配列に要素が1つ以上あるときのみ画像表示処理を行います。
• 安全にアクセスするためのチェックです(null/undefined 対策)。

ProductList.tsx
product.imageUrls.map((url, index) => (
  <img
    key={index}
    src={url}
    alt={`${t("product.name")} ${index + 1}`}
    className="w-24 h-24 object-cover rounded"
  />
))

• imageUrls は画像のダウンロードURLの配列。
• .map() を使って、各URLを タグでレンダリング。
• key={index} は React のリスト描画に必要な一意のキー。
• alt 属性には翻訳テキスト+インデックス番号を使って、アクセシビリティを向上。

ProductList.tsx
className="w-24 h-24 object-cover rounded"

• w-24 h-24: 画像サイズを幅・高さともに 6rem(96px)に固定。
• object-cover: 画像のアスペクト比を維持しつつ、コンテナいっぱいにトリミングして表示。
• rounded: 角を丸くするTailwindクラスで、柔らかい印象に。

ProductList.tsx
<div className="flex gap-2 ml-4 flex-wrap">

• flex: Flexboxで画像を横並びに。
• gap-2: 各画像間にスペースを確保。
• ml-4: 左側に余白(マージン)を入れることで見た目を整える。
• flex-wrap: 画面幅が足りない場合に折り返し表示。

UI

スクリーンショット 2025-08-01 8.13.12.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?