Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/components/moz-status-badge/moz-status-badge.css
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down
79 changes: 77 additions & 2 deletions src/components/moz-status-badge/moz-status-badge.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ 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;
}

const types: StatusBadgeType[] = [
'default',
'ghost',
'neutral',
'success',
'warning',
'critical',
Expand All @@ -27,15 +30,21 @@ const meta: Meta<Args> = {
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`
<moz-status-badge type=${args.type} icon-start=${ifDefined(args.iconStart)}>
<moz-status-badge
type=${args.type}
size=${args.size}
icon-start=${ifDefined(args.iconStart)}
>
${args.label}
</moz-status-badge>
`,
Expand Down Expand Up @@ -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`
<moz-status-badge type=${args.type}>
<moz-icon slot="icon" name="notification-fill" color="success"></moz-icon>
${args.label}
</moz-status-badge>
`,
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`
<moz-status-badge size=${args.size} type=${args.type}>
<moz-icon slot="icon" name="history" color="warning"></moz-icon>
${args.label}
</moz-status-badge>
`,
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`
<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;">
Expand All @@ -73,3 +133,18 @@ export const AllTypes: Story = {
</div>
`,
};

export const AllSizes: Story = {
render: () => html`
<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;">
<moz-status-badge>
<moz-icon slot="icon" name="notification-fill" color="success"></moz-icon>
Live
</moz-status-badge>
<moz-status-badge size="large">
<moz-icon slot="icon" name="notification-fill" color="success"></moz-icon>
Live
</moz-status-badge>
</div>
`,
};
16 changes: 12 additions & 4 deletions src/components/moz-status-badge/moz-status-badge.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand All @@ -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;

Expand All @@ -41,7 +49,7 @@ export class MozStatusBadge extends MozLitElement {
${
this.iconStart
? html`<moz-icon class="icon" name=${this.iconStart}></moz-icon>`
: nothing
: html`<slot name="icon"></slot>`
}
<span class="label"><slot></slot></span>
</span>
Expand Down
6 changes: 3 additions & 3 deletions src/components/moz-status-dot/moz-status-dot.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions src/components/moz-status-dot/moz-status-dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatusBadgeType, 'neutral'>;

// Each status's glyph, matching moz-message-bar.
const typeIcon: Record<StatusBadgeType, IconName> = {
const typeIcon: Record<StatusDotType, IconName> = {
ghost: 'information-fill',
default: 'information-fill',
information: 'information-fill',
Expand All @@ -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;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions tests/visual/moz-status-badge.visual.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -20,6 +22,14 @@ const badges = html`<div
<moz-status-badge type="success" icon-start="checkmark"
>Approved</moz-status-badge
>
<moz-status-badge>
<moz-icon slot="icon" name="notification-fill" color="success"></moz-icon>
Live
</moz-status-badge>
<moz-status-badge size="large">
<moz-icon slot="icon" name="history" color="warning"></moz-icon>
Awaiting review
</moz-status-badge>
</div>`;

test('status-badge variants', () => snapshot('status-badge-variants', badges));
Expand Down