-
Notifications
You must be signed in to change notification settings - Fork 4
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
erunion
wants to merge
1
commit into
main
Choose a base branch
from
feat/github-callout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
GitHubCallout
#16
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`}> | ||
<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> | ||
</> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
 | ||
|
||
It also supports dark mode: | ||
|
||
 | ||
|
||
## Usage | ||
|
||
It supports five different types of callouts: `note`, `tip`, `important`, `warning`, and `caution`. | ||
|
||
```jsx | ||
<GitHubCallout type="note"> | ||
This is a note! | ||
</GitHubCallout> | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
(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.)
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?