summary refs log tree commit diff
path: root/components/InfoBar/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'components/InfoBar/index.tsx')
-rw-r--r--components/InfoBar/index.tsx66
1 files changed, 66 insertions, 0 deletions
diff --git a/components/InfoBar/index.tsx b/components/InfoBar/index.tsx
new file mode 100644
index 0000000..cb5ac9a
--- /dev/null
+++ b/components/InfoBar/index.tsx
@@ -0,0 +1,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')
+}