forked from shuding/nextra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(callout): Move Callout component to nextra/components (shuding#1864
) Co-authored-by: Dimitri POSTOLOV <en3m@ya.ru> Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
- Loading branch information
1 parent
e024e6e
commit 1f9dd6d
Showing
6 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,60 @@ | ||
import type { ReactElement, ReactNode } from 'react' | ||
import cn from 'clsx' | ||
|
||
import { InformationCircleIcon } from '../icons' | ||
|
||
const TypeToEmoji = { | ||
default: '💡', | ||
error: '🚫', | ||
info: <InformationCircleIcon className="nx-mt-1" />, | ||
warning: '⚠️' | ||
} | ||
|
||
type CalloutType = keyof typeof TypeToEmoji | ||
|
||
const classes: Record<CalloutType, string> = { | ||
default: cn( | ||
'nx-border-orange-100 nx-bg-orange-50 nx-text-orange-800 dark:nx-border-orange-400/30 dark:nx-bg-orange-400/20 dark:nx-text-orange-300' | ||
), | ||
error: cn( | ||
'nx-border-red-200 nx-bg-red-100 nx-text-red-900 dark:nx-border-red-200/30 dark:nx-bg-red-900/30 dark:nx-text-red-200' | ||
), | ||
info: cn( | ||
'nx-border-blue-200 nx-bg-blue-100 nx-text-blue-900 dark:nx-border-blue-200/30 dark:nx-bg-blue-900/30 dark:nx-text-blue-200' | ||
), | ||
warning: cn( | ||
'nx-border-yellow-100 nx-bg-yellow-50 nx-text-yellow-900 dark:nx-border-yellow-200/30 dark:nx-bg-yellow-700/30 dark:nx-text-yellow-200' | ||
) | ||
} | ||
|
||
type CalloutProps = { | ||
type?: CalloutType | ||
emoji?: string | ReactElement | ||
children: ReactNode | ||
} | ||
|
||
export function Callout({ | ||
children, | ||
type = 'default', | ||
emoji = TypeToEmoji[type] | ||
}: CalloutProps): ReactElement { | ||
return ( | ||
<div | ||
className={cn( | ||
'nextra-callout nx-overflow-x-auto nx-mt-6 nx-flex nx-rounded-lg nx-border nx-py-2 ltr:nx-pr-4 rtl:nx-pl-4', | ||
'contrast-more:nx-border-current contrast-more:dark:nx-border-current', | ||
classes[type] | ||
)} | ||
> | ||
<div | ||
className="nx-select-none nx-text-xl ltr:nx-pl-3 ltr:nx-pr-2 rtl:nx-pr-3 rtl:nx-pl-2" | ||
style={{ | ||
fontFamily: '"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"' | ||
}} | ||
> | ||
{emoji} | ||
</div> | ||
<div className="nx-w-full nx-min-w-0 nx-leading-7">{children}</div> | ||
</div> | ||
) | ||
} |
This file contains 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
This file contains 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
This file contains 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