diff options
Diffstat (limited to 'src/ui.js')
| -rw-r--r-- | src/ui.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/ui.js b/src/ui.js new file mode 100644 index 0000000..10755e6 --- /dev/null +++ b/src/ui.js @@ -0,0 +1,89 @@ +import ColorHash from 'color-hash'; +import { formatRelative } from 'date-fns'; +import * as dom from './dom'; + +dom.css` +body { + background: #1e1e1e; + font-family: sans-serif; +} +`; + +const now = new Date(); +const Time = ({ time }) => { + const dt = new Date(time); + return formatRelative(dt, now); +}; + +dom.css` +.flex-space { + flex: 1; +} +`; + +const Space = () => <div class="flex-space" />; + +dom.css` +section { + position: absolute; + overflow: hidden; + + width: 350px; + + background: #363636; + border-radius: 0.4em; +} + +section > header { + display: flex; + flex-direction: row; + + height: 2.5em; + line-height: 2.5em; + + color: #121212; +} + +section > header > * { + margin: 0 0.5em; +} + +section > header > img { + height: 2em; + width: 2em; + margin: 0.25em; + border-radius: 0.2em; +} + +section > header > .time { + font-size: 0.8em; + color: #363636; +} + +section > main { + padding: 1em; + color: #eeeeee; + font-family: serif; +} +`; + +const colors = new ColorHash({ lightness: 0.8 }); +export const Note = ({ id, attributedTo, published, content }) => { + const backgroundColor = attributedTo.color || colors.hex(attributedTo.id); + const username = attributedTo.name || attributedTo.preferredUsername; + + return ( + <section dataset={{ id }}> + <header style={{ backgroundColor }}> + <img src={attributedTo.icon.url} /> + <span class="user">{username}</span> + <Space /> + <span class="time"><Time time={published} /></span> + </header> + <main> + {content} + </main> + </section> + ); +}; + |
