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 deprecated isReversed prop to Button #5325

Merged
merged 7 commits into from
Dec 3, 2024
8 changes: 8 additions & 0 deletions .changeset/hot-deers-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@kaizen/components": patch
---

Add a deprecated isReversed prop to Button v3 to allow for safe migration path to the ReversedColors Provider.

* `isReversed` to allow users to toggle the reversed variants with a `boolean`.
* Adds `@deprecated` flag to prompt user to use the `ReverseColors` Provider instead.
12 changes: 10 additions & 2 deletions packages/components/src/__actions__/Button/v3/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type ButtonBaseProps = Omit<RACButtonProps, "children"> & {
iconPosition?: "start" | "end"
/** Controls if the button inherits width from its parent. @default "false" */
isFullWidth?: boolean
/**
* Controls the reversed style of Button
* @deprecated Use the ReversedColors Provider instead. This is here to support gradual migration to the ReversedColors Provider and will take precedence if a value is provided. {@link https://cultureamp.design/?path=/docs/actions-button-button-v3-api-specification--docs#variants}
*/
isReversed?: boolean
}

export type ButtonProps = ButtonBaseProps & PendingButtonProps
Expand All @@ -45,11 +50,14 @@ export const Button = forwardRef(
isPending,
hasHiddenPendingLabel: propsHasHiddenPendingLabel = false,
pendingLabel,
isReversed,
...restProps
}: ButtonProps,
ref: React.ForwardedRef<HTMLButtonElement>
) => {
const isReversed = useReversedColors()
const shouldUseReverse = useReversedColors()
const isReversedVariant =
isReversed !== undefined ? isReversed : shouldUseReverse
mcwinter07 marked this conversation as resolved.
Show resolved Hide resolved
const pendingProps: PendingButtonProps = isPending
? {
isPending,
Expand All @@ -71,7 +79,7 @@ export const Button = forwardRef(
styles[size],
hasHiddenLabel && styles[`${size}IconButton`],
isDisabled && styles.isDisabled,
isReversed ? styles[`${variant}Reversed`] : styles[variant],
isReversedVariant ? styles[`${variant}Reversed`] : styles[variant],
isFullWidth && styles.fullWidth,
className
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following example and table showcases the essential props that enable the co

<Canvas of={exampleStories.Playground} />

<Controls of={exampleStories.Playground} className="mb-64" include={["children", "hasHiddenLabel", "className", "size", "variant", "onPress", "icon", "iconPosition", "isFullWidth", "isDisabled", "isPending","pendingLabel", "hasHiddenPendingLabel" ]} />
<Controls of={exampleStories.Playground} className="mb-64" include={["children", "hasHiddenLabel", "className", "size", "variant", "isReversed", "onPress", "icon", "iconPosition", "isFullWidth", "isDisabled", "isPending","pendingLabel", "hasHiddenPendingLabel" ]} />

## Buttons and links

Expand All @@ -43,7 +43,7 @@ This is built on top of [React Aria's Button component](https://react-spectrum.a

<Canvas of={exampleStories.ButtonVariants} />

Reversed variants are handled via the `ReversedColors` Provider - read more on this in the [reversed colors section](#reversed-colors).
Reversed variants are handled via the `ReversedColors` Provider.

<DocsStory of={exampleStories.ButtonVariantsReversed} expanded={false} />

Expand Down
Loading