Skip to content
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

Add status prop and rename state prop to stage for steps in SteppedTracker #3584

Merged
merged 23 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
28d7124
Adding error and warning statuses to TrackerStep
tomhazledine Jun 17, 2024
60a74ae
Adding statuses example to Stepped Tracker docs
tomhazledine Jun 17, 2024
773d1c8
changeset for SteppedTracker statuses
tomhazledine Jun 17, 2024
5d49459
adding error and warning examples to QA stories
tomhazledine Jun 18, 2024
42ae96d
Tests for SteppedTracker warning and error states
tomhazledine Jun 18, 2024
ee30390
renaming TrackerStep state prop
tomhazledine Jun 25, 2024
84456a3
New stage and status props for TrackerStep
tomhazledine Jul 4, 2024
2922af0
changeset and tests update for new TrackerStep props
tomhazledine Jul 4, 2024
ad43fb2
story and example updates for new TrackerStep props
tomhazledine Jul 4, 2024
953272b
stage and status type descriptions
tomhazledine Jul 8, 2024
a4ad682
renaming state to stage in examples to avoid confusion
tomhazledine Jul 8, 2024
cc93b45
removing undefined from status options
tomhazledine Jul 8, 2024
aee634d
updating stage and status example text
tomhazledine Jul 8, 2024
6956244
Using ValidationStatus type for TrackerStep
tomhazledine Jul 17, 2024
3b783a3
removing references to state in TrackerStep
tomhazledine Jul 17, 2024
e8550d0
appease linter
tomhazledine Jul 17, 2024
d4ffdd4
removing redundant StackLayout
tomhazledine Jul 19, 2024
96f2839
removing redundant use of index as key
tomhazledine Jul 19, 2024
43baac1
matching example name to docs description
tomhazledine Jul 19, 2024
dfdb7d1
removing focus on icon from SteppedTracker docs
tomhazledine Jul 19, 2024
a4e3b68
inlining type
tomhazledine Jul 19, 2024
67d789d
apply stage, status, and active classes to TrackerStep
tomhazledine Jul 24, 2024
5b2c0be
Add step icon combo states to qa stories
tomhazledine Jul 24, 2024
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
5 changes: 5 additions & 0 deletions .changeset/short-plants-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@salt-ds/lab": minor
---

Replaced TrackerStep's `state` prop with new `stage` and `status` props. Valid `stage` values are `"pending"` and `"completed"`. Valid `status` values are `"error"` and `"warning"`.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("GIVEN a SteppedTracker", () => {
{labels.map((label, key) => (
<TrackerStep
key={key}
state={key === completedStep ? "completed" : undefined}
stage={key === completedStep ? "completed" : undefined}
>
<StepLabel>{label}</StepLabel>
</TrackerStep>
Expand All @@ -114,7 +114,7 @@ describe("GIVEN a SteppedTracker", () => {
.should("not.exist");
});

it("should show completed icon if a state is completed and active", () => {
it("should show completed icon if stage prop is completed and step is active", () => {
const labels = ["Step 1", "Step 2", "Step 3"];

const stepNum = 1;
Expand All @@ -124,7 +124,7 @@ describe("GIVEN a SteppedTracker", () => {
{labels.map((label, key) => (
<TrackerStep
key={key}
state={key === stepNum ? "completed" : undefined}
stage={key === stepNum ? "completed" : undefined}
>
<StepLabel>{label}</StepLabel>
</TrackerStep>
Expand All @@ -143,4 +143,92 @@ describe("GIVEN a SteppedTracker", () => {
.findByTestId("StepActiveIcon")
.should("not.exist");
});

it("should show warning icon if status prop is warning", () => {
const labels = ["Step 1", "Step 2", "Step 3"];

const TestComponent = (
<SteppedTracker activeStep={0} style={{ width: 300 }}>
{labels.map((label, key) => (
<TrackerStep key={key} status={key === 1 ? "warning" : undefined}>
<StepLabel>{label}</StepLabel>
</TrackerStep>
))}
</SteppedTracker>
);

cy.mount(TestComponent);

cy.findAllByRole("listitem")
.filter(`:nth-child(${2})`)
.findByTestId("WarningSolidIcon")
.should("exist");
});

it("should show completed icon if status prop is warning but stage prop is completed", () => {
const labels = ["Step 1", "Step 2", "Step 3"];

const TestComponent = (
<SteppedTracker activeStep={0} style={{ width: 300 }}>
{labels.map((label, key) => (
<TrackerStep
key={key}
stage={key <= 1 ? "completed" : undefined}
status={key === 1 ? "warning" : undefined}
>
<StepLabel>{label}</StepLabel>
</TrackerStep>
))}
</SteppedTracker>
);

cy.mount(TestComponent);

cy.findAllByRole("listitem")
.filter(`:nth-child(${2})`)
.findByTestId("StepSuccessIcon")
.should("exist");
});

it("should show active icon if status prop is warning but step is active", () => {
const labels = ["Step 1", "Step 2", "Step 3"];

const TestComponent = (
<SteppedTracker activeStep={1} style={{ width: 300 }}>
{labels.map((label, key) => (
<TrackerStep key={key} status={key === 1 ? "warning" : undefined}>
<StepLabel>{label}</StepLabel>
</TrackerStep>
))}
</SteppedTracker>
);

cy.mount(TestComponent);

cy.findAllByRole("listitem")
.filter(`:nth-child(${2})`)
.findByTestId("StepActiveIcon")
.should("exist");
});

it("should show error icon if status prop is error", () => {
const labels = ["Step 1", "Step 2", "Step 3"];

const TestComponent = (
<SteppedTracker activeStep={0} style={{ width: 300 }}>
{labels.map((label, key) => (
<TrackerStep key={key} status={key === 1 ? "error" : undefined}>
<StepLabel>{label}</StepLabel>
</TrackerStep>
))}
</SteppedTracker>
);

cy.mount(TestComponent);

cy.findAllByRole("listitem")
.filter(`:nth-child(${2})`)
.findByTestId("ErrorSolidIcon")
.should("exist");
});
});
12 changes: 11 additions & 1 deletion packages/lab/src/stepped-tracker/TrackerStep/TrackerStep.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.saltTrackerStep {
--trackerStep-icon-color-active: var(--saltTrackerStep-icon-color-active, var(--salt-status-info-foreground-decorative));
--trackerStep-icon-color-completed: var(--saltTrackerStep-icon-color-completed, var(--salt-status-success-foreground-decorative));
--trackerStep-icon-color-warning: var(--saltTrackerStep-icon-color-warning, var(--salt-status-warning-foreground-decorative));
--trackerStep-icon-color-error: var(--saltTrackerStep-icon-color-error, var(--salt-status-error-foreground-decorative));

--trackerStep-icon-color: var(--saltTrackerStep-icon-color, var(--salt-status-static-foreground));

Expand Down Expand Up @@ -50,10 +52,18 @@
flex-direction: column;
}

.saltTrackerStep.saltTrackerStep-status-warning {
--trackerStep-icon-color: var(--trackerStep-icon-color-warning);
}

.saltTrackerStep.saltTrackerStep-status-error {
--trackerStep-icon-color: var(--trackerStep-icon-color-error);
}

.saltTrackerStep.saltTrackerStep-active {
--trackerStep-icon-color: var(--trackerStep-icon-color-active);
}

.saltTrackerStep.saltTrackerStep-completed {
.saltTrackerStep.saltTrackerStep-stage-completed {
--trackerStep-icon-color: var(--trackerStep-icon-color-completed);
}
82 changes: 44 additions & 38 deletions packages/lab/src/stepped-tracker/TrackerStep/TrackerStep.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { makePrefixer } from "@salt-ds/core";
import { type ValidationStatus, makePrefixer } from "@salt-ds/core";
import {
ErrorSolidIcon,
StepActiveIcon,
StepDefaultIcon,
StepSuccessIcon,
WarningSolidIcon,
} from "@salt-ds/icons";
import { useComponentCssInjection } from "@salt-ds/styles";
import { useWindow } from "@salt-ds/window";
Expand All @@ -19,46 +21,28 @@ import trackerStepCss from "./TrackerStep.css";

const withBaseName = makePrefixer("saltTrackerStep");

type State = "default" | "completed";

type StateWithActive = State | "active";
type StageOptions = "pending" | "completed";
type StatusOptions = Extract<ValidationStatus, "warning" | "error">;

export interface TrackerStepProps extends ComponentPropsWithoutRef<"li"> {
/**
* The state of the TrackerStep
* The stage of the step: "pending" or "completed" (note, "active" is derived from "activeStep" in parent SteppedTracker component)
*/
stage?: StageOptions;
/**
* The status of the step: warning or error
*
* If the stage is completed or active, the status prop will be ignored
*/
state?: State;
status?: StatusOptions;
}
tomhazledine marked this conversation as resolved.
Show resolved Hide resolved

const iconMap = {
default: StepDefaultIcon,
pending: StepDefaultIcon,
active: StepActiveIcon,
completed: StepSuccessIcon,
};

const getStateIcon = ({
isActive,
state,
}: {
isActive: boolean;
state: State;
}) => {
if (state === "default" && isActive) {
return StepActiveIcon;
}
return iconMap[state];
};

const getState = ({
isActive,
state,
}: {
isActive: boolean;
state: State;
}): StateWithActive => {
if (state === "default" && isActive) {
return "active";
}
return state;
warning: WarningSolidIcon,
error: ErrorSolidIcon,
};

const useCheckWithinSteppedTracker = (isWithinSteppedTracker: boolean) => {
Expand All @@ -73,10 +57,26 @@ const useCheckWithinSteppedTracker = (isWithinSteppedTracker: boolean) => {
}, [isWithinSteppedTracker]);
};

const parseIconName = ({
stage,
status,
active,
}: {
stage: StageOptions;
status?: StatusOptions;
active: boolean;
}) => {
if (stage === "completed") return "completed";
if (active) return "active";
if (status) return status;
return stage;
};
joshwooding marked this conversation as resolved.
Show resolved Hide resolved

export const TrackerStep = forwardRef<HTMLLIElement, TrackerStepProps>(
function TrackerStep(props, ref) {
const {
state = "default",
stage = "pending",
status,
style,
className,
children,
Expand All @@ -97,8 +97,9 @@ export const TrackerStep = forwardRef<HTMLLIElement, TrackerStepProps>(
useCheckWithinSteppedTracker(isWithinSteppedTracker);

const isActive = activeStep === stepNumber;
const Icon = getStateIcon({ isActive, state });
const resolvedState = getState({ isActive, state });
const iconName = parseIconName({ stage, status, active: isActive });

const Icon = iconMap[iconName];
const connectorState = activeStep > stepNumber ? "active" : "default";
const hasConnector = stepNumber < totalSteps - 1;

Expand All @@ -109,10 +110,15 @@ export const TrackerStep = forwardRef<HTMLLIElement, TrackerStepProps>(

return (
<li
className={clsx(withBaseName(), withBaseName(resolvedState), className)}
className={clsx(
withBaseName(),
withBaseName(`stage-${stage}`),
withBaseName(`status-${status}`),
{ [withBaseName("active")]: isActive },
className,
)}
style={innerStyle}
aria-current={isActive ? "step" : undefined}
data-state={state}
ref={ref}
{...restProps}
>
Expand Down
Loading
Loading