-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.tsx
33 lines (28 loc) · 912 Bytes
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* eslint-disable import/no-extraneous-dependencies */
import ReactDom from 'react-dom';
import React, { useState } from 'react';
import { fitGradient } from '../../src/lib';
import src from './image.jpg';
import './index.css';
interface FramedImageProps {
src: string;
}
function useFittingGradient(defaultColor: string = '#333'): [string, (image:CanvasImageSource)=>void] {
const [background, setBackground] = useState(defaultColor);
return [
background,
(image) => setBackground(fitGradient(image)),
];
}
function FramedImage(props: FramedImageProps) {
const [background, setImage] = useFittingGradient();
return <div className="frame" style={{ background }}>
<img src={props.src} onLoad={(e) => setImage(e.currentTarget)} />
</div>;
}
const root = document.createElement('div');
document.body.appendChild(root);
ReactDom.render(
<FramedImage src={src} />,
root,
);