Image
画像を表示するコンポーネント。
インストール
import { Image } from "@ginga-ui/core";基本的な使い方
シンプルな画像の使用例です。
image.tsx
image.module.css
import { Image } from "@ginga-ui/core";
import styles from "./image.module.css";
export function BasicExample() {
return (
<Image
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="美しい山の風景"
className={styles.basicImage}
/>
);
}アバター
アバター画像の例です。
image.tsx
image.module.css
import { Image } from "@ginga-ui/core";
import styles from "./image.module.css";
export function AvatarExample() {
return (
<div className={styles.avatars}>
<Image
src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde"
alt="ユーザーアバター"
variant="avatar"
className={styles.avatarSmall}
/>
<Image
src="https://images.unsplash.com/photo-1494790108377-be9c29b29330"
alt="ユーザーアバター"
variant="avatar"
className={styles.avatarMedium}
/>
<Image
src="https://images.unsplash.com/photo-1599566150163-29194dcaad36"
alt="ユーザーアバター"
variant="avatar"
className={styles.avatarLarge}
/>
</div>
);
}サイズ
様々なサイズの画像を表示します。
image.tsx
image.module.css
import { Image } from "@ginga-ui/core";
import styles from "./image.module.css";
export function SizesExample() {
return (
<div className={styles.sizes}>
<Image
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="小サイズ"
className={styles.smallImage}
/>
<Image
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="中サイズ"
className={styles.mediumImage}
/>
</div>
);
}角丸
角丸の画像を表示します。
image.tsx
image.module.css
import { Image } from "@ginga-ui/core";
import styles from "./image.module.css";
export function RoundedExample() {
return (
<Image
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="角丸の画像"
className={styles.roundedImage}
/>
);
}Props
Image
| 名前 | 型 | 既定値 | 説明 |
|---|---|---|---|
alt | string | - | 必須のpropsです。代替テキスト。装飾目的の画像には "" を渡します。 |
variant | "default" | "avatar" | "default" | "avatar" を指定すると円形に切り抜いて表示します。 |
render | (props) => ReactElement | - | ルート要素を差し替える関数。受け取った props を渡した要素(next/link など)を返します。 |
上記に加えて、HTML の img(新しいタブで開く) 要素の属性を受け取ります。