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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DocFooter from "@/common/DocFooter";
import { TableCode } from "@/common/Code";
import Example from "@/common/example/Example";
import basicUsage from "./examples/basicUsage";
import StatusBadge from "@/common/StatusBadge";

const sections = [
{
Expand All @@ -21,16 +20,16 @@ const sections = [
</thead>
<tbody>
<tr>
<td>label</td>
<td>
<DxcFlex direction="column" gap="var(--spacing-gap-xs)" alignItems="baseline">
<StatusBadge status="required" />
label
</DxcFlex>
<TableCode>string</TableCode>
</td>
<td>
<TableCode>string</TableCode>
An auxiliary text that will add some context to the status. It is the only accessible text of the
component: without it, the status light is only a colored dot and it must be accompanied by a visible
element or by surrounding context that explains its meaning. Screen readers only announce the status when
a label is provided.
</td>
<td>An auxiliary text that will add some context to the status.</td>
<td>-</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const sections = [
easy recognition.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Label:</strong> a short text description alongside the status light to provide additional context.
<strong>Label (Optional):</strong> a short text description alongside the status light to provide additional
context.
</DxcBulletedList.Item>
</DxcBulletedList>
</>
Expand Down
63 changes: 63 additions & 0 deletions packages/lib/src/status-light/StatusLight.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {

const StatusLight = () => (
<>
<Title title="With label" theme="light" level={2} />
<ExampleContainer>
<Title title="Default light small" theme="light" level={4} />
<DxcStatusLight label="StatusLight" size="small" />
Expand Down Expand Up @@ -77,6 +78,68 @@ const StatusLight = () => (
<DxcStatusLight label="Very long label to try to force ellipsis" />
</DxcContainer>
</ExampleContainer>

<Title title="Without label" theme="light" level={2} />
<ExampleContainer>
<Title title="Default light small" theme="light" level={4} />
<DxcStatusLight size="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Default light medium" theme="light" level={4} />
<DxcStatusLight />
</ExampleContainer>
<ExampleContainer>
<Title title="Default light large" theme="light" level={4} />
<DxcStatusLight size="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="Info light small" theme="light" level={4} />
<DxcStatusLight mode="info" size="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Info light medium" theme="light" level={4} />
<DxcStatusLight mode="info" />
</ExampleContainer>
<ExampleContainer>
<Title title="Info light large" theme="light" level={4} />
<DxcStatusLight mode="info" size="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="Success light small" theme="light" level={4} />
<DxcStatusLight mode="success" size="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Success lights medium" theme="light" level={4} />
<DxcStatusLight mode="success" />
</ExampleContainer>
<ExampleContainer>
<Title title="Success lights large" theme="light" level={4} />
<DxcStatusLight mode="success" size="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="Warning light small" theme="light" level={4} />
<DxcStatusLight mode="warning" size="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Warning light medium" theme="light" level={4} />
<DxcStatusLight mode="warning" />
</ExampleContainer>
<ExampleContainer>
<Title title="Warning light large" theme="light" level={4} />
<DxcStatusLight mode="warning" size="large" />
</ExampleContainer>
<ExampleContainer>
<Title title="Error light small" theme="light" level={4} />
<DxcStatusLight mode="error" size="small" />
</ExampleContainer>
<ExampleContainer>
<Title title="Error lights medium" theme="light" level={4} />
<DxcStatusLight mode="error" />
</ExampleContainer>
<ExampleContainer>
<Title title="Error lights large" theme="light" level={4} />
<DxcStatusLight mode="error" size="large" />
</ExampleContainer>
</>
);

Expand Down
19 changes: 8 additions & 11 deletions packages/lib/src/status-light/StatusLight.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ import { render } from "@testing-library/react";
import DxcStatusLight from "./StatusLight";

describe("StatusLight component tests", () => {
test("StatusLight renders with correct label", () => {
const { getByText } = render(<DxcStatusLight label="Status Light Test" />);
expect(getByText("Status Light Test")).toBeTruthy();
});
test("StatusLight renders with role 'status'", () => {
const { getByRole } = render(<DxcStatusLight label="Status Light Test" />);
expect(getByRole("status")).toBeTruthy();
test("StatusLight with label has role status and shows the label", () => {
const { getByRole } = render(<DxcStatusLight label="Online" />);
const status = getByRole("status");
expect(status.textContent).toBe("Online");
});

test("StatusLight dot is aria-hidden", () => {
const { container } = render(<DxcStatusLight label="Hidden Dot Test" />);
const dot = container.querySelector("div[aria-hidden='true']");
expect(dot).toBeTruthy();
test("StatusLight without label has no status role, since there is nothing to announce", () => {
const { queryByRole, container } = render(<DxcStatusLight mode="error" />);
expect(queryByRole("status")).toBeNull();
expect(container.querySelector("[aria-hidden='true']")).not.toBeNull();
});
});
10 changes: 6 additions & 4 deletions packages/lib/src/status-light/StatusLight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ const Label = styled.span<{

export default function DxcStatusLight({ label, mode = "default", size = "medium" }: StatusLightProps) {
return (
<StatusLightContainer role="status" size={size}>
<StatusLightContainer role={label ? "status" : undefined} size={size}>
<Dot mode={mode} size={size} aria-hidden="true" />
<Label mode={mode} size={size}>
{label}
</Label>
{label && (
<Label mode={mode} size={size}>
{label}
</Label>
)}
</StatusLightContainer>
);
}
6 changes: 4 additions & 2 deletions packages/lib/src/status-light/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export type StatusLightProps = {
*/
mode?: Mode;
/**
* An auxiliar text that will add some context to the status.
* An auxiliar text that will add some context to the status. It is the only accessible text of the component:
* without it, the status light is only a colored dot and it must be accompanied by a visible element or by
* surrounding context that explains its meaning. Screen readers only announce the status when a label is provided.
*/
label: string;
label?: string;
/**
* Size of the component. Should be defined based on its importance and/or available space.
*/
Expand Down
Loading