Skip to content

Commit

Permalink
Update Steps to array of objects (#3761)
Browse files Browse the repository at this point in the history
* Update Workflow Step and Steps types and id logic

* add test coverage for progress stepper

* update stepper controls story for better DX

* add sr only colon to title for better screen reader experience

* update docs on how progress is maintained

* add changeset

* revert changes for Workflow steps

* add future version of workflow with breaking change

* delete example component

* update future and legacy docs and changeset

* fix stories that were broken when reverting to previous version

* add JSDoc @deprecated to original Workflow export

* add @deprecated JSDoc on the old workflow and update legacy prompt in docs

---------

Co-authored-by: Geoffrey Chong <gyfchong@users.noreply.github.com>
  • Loading branch information
mcwinter07 and gyfchong authored Jun 21, 2023
1 parent d3968f5 commit 41a305d
Show file tree
Hide file tree
Showing 58 changed files with 1,755 additions and 56 deletions.
10 changes: 10 additions & 0 deletions .changeset/itchy-sloths-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@kaizen/components": minor
---

Create /future release for Workflow component that updates Steps to array of objects and stepName to currentStepId
- updates the stepName to currentStepId
- updates steps from non-empty array of strings to non-empty array of Steps
- exports Step and Steps types for convenience in consuming repos
- refactor Workflow to use the new type and id to reference active steps from array
- adds test coverage to ProgressStepper and improve docs
3 changes: 3 additions & 0 deletions packages/components/src/Workflow/Workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const WorkflowComponent = ({
</Workflow.Wrapper>
)

/**
* @deprecated Use { Workflow } from `@kaizen/components/future`
*/
export const Workflow = Object.assign(WorkflowComponent, {
Header,
Footer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const defaultArgs = {

const meta = {
tags: ["autodocs"],
title: "Pages/Workflow/Components/Progress Stepper",
title: "Pages/Workflow/Legacy/Components/Progress Stepper",
component: Workflow.ProgressStepper,
parameters: {
docs: {
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/Workflow/_docs/Workflow.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ArgTypes, Canvas, Meta } from "@storybook/blocks"
import { Installation, KaioNotification, ResourceLinks } from "../../../../../storybook/components"
import { InlineNotification } from "@kaizen/notification"
import * as Workflow from "./Workflow.stories"
import * as WorkflowFooter from "./WorkflowFooter.stories"
import * as WorkflowHeader from "./WorkflowHeader.stories"

<Meta title="Pages/Workflow" />
<Meta title="Pages/Workflow/Legacy" />

# Workflow

Expand All @@ -15,11 +16,17 @@ import * as WorkflowHeader from "./WorkflowHeader.stories"

<KaioNotification />

<InlineNotification type="negative" persistent>
{`This version of the Workflow is deprecated and will be removed in the next major release.
Import from "@kaizen/components/future" for the latest version.`}
</InlineNotification>

<Installation
installCommand="yarn add @kaizen/components"
importStatement='import { Workflow } from "@kaizen/components"'
/>


## Overview

This is a page template component containing the header, footer, and main landmarks that compose a Workflow page. Its purpose is to guide a customer through a multi-step form to create a Workflow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const defaultArgs = {
} satisfies WorkflowProps

const meta = {
title: "Pages/Workflow/Components/Workflow",
title: "Pages/Workflow/Legacy/Components/Workflow",
component: Workflow,
args: defaultArgs,
argTypes: WorkflowControls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const defaultArgs = {

const meta = {
tags: ["autodocs"],
title: "Pages/Workflow/Components/Footer",
title: "Pages/Workflow/Legacy/Components/Footer",
component: Workflow.Footer,
parameters: {
docs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultArgs = {

const meta = {
tags: ["autodocs"],
title: "Pages/Workflow/Components/Header",
title: "Pages/Workflow/Legacy/Components/Header",
component: Workflow.Header,
parameters: {
docs: {
Expand Down
12 changes: 12 additions & 0 deletions packages/components/src/Workflow/_docs/controls/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ export const WorkflowControls = {
"No Previous action": undefined,
},
},
currentStepId: {
control: {
type: "select",
},
options: {
"settings-step": "settings-step",
"questions-step": "questions-step",
"preview-step": "preview-step",
"employees-step": "employees-step",
"schedule-step": "schedule-step",
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ export const Titles = ({
status,
...restProps
}: WorkflowTitlesProps): JSX.Element => (
<div
className={styles.titles}
// "flex flex-grow flex-col items-center justify-center"
{...restProps}
>
<div className={styles.titles} {...restProps}>
<Heading
variant="heading-1"
tag="h1"
Expand All @@ -42,6 +38,7 @@ export const Titles = ({
color="dark-reduced-opacity"
>
{workflowName}
<span className="sr-only">:</span>
</Heading>
<span>{stepName}</span>
</Heading>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

57 changes: 57 additions & 0 deletions packages/components/src/__future__/Workflow/Workflow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { HTMLAttributes } from "react"
import { OverrideClassName } from "~types/OverrideClassName"
import {
Footer,
FooterProps,
Header,
Main,
HeaderProps,
ProgressStepper,
Wrapper,
} from "./subcomponents"

export type WorkflowProps = OverrideClassName<HTMLAttributes<HTMLDivElement>> &
FooterProps &
Pick<HeaderProps, "workflowName" | "status" | "headerActions">

const WorkflowComponent = ({
steps,
currentStepId,
isComplete,
workflowName,
status,
headerActions,
children,
nextAction,
previousAction,
classNameOverride,
...restProps
}: WorkflowProps): JSX.Element => {
const currentStep = steps.find(step => step.id === currentStepId)
return (
<Workflow.Wrapper classNameOverride={classNameOverride} {...restProps}>
<Workflow.Header
workflowName={workflowName}
stepName={currentStep!.label}
status={status}
headerActions={headerActions}
/>
<Workflow.Main>{children}</Workflow.Main>
<Workflow.Footer
currentStepId={currentStepId}
steps={steps}
isComplete={isComplete}
nextAction={nextAction}
previousAction={previousAction}
/>
</Workflow.Wrapper>
)
}

export const Workflow = Object.assign(WorkflowComponent, {
Header,
Footer,
Main,
ProgressStepper,
Wrapper,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import React from "react"
import { Meta, StoryFn } from "@storybook/react"
import { ComponentDocsTemplate } from "../../../../../../storybook/components/DocsContainer"
import { ProgressStepperProps } from "../subcomponents"
import { Workflow } from "../"
import { WorkflowControls } from "./controls"

const defaultArgs = {
currentStepId: "preview-step",
steps: [
{ label: "Settings", id: "settings-step" },
{ label: "Questions", id: "questions-step" },
{ label: "Preview", id: "preview-step" },
{ label: "Employees", id: "employees-step" },
{ label: "Schedule", id: "schedule-step" },
],
isComplete: false,
} satisfies ProgressStepperProps

const meta = {
tags: ["autodocs"],
title: "Pages/Workflow/Components/Progress Stepper",
component: Workflow.ProgressStepper,
parameters: {
docs: {
source: { type: "code" },
container: ComponentDocsTemplate,
},
installation: [
"yarn add @kaizen/workflow",
"import { ProgressStepper } from `@kaizen/components/future`",
],
resourceLinks: {
sourceCode:
"https://github.com/cultureamp/kaizen-design-system/tree/main/packages/workflow/",
figma:
"https://www.figma.com/file/IJTy1JpS4Xyop5cQwroRje/%F0%9F%9B%A0%EF%B8%8F-Self-reflection%3A-Build-Handoff?node-id=188%3A62005&t=x4zyx07E2G3BmKGw-1",
/** @todo (optional): Add Confluence link */
designGuidelines:
"https://cultureamp.atlassian.net/wiki/spaces/DesignSystem/pages/3064989884/Documentation",
},
},
argTypes: {
currentStepId: WorkflowControls.currentStepId,
},
} satisfies Meta<typeof Workflow.ProgressStepper>

export default meta

/**
* <p>This component is used in the `Footer` to track progress of the Workflows steps.</p>
* <p>It has no reverse variant and should only be used in the Worflow's `Footer` component.</p>
*/
export const Playground: StoryFn<ProgressStepperProps> = ({
currentStepId,
steps,
isComplete,
...restProps
}) => (
<div className="bg-blue-500 p-8">
<Workflow.ProgressStepper
currentStepId={currentStepId}
steps={steps}
isComplete={isComplete}
{...restProps}
/>
</div>
)

Playground.args = { ...defaultArgs }

const VariantTemplate: StoryFn<ProgressStepperProps> = ({
currentStepId,
steps,
isComplete,
...restProps
}) => (
<div className="bg-blue-500 p-8">
<Workflow.ProgressStepper
currentStepId={currentStepId}
steps={steps}
isComplete={isComplete}
{...restProps}
/>
</div>
)

/** <p>To ensure WCAG AA compliance, there are 3 visually destinct states.</p>
* <p>These are reflected in their accessible names for screen reader: "Completed", "Current" and "Not started"</p>
*/
export const ProgressStates = VariantTemplate.bind({})

ProgressStates.args = {
currentStepId: "questions-step",
steps: defaultArgs.steps,
isComplete: false,
}

/**
* <p>You can use the `isComplete` follow a successful submission to render all steps as complete.</p>
*/
export const AllStepsComplete = VariantTemplate.bind({})

AllStepsComplete.args = {
currentStepId: "schedule-step",
steps: defaultArgs.steps,
isComplete: true,
}

export const FewerSteps = VariantTemplate.bind({})

FewerSteps.args = {
currentStepId: "questions-step",
steps: [
{ label: "Settings", id: "settings-step" },
{ label: "Questions", id: "questions-step" },
{ label: "Preview", id: "preview-step" },
],
isComplete: false,
}

/**
* <p>We have baked in a container query to ensure the component can be responsive.</p>
* <p>When a step reaches its minimum size (4.5rem), it will hide the display name to maximise realestate.</p>
*/
export const SevenSteps = VariantTemplate.bind({})

SevenSteps.args = {
currentStepId: "questions-step",
steps: [
...defaultArgs.steps,
{ label: "Plan", id: "plan-step" },
{ label: "Provision", id: "provision-step" },
{ label: "Procure", id: "procure-step" },
],
isComplete: false,
}
Loading

0 comments on commit 41a305d

Please sign in to comment.