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

KZN-2527/progressbar-rename-mood-to-color #4919

Merged
merged 24 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
30926c4
deprecate mood + add color prop
Aug 12, 2024
52591e5
update docs
Aug 12, 2024
c116ff3
add transform for codemod
Aug 12, 2024
1eddd03
fix codemod ascii
Aug 12, 2024
eb98c12
fix styles
Aug 12, 2024
f1666ab
add changeset
Aug 12, 2024
1679bdc
fix lint
Aug 12, 2024
6ce2fdb
Merge branch 'main' into KZN-2527/progressbar-rename-mood-to-color
gyfchong Aug 12, 2024
aaa14fa
Update packages/components/codemods/migrateProgressBarMoodToColor/ind…
gyfchong Aug 12, 2024
a50e229
Update packages/components/codemods/migrateProgressBarMoodToColor/ind…
gyfchong Aug 12, 2024
f7ddc2d
fix types
Aug 12, 2024
efb1b0a
Merge branch 'KZN-2527/progressbar-rename-mood-to-color' of github.co…
Aug 12, 2024
de644bb
fix lint
Aug 12, 2024
801cd24
fix story control
Aug 12, 2024
5aa9983
Update packages/components/src/ProgressBar/_docs/ProgressBar.stories.tsx
gyfchong Aug 12, 2024
e921152
Update packages/components/src/ProgressBar/ProgressBar.tsx
gyfchong Aug 12, 2024
babff59
fix storybook stories
Aug 12, 2024
4e9c539
added animation example to stickersheet
Aug 12, 2024
2855c65
Update packages/components/src/ProgressBar/ProgressBar.tsx
gyfchong Aug 12, 2024
8959618
Update packages/components/src/ProgressBar/ProgressBar.tsx
gyfchong Aug 12, 2024
d0829c1
Update packages/components/src/ProgressBar/ProgressBar.tsx
gyfchong Aug 12, 2024
6c8ec20
fix types
Aug 12, 2024
1c51f88
Merge branch 'main' into KZN-2527/progressbar-rename-mood-to-color
gyfchong Aug 12, 2024
267cb49
update codemod readme
Aug 12, 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/flat-dryers-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kaizen/components": minor
---

- ProgressBar: deprecated `mood` in favour of `color`
1 change: 1 addition & 0 deletions packages/components/codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ Example:
- `migrateInlineNotificationTypeToVariant`: Transforms `InlineNotification`'s `type` prop to the new `variant` prop.
- `migrateInformationTileMoodToVariant`: Migrates `InformationTile` component prop from `mood` to `variant`.
- `migrateMultiActionTileMoodToVariant`: Migrates `MultiActionTile` component prop from `mood` to `variant`.
- `migrateProgressBarMoodToColor`: Migrates `ProgressBar` component prop from `mood` to `color`
- `migrateToastNotificationTypeToVariant`: Transforms `ToastNotification`'s `type` prop to the new `variant` prop.
- `migrateWellVariantToColor`: Migrates `Well` component prop from `variant` to `color`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { transformComponentsInDir } from "../utils"
import { transformProgressBarMoodToColor } from "./transformProgressBarMoodToColor"

const migrateProgressBarMoodToColor = (): void => {
// eslint-disable-next-line no-console
console.log(
" ~(-_- ~) Running ProgressBar mood to color transformer (~ -_-)~"
)
const targetDir = process.argv[2]
if (!targetDir) {
process.exit(1)
}

transformComponentsInDir(
targetDir,
transformProgressBarMoodToColor,
"ProgressBar"
)
}

migrateProgressBarMoodToColor()
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst, TransformConfig } from "../utils"
import { transformProgressBarMoodToColor } from "./transformProgressBarMoodToColor"

const transformProgressBar = (
sourceFile: TransformConfig["sourceFile"]
): string =>
transformSource({
sourceFile,
astTransformer: transformProgressBarMoodToColor,
tagName: "ProgressBar",
})

describe("transformProgressBarMoodToColor()", () => {
it('replaces mood="cautionary" with color="yellow"', () => {
const inputAst = parseJsx(
'export const TestComponent = () => <ProgressBar mood="cautionary" />'
)
const outputAst = parseJsx(
'export const TestComponent = () => <ProgressBar color="yellow" />'
)
expect(transformProgressBar(inputAst)).toEqual(printAst(outputAst))
})

it('replaces mood="informative" with color="blue', () => {
const inputAst = parseJsx(
'export const TestComponent = () => <ProgressBar mood="informative" />'
)
const outputAst = parseJsx(
'export const TestComponent = () => <ProgressBar color="blue" />'
)
expect(transformProgressBar(inputAst)).toEqual(printAst(outputAst))
})

it('replaces mood="negative" with color="red"', () => {
const inputAst = parseJsx(
'export const TestComponent = () => <ProgressBar mood="negative" />'
)
const outputAst = parseJsx(
'export const TestComponent = () => <ProgressBar color="red" />'
)
expect(transformProgressBar(inputAst)).toEqual(printAst(outputAst))
})

it('replaces mood="positive" with color="green"', () => {
const inputAst = parseJsx(
'export const TestComponent = () => <ProgressBar mood="positive" />'
)
const outputAst = parseJsx(
'export const TestComponent = () => <ProgressBar color="green" />'
)
expect(transformProgressBar(inputAst)).toEqual(printAst(outputAst))
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ProgressBarProps } from "~components/ProgressBar"
import { migrateStringProp } from "../utils"

const OLD_PROP_NAME = "mood"
const NEW_PROP_NAME = "color"

const getNewVariantValue = (
oldValue: Exclude<ProgressBarProps[typeof OLD_PROP_NAME], undefined>
): Exclude<ProgressBarProps[typeof NEW_PROP_NAME], undefined> => {
switch (oldValue) {
case "cautionary":
return "yellow"
case "informative":
return "blue"
case "negative":
return "red"
case "positive":
return "green"
}
}

export const transformProgressBarMoodToColor = migrateStringProp(
OLD_PROP_NAME,
NEW_PROP_NAME,
getNewVariantValue
)
62 changes: 37 additions & 25 deletions packages/components/src/ProgressBar/ProgressBar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

$height: 10px;

@mixin animation-background($color) {
background: linear-gradient(90deg, transparent, #{$color} 75%, transparent);
}

.subtext {
color: $color-purple-800;
padding-top: $spacing-6;
Expand Down Expand Up @@ -39,43 +35,59 @@ $height: 10px;
border-radius: $height;
overflow: hidden;
transition: transform 200ms ease;
background-color: var(--progressbar-background-color);
}

// ------------------------------
// Moods
// @deprecated use colors instead
// ------------------------------
.positive {
composes: progress;
background: $color-green-400;

&::after {
@include animation-background($color-green-300);
}
--progressbar-background-color: var(--color-green-400);
}

.informative {
composes: progress;
background: $color-blue-400;

&::after {
@include animation-background($color-blue-300);
}
--progressbar-background-color: var(--color-blue-400);
}

.cautionary {
composes: progress;
background: $color-yellow-400;

&::after {
@include animation-background($color-yellow-300);
}
--progressbar-background-color: var(--color-yellow-400);
}

.negative {
composes: progress;
background: $color-red-400;
--progressbar-background-color: var(--color-red-400);
}

// End deprecated styles

// ------------------------------
// Colors
// ------------------------------
.blue {
--progressbar-background-color: var(--color-blue-400);
}

.green {
--progressbar-background-color: var(--color-green-400);
}

.red {
--progressbar-background-color: var(--color-red-400);
}

.yellow {
--progressbar-background-color: var(--color-yellow-400);
}

.isAnimating {
&::after {
opacity: 100%;
background: linear-gradient(
90deg,
transparent,
var(--color-white) 75%,
transparent
);
opacity: 25%;
content: "";
position: absolute;
top: 0;
Expand Down
35 changes: 30 additions & 5 deletions packages/components/src/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,43 @@ import { Label } from "./subcomponents/Label"
import { calculatePercentage } from "./utils/calculatePercentage"
import styles from "./ProgressBar.module.scss"

export type ProgressBarProps = {
export type ProgressBarMood = {
/**
* @deprecated Use `color` prop instead
*/
mood: "positive" | "informative" | "negative" | "cautionary"
color?: never
}

export type ProgressBarColor = {
/**
* @deprecated Use `color` prop instead
*/
mood?: never
/**
* If transitioning from `mood`:
* - `cautionary` -> `yellow`
* - `informative` -> `blue`
* - `negative` -> `red`
* - `positive` -> `green`
*/
color: "blue" | "green" | "red" | "yellow"
}

export type ProgressBarBaseProps = {
/** A value that represents completed progress */
value: number
/** A value that sets the maximum progress that can be achieved */
max: number
/** Adds an animated state to indicate loading progress */
isAnimating: boolean
mood: Mood
subtext?: string
label?: string
isReversed: boolean
} & OverrideClassName<HTMLAttributes<HTMLDivElement>>
} & OverrideClassName<Omit<HTMLAttributes<HTMLDivElement>, "color">>

type Mood = "positive" | "informative" | "negative" | "cautionary"
export type ProgressBarProps = ProgressBarBaseProps &
(ProgressBarMood | ProgressBarColor)

/**
* {@link https://cultureamp.atlassian.net/wiki/spaces/DesignSystem/pages/3081896891/Progress+Bar Guidance} |
Expand All @@ -30,6 +53,7 @@ export const ProgressBar = ({
max,
isAnimating,
mood,
color,
subtext,
label,
classNameOverride,
Expand All @@ -50,7 +74,8 @@ export const ProgressBar = ({
<div className={styles.progressBackground}>
<div
className={classnames(
styles[mood],
styles.progress,
color ? styles[color] : styles[mood],
isAnimating && styles.isAnimating
)}
style={{ transform: `translateX(-${100 - percentage}%` }}
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/ProgressBar/_docs/ProgressBar.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Canvas, Controls, DocsStory, Meta } from "@storybook/blocks"
import { ResourceLinks, KAIOInstallation } from "~storybook/components"
import * as ProgressBarStickersheetStories from "./ProgressBar.stickersheet.stories"
import * as ProgressBarStories from "./ProgressBar.stories"

<Meta of={ProgressBarStories} />
Expand Down Expand Up @@ -31,9 +30,9 @@ Adds an animated state that indicates system processes, such as downloading, upl

<Canvas of={ProgressBarStories.IsAnimating} />

### Moods
### Colors

<Canvas of={ProgressBarStickersheetStories.StickerSheetDefault} />
<Canvas of={ProgressBarStories.Colors} />

### Value and max

Expand Down
Loading
Loading