@khanacademy/wonder-blocks-button 3.0.14 → 3.0.15
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/CHANGELOG.md +30 -0
- package/dist/components/button-core.d.ts +9 -0
- package/dist/components/button-core.js.flow +18 -0
- package/dist/components/button.d.ts +178 -0
- package/dist/components/button.js.flow +203 -0
- package/dist/es/index.js +108 -75
- package/dist/index.d.ts +4 -0
- package/dist/index.js +127 -96
- package/dist/index.js.flow +11 -2
- package/package.json +10 -10
- package/src/__tests__/{custom-snapshot.test.js → custom-snapshot.test.tsx} +11 -12
- package/src/components/__tests__/{button.flowtest.js → button.flowtest.tsx} +0 -5
- package/src/components/__tests__/{button.test.js → button.test.tsx} +16 -18
- package/src/components/{button-core.js → button-core.tsx} +23 -24
- package/src/components/button.tsx +298 -0
- package/src/{index.js → index.ts} +0 -1
- package/tsconfig.json +17 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/__docs__/accessibility.stories.mdx +0 -92
- package/src/components/__docs__/best-practices.stories.mdx +0 -107
- package/src/components/__docs__/button.argtypes.js +0 -231
- package/src/components/__docs__/button.stories.js +0 -508
- package/src/components/__docs__/navigation-callbacks.stories.mdx +0 -187
- package/src/components/button.js +0 -347
- /package/src/__tests__/__snapshots__/{custom-snapshot.test.js.snap → custom-snapshot.test.tsx.snap} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-button
|
|
2
2
|
|
|
3
|
+
## 3.0.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d816af08: Update build and test configs use TypeScript
|
|
8
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
9
|
+
- 0d28bb1c: Configured TypeScript
|
|
10
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
11
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
12
|
+
- 2983c05b: Include 'types' field in package.json
|
|
13
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
14
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
15
|
+
- Updated dependencies [d816af08]
|
|
16
|
+
- Updated dependencies [3891f544]
|
|
17
|
+
- Updated dependencies [3813715d]
|
|
18
|
+
- Updated dependencies [0d28bb1c]
|
|
19
|
+
- Updated dependencies [873f4a14]
|
|
20
|
+
- Updated dependencies [3d05f764]
|
|
21
|
+
- Updated dependencies [c2ec4902]
|
|
22
|
+
- Updated dependencies [2983c05b]
|
|
23
|
+
- Updated dependencies [77ff6a66]
|
|
24
|
+
- Updated dependencies [ec8d4b7f]
|
|
25
|
+
- @khanacademy/wonder-blocks-clickable@2.4.6
|
|
26
|
+
- @khanacademy/wonder-blocks-color@1.2.2
|
|
27
|
+
- @khanacademy/wonder-blocks-core@4.8.0
|
|
28
|
+
- @khanacademy/wonder-blocks-icon@1.2.38
|
|
29
|
+
- @khanacademy/wonder-blocks-progress-spinner@1.1.41
|
|
30
|
+
- @khanacademy/wonder-blocks-spacing@3.0.6
|
|
31
|
+
- @khanacademy/wonder-blocks-typography@1.1.39
|
|
32
|
+
|
|
3
33
|
## 3.0.14
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ChildrenProps, ClickableState } from "@khanacademy/wonder-blocks-clickable";
|
|
3
|
+
import type { SharedProps } from "./button";
|
|
4
|
+
type Props = SharedProps & ChildrenProps & ClickableState;
|
|
5
|
+
export default class ButtonCore extends React.Component<Props> {
|
|
6
|
+
renderInner(router: any): React.ReactNode;
|
|
7
|
+
render(): React.ReactElement;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for button-core
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type {
|
|
10
|
+
ChildrenProps,
|
|
11
|
+
ClickableState,
|
|
12
|
+
} from "@khanacademy/wonder-blocks-clickable";
|
|
13
|
+
import type { SharedProps } from "./button";
|
|
14
|
+
declare type Props = { ...SharedProps, ...ChildrenProps, ...ClickableState };
|
|
15
|
+
declare export default class ButtonCore mixins React.Component<Props> {
|
|
16
|
+
renderInner(router: any): React.Node;
|
|
17
|
+
render(): React.Element<>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import type { IconAsset } from "@khanacademy/wonder-blocks-icon";
|
|
4
|
+
export type SharedProps =
|
|
5
|
+
/**
|
|
6
|
+
* aria-label should be used when `spinner={true}` to let people using screen
|
|
7
|
+
* readers that the action taken by clicking the button will take some
|
|
8
|
+
* time to complete.
|
|
9
|
+
*/
|
|
10
|
+
Partial<Omit<AriaProps, "aria-disabled">> & {
|
|
11
|
+
/**
|
|
12
|
+
* Text to appear on the button.
|
|
13
|
+
*/
|
|
14
|
+
children: string;
|
|
15
|
+
/**
|
|
16
|
+
* An icon, displayed to the left of the title.
|
|
17
|
+
*/
|
|
18
|
+
icon?: IconAsset;
|
|
19
|
+
/**
|
|
20
|
+
* If true, replaces the contents with a spinner.
|
|
21
|
+
*
|
|
22
|
+
* Note: setting this prop to `true` will disable the button.
|
|
23
|
+
*
|
|
24
|
+
* TODO(kevinb): support spinner + light once we have designs
|
|
25
|
+
*/
|
|
26
|
+
spinner: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The color of the button, either blue or red.
|
|
29
|
+
*/
|
|
30
|
+
color: "default" | "destructive";
|
|
31
|
+
/**
|
|
32
|
+
* The kind of the button, either primary, secondary, or tertiary.
|
|
33
|
+
*
|
|
34
|
+
* In default state:
|
|
35
|
+
*
|
|
36
|
+
* - Primary buttons have background colors
|
|
37
|
+
* - Secondary buttons have a border and no background color
|
|
38
|
+
* - Tertiary buttons have no background or border
|
|
39
|
+
*/
|
|
40
|
+
kind: "primary" | "secondary" | "tertiary";
|
|
41
|
+
/**
|
|
42
|
+
* Whether the button is on a dark/colored background.
|
|
43
|
+
*
|
|
44
|
+
* Sets primary button background color to white, and secondary and
|
|
45
|
+
* tertiary button title to color.
|
|
46
|
+
*/
|
|
47
|
+
light: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The size of the button. "medium" = height: 40; "small" = height: 32;
|
|
50
|
+
* "large" = height: 56;
|
|
51
|
+
*/
|
|
52
|
+
size: "medium" | "small" | "large";
|
|
53
|
+
/**
|
|
54
|
+
* Whether the button is disabled.
|
|
55
|
+
*/
|
|
56
|
+
disabled: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* An optional id attribute.
|
|
59
|
+
*/
|
|
60
|
+
id?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Test ID used for e2e testing.
|
|
63
|
+
*/
|
|
64
|
+
testId?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Specifies the type of relationship between the current document and the
|
|
67
|
+
* linked document. Should only be used when `href` is specified. This
|
|
68
|
+
* defaults to "noopener noreferrer" when `target="_blank"`, but can be
|
|
69
|
+
* overridden by setting this prop to something else.
|
|
70
|
+
*/
|
|
71
|
+
rel?: string;
|
|
72
|
+
/**
|
|
73
|
+
* A target destination window for a link to open in. Should only be used
|
|
74
|
+
* when `href` is specified.
|
|
75
|
+
*
|
|
76
|
+
* TODO(WB-1262): only allow this prop when `href` is also set.t
|
|
77
|
+
*/
|
|
78
|
+
target?: "_blank";
|
|
79
|
+
/**
|
|
80
|
+
* Set the tabindex attribute on the rendered element.
|
|
81
|
+
*/
|
|
82
|
+
tabIndex?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to avoid using client-side navigation.
|
|
85
|
+
*
|
|
86
|
+
* If the URL passed to href is local to the client-side, e.g.
|
|
87
|
+
* /math/algebra/eval-exprs, then it tries to use react-router-dom's Link
|
|
88
|
+
* component which handles the client-side navigation. You can set
|
|
89
|
+
* `skipClientNav` to true avoid using client-side nav entirely.
|
|
90
|
+
*
|
|
91
|
+
* NOTE: All URLs containing a protocol are considered external, e.g.
|
|
92
|
+
* https://khanacademy.org/math/algebra/eval-exprs will trigger a full
|
|
93
|
+
* page reload.
|
|
94
|
+
*/
|
|
95
|
+
skipClientNav?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Optional custom styles.
|
|
98
|
+
*/
|
|
99
|
+
style?: StyleType;
|
|
100
|
+
/**
|
|
101
|
+
* URL to navigate to.
|
|
102
|
+
*/
|
|
103
|
+
href?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Used for buttons within <form>s.
|
|
106
|
+
*/
|
|
107
|
+
type?: "submit";
|
|
108
|
+
/**
|
|
109
|
+
* Adds CSS classes to the Button.
|
|
110
|
+
*/
|
|
111
|
+
className?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Function to call when button is clicked.
|
|
114
|
+
*
|
|
115
|
+
* This callback should be used for running synchronous code, like
|
|
116
|
+
* dispatching a Redux action. For asynchronous code see the
|
|
117
|
+
* beforeNav and safeWithNav props. It should NOT be used to redirect
|
|
118
|
+
* to a different URL.
|
|
119
|
+
*
|
|
120
|
+
* Note: onClick is optional if href is present, but must be defined if
|
|
121
|
+
* href is not
|
|
122
|
+
*/
|
|
123
|
+
onClick?: (e: React.SyntheticEvent) => unknown;
|
|
124
|
+
/**
|
|
125
|
+
* Run async code before navigating. If the promise returned rejects then
|
|
126
|
+
* navigation will not occur.
|
|
127
|
+
*
|
|
128
|
+
* If both safeWithNav and beforeNav are provided, beforeNav will be run
|
|
129
|
+
* first and safeWithNav will only be run if beforeNav does not reject.
|
|
130
|
+
*
|
|
131
|
+
* WARNING: Do not use with `type="submit"`.
|
|
132
|
+
*/
|
|
133
|
+
beforeNav?: () => Promise<unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* Run async code in the background while client-side navigating. If the
|
|
136
|
+
* browser does a full page load navigation, the callback promise must be
|
|
137
|
+
* settled before the navigation will occur. Errors are ignored so that
|
|
138
|
+
* navigation is guaranteed to succeed.
|
|
139
|
+
*
|
|
140
|
+
* WARNING: Do not use with `type="submit"`.
|
|
141
|
+
*/
|
|
142
|
+
safeWithNav?: () => Promise<unknown>;
|
|
143
|
+
};
|
|
144
|
+
type Props = SharedProps;
|
|
145
|
+
type DefaultProps = {
|
|
146
|
+
color: Props["color"];
|
|
147
|
+
kind: Props["kind"];
|
|
148
|
+
light: Props["light"];
|
|
149
|
+
size: Props["size"];
|
|
150
|
+
disabled: Props["disabled"];
|
|
151
|
+
spinner: Props["spinner"];
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Reusable button component.
|
|
155
|
+
*
|
|
156
|
+
* Consisting of a [`ClickableBehavior`](#clickablebehavior) surrounding a
|
|
157
|
+
* `ButtonCore`. `ClickableBehavior` handles interactions and state changes.
|
|
158
|
+
* `ButtonCore` is a stateless component which displays the different states
|
|
159
|
+
* the `Button` can take.
|
|
160
|
+
*
|
|
161
|
+
* ### Usage
|
|
162
|
+
*
|
|
163
|
+
* ```jsx
|
|
164
|
+
* import Button from "@khanacademy/wonder-blocks-button";
|
|
165
|
+
*
|
|
166
|
+
* <Button
|
|
167
|
+
* onClick={(e) => console.log("Hello, world!")}
|
|
168
|
+
* >
|
|
169
|
+
* Hello, world!
|
|
170
|
+
* </Button>
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export default class Button extends React.Component<Props> {
|
|
174
|
+
static defaultProps: DefaultProps;
|
|
175
|
+
renderClickableBehavior(router: any): React.ReactNode;
|
|
176
|
+
render(): React.ReactElement;
|
|
177
|
+
}
|
|
178
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for button
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
import type { IconAsset } from "@khanacademy/wonder-blocks-icon";
|
|
11
|
+
export type SharedProps = {
|
|
12
|
+
...$Rest<$Diff<AriaProps, { "aria-disabled": any }>, { ... }>,
|
|
13
|
+
...{
|
|
14
|
+
/**
|
|
15
|
+
* Text to appear on the button.
|
|
16
|
+
*/
|
|
17
|
+
children: string,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An icon, displayed to the left of the title.
|
|
21
|
+
*/
|
|
22
|
+
icon?: IconAsset,
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* If true, replaces the contents with a spinner.
|
|
26
|
+
*
|
|
27
|
+
* Note: setting this prop to `true` will disable the button.
|
|
28
|
+
*
|
|
29
|
+
* TODO(kevinb): support spinner + light once we have designs
|
|
30
|
+
*/
|
|
31
|
+
spinner: boolean,
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The color of the button, either blue or red.
|
|
35
|
+
*/
|
|
36
|
+
color: "default" | "destructive",
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The kind of the button, either primary, secondary, or tertiary.
|
|
40
|
+
*
|
|
41
|
+
* In default state:
|
|
42
|
+
*
|
|
43
|
+
* - Primary buttons have background colors
|
|
44
|
+
* - Secondary buttons have a border and no background color
|
|
45
|
+
* - Tertiary buttons have no background or border
|
|
46
|
+
*/
|
|
47
|
+
kind: "primary" | "secondary" | "tertiary",
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether the button is on a dark/colored background.
|
|
51
|
+
*
|
|
52
|
+
* Sets primary button background color to white, and secondary and
|
|
53
|
+
* tertiary button title to color.
|
|
54
|
+
*/
|
|
55
|
+
light: boolean,
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The size of the button. "medium" = height: 40; "small" = height: 32;
|
|
59
|
+
* "large" = height: 56;
|
|
60
|
+
*/
|
|
61
|
+
size: "medium" | "small" | "large",
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Whether the button is disabled.
|
|
65
|
+
*/
|
|
66
|
+
disabled: boolean,
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* An optional id attribute.
|
|
70
|
+
*/
|
|
71
|
+
id?: string,
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Test ID used for e2e testing.
|
|
75
|
+
*/
|
|
76
|
+
testId?: string,
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Specifies the type of relationship between the current document and the
|
|
80
|
+
* linked document. Should only be used when `href` is specified. This
|
|
81
|
+
* defaults to "noopener noreferrer" when `target="_blank"`, but can be
|
|
82
|
+
* overridden by setting this prop to something else.
|
|
83
|
+
*/
|
|
84
|
+
rel?: string,
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A target destination window for a link to open in. Should only be used
|
|
88
|
+
* when `href` is specified.
|
|
89
|
+
*
|
|
90
|
+
* TODO(WB-1262): only allow this prop when `href` is also set.t
|
|
91
|
+
*/
|
|
92
|
+
target?: "_blank",
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Set the tabindex attribute on the rendered element.
|
|
96
|
+
*/
|
|
97
|
+
tabIndex?: number,
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether to avoid using client-side navigation.
|
|
101
|
+
*
|
|
102
|
+
* If the URL passed to href is local to the client-side, e.g.
|
|
103
|
+
* /math/algebra/eval-exprs, then it tries to use react-router-dom's Link
|
|
104
|
+
* component which handles the client-side navigation. You can set
|
|
105
|
+
* `skipClientNav` to true avoid using client-side nav entirely.
|
|
106
|
+
*
|
|
107
|
+
* NOTE: All URLs containing a protocol are considered external, e.g.
|
|
108
|
+
* https://khanacademy.org/math/algebra/eval-exprs will trigger a full
|
|
109
|
+
* page reload.
|
|
110
|
+
*/
|
|
111
|
+
skipClientNav?: boolean,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Optional custom styles.
|
|
115
|
+
*/
|
|
116
|
+
style?: StyleType,
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* URL to navigate to.
|
|
120
|
+
*/
|
|
121
|
+
href?: string,
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Used for buttons within <form>s.
|
|
125
|
+
*/
|
|
126
|
+
type?: "submit",
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Adds CSS classes to the Button.
|
|
130
|
+
*/
|
|
131
|
+
className?: string,
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Function to call when button is clicked.
|
|
135
|
+
*
|
|
136
|
+
* This callback should be used for running synchronous code, like
|
|
137
|
+
* dispatching a Redux action. For asynchronous code see the
|
|
138
|
+
* beforeNav and safeWithNav props. It should NOT be used to redirect
|
|
139
|
+
* to a different URL.
|
|
140
|
+
*
|
|
141
|
+
* Note: onClick is optional if href is present, but must be defined if
|
|
142
|
+
* href is not
|
|
143
|
+
*/
|
|
144
|
+
onClick?: (e: React.SyntheticEvent<>) => mixed,
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Run async code before navigating. If the promise returned rejects then
|
|
148
|
+
* navigation will not occur.
|
|
149
|
+
*
|
|
150
|
+
* If both safeWithNav and beforeNav are provided, beforeNav will be run
|
|
151
|
+
* first and safeWithNav will only be run if beforeNav does not reject.
|
|
152
|
+
*
|
|
153
|
+
* WARNING: Do not use with `type="submit"`.
|
|
154
|
+
*/
|
|
155
|
+
beforeNav?: () => Promise<mixed>,
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Run async code in the background while client-side navigating. If the
|
|
159
|
+
* browser does a full page load navigation, the callback promise must be
|
|
160
|
+
* settled before the navigation will occur. Errors are ignored so that
|
|
161
|
+
* navigation is guaranteed to succeed.
|
|
162
|
+
*
|
|
163
|
+
* WARNING: Do not use with `type="submit"`.
|
|
164
|
+
*/
|
|
165
|
+
safeWithNav?: () => Promise<mixed>,
|
|
166
|
+
...
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
declare type Props = SharedProps;
|
|
170
|
+
declare type DefaultProps = {
|
|
171
|
+
color: $PropertyType<Props, "color">,
|
|
172
|
+
kind: $PropertyType<Props, "kind">,
|
|
173
|
+
light: $PropertyType<Props, "light">,
|
|
174
|
+
size: $PropertyType<Props, "size">,
|
|
175
|
+
disabled: $PropertyType<Props, "disabled">,
|
|
176
|
+
spinner: $PropertyType<Props, "spinner">,
|
|
177
|
+
...
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Reusable button component.
|
|
181
|
+
*
|
|
182
|
+
* Consisting of a [`ClickableBehavior`](#clickablebehavior) surrounding a
|
|
183
|
+
* `ButtonCore`. `ClickableBehavior` handles interactions and state changes.
|
|
184
|
+
* `ButtonCore` is a stateless component which displays the different states
|
|
185
|
+
* the `Button` can take.
|
|
186
|
+
*
|
|
187
|
+
* ### Usage
|
|
188
|
+
*
|
|
189
|
+
* ```jsx
|
|
190
|
+
* import Button from "@khanacademy/wonder-blocks-button";
|
|
191
|
+
*
|
|
192
|
+
* <Button
|
|
193
|
+
* onClick={(e) => console.log("Hello, world!")}
|
|
194
|
+
* >
|
|
195
|
+
* Hello, world!
|
|
196
|
+
* </Button>
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare export default class Button mixins React.Component<Props> {
|
|
200
|
+
static defaultProps: DefaultProps;
|
|
201
|
+
renderClickableBehavior(router: any): React.Node;
|
|
202
|
+
render(): React.Element<>;
|
|
203
|
+
}
|