orcs-design-system 3.2.0 → 3.2.2
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/es/components/Button/Button.stories.js +19 -2
- package/es/components/Button/ButtonLink.stories.js +231 -0
- package/es/components/Button/index.js +350 -223
- package/es/components/StyledLink/StyledLink.stories.js +28 -4
- package/es/components/StyledLink/index.js +9 -145
- package/es/components.test.js +1 -1
- package/es/index.js +1 -1
- package/package.json +1 -1
|
@@ -3,15 +3,27 @@ import { action } from "@storybook/addon-actions";
|
|
|
3
3
|
import Icon from "../Icon";
|
|
4
4
|
import Spacer from "../Spacer";
|
|
5
5
|
import Flex from "../Flex";
|
|
6
|
-
import Button from ".";
|
|
6
|
+
import Button, { VARIANT_COLORS } from ".";
|
|
7
7
|
export default {
|
|
8
|
-
title: "Components/Button",
|
|
8
|
+
title: "Components/Buttons/Button",
|
|
9
9
|
component: Button
|
|
10
10
|
};
|
|
11
11
|
export var defaultButton = function defaultButton() {
|
|
12
12
|
return /*#__PURE__*/React.createElement(Button, null, "Default button");
|
|
13
13
|
};
|
|
14
14
|
defaultButton.storyName = "Default button";
|
|
15
|
+
export var variants = function variants() {
|
|
16
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
17
|
+
my: "3"
|
|
18
|
+
}, Object.keys(VARIANT_COLORS).map(function (variant) {
|
|
19
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
20
|
+
large: true,
|
|
21
|
+
key: variant,
|
|
22
|
+
variant: variant,
|
|
23
|
+
onClick: action("clicked")
|
|
24
|
+
}, variant);
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
15
27
|
export var alternateSize = function alternateSize() {
|
|
16
28
|
return /*#__PURE__*/React.createElement(Spacer, {
|
|
17
29
|
my: "3"
|
|
@@ -179,6 +191,11 @@ defaultButton.__docgenInfo = {
|
|
|
179
191
|
"methods": [],
|
|
180
192
|
"displayName": "defaultButton"
|
|
181
193
|
};
|
|
194
|
+
variants.__docgenInfo = {
|
|
195
|
+
"description": "",
|
|
196
|
+
"methods": [],
|
|
197
|
+
"displayName": "variants"
|
|
198
|
+
};
|
|
182
199
|
alternateSize.__docgenInfo = {
|
|
183
200
|
"description": "",
|
|
184
201
|
"methods": [],
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Icon from "../Icon";
|
|
3
|
+
import Spacer from "../Spacer";
|
|
4
|
+
import Flex from "../Flex";
|
|
5
|
+
import { VARIANT_COLORS, ButtonLink } from ".";
|
|
6
|
+
export default {
|
|
7
|
+
title: "Components/Buttons/ButtonLink",
|
|
8
|
+
component: ButtonLink
|
|
9
|
+
};
|
|
10
|
+
var link = "http://www.google.com";
|
|
11
|
+
export var defaultButton = function defaultButton() {
|
|
12
|
+
return /*#__PURE__*/React.createElement(ButtonLink, {
|
|
13
|
+
href: link
|
|
14
|
+
}, "Default button");
|
|
15
|
+
};
|
|
16
|
+
defaultButton.storyName = "Default button";
|
|
17
|
+
export var variants = function variants() {
|
|
18
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
19
|
+
my: "3"
|
|
20
|
+
}, Object.keys(VARIANT_COLORS).map(function (variant) {
|
|
21
|
+
return /*#__PURE__*/React.createElement(ButtonLink, {
|
|
22
|
+
large: true,
|
|
23
|
+
key: variant,
|
|
24
|
+
variant: variant,
|
|
25
|
+
href: link
|
|
26
|
+
}, variant);
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
export var alternateSize = function alternateSize() {
|
|
30
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
31
|
+
my: "3"
|
|
32
|
+
}, /*#__PURE__*/React.createElement(ButtonLink, {
|
|
33
|
+
small: true,
|
|
34
|
+
href: link
|
|
35
|
+
}, "Small button"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
36
|
+
large: true,
|
|
37
|
+
href: link
|
|
38
|
+
}, "Large button"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
39
|
+
height: "xxxl",
|
|
40
|
+
href: link
|
|
41
|
+
}, "Specified height button"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
42
|
+
href: link,
|
|
43
|
+
width: "100px"
|
|
44
|
+
}, "A multiple-line button with specified width"));
|
|
45
|
+
};
|
|
46
|
+
alternateSize.storyName = "Alternate sizes";
|
|
47
|
+
export var alternateColours = function alternateColours() {
|
|
48
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
49
|
+
my: "3"
|
|
50
|
+
}, /*#__PURE__*/React.createElement(ButtonLink, {
|
|
51
|
+
variant: "success",
|
|
52
|
+
href: link
|
|
53
|
+
}, "Success/green button"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
54
|
+
variant: "danger",
|
|
55
|
+
href: link
|
|
56
|
+
}, "Danger/red button"));
|
|
57
|
+
};
|
|
58
|
+
alternateColours.storyName = "Alternate colours";
|
|
59
|
+
export var ghost = function ghost() {
|
|
60
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
61
|
+
my: "3"
|
|
62
|
+
}, /*#__PURE__*/React.createElement(ButtonLink, {
|
|
63
|
+
small: true,
|
|
64
|
+
variant: "ghost",
|
|
65
|
+
href: link
|
|
66
|
+
}, "Small ghost button"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
67
|
+
variant: "ghost",
|
|
68
|
+
href: link
|
|
69
|
+
}, "Regular ghost button"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
70
|
+
large: true,
|
|
71
|
+
variant: "ghost",
|
|
72
|
+
href: link
|
|
73
|
+
}, "Large ghost button"));
|
|
74
|
+
};
|
|
75
|
+
ghost.storyName = "Ghost style";
|
|
76
|
+
export var fullWidth = function fullWidth() {
|
|
77
|
+
return /*#__PURE__*/React.createElement(ButtonLink, {
|
|
78
|
+
fullWidth: true,
|
|
79
|
+
href: link
|
|
80
|
+
}, "Full width button");
|
|
81
|
+
};
|
|
82
|
+
fullWidth.storyName = "Full width";
|
|
83
|
+
export var disabled = function disabled() {
|
|
84
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
85
|
+
my: "r"
|
|
86
|
+
}, /*#__PURE__*/React.createElement(ButtonLink, {
|
|
87
|
+
disabled: true,
|
|
88
|
+
href: link
|
|
89
|
+
}, "Disabled button"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
90
|
+
variant: "disabled",
|
|
91
|
+
href: link
|
|
92
|
+
}, "Alternate way of making button disabled"));
|
|
93
|
+
};
|
|
94
|
+
disabled.storyName = "Disabled state";
|
|
95
|
+
export var withIcon = function withIcon() {
|
|
96
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
97
|
+
my: "3"
|
|
98
|
+
}, /*#__PURE__*/React.createElement(ButtonLink, {
|
|
99
|
+
iconLeft: true,
|
|
100
|
+
href: link,
|
|
101
|
+
isLoading: true
|
|
102
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
103
|
+
icon: ["fas", "user-plus"]
|
|
104
|
+
}), "Left aligned icon"), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
105
|
+
iconRight: true,
|
|
106
|
+
href: link
|
|
107
|
+
}, "Right aligned icon", /*#__PURE__*/React.createElement(Icon, {
|
|
108
|
+
icon: ["fas", "download"]
|
|
109
|
+
})), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
110
|
+
leftIcon: ["fas", "star"],
|
|
111
|
+
href: link
|
|
112
|
+
}, "Left icon magic!"));
|
|
113
|
+
};
|
|
114
|
+
withIcon.storyName = "With icon";
|
|
115
|
+
export var iconOnly = function iconOnly() {
|
|
116
|
+
return /*#__PURE__*/React.createElement(Spacer, {
|
|
117
|
+
my: "3"
|
|
118
|
+
}, /*#__PURE__*/React.createElement(ButtonLink, {
|
|
119
|
+
small: true,
|
|
120
|
+
iconOnly: true,
|
|
121
|
+
p: "s",
|
|
122
|
+
ariaLabel: /*#__PURE__*/React.createElement(Icon, {
|
|
123
|
+
icon: ["fas", "download"]
|
|
124
|
+
}),
|
|
125
|
+
href: link
|
|
126
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
127
|
+
icon: ["far", "calendar-alt"]
|
|
128
|
+
})), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
129
|
+
iconOnly: true,
|
|
130
|
+
p: "s",
|
|
131
|
+
ariaLabel: "Show calendar",
|
|
132
|
+
href: link
|
|
133
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
134
|
+
icon: ["far", "calendar-alt"]
|
|
135
|
+
})), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
136
|
+
large: true,
|
|
137
|
+
iconOnly: true,
|
|
138
|
+
p: "s",
|
|
139
|
+
ariaLabel: "Show calendar",
|
|
140
|
+
href: link
|
|
141
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
142
|
+
icon: ["far", "calendar-alt"]
|
|
143
|
+
})), /*#__PURE__*/React.createElement(Flex, {
|
|
144
|
+
alignItems: "center",
|
|
145
|
+
mt: "r"
|
|
146
|
+
}, /*#__PURE__*/React.createElement(Spacer, {
|
|
147
|
+
mr: "r"
|
|
148
|
+
}, /*#__PURE__*/React.createElement(ButtonLink, {
|
|
149
|
+
iconOnly: true,
|
|
150
|
+
variant: "success",
|
|
151
|
+
href: link,
|
|
152
|
+
width: "33px",
|
|
153
|
+
height: "32px",
|
|
154
|
+
ariaLabel: "Confirm"
|
|
155
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
156
|
+
icon: ["fas", "check"]
|
|
157
|
+
})), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
158
|
+
iconOnly: true,
|
|
159
|
+
variant: "successAlternate",
|
|
160
|
+
href: link,
|
|
161
|
+
width: "33px",
|
|
162
|
+
height: "32px",
|
|
163
|
+
ariaLabel: "Confirm"
|
|
164
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
165
|
+
icon: ["fas", "check"]
|
|
166
|
+
})), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
167
|
+
iconOnly: true,
|
|
168
|
+
variant: "danger",
|
|
169
|
+
href: link,
|
|
170
|
+
width: "33px",
|
|
171
|
+
height: "32px",
|
|
172
|
+
ariaLabel: "Cancel"
|
|
173
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
174
|
+
icon: ["fas", "times"]
|
|
175
|
+
})), /*#__PURE__*/React.createElement(ButtonLink, {
|
|
176
|
+
iconOnly: true,
|
|
177
|
+
variant: "dangerAlternate",
|
|
178
|
+
href: link,
|
|
179
|
+
width: "33px",
|
|
180
|
+
height: "32px",
|
|
181
|
+
ariaLabel: "Cancel"
|
|
182
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
183
|
+
icon: ["fas", "times"]
|
|
184
|
+
})))));
|
|
185
|
+
};
|
|
186
|
+
iconOnly.storyName = "Icon only";
|
|
187
|
+
defaultButton.__docgenInfo = {
|
|
188
|
+
"description": "",
|
|
189
|
+
"methods": [],
|
|
190
|
+
"displayName": "defaultButton"
|
|
191
|
+
};
|
|
192
|
+
variants.__docgenInfo = {
|
|
193
|
+
"description": "",
|
|
194
|
+
"methods": [],
|
|
195
|
+
"displayName": "variants"
|
|
196
|
+
};
|
|
197
|
+
alternateSize.__docgenInfo = {
|
|
198
|
+
"description": "",
|
|
199
|
+
"methods": [],
|
|
200
|
+
"displayName": "alternateSize"
|
|
201
|
+
};
|
|
202
|
+
alternateColours.__docgenInfo = {
|
|
203
|
+
"description": "",
|
|
204
|
+
"methods": [],
|
|
205
|
+
"displayName": "alternateColours"
|
|
206
|
+
};
|
|
207
|
+
ghost.__docgenInfo = {
|
|
208
|
+
"description": "",
|
|
209
|
+
"methods": [],
|
|
210
|
+
"displayName": "ghost"
|
|
211
|
+
};
|
|
212
|
+
fullWidth.__docgenInfo = {
|
|
213
|
+
"description": "",
|
|
214
|
+
"methods": [],
|
|
215
|
+
"displayName": "fullWidth"
|
|
216
|
+
};
|
|
217
|
+
disabled.__docgenInfo = {
|
|
218
|
+
"description": "",
|
|
219
|
+
"methods": [],
|
|
220
|
+
"displayName": "disabled"
|
|
221
|
+
};
|
|
222
|
+
withIcon.__docgenInfo = {
|
|
223
|
+
"description": "",
|
|
224
|
+
"methods": [],
|
|
225
|
+
"displayName": "withIcon"
|
|
226
|
+
};
|
|
227
|
+
iconOnly.__docgenInfo = {
|
|
228
|
+
"description": "",
|
|
229
|
+
"methods": [],
|
|
230
|
+
"displayName": "iconOnly"
|
|
231
|
+
};
|
|
@@ -1,251 +1,258 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
5
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
6
|
import React from "react";
|
|
8
|
-
import styled, { ThemeProvider } from "styled-components";
|
|
7
|
+
import styled, { ThemeProvider, css } from "styled-components";
|
|
9
8
|
import PropTypes from "prop-types";
|
|
10
|
-
import { space, layout, color, border,
|
|
11
|
-
import { css } from "@styled-system/css";
|
|
9
|
+
import { space, layout, color, border, compose } from "styled-system";
|
|
12
10
|
import shouldForwardProp from "@styled-system/should-forward-prop";
|
|
13
11
|
import Icon from "../Icon";
|
|
14
12
|
import Loading from "../Loading";
|
|
15
13
|
import { themeGet } from "@styled-system/theme-get";
|
|
14
|
+
import { Link } from "react-router-dom";
|
|
15
|
+
import { omit } from "lodash";
|
|
16
16
|
export var VARIANT_COLORS = {
|
|
17
17
|
"default": {
|
|
18
18
|
background: "colors.primary",
|
|
19
19
|
color: "colors.white",
|
|
20
|
+
borderColor: "colors.primary",
|
|
20
21
|
hovered: {
|
|
21
22
|
background: "colors.primaryDark",
|
|
22
|
-
color: "colors.white"
|
|
23
|
+
color: "colors.white",
|
|
24
|
+
borderColor: "colors.primaryDark"
|
|
23
25
|
}
|
|
24
26
|
},
|
|
25
27
|
success: {
|
|
26
28
|
background: "colors.success",
|
|
27
29
|
color: "colors.white",
|
|
30
|
+
borderColor: "colors.success",
|
|
28
31
|
hovered: {
|
|
29
32
|
background: "colors.successDark",
|
|
30
|
-
color: "colors.white"
|
|
33
|
+
color: "colors.white",
|
|
34
|
+
borderColor: "colors.successDark"
|
|
35
|
+
},
|
|
36
|
+
focused: {
|
|
37
|
+
outline: "colors.successDarker"
|
|
31
38
|
}
|
|
32
39
|
},
|
|
33
40
|
successAlternate: {
|
|
34
41
|
background: "colors.greyLightest",
|
|
35
42
|
color: "colors.success",
|
|
43
|
+
borderColor: "colors.greyLightest",
|
|
36
44
|
hovered: {
|
|
37
45
|
background: "colors.greyLighter",
|
|
38
|
-
color: "colors.success"
|
|
46
|
+
color: "colors.success",
|
|
47
|
+
borderColor: "colors.greyLighter"
|
|
48
|
+
},
|
|
49
|
+
focused: {
|
|
50
|
+
outline: "colors.successLight"
|
|
39
51
|
}
|
|
40
52
|
},
|
|
41
53
|
danger: {
|
|
42
54
|
background: "colors.danger",
|
|
43
55
|
color: "colors.white",
|
|
56
|
+
borderColor: "colors.danger",
|
|
44
57
|
hovered: {
|
|
45
58
|
background: "colors.dangerDark",
|
|
46
|
-
color: "colors.white"
|
|
59
|
+
color: "colors.white",
|
|
60
|
+
borderColor: "colors.dangerDark"
|
|
61
|
+
},
|
|
62
|
+
focused: {
|
|
63
|
+
outline: "colors.dangerDarker"
|
|
47
64
|
}
|
|
48
65
|
},
|
|
49
66
|
dangerAlternate: {
|
|
50
67
|
background: "colors.greyLightest",
|
|
51
68
|
color: "colors.danger",
|
|
69
|
+
borderColor: "colors.greyLightest",
|
|
52
70
|
hovered: {
|
|
53
71
|
background: "colors.greyLighter",
|
|
54
|
-
color: "colors.danger"
|
|
72
|
+
color: "colors.danger",
|
|
73
|
+
borderColor: "colors.greyLighter"
|
|
74
|
+
},
|
|
75
|
+
focused: {
|
|
76
|
+
outline: "colors.dangerLight"
|
|
55
77
|
}
|
|
56
78
|
},
|
|
57
79
|
disabled: {
|
|
58
80
|
background: "colors.greyLighter",
|
|
59
81
|
color: "colors.grey",
|
|
82
|
+
borderColor: "colors.greyLighter",
|
|
60
83
|
hovered: {
|
|
61
84
|
background: "colors.greyLighter",
|
|
62
|
-
color: "colors.grey"
|
|
85
|
+
color: "colors.grey",
|
|
86
|
+
borderColor: "colors.greyLighter"
|
|
63
87
|
}
|
|
64
88
|
},
|
|
65
89
|
ghost: {
|
|
66
90
|
background: "colors.primaryLightest",
|
|
67
91
|
color: "colors.primaryDark",
|
|
92
|
+
borderColor: "colors.primaryLightest",
|
|
68
93
|
hovered: {
|
|
69
94
|
background: "colors.primaryLighter",
|
|
70
|
-
color: "colors.primaryDarker"
|
|
95
|
+
color: "colors.primaryDarker",
|
|
96
|
+
borderColor: "colors.primaryLighter"
|
|
97
|
+
},
|
|
98
|
+
focused: {
|
|
99
|
+
outline: "colors.primaryLight"
|
|
71
100
|
}
|
|
72
101
|
}
|
|
73
102
|
};
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
bg: themeGet(VARIANT_COLORS[key].background)(props),
|
|
78
|
-
color: themeGet(VARIANT_COLORS[key].color)(props),
|
|
79
|
-
"&:hover": _objectSpread(_objectSpread({}, variant["&:hover"] || {}), {}, {
|
|
80
|
-
bg: themeGet(VARIANT_COLORS[key].hovered.background)(props),
|
|
81
|
-
color: themeGet(VARIANT_COLORS[key].hovered.color)(props)
|
|
82
|
-
})
|
|
103
|
+
var getOutlineStyle = function getOutlineStyle(color) {
|
|
104
|
+
return css(["outline:0;box-shadow:", ";"], function (props) {
|
|
105
|
+
return [themeGet("shadows.thinOutline")(props), themeGet(color)(props)].join(" ");
|
|
83
106
|
});
|
|
84
107
|
};
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
108
|
+
var addVariantColors = function addVariantColors(key) {
|
|
109
|
+
var variantStyle = VARIANT_COLORS[key];
|
|
110
|
+
return css(["background:", ";color:", ";border-color:", ";&:hover{background:", ";color:", ";border-color:", ";}", ""], themeGet(variantStyle.background), themeGet(variantStyle.color), themeGet(variantStyle.borderColor), themeGet(variantStyle.hovered.background), themeGet(variantStyle.hovered.color), themeGet(variantStyle.hovered.borderColor), variantStyle.focused && css(["&:focus{", "}"], getOutlineStyle(variantStyle.focused.outline)));
|
|
111
|
+
};
|
|
112
|
+
var getVariantStyle = function getVariantStyle(props) {
|
|
113
|
+
var styles = Object.keys(VARIANT_COLORS).reduce(function (obj, key) {
|
|
114
|
+
obj[key] = css(["", ""], addVariantColors(key));
|
|
115
|
+
return obj;
|
|
116
|
+
}, {});
|
|
117
|
+
if (props.disabled) return styles.disabled;
|
|
118
|
+
return styles[props.variant] || styles["default"];
|
|
119
|
+
};
|
|
120
|
+
var getSpace = function getSpace(getter) {
|
|
121
|
+
return function (props) {
|
|
122
|
+
return themeGet("space.".concat(getter(props)))(props);
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
var buttonStyles = css(["background:", ";color:", ";border-color:", ";display:flex;align-items:center;justify-content:center;appearance:none;box-shadow:none;margin:0;text-decoration:none;text-align:center;font-family:", ";font-weight:", ";border-radius:", ";transition:", ";border-width:", ";cursor:", ";width:", ";height:auto;font-size:", ";padding:", " ", ";svg{margin-right:", ";margin-left:", ";}&:hover{background:", ";border-color:", ";border-width:", ";border-style:solid;}&:focus{outline:0;box-shadow:", " ", ";}", " ", ""], themeGet(VARIANT_COLORS["default"].background), themeGet(VARIANT_COLORS["default"].color), themeGet("colors.primary"), themeGet("fonts.main"), themeGet("fontWeights.2"), themeGet("radii.2"), themeGet("transition.transitionDefault"), themeGet("borderWidths.1"), function (props) {
|
|
126
|
+
return props.disabled ? "not-allowed" : props.isLoading ? "progress" : "pointer";
|
|
127
|
+
}, function (props) {
|
|
128
|
+
return props.fullWidth ? "100%" : "auto";
|
|
129
|
+
}, function (props) {
|
|
130
|
+
var fontSize = 2;
|
|
131
|
+
if (props.large && props.iconOnly) fontSize = 5;
|
|
132
|
+
if (props.large) fontSize = 3;
|
|
133
|
+
if (props.small) fontSize = 1;
|
|
134
|
+
return themeGet("fontSizes.".concat(fontSize))(props);
|
|
135
|
+
}, getSpace(function (props) {
|
|
136
|
+
return props.large ? "s" : props.small ? "xxs" : "xs";
|
|
137
|
+
}), getSpace(function (props) {
|
|
138
|
+
return props.large ? "r" : props.small ? "s" : "between";
|
|
139
|
+
}), getSpace(function (props) {
|
|
140
|
+
return !props.iconLeft ? "" : props.small ? "xs" : "s";
|
|
141
|
+
}), getSpace(function (props) {
|
|
142
|
+
return !props.iconRight ? "" : props.small ? "xs" : "s";
|
|
143
|
+
}), themeGet(VARIANT_COLORS["default"].hovered.background), themeGet("colors.primaryDark"), themeGet("borderWidths.1"), themeGet("shadows.thinOutline"), themeGet("colors.primaryDarker"), getVariantStyle, compose(space, layout, color, border));
|
|
144
|
+
var attrs = function attrs(props) {
|
|
90
145
|
return {
|
|
91
146
|
"data-testid": props.dataTestId || props["data-testid"],
|
|
92
147
|
disabled: props.disabled || props.variant == "disabled",
|
|
93
148
|
className: "".concat(props.className || "", " variant-").concat(props.variant || "default")
|
|
94
149
|
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
boxShadow: "none",
|
|
105
|
-
margin: "0",
|
|
106
|
-
textDecoration: "none",
|
|
107
|
-
textAlign: "center",
|
|
108
|
-
verticalAlign: "center",
|
|
109
|
-
fontFamily: themeGet("fonts.main")(props),
|
|
110
|
-
fontWeight: themeGet("fontWeights.2")(props),
|
|
111
|
-
borderRadius: themeGet("radii.2")(props),
|
|
112
|
-
transition: themeGet("transition.transitionDefault")(props),
|
|
113
|
-
borderWidth: themeGet("borderWidths.1")(props),
|
|
114
|
-
cursor: props.disabled ? "not-allowed" : props.isLoading ? "progress" : "pointer",
|
|
115
|
-
width: props.fullWidth ? "100%" : "auto",
|
|
116
|
-
height: "auto",
|
|
117
|
-
fontSize: props.small ? themeGet("fontSizes.1")(props) : props.large && props.iconOnly ? themeGet("fontSizes.5")(props) : props.large ? themeGet("fontSizes.3")(props) : themeGet("fontSizes.2")(props),
|
|
118
|
-
py: props.large ? "s" : props.small ? "xxs" : "xs",
|
|
119
|
-
px: props.large ? "r" : props.small ? "s" : "between",
|
|
120
|
-
svg: {
|
|
121
|
-
marginRight: !props.iconLeft ? "" : props.small ? "xs" : "s",
|
|
122
|
-
marginLeft: !props.iconRight ? "" : props.small ? "xs" : "s"
|
|
123
|
-
},
|
|
124
|
-
"&:hover": {
|
|
125
|
-
bg: themeGet(VARIANT_COLORS["default"].hovered.background)(props),
|
|
126
|
-
borderColor: themeGet("colors.primaryDark")(props),
|
|
127
|
-
borderWidth: themeGet("borderWidths.1")(props),
|
|
128
|
-
borderStyle: "solid"
|
|
129
|
-
},
|
|
130
|
-
"&:focus": {
|
|
131
|
-
outline: "0",
|
|
132
|
-
boxShadow: themeGet("shadows.thinOutline")(props) + " " + themeGet("colors.primaryDarker")(props)
|
|
133
|
-
}
|
|
134
|
-
});
|
|
150
|
+
};
|
|
151
|
+
var StyledButton = styled("button").withConfig({
|
|
152
|
+
shouldForwardProp: shouldForwardProp
|
|
153
|
+
}).attrs(attrs).withConfig({
|
|
154
|
+
displayName: "Button__StyledButton",
|
|
155
|
+
componentId: "sc-10uojnk-0"
|
|
156
|
+
})(["", ""], buttonStyles);
|
|
157
|
+
var linkStyles = css(["width:", ";display:", ";align-items:", ";"], function (props) {
|
|
158
|
+
return props.width || "fit-content";
|
|
135
159
|
}, function (props) {
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
outline: "0",
|
|
139
|
-
boxShadow: [themeGet("shadows.thinOutline")(props), themeGet(color)(props)].join(" ")
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
var variants = {
|
|
143
|
-
"default": {},
|
|
144
|
-
success: {
|
|
145
|
-
borderColor: themeGet("colors.success")(props),
|
|
146
|
-
"&:hover": {
|
|
147
|
-
borderColor: themeGet("colors.successDark")(props)
|
|
148
|
-
},
|
|
149
|
-
"&:focus": getOutlineStyle("colors.successDarker")
|
|
150
|
-
},
|
|
151
|
-
successAlternate: {
|
|
152
|
-
borderColor: themeGet("colors.greyLightest")(props),
|
|
153
|
-
"&:hover": {
|
|
154
|
-
borderColor: themeGet("colors.greyLighter")(props)
|
|
155
|
-
},
|
|
156
|
-
"&:focus": getOutlineStyle("colors.successLight")
|
|
157
|
-
},
|
|
158
|
-
danger: {
|
|
159
|
-
borderColor: themeGet("colors.danger")(props),
|
|
160
|
-
"&:hover": {
|
|
161
|
-
borderColor: themeGet("colors.dangerDark")(props)
|
|
162
|
-
},
|
|
163
|
-
"&:focus": getOutlineStyle("colors.dangerDarker")
|
|
164
|
-
},
|
|
165
|
-
dangerAlternate: {
|
|
166
|
-
borderColor: themeGet("colors.greyLightest")(props),
|
|
167
|
-
"&:hover": {
|
|
168
|
-
borderColor: themeGet("colors.greyLighter")(props)
|
|
169
|
-
},
|
|
170
|
-
"&:focus": getOutlineStyle("colors.dangerLight")
|
|
171
|
-
},
|
|
172
|
-
disabled: {
|
|
173
|
-
borderColor: themeGet("colors.greyLighter")(props),
|
|
174
|
-
"&:hover": {
|
|
175
|
-
borderColor: themeGet("colors.greyLighter")(props)
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
ghost: {
|
|
179
|
-
borderColor: themeGet("colors.primaryLightest")(props),
|
|
180
|
-
"&:hover": {
|
|
181
|
-
borderColor: themeGet("colors.primaryLighter")(props)
|
|
182
|
-
},
|
|
183
|
-
"&:focus": getOutlineStyle("colors.primaryLight")
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
var newVariants = Object.entries(variants).reduce(function (variantsWithColors, _ref) {
|
|
187
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
188
|
-
key = _ref2[0],
|
|
189
|
-
variant = _ref2[1];
|
|
190
|
-
if (VARIANT_COLORS[key]) {
|
|
191
|
-
variantsWithColors[key] = addVariantColors(variant, key, props);
|
|
192
|
-
}
|
|
193
|
-
return variantsWithColors;
|
|
194
|
-
}, _objectSpread({}, variants));
|
|
195
|
-
return variant({
|
|
196
|
-
variants: newVariants
|
|
197
|
-
});
|
|
160
|
+
return props.height || props.width ? "flex" : props.display || "inline-block";
|
|
198
161
|
}, function (props) {
|
|
199
|
-
return props.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
162
|
+
return props.alignItems || "center";
|
|
163
|
+
});
|
|
164
|
+
var StyledButtonLink = styled.a.withConfig({
|
|
165
|
+
shouldForwardProp: shouldForwardProp
|
|
166
|
+
}).attrs(attrs).withConfig({
|
|
167
|
+
displayName: "Button__StyledButtonLink",
|
|
168
|
+
componentId: "sc-10uojnk-1"
|
|
169
|
+
})(["", " ", ""], buttonStyles, linkStyles);
|
|
170
|
+
var StyledReactButtonLink = styled(Link).withConfig({
|
|
171
|
+
shouldForwardProp: shouldForwardProp
|
|
172
|
+
}).attrs(attrs).withConfig({
|
|
173
|
+
displayName: "Button__StyledReactButtonLink",
|
|
174
|
+
componentId: "sc-10uojnk-2"
|
|
175
|
+
})(["", " ", ""], buttonStyles, linkStyles);
|
|
176
|
+
var buttonPropTypes = {
|
|
177
|
+
/** Large button */
|
|
178
|
+
large: PropTypes.bool,
|
|
179
|
+
/** Small button */
|
|
180
|
+
small: PropTypes.bool,
|
|
181
|
+
/** Specifies alternate button colours/styles. */
|
|
182
|
+
variant: PropTypes.oneOf(["success", "successAlternate", "danger", "dangerAlternate", "ghost", "disabled", "default"]),
|
|
183
|
+
/** Full width button that takes up all available space of parent */
|
|
184
|
+
fullWidth: PropTypes.bool,
|
|
185
|
+
/** Adds a spinner animation to indicate loading or processing */
|
|
186
|
+
isLoading: PropTypes.bool,
|
|
187
|
+
/** Styles button to fit an icon on the left of text. Uses Icon component. */
|
|
188
|
+
iconLeft: PropTypes.bool,
|
|
189
|
+
/** Styles button to fit an icon on the right of text. Uses Icon component. */
|
|
190
|
+
iconRight: PropTypes.bool,
|
|
191
|
+
/** New functionality to specify an `Icon` on the left side without having to include it as a child. */
|
|
192
|
+
leftIcon: PropTypes.array,
|
|
193
|
+
/** New functionality to specify an `Icon` on the right side without having to include it as a child. */
|
|
194
|
+
rightIcon: PropTypes.array,
|
|
195
|
+
/** Styles button to suit having only an icon. Uses Icon component. */
|
|
196
|
+
iconOnly: PropTypes.bool,
|
|
197
|
+
/** Specifies whether the button is disabled. */
|
|
198
|
+
disabled: PropTypes.bool,
|
|
199
|
+
/** The text label on the button is passed as a child. Keep this text short and descriptive. Use an action word or confirmation if possible. */
|
|
200
|
+
children: PropTypes.node,
|
|
201
|
+
/** Adds additional styling to the rendered `<button>` using `space`, `layout`, `color` and `border` prop categories */
|
|
202
|
+
ButtonStyles: PropTypes.object,
|
|
203
|
+
/** Specifies the `data-testid` attribute for testing. */
|
|
204
|
+
dataTestId: PropTypes.string,
|
|
205
|
+
/** Specifies aria-label for iconOnly buttons. This is only required if the iconOnly button is used, as it doesn't have supporting text for accessibility.*/
|
|
206
|
+
ariaLabel: function ariaLabel(props, propName) {
|
|
207
|
+
if (props.iconOnly && (props[propName] == null || props[propName] === "")) {
|
|
208
|
+
return new Error("Missing prop `".concat(propName, "` not specified for Button component. When `iconOnly` is true, `").concat(propName, "` is required."));
|
|
203
209
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
large: large,
|
|
225
|
-
small: small,
|
|
226
|
-
fullWidth: fullWidth,
|
|
227
|
-
isLoading: isLoading,
|
|
228
|
-
leftIcon: leftIcon,
|
|
229
|
-
rightIcon: rightIcon,
|
|
230
|
-
iconLeft: iconLeft,
|
|
231
|
-
iconRight: iconRight,
|
|
232
|
-
iconOnly: iconOnly,
|
|
233
|
-
dataTestId: dataTestId,
|
|
234
|
-
borderStyle: "solid",
|
|
235
|
-
disabled: disabled,
|
|
236
|
-
onClick: onClick,
|
|
237
|
-
ref: ref,
|
|
238
|
-
"aria-label": ariaLabel
|
|
239
|
-
}, ButtonStyles, props), leftIcon && /*#__PURE__*/React.createElement(Icon, {
|
|
240
|
-
icon: leftIcon,
|
|
241
|
-
mr: small ? "xxs" : "xs"
|
|
242
|
-
}), children, rightIcon && /*#__PURE__*/React.createElement(Icon, {
|
|
243
|
-
icon: rightIcon,
|
|
244
|
-
ml: small ? "xxs" : "xs"
|
|
245
|
-
}), isLoading && /*#__PURE__*/React.createElement(Loading, {
|
|
210
|
+
if (props[propName] && typeof props[propName] !== "string") {
|
|
211
|
+
return new Error("Invalid propType for `".concat(propName, "` supplied to Button component. Expected `string`, received `").concat(_typeof(props[propName]), "`."));
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
},
|
|
215
|
+
/** Specifies the color theme object. */
|
|
216
|
+
theme: PropTypes.object
|
|
217
|
+
};
|
|
218
|
+
var renderButton = function renderButton(ButtonComponent, props) {
|
|
219
|
+
return /*#__PURE__*/React.createElement(ButtonComponent, _extends({
|
|
220
|
+
borderStyle: "solid"
|
|
221
|
+
}, props.ButtonStyles, props, {
|
|
222
|
+
ref: props.ref
|
|
223
|
+
}), props.leftIcon && /*#__PURE__*/React.createElement(Icon, {
|
|
224
|
+
icon: props.leftIcon,
|
|
225
|
+
mr: props.small ? "xxs" : "xs"
|
|
226
|
+
}), props.children, props.rightIcon && /*#__PURE__*/React.createElement(Icon, {
|
|
227
|
+
icon: props.rightIcon,
|
|
228
|
+
ml: props.small ? "xxs" : "xs"
|
|
229
|
+
}), props.isLoading && /*#__PURE__*/React.createElement(Loading, {
|
|
246
230
|
inverted: true,
|
|
247
231
|
ml: "s"
|
|
248
232
|
}));
|
|
233
|
+
};
|
|
234
|
+
export var ButtonLink = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
235
|
+
var theme = props.theme;
|
|
236
|
+
var component = renderButton(props.to ? StyledReactButtonLink : StyledButtonLink, _objectSpread(_objectSpread({}, omit(props, "isLoading")), {}, {
|
|
237
|
+
ref: ref
|
|
238
|
+
}));
|
|
239
|
+
return theme ? /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
240
|
+
theme: theme
|
|
241
|
+
}, component) : component;
|
|
242
|
+
});
|
|
243
|
+
ButtonLink.propTypes = _objectSpread(_objectSpread({}, buttonPropTypes), {}, {
|
|
244
|
+
target: PropTypes.string,
|
|
245
|
+
/** Link to navigate user to */
|
|
246
|
+
href: PropTypes.string
|
|
247
|
+
});
|
|
248
|
+
ButtonLink.defaultProps = {
|
|
249
|
+
variant: "default"
|
|
250
|
+
};
|
|
251
|
+
export var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
252
|
+
var theme = props.theme;
|
|
253
|
+
var component = renderButton(StyledButton, _objectSpread(_objectSpread({}, props), {}, {
|
|
254
|
+
ref: ref
|
|
255
|
+
}));
|
|
249
256
|
return theme ? /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
250
257
|
theme: theme
|
|
251
258
|
}, component) : component;
|
|
@@ -358,12 +365,166 @@ Button.__docgenInfo = {
|
|
|
358
365
|
},
|
|
359
366
|
"required": false
|
|
360
367
|
},
|
|
368
|
+
"children": {
|
|
369
|
+
"description": "The text label on the button is passed as a child. Keep this text short and descriptive. Use an action word or confirmation if possible.",
|
|
370
|
+
"type": {
|
|
371
|
+
"name": "node"
|
|
372
|
+
},
|
|
373
|
+
"required": false
|
|
374
|
+
},
|
|
375
|
+
"ButtonStyles": {
|
|
376
|
+
"description": "Adds additional styling to the rendered `<button>` using `space`, `layout`, `color` and `border` prop categories",
|
|
377
|
+
"type": {
|
|
378
|
+
"name": "object"
|
|
379
|
+
},
|
|
380
|
+
"required": false
|
|
381
|
+
},
|
|
382
|
+
"dataTestId": {
|
|
383
|
+
"description": "Specifies the `data-testid` attribute for testing.",
|
|
384
|
+
"type": {
|
|
385
|
+
"name": "string"
|
|
386
|
+
},
|
|
387
|
+
"required": false
|
|
388
|
+
},
|
|
389
|
+
"ariaLabel": {
|
|
390
|
+
"description": "Specifies aria-label for iconOnly buttons. This is only required if the iconOnly button is used, as it doesn't have supporting text for accessibility.",
|
|
391
|
+
"type": {
|
|
392
|
+
"name": "custom",
|
|
393
|
+
"raw": "(props, propName) => {\n if (props.iconOnly && (props[propName] == null || props[propName] === \"\")) {\n return new Error(\n `Missing prop \\`${propName}\\` not specified for Button component. When \\`iconOnly\\` is true, \\`${propName}\\` is required.`\n );\n }\n if (props[propName] && typeof props[propName] !== \"string\") {\n return new Error(\n `Invalid propType for \\`${propName}\\` supplied to Button component. Expected \\`string\\`, received \\`${typeof props[\n propName\n ]}\\`.`\n );\n }\n return null;\n}"
|
|
394
|
+
},
|
|
395
|
+
"required": false
|
|
396
|
+
},
|
|
397
|
+
"theme": {
|
|
398
|
+
"description": "Specifies the color theme object.",
|
|
399
|
+
"type": {
|
|
400
|
+
"name": "object"
|
|
401
|
+
},
|
|
402
|
+
"required": false
|
|
403
|
+
},
|
|
361
404
|
"onClick": {
|
|
362
405
|
"description": "Function to run when the `Button` is clicked",
|
|
363
406
|
"type": {
|
|
364
407
|
"name": "func"
|
|
365
408
|
},
|
|
366
409
|
"required": false
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
export default Button;
|
|
414
|
+
Button.propTypes = _objectSpread(_objectSpread({}, buttonPropTypes), {}, {
|
|
415
|
+
/** Function to run when the `Button` is clicked */
|
|
416
|
+
onClick: PropTypes.func
|
|
417
|
+
});
|
|
418
|
+
Button.defaultProps = {
|
|
419
|
+
variant: "default"
|
|
420
|
+
};
|
|
421
|
+
ButtonLink.__docgenInfo = {
|
|
422
|
+
"description": "",
|
|
423
|
+
"methods": [],
|
|
424
|
+
"displayName": "ButtonLink",
|
|
425
|
+
"props": {
|
|
426
|
+
"variant": {
|
|
427
|
+
"defaultValue": {
|
|
428
|
+
"value": "\"default\"",
|
|
429
|
+
"computed": false
|
|
430
|
+
},
|
|
431
|
+
"description": "Specifies alternate button colours/styles.",
|
|
432
|
+
"type": {
|
|
433
|
+
"name": "enum",
|
|
434
|
+
"value": [{
|
|
435
|
+
"value": "\"success\"",
|
|
436
|
+
"computed": false
|
|
437
|
+
}, {
|
|
438
|
+
"value": "\"successAlternate\"",
|
|
439
|
+
"computed": false
|
|
440
|
+
}, {
|
|
441
|
+
"value": "\"danger\"",
|
|
442
|
+
"computed": false
|
|
443
|
+
}, {
|
|
444
|
+
"value": "\"dangerAlternate\"",
|
|
445
|
+
"computed": false
|
|
446
|
+
}, {
|
|
447
|
+
"value": "\"ghost\"",
|
|
448
|
+
"computed": false
|
|
449
|
+
}, {
|
|
450
|
+
"value": "\"disabled\"",
|
|
451
|
+
"computed": false
|
|
452
|
+
}, {
|
|
453
|
+
"value": "\"default\"",
|
|
454
|
+
"computed": false
|
|
455
|
+
}]
|
|
456
|
+
},
|
|
457
|
+
"required": false
|
|
458
|
+
},
|
|
459
|
+
"large": {
|
|
460
|
+
"description": "Large button",
|
|
461
|
+
"type": {
|
|
462
|
+
"name": "bool"
|
|
463
|
+
},
|
|
464
|
+
"required": false
|
|
465
|
+
},
|
|
466
|
+
"small": {
|
|
467
|
+
"description": "Small button",
|
|
468
|
+
"type": {
|
|
469
|
+
"name": "bool"
|
|
470
|
+
},
|
|
471
|
+
"required": false
|
|
472
|
+
},
|
|
473
|
+
"fullWidth": {
|
|
474
|
+
"description": "Full width button that takes up all available space of parent",
|
|
475
|
+
"type": {
|
|
476
|
+
"name": "bool"
|
|
477
|
+
},
|
|
478
|
+
"required": false
|
|
479
|
+
},
|
|
480
|
+
"isLoading": {
|
|
481
|
+
"description": "Adds a spinner animation to indicate loading or processing",
|
|
482
|
+
"type": {
|
|
483
|
+
"name": "bool"
|
|
484
|
+
},
|
|
485
|
+
"required": false
|
|
486
|
+
},
|
|
487
|
+
"iconLeft": {
|
|
488
|
+
"description": "Styles button to fit an icon on the left of text. Uses Icon component.",
|
|
489
|
+
"type": {
|
|
490
|
+
"name": "bool"
|
|
491
|
+
},
|
|
492
|
+
"required": false
|
|
493
|
+
},
|
|
494
|
+
"iconRight": {
|
|
495
|
+
"description": "Styles button to fit an icon on the right of text. Uses Icon component.",
|
|
496
|
+
"type": {
|
|
497
|
+
"name": "bool"
|
|
498
|
+
},
|
|
499
|
+
"required": false
|
|
500
|
+
},
|
|
501
|
+
"leftIcon": {
|
|
502
|
+
"description": "New functionality to specify an `Icon` on the left side without having to include it as a child.",
|
|
503
|
+
"type": {
|
|
504
|
+
"name": "array"
|
|
505
|
+
},
|
|
506
|
+
"required": false
|
|
507
|
+
},
|
|
508
|
+
"rightIcon": {
|
|
509
|
+
"description": "New functionality to specify an `Icon` on the right side without having to include it as a child.",
|
|
510
|
+
"type": {
|
|
511
|
+
"name": "array"
|
|
512
|
+
},
|
|
513
|
+
"required": false
|
|
514
|
+
},
|
|
515
|
+
"iconOnly": {
|
|
516
|
+
"description": "Styles button to suit having only an icon. Uses Icon component.",
|
|
517
|
+
"type": {
|
|
518
|
+
"name": "bool"
|
|
519
|
+
},
|
|
520
|
+
"required": false
|
|
521
|
+
},
|
|
522
|
+
"disabled": {
|
|
523
|
+
"description": "Specifies whether the button is disabled.",
|
|
524
|
+
"type": {
|
|
525
|
+
"name": "bool"
|
|
526
|
+
},
|
|
527
|
+
"required": false
|
|
367
528
|
},
|
|
368
529
|
"children": {
|
|
369
530
|
"description": "The text label on the button is passed as a child. Keep this text short and descriptive. Use an action word or confirmation if possible.",
|
|
@@ -400,54 +561,20 @@ Button.__docgenInfo = {
|
|
|
400
561
|
"name": "object"
|
|
401
562
|
},
|
|
402
563
|
"required": false
|
|
564
|
+
},
|
|
565
|
+
"target": {
|
|
566
|
+
"description": "",
|
|
567
|
+
"type": {
|
|
568
|
+
"name": "string"
|
|
569
|
+
},
|
|
570
|
+
"required": false
|
|
571
|
+
},
|
|
572
|
+
"href": {
|
|
573
|
+
"description": "Link to navigate user to",
|
|
574
|
+
"type": {
|
|
575
|
+
"name": "string"
|
|
576
|
+
},
|
|
577
|
+
"required": false
|
|
403
578
|
}
|
|
404
579
|
}
|
|
405
|
-
};
|
|
406
|
-
export default Button;
|
|
407
|
-
Button.propTypes = {
|
|
408
|
-
/** Large button */
|
|
409
|
-
large: PropTypes.bool,
|
|
410
|
-
/** Small button */
|
|
411
|
-
small: PropTypes.bool,
|
|
412
|
-
/** Specifies alternate button colours/styles. */
|
|
413
|
-
variant: PropTypes.oneOf(["success", "successAlternate", "danger", "dangerAlternate", "ghost", "disabled", "default"]),
|
|
414
|
-
/** Full width button that takes up all available space of parent */
|
|
415
|
-
fullWidth: PropTypes.bool,
|
|
416
|
-
/** Adds a spinner animation to indicate loading or processing */
|
|
417
|
-
isLoading: PropTypes.bool,
|
|
418
|
-
/** Styles button to fit an icon on the left of text. Uses Icon component. */
|
|
419
|
-
iconLeft: PropTypes.bool,
|
|
420
|
-
/** Styles button to fit an icon on the right of text. Uses Icon component. */
|
|
421
|
-
iconRight: PropTypes.bool,
|
|
422
|
-
/** New functionality to specify an `Icon` on the left side without having to include it as a child. */
|
|
423
|
-
leftIcon: PropTypes.array,
|
|
424
|
-
/** New functionality to specify an `Icon` on the right side without having to include it as a child. */
|
|
425
|
-
rightIcon: PropTypes.array,
|
|
426
|
-
/** Styles button to suit having only an icon. Uses Icon component. */
|
|
427
|
-
iconOnly: PropTypes.bool,
|
|
428
|
-
/** Specifies whether the button is disabled. */
|
|
429
|
-
disabled: PropTypes.bool,
|
|
430
|
-
/** Function to run when the `Button` is clicked */
|
|
431
|
-
onClick: PropTypes.func,
|
|
432
|
-
/** The text label on the button is passed as a child. Keep this text short and descriptive. Use an action word or confirmation if possible. */
|
|
433
|
-
children: PropTypes.node,
|
|
434
|
-
/** Adds additional styling to the rendered `<button>` using `space`, `layout`, `color` and `border` prop categories */
|
|
435
|
-
ButtonStyles: PropTypes.object,
|
|
436
|
-
/** Specifies the `data-testid` attribute for testing. */
|
|
437
|
-
dataTestId: PropTypes.string,
|
|
438
|
-
/** Specifies aria-label for iconOnly buttons. This is only required if the iconOnly button is used, as it doesn't have supporting text for accessibility.*/
|
|
439
|
-
ariaLabel: function ariaLabel(props, propName) {
|
|
440
|
-
if (props.iconOnly && (props[propName] == null || props[propName] === "")) {
|
|
441
|
-
return new Error("Missing prop `".concat(propName, "` not specified for Button component. When `iconOnly` is true, `").concat(propName, "` is required."));
|
|
442
|
-
}
|
|
443
|
-
if (props[propName] && typeof props[propName] !== "string") {
|
|
444
|
-
return new Error("Invalid propType for `".concat(propName, "` supplied to Button component. Expected `string`, received `").concat(_typeof(props[propName]), "`."));
|
|
445
|
-
}
|
|
446
|
-
return null;
|
|
447
|
-
},
|
|
448
|
-
/** Specifies the color theme object. */
|
|
449
|
-
theme: PropTypes.object
|
|
450
|
-
};
|
|
451
|
-
Button.defaultProps = {
|
|
452
|
-
variant: "default"
|
|
453
580
|
};
|
|
@@ -3,7 +3,7 @@ import StyledLink from ".";
|
|
|
3
3
|
import Box from "../Box";
|
|
4
4
|
import Flex from "../Flex";
|
|
5
5
|
import Spacer from "../Spacer";
|
|
6
|
-
import { BrowserRouter } from "react-router-dom";
|
|
6
|
+
import { BrowserRouter, Route, Switch } from "react-router-dom";
|
|
7
7
|
export default {
|
|
8
8
|
title: "Components/StyledLink",
|
|
9
9
|
component: StyledLink,
|
|
@@ -56,10 +56,34 @@ export var invertedStyledLink = function invertedStyledLink() {
|
|
|
56
56
|
}, "Bold inverted link"))));
|
|
57
57
|
};
|
|
58
58
|
invertedStyledLink.storyName = "Inverted";
|
|
59
|
+
var routes = [{
|
|
60
|
+
path: "/",
|
|
61
|
+
label: "React link to home",
|
|
62
|
+
exact: true
|
|
63
|
+
}, {
|
|
64
|
+
path: "/about",
|
|
65
|
+
label: "React link to about"
|
|
66
|
+
}, {
|
|
67
|
+
path: "/cats",
|
|
68
|
+
label: "React link to cats"
|
|
69
|
+
}];
|
|
59
70
|
export var reactLink = function reactLink() {
|
|
60
|
-
return /*#__PURE__*/React.createElement(BrowserRouter, null,
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
return /*#__PURE__*/React.createElement(BrowserRouter, null, routes.map(function (route) {
|
|
72
|
+
return /*#__PURE__*/React.createElement(StyledLink, {
|
|
73
|
+
key: route.path,
|
|
74
|
+
to: route.path
|
|
75
|
+
}, route.label);
|
|
76
|
+
}), /*#__PURE__*/React.createElement(Switch, null, routes.map(function (route) {
|
|
77
|
+
return /*#__PURE__*/React.createElement(Route, {
|
|
78
|
+
key: route.path,
|
|
79
|
+
path: route.path,
|
|
80
|
+
exact: route.exact
|
|
81
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
style: {
|
|
83
|
+
padding: "100px"
|
|
84
|
+
}
|
|
85
|
+
}, "ROUTE RENDERED: ", route.label));
|
|
86
|
+
})));
|
|
63
87
|
};
|
|
64
88
|
reactLink.storyName = "Using react-router-dom";
|
|
65
89
|
export var buttonLink = function buttonLink() {
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["children", "
|
|
3
|
+
var _excluded = ["children", "to", "button"];
|
|
4
4
|
import React from "react";
|
|
5
5
|
import PropTypes from "prop-types";
|
|
6
6
|
import shouldForwardProp from "@styled-system/should-forward-prop";
|
|
7
7
|
import styled from "styled-components";
|
|
8
8
|
import { Link } from "react-router-dom";
|
|
9
|
-
import { space, layout,
|
|
9
|
+
import { space, layout, typography } from "styled-system";
|
|
10
10
|
import { css } from "@styled-system/css";
|
|
11
11
|
import { themeGet } from "@styled-system/theme-get";
|
|
12
|
+
import { ButtonLink } from "../Button";
|
|
12
13
|
var styleLink = function styleLink(LinkComponent) {
|
|
13
14
|
return styled(LinkComponent).withConfig({
|
|
14
15
|
shouldForwardProp: shouldForwardProp,
|
|
@@ -42,115 +43,11 @@ var styleLink = function styleLink(LinkComponent) {
|
|
|
42
43
|
});
|
|
43
44
|
}, space, layout, typography);
|
|
44
45
|
};
|
|
45
|
-
var styleButtonLink = function styleButtonLink(LinkComponent) {
|
|
46
|
-
return styled(LinkComponent).withConfig({
|
|
47
|
-
shouldForwardProp: shouldForwardProp,
|
|
48
|
-
displayName: "StyledLink",
|
|
49
|
-
componentId: "sc-1beg6q3-1"
|
|
50
|
-
}).attrs(function (props) {
|
|
51
|
-
return {
|
|
52
|
-
className: "StyledLink",
|
|
53
|
-
to: props.to,
|
|
54
|
-
target: props.target,
|
|
55
|
-
"data-testid": props.dataTestId ? props.dataTestId : props["data-testid"] ? props["data-testid"] : null,
|
|
56
|
-
disabled: props.disabled ? true : props.variant == "disabled" ? true : false
|
|
57
|
-
};
|
|
58
|
-
})(function (props) {
|
|
59
|
-
return css({
|
|
60
|
-
bg: themeGet("colors.primary")(props),
|
|
61
|
-
color: themeGet("colors.white")(props),
|
|
62
|
-
borderColor: themeGet("colors.primary")(props),
|
|
63
|
-
borderWidth: themeGet("borderWidths.1")(props),
|
|
64
|
-
width: props.fullWidth ? "100%" : "auto",
|
|
65
|
-
textAlign: "center",
|
|
66
|
-
borderStyle: "solid",
|
|
67
|
-
textDecoration: "none",
|
|
68
|
-
fontFamily: themeGet("fonts.main")(props),
|
|
69
|
-
display: "inline-block",
|
|
70
|
-
fontWeight: themeGet("fontWeights.2")(props),
|
|
71
|
-
borderRadius: themeGet("radii.2")(props),
|
|
72
|
-
transition: themeGet("transition.transitionDefault")(props),
|
|
73
|
-
cursor: props.disabled ? "not-allowed" : props.isLoading ? "progress" : "pointer",
|
|
74
|
-
height: "auto",
|
|
75
|
-
fontSize: props.small ? themeGet("fontSizes.1")(props) : props.large && props.iconOnly ? themeGet("fontSizes.5")(props) : props.large ? themeGet("fontSizes.3")(props) : themeGet("fontSizes.2")(props),
|
|
76
|
-
py: props.large ? "s" : props.small ? "xxs" : "xs",
|
|
77
|
-
px: props.large ? "r" : props.small ? "s" : "between",
|
|
78
|
-
svg: {
|
|
79
|
-
marginRight: !props.iconLeft ? "" : props.small ? "xs" : "s",
|
|
80
|
-
marginLeft: !props.iconRight ? "" : props.small ? "xs" : "s"
|
|
81
|
-
},
|
|
82
|
-
"&:hover": {
|
|
83
|
-
bg: themeGet("colors.primaryDark")(props),
|
|
84
|
-
borderColor: themeGet("colors.primaryDark")(props)
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}, function (props) {
|
|
88
|
-
return variant({
|
|
89
|
-
variants: {
|
|
90
|
-
"default": {},
|
|
91
|
-
success: {
|
|
92
|
-
bg: themeGet("colors.success")(props),
|
|
93
|
-
color: themeGet("colors.white")(props),
|
|
94
|
-
borderColor: themeGet("colors.success")(props),
|
|
95
|
-
"&:hover": {
|
|
96
|
-
bg: themeGet("colors.successDark")(props),
|
|
97
|
-
borderColor: themeGet("colors.successDark")(props)
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
danger: {
|
|
101
|
-
bg: themeGet("colors.danger")(props),
|
|
102
|
-
color: themeGet("colors.white")(props),
|
|
103
|
-
borderColor: themeGet("colors.danger")(props),
|
|
104
|
-
"&:hover": {
|
|
105
|
-
bg: themeGet("colors.dangerDark")(props),
|
|
106
|
-
borderColor: themeGet("colors.dangerDark")(props)
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
disabled: {
|
|
110
|
-
bg: themeGet("colors.greyLighter")(props),
|
|
111
|
-
color: themeGet("colors.grey")(props),
|
|
112
|
-
borderColor: themeGet("colors.greyLighter")(props),
|
|
113
|
-
"&:hover": {
|
|
114
|
-
bg: themeGet("colors.greyLighter")(props),
|
|
115
|
-
color: themeGet("colors.grey")(props),
|
|
116
|
-
borderColor: themeGet("colors.greyLighter")(props)
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
ghost: {
|
|
120
|
-
bg: themeGet("colors.primaryLightest")(props),
|
|
121
|
-
color: themeGet("colors.primary")(props),
|
|
122
|
-
borderColor: themeGet("colors.primaryLightest")(props),
|
|
123
|
-
"&:hover": {
|
|
124
|
-
bg: themeGet("colors.primaryLighter")(props),
|
|
125
|
-
borderColor: themeGet("colors.primaryLighter")(props),
|
|
126
|
-
color: themeGet("colors.primaryDark")(props)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}, function (props) {
|
|
132
|
-
return props.disabled ? css({
|
|
133
|
-
bg: themeGet("colors.greyLighter")(props),
|
|
134
|
-
color: themeGet("colors.grey")(props),
|
|
135
|
-
borderColor: themeGet("colors.greyLighter")(props),
|
|
136
|
-
"&:hover": {
|
|
137
|
-
bg: themeGet("colors.greyLighter")(props),
|
|
138
|
-
color: themeGet("colors.grey")(props),
|
|
139
|
-
borderColor: themeGet("colors.greyLighter")(props)
|
|
140
|
-
}
|
|
141
|
-
}) : css();
|
|
142
|
-
}, space, layout, typography);
|
|
143
|
-
};
|
|
144
46
|
var Hyperlink = styleLink(styled.a.withConfig({
|
|
145
47
|
displayName: "StyledLink__Hyperlink",
|
|
146
|
-
componentId: "sc-1beg6q3-
|
|
48
|
+
componentId: "sc-1beg6q3-1"
|
|
147
49
|
})([""]));
|
|
148
50
|
var ReactLink = styleLink(Link);
|
|
149
|
-
var ButtonLink = styleButtonLink(styled.a.withConfig({
|
|
150
|
-
displayName: "StyledLink__ButtonLink",
|
|
151
|
-
componentId: "sc-1beg6q3-3"
|
|
152
|
-
})([""]));
|
|
153
|
-
var ReactButtonLink = styleButtonLink(Link);
|
|
154
51
|
|
|
155
52
|
/**
|
|
156
53
|
* This `StyledLink` component supports both standard html hyperlinks and react Link components (if using react router for example).
|
|
@@ -176,49 +73,16 @@ var ReactButtonLink = styleButtonLink(Link);
|
|
|
176
73
|
*/
|
|
177
74
|
var StyledLink = function StyledLink(_ref) {
|
|
178
75
|
var children = _ref.children,
|
|
179
|
-
active = _ref.active,
|
|
180
|
-
white = _ref.white,
|
|
181
|
-
bold = _ref.bold,
|
|
182
|
-
theme = _ref.theme,
|
|
183
76
|
to = _ref.to,
|
|
184
|
-
block = _ref.block,
|
|
185
|
-
target = _ref.target,
|
|
186
77
|
button = _ref.button,
|
|
187
78
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
188
79
|
if (button) {
|
|
189
|
-
return
|
|
190
|
-
theme: theme,
|
|
191
|
-
active: active,
|
|
192
|
-
white: white,
|
|
193
|
-
bold: bold,
|
|
194
|
-
to: to,
|
|
195
|
-
target: target
|
|
196
|
-
}, props), children) : /*#__PURE__*/React.createElement(ButtonLink, _extends({
|
|
197
|
-
theme: theme,
|
|
198
|
-
active: active,
|
|
199
|
-
white: white,
|
|
200
|
-
bold: bold,
|
|
201
|
-
to: to,
|
|
202
|
-
target: target
|
|
203
|
-
}, props), children);
|
|
80
|
+
return /*#__PURE__*/React.createElement(ButtonLink, props, children);
|
|
204
81
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
bold: bold,
|
|
210
|
-
to: to,
|
|
211
|
-
block: block,
|
|
212
|
-
target: target
|
|
213
|
-
}, props), children) : /*#__PURE__*/React.createElement(Hyperlink, _extends({
|
|
214
|
-
theme: theme,
|
|
215
|
-
active: active,
|
|
216
|
-
white: white,
|
|
217
|
-
bold: bold,
|
|
218
|
-
to: to,
|
|
219
|
-
block: block,
|
|
220
|
-
target: target
|
|
221
|
-
}, props), children);
|
|
82
|
+
var LinkComponent = to ? ReactLink : Hyperlink;
|
|
83
|
+
return /*#__PURE__*/React.createElement(LinkComponent, _extends({}, props, {
|
|
84
|
+
to: to
|
|
85
|
+
}), children);
|
|
222
86
|
};
|
|
223
87
|
StyledLink.propTypes = {
|
|
224
88
|
/** The content wrapped by the link component */
|
package/es/components.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as components from ".";
|
|
2
2
|
test("all components exported", function () {
|
|
3
|
-
expect(Object.keys(components)).toMatchInlineSnapshot("\n Array [\n \"ActionsMenu\",\n \"ActionsMenuBody\",\n \"ActionsMenuHeading\",\n \"ActionsMenuItem\",\n \"Avatar\",\n \"Badge\",\n \"Box\",\n \"Button\",\n \"ButtonGroupContainer\",\n \"ButtonGroupItem\",\n \"Card\",\n \"Checkbox\",\n \"Code\",\n \"DatePicker\",\n \"Divider\",\n \"Expandable\",\n \"Flex\",\n \"FlexItem\",\n \"GlobalStyles\",\n \"Grid\",\n \"GridItem\",\n \"H1\",\n \"H2\",\n \"H3\",\n \"H4\",\n \"H5\",\n \"H6\",\n \"Header\",\n \"HeaderSimple\",\n \"Icon\",\n \"Loading\",\n \"Modal\",\n \"Notification\",\n \"P\",\n \"Popover\",\n \"ProgressBar\",\n \"Quote\",\n \"RadioButton\",\n \"Range\",\n \"Select\",\n \"SideNav\",\n \"Sidebar\",\n \"SidebarClose\",\n \"SidebarPanel\",\n \"SidebarPanels\",\n \"SidebarTab\",\n \"SidebarTabs\",\n \"Small\",\n \"Spacer\",\n \"StatusDot\",\n \"StyledLink\",\n \"SystemThemeProvider\",\n \"Tab\",\n \"Table\",\n \"TabsContainer\",\n \"Tag\",\n \"Text\",\n \"TextArea\",\n \"TextInput\",\n \"Toggle\",\n \"TreeNav\",\n \"Typography\",\n \"VARIANT_COLORS\",\n \"getOptionByValue\",\n \"styleLink\",\n \"systemThemeCollapsed\",\n \"systemtheme\",\n ]\n ");
|
|
3
|
+
expect(Object.keys(components)).toMatchInlineSnapshot("\n Array [\n \"ActionsMenu\",\n \"ActionsMenuBody\",\n \"ActionsMenuHeading\",\n \"ActionsMenuItem\",\n \"Avatar\",\n \"Badge\",\n \"Box\",\n \"Button\",\n \"ButtonGroupContainer\",\n \"ButtonGroupItem\",\n \"ButtonLink\",\n \"Card\",\n \"Checkbox\",\n \"Code\",\n \"DatePicker\",\n \"Divider\",\n \"Expandable\",\n \"Flex\",\n \"FlexItem\",\n \"GlobalStyles\",\n \"Grid\",\n \"GridItem\",\n \"H1\",\n \"H2\",\n \"H3\",\n \"H4\",\n \"H5\",\n \"H6\",\n \"Header\",\n \"HeaderSimple\",\n \"Icon\",\n \"Loading\",\n \"Modal\",\n \"Notification\",\n \"P\",\n \"Popover\",\n \"ProgressBar\",\n \"Quote\",\n \"RadioButton\",\n \"Range\",\n \"Select\",\n \"SideNav\",\n \"Sidebar\",\n \"SidebarClose\",\n \"SidebarPanel\",\n \"SidebarPanels\",\n \"SidebarTab\",\n \"SidebarTabs\",\n \"Small\",\n \"Spacer\",\n \"StatusDot\",\n \"StyledLink\",\n \"SystemThemeProvider\",\n \"Tab\",\n \"Table\",\n \"TabsContainer\",\n \"Tag\",\n \"Text\",\n \"TextArea\",\n \"TextInput\",\n \"Toggle\",\n \"TreeNav\",\n \"Typography\",\n \"VARIANT_COLORS\",\n \"getOptionByValue\",\n \"styleLink\",\n \"systemThemeCollapsed\",\n \"systemtheme\",\n ]\n ");
|
|
4
4
|
});
|
package/es/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export { default as ActionsMenu, ActionsMenuBody, ActionsMenuHeading, ActionsMen
|
|
|
11
11
|
export { default as Avatar } from "./components/Avatar";
|
|
12
12
|
export { default as Badge } from "./components/Badge";
|
|
13
13
|
export { default as Box } from "./components/Box";
|
|
14
|
-
export { default as Button, VARIANT_COLORS } from "./components/Button";
|
|
14
|
+
export { default as Button, ButtonLink, VARIANT_COLORS } from "./components/Button";
|
|
15
15
|
export { ButtonGroupContainer, ButtonGroupItem } from "./components/ButtonGroup";
|
|
16
16
|
export { default as Card } from "./components/Card";
|
|
17
17
|
export { default as Checkbox } from "./components/Checkbox";
|