@lamenna/lxp-react 0.0.1
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.
- package/dist/components/Button/Button.d.ts +4 -0
- package/dist/components/Button/Button.js +14 -0
- package/dist/components/Button/__tests__/button.test.d.ts +7 -0
- package/dist/components/Button/__tests__/button.test.js +94 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { buttonConfig, } from "@lamenna/lxp-shared-components";
|
|
3
|
+
export const Button = ({ children, variant = "primary", size = "md", disabled = false, className, id, ariaLabel, testID, onClick, }) => {
|
|
4
|
+
const variantConfig = buttonConfig.variants[variant];
|
|
5
|
+
const sizeConfig = buttonConfig.sizes[size];
|
|
6
|
+
const styles = {
|
|
7
|
+
...buttonConfig.common,
|
|
8
|
+
...variantConfig,
|
|
9
|
+
...sizeConfig,
|
|
10
|
+
opacity: disabled ? 0.6 : 1,
|
|
11
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
12
|
+
};
|
|
13
|
+
return (React.createElement("button", { style: styles, onClick: onClick, disabled: disabled, className: className, id: id, "aria-label": ariaLabel, "data-testid": testID }, children));
|
|
14
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Button Component Tests - React Implementation
|
|
3
|
+
*
|
|
4
|
+
* This test suite validates the React implementation of the Button component,
|
|
5
|
+
* ensuring it properly renders and responds to user interactions.
|
|
6
|
+
*/
|
|
7
|
+
import '@testing-library/jest-dom';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
10
|
+
import { Button } from '../Button';
|
|
11
|
+
describe('Button Component (React)', () => {
|
|
12
|
+
describe('Rendering', () => {
|
|
13
|
+
it('should render a button element', () => {
|
|
14
|
+
render(React.createElement(Button, null, "Click me"));
|
|
15
|
+
const button = screen.getByRole('button');
|
|
16
|
+
expect(button).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
it('should display button text', () => {
|
|
19
|
+
render(React.createElement(Button, null, "Test Button"));
|
|
20
|
+
expect(screen.getByText('Test Button')).toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
it('should apply primary variant by default', () => {
|
|
23
|
+
render(React.createElement(Button, null, "Primary"));
|
|
24
|
+
const button = screen.getByRole('button');
|
|
25
|
+
expect(button).toHaveClass('button-primary');
|
|
26
|
+
});
|
|
27
|
+
it('should apply secondary variant when specified', () => {
|
|
28
|
+
render(React.createElement(Button, { variant: "secondary" }, "Secondary"));
|
|
29
|
+
const button = screen.getByRole('button');
|
|
30
|
+
expect(button).toHaveClass('button-secondary');
|
|
31
|
+
});
|
|
32
|
+
it('should apply size classes correctly', () => {
|
|
33
|
+
const { rerender } = render(React.createElement(Button, { size: "sm" }, "Small"));
|
|
34
|
+
expect(screen.getByRole('button')).toHaveClass('button-sm');
|
|
35
|
+
rerender(React.createElement(Button, { size: "md" }, "Medium"));
|
|
36
|
+
expect(screen.getByRole('button')).toHaveClass('button-md');
|
|
37
|
+
rerender(React.createElement(Button, { size: "lg" }, "Large"));
|
|
38
|
+
expect(screen.getByRole('button')).toHaveClass('button-lg');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('Interactions', () => {
|
|
42
|
+
it('should handle click events', () => {
|
|
43
|
+
const onClick = jest.fn();
|
|
44
|
+
render(React.createElement(Button, { onClick: onClick }, "Click me"));
|
|
45
|
+
const button = screen.getByRole('button');
|
|
46
|
+
fireEvent.click(button);
|
|
47
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
48
|
+
});
|
|
49
|
+
it('should not trigger onClick when disabled', () => {
|
|
50
|
+
const onClick = jest.fn();
|
|
51
|
+
render(React.createElement(Button, { onClick: onClick, disabled: true }, "Disabled"));
|
|
52
|
+
const button = screen.getByRole('button');
|
|
53
|
+
fireEvent.click(button);
|
|
54
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
it('should have disabled attribute when disabled', () => {
|
|
57
|
+
render(React.createElement(Button, { disabled: true }, "Disabled"));
|
|
58
|
+
const button = screen.getByRole('button');
|
|
59
|
+
expect(button).toBeDisabled();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('Accessibility', () => {
|
|
63
|
+
it('should support aria-label', () => {
|
|
64
|
+
render(React.createElement(Button, { ariaLabel: "Close dialog" }, "\u00D7"));
|
|
65
|
+
const button = screen.getByLabelText('Close dialog');
|
|
66
|
+
expect(button).toBeInTheDocument();
|
|
67
|
+
});
|
|
68
|
+
it('should be keyboard accessible', () => {
|
|
69
|
+
const onClick = jest.fn();
|
|
70
|
+
render(React.createElement(Button, { onClick: onClick }, "Press me"));
|
|
71
|
+
const button = screen.getByRole('button');
|
|
72
|
+
fireEvent.keyDown(button, { key: 'Enter', code: 'Enter' });
|
|
73
|
+
// Button should handle Enter key (default behavior)
|
|
74
|
+
expect(button).toBeInTheDocument();
|
|
75
|
+
});
|
|
76
|
+
it('should have proper role attribute', () => {
|
|
77
|
+
render(React.createElement(Button, null, "Action"));
|
|
78
|
+
const button = screen.getByRole('button');
|
|
79
|
+
expect(button).toHaveAttribute('type', 'button');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('CSS Classes', () => {
|
|
83
|
+
it('should apply custom className', () => {
|
|
84
|
+
render(React.createElement(Button, { className: "custom-class" }, "Custom"));
|
|
85
|
+
const button = screen.getByRole('button');
|
|
86
|
+
expect(button).toHaveClass('custom-class');
|
|
87
|
+
});
|
|
88
|
+
it('should apply id when provided', () => {
|
|
89
|
+
render(React.createElement(Button, { id: "test-button" }, "ID Button"));
|
|
90
|
+
const button = screen.getByRole('button');
|
|
91
|
+
expect(button).toHaveAttribute('id', 'test-button');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./components/Button/Button";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./components/Button/Button";
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lamenna/lxp-react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "React components for LXP",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": "^18.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lamenna/lxp-core": "0.0.1",
|
|
18
|
+
"@lamenna/lxp-tokens": "0.0.1",
|
|
19
|
+
"@lamenna/lxp-shared-components": "0.0.1"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@testing-library/jest-dom": "^6.1.5",
|
|
23
|
+
"@testing-library/react": "^14.1.2",
|
|
24
|
+
"@types/jest": "^29.5.11",
|
|
25
|
+
"@types/react": "^18.2.0",
|
|
26
|
+
"react": "^18.2.0",
|
|
27
|
+
"typescript": "^5.3.3"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"dev": "tsc --watch",
|
|
32
|
+
"test": "jest",
|
|
33
|
+
"test:watch": "jest --watch",
|
|
34
|
+
"test:coverage": "jest --coverage",
|
|
35
|
+
"clean": "rm -rf dist"
|
|
36
|
+
}
|
|
37
|
+
}
|