@entur/layout 3.1.8 → 3.1.9-beta.0

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,239 +1,280 @@
1
- import { ConditionalWrapper, warnAboutMissingStyles } from '@entur/utils';
2
- import React from 'react';
3
- import classNames from 'classnames';
4
- import { Heading3, Paragraph, Label } from '@entur/typography';
5
- import { ForwardIcon } from '@entur/icons';
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);
1
+ import { ConditionalWrapper, warnAboutMissingStyles } from "@entur/utils";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import React from "react";
4
+ import { Heading3, Paragraph, Label } from "@entur/typography";
5
+ import { ForwardIcon } from "@entur/icons";
6
+ function getDefaultExportFromCjs(x) {
7
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
15
8
  }
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 (e.includes(n)) continue;
21
- t[n] = r[n];
22
- }
23
- return t;
9
+ var classnames = { exports: {} };
10
+ /*!
11
+ Copyright (c) 2018 Jed Watson.
12
+ Licensed under the MIT License (MIT), see
13
+ http://jedwatson.github.io/classnames
14
+ */
15
+ var hasRequiredClassnames;
16
+ function requireClassnames() {
17
+ if (hasRequiredClassnames) return classnames.exports;
18
+ hasRequiredClassnames = 1;
19
+ (function(module) {
20
+ (function() {
21
+ var hasOwn = {}.hasOwnProperty;
22
+ function classNames2() {
23
+ var classes = "";
24
+ for (var i = 0; i < arguments.length; i++) {
25
+ var arg = arguments[i];
26
+ if (arg) {
27
+ classes = appendClass(classes, parseValue(arg));
28
+ }
29
+ }
30
+ return classes;
31
+ }
32
+ function parseValue(arg) {
33
+ if (typeof arg === "string" || typeof arg === "number") {
34
+ return arg;
35
+ }
36
+ if (typeof arg !== "object") {
37
+ return "";
38
+ }
39
+ if (Array.isArray(arg)) {
40
+ return classNames2.apply(null, arg);
41
+ }
42
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
43
+ return arg.toString();
44
+ }
45
+ var classes = "";
46
+ for (var key in arg) {
47
+ if (hasOwn.call(arg, key) && arg[key]) {
48
+ classes = appendClass(classes, key);
49
+ }
50
+ }
51
+ return classes;
52
+ }
53
+ function appendClass(value, newClass) {
54
+ if (!newClass) {
55
+ return value;
56
+ }
57
+ if (value) {
58
+ return value + " " + newClass;
59
+ }
60
+ return value + newClass;
61
+ }
62
+ if (module.exports) {
63
+ classNames2.default = classNames2;
64
+ module.exports = classNames2;
65
+ } else {
66
+ window.classNames = classNames2;
67
+ }
68
+ })();
69
+ })(classnames);
70
+ return classnames.exports;
24
71
  }
25
-
26
- var _excluded$5 = ["className", "as"];
27
- var defaultElement$8 = 'div';
28
- var Contrast = /*#__PURE__*/React.forwardRef(function Contrast(_ref, ref) {
29
- var className = _ref.className,
30
- as = _ref.as,
31
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
32
- var Element = as || defaultElement$8;
33
- return React.createElement(ContrastContext.Provider, {
34
- value: true
35
- }, React.createElement(Element, _extends({
36
- className: classNames('eds-contrast', className),
37
- ref: ref
38
- }, rest)));
72
+ var classnamesExports = requireClassnames();
73
+ const classNames = /* @__PURE__ */ getDefaultExportFromCjs(classnamesExports);
74
+ const defaultElement$8 = "div";
75
+ const Contrast = React.forwardRef(function Contrast2({ className, as, ...rest }, ref) {
76
+ const Element = as || defaultElement$8;
77
+ return /* @__PURE__ */ jsx(ContrastContext.Provider, { value: true, children: /* @__PURE__ */ jsx(
78
+ Element,
79
+ {
80
+ className: classNames("eds-contrast", className),
81
+ ref,
82
+ ...rest
83
+ }
84
+ ) });
39
85
  });
40
- var ContrastContext = /*#__PURE__*/React.createContext(false);
41
- var useContrast = function useContrast() {
42
- return React.useContext(ContrastContext);
43
- };
44
-
45
- var _excluded$4 = ["children", "className", "as"];
46
- var defaultElement$7 = 'div';
47
- var BaseCard = function BaseCard(_ref) {
48
- var children = _ref.children,
49
- className = _ref.className,
50
- as = _ref.as,
51
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
52
- var Element = as || defaultElement$7;
53
- var classList = classNames('eds-base-card', className);
54
- return React.createElement(Element, _extends({
55
- className: classList
56
- }, rest), children);
86
+ const ContrastContext = React.createContext(false);
87
+ const useContrast = () => React.useContext(ContrastContext);
88
+ const defaultElement$7 = "div";
89
+ const BaseCard = ({
90
+ children,
91
+ className,
92
+ as,
93
+ ...rest
94
+ }) => {
95
+ const Element = as || defaultElement$7;
96
+ const classList = classNames("eds-base-card", className);
97
+ return /* @__PURE__ */ jsx(Element, { className: classList, ...rest, children });
57
98
  };
58
-
59
- var _excluded$3 = ["title", "children", "titleIcon", "compact", "className", "as"];
60
- var defaultElement$6 = 'a';
61
- var NavigationCard = function NavigationCard(_ref) {
62
- var title = _ref.title,
63
- children = _ref.children,
64
- titleIcon = _ref.titleIcon,
65
- _ref$compact = _ref.compact,
66
- compact = _ref$compact === void 0 ? false : _ref$compact,
67
- className = _ref.className,
68
- as = _ref.as,
69
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
70
- var Element = as || defaultElement$6;
71
- var classList = classNames('eds-navigation-card', className, {
72
- 'eds-base-card--red-line': compact,
73
- 'eds-navigation-card--compact': compact
99
+ const defaultElement$6 = "a";
100
+ const NavigationCard = ({
101
+ title,
102
+ children,
103
+ titleIcon,
104
+ compact = false,
105
+ className,
106
+ as,
107
+ ...rest
108
+ }) => {
109
+ const Element = as || defaultElement$6;
110
+ const classList = classNames("eds-navigation-card", className, {
111
+ "eds-base-card--red-line": compact,
112
+ "eds-navigation-card--compact": compact
74
113
  });
75
- return React.createElement(BaseCard, _extends({
76
- as: Element,
77
- className: classList
78
- }, rest), React.createElement("div", {
79
- className: "eds-navigation-card-header"
80
- }, React.createElement("div", {
81
- className: "eds-navigation-card-header__content"
82
- }, titleIcon && React.createElement("div", {
83
- className: "eds-navigation-card-header__title-icon",
84
- "aria-hidden": "true"
85
- }, titleIcon), React.createElement("span", {
86
- className: "eds-navigation-card-header__title"
87
- }, React.createElement(Heading3, {
88
- as: "span"
89
- }, title))), !compact && React.createElement("div", {
90
- className: "eds-navigation-card-header__highlight"
91
- })), !compact && React.createElement(React.Fragment, null, React.createElement(Paragraph, null, children)));
114
+ return /* @__PURE__ */ jsxs(BaseCard, { as: Element, className: classList, ...rest, children: [
115
+ /* @__PURE__ */ jsxs("div", { className: "eds-navigation-card-header", children: [
116
+ /* @__PURE__ */ jsxs("div", { className: "eds-navigation-card-header__content", children: [
117
+ titleIcon && /* @__PURE__ */ jsx(
118
+ "div",
119
+ {
120
+ className: "eds-navigation-card-header__title-icon",
121
+ "aria-hidden": "true",
122
+ children: titleIcon
123
+ }
124
+ ),
125
+ /* @__PURE__ */ jsx("span", { className: "eds-navigation-card-header__title", children: /* @__PURE__ */ jsx(Heading3, { as: "span", children: title }) })
126
+ ] }),
127
+ !compact && /* @__PURE__ */ jsx("div", { className: "eds-navigation-card-header__highlight" })
128
+ ] }),
129
+ !compact && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Paragraph, { children }) })
130
+ ] });
92
131
  };
93
-
94
- var _excluded$2 = ["title", "description", "children", "className", "category", "style", "as", "headingLevel", "wholeCardAsElement", "hideArrow", "wrapperProps", "orientation"];
95
- var defaultElement$5 = 'a';
96
- var MediaCard = function MediaCard(_ref) {
97
- var title = _ref.title,
98
- description = _ref.description,
99
- children = _ref.children,
100
- className = _ref.className,
101
- category = _ref.category,
102
- style = _ref.style,
103
- as = _ref.as,
104
- _ref$headingLevel = _ref.headingLevel,
105
- headingLevel = _ref$headingLevel === void 0 ? 'h2' : _ref$headingLevel,
106
- whole = _ref.wholeCardAsElement,
107
- hideArrow = _ref.hideArrow,
108
- wrapperProps = _ref.wrapperProps,
109
- orientation = _ref.orientation,
110
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
111
- var Element = as || defaultElement$5;
112
- var Heading = Heading3;
113
- var _wrapperProps = whole ? _extends({}, wrapperProps, rest) : _extends({}, wrapperProps);
114
- var classList = classNames('eds-base-card, eds-media-card', className, {
115
- 'eds-media-card--horizontal': orientation === 'horizontal'
132
+ const defaultElement$5 = "a";
133
+ const MediaCard = ({
134
+ title,
135
+ description,
136
+ children,
137
+ className,
138
+ category,
139
+ style,
140
+ as,
141
+ headingLevel = "h2",
142
+ wholeCardAsElement: whole,
143
+ hideArrow,
144
+ wrapperProps,
145
+ orientation,
146
+ ...rest
147
+ }) => {
148
+ const Element = as || defaultElement$5;
149
+ const Heading = Heading3;
150
+ const _wrapperProps = whole ? { ...wrapperProps, ...rest } : { ...wrapperProps };
151
+ const classList = classNames("eds-base-card, eds-media-card", className, {
152
+ "eds-media-card--horizontal": orientation === "horizontal"
116
153
  });
117
- return React.createElement(BaseCard, _extends({
118
- className: classList,
119
- style: style
120
- }, _wrapperProps), React.createElement("div", {
121
- className: "eds-media-card__media"
122
- }, children), React.createElement("div", {
123
- className: "eds-media-card__text"
124
- }, category && React.createElement(Label, {
125
- className: "eds-media-card__text__category"
126
- }, category), React.createElement(ConditionalWrapper, {
127
- condition: description !== undefined,
128
- wrapper: function wrapper(children) {
129
- return React.createElement(Heading, {
130
- as: headingLevel,
131
- className: "eds-media-card__text__title"
132
- }, children);
133
- }
134
- }, React.createElement(Element, _extends({
135
- tabIndex: 0,
136
- className: "eds-media-card__text__title-link"
137
- }, rest), title)), description !== undefined && React.createElement(Paragraph, null, description), !hideArrow && React.createElement(ForwardIcon, {
138
- className: "eds-media-card__arrow-icon",
139
- "aria-hidden": "true"
140
- })));
154
+ return /* @__PURE__ */ jsxs(BaseCard, { className: classList, style, ..._wrapperProps, children: [
155
+ /* @__PURE__ */ jsx("div", { className: "eds-media-card__media", children }),
156
+ /* @__PURE__ */ jsxs("div", { className: "eds-media-card__text", children: [
157
+ category && /* @__PURE__ */ jsx(Label, { className: "eds-media-card__text__category", children: category }),
158
+ /* @__PURE__ */ jsx(
159
+ ConditionalWrapper,
160
+ {
161
+ condition: description !== void 0,
162
+ wrapper: (children2) => /* @__PURE__ */ jsx(Heading, { as: headingLevel, className: "eds-media-card__text__title", children: children2 }),
163
+ children: /* @__PURE__ */ jsx(
164
+ Element,
165
+ {
166
+ tabIndex: 0,
167
+ className: "eds-media-card__text__title-link",
168
+ ...rest,
169
+ children: title
170
+ }
171
+ )
172
+ }
173
+ ),
174
+ description !== void 0 && /* @__PURE__ */ jsx(Paragraph, { children: description }),
175
+ !hideArrow && /* @__PURE__ */ jsx(
176
+ ForwardIcon,
177
+ {
178
+ className: "eds-media-card__arrow-icon",
179
+ "aria-hidden": "true"
180
+ }
181
+ )
182
+ ] })
183
+ ] });
141
184
  };
142
-
143
- var _excluded$1 = ["children", "className", "max", "variant", "showZero", "invisible", "hide", "as", "type"];
144
- var defaultElement$4 = 'span';
145
- var Badge = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
146
- var children = _ref.children,
147
- className = _ref.className,
148
- _ref$max = _ref.max,
149
- max = _ref$max === void 0 ? 99 : _ref$max,
150
- variant = _ref.variant,
151
- _ref$showZero = _ref.showZero,
152
- showZero = _ref$showZero === void 0 ? false : _ref$showZero,
153
- _ref$invisible = _ref.invisible,
154
- invisibleProp = _ref$invisible === void 0 ? false : _ref$invisible,
155
- _ref$hide = _ref.hide,
156
- hideProp = _ref$hide === void 0 ? false : _ref$hide,
157
- as = _ref.as,
158
- _ref$type = _ref.type,
159
- type = _ref$type === void 0 ? 'status' : _ref$type,
160
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
161
- var Element = as || defaultElement$4;
162
- var computedHide = hideProp || invisibleProp || children === 0 && !showZero || children == null;
163
- var displayValue;
164
- if (typeof children === 'number') {
165
- displayValue = children > max ? max + "+" : children;
166
- } else {
167
- displayValue = children;
185
+ const defaultElement$4 = "span";
186
+ const Badge = React.forwardRef(
187
+ ({
188
+ children,
189
+ className,
190
+ max = 99,
191
+ variant,
192
+ showZero = false,
193
+ invisible: invisibleProp = false,
194
+ hide: hideProp = false,
195
+ as,
196
+ type = "status",
197
+ ...rest
198
+ }, ref) => {
199
+ const Element = as || defaultElement$4;
200
+ const computedHide = hideProp || invisibleProp || children === 0 && !showZero || children == null;
201
+ let displayValue;
202
+ if (typeof children === "number") {
203
+ displayValue = children > max ? `${max}+` : children;
204
+ } else {
205
+ displayValue = children;
206
+ }
207
+ const classList = classNames(
208
+ className,
209
+ "eds-badge",
210
+ {
211
+ "eds-badge--hide": computedHide,
212
+ "eds-badge--show-zero": showZero
213
+ },
214
+ `eds-badge--variant-${variant}`,
215
+ `eds-badge--type-${type}`
216
+ );
217
+ return /* @__PURE__ */ jsx(Element, { className: classList, ref, ...rest, children: displayValue });
168
218
  }
169
- var classList = classNames(className, 'eds-badge', {
170
- 'eds-badge--hide': computedHide,
171
- 'eds-badge--show-zero': showZero
172
- }, "eds-badge--variant-" + variant, "eds-badge--type-" + type);
173
- return React.createElement(Element, _extends({
174
- className: classList,
175
- ref: ref
176
- }, rest), displayValue);
177
- });
178
-
179
- var defaultElement$3 = 'span';
180
- var BulletBadge = /*#__PURE__*/React.forwardRef(function (props, ref) {
181
- var Element = props.as || defaultElement$3;
182
- // @ts-expect-error type error due to props not being BadgeOwnProps
183
- return React.createElement(Badge, _extends({
184
- as: Element
185
- }, props, {
186
- ref: ref,
187
- type: "bullet"
188
- }));
189
- });
190
-
191
- var defaultElement$2 = 'span';
192
- var NotificationBadge = /*#__PURE__*/React.forwardRef(function (props, ref) {
193
- var Element = props.as || defaultElement$2;
194
- // @ts-expect-error type error due to props not being BadgeOwnProps
195
- return React.createElement(Badge, _extends({
196
- as: Element
197
- }, props, {
198
- ref: ref,
199
- type: "notification"
200
- }));
201
- });
202
-
203
- var defaultElement$1 = 'span';
204
- var StatusBadge = /*#__PURE__*/React.forwardRef(function (props, ref) {
205
- var Element = props.as || defaultElement$1;
206
- // @ts-expect-error type error due to props not being BadgeOwnProps
207
- return React.createElement(Badge, _extends({
208
- as: Element
209
- }, props, {
210
- ref: ref,
211
- type: "status"
212
- }));
213
- });
214
-
215
- var _excluded = ["className", "children", "compact", "as"];
216
- var defaultElement = 'div';
217
- var Tag = function Tag(_ref) {
218
- var className = _ref.className,
219
- children = _ref.children,
220
- compact = _ref.compact,
221
- as = _ref.as,
222
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
223
- var Element = as || defaultElement;
224
- var childrenArray = React.Children.toArray(children);
225
- var hasLeadingIcon = childrenArray.length > 1 && typeof childrenArray[0] !== 'string';
226
- var hasTrailingIcon = childrenArray.length > 1 && typeof childrenArray[childrenArray.length - 1] !== 'string';
227
- return React.createElement(Element, _extends({
228
- className: classNames('eds-tag', className, {
229
- 'eds-tag--leading-icon': hasLeadingIcon,
230
- 'eds-tag--trailing-icon': hasTrailingIcon,
231
- 'eds-tag--compact': compact
232
- })
233
- }, rest), children);
219
+ );
220
+ const defaultElement$3 = "span";
221
+ const BulletBadge = React.forwardRef(
222
+ (props, ref) => {
223
+ const Element = props.as || defaultElement$3;
224
+ return /* @__PURE__ */ jsx(Badge, { as: Element, ...props, ref, type: "bullet" });
225
+ }
226
+ );
227
+ const defaultElement$2 = "span";
228
+ const NotificationBadge = React.forwardRef(
229
+ (props, ref) => {
230
+ const Element = props.as || defaultElement$2;
231
+ return /* @__PURE__ */ jsx(Badge, { as: Element, ...props, ref, type: "notification" });
232
+ }
233
+ );
234
+ const defaultElement$1 = "span";
235
+ const StatusBadge = React.forwardRef(
236
+ (props, ref) => {
237
+ const Element = props.as || defaultElement$1;
238
+ return /* @__PURE__ */ jsx(Badge, { as: Element, ...props, ref, type: "status" });
239
+ }
240
+ );
241
+ const defaultElement = "div";
242
+ const Tag = ({
243
+ className,
244
+ children,
245
+ compact,
246
+ as,
247
+ ...rest
248
+ }) => {
249
+ const Element = as || defaultElement;
250
+ const childrenArray = React.Children.toArray(children);
251
+ const hasLeadingIcon = childrenArray.length > 1 && typeof childrenArray[0] !== "string";
252
+ const hasTrailingIcon = childrenArray.length > 1 && typeof childrenArray[childrenArray.length - 1] !== "string";
253
+ return /* @__PURE__ */ jsx(
254
+ Element,
255
+ {
256
+ className: classNames("eds-tag", className, {
257
+ "eds-tag--leading-icon": hasLeadingIcon,
258
+ "eds-tag--trailing-icon": hasTrailingIcon,
259
+ "eds-tag--compact": compact
260
+ }),
261
+ ...rest,
262
+ children
263
+ }
264
+ );
265
+ };
266
+ warnAboutMissingStyles("layout", "typography");
267
+ export {
268
+ Badge,
269
+ BaseCard,
270
+ BulletBadge,
271
+ Contrast,
272
+ ContrastContext,
273
+ MediaCard,
274
+ NavigationCard,
275
+ NotificationBadge,
276
+ StatusBadge,
277
+ Tag,
278
+ useContrast
234
279
  };
235
-
236
- warnAboutMissingStyles('layout', 'typography');
237
-
238
- export { Badge, BaseCard, BulletBadge, Contrast, ContrastContext, MediaCard, NavigationCard, NotificationBadge, StatusBadge, Tag, useContrast };
239
280
  //# sourceMappingURL=layout.esm.js.map