@entur/button 3.3.13-beta.9 → 3.3.14

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.
@@ -1,276 +1,252 @@
1
- import { warnAboutMissingStyles } from '@entur/utils';
2
- import * as React from 'react';
3
- import React__default from 'react';
4
- import classNames from 'classnames';
5
- import { LoadingDots } from '@entur/loader';
6
-
7
- function _extends() {
8
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
9
- for (var e = 1; e < arguments.length; e++) {
10
- var t = arguments[e];
11
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
12
- }
13
- return n;
14
- }, _extends.apply(null, arguments);
15
- }
16
- function _objectWithoutPropertiesLoose(r, e) {
17
- if (null == r) return {};
18
- var t = {};
19
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
20
- if (-1 !== e.indexOf(n)) continue;
21
- t[n] = r[n];
1
+ import { warnAboutMissingStyles } from "@entur/utils";
2
+ import { jsx, Fragment } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import React__default from "react";
5
+ import classNames from "classnames";
6
+ import { LoadingDots } from "@entur/loader";
7
+ const defaultElement$9 = "button";
8
+ const Button = React.forwardRef(
9
+ ({
10
+ as,
11
+ children,
12
+ variant = "primary",
13
+ size = "medium",
14
+ loading,
15
+ className,
16
+ disabled = false,
17
+ width = "auto",
18
+ "aria-label": ariaLabel,
19
+ ...rest
20
+ }, ref) => {
21
+ const Element = as || defaultElement$9;
22
+ const childrenArray = React.Children.toArray(children);
23
+ const hasLeadingIcon = childrenArray.length > 1 && typeof childrenArray[0] !== "string";
24
+ const hasTrailingIcon = childrenArray.length > 1 && typeof childrenArray[childrenArray.length - 1] !== "string";
25
+ const ariaLabelWhenLoading = childrenArray.filter((child) => typeof child === "string").join(" ");
26
+ const ariaLabelValue = () => {
27
+ if (ariaLabel) return ariaLabel;
28
+ if (loading) return ariaLabelWhenLoading;
29
+ return void 0;
30
+ };
31
+ return /* @__PURE__ */ jsx(
32
+ Element,
33
+ {
34
+ className: classNames(
35
+ "eds-button",
36
+ {
37
+ [`eds-button--variant-${variant}`]: variant,
38
+ [`eds-button--size-${size}`]: size,
39
+ "eds-button--width-fluid": width === "fluid",
40
+ "eds-button--loading": loading,
41
+ "eds-button--leading-icon": hasLeadingIcon,
42
+ "eds-button--trailing-icon": hasTrailingIcon
43
+ },
44
+ className
45
+ ),
46
+ ref,
47
+ "aria-busy": loading,
48
+ disabled,
49
+ "aria-disabled": disabled,
50
+ "aria-label": ariaLabelValue(),
51
+ ...rest,
52
+ children: loading ? /* @__PURE__ */ jsx(LoadingDots, { className: "eds-button__loading-dots" }) : children
53
+ }
54
+ );
22
55
  }
23
- return t;
24
- }
25
-
26
- var _excluded$4 = ["as", "children", "variant", "size", "loading", "className", "disabled", "width", "aria-label"];
27
- var defaultElement$9 = 'button';
28
- var Button = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
29
- var _cx;
30
- var as = _ref.as,
31
- children = _ref.children,
32
- _ref$variant = _ref.variant,
33
- variant = _ref$variant === void 0 ? 'primary' : _ref$variant,
34
- _ref$size = _ref.size,
35
- size = _ref$size === void 0 ? 'medium' : _ref$size,
36
- loading = _ref.loading,
37
- className = _ref.className,
38
- _ref$disabled = _ref.disabled,
39
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
40
- _ref$width = _ref.width,
41
- width = _ref$width === void 0 ? 'auto' : _ref$width,
42
- ariaLabel = _ref['aria-label'],
43
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
44
- var Element = as || defaultElement$9;
45
- var childrenArray = React.Children.toArray(children);
46
- var hasLeadingIcon = childrenArray.length > 1 && typeof childrenArray[0] !== 'string';
47
- var hasTrailingIcon = childrenArray.length > 1 && typeof childrenArray[childrenArray.length - 1] !== 'string';
48
- var ariaLabelWhenLoading = childrenArray.filter(function (child) {
49
- return typeof child === 'string';
50
- }).join(' ');
51
- var ariaLabelValue = function ariaLabelValue() {
52
- if (ariaLabel) return ariaLabel;
53
- if (loading) return ariaLabelWhenLoading;
54
- return undefined;
55
- };
56
- return React.createElement(Element, _extends({
57
- className: classNames('eds-button', (_cx = {}, _cx["eds-button--variant-" + variant] = variant, _cx["eds-button--size-" + size] = size, _cx['eds-button--width-fluid'] = width === 'fluid', _cx['eds-button--loading'] = loading, _cx['eds-button--leading-icon'] = hasLeadingIcon, _cx['eds-button--trailing-icon'] = hasTrailingIcon, _cx), className),
58
- ref: ref,
59
- "aria-busy": loading,
60
- disabled: disabled,
61
- "aria-disabled": disabled,
62
- "aria-label": ariaLabelValue()
63
- }, rest), loading ? React.createElement(LoadingDots, {
64
- className: "eds-button__loading-dots"
65
- }) : children);
66
- });
67
-
68
- var defaultElement$8 = 'button';
69
- var PrimaryButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
70
- var Element = props.as || defaultElement$8;
71
- // @ts-expect-error type error due to props not being BaseButtonProps
72
- return React__default.createElement(Button, _extends({
73
- as: Element
74
- }, props, {
75
- ref: ref,
76
- variant: "primary"
77
- }));
78
- });
79
-
80
- var defaultElement$7 = 'button';
81
- var SecondaryButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
82
- var Element = props.as || defaultElement$7;
83
- // @ts-expect-error type error due to props not being BaseButtonProps
84
- return React__default.createElement(Button, _extends({
85
- as: Element
86
- }, props, {
87
- ref: ref,
88
- variant: "secondary"
89
- }));
90
- });
91
-
92
- var defaultElement$6 = 'button';
93
- var SuccessButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
94
- var Element = props.as || defaultElement$6;
95
- // @ts-expect-error type error due to props not being BaseButtonProps
96
- return React__default.createElement(Button, _extends({
97
- as: Element
98
- }, props, {
99
- ref: ref,
100
- variant: "success"
101
- }));
102
- });
103
-
104
- var defaultElement$5 = 'button';
105
- var NegativeButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
106
- var Element = props.as || defaultElement$5;
107
- // @ts-expect-error type error due to props not being BaseButtonProps
108
- return React__default.createElement(Button, _extends({
109
- as: Element
110
- }, props, {
111
- ref: ref,
112
- variant: "negative"
113
- }));
114
- });
115
-
116
- var defaultElement$4 = 'button';
117
- /** @deprecated use SecondaryButton size="small" instead */
118
- var TertiaryButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
119
- var Element = props.as || defaultElement$4;
120
- return React__default.createElement(Button, _extends({
121
- as: Element
122
- }, props, {
123
- ref: ref,
124
- variant: "tertiary",
125
- size: "small"
126
- }));
127
- });
128
-
129
- var _excluded$3 = ["as", "className"];
130
- var ButtonGroup = function ButtonGroup(_ref) {
131
- var _ref$as = _ref.as,
132
- Element = _ref$as === void 0 ? 'div' : _ref$as,
133
- className = _ref.className,
134
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
135
- return React__default.createElement(Element, _extends({
136
- className: classNames('eds-button-group', className)
137
- }, rest));
138
- };
139
-
140
- var _excluded$2 = ["className", "children", "size"];
141
- var FloatingButton = function FloatingButton(_ref) {
142
- var className = _ref.className,
143
- children = _ref.children,
144
- _ref$size = _ref.size,
145
- size = _ref$size === void 0 ? 'medium' : _ref$size,
146
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
147
- return React__default.createElement("button", _extends({
148
- className: classNames('eds-floating-button', {
149
- 'eds-floating-button--extended': React__default.Children.count(children) > 1
150
- }, {
151
- 'eds-floating-button--small': size === 'small'
152
- }, className),
153
- type: "button"
154
- }, rest), wrapStringsInSpans(children));
155
- };
156
- var wrapStringsInSpans = function wrapStringsInSpans(children) {
157
- return React__default.Children.map(children, function (child) {
158
- return typeof child === 'string' ? React__default.createElement("span", null, child) : child;
159
- });
56
+ );
57
+ const defaultElement$8 = "button";
58
+ const PrimaryButton = React__default.forwardRef(
59
+ (props, ref) => {
60
+ const Element = props.as || defaultElement$8;
61
+ return /* @__PURE__ */ jsx(Button, { as: Element, ...props, ref, variant: "primary" });
62
+ }
63
+ );
64
+ const defaultElement$7 = "button";
65
+ const SecondaryButton = React__default.forwardRef(
66
+ (props, ref) => {
67
+ const Element = props.as || defaultElement$7;
68
+ return /* @__PURE__ */ jsx(Button, { as: Element, ...props, ref, variant: "secondary" });
69
+ }
70
+ );
71
+ const defaultElement$6 = "button";
72
+ const SuccessButton = React__default.forwardRef(
73
+ (props, ref) => {
74
+ const Element = props.as || defaultElement$6;
75
+ return /* @__PURE__ */ jsx(Button, { as: Element, ...props, ref, variant: "success" });
76
+ }
77
+ );
78
+ const defaultElement$5 = "button";
79
+ const NegativeButton = React__default.forwardRef(
80
+ (props, ref) => {
81
+ const Element = props.as || defaultElement$5;
82
+ return /* @__PURE__ */ jsx(Button, { as: Element, ...props, ref, variant: "negative" });
83
+ }
84
+ );
85
+ const defaultElement$4 = "button";
86
+ const TertiaryButton = React__default.forwardRef(
87
+ (props, ref) => {
88
+ const Element = props.as || defaultElement$4;
89
+ return /* @__PURE__ */ jsx(
90
+ Button,
91
+ {
92
+ as: Element,
93
+ ...props,
94
+ ref,
95
+ variant: "tertiary",
96
+ size: "small"
97
+ }
98
+ );
99
+ }
100
+ );
101
+ const ButtonGroup = ({
102
+ as: Element = "div",
103
+ className,
104
+ ...rest
105
+ }) => {
106
+ return /* @__PURE__ */ jsx(Element, { className: classNames("eds-button-group", className), ...rest });
160
107
  };
161
-
162
- var _excluded$1 = ["as", "children", "className", "disabled", "loading", "variant"];
163
- var defaultElement$3 = 'button';
164
- var SquareButton = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
165
- var as = _ref.as,
166
- children = _ref.children,
167
- className = _ref.className,
168
- _ref$disabled = _ref.disabled,
169
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
170
- _ref$loading = _ref.loading,
171
- loading = _ref$loading === void 0 ? false : _ref$loading,
172
- _ref$variant = _ref.variant,
173
- variant = _ref$variant === void 0 ? 'secondary' : _ref$variant,
174
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
175
- var Element = as || defaultElement$3;
176
- return React.createElement(Element, _extends({
177
- className: classNames('eds-square-button', "eds-square-button--" + variant, {
178
- 'eds-square-button--loading': loading
179
- }, className),
180
- "aria-busy": loading,
181
- disabled: disabled,
182
- "aria-disabled": disabled,
183
- ref: ref
184
- }, rest), React.Children.map(children, function (child) {
185
- if (typeof child === 'string') {
186
- return React.createElement("span", {
187
- className: "eds-square-button__label"
188
- }, child);
108
+ const FloatingButton = ({
109
+ className,
110
+ children,
111
+ size = "medium",
112
+ ...rest
113
+ }) => {
114
+ return /* @__PURE__ */ jsx(
115
+ "button",
116
+ {
117
+ className: classNames(
118
+ "eds-floating-button",
119
+ { "eds-floating-button--extended": React__default.Children.count(children) > 1 },
120
+ { "eds-floating-button--small": size === "small" },
121
+ className
122
+ ),
123
+ type: "button",
124
+ ...rest,
125
+ children: wrapStringsInSpans(children)
189
126
  }
190
- return React.createElement("span", {
191
- className: "eds-square-button__button"
192
- }, loading ? React.createElement(LoadingDots, {
193
- className: "eds-square-button__loading-dots"
194
- }) : child);
195
- }));
196
- });
197
-
198
- var defaultElement$2 = 'button';
199
- var SecondarySquareButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
200
- var Element = props.as || defaultElement$2;
201
- return (
202
- // @ts-expect-error type error due to props not being BaseButtonProps
203
- React__default.createElement(SquareButton, _extends({
204
- as: Element,
205
- ref: ref
206
- }, props, {
207
- variant: "secondary"
208
- }))
209
- );
210
- });
211
-
212
- var defaultElement$1 = 'button';
213
- var SuccessSquareButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
214
- var Element = props.as || defaultElement$1;
215
- return (
216
- // @ts-expect-error type error due to props not being BaseButtonProps
217
- React__default.createElement(SquareButton, _extends({
218
- as: Element,
219
- ref: ref
220
- }, props, {
221
- variant: "success"
222
- }))
223
127
  );
224
- });
225
-
226
- var TertiarySquareButton = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
227
- return React__default.createElement(SquareButton, _extends({
228
- ref: ref
229
- }, props, {
230
- variant: "tertiary"
231
- }));
232
- });
233
-
234
- var _excluded = ["children", "className", "disabled", "size", "as", "loading"];
235
- var defaultElement = 'button';
236
- var IconButton = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
237
- var children = _ref.children,
238
- className = _ref.className,
239
- _ref$disabled = _ref.disabled,
240
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
241
- _ref$size = _ref.size,
242
- size = _ref$size === void 0 ? 'medium' : _ref$size,
243
- as = _ref.as,
244
- loading = _ref.loading,
245
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
246
- var Element = as || defaultElement;
247
- var IconWithAriaHidden = React__default.Children.map(children, function (child) {
248
- if (React__default.isValidElement(child)) {
249
- // @ts-expect-error aria-hidden does, in fact, exist
250
- return React__default.cloneElement(child, {
251
- 'aria-hidden': true
252
- });
128
+ };
129
+ const wrapStringsInSpans = (children) => React__default.Children.map(
130
+ children,
131
+ (child) => typeof child === "string" ? /* @__PURE__ */ jsx("span", { children: child }) : child
132
+ );
133
+ const defaultElement$3 = "button";
134
+ const SquareButton = React.forwardRef(
135
+ ({
136
+ as,
137
+ children,
138
+ className,
139
+ disabled = false,
140
+ loading = false,
141
+ variant = "secondary",
142
+ ...rest
143
+ }, ref) => {
144
+ const Element = as || defaultElement$3;
145
+ return /* @__PURE__ */ jsx(
146
+ Element,
147
+ {
148
+ className: classNames(
149
+ "eds-square-button",
150
+ `eds-square-button--${variant}`,
151
+ {
152
+ "eds-square-button--loading": loading
153
+ },
154
+ className
155
+ ),
156
+ "aria-busy": loading,
157
+ disabled,
158
+ "aria-disabled": disabled,
159
+ ref,
160
+ ...rest,
161
+ children: React.Children.map(children, (child) => {
162
+ if (typeof child === "string") {
163
+ return /* @__PURE__ */ jsx("span", { className: "eds-square-button__label", children: child });
164
+ }
165
+ return /* @__PURE__ */ jsx("span", { className: "eds-square-button__button", children: loading ? /* @__PURE__ */ jsx(LoadingDots, { className: "eds-square-button__loading-dots" }) : child });
166
+ })
167
+ }
168
+ );
169
+ }
170
+ );
171
+ const defaultElement$2 = "button";
172
+ const SecondarySquareButton = React__default.forwardRef(
173
+ (props, ref) => {
174
+ const Element = props.as || defaultElement$2;
175
+ return (
176
+ // @ts-expect-error type error due to props not being BaseButtonProps
177
+ /* @__PURE__ */ jsx(SquareButton, { as: Element, ref, ...props, variant: "secondary" })
178
+ );
179
+ }
180
+ );
181
+ const defaultElement$1 = "button";
182
+ const SuccessSquareButton = React__default.forwardRef(
183
+ (props, ref) => {
184
+ const Element = props.as || defaultElement$1;
185
+ return (
186
+ // @ts-expect-error type error due to props not being BaseButtonProps
187
+ /* @__PURE__ */ jsx(SquareButton, { as: Element, ref, ...props, variant: "success" })
188
+ );
189
+ }
190
+ );
191
+ const TertiarySquareButton = React__default.forwardRef(
192
+ (props, ref) => /* @__PURE__ */ jsx(SquareButton, { ref, ...props, variant: "tertiary" })
193
+ );
194
+ const defaultElement = "button";
195
+ const IconButton = React__default.forwardRef(
196
+ ({
197
+ children,
198
+ className,
199
+ disabled = false,
200
+ size = "medium",
201
+ as,
202
+ loading,
203
+ ...rest
204
+ }, ref) => {
205
+ const Element = as || defaultElement;
206
+ const IconWithAriaHidden = React__default.Children.map(children, (child) => {
207
+ if (React__default.isValidElement(child)) {
208
+ return React__default.cloneElement(child, { "aria-hidden": true });
209
+ }
210
+ return child;
211
+ });
212
+ const iconButtonElement = /* @__PURE__ */ jsx(
213
+ Element,
214
+ {
215
+ className: classNames(
216
+ "eds-icon-button",
217
+ className,
218
+ {
219
+ "eds-icon-button--disabled": disabled
220
+ },
221
+ `eds-icon-button--size-${size}`
222
+ ),
223
+ disabled,
224
+ "aria-disabled": disabled,
225
+ "aria-busy": loading,
226
+ ref,
227
+ ...rest,
228
+ children: loading ? /* @__PURE__ */ jsx(LoadingDots, {}) : /* @__PURE__ */ jsx(Fragment, { children: IconWithAriaHidden })
229
+ }
230
+ );
231
+ if (disabled) {
232
+ return /* @__PURE__ */ jsx("div", { className: "eds-icon-button--disabled__wrapper", children: iconButtonElement });
253
233
  }
254
- return child;
255
- });
256
- var iconButtonElement = React__default.createElement(Element, _extends({
257
- className: classNames('eds-icon-button', className, {
258
- 'eds-icon-button--disabled': disabled
259
- }, "eds-icon-button--size-" + size),
260
- disabled: disabled,
261
- "aria-disabled": disabled,
262
- "aria-busy": loading,
263
- ref: ref
264
- }, rest), loading ? React__default.createElement(LoadingDots, null) : React__default.createElement(React__default.Fragment, null, IconWithAriaHidden));
265
- if (disabled) {
266
- return React__default.createElement("div", {
267
- className: "eds-icon-button--disabled__wrapper"
268
- }, iconButtonElement);
234
+ return /* @__PURE__ */ jsx(Fragment, { children: iconButtonElement });
269
235
  }
270
- return React__default.createElement(React__default.Fragment, null, iconButtonElement);
271
- });
272
-
273
- warnAboutMissingStyles('button');
274
-
275
- export { Button, ButtonGroup, FloatingButton, IconButton, NegativeButton, PrimaryButton, SecondaryButton, SecondarySquareButton, SuccessButton, SuccessSquareButton, TertiaryButton, TertiarySquareButton };
236
+ );
237
+ warnAboutMissingStyles("button");
238
+ export {
239
+ Button,
240
+ ButtonGroup,
241
+ FloatingButton,
242
+ IconButton,
243
+ NegativeButton,
244
+ PrimaryButton,
245
+ SecondaryButton,
246
+ SecondarySquareButton,
247
+ SuccessButton,
248
+ SuccessSquareButton,
249
+ TertiaryButton,
250
+ TertiarySquareButton
251
+ };
276
252
  //# sourceMappingURL=button.esm.js.map