diff options
author | Ashelyn Rose <git@tempest.dev> | 2023-05-08 14:45:55 -0600 |
---|---|---|
committer | Ashelyn Rose <git@tempest.dev> | 2023-05-08 14:45:55 -0600 |
commit | 7e3dc4ace4c6b21bc68264dc76c8c442aec8031a (patch) | |
tree | c6ff346374e91913a12a8bb21da7fe8c29dd5429 /components/InfoBar/index.tsx | |
parent | 880cfbeb74546056feab63ed6e92a10c0dbaf2c3 (diff) |
standardize component structure more
Diffstat (limited to 'components/InfoBar/index.tsx')
-rw-r--r-- | components/InfoBar/index.tsx | 66 |
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') +} |