summary refs log tree commit diff
path: root/components/InfoBar/index.tsx
blob: cb5ac9af7379b3b559e85c8afc9bcf622094704a (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { ReactNode } from 'react'
import styles from './InfoBar.module.css'

interface ArbitraryChildrenProps {
  children: ReactNode
}

interface SideNoteProps {
  text: string
}

interface PostInfoPros {
  publishedDate: Date,
  authorName: string
}

interface SystemMemberInfoProps {
  memberName: string,
  memberAvatar: string
}

type InfobarProps = (
  ArbitraryChildrenProps
  | SideNoteProps
  | PostInfoPros
  | SystemMemberInfoProps
)

export default function InfoBar(props: InfobarProps) {
  if ('text' in props) {
    return (
      <aside className={`${styles.infobar} ${styles.sideNote}`}>
        {props.text}
      </aside>
    )
  }

  if ('authorName' in props) {
    return (
      <aside className={`${styles.infobar} ${styles.postMeta}`}>
        <span>
          by <span className={styles.author}>{props.authorName}</span>;{' '}
          <span className={styles.date}>published {props.publishedDate.toLocaleDateString()}</span>
        </span>
      </aside>
    )
  }

  if ('memberName' in props) {
    return (
      <aside className={`${styles.infobar} ${styles.sideNote}`}>
        {props.memberName}
      </aside>
    )
  }

  if ('children' in props) {
    return (
      <aside className={styles.infobar}>
        {props.children}
      </aside>
    )
  }

  throw new Error('Unknown infobar type')
}