@edux-design/buttons 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,62 +0,0 @@
1
- import React from "react";
2
- import { render, screen } from "@testing-library/react";
3
- import { IconButton } from "./IconButton";
4
-
5
- describe("IconButton", () => {
6
- it("renders an icon-only button with an accessible name", () => {
7
- render(
8
- <IconButton icon={<span aria-hidden="true">X</span>} aria-label="Close" />,
9
- );
10
-
11
- expect(screen.getByRole("button", { name: "Close" })).toBeInTheDocument();
12
- });
13
-
14
- it("warns in dev mode when no accessible name is provided", () => {
15
- const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
16
- process.env.NODE_ENV = "development";
17
-
18
- render(<IconButton icon={<span aria-hidden="true">X</span>} />);
19
-
20
- expect(warnSpy).toHaveBeenCalledWith(
21
- "[IconButton]: Provide an accessible name with aria-label or aria-labelledby.",
22
- );
23
-
24
- warnSpy.mockRestore();
25
- });
26
-
27
- it("does not warn when aria-labelledby is provided", () => {
28
- const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
29
- process.env.NODE_ENV = "development";
30
-
31
- render(
32
- <>
33
- <span id="icon-label">Close</span>
34
- <IconButton icon={<span aria-hidden="true">X</span>} aria-labelledby="icon-label" />
35
- </>,
36
- );
37
-
38
- expect(warnSpy).not.toHaveBeenCalledWith(
39
- "[IconButton]: Provide an accessible name with aria-label or aria-labelledby.",
40
- );
41
-
42
- warnSpy.mockRestore();
43
- });
44
-
45
- it.each([
46
- ["small", "size-control-sm"],
47
- ["medium", "size-control-md"],
48
- ["large", "size-control-lg"],
49
- ])("maps the %s size to the shared control token", (size, className) => {
50
- render(
51
- <IconButton
52
- icon={<span aria-hidden="true">X</span>}
53
- aria-label="Close"
54
- size={size}
55
- />,
56
- );
57
-
58
- expect(screen.getByRole("button", { name: "Close" })).toHaveClass(
59
- className,
60
- );
61
- });
62
- });
@@ -1,68 +0,0 @@
1
- import React, { forwardRef } from "react";
2
- import { cx } from "@edux-design/utils";
3
- import { Chevron } from "@edux-design/icons";
4
-
5
- /**
6
- * Props for the MenuButton component.
7
- *
8
- * @typedef {React.ButtonHTMLAttributes<HTMLButtonElement> & {
9
- * children?: React.ReactNode,
10
- * caret?: React.ReactNode,
11
- * size?: "small"|"medium",
12
- * className?: string,
13
- * }} MenuButtonProps
14
- */
15
-
16
- /**
17
- * MenuButton component.
18
- *
19
- * Provides a styled button intended for menu triggers.
20
- * Consumers should pass `aria-expanded`, `aria-controls`, and any
21
- * custom labeling they need. `aria-haspopup="menu"` is applied by default.
22
- *
23
- * @component
24
- * @type {React.ForwardRefExoticComponent<MenuButtonProps & React.RefAttributes<HTMLButtonElement>>}
25
- *
26
- * @example
27
- * ```jsx
28
- * <MenuButton aria-expanded={open} onClick={() => setOpen((prev) => !prev)}>
29
- * Options
30
- * </MenuButton>
31
- * ```
32
- */
33
- export const MenuButton = forwardRef(function MenuButton(
34
- {
35
- children,
36
- caret,
37
- size = "medium",
38
- className,
39
- type = "button",
40
- "aria-haspopup": ariaHasPopup = "menu",
41
- ...props
42
- },
43
- ref,
44
- ) {
45
- const styles = cx(
46
- "inline-flex items-center justify-center gap-8 rounded-lg border-2 border-border-primary-base bg-bg-base px-16 text-fg-primary-emphasis transition-all duration-300 ease-in-out outline-none focus:shadow-focus focus-visible:shadow-focus disabled:cursor-not-allowed disabled:border-border-subtle disabled:bg-bg-inactive disabled:text-fg-inactive",
47
- {
48
- "min-h-control-sm text-sm": size === "small",
49
- "min-h-control-md text-base": size === "medium",
50
- },
51
- className,
52
- );
53
-
54
- return (
55
- <button
56
- {...props}
57
- ref={ref}
58
- type={type}
59
- aria-haspopup={ariaHasPopup}
60
- className={styles}
61
- >
62
- {children ? <span>{children}</span> : null}
63
- <span aria-hidden="true" className="flex items-center text-current">
64
- {caret ?? <Chevron />}
65
- </span>
66
- </button>
67
- );
68
- });
@@ -1,40 +0,0 @@
1
- import React from "react";
2
- import { fireEvent, render, screen } from "@testing-library/react";
3
- import { MenuButton } from "./MenuButton";
4
-
5
- describe("MenuButton", () => {
6
- it("renders a semantic button trigger", () => {
7
- render(<MenuButton>Options</MenuButton>);
8
-
9
- expect(screen.getByRole("button", { name: "Options" })).toHaveAttribute(
10
- "aria-haspopup",
11
- "menu",
12
- );
13
- });
14
-
15
- it("forwards interactive props to the native button", () => {
16
- const onClick = vi.fn();
17
- render(
18
- <MenuButton aria-expanded={true} onClick={onClick}>
19
- Options
20
- </MenuButton>,
21
- );
22
-
23
- const button = screen.getByRole("button", { name: "Options" });
24
- fireEvent.click(button);
25
-
26
- expect(onClick).toHaveBeenCalledTimes(1);
27
- expect(button).toHaveAttribute("aria-expanded", "true");
28
- });
29
-
30
- it.each([
31
- ["small", "min-h-control-sm"],
32
- ["medium", "min-h-control-md"],
33
- ])("maps the %s size to the shared control token", (size, className) => {
34
- render(<MenuButton size={size}>Options</MenuButton>);
35
-
36
- expect(screen.getByRole("button", { name: "Options" })).toHaveClass(
37
- className,
38
- );
39
- });
40
- });
@@ -1,14 +0,0 @@
1
- import axe from "axe-core";
2
-
3
- export async function expectNoAxeViolations(container) {
4
- const results = await axe.run(container, {
5
- rules: {
6
- "color-contrast": { enabled: false },
7
- },
8
- });
9
- const message = results.violations
10
- .map((violation) => `${violation.id}: ${violation.help}`)
11
- .join("\n");
12
-
13
- expect(results.violations, message).toHaveLength(0);
14
- }
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- export { IconButton } from "./elements/IconButton";
2
- export { Button } from "./elements/Button";
3
- export { MenuButton } from "./elements/MenuButton";
4
- export { ButtonGroup } from "./elements/ButtonGroup";
5
- export { ButtonGroupItem } from "./elements/ButtonGroupItem";
6
- export { ButtonCounter } from "./elements/ButtonCounter";
@@ -1,3 +0,0 @@
1
- import React, { createContext, useContext } from "react";
2
-
3
- export const MenuButtonContext = createContext();
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
-
2
- {
3
-
4
- "compilerOptions": {
5
- "allowJs": true,
6
- "checkJs": false,
7
- "declaration": true,
8
- "emitDeclarationOnly": true,
9
- "jsx": "react-jsx",
10
- "outDir": "dist"
11
- }
12
- }