Skip to content

GitHubCallout #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions components/GitHubCallout/GitHubCallout.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export const GitHubCallout = ({ type, children }) => {
let color;
let icon;
switch (type) {
case 'tip':
color = 'green';
icon = 'fa-lightbulb';
break;
case 'important':
color = 'purple';
icon = 'fa-message-exclamation';
break;
case 'warning':
color = 'yellow';
icon = 'fa-triangle-exclamation';
break;
case 'caution':
color = 'red';
icon = 'fa-stop';
break;
case 'note':
default:
color = 'blue';
icon = 'fa-circle-info';
break;
}

return (
<div className={`pl-3 border-l-1 border-${color}-500 dark:border-${color}-400`}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may or may not work, just make sure it does! (I can see it working in the preview but not working when used)

The reason is that Tailwind compiles down the strings for performance reasons, so it doesn't understand interpolation like this.

If it doesn't work, the way to fix it is to do this:

color  = 'border-green-500';
...
<div className={`pl-3 border-l-1 ${color}`}>

(Tailwind just uses a regex to find everything that fits, so as long as it's written SOMEWHERE in the code it'll catch it. But it can't deal with variables like this.)

(If it works in the preview, it should work everywhere! If not that's a bigger issue we should address.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If you get stuck here, just ping me and I can help out! Both for this PR and ReadMe in general)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My eyes may be deceiving because of the minor difference I put in for the light vs dark colors but it seems to be working as-is?

Screenshot 2025-04-01 at 4 35 45 PM
Screenshot 2025-04-01 at 4 35 49 PM

<p className={`text-${color}-500 dark:text-${color}-400`}>
<i className={`fa-solid ${icon} mr-1`} /> {type.slice(0, 1).toUpperCase() + type.slice(1)}
</p>
<p>{children}</p>
</div>
);
};

<>
<GitHubCallout type="note">Highlights information that users should take into account, even when skimming.</GitHubCallout>
<GitHubCallout type="tip">Optional information to help a user be more successful.</GitHubCallout>
<GitHubCallout type="important">Crucial information necessary for users to succeed.</GitHubCallout>
<GitHubCallout type="warning">Critical content demanding immediate user attention due to potential risks.</GitHubCallout>
<GitHubCallout type="caution">Negative potential consequences of an action.</GitHubCallout>
</>
Binary file added components/GitHubCallout/callout-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added components/GitHubCallout/callout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions components/GitHubCallout/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# `<GitHubCallout />`

## Overview

This component mimics the undocumented way that GitHub renders callouts. https://github.com/orgs/community/discussions/16925

![GitHubCallout](callout.png)

It also supports dark mode:

![GitHubCallout dark mode](callout-dark.png)

## Usage

It supports five different types of callouts: `note`, `tip`, `important`, `warning`, and `caution`.

```jsx
<GitHubCallout type="note">
This is a note!
</GitHubCallout>
```