Files
aurora-admin/frameworks/ImagePreview.jsx
T

24 lines
1.0 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React from 'react';
import './ImagePreview.css';
export default function ImagePreview({ images = [], visible = false, index = 0, onClose, onChange }) {
if (!visible) return null;
const len = images.length || 1;
const go = dir => onChange && onChange((index + dir + len) % len);
return (
<div className="aa-imgprev-mask" onClick={e => { if (e.target === e.currentTarget) onClose && onClose(); }}>
<button className="aa-imgprev-close" onClick={onClose}>✕</button>
<button className="aa-imgprev-arrow prev" onClick={() => go(-1)}>‹</button>
<img className="aa-imgprev-img" src={images[index]} alt={index} />
<button className="aa-imgprev-arrow next" onClick={() => go(1)}>›</button>
<div className="aa-imgprev-count">{index + 1} / {len}</div>
<div className="aa-imgprev-thumbs">
{images.map((u, i) => (
<img key={i} className={'aa-imgprev-thumb' + (i === index ? ' is-active' : '')}
src={u} onClick={() => onChange && onChange(i)} />
))}
</div>
</div>
);
}