@khanacademy/wonder-blocks-button 2.9.13
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/LICENSE +21 -0
- package/dist/es/index.js +402 -0
- package/dist/index.js +668 -0
- package/dist/index.js.flow +2 -0
- package/docs.md +0 -0
- package/package.json +37 -0
- package/src/__tests__/__snapshots__/custom-snapshot.test.js.snap +8710 -0
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +4774 -0
- package/src/__tests__/custom-snapshot.test.js +117 -0
- package/src/__tests__/generated-snapshot.test.js +727 -0
- package/src/components/__tests__/button.flowtest.js +53 -0
- package/src/components/__tests__/button.test.js +826 -0
- package/src/components/button-core.js +375 -0
- package/src/components/button.js +347 -0
- package/src/components/button.md +810 -0
- package/src/components/button.stories.js +276 -0
- package/src/index.js +6 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import React from "react";
|
|
3
|
+
import renderer from "react-test-renderer";
|
|
4
|
+
|
|
5
|
+
import ButtonCore from "../components/button-core.js";
|
|
6
|
+
import Button from "../components/button.js";
|
|
7
|
+
|
|
8
|
+
const defaultHandlers = {
|
|
9
|
+
onClick: () => void 0,
|
|
10
|
+
onMouseEnter: () => void 0,
|
|
11
|
+
onMouseLeave: () => void 0,
|
|
12
|
+
onMouseDown: () => void 0,
|
|
13
|
+
onMouseUp: () => void 0,
|
|
14
|
+
onDragStart: () => void 0,
|
|
15
|
+
onTouchStart: () => void 0,
|
|
16
|
+
onTouchEnd: () => void 0,
|
|
17
|
+
onTouchCancel: () => void 0,
|
|
18
|
+
onKeyDown: () => void 0,
|
|
19
|
+
onKeyUp: () => void 0,
|
|
20
|
+
onFocus: () => void 0,
|
|
21
|
+
onBlur: () => void 0,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe("Button", () => {
|
|
25
|
+
test.each`
|
|
26
|
+
tabIndex
|
|
27
|
+
${-1}
|
|
28
|
+
${0}
|
|
29
|
+
${1}
|
|
30
|
+
`("<Link tabIndex={$tabIndex}>", ({tabIndex}) => {
|
|
31
|
+
const tree = renderer
|
|
32
|
+
.create(<Button tabIndex={tabIndex}>Click me</Button>)
|
|
33
|
+
.toJSON();
|
|
34
|
+
expect(tree).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("ButtonCore", () => {
|
|
39
|
+
for (const kind of ["primary", "secondary", "tertiary"]) {
|
|
40
|
+
for (const color of ["default", "destructive"]) {
|
|
41
|
+
for (const size of ["medium", "small"]) {
|
|
42
|
+
for (const light of [true, false]) {
|
|
43
|
+
for (const state of [
|
|
44
|
+
"disabled",
|
|
45
|
+
"focused",
|
|
46
|
+
"hovered",
|
|
47
|
+
"pressed",
|
|
48
|
+
]) {
|
|
49
|
+
const disabled = state === "disabled";
|
|
50
|
+
const stateProps = {
|
|
51
|
+
disabled,
|
|
52
|
+
focused: state === "focused",
|
|
53
|
+
hovered: state === "hovered",
|
|
54
|
+
pressed: state === "pressed",
|
|
55
|
+
waiting: false,
|
|
56
|
+
};
|
|
57
|
+
test(`kind:${kind} color:${color} size:${size} light:${String(
|
|
58
|
+
light,
|
|
59
|
+
)} ${state}`, () => {
|
|
60
|
+
const tree = renderer
|
|
61
|
+
.create(
|
|
62
|
+
<ButtonCore
|
|
63
|
+
kind={kind}
|
|
64
|
+
size={size}
|
|
65
|
+
color={color}
|
|
66
|
+
light={light}
|
|
67
|
+
tabIndex={disabled ? -1 : 0}
|
|
68
|
+
spinner={false}
|
|
69
|
+
aria-label={""}
|
|
70
|
+
{...stateProps}
|
|
71
|
+
{...defaultHandlers}
|
|
72
|
+
>
|
|
73
|
+
Click me
|
|
74
|
+
</ButtonCore>,
|
|
75
|
+
)
|
|
76
|
+
.toJSON();
|
|
77
|
+
expect(tree).toMatchSnapshot();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const kind of ["primary", "secondary", "tertiary"]) {
|
|
85
|
+
for (const size of ["medium", "small"]) {
|
|
86
|
+
test(`kind:${kind} size:${size} spinner:true`, () => {
|
|
87
|
+
const spinner = true;
|
|
88
|
+
const disabled = spinner;
|
|
89
|
+
const stateProps = {
|
|
90
|
+
disabled,
|
|
91
|
+
focused: false,
|
|
92
|
+
hovered: false,
|
|
93
|
+
pressed: false,
|
|
94
|
+
waiting: false,
|
|
95
|
+
};
|
|
96
|
+
const tree = renderer
|
|
97
|
+
.create(
|
|
98
|
+
<ButtonCore
|
|
99
|
+
kind={kind}
|
|
100
|
+
size={size}
|
|
101
|
+
color="default"
|
|
102
|
+
light={false}
|
|
103
|
+
tabIndex={disabled ? -1 : 0}
|
|
104
|
+
spinner={spinner}
|
|
105
|
+
aria-label={"loading"}
|
|
106
|
+
{...stateProps}
|
|
107
|
+
{...defaultHandlers}
|
|
108
|
+
>
|
|
109
|
+
Click me
|
|
110
|
+
</ButtonCore>,
|
|
111
|
+
)
|
|
112
|
+
.toJSON();
|
|
113
|
+
expect(tree).toMatchSnapshot();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|