@khanacademy/wonder-blocks-icon-button 3.4.21 → 3.4.23
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 +36 -0
- package/dist/components/icon-button-core.d.ts +17 -0
- package/dist/components/icon-button-core.js.flow +32 -0
- package/dist/components/icon-button.d.ts +141 -0
- package/dist/components/icon-button.js.flow +165 -0
- package/dist/es/index.js +94 -55
- package/dist/index.d.ts +2 -0
- package/dist/index.js +113 -76
- package/dist/index.js.flow +9 -2
- package/package.json +7 -7
- package/src/__tests__/{custom-snapshot.test.js → custom-snapshot.test.tsx} +8 -9
- package/src/components/__tests__/{icon-button.test.js → icon-button.test.tsx} +2 -1
- package/src/components/{icon-button-core.js → icon-button-core.tsx} +24 -20
- package/src/components/{icon-button.js → icon-button.tsx} +24 -39
- package/src/{index.js → index.ts} +0 -1
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/__docs__/icon-button.stories.js +0 -201
- /package/src/__tests__/__snapshots__/{custom-snapshot.test.js.snap → custom-snapshot.test.tsx.snap} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-icon-button
|
|
2
2
|
|
|
3
|
+
## 3.4.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [779b031d]
|
|
8
|
+
- @khanacademy/wonder-blocks-core@4.9.0
|
|
9
|
+
- @khanacademy/wonder-blocks-clickable@2.4.7
|
|
10
|
+
- @khanacademy/wonder-blocks-icon@1.2.39
|
|
11
|
+
|
|
12
|
+
## 3.4.22
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- d816af08: Update build and test configs use TypeScript
|
|
17
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
18
|
+
- 0d28bb1c: Configured TypeScript
|
|
19
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
20
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
21
|
+
- 2983c05b: Include 'types' field in package.json
|
|
22
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
23
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
24
|
+
- Updated dependencies [d816af08]
|
|
25
|
+
- Updated dependencies [3891f544]
|
|
26
|
+
- Updated dependencies [3813715d]
|
|
27
|
+
- Updated dependencies [0d28bb1c]
|
|
28
|
+
- Updated dependencies [873f4a14]
|
|
29
|
+
- Updated dependencies [3d05f764]
|
|
30
|
+
- Updated dependencies [c2ec4902]
|
|
31
|
+
- Updated dependencies [2983c05b]
|
|
32
|
+
- Updated dependencies [77ff6a66]
|
|
33
|
+
- Updated dependencies [ec8d4b7f]
|
|
34
|
+
- @khanacademy/wonder-blocks-clickable@2.4.6
|
|
35
|
+
- @khanacademy/wonder-blocks-color@1.2.2
|
|
36
|
+
- @khanacademy/wonder-blocks-core@4.8.0
|
|
37
|
+
- @khanacademy/wonder-blocks-icon@1.2.38
|
|
38
|
+
|
|
3
39
|
## 3.4.21
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ChildrenProps, ClickableState } from "@khanacademy/wonder-blocks-clickable";
|
|
3
|
+
import type { SharedProps } from "./icon-button";
|
|
4
|
+
type Props = SharedProps & ChildrenProps & ClickableState & {
|
|
5
|
+
/**
|
|
6
|
+
* URL to navigate to.
|
|
7
|
+
*
|
|
8
|
+
* Used to determine whether to render an `<a>` or `<button>` tag. Also
|
|
9
|
+
* passed in as the `<a>` tag's `href` if present.
|
|
10
|
+
*/
|
|
11
|
+
href?: string;
|
|
12
|
+
};
|
|
13
|
+
export default class IconButtonCore extends React.Component<Props> {
|
|
14
|
+
renderInner(router: any): React.ReactNode;
|
|
15
|
+
render(): React.ReactElement;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for icon-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 "./icon-button";
|
|
14
|
+
declare type Props = {
|
|
15
|
+
...SharedProps,
|
|
16
|
+
...ChildrenProps,
|
|
17
|
+
...ClickableState,
|
|
18
|
+
...{
|
|
19
|
+
/**
|
|
20
|
+
* URL to navigate to.
|
|
21
|
+
*
|
|
22
|
+
* Used to determine whether to render an `<a>` or `<button>` tag. Also
|
|
23
|
+
* passed in as the `<a>` tag's `href` if present.
|
|
24
|
+
*/
|
|
25
|
+
href?: string,
|
|
26
|
+
...
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
declare export default class IconButtonCore extends React.Component<Props> {
|
|
30
|
+
renderInner(router: any): React.Node;
|
|
31
|
+
render(): React.Element<>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { IconAsset } from "@khanacademy/wonder-blocks-icon";
|
|
3
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
4
|
+
export type SharedProps = Partial<Omit<AriaProps, "aria-disabled">> & {
|
|
5
|
+
/**
|
|
6
|
+
* A Wonder Blocks icon asset, an object specifing paths for one or more of
|
|
7
|
+
* the following sizes: small, medium, large, xlarge.
|
|
8
|
+
*/
|
|
9
|
+
icon: IconAsset;
|
|
10
|
+
/**
|
|
11
|
+
* The color of the icon button, either blue or red.
|
|
12
|
+
*/
|
|
13
|
+
color: "default" | "destructive";
|
|
14
|
+
/**
|
|
15
|
+
* The kind of the icon button, either primary, secondary, or tertiary.
|
|
16
|
+
*
|
|
17
|
+
* In default state:
|
|
18
|
+
* - Primary icon buttons are color: props.color
|
|
19
|
+
* - Secondary buttons are offBlack
|
|
20
|
+
* - Tertiary buttons are offBlack64
|
|
21
|
+
*
|
|
22
|
+
* In the hover/focus/press states, all variants have a border.
|
|
23
|
+
*/
|
|
24
|
+
kind: "primary" | "secondary" | "tertiary";
|
|
25
|
+
/**
|
|
26
|
+
* Whether the icon button is on a dark/colored background.
|
|
27
|
+
*/
|
|
28
|
+
light: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the icon button is disabled.
|
|
31
|
+
*/
|
|
32
|
+
disabled: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Test ID used for e2e testing.
|
|
35
|
+
*/
|
|
36
|
+
testId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Optional custom styles.
|
|
39
|
+
*/
|
|
40
|
+
style?: StyleType;
|
|
41
|
+
/**
|
|
42
|
+
* Adds CSS classes to the IconButton.
|
|
43
|
+
*/
|
|
44
|
+
className?: string;
|
|
45
|
+
/**
|
|
46
|
+
* URL to navigate to.
|
|
47
|
+
*
|
|
48
|
+
* Note: Either href or onClick must be defined
|
|
49
|
+
*/
|
|
50
|
+
href?: string;
|
|
51
|
+
/**
|
|
52
|
+
* A target destination window for a link to open in.
|
|
53
|
+
*/
|
|
54
|
+
target?: "_blank";
|
|
55
|
+
/**
|
|
56
|
+
* Specifies the type of relationship between the current document and the
|
|
57
|
+
* linked document. Should only be used when `href` is specified. This
|
|
58
|
+
* defaults to "noopener noreferrer" when `target="_blank"`, but can be
|
|
59
|
+
* overridden by setting this prop to something else.
|
|
60
|
+
*/
|
|
61
|
+
rel?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Set the tabindex attribute on the rendered element.
|
|
64
|
+
*/
|
|
65
|
+
tabIndex?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Whether to avoid using client-side navigation.
|
|
68
|
+
*
|
|
69
|
+
* If the URL passed to href is local to the client-side, e.g.
|
|
70
|
+
* /math/algebra/eval-exprs, then it tries to use react-router-dom's Link
|
|
71
|
+
* component which handles the client-side navigation. You can set
|
|
72
|
+
* `skipClientNav` to true avoid using client-side nav entirely.
|
|
73
|
+
*
|
|
74
|
+
* NOTE: All URLs containing a protocol are considered external, e.g.
|
|
75
|
+
* https://khanacademy.org/math/algebra/eval-exprs will trigger a full
|
|
76
|
+
* page reload.
|
|
77
|
+
*/
|
|
78
|
+
skipClientNav?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Function to call when button is clicked.
|
|
81
|
+
*
|
|
82
|
+
* This callback should be used for things like marking BigBingo
|
|
83
|
+
* conversions. It should NOT be used to redirect to a different URL or to
|
|
84
|
+
* prevent navigation via e.preventDefault(). The event passed to this
|
|
85
|
+
* handler will have its preventDefault() and stopPropagation() methods
|
|
86
|
+
* stubbed out.
|
|
87
|
+
*
|
|
88
|
+
* Note: onClick is optional if href is present, but must be defined if
|
|
89
|
+
* href is not
|
|
90
|
+
*/
|
|
91
|
+
onClick?: (e: React.SyntheticEvent) => unknown;
|
|
92
|
+
};
|
|
93
|
+
type DefaultProps = {
|
|
94
|
+
color: SharedProps["color"];
|
|
95
|
+
kind: SharedProps["kind"];
|
|
96
|
+
light: SharedProps["light"];
|
|
97
|
+
disabled: SharedProps["disabled"];
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* An IconButton is a button whose contents are an SVG image.
|
|
101
|
+
*
|
|
102
|
+
* To use, supply an onClick function, a wonder-blocks icon asset (see
|
|
103
|
+
* the Icon section) and an aria-label to describe the button functionality.
|
|
104
|
+
* Optionally specify href (URL), clientSideNav, color
|
|
105
|
+
* (Wonder Blocks Blue or Red), kind ("primary", "secondary", or "tertiary"),
|
|
106
|
+
* light (whether the IconButton will be rendered on a dark background),
|
|
107
|
+
* disabled , test ID, and custom styling.
|
|
108
|
+
*
|
|
109
|
+
* The size of an IconButton matches the size of icon it wraps which is 24x24
|
|
110
|
+
* pixels. The focus ring which is displayed on hover and focus is much
|
|
111
|
+
* larger but does not affect its size. This matches the behavior of Button.
|
|
112
|
+
*
|
|
113
|
+
* IconButtons require a certain amount of space between them to ensure the
|
|
114
|
+
* focus rings don't overlap. The minimum amount of spacing is 16px, but
|
|
115
|
+
* you should refer to the mocks provided by design. Using a Strut in between
|
|
116
|
+
* IconButtons is the preferred way to for adding this spacing.
|
|
117
|
+
*
|
|
118
|
+
* Many layouts require alignment of visual left (or right) side of an
|
|
119
|
+
* IconButton. This requires a little bit of pixel nudging since each icon
|
|
120
|
+
* as a different amount of internal padding.
|
|
121
|
+
*
|
|
122
|
+
* See the Toolbar documentation for examples of IconButton use that follow
|
|
123
|
+
* the best practices described above.
|
|
124
|
+
*
|
|
125
|
+
* ```js
|
|
126
|
+
* import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
127
|
+
* import IconButton from "@khanacademy/wonder-blocks-icon-button";
|
|
128
|
+
*
|
|
129
|
+
* <IconButton
|
|
130
|
+
* icon={icons.anIcon}
|
|
131
|
+
* aria-label="An Icon"
|
|
132
|
+
* onClick={(e) => console.log("Hello, world!")}
|
|
133
|
+
* />
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export default class IconButton extends React.Component<SharedProps> {
|
|
137
|
+
static defaultProps: DefaultProps;
|
|
138
|
+
renderClickableBehavior(router: any): React.ReactNode;
|
|
139
|
+
render(): React.ReactElement;
|
|
140
|
+
}
|
|
141
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for icon-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 { IconAsset } from "@khanacademy/wonder-blocks-icon";
|
|
10
|
+
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
11
|
+
export type SharedProps = {
|
|
12
|
+
...$Rest<$Diff<AriaProps, { "aria-disabled": any }>, { ... }>,
|
|
13
|
+
...{
|
|
14
|
+
/**
|
|
15
|
+
* A Wonder Blocks icon asset, an object specifing paths for one or more of
|
|
16
|
+
* the following sizes: small, medium, large, xlarge.
|
|
17
|
+
*/
|
|
18
|
+
icon: IconAsset,
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The color of the icon button, either blue or red.
|
|
22
|
+
*/
|
|
23
|
+
color: "default" | "destructive",
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The kind of the icon button, either primary, secondary, or tertiary.
|
|
27
|
+
*
|
|
28
|
+
* In default state:
|
|
29
|
+
* - Primary icon buttons are color: props.color
|
|
30
|
+
* - Secondary buttons are offBlack
|
|
31
|
+
* - Tertiary buttons are offBlack64
|
|
32
|
+
*
|
|
33
|
+
* In the hover/focus/press states, all variants have a border.
|
|
34
|
+
*/
|
|
35
|
+
kind: "primary" | "secondary" | "tertiary",
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether the icon button is on a dark/colored background.
|
|
39
|
+
*/
|
|
40
|
+
light: boolean,
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether the icon button is disabled.
|
|
44
|
+
*/
|
|
45
|
+
disabled: boolean,
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Test ID used for e2e testing.
|
|
49
|
+
*/
|
|
50
|
+
testId?: string,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Optional custom styles.
|
|
54
|
+
*/
|
|
55
|
+
style?: StyleType,
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Adds CSS classes to the IconButton.
|
|
59
|
+
*/
|
|
60
|
+
className?: string,
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* URL to navigate to.
|
|
64
|
+
*
|
|
65
|
+
* Note: Either href or onClick must be defined
|
|
66
|
+
*/
|
|
67
|
+
href?: string,
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A target destination window for a link to open in.
|
|
71
|
+
*/
|
|
72
|
+
target?: "_blank",
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Specifies the type of relationship between the current document and the
|
|
76
|
+
* linked document. Should only be used when `href` is specified. This
|
|
77
|
+
* defaults to "noopener noreferrer" when `target="_blank"`, but can be
|
|
78
|
+
* overridden by setting this prop to something else.
|
|
79
|
+
*/
|
|
80
|
+
rel?: string,
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set the tabindex attribute on the rendered element.
|
|
84
|
+
*/
|
|
85
|
+
tabIndex?: number,
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Whether to avoid using client-side navigation.
|
|
89
|
+
*
|
|
90
|
+
* If the URL passed to href is local to the client-side, e.g.
|
|
91
|
+
* /math/algebra/eval-exprs, then it tries to use react-router-dom's Link
|
|
92
|
+
* component which handles the client-side navigation. You can set
|
|
93
|
+
* `skipClientNav` to true avoid using client-side nav entirely.
|
|
94
|
+
*
|
|
95
|
+
* NOTE: All URLs containing a protocol are considered external, e.g.
|
|
96
|
+
* https://khanacademy.org/math/algebra/eval-exprs will trigger a full
|
|
97
|
+
* page reload.
|
|
98
|
+
*/
|
|
99
|
+
skipClientNav?: boolean,
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Function to call when button is clicked.
|
|
103
|
+
*
|
|
104
|
+
* This callback should be used for things like marking BigBingo
|
|
105
|
+
* conversions. It should NOT be used to redirect to a different URL or to
|
|
106
|
+
* prevent navigation via e.preventDefault(). The event passed to this
|
|
107
|
+
* handler will have its preventDefault() and stopPropagation() methods
|
|
108
|
+
* stubbed out.
|
|
109
|
+
*
|
|
110
|
+
* Note: onClick is optional if href is present, but must be defined if
|
|
111
|
+
* href is not
|
|
112
|
+
*/
|
|
113
|
+
onClick?: (e: React.SyntheticEvent<>) => mixed,
|
|
114
|
+
...
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
declare type DefaultProps = {
|
|
118
|
+
color: $PropertyType<SharedProps, "color">,
|
|
119
|
+
kind: $PropertyType<SharedProps, "kind">,
|
|
120
|
+
light: $PropertyType<SharedProps, "light">,
|
|
121
|
+
disabled: $PropertyType<SharedProps, "disabled">,
|
|
122
|
+
...
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* An IconButton is a button whose contents are an SVG image.
|
|
126
|
+
*
|
|
127
|
+
* To use, supply an onClick function, a wonder-blocks icon asset (see
|
|
128
|
+
* the Icon section) and an aria-label to describe the button functionality.
|
|
129
|
+
* Optionally specify href (URL), clientSideNav, color
|
|
130
|
+
* (Wonder Blocks Blue or Red), kind ("primary", "secondary", or "tertiary"),
|
|
131
|
+
* light (whether the IconButton will be rendered on a dark background),
|
|
132
|
+
* disabled , test ID, and custom styling.
|
|
133
|
+
*
|
|
134
|
+
* The size of an IconButton matches the size of icon it wraps which is 24x24
|
|
135
|
+
* pixels. The focus ring which is displayed on hover and focus is much
|
|
136
|
+
* larger but does not affect its size. This matches the behavior of Button.
|
|
137
|
+
*
|
|
138
|
+
* IconButtons require a certain amount of space between them to ensure the
|
|
139
|
+
* focus rings don't overlap. The minimum amount of spacing is 16px, but
|
|
140
|
+
* you should refer to the mocks provided by design. Using a Strut in between
|
|
141
|
+
* IconButtons is the preferred way to for adding this spacing.
|
|
142
|
+
*
|
|
143
|
+
* Many layouts require alignment of visual left (or right) side of an
|
|
144
|
+
* IconButton. This requires a little bit of pixel nudging since each icon
|
|
145
|
+
* as a different amount of internal padding.
|
|
146
|
+
*
|
|
147
|
+
* See the Toolbar documentation for examples of IconButton use that follow
|
|
148
|
+
* the best practices described above.
|
|
149
|
+
*
|
|
150
|
+
* ```js
|
|
151
|
+
* import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
152
|
+
* import IconButton from "@khanacademy/wonder-blocks-icon-button";
|
|
153
|
+
*
|
|
154
|
+
* <IconButton
|
|
155
|
+
* icon={icons.anIcon}
|
|
156
|
+
* aria-label="An Icon"
|
|
157
|
+
* onClick={(e) => console.log("Hello, world!")}
|
|
158
|
+
* />
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare export default class IconButton extends React.Component<SharedProps> {
|
|
162
|
+
static defaultProps: DefaultProps;
|
|
163
|
+
renderClickableBehavior(router: any): React.Node;
|
|
164
|
+
render(): React.Element<>;
|
|
165
|
+
}
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
-
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
3
1
|
import * as React from 'react';
|
|
4
2
|
import { __RouterContext } from 'react-router';
|
|
5
3
|
import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
|
|
@@ -9,45 +7,91 @@ import Color, { SemanticColor, mix, fade } from '@khanacademy/wonder-blocks-colo
|
|
|
9
7
|
import { addStyle } from '@khanacademy/wonder-blocks-core';
|
|
10
8
|
import Icon from '@khanacademy/wonder-blocks-icon';
|
|
11
9
|
|
|
10
|
+
function _objectDestructuringEmpty(obj) {
|
|
11
|
+
if (obj == null) throw new TypeError("Cannot destructure " + obj);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function _extends() {
|
|
15
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
16
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
17
|
+
var source = arguments[i];
|
|
18
|
+
for (var key in source) {
|
|
19
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
20
|
+
target[key] = source[key];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
return _extends.apply(this, arguments);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
30
|
+
if (source == null) return {};
|
|
31
|
+
var target = {};
|
|
32
|
+
var sourceKeys = Object.keys(source);
|
|
33
|
+
var key, i;
|
|
34
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
35
|
+
key = sourceKeys[i];
|
|
36
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
37
|
+
target[key] = source[key];
|
|
38
|
+
}
|
|
39
|
+
return target;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _setPrototypeOf(o, p) {
|
|
43
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
44
|
+
o.__proto__ = p;
|
|
45
|
+
return o;
|
|
46
|
+
};
|
|
47
|
+
return _setPrototypeOf(o, p);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _inheritsLoose(subClass, superClass) {
|
|
51
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
52
|
+
subClass.prototype.constructor = subClass;
|
|
53
|
+
_setPrototypeOf(subClass, superClass);
|
|
54
|
+
}
|
|
55
|
+
|
|
12
56
|
const _excluded$1 = ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"];
|
|
13
57
|
const StyledAnchor = addStyle("a");
|
|
14
58
|
const StyledButton = addStyle("button");
|
|
15
59
|
const StyledLink = addStyle(Link);
|
|
16
|
-
|
|
17
|
-
|
|
60
|
+
let IconButtonCore = function (_React$Component) {
|
|
61
|
+
_inheritsLoose(IconButtonCore, _React$Component);
|
|
62
|
+
function IconButtonCore() {
|
|
63
|
+
return _React$Component.apply(this, arguments) || this;
|
|
64
|
+
}
|
|
65
|
+
var _proto = IconButtonCore.prototype;
|
|
66
|
+
_proto.renderInner = function renderInner(router) {
|
|
18
67
|
const _this$props = this.props,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
68
|
+
{
|
|
69
|
+
skipClientNav,
|
|
70
|
+
color,
|
|
71
|
+
disabled,
|
|
72
|
+
focused,
|
|
73
|
+
hovered,
|
|
74
|
+
href,
|
|
75
|
+
icon,
|
|
76
|
+
kind,
|
|
77
|
+
light,
|
|
78
|
+
pressed,
|
|
79
|
+
style,
|
|
80
|
+
testId
|
|
81
|
+
} = _this$props,
|
|
82
|
+
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
35
83
|
const buttonColor = color === "destructive" ? SemanticColor.controlDestructive : SemanticColor.controlDefault;
|
|
36
|
-
|
|
37
84
|
const buttonStyles = _generateStyles(buttonColor, kind, light);
|
|
38
|
-
|
|
39
85
|
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
|
|
40
86
|
const child = React.createElement(Icon, {
|
|
41
87
|
size: "medium",
|
|
42
88
|
color: "currentColor",
|
|
43
89
|
icon: icon
|
|
44
90
|
});
|
|
45
|
-
|
|
46
91
|
const commonProps = _extends({
|
|
47
92
|
"data-test-id": testId,
|
|
48
93
|
style: [defaultStyle, style]
|
|
49
94
|
}, restProps);
|
|
50
|
-
|
|
51
95
|
if (href && !disabled) {
|
|
52
96
|
return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
|
|
53
97
|
to: href
|
|
@@ -61,13 +105,12 @@ class IconButtonCore extends React.Component {
|
|
|
61
105
|
disabled: disabled
|
|
62
106
|
}), child);
|
|
63
107
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
render() {
|
|
108
|
+
};
|
|
109
|
+
_proto.render = function render() {
|
|
67
110
|
return React.createElement(__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
111
|
+
};
|
|
112
|
+
return IconButtonCore;
|
|
113
|
+
}(React.Component);
|
|
71
114
|
const sharedStyles = StyleSheet.create({
|
|
72
115
|
shared: {
|
|
73
116
|
position: "relative",
|
|
@@ -94,18 +137,14 @@ const sharedStyles = StyleSheet.create({
|
|
|
94
137
|
}
|
|
95
138
|
});
|
|
96
139
|
const styles = {};
|
|
97
|
-
|
|
98
140
|
const _generateStyles = (color, kind, light) => {
|
|
99
141
|
const buttonType = color + kind + light.toString();
|
|
100
|
-
|
|
101
142
|
if (styles[buttonType]) {
|
|
102
143
|
return styles[buttonType];
|
|
103
144
|
}
|
|
104
|
-
|
|
105
145
|
if (light && kind !== "primary") {
|
|
106
146
|
throw new Error("Light is only supported for primary IconButtons");
|
|
107
147
|
}
|
|
108
|
-
|
|
109
148
|
const {
|
|
110
149
|
white,
|
|
111
150
|
offBlack32,
|
|
@@ -133,7 +172,6 @@ const _generateStyles = (color, kind, light) => {
|
|
|
133
172
|
cursor: "default"
|
|
134
173
|
}
|
|
135
174
|
};
|
|
136
|
-
|
|
137
175
|
if (kind === "primary") {
|
|
138
176
|
newStyles["default"] = {
|
|
139
177
|
color: light ? white : color
|
|
@@ -149,24 +187,27 @@ const _generateStyles = (color, kind, light) => {
|
|
|
149
187
|
} else {
|
|
150
188
|
throw new Error("IconButton kind not recognized");
|
|
151
189
|
}
|
|
152
|
-
|
|
153
190
|
styles[buttonType] = StyleSheet.create(newStyles);
|
|
154
191
|
return styles[buttonType];
|
|
155
192
|
};
|
|
156
193
|
|
|
157
194
|
const _excluded = ["onClick", "href", "skipClientNav", "tabIndex", "target"];
|
|
158
|
-
|
|
159
|
-
|
|
195
|
+
let IconButton = function (_React$Component) {
|
|
196
|
+
_inheritsLoose(IconButton, _React$Component);
|
|
197
|
+
function IconButton() {
|
|
198
|
+
return _React$Component.apply(this, arguments) || this;
|
|
199
|
+
}
|
|
200
|
+
var _proto = IconButton.prototype;
|
|
201
|
+
_proto.renderClickableBehavior = function renderClickableBehavior(router) {
|
|
160
202
|
const _this$props = this.props,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
203
|
+
{
|
|
204
|
+
onClick,
|
|
205
|
+
href,
|
|
206
|
+
skipClientNav,
|
|
207
|
+
tabIndex,
|
|
208
|
+
target
|
|
209
|
+
} = _this$props,
|
|
210
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
170
211
|
const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
|
|
171
212
|
return React.createElement(ClickableBehavior, {
|
|
172
213
|
disabled: sharedProps.disabled,
|
|
@@ -175,8 +216,7 @@ class IconButton extends React.Component {
|
|
|
175
216
|
role: "button",
|
|
176
217
|
target: target
|
|
177
218
|
}, (state, _ref) => {
|
|
178
|
-
let childrenProps = _extends({}, _ref);
|
|
179
|
-
|
|
219
|
+
let childrenProps = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
180
220
|
return React.createElement(IconButtonCore, _extends({}, sharedProps, state, childrenProps, {
|
|
181
221
|
skipClientNav: skipClientNav,
|
|
182
222
|
href: href,
|
|
@@ -184,13 +224,12 @@ class IconButton extends React.Component {
|
|
|
184
224
|
tabIndex: tabIndex
|
|
185
225
|
}));
|
|
186
226
|
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
render() {
|
|
227
|
+
};
|
|
228
|
+
_proto.render = function render() {
|
|
190
229
|
return React.createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
}
|
|
230
|
+
};
|
|
231
|
+
return IconButton;
|
|
232
|
+
}(React.Component);
|
|
194
233
|
IconButton.defaultProps = {
|
|
195
234
|
color: "default",
|
|
196
235
|
kind: "primary",
|
package/dist/index.d.ts
ADDED