forked from rocicorp/zero-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.tsx
More file actions
76 lines (68 loc) · 1.94 KB
/
note.tsx
File metadata and controls
76 lines (68 loc) · 1.94 KB
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
67
68
69
70
71
72
73
74
75
76
import {cn, sluggify} from '@/lib/utils';
import clsx from 'clsx';
import {PropsWithChildren} from 'react';
type NoteProps = PropsWithChildren & {
type?: 'note' | 'danger' | 'warning' | 'todo';
emoji?: string;
heading?: string;
slug?: string;
};
export default function Note({
children,
type = 'note',
emoji,
heading,
slug,
}: NoteProps) {
const noteClassNames = clsx({
'dark:bg-gray-900 dark:border-gray-800 bg-blue-50 border-blue-200':
type === 'note',
'dark:bg-yellow-950 dark:border-yellow-900 bg-yellow-50 border-yellow-200':
type === 'warning' || type === 'todo',
'dark:bg-red-950 dark:border-red-900 bg-red-50 border-red-200':
type === 'danger',
});
// Default emojis by note type
const typeEmojis: Record<'note' | 'warning' | 'danger' | 'todo', string> = {
note: '🤔',
warning: '😬',
danger: '😱',
todo: '😅',
};
// Default headings by note type
const defaultHeadings: Record<
'note' | 'warning' | 'danger' | 'todo',
string
> = {
note: 'Note',
warning: 'Warning',
danger: 'Danger',
todo: 'TODO',
};
// Use the overridden emoji if provided; otherwise, use the default
const displayedEmoji = emoji || typeEmojis[type];
// Use the overridden heading if provided; otherwise, use the default
const displayedHeading = heading || defaultHeadings[type];
if (!slug) {
slug = sluggify(displayedHeading);
}
return (
<div
id={slug}
className={cn(
'note-container border rounded-md p-3.5 text-sm tracking-wide items-start',
noteClassNames,
)}
>
<div>
<div className="note-heading-container">
<a className="heading-link" href={`#${slug}`}>
<span className="note-emoji">{displayedEmoji}</span>
<span className="note-heading">{displayedHeading}</span>
</a>
</div>
</div>
<aside className="note-aside">{children}</aside>
</div>
);
}