Files
WeatherTool/web/src/harmonie/SlideShow.tsx
T

32 lines
862 B
TypeScript
Raw Normal View History

2025-02-21 23:07:49 +02:00
import { Accessor, Component } from 'solid-js'
import styles from './harmonie.module.css'
export const SlideShow: Component<{
getCanvas: Accessor<HTMLCanvasElement | undefined>,
2025-02-23 20:21:11 +02:00
getImgList: Accessor<[string, ImageBitmap | undefined][]>,
2025-02-21 23:07:49 +02:00
}> = ({
getCanvas,
getImgList
}) => {
2025-02-23 20:21:11 +02:00
function draw(img: ImageBitmap | undefined) {
2025-02-21 23:07:49 +02:00
const canvas = getCanvas()!
const ctx = canvas.getContext('2d')!
ctx.clearRect(0, 0, canvas.width, canvas.height)
2025-02-23 20:21:11 +02:00
if (!img) return;
2025-02-21 23:07:49 +02:00
ctx.drawImage(img, 0, 0)
}
return <ul class={styles.slideShow}>
{ getImgList().map(([forecastDate, img]) =>
2025-02-23 20:21:11 +02:00
<li class={img ? styles.withImg : ''} onClick={() => draw(img)}>
2025-02-21 23:07:49 +02:00
{ format(forecastDate) }
</li>)}
</ul>
}
function format(date: string) {
return date.slice(11, 13)
// return date
}