@ebay/ui-core-react 1.4.1 → 1.5.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 +1 @@
1
- {"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../src/ebay-icon/icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAM,GAAG,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAA;AAIrE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAM9B,oBAAY,WAAW,GAAG,OAAO,CAAC;AAElC,oBAAY,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,GAAE,eAAe,GAAG,MAAM,CAAA;IACvC,IAAI,EAAE,IAAI,CAAC;IACX,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,YAAY,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;CACrC,CAAC;;AAqEF,wBAAuC"}
1
+ {"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../src/ebay-icon/icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAM,GAAG,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAA;AAIrE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAQ9B,oBAAY,WAAW,GAAG,OAAO,CAAC;AAElC,oBAAY,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,GAAE,eAAe,GAAG,MAAM,CAAA;IACvC,IAAI,EAAE,IAAI,CAAC;IACX,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,YAAY,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;CACrC,CAAC;;AAoEF,wBAAuC"}
package/ebay-icon/icon.js CHANGED
@@ -48,8 +48,10 @@ var react_1 = __importStar(require("react"));
48
48
  var classnames_1 = __importDefault(require("classnames"));
49
49
  var component_utils_1 = require("../common/component-utils");
50
50
  var random_id_1 = require("../common/random-id");
51
- var SMALL_ICON_SIZE = 16;
52
- var LARGE_ICON_SIZE = 64;
51
+ var iconPixelSizes = {
52
+ small: 16,
53
+ large: 64
54
+ };
53
55
  var DEFAULT_ICON_SIZE = 24;
54
56
  var EbayIcon = function (_a) {
55
57
  var _b;
@@ -58,29 +60,26 @@ var EbayIcon = function (_a) {
58
60
  react_1.useEffect(function () {
59
61
  setRandomId(random_id_1.randomId());
60
62
  }, []);
61
- var noTitle = a11yVariant === 'label';
63
+ var withAriaLabel = a11yVariant === 'label';
62
64
  var a11yTextId = a11yText && "icon-title-" + rId;
63
65
  var a11yProps = a11yText ? {
64
- 'aria-labelledby': noTitle ? undefined : a11yTextId,
65
- 'aria-label': noTitle ? a11yText : undefined,
66
+ 'aria-labelledby': withAriaLabel ? undefined : a11yTextId,
67
+ 'aria-label': withAriaLabel ? a11yText : undefined,
66
68
  role: 'img'
67
69
  } : {
68
70
  'aria-hidden': true
69
71
  };
70
- var iconSize = getIconSize(name) + "px";
71
72
  var prefixSvg = type === 'icon' ? 'icon-' : '';
72
73
  var kebabName = kebabCased(name);
74
+ var iconSize = getIconPixelSize(kebabName) + "px";
73
75
  var className = classnames_1.default(extraClass, (_b = {}, _b[getIconClass(type, kebabName)] = !noSkinClasses, _b));
74
76
  return (react_1.default.createElement("svg", __assign({ height: iconSize, width: iconSize }, rest, { className: className, xmlns: "http://www.w3.org/2000/svg", focusable: false, ref: forwardedRef }, a11yProps),
75
- a11yText && !noTitle && react_1.default.createElement("title", { id: a11yTextId }, a11yText),
77
+ a11yText && !withAriaLabel && react_1.default.createElement("title", { id: a11yTextId }, a11yText),
76
78
  react_1.default.createElement("use", { xlinkHref: "#" + prefixSvg + kebabName })));
77
79
  };
78
- function getIconSize(iconName) {
80
+ function getIconPixelSize(iconName) {
79
81
  var sizeCandidate = iconName.split('-').slice(-1)[0];
80
- return {
81
- small: SMALL_ICON_SIZE,
82
- large: LARGE_ICON_SIZE
83
- }[sizeCandidate] || DEFAULT_ICON_SIZE;
82
+ return iconPixelSizes[sizeCandidate] || DEFAULT_ICON_SIZE;
84
83
  }
85
84
  function kebabCased(str) {
86
85
  return str.replace(/([A-Z])/g, function (s, c) { return "-" + c.toLowerCase(); });
@@ -56,7 +56,7 @@ var EbayInlineNotice = function (_a) {
56
56
  var isGeneral = status === "general";
57
57
  return (react_1.default.createElement("div", { className: classnames_1.default(className, "inline-notice " + (!isGeneral ? "inline-notice--" + status : "")) },
58
58
  !isGeneral ? (react_1.default.createElement("span", { className: "inline-notice__header" },
59
- react_1.default.createElement(ebay_icon_1.EbayIcon, { name: status + "-filled", a11yText: ariaLabel, a11yVariant: "label" }))) : null,
59
+ react_1.default.createElement(ebay_icon_1.EbayIcon, { name: status + "FilledSmall", a11yText: ariaLabel, a11yVariant: "label" }))) : null,
60
60
  react_1.default.createElement(notice_content_1.default, __assign({}, content.props, { type: "inline" }))));
61
61
  };
62
62
  exports.default = EbayInlineNotice;
@@ -28,7 +28,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
28
  var react_1 = __importDefault(require("react"));
29
29
  var notice_content_1 = __importDefault(require("../common/notice-utils/notice-content"));
30
30
  var ebay_notice_content_1 = require("../ebay-notice-base/components/ebay-notice-content");
31
- var icon_1 = __importDefault(require("../ebay-icon/icon"));
31
+ var ebay_icon_1 = require("../ebay-icon");
32
32
  var EbayPageNotice = function (_a) {
33
33
  var _b = _a.status, status = _b === void 0 ? 'general' : _b, children = _a.children, ariaLabel = _a["aria-label"], rest = __rest(_a, ["status", "children", 'aria-label']);
34
34
  var childrenArray = react_1.default.Children.toArray(children);
@@ -38,7 +38,7 @@ var EbayPageNotice = function (_a) {
38
38
  }
39
39
  return (react_1.default.createElement("section", __assign({}, rest, { "aria-labelledby": status + "-status", className: "page-notice " + (status !== "general" ? "page-notice--" + status : ""), role: "region" }),
40
40
  status !== "general" ? (react_1.default.createElement("div", { className: "page-notice__header", id: status + "-status" },
41
- react_1.default.createElement(icon_1.default, { name: status + "-filled", a11yText: ariaLabel, a11yVariant: "label" }))) : null,
41
+ react_1.default.createElement(ebay_icon_1.EbayIcon, { name: status + "FilledSmall", a11yText: ariaLabel, a11yVariant: "label" }))) : null,
42
42
  react_1.default.createElement(notice_content_1.default, __assign({}, content.props, { type: "page" })),
43
43
  children));
44
44
  };
@@ -29,7 +29,7 @@ var react_1 = __importDefault(require("react"));
29
29
  var classnames_1 = __importDefault(require("classnames"));
30
30
  var ebay_notice_content_1 = require("../ebay-notice-base/components/ebay-notice-content");
31
31
  var notice_content_1 = __importDefault(require("../common/notice-utils/notice-content"));
32
- var icon_1 = __importDefault(require("../ebay-icon/icon"));
32
+ var ebay_icon_1 = require("../ebay-icon");
33
33
  var EbaySectionNotice = function (_a) {
34
34
  var _b = _a.status, status = _b === void 0 ? 'general' : _b, children = _a.children, className = _a.className, ariaLabel = _a["aria-label"], _c = _a["aria-roledescription"], ariaRoleDescription = _c === void 0 ? 'Notice' : _c, rest = __rest(_a, ["status", "children", "className", 'aria-label', 'aria-roledescription']);
35
35
  var childrenArray = react_1.default.Children.toArray(children);
@@ -43,7 +43,7 @@ var EbaySectionNotice = function (_a) {
43
43
  }
44
44
  return (react_1.default.createElement("section", __assign({}, rest, { className: classnames_1.default(className, "section-notice", hasStatus && "section-notice--" + status), role: "region", "aria-label": !hasStatus ? ariaLabel : null, "aria-labelledby": hasStatus ? "section-notice-" + status : null, "aria-roledescription": ariaRoleDescription }),
45
45
  hasStatus && (react_1.default.createElement("div", { className: "section-notice__header", id: "section-notice-" + status },
46
- react_1.default.createElement(icon_1.default, { name: status + "-filled", a11yText: ariaLabel, a11yVariant: "label" }))),
46
+ react_1.default.createElement(ebay_icon_1.EbayIcon, { name: status + "FilledSmall", a11yText: ariaLabel, a11yVariant: "label" }))),
47
47
  react_1.default.createElement(notice_content_1.default, __assign({}, content.props, { type: "section" })),
48
48
  children));
49
49
  };
@@ -1,4 +1,4 @@
1
- import { Component, ComponentProps, ReactElement } from 'react';
1
+ import { ComponentProps, FC } from 'react';
2
2
  import { Activation, Size } from './types';
3
3
  declare type TabsProps = ComponentProps<'div'> & {
4
4
  index?: number;
@@ -8,21 +8,6 @@ declare type TabsProps = ComponentProps<'div'> & {
8
8
  activation?: Activation;
9
9
  onTabSelect?: (index: number) => void;
10
10
  };
11
- declare type State = {
12
- selectedIndex: number;
13
- focusedIndex: number;
14
- };
15
- declare class Tabs extends Component<TabsProps, State> {
16
- headings: HTMLElement[];
17
- constructor(props: TabsProps);
18
- componentDidUpdate(prevProps: TabsProps): void;
19
- onTabSelect(i: number): void;
20
- /**
21
- * Handle a11y for heading
22
- * https://ebay.gitbooks.io/mindpatterns/content/disclosure/tabs.html
23
- */
24
- onTabKeyDown(ev: KeyboardEvent, index: number): void;
25
- render(): ReactElement;
26
- }
11
+ declare const Tabs: FC<TabsProps>;
27
12
  export default Tabs;
28
13
  //# sourceMappingURL=tabs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/ebay-tabs/tabs.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAItE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAI1C,aAAK,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAE9D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ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this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
3
  if (k2 === undefined) k2 = k;
17
4
  Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
@@ -41,99 +28,79 @@ var tab_1 = __importDefault(require("./tab"));
41
28
  var tab_panel_1 = __importDefault(require("./tab-panel"));
42
29
  var component_utils_1 = require("../common/component-utils");
43
30
  var classnames_1 = __importDefault(require("classnames"));
44
- // todo: convert to hooks
45
- var Tabs = /** @class */ (function (_super) {
46
- __extends(Tabs, _super);
47
- function Tabs(props) {
48
- var _this = _super.call(this, props) || this;
49
- var _a = props.index, index = _a === void 0 ? 0 : _a;
50
- _this.onTabSelect = _this.onTabSelect.bind(_this);
51
- _this.headings = [];
52
- _this.state = {
53
- selectedIndex: index,
54
- focusedIndex: index
55
- };
56
- return _this;
57
- }
58
- Tabs.prototype.componentDidUpdate = function (prevProps) {
59
- var _a;
60
- if (this.props.index !== prevProps.index) {
61
- this.onTabSelect(this.props.index);
62
- }
63
- (_a = this.headings[this.state.focusedIndex]) === null || _a === void 0 ? void 0 : _a.focus();
64
- };
65
- Tabs.prototype.onTabSelect = function (i) {
66
- if (this.props.onTabSelect) {
67
- this.props.onTabSelect(i);
68
- }
69
- this.setState({
70
- selectedIndex: i,
71
- focusedIndex: i
72
- });
31
+ var Tabs = function (_a) {
32
+ var id = _a.id, className = _a.className, _b = _a.index, index = _b === void 0 ? 0 : _b, _c = _a.size, size = _c === void 0 ? 'medium' : _c, _d = _a.activation, activation = _d === void 0 ? 'auto' : _d, _e = _a.onTabSelect, onTabSelect = _e === void 0 ? function () { } : _e, children = _a.children;
33
+ var headings = [];
34
+ var _f = react_1.useState(index), selectedIndex = _f[0], setSelectedIndex = _f[1];
35
+ var _g = react_1.useState(index), focusedIndex = _g[0], setFocusedIndex = _g[1];
36
+ var onSelect = function (i) {
37
+ onTabSelect(i);
38
+ setSelectedIndex(i);
39
+ setFocusedIndex(i);
73
40
  };
74
41
  /**
75
42
  * Handle a11y for heading
76
43
  * https://ebay.gitbooks.io/mindpatterns/content/disclosure/tabs.html
77
44
  */
78
- Tabs.prototype.onTabKeyDown = function (ev, index) {
79
- var _this = this;
80
- var _a = this.props, _b = _a.activation, activation = _b === void 0 ? 'auto' : _b, children = _a.children;
45
+ var onKeyDown = function (ev, i) {
81
46
  event_utils_1.handleActionKeydown(ev, function () {
82
47
  ev.preventDefault();
83
48
  if (activation === 'manual') {
84
- _this.onTabSelect(index);
49
+ onSelect(i);
85
50
  }
86
51
  });
87
52
  event_utils_1.handleLeftRightArrowsKeydown(ev, function () {
88
53
  ev.preventDefault();
89
54
  var len = component_utils_1.filterByType(children, tab_1.default).length;
90
55
  var direction = ['Left', 'ArrowLeft'].includes(ev.key) ? -1 : 1;
91
- var nextIndex = (_this.state.focusedIndex + len + direction) % len;
92
- _this.setState({ focusedIndex: nextIndex });
56
+ var nextIndex = (focusedIndex + len + direction) % len;
57
+ setFocusedIndex(nextIndex);
93
58
  if (activation !== 'manual') {
94
- _this.onTabSelect(nextIndex);
59
+ onSelect(nextIndex);
95
60
  }
96
61
  });
97
62
  };
98
- Tabs.prototype.render = function () {
99
- var _this = this;
100
- var _a = this.props, id = _a.id, className = _a.className, _b = _a.size, size = _b === void 0 ? 'medium' : _b, children = _a.children;
101
- var fake = component_utils_1.filterBy(children, function (_a) {
102
- var type = _a.type, props = _a.props;
103
- return type === tab_1.default && props.href;
104
- }).length > 0;
105
- var large = size === 'large';
106
- var tabHeadings = component_utils_1.filterByType(children, tab_1.default).map(function (item, i) {
107
- var _a = item.props, href = _a.href, content = _a.children;
108
- var itemProps = {
109
- refCallback: function (ref) { _this.headings[i] = ref; },
110
- index: i,
111
- parentId: id,
112
- selected: _this.state.selectedIndex === i,
113
- href: href,
114
- children: content,
115
- onClick: function () { _this.onTabSelect(i); },
116
- onKeyDown: function (e) { _this.onTabKeyDown(e, i); }
117
- };
118
- return react_1.default.cloneElement(item, itemProps);
119
- });
120
- var tabPanels = component_utils_1.filterByType(children, tab_panel_1.default).map(function (item, i) {
121
- var content = item.props.children;
122
- var itemProps = {
123
- index: i,
124
- parentId: id,
125
- selected: _this.state.selectedIndex === i,
126
- fake: fake,
127
- children: content
128
- };
129
- return react_1.default.cloneElement(item, itemProps);
130
- });
131
- return fake ? (react_1.default.createElement("div", { id: id, className: classnames_1.default(className, 'fake-tabs') },
132
- react_1.default.createElement("ul", { className: classnames_1.default('fake-tabs__items', { 'fake-tabs__items--large': large }) }, tabHeadings),
133
- react_1.default.createElement("div", { className: "fake-tabs__content" }, tabPanels))) : (react_1.default.createElement("div", { id: id, className: classnames_1.default(className, 'tabs') },
134
- react_1.default.createElement("div", { className: classnames_1.default('tabs__items', { 'tabs__items--large': large }), role: "tablist" }, tabHeadings),
135
- react_1.default.createElement("div", { className: "tabs__content" }, tabPanels)));
136
- };
137
- return Tabs;
138
- }(react_1.Component));
63
+ react_1.useEffect(function () {
64
+ onSelect(index);
65
+ }, [index]);
66
+ react_1.useEffect(function () {
67
+ var _a;
68
+ (_a = headings[focusedIndex]) === null || _a === void 0 ? void 0 : _a.focus();
69
+ }, [focusedIndex]);
70
+ var isFake = component_utils_1.filterBy(children, function (_a) {
71
+ var type = _a.type, props = _a.props;
72
+ return type === tab_1.default && props.href;
73
+ }).length > 0;
74
+ var isLarge = size === 'large';
75
+ var tabHeadings = component_utils_1.filterByType(children, tab_1.default).map(function (item, i) {
76
+ var _a = item.props, href = _a.href, content = _a.children;
77
+ var itemProps = {
78
+ refCallback: function (ref) { headings[i] = ref; },
79
+ index: i,
80
+ parentId: id,
81
+ selected: selectedIndex === i,
82
+ href: href,
83
+ children: content,
84
+ onClick: function () { onSelect(i); },
85
+ onKeyDown: function (e) { onKeyDown(e, i); }
86
+ };
87
+ return react_1.cloneElement(item, itemProps);
88
+ });
89
+ var tabPanels = component_utils_1.filterByType(children, tab_panel_1.default).map(function (item, i) {
90
+ var content = item.props.children;
91
+ var itemProps = {
92
+ index: i,
93
+ parentId: id,
94
+ selected: selectedIndex === i,
95
+ fake: isFake,
96
+ children: content
97
+ };
98
+ return react_1.cloneElement(item, itemProps);
99
+ });
100
+ return isFake ? (react_1.default.createElement("div", { id: id, className: classnames_1.default(className, 'fake-tabs') },
101
+ react_1.default.createElement("ul", { className: classnames_1.default('fake-tabs__items', { 'fake-tabs__items--large': isLarge }) }, tabHeadings),
102
+ react_1.default.createElement("div", { className: "fake-tabs__content" }, tabPanels))) : (react_1.default.createElement("div", { id: id, className: classnames_1.default(className, 'tabs') },
103
+ react_1.default.createElement("div", { className: classnames_1.default('tabs__items', { 'tabs__items--large': isLarge }), role: "tablist" }, tabHeadings),
104
+ react_1.default.createElement("div", { className: "tabs__content" }, tabPanels)));
105
+ };
139
106
  exports.default = Tabs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebay/ui-core-react",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Skin components build off React",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",