diff --git a/.changeset/rich-days-count.md b/.changeset/rich-days-count.md new file mode 100644 index 0000000000..8e99f82538 --- /dev/null +++ b/.changeset/rich-days-count.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/wonder-blocks-button": patch +--- + +Use pseudo-classes for styling states (:hover, :focus-visible). Keep some clickable states for programmatic focus and preserve active/pressed overrides. diff --git a/__docs__/wonder-blocks-button/button-variants.stories.tsx b/__docs__/wonder-blocks-button/button-variants.stories.tsx new file mode 100644 index 0000000000..cea281d5c8 --- /dev/null +++ b/__docs__/wonder-blocks-button/button-variants.stories.tsx @@ -0,0 +1,194 @@ +import * as React from "react"; +import {StyleSheet} from "aphrodite"; +import {action} from "@storybook/addon-actions"; +import type {Meta, StoryObj} from "@storybook/react"; + +import paperPlaneIcon from "@phosphor-icons/core/fill/paper-plane-tilt-fill.svg"; +import {PropsFor, View} from "@khanacademy/wonder-blocks-core"; +import {ThemeSwitcherContext} from "@khanacademy/wonder-blocks-theming"; +import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens"; +import {HeadingLarge, LabelMedium} from "@khanacademy/wonder-blocks-typography"; +import Button from "@khanacademy/wonder-blocks-button"; + +/** + * The following stories are used to generate the pseudo states for the + * Button component. This is only used for visual testing in Chromatic. + */ +export default { + title: "Packages / Button / All Variants", + parameters: { + docs: { + autodocs: false, + }, + chromatic: { + // NOTE: This is required to prevent Chromatic from cutting off the + // dark background in screenshots (accounts for all the space taken + // by the variants). + viewports: [1700], + }, + }, +} as Meta; + +type StoryComponentType = StoryObj; + +type ButtonProps = PropsFor; + +const sizes: Array = ["medium", "small", "large"]; +const kinds: Array = ["primary", "secondary", "tertiary"]; + +const colors: Array = ["default", "destructive"]; + +function VariantsGroup({ + color = "default", + disabled = false, + label = "Button", + light, + size, +}: { + color?: ButtonProps["color"]; + disabled?: ButtonProps["disabled"]; + label?: string; + light: boolean; + size: ButtonProps["size"]; +}) { + const theme = React.useContext(ThemeSwitcherContext); + const category = disabled ? "disabled" : color; + + return ( + + + {size} / {category} + + {kinds.map((kind) => ( + + + {/* startIcon */} + + {/* endIcon */} + + + ))} + + ); +} + +const KindVariants = ({light}: {light: boolean}) => { + return ( + <> + {sizes.map((size) => ( + <> + {colors.map((color) => ( + + ))} + + + ))} + + ); +}; + +const VariantsByTheme = ({themeName = "Default"}: {themeName?: string}) => ( + + {themeName} theme + + + +); + +const AllVariants = () => ( + <> + + + + + +); + +export const Default: StoryComponentType = { + render: AllVariants, +}; + +export const Hover: StoryComponentType = { + render: AllVariants, + parameters: {pseudo: {hover: true}}, +}; + +export const Focus: StoryComponentType = { + render: AllVariants, + parameters: {pseudo: {focusVisible: true}}, +}; + +export const HoverFocus: StoryComponentType = { + name: "Hover + Focus", + render: AllVariants, + parameters: {pseudo: {hover: true, focusVisible: true}}, +}; + +export const Active: StoryComponentType = { + render: AllVariants, + parameters: {pseudo: {active: true}}, +}; + +const styles = StyleSheet.create({ + darkDefault: { + backgroundColor: color.darkBlue, + }, + darkKhanmigo: { + backgroundColor: color.eggplant, + }, + variants: { + justifyContent: "flex-start", + padding: spacing.medium_16, + display: "flex", + flexDirection: "row", + alignItems: "center", + gap: spacing.xLarge_32, + }, + label: { + minWidth: 150, + }, + inverseLabel: { + color: semanticColor.text.inverse, + }, +}); diff --git a/__docs__/wonder-blocks-button/button.stories.tsx b/__docs__/wonder-blocks-button/button.stories.tsx index d56b64a514..ffe8e691c4 100644 --- a/__docs__/wonder-blocks-button/button.stories.tsx +++ b/__docs__/wonder-blocks-button/button.stories.tsx @@ -1,7 +1,6 @@ import * as React from "react"; import {StyleSheet} from "aphrodite"; import type {Meta, StoryObj} from "@storybook/react"; -import {expect, userEvent, within} from "@storybook/test"; import {MemoryRouter, Route, Switch} from "react-router-dom"; @@ -27,26 +26,6 @@ import ComponentInfo from "../components/component-info"; import ButtonArgTypes from "./button.argtypes"; import {ThemeSwitcherContext} from "@khanacademy/wonder-blocks-theming"; -/** - * Reusable button component. - * - * Consisting of a [`ClickableBehavior`](#clickablebehavior) surrounding a - * `ButtonCore`. `ClickableBehavior` handles interactions and state changes. - * `ButtonCore` is a stateless component which displays the different states the - * `Button` can take. - * - * ### Usage - * - * ```tsx - * import Button from "@khanacademy/wonder-blocks-button"; - * - * - * ``` - */ export default { title: "Packages / Button", component: Button, @@ -80,61 +59,14 @@ export const Default: StoryComponentType = { }, }, parameters: { - design: { - type: "figma", - url: "https://www.figma.com/file/VbVu3h2BpBhH80niq101MHHE/%F0%9F%92%A0-Main-Components?type=design&node-id=389-0&mode=design", - }, chromatic: { - // We already have screenshots of other stories that cover more of the button states + // We already have screenshots of other stories that cover more of + // the button states disableSnapshot: true, }, }, }; -export const Tertiary: StoryComponentType = { - args: { - onClick: () => {}, - kind: "tertiary", - testId: "test-button", - children: "Hello, world!", - }, - play: async ({canvasElement}) => { - const canvas = within(canvasElement); - - // Get HTML elements - const button = canvas.getByRole("button"); - const innerLabel = canvas.getByTestId("test-button-inner-label"); - const computedStyleLabel = getComputedStyle(innerLabel, ":after"); - - // Resting style - await expect(button).toHaveStyle(`color: ${color.blue}`); - await expect(button).toHaveTextContent("Hello, world!"); - - // Hover style - await userEvent.hover(button); - await expect(computedStyleLabel.height).toBe("2px"); - await expect(computedStyleLabel.color).toBe("rgb(24, 101, 242)"); - - // TODO(WB-1808, somewhatabstract): This isn't working. I got it passing - // locally by calling `button.focus()` as well, but it was super flaky - // and never passed first time. - // Focus style - // const computedStyleButton = getComputedStyle(button); - // await fireEvent.focus(button); - // await expect(computedStyleButton.outlineColor).toBe( - // "rgb(24, 101, 242)", - // ); - // await expect(computedStyleButton.outlineWidth).toBe("2px"); - - // // Active (mouse down) style - // // eslint-disable-next-line testing-library/prefer-user-event - // await fireEvent.mouseDown(button); - // await expect(innerLabel).toHaveStyle("color: rgb(27, 80, 179)"); - // await expect(computedStyleLabel.color).toBe("rgb(27, 80, 179)"); - // await expect(computedStyleLabel.height).toBe("2px"); - }, -}; - export const styles: StyleDeclaration = StyleSheet.create({ row: { flexDirection: "row", @@ -203,6 +135,11 @@ Variants.parameters = { story: "There are three kinds of buttons: `primary` (default), `secondary`, and `tertiary`.", }, }, + chromatic: { + // We already have screenshots of other stories that cover more of + // the button states + disableSnapshot: true, + }, }; export const WithColor: StoryComponentType = { @@ -324,6 +261,11 @@ Dark.parameters = { story: "Buttons on a `darkBlue` background should set `light` to `true`.", }, }, + chromatic: { + // We already have screenshots of other stories that cover more of + // the button states + disableSnapshot: true, + }, }; const kinds = ["primary", "secondary", "tertiary"] as const; @@ -539,6 +481,11 @@ Size.parameters = { story: "Buttons have a size that's either `medium` (default), `small`, or `large`.", }, }, + chromatic: { + // We already have screenshots of other stories that cover more of + // the button states + disableSnapshot: true, + }, }; export const Spinner: StoryComponentType = () => ( @@ -789,4 +736,11 @@ export const KhanmigoTheme: StoryComponentType = { ); }, + parameters: { + chromatic: { + // We already have screenshots of other stories that cover more of + // the button states + disableSnapshot: true, + }, + }, }; diff --git a/packages/wonder-blocks-button/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap b/packages/wonder-blocks-button/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap deleted file mode 100644 index 66e0d7654b..0000000000 --- a/packages/wonder-blocks-button/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap +++ /dev/null @@ -1,3325 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Button 1`] = ` -
- -
-`; - -exports[`Button 1`] = ` -
- -
-`; - -exports[`Button 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:large light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:medium light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:default size:small light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:large light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:medium light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary color:destructive size:small light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary size:medium spinner:true 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:primary size:small spinner:true 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:large light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:medium light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:default size:small light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:large light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:medium light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary color:destructive size:small light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary size:medium spinner:true 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:secondary size:small spinner:true 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:large light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:medium light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:default size:small light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:large light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:medium light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:false disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:false focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:false hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:false pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:true disabled 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:true focused 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:true hovered 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary color:destructive size:small light:true pressed 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary size:medium spinner:true 1`] = ` -
- -
-`; - -exports[`ButtonCore kind:tertiary size:small spinner:true 1`] = ` -
- -
-`; diff --git a/packages/wonder-blocks-button/src/__tests__/custom-snapshot.test.tsx b/packages/wonder-blocks-button/src/__tests__/custom-snapshot.test.tsx deleted file mode 100644 index fd8294e11a..0000000000 --- a/packages/wonder-blocks-button/src/__tests__/custom-snapshot.test.tsx +++ /dev/null @@ -1,110 +0,0 @@ -import * as React from "react"; -import {render} from "@testing-library/react"; -import ButtonCore from "../components/button-core"; -import Button from "../components/button"; - -const defaultHandlers = { - onClick: () => void 0, - onMouseEnter: () => void 0, - onMouseLeave: () => void 0, - onMouseDown: () => void 0, - onMouseUp: () => void 0, - onTouchStart: () => void 0, - onTouchEnd: () => void 0, - onTouchCancel: () => void 0, - onKeyDown: () => void 0, - onKeyUp: () => void 0, - onFocus: () => void 0, - onBlur: () => void 0, -} as const; - -describe("Button", () => { - test.each` - tabIndex - ${-1} - ${0} - ${1} - `("", ({tabIndex}: any) => { - const {container} = render( - , - ); - expect(container).toMatchSnapshot(); - }); -}); - -describe("ButtonCore", () => { - for (const kind of ["primary", "secondary", "tertiary"] as const) { - for (const color of ["default", "destructive"] as const) { - for (const size of ["medium", "small", "large"] as const) { - for (const light of [true, false]) { - for (const state of [ - "disabled", - "focused", - "hovered", - "pressed", - ]) { - const disabled = state === "disabled"; - const stateProps = { - disabled, - focused: state === "focused", - hovered: state === "hovered", - pressed: state === "pressed", - waiting: false, - } as const; - test(`kind:${kind} color:${color} size:${size} light:${String( - light, - )} ${state}`, () => { - const {container} = render( - - Click me - , - ); - expect(container).toMatchSnapshot(); - }); - } - } - } - } - } - for (const kind of ["primary", "secondary", "tertiary"] as const) { - for (const size of ["medium", "small"] as const) { - test(`kind:${kind} size:${size} spinner:true`, () => { - const spinner = true; - const disabled = spinner; - const stateProps = { - disabled, - focused: false, - hovered: false, - pressed: false, - waiting: false, - } as const; - const {container} = render( - - Click me - , - ); - expect(container).toMatchSnapshot(); - }); - } - } -}); diff --git a/packages/wonder-blocks-button/src/components/button-core.tsx b/packages/wonder-blocks-button/src/components/button-core.tsx index b420d1ce36..af7900bbe9 100644 --- a/packages/wonder-blocks-button/src/components/button-core.tsx +++ b/packages/wonder-blocks-button/src/components/button-core.tsx @@ -84,12 +84,12 @@ const ButtonCore: React.ForwardRefExoticComponent< kind !== "tertiary" && !disabled && (pressed - ? buttonStyles.active - : (hovered || focused) && buttonStyles.focus), + ? buttonStyles.pressed + : focused && buttonStyles.focused), kind === "tertiary" && !pressed && focused && [ - buttonStyles.focus, + buttonStyles.focused, disabled && buttonStyles.disabledFocus, ], size === "small" && sharedStyles.small, @@ -110,6 +110,7 @@ const ButtonCore: React.ForwardRefExoticComponent<