-
-
Couldn't load subscription status.
- Fork 199
feat(theme-default): children, outline and fixes for Badge #1451
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
Merged
Merged
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Internal Components | ||
| # Built-in Components | ||
|
|
||
| import InternalComponents from '../../fragments/internal-components'; | ||
| import BuiltinComponents from '../../fragments/builtin-components'; | ||
|
|
||
| <InternalComponents /> | ||
| <BuiltinComponents /> |
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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Internal Components | ||
| # Built-in Components | ||
|
|
||
| import InternalComponents from '../../fragments/internal-components' | ||
| import BuiltinComponents from '../../fragments/builtin-components'; | ||
|
|
||
| <InternalComponents /> | ||
| <BuiltinComponents /> |
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # 内置组件 | ||
|
|
||
| import InternalComponents from '../../fragments/internal-components'; | ||
| import BuiltinComponents from '../../fragments/builtin-components'; | ||
|
|
||
| <InternalComponents /> | ||
| <BuiltinComponents /> |
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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # 内置组件 | ||
|
|
||
| import InternalComponents from '../../fragments/internal-components' | ||
| import BuiltinComponents from '../../fragments/builtin-components'; | ||
|
|
||
| <InternalComponents /> | ||
| <BuiltinComponents /> |
44 changes: 35 additions & 9 deletions
44
packages/theme-default/src/components/Badge/index.module.scss
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 |
|---|---|---|
| @@ -1,18 +1,44 @@ | ||
| .badge { | ||
| padding: 0 10px; | ||
| line-height: 22px; | ||
| font-size: 12px; | ||
| font-weight: 500; | ||
| transition: color 0.25s; | ||
|
|
||
| &.tip { | ||
| color: var(--rp-container-tip-text); | ||
| background-color: var(--rp-container-tip-bg); | ||
| } | ||
|
|
||
| &.info { | ||
| color: #2e3440; | ||
| background-color: rgba(46, 52, 64, 0.16); | ||
| color: var(--rp-container-info-text); | ||
| background-color: var(--rp-container-info-bg); | ||
| } | ||
|
|
||
| &.warning { | ||
| color: #ad850e; | ||
| background-color: rgba(255, 197, 23, 0.16); | ||
| color: var(--rp-container-warning-text); | ||
| background-color: var(--rp-container-warning-bg); | ||
| } | ||
|
|
||
| &.danger { | ||
| color: #ab2131; | ||
| background-color: rgba(237, 60, 80, 0.16); | ||
| color: var(--rp-container-danger-text); | ||
| background-color: var(--rp-container-danger-bg); | ||
| } | ||
|
|
||
| &.outline { | ||
| border: 1px solid; | ||
|
|
||
| &.tip { | ||
| border-color: var(--rp-container-tip-border); | ||
| } | ||
|
|
||
| &.info { | ||
| border-color: var(--rp-container-info-border); | ||
| } | ||
|
|
||
| &.warning { | ||
| border-color: var(--rp-container-warning-border); | ||
| } | ||
|
|
||
| &.danger { | ||
| border-color: var(--rp-container-danger-border); | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,17 +1,64 @@ | ||
| import styles from './index.module.scss'; | ||
|
|
||
| interface BadgeProps { | ||
| text: string; | ||
| type: 'info' | 'warning' | 'danger'; | ||
| /** | ||
| * The content to display inside the badge. Can be a string or React nodes. | ||
| */ | ||
| children?: React.ReactNode; | ||
| /** | ||
| * The type of badge, which determines its color and style. | ||
| * @default 'tip' | ||
| */ | ||
| type?: 'tip' | 'info' | 'warning' | 'danger'; | ||
| /** | ||
| * The text content to display inside the badge (for backwards compatibility). | ||
| */ | ||
| text?: string; | ||
| /** | ||
| * Whether to display the badge with an outline style. | ||
| * @default false | ||
| */ | ||
| outline?: boolean; | ||
| } | ||
|
|
||
| export function Badge(props: BadgeProps) { | ||
| const { text, type = 'info' } = props; | ||
| /** | ||
| * A component that renders a styled badge with custom content. | ||
| * | ||
| * The Badge component displays a small, inline element with customizable content and appearance. | ||
| * It's useful for highlighting status, categories, or other short pieces of information. | ||
| * | ||
| * @param {BadgeProps} props - The properties for the Badge component. | ||
| * @returns {JSX.Element} A span element representing the badge. | ||
| * | ||
| * @example | ||
| * Using children: | ||
| * <Badge type="info">New</Badge> | ||
| * <Badge type="warning" outline>Experimental</Badge> | ||
| * <Badge type="danger">Deprecated</Badge> | ||
| * <Badge type="tip" outline><strong>Pro Tip:</strong> Use custom elements</Badge> | ||
| * | ||
| * Using text prop: | ||
| * <Badge text="New" type="info" /> | ||
| * <Badge text="Experimental" type="warning" outline /> | ||
| * <Badge text="Deprecated" type="danger" /> | ||
| */ | ||
| export function Badge({ | ||
| children, | ||
| type = 'tip', | ||
| text, | ||
| outline = false, | ||
| }: BadgeProps) { | ||
| const content = children || text; | ||
|
|
||
| return ( | ||
| <span | ||
| className={`inline-block rounded-full border border-solid border-transparent font-medium ${styles.badge} ${styles[type]}`} | ||
| className={`inline-flex items-center justify-center rounded-full border border-solid ${ | ||
| outline ? 'border-current' : 'border-transparent' | ||
| } font-semibold align-middle px-2.5 h-6 gap-1 text-xs ${styles.badge} ${styles[type]} ${ | ||
| outline ? styles.outline : '' | ||
| }`} | ||
| > | ||
| {text} | ||
| {content} | ||
| </span> | ||
| ); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.