-
Notifications
You must be signed in to change notification settings - Fork 1
docs: add per-component lifecycle status badges #738
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4bc3e78
docs: add per-component lifecycle status badges (pds-button, modal, t…
QuintonJason 25cf513
docs: source StatusBadge from component-status.json manifest
QuintonJason 2031e57
fix(docs): address StatusBadge Bugbot review feedback
QuintonJason 176068c
fix(docs): harden StatusBadge manifest lookup and note resolution
QuintonJason 29eb61b
docs(storybook): convert component-status tables to pds-table formatting
QuintonJason 0e7daf9
style(storybook): tint status badge background per status to match chips
QuintonJason 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
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
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,56 @@ | ||
| .pine-status-badge { | ||
| --pine-status-badge-bg: var(--pine-color-background-subtle); | ||
| --pine-status-badge-fg: var(--pine-color-text-primary); | ||
| --pine-status-badge-dot: currentColor; | ||
|
|
||
| align-items: center; | ||
| background-color: var(--pine-status-badge-bg); | ||
| border-radius: 999px; | ||
| color: var(--pine-status-badge-fg); | ||
| display: inline-flex; | ||
| font-size: 0.8125rem; | ||
| font-weight: 500; | ||
| gap: 0.5rem; | ||
| line-height: 1.2; | ||
| margin: 0 0 1rem; | ||
| padding: 0.25rem 0.625rem; | ||
| } | ||
|
|
||
| .pine-status-badge__dot { | ||
| background-color: var(--pine-status-badge-dot); | ||
| border-radius: 50%; | ||
| display: inline-block; | ||
| flex: 0 0 auto; | ||
| height: 0.5rem; | ||
| width: 0.5rem; | ||
| } | ||
|
|
||
| .pine-status-badge__note { | ||
| color: inherit; | ||
| font-weight: 400; | ||
| opacity: 0.8; | ||
| } | ||
|
|
||
| .pine-status-badge[data-status='stable'] { | ||
| --pine-status-badge-bg: var(--pine-color-success-disabled); | ||
| --pine-status-badge-fg: var(--pine-color-text-success); | ||
| --pine-status-badge-dot: var(--pine-color-success-hover); | ||
| } | ||
|
|
||
| .pine-status-badge[data-status='beta'] { | ||
| --pine-status-badge-bg: var(--pine-color-warning-disabled); | ||
| --pine-status-badge-fg: var(--pine-color-text-warning); | ||
| --pine-status-badge-dot: var(--pine-color-warning-hover); | ||
| } | ||
|
|
||
| .pine-status-badge[data-status='deprecated'] { | ||
| --pine-status-badge-bg: var(--pine-color-danger-disabled); | ||
| --pine-status-badge-fg: var(--pine-color-text-danger); | ||
| --pine-status-badge-dot: var(--pine-color-danger-hover); | ||
| } | ||
|
|
||
| .pine-status-badge[data-status='unknown'] { | ||
| --pine-status-badge-bg: var(--pine-color-warning-disabled); | ||
| --pine-status-badge-fg: var(--pine-color-text-warning); | ||
| --pine-status-badge-dot: var(--pine-color-warning-hover); | ||
| } |
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,142 @@ | ||
| import React from 'react'; | ||
|
|
||
| import componentStatus from '../resources/component-status.json'; | ||
| import './StatusBadge.css'; | ||
|
|
||
| export type ComponentStatus = 'stable' | 'beta' | 'deprecated'; | ||
|
|
||
| /** Display-only when manifest lookup fails or status is invalid. */ | ||
| type ResolvedStatus = ComponentStatus | 'unknown'; | ||
|
|
||
| export interface StatusBadgeProps { | ||
| /** | ||
| * Component tag (for example `pds-button`). When provided the badge | ||
| * reads the lifecycle label from `component-status.json` so the badge | ||
| * and the central status table cannot drift. | ||
| */ | ||
| component?: string; | ||
|
|
||
| /** | ||
| * Lifecycle label override. Takes priority over the JSON manifest when | ||
| * both are set — use to force a status that differs from the central | ||
| * table (rare; prefer updating the JSON manifest). | ||
| */ | ||
| status?: ComponentStatus; | ||
|
|
||
| /** Optional inline note (for example: 'Replaced by `pds-property`'). */ | ||
| note?: string; | ||
| } | ||
|
|
||
| interface ComponentEntry { | ||
| status: ComponentStatus; | ||
| note?: string; | ||
| } | ||
|
|
||
| const VALID_STATUSES: readonly ComponentStatus[] = ['stable', 'beta', 'deprecated']; | ||
|
|
||
| const STATUS_LABELS: Record<ResolvedStatus, string> = { | ||
| stable: 'Stable', | ||
| beta: 'Beta', | ||
| deprecated: 'Deprecated', | ||
| unknown: 'Unknown', | ||
| }; | ||
|
|
||
| const COMPONENTS = componentStatus.components as Record<string, ComponentEntry>; | ||
|
|
||
| function isComponentStatus(value: unknown): value is ComponentStatus { | ||
| return typeof value === 'string' && (VALID_STATUSES as readonly string[]).includes(value); | ||
| } | ||
|
|
||
| function isComponentEntry(value: unknown): value is ComponentEntry { | ||
| return value != null && typeof value === 'object'; | ||
| } | ||
|
|
||
| function warnDev(message: string): void { | ||
| if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') { | ||
| // eslint-disable-next-line no-console | ||
| console.warn(`[StatusBadge] ${message}`); | ||
| } | ||
| } | ||
|
|
||
| function resolveStatus( | ||
| component: string | undefined, | ||
| status: ComponentStatus | undefined, | ||
| entry: ComponentEntry | undefined, | ||
| ): ResolvedStatus { | ||
| if (status !== undefined) { | ||
| if (!isComponentStatus(status)) { | ||
| warnDev(`Invalid status prop "${status}".`); | ||
| return 'unknown'; | ||
| } | ||
| return status; | ||
| } | ||
|
|
||
| if (isComponentEntry(entry)) { | ||
| if (!isComponentStatus(entry.status)) { | ||
| warnDev( | ||
| `Invalid status "${String(entry.status)}" for "${component ?? 'component'}" in component-status.json.`, | ||
| ); | ||
| return 'unknown'; | ||
| } | ||
| return entry.status; | ||
| } | ||
|
|
||
| if (component !== undefined) { | ||
| warnDev(`"${component}" is not listed in component-status.json.`); | ||
| return 'unknown'; | ||
| } | ||
|
|
||
| return 'stable'; | ||
| } | ||
|
|
||
| function buildAriaLabel(label: string, note: string | undefined): string { | ||
| if (note !== undefined && note !== '') { | ||
| return `Component status: ${label}. ${note}`; | ||
| } | ||
| return `Component status: ${label}`; | ||
| } | ||
|
|
||
| /** | ||
| * Renders the per-component lifecycle label that mirrors the central | ||
| * Resources/Component status table. Apply once at the top of each | ||
| * component's MDX page so consumers see stability state without | ||
| * navigating elsewhere. | ||
| * | ||
| * Source of truth: `libs/core/src/stories/resources/component-status.json`. | ||
| * Pass the component tag (`component="pds-button"`) so the badge stays | ||
| * in sync automatically. | ||
| */ | ||
| export const StatusBadge: React.FC<StatusBadgeProps> = ({ component, status, note }) => { | ||
| const rawEntry = component !== undefined ? COMPONENTS[component] : undefined; | ||
| let entry: ComponentEntry | undefined; | ||
|
|
||
| if (rawEntry === undefined) { | ||
| entry = undefined; | ||
| } else if (isComponentEntry(rawEntry)) { | ||
| entry = rawEntry; | ||
| } else { | ||
| warnDev(`Invalid entry for "${component}" in component-status.json.`); | ||
| entry = undefined; | ||
| } | ||
|
|
||
| const resolvedStatus = resolveStatus(component, status, entry); | ||
| const resolvedNote = | ||
| note ?? (status === undefined && entry !== undefined ? entry.note : undefined); | ||
| const label = STATUS_LABELS[resolvedStatus]; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| const ariaLabel = buildAriaLabel(label, resolvedNote); | ||
|
|
||
| return ( | ||
| <div | ||
| className="pine-status-badge" | ||
| data-status={resolvedStatus} | ||
| role="note" | ||
| aria-label={ariaLabel} | ||
| > | ||
| <span className="pine-status-badge__dot" aria-hidden="true" /> | ||
| <span className="pine-status-badge__label">{label}</span> | ||
| {resolvedNote !== undefined && resolvedNote !== '' ? ( | ||
| <span className="pine-status-badge__note">— {resolvedNote}</span> | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| ) : null} | ||
| </div> | ||
| ); | ||
| }; | ||
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
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.