diff --git a/src/components/moz-status-badge/moz-status-badge.css b/src/components/moz-status-badge/moz-status-badge.css index 4d0360a..b3503d4 100644 --- a/src/components/moz-status-badge/moz-status-badge.css +++ b/src/components/moz-status-badge/moz-status-badge.css @@ -10,10 +10,10 @@ box-sizing: border-box; display: inline-flex; align-items: center; - gap: var(--space-xxsmall); + gap: var(--space-xsmall); inline-size: fit-content; min-block-size: 22px; - padding-inline: var(--space-xsmall); + padding-inline: var(--space-small); /* Faint inset ring on every type; --badge-border-color is the shared 40% * neutral. box-sizing keeps the height at 22px with the border included. */ @@ -30,11 +30,26 @@ --icon-color: currentColor; } -.icon { +.icon, +::slotted([slot="icon"]) { --icon-size: var(--icon-size-xsmall); flex-shrink: 0; } +/* The large step: root-size text in a 32px pill, for a status that stands on + * its own rather than trailing a title. */ +:host([size="large"]) .badge { + gap: var(--space-small); + min-block-size: 32px; + padding-inline: var(--space-medium); + font-size: var(--font-size-root); +} + +:host([size="large"]) .icon, +:host([size="large"]) ::slotted([slot="icon"]) { + --icon-size: var(--icon-size-small); +} + :host([type="ghost"]) { --status-badge-color: var(--button-text-color); } @@ -76,6 +91,12 @@ --status-badge-background-color: var(--background-color-information); } +/* A status that's inert rather than good or bad (superseded, archived): the + * muted box surface, with the normal text color. */ +:host([type="neutral"]) { + --status-badge-background-color: var(--background-color-box-info); +} + /* Faint borders can drop under forced colors, so pin a visible one. */ @media (forced-colors: active) { .badge { diff --git a/src/components/moz-status-badge/moz-status-badge.stories.ts b/src/components/moz-status-badge/moz-status-badge.stories.ts index b7beb81..673a84d 100644 --- a/src/components/moz-status-badge/moz-status-badge.stories.ts +++ b/src/components/moz-status-badge/moz-status-badge.stories.ts @@ -3,11 +3,13 @@ import { html } from 'lit'; import { ifDefined } from 'lit/directives/if-defined.js'; import { expect } from 'storybook/test'; import './moz-status-badge'; +import '../moz-icon/moz-icon'; import { type IconName, iconNames } from '../../generated/icons'; -import type { StatusBadgeType } from './moz-status-badge'; +import type { StatusBadgeSize, StatusBadgeType } from './moz-status-badge'; interface Args { type: StatusBadgeType; + size: StatusBadgeSize; label: string; iconStart?: IconName; } @@ -15,6 +17,7 @@ interface Args { const types: StatusBadgeType[] = [ 'default', 'ghost', + 'neutral', 'success', 'warning', 'critical', @@ -27,15 +30,21 @@ const meta: Meta = { tags: ['autodocs', 'stable'], argTypes: { type: { control: 'select', options: types }, + size: { control: 'inline-radio', options: ['default', 'large'] }, label: { control: 'text' }, iconStart: { control: 'select', options: [undefined, ...iconNames] }, }, args: { type: 'default', + size: 'default', label: 'Status', }, render: (args) => html` - + ${args.label} `, @@ -64,6 +73,57 @@ export const WithIcon: Story = { args: { type: 'success', label: 'Approved', iconStart: 'checkmark' }, }; +// The dev hub's add-on status (Figma 3018-71745): a default pill whose dot +// carries the status colour. Slotted because that colour is independent of the +// badge's type, which `icon-start` can't express. +export const WithStatusDot: Story = { + args: { type: 'default', label: 'Live' }, + render: (args) => html` + + + ${args.label} + + `, + play: async ({ canvasElement }) => { + const badge = canvasElement.querySelector('moz-status-badge')!; + await badge.updateComplete; + const icon = badge.querySelector('moz-icon')!; + await icon.updateComplete; + expect(icon.assignedSlot?.name).toBe('icon'); + // The slotted icon takes the badge's icon sizing, not moz-icon's default. + expect(getComputedStyle(icon).getPropertyValue('--icon-size')).toBe( + getComputedStyle(badge).getPropertyValue('--icon-size-xsmall'), + ); + }, +}; + +export const Neutral: Story = { + args: { type: 'neutral', label: 'Superseded' }, + tags: ['new'], +}; + +// The large step pairs with the dev hub's standalone add-on status, where the +// badge carries a 15px label rather than trailing a title. +export const Large: Story = { + args: { size: 'large', label: 'Awaiting review' }, + tags: ['new'], + render: (args) => html` + + + ${args.label} + + `, + play: async ({ canvasElement }) => { + const badge = canvasElement.querySelector('moz-status-badge')!; + await badge.updateComplete; + const icon = badge.querySelector('moz-icon')!; + await icon.updateComplete; + expect(badge.getBoundingClientRect().height).toBe(32); + // The large step steps the icon up with the text. + expect(icon.getBoundingClientRect().width).toBe(16); + }, +}; + export const AllTypes: Story = { render: () => html`
@@ -73,3 +133,18 @@ export const AllTypes: Story = {
`, }; + +export const AllSizes: Story = { + render: () => html` +
+ + + Live + + + + Live + +
+ `, +}; diff --git a/src/components/moz-status-badge/moz-status-badge.ts b/src/components/moz-status-badge/moz-status-badge.ts index 78d0242..03db990 100644 --- a/src/components/moz-status-badge/moz-status-badge.ts +++ b/src/components/moz-status-badge/moz-status-badge.ts @@ -1,4 +1,4 @@ -import { html, nothing } from 'lit'; +import { html } from 'lit'; import { property } from 'lit/decorators.js'; import { MozLitElement } from '../../base/moz-lit-element'; import shared from '../../base/shared.css'; @@ -11,19 +11,24 @@ import styles from './moz-status-badge.css'; export type StatusBadgeType = | 'default' | 'ghost' + | 'neutral' | 'success' | 'warning' | 'critical' | 'information'; +export type StatusBadgeSize = 'default' | 'large'; + /** * Small status pill: like `moz-badge` but xsmall, normal-cased, and 22px tall, * with status color types. Colors come from the global status tokens * (`--background-color-success`, `--icon-color-success`, and so on). The label - * goes in the default slot; `icon-start` renders a leading moz-icon. Purely - * presentational. + * goes in the default slot; `icon-start` renders a leading moz-icon, or slot + * one into `icon` to control it — a status dot is a `notification-fill` icon + * with its own `color`, which the attribute can't set. Purely presentational. * * @slot - the badge label. + * @slot icon - a leading icon, when `icon-start` isn't enough. * @csspart badge - the pill container. */ export class MozStatusBadge extends MozLitElement { @@ -32,6 +37,9 @@ export class MozStatusBadge extends MozLitElement { /** Status type, selecting the color set. */ @property({ reflect: true }) type: StatusBadgeType = 'default'; + /** Size step: a 22px pill, or a 32px one with root-size text. */ + @property({ reflect: true }) size: StatusBadgeSize = 'default'; + /** Icon rendered before the label. */ @property({ attribute: 'icon-start' }) iconStart?: IconName; @@ -41,7 +49,7 @@ export class MozStatusBadge extends MozLitElement { ${ this.iconStart ? html`` - : nothing + : html`` } diff --git a/src/components/moz-status-dot/moz-status-dot.stories.ts b/src/components/moz-status-dot/moz-status-dot.stories.ts index 59c1f12..8570283 100644 --- a/src/components/moz-status-dot/moz-status-dot.stories.ts +++ b/src/components/moz-status-dot/moz-status-dot.stories.ts @@ -3,15 +3,15 @@ import { html } from 'lit'; import { ifDefined } from 'lit/directives/if-defined.js'; import { expect } from 'storybook/test'; import './moz-status-dot'; -import type { StatusBadgeType } from '../moz-status-badge/moz-status-badge'; +import type { StatusDotType } from './moz-status-dot'; interface Args { - type: StatusBadgeType; + type: StatusDotType; icon: boolean; label?: string; } -const types: StatusBadgeType[] = [ +const types: StatusDotType[] = [ 'information', 'success', 'warning', diff --git a/src/components/moz-status-dot/moz-status-dot.ts b/src/components/moz-status-dot/moz-status-dot.ts index 5ad749d..38bff0c 100644 --- a/src/components/moz-status-dot/moz-status-dot.ts +++ b/src/components/moz-status-dot/moz-status-dot.ts @@ -7,8 +7,11 @@ import type { IconName } from '../../generated/icons'; import type { StatusBadgeType } from '../moz-status-badge/moz-status-badge'; import styles from './moz-status-dot.css'; +/** The badge types that carry a status color; `neutral` has no dot. */ +export type StatusDotType = Exclude; + // Each status's glyph, matching moz-message-bar. -const typeIcon: Record = { +const typeIcon: Record = { ghost: 'information-fill', default: 'information-fill', information: 'information-fill', @@ -29,7 +32,7 @@ export class MozStatusDot extends MozLitElement { static styles = [shared, styles]; /** Status color. */ - @property({ reflect: true }) type: StatusBadgeType = 'information'; + @property({ reflect: true }) type: StatusDotType = 'information'; /** Show the type's icon inside the disc; omit for a solid dot. */ @property({ type: Boolean, reflect: true }) icon = false; diff --git a/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-dark-chromium-linux.png b/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-dark-chromium-linux.png index 0d4c806..996c4cd 100644 Binary files a/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-dark-chromium-linux.png and b/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-dark-chromium-linux.png differ diff --git a/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-high-contrast-chromium-linux.png b/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-high-contrast-chromium-linux.png index 9bd3e9a..0305c90 100644 Binary files a/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-high-contrast-chromium-linux.png and b/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-high-contrast-chromium-linux.png differ diff --git a/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-variants-chromium-linux.png b/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-variants-chromium-linux.png index 9041341..777b06b 100644 Binary files a/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-variants-chromium-linux.png and b/tests/visual/__screenshots__/moz-status-badge.visual.ts/status-badge-variants-chromium-linux.png differ diff --git a/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-chromium-linux.png b/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-chromium-linux.png index 54ab617..dae1146 100644 Binary files a/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-chromium-linux.png and b/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-chromium-linux.png differ diff --git a/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-dark-chromium-linux.png b/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-dark-chromium-linux.png index dd49529..37b12d6 100644 Binary files a/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-dark-chromium-linux.png and b/tests/visual/__screenshots__/moz-visual-picker.visual.ts/visual-picker-radio-dark-chromium-linux.png differ diff --git a/tests/visual/moz-status-badge.visual.ts b/tests/visual/moz-status-badge.visual.ts index 783e6b6..780fb96 100644 --- a/tests/visual/moz-status-badge.visual.ts +++ b/tests/visual/moz-status-badge.visual.ts @@ -1,12 +1,14 @@ import { html } from 'lit'; import { test } from 'vitest'; import type { StatusBadgeType } from '../../src/components/moz-status-badge/moz-status-badge'; +import '../../src/components/moz-icon/moz-icon'; import '../../src/components/moz-status-badge/moz-status-badge'; import { snapshot, snapshotContrast, snapshotDark } from './snapshot'; const types: StatusBadgeType[] = [ 'default', 'ghost', + 'neutral', 'success', 'warning', 'critical', @@ -20,6 +22,14 @@ const badges = html`
Approved + + + Live + + + + Awaiting review +
`; test('status-badge variants', () => snapshot('status-badge-variants', badges));