-
Notifications
You must be signed in to change notification settings - Fork 7
feat: badge component #43
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 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2f37530
feat: badge component
olaf-k a97b4b2
Merge branch 'main' into olaf/badge
olaf-k c43fe75
fix: remove useless context, fix doc
olaf-k ee9d486
Merge branch 'main' into olaf/badge
olaf-k 3abd908
feat: split badge into 4 distinct components
olaf-k a2afac6
Merge branch 'main' into olaf/badge
olaf-k 07c762a
fix(badge): categories > colors
olaf-k 0f38ddb
Merge branch 'main' into olaf/badge
olaf-k b03ec1d
chore: update badge react doc
olaf-k e5a4a17
Merge branch 'main' into olaf/badge
R-Bower 002e513
optimized styles
R-Bower a7998a2
variant > emphasis in mdx
olaf-k a10b74e
Merge pull request #61 from qualcomm/feature/badge-style-rework
R-Bower b2deb3d
Merge branch 'main' into olaf/badge
R-Bower b2e4555
docs startup fix
R-Bower 26697db
consolidate badge emphasis docs, remove redundant docs
R-Bower 301126e
version bumps, changelogs
R-Bower 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,77 @@ | ||
| // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| // SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| import {booleanDataAttr} from "@qualcomm-ui/utils/attributes" | ||
| import type {PropNormalizer} from "@qualcomm-ui/utils/machine" | ||
|
|
||
| import {badgeClasses} from "./badge.classes" | ||
| import type { | ||
| QdsBadgeApi, | ||
| QdsBadgeApiProps, | ||
| QdsBadgeCountProps, | ||
| QdsBadgeIconBindings, | ||
| QdsBadgeIconProps, | ||
| QdsBadgeRootBindings, | ||
| QdsBadgeStatusProps, | ||
| QdsBadgeTextProps, | ||
| } from "./badge.types" | ||
|
|
||
| export function createQdsBadgeApi( | ||
| props: QdsBadgeApiProps, | ||
| normalize: PropNormalizer, | ||
| ): QdsBadgeApi { | ||
| const type = props.type || "text" | ||
| const size = props.size || "md" | ||
|
|
||
| let emphasis: string | undefined | ||
| let variant: string | undefined | ||
| let overflow = false | ||
| let displayCount: number | string | null = null | ||
|
|
||
| if (type === "count") { | ||
| const countProps = props as QdsBadgeCountProps | ||
| variant = countProps.variant || "neutral" | ||
| if (countProps.count != null) { | ||
| const max = countProps.max ?? 99 | ||
| overflow = countProps.count > max | ||
| displayCount = overflow ? `${max}+` : countProps.count | ||
| } | ||
| } else if (type === "status") { | ||
| emphasis = (props as QdsBadgeStatusProps).emphasis || "neutral" | ||
| variant = (props as QdsBadgeStatusProps).variant || "filled" | ||
| } else if (type === "icon") { | ||
| emphasis = (props as QdsBadgeIconProps).emphasis || "neutral" | ||
| variant = (props as QdsBadgeIconProps).variant || "default" | ||
| } else { | ||
| emphasis = (props as QdsBadgeTextProps).emphasis || "neutral" | ||
| variant = (props as QdsBadgeTextProps).variant || "default" | ||
| } | ||
|
|
||
| return { | ||
| getDisplayCount(): number | string | null { | ||
| return displayCount | ||
| }, | ||
| getIconBindings(): QdsBadgeIconBindings { | ||
| return normalize.element({ | ||
| className: badgeClasses.icon, | ||
| "data-part": "icon", | ||
| "data-scope": "badge", | ||
| "data-size": size, | ||
| }) | ||
| }, | ||
| getRootBindings(): QdsBadgeRootBindings { | ||
| return normalize.element({ | ||
| className: badgeClasses.root, | ||
| "data-disabled": booleanDataAttr(props.disabled), | ||
| "data-emphasis": emphasis, | ||
| "data-overflow": booleanDataAttr(overflow), | ||
| "data-part": "root", | ||
| "data-scope": "badge", | ||
| "data-size": size, | ||
| "data-type": type, | ||
| "data-variant": variant, | ||
| }) | ||
| }, | ||
| type, | ||
| } | ||
| } | ||
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,7 @@ | ||
| // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| // SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| export const badgeClasses = { | ||
| icon: "qui-badge__icon", | ||
| root: "qui-badge__root", | ||
| } as const |
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,203 @@ | ||
| // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| // SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| import type {BooleanDataAttr} from "@qualcomm-ui/utils/attributes" | ||
|
|
||
| import type {badgeClasses} from "./badge.classes" | ||
|
|
||
| export type QdsBadgeType = "count" | "icon" | "text" | "status" | ||
|
|
||
| export type QdsBadgeBasicSize = "sm" | "md" | "lg" | ||
| export type QdsBadgeExtendedSize = "xs" | QdsBadgeBasicSize | "xl" | ||
| export type QdsBadgeIconSize = "xxs" | QdsBadgeExtendedSize | ||
|
|
||
| export type QdsBadgeSize = | ||
| | QdsBadgeBasicSize | ||
| | QdsBadgeExtendedSize | ||
| | QdsBadgeIconSize | ||
|
|
||
| export type QdsBadgeSemanticEmphasis = | ||
| | "neutral" | ||
| | "brand" | ||
| | "info" | ||
| | "success" | ||
| | "warning" | ||
| | "danger" | ||
|
|
||
| export type QdsBadgeCategoryEmphasis = | ||
| | "cat-1" | ||
| | "cat-2" | ||
| | "cat-3" | ||
| | "cat-4" | ||
| | "cat-5" | ||
| | "cat-6" | ||
| | "cat-7" | ||
| | "cat-8" | ||
| | "cat-9" | ||
| | "cat-10" | ||
|
|
||
| export type QdsBadgeCountVariant = | ||
| | "neutral" | ||
| | "neutral-outline" | ||
| | "brand" | ||
| | "brand-outline" | ||
| | "info" | ||
| | "success" | ||
| | "warning" | ||
| | "danger" | ||
| | "persistent-black" | ||
| | "persistent-white" | ||
|
|
||
| export type QdsBadgeStatusEmphasis = QdsBadgeSemanticEmphasis | ||
| export type QdsBadgeStatusVariant = "filled" | "outlined" | ||
|
|
||
| export type QdsBadgeIconTextEmphasis = | ||
| | QdsBadgeSemanticEmphasis | ||
| | QdsBadgeCategoryEmphasis | ||
| export type QdsBadgeIconTextVariant = "default" | "subtle" | ||
|
|
||
| interface QdsBadgeBaseProps { | ||
| /** | ||
| * The badge disabled state. | ||
| */ | ||
| disabled?: boolean | ||
| } | ||
|
|
||
| export interface QdsBadgeCountProps extends QdsBadgeBaseProps { | ||
| /** | ||
| * The numeric count to display. | ||
| */ | ||
| count?: number | ||
|
|
||
| /** | ||
| * Maximum count to display. | ||
| * @default 99 | ||
| */ | ||
| max?: number | ||
|
|
||
| /** | ||
| * Governs the size of the badge. | ||
| * @default 'md' | ||
| */ | ||
| size?: QdsBadgeBasicSize | ||
|
|
||
| /** | ||
| * The badge type. | ||
| */ | ||
| type: "count" | ||
|
|
||
| /** | ||
| * Governs the color and style of the count badge. | ||
| * @default 'neutral' | ||
| */ | ||
| variant?: QdsBadgeCountVariant | ||
| } | ||
|
|
||
| export interface QdsBadgeStatusProps extends QdsBadgeBaseProps { | ||
| /** | ||
| * Governs the color of the status badge. | ||
| * @default 'neutral' | ||
| */ | ||
| emphasis?: QdsBadgeStatusEmphasis | ||
|
|
||
| /** | ||
| * Governs the size of the badge. | ||
| * @default 'md' | ||
| */ | ||
| size?: QdsBadgeExtendedSize | ||
|
|
||
| /** | ||
| * The badge type. | ||
| */ | ||
| type: "status" | ||
|
|
||
| /** | ||
| * Governs the style of the status badge. | ||
| * @default 'filled' | ||
| */ | ||
| variant?: QdsBadgeStatusVariant | ||
| } | ||
|
|
||
| export interface QdsBadgeIconProps extends QdsBadgeBaseProps { | ||
| /** | ||
| * Governs the color of the icon badge. | ||
| * @default 'neutral' | ||
| */ | ||
| emphasis?: QdsBadgeIconTextEmphasis | ||
|
|
||
| /** | ||
| * Governs the size of the badge. | ||
| * @default 'md' | ||
| */ | ||
| size?: QdsBadgeIconSize | ||
|
|
||
| /** | ||
| * The badge type. | ||
| */ | ||
| type: "icon" | ||
|
|
||
| /** | ||
| * Governs the style of the icon badge. | ||
| * @default 'default' | ||
| */ | ||
| variant?: QdsBadgeIconTextVariant | ||
| } | ||
|
|
||
| export interface QdsBadgeTextProps extends QdsBadgeBaseProps { | ||
| /** | ||
| * Governs the color of the text badge. | ||
| * @default 'neutral' | ||
| */ | ||
| emphasis?: QdsBadgeIconTextEmphasis | ||
|
|
||
| /** | ||
| * Governs the size of the badge. | ||
| * @default 'md' | ||
| */ | ||
| size?: QdsBadgeBasicSize | ||
|
|
||
| /** | ||
| * The badge type. | ||
| */ | ||
| type?: "text" | ||
|
|
||
| /** | ||
| * Governs the style of the text badge. | ||
| * @default 'default' | ||
| */ | ||
| variant?: QdsBadgeIconTextVariant | ||
| } | ||
|
|
||
| export type QdsBadgeApiProps = | ||
| | QdsBadgeCountProps | ||
| | QdsBadgeStatusProps | ||
| | QdsBadgeIconProps | ||
| | QdsBadgeTextProps | ||
|
|
||
| type BadgeClasses = typeof badgeClasses | ||
|
|
||
| export interface QdsBadgeRootBindings { | ||
| className: BadgeClasses["root"] | ||
| "data-disabled": BooleanDataAttr | ||
| "data-emphasis"?: string | ||
| "data-overflow": BooleanDataAttr | ||
| "data-part": "root" | ||
| "data-scope": "badge" | ||
| "data-size": QdsBadgeSize | ||
| "data-type": QdsBadgeType | ||
| "data-variant"?: string | ||
| } | ||
|
|
||
| export interface QdsBadgeIconBindings { | ||
| className: BadgeClasses["icon"] | ||
| "data-part": "icon" | ||
| "data-scope": "badge" | ||
| "data-size": QdsBadgeSize | ||
| } | ||
|
|
||
| export interface QdsBadgeApi { | ||
| getDisplayCount(): number | string | null | ||
| getIconBindings(): QdsBadgeIconBindings | ||
| getRootBindings(): QdsBadgeRootBindings | ||
| type: QdsBadgeType | ||
| } |
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,3 @@ | ||
| export * from "./badge.api" | ||
| export * from "./badge.classes" | ||
| export type * from "./badge.types" |
Oops, something went wrong.
Oops, something went wrong.
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.