@dhis2-ui/popper 9.10.3 → 9.11.1-beta.1

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,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
4
-
5
4
  (0, _cypressCucumberPreprocessor.Given)('a Popper with placement bottom-start has a React Ref as its reference', () => {
6
5
  cy.visitStory('Popper', 'React Ref As Reference');
7
6
  });
@@ -12,25 +11,25 @@ var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preproces
12
11
  cy.visitStory('Popper', 'Virtual Element As Reference');
13
12
  });
14
13
  (0, _cypressCucumberPreprocessor.Then)('the left of the popper is aligned with the left of the reference element', () => {
15
- cy.all(() => cy.get('button'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref => {
14
+ cy.all(() => cy.get('button:contains("Reference")'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref => {
16
15
  let [$reference, $popper] = _ref;
17
16
  const referenceRect = $reference.get(0).getBoundingClientRect();
18
17
  const popperRect = $popper.get(0).getBoundingClientRect();
19
- expect(referenceRect.left).to.equal(popperRect.left);
18
+ expect(referenceRect.left).to.be.closeTo(popperRect.left, 1);
20
19
  });
21
20
  });
22
21
  (0, _cypressCucumberPreprocessor.Then)('the top of the popper is adjacent to the bottom of the reference element', () => {
23
- cy.all(() => cy.get('button'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref2 => {
24
- let [$reference, $popper] = _ref2;
25
- const referenceRect = $reference.get(0).getBoundingClientRect();
22
+ cy.all(() => cy.get('button:contains("Reference")'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref2 => {
23
+ let [$button, $popper] = _ref2;
24
+ const buttonRect = $button.get(0).getBoundingClientRect();
26
25
  const popperRect = $popper.get(0).getBoundingClientRect();
27
- expect(Math.round(referenceRect.bottom)).to.equal(Math.round(popperRect.top));
26
+ expect(buttonRect.bottom).to.be.closeTo(popperRect.top, 1);
28
27
  });
29
28
  });
30
29
  (0, _cypressCucumberPreprocessor.Then)('the top and left of the popper correspond with the virtualElement', () => {
31
30
  cy.get('[data-test="dhis2-uicore-popper"]').should($popper => {
32
31
  const popperRect = $popper.get(0).getBoundingClientRect();
33
- expect(popperRect.top).to.equal(200);
34
- expect(popperRect.left).to.equal(200);
32
+ expect(popperRect.top).to.be.closeTo(200, 1);
33
+ expect(popperRect.left).to.be.closeTo(200, 1);
35
34
  });
36
35
  });
@@ -13,4 +13,3 @@ Feature: Accept different reference types
13
13
  Scenario: Accepts a virtual element
14
14
  Given a Popper with placement bottom-start has a virtual element as its reference
15
15
  Then the top and left of the popper correspond with the virtualElement
16
-
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
4
-
5
4
  // Visit stories with different placements
6
5
  (0, _cypressCucumberPreprocessor.Given)('the Popper is rendered with placement top', () => {
7
6
  cy.visitStory('Popper', 'top');
@@ -38,45 +37,47 @@ var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preproces
38
37
  });
39
38
  (0, _cypressCucumberPreprocessor.Given)('the Popper is rendered with placement left-end', () => {
40
39
  cy.visitStory('Popper', 'left-end');
41
- }); // Directional assertions
42
- // top
40
+ });
43
41
 
42
+ // Directional assertions
43
+ // top
44
44
  (0, _cypressCucumberPreprocessor.Then)('the bottom of the popper is adjacent to the top of the reference element', () => {
45
45
  getRefAndPopperPositions().should(_ref => {
46
46
  let [refPos, popperPos] = _ref;
47
47
  expect(refPos.top).to.equal(popperPos.bottom);
48
48
  });
49
- }); // right
50
-
49
+ });
50
+ // right
51
51
  (0, _cypressCucumberPreprocessor.Then)('the left of the popper is adjacent to the right of the reference element', () => {
52
52
  getRefAndPopperPositions().should(_ref2 => {
53
53
  let [refPos, popperPos] = _ref2;
54
54
  expect(refPos.right).to.equal(popperPos.left);
55
55
  });
56
- }); // bottom
57
-
56
+ });
57
+ // bottom
58
58
  (0, _cypressCucumberPreprocessor.Then)('the top of the popper is adjacent to the bottom of the reference element', () => {
59
59
  getRefAndPopperPositions().should(_ref3 => {
60
60
  let [refPos, popperPos] = _ref3;
61
61
  expect(refPos.bottom).to.equal(popperPos.top);
62
62
  });
63
- }); // left
64
-
63
+ });
64
+ // left
65
65
  (0, _cypressCucumberPreprocessor.Then)('the right of the popper is adjacent to the left of the reference element', () => {
66
66
  getRefAndPopperPositions().should(_ref4 => {
67
67
  let [refPos, popperPos] = _ref4;
68
68
  expect(refPos.left).to.equal(popperPos.right);
69
69
  });
70
- }); // Horizontal alignments
71
- // *-start
70
+ });
72
71
 
72
+ // Horizontal alignments
73
+ // *-start
73
74
  (0, _cypressCucumberPreprocessor.Then)('it is horizontally left aligned with the reference element', () => {
74
75
  getRefAndPopperPositions().should(_ref5 => {
75
76
  let [refPos, popperPos] = _ref5;
76
77
  expect(refPos.left).to.equal(popperPos.left);
77
78
  });
78
- }); // * (no suffix)
79
-
79
+ });
80
+ // * (no suffix)
80
81
  (0, _cypressCucumberPreprocessor.Then)('it is horizontally center aligned with the reference element', () => {
81
82
  getRefAndPopperPositions().should(_ref6 => {
82
83
  let [refPos, popperPos] = _ref6;
@@ -84,23 +85,24 @@ var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preproces
84
85
  const popperCenterX = popperPos.left + popperPos.width / 2;
85
86
  expect(refCenterX).to.equal(popperCenterX);
86
87
  });
87
- }); // *-end
88
-
88
+ });
89
+ // *-end
89
90
  (0, _cypressCucumberPreprocessor.Then)('it is horizontally right aligned with the reference element', () => {
90
91
  getRefAndPopperPositions().should(_ref7 => {
91
92
  let [refPos, popperPos] = _ref7;
92
93
  expect(refPos.right).to.equal(popperPos.right);
93
94
  });
94
- }); // Vertical alignments
95
- // *-start
95
+ });
96
96
 
97
+ // Vertical alignments
98
+ // *-start
97
99
  (0, _cypressCucumberPreprocessor.Then)('it is vertically top aligned with the reference element', () => {
98
100
  getRefAndPopperPositions().should(_ref8 => {
99
101
  let [refPos, popperPos] = _ref8;
100
102
  expect(refPos.top).to.equal(popperPos.top);
101
103
  });
102
- }); // * (no suffix)
103
-
104
+ });
105
+ // * (no suffix)
104
106
  (0, _cypressCucumberPreprocessor.Then)('it is vertically center aligned with the reference element', () => {
105
107
  getRefAndPopperPositions().should(_ref9 => {
106
108
  let [refPos, popperPos] = _ref9;
@@ -108,15 +110,16 @@ var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preproces
108
110
  const popperCenterY = popperPos.top + popperPos.height / 2;
109
111
  expect(refCenterY).to.equal(popperCenterY);
110
112
  });
111
- }); // *-end
112
-
113
+ });
114
+ // *-end
113
115
  (0, _cypressCucumberPreprocessor.Then)('it is vertically bottom aligned with the reference element', () => {
114
116
  getRefAndPopperPositions().should(_ref10 => {
115
117
  let [refPos, popperPos] = _ref10;
116
118
  expect(refPos.bottom).to.equal(popperPos.bottom);
117
119
  });
118
- }); // helper
120
+ });
119
121
 
122
+ // helper
120
123
  function getRefAndPopperPositions() {
121
124
  return cy.getPositionsBySelectors('.reference-element', '[data-test="dhis2-uicore-popper"]');
122
125
  }
@@ -4,19 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getReferenceElement = void 0;
7
-
8
7
  const getReferenceElement = reference => {
9
8
  // Elements or virtualElements
10
9
  if (reference instanceof Element || reference && 'getBoundingClientRect' in reference) {
11
10
  return reference;
12
- } // react refs
13
-
11
+ }
14
12
 
13
+ // react refs
15
14
  if (reference && 'current' in reference) {
16
15
  return reference.current;
17
16
  }
18
-
19
17
  return null;
20
18
  };
21
-
22
19
  exports.getReferenceElement = getReferenceElement;
@@ -27,11 +27,7 @@ Object.defineProperty(exports, "usePopper", {
27
27
  return _reactPopper.usePopper;
28
28
  }
29
29
  });
30
-
31
30
  var _popper = require("./popper.js");
32
-
33
31
  var _getReferenceElement = require("./get-reference-element.js");
34
-
35
32
  var _modifiers = require("./modifiers.js");
36
-
37
33
  var _reactPopper = require("react-popper");
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resizeObserver = exports.getBaseModifiers = exports.deduplicateModifiers = void 0;
7
-
8
7
  var _resizeObserverPolyfill = _interopRequireDefault(require("resize-observer-polyfill"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
9
  const attachResizeObservers = _ref => {
13
10
  let {
14
11
  state: {
@@ -25,7 +22,6 @@ const attachResizeObservers = _ref => {
25
22
  observer.observe(elements[elementKey]);
26
23
  acc.push(observer);
27
24
  }
28
-
29
25
  return acc;
30
26
  }, []);
31
27
  return () => {
@@ -34,7 +30,6 @@ const attachResizeObservers = _ref => {
34
30
  });
35
31
  };
36
32
  };
37
-
38
33
  const getBaseModifiers = _ref2 => {
39
34
  let {
40
35
  observePopperResize,
@@ -65,9 +60,7 @@ const getBaseModifiers = _ref2 => {
65
60
  }
66
61
  }];
67
62
  };
68
-
69
63
  exports.getBaseModifiers = getBaseModifiers;
70
-
71
64
  const deduplicateModifiers = (modifiers, resizeObservers) => {
72
65
  // Deduplicate modifiers from props and baseModifiers,
73
66
  // when duplicates are encountered (by name), use the
@@ -79,9 +72,8 @@ const deduplicateModifiers = (modifiers, resizeObservers) => {
79
72
  return !modifiers.some(m => m.name === name);
80
73
  }).concat(modifiers);
81
74
  };
82
-
83
75
  exports.deduplicateModifiers = deduplicateModifiers;
84
- const resizeObserver = {
76
+ const resizeObserver = exports.resizeObserver = {
85
77
  name: 'resizeObserver',
86
78
  enabled: true,
87
79
  phase: 'write',
@@ -102,7 +94,6 @@ const resizeObserver = {
102
94
  observer.observe(elements[elementKey]);
103
95
  acc.push(observer);
104
96
  }
105
-
106
97
  return acc;
107
98
  }, []);
108
99
  return () => {
@@ -111,5 +102,4 @@ const resizeObserver = {
111
102
  });
112
103
  };
113
104
  }
114
- };
115
- exports.resizeObserver = resizeObserver;
105
+ };
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.VirtualElementAsReference = exports.TopStart = exports.TopEnd = exports.Top = exports.RightStart = exports.RightEnd = exports.Right = exports.ReactRefAsReference = exports.LeftStart = exports.LeftEnd = exports.Left = exports.DOMNodeAsReference = exports.BottomStart = exports.BottomEnd = exports.Bottom = void 0;
7
-
8
7
  var _style = _interopRequireDefault(require("styled-jsx/style"));
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _react = _interopRequireWildcard(require("react"));
13
-
14
10
  var _popper = require("./popper.js");
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
14
  const PopperPlacement = _ref => {
23
15
  let {
24
16
  placement
@@ -38,88 +30,61 @@ const PopperPlacement = _ref => {
38
30
  id: "305551169"
39
31
  }, [".box.jsx-305551169{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;width:400px;height:400px;margin-bottom:1000px;background-color:aliceblue;}", ".reference-element.jsx-305551169{width:100px;height:50px;background-color:cadetblue;text-align:center;padding:6px;}", ".popper-content.jsx-305551169{width:80px;height:30px;background-color:lightblue;text-align:center;padding:6px;}"]));
40
32
  };
41
-
42
33
  PopperPlacement.propTypes = {
43
34
  placement: _propTypes.default.string
44
35
  };
45
- var _default = {
36
+ var _default = exports.default = {
46
37
  title: 'Popper',
47
38
  component: _popper.Popper
48
39
  };
49
- exports.default = _default;
50
-
51
40
  const Top = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
52
41
  placement: "top"
53
42
  });
54
-
55
43
  exports.Top = Top;
56
-
57
44
  const TopStart = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
58
45
  placement: "top-start"
59
46
  });
60
-
61
47
  exports.TopStart = TopStart;
62
-
63
48
  const TopEnd = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
64
49
  placement: "top-end"
65
50
  });
66
-
67
51
  exports.TopEnd = TopEnd;
68
-
69
52
  const Bottom = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
70
53
  placement: "bottom"
71
54
  });
72
-
73
55
  exports.Bottom = Bottom;
74
-
75
56
  const BottomStart = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
76
57
  placement: "bottom-start"
77
58
  });
78
-
79
59
  exports.BottomStart = BottomStart;
80
-
81
60
  const BottomEnd = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
82
61
  placement: "bottom-end"
83
62
  });
84
-
85
63
  exports.BottomEnd = BottomEnd;
86
-
87
64
  const Right = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
88
65
  placement: "right"
89
66
  });
90
-
91
67
  exports.Right = Right;
92
-
93
68
  const RightStart = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
94
69
  placement: "right-start"
95
70
  });
96
-
97
71
  exports.RightStart = RightStart;
98
-
99
72
  const RightEnd = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
100
73
  placement: "right-end"
101
74
  });
102
-
103
75
  exports.RightEnd = RightEnd;
104
-
105
76
  const Left = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
106
77
  placement: "left"
107
78
  });
108
-
109
79
  exports.Left = Left;
110
-
111
80
  const LeftStart = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
112
81
  placement: "left-start"
113
82
  });
114
-
115
83
  exports.LeftStart = LeftStart;
116
-
117
84
  const LeftEnd = () => /*#__PURE__*/_react.default.createElement(PopperPlacement, {
118
85
  placement: "left-end"
119
86
  });
120
-
121
87
  exports.LeftEnd = LeftEnd;
122
-
123
88
  const ReactRefAsReference = () => {
124
89
  const ref = (0, _react.useRef)();
125
90
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("button", {
@@ -129,9 +94,7 @@ const ReactRefAsReference = () => {
129
94
  reference: ref
130
95
  }, "Popper"));
131
96
  };
132
-
133
97
  exports.ReactRefAsReference = ReactRefAsReference;
134
-
135
98
  const DOMNodeAsReference = () => {
136
99
  const [node, setNode] = (0, _react.useState)(null);
137
100
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("button", {
@@ -141,9 +104,7 @@ const DOMNodeAsReference = () => {
141
104
  reference: node
142
105
  }, "Popper"));
143
106
  };
144
-
145
107
  exports.DOMNodeAsReference = DOMNodeAsReference;
146
-
147
108
  const VirtualElementAsReference = () => {
148
109
  const virtualElement = {
149
110
  getBoundingClientRect: () => ({
@@ -160,5 +121,4 @@ const VirtualElementAsReference = () => {
160
121
  reference: virtualElement
161
122
  }, "Popper");
162
123
  };
163
-
164
124
  exports.VirtualElementAsReference = VirtualElementAsReference;
@@ -4,39 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Popper = void 0;
7
-
8
7
  var _uiConstants = require("@dhis2/ui-constants");
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _react = _interopRequireWildcard(require("react"));
13
-
14
10
  var _reactPopper = require("react-popper");
15
-
16
11
  var _getReferenceElement = require("./get-reference-element.js");
17
-
18
12
  var _modifiers = require("./modifiers.js");
19
-
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
-
22
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
27
-
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
28
17
  const flipPlacement = placement => {
29
18
  if (placement.startsWith('right')) {
30
19
  return placement.replace('right', 'left');
31
20
  }
32
-
33
21
  if (placement.startsWith('left')) {
34
22
  return placement.replace('left', 'right');
35
23
  }
36
-
37
24
  return placement;
38
25
  };
39
-
40
26
  const Popper = _ref => {
41
27
  let {
42
28
  children,
@@ -65,49 +51,50 @@ const Popper = _ref => {
65
51
  placement: document.documentElement.dir === 'rtl' ? flipPlacement(placement) : placement,
66
52
  modifiers: deduplicatedModifiers
67
53
  });
54
+ (0, _react.useEffect)(() => {
55
+ if (popperElement) {
56
+ var _popperElement$firstE;
57
+ popperElement === null || popperElement === void 0 ? void 0 : (_popperElement$firstE = popperElement.firstElementChild) === null || _popperElement$firstE === void 0 ? void 0 : _popperElement$firstE.focus();
58
+ }
59
+ }, [popperElement]);
68
60
  return /*#__PURE__*/_react.default.createElement("div", _extends({
69
61
  className: className,
70
62
  "data-test": dataTest,
71
63
  ref: setPopperElement,
72
64
  style: styles.popper
73
- }, attributes.popper), children);
65
+ }, attributes.popper, {
66
+ tabIndex: 0
67
+ }), children);
74
68
  };
75
-
76
69
  exports.Popper = Popper;
77
70
  Popper.defaultProps = {
78
71
  dataTest: 'dhis2-uicore-popper',
79
72
  modifiers: [],
80
73
  placement: 'auto'
81
- }; // Prop names follow the names here: https://popper.js.org/docs/v2/constructors/
74
+ };
82
75
 
76
+ // Prop names follow the names here: https://popper.js.org/docs/v2/constructors/
83
77
  Popper.propTypes = {
84
78
  /** Content inside the Popper */
85
79
  children: _propTypes.default.node.isRequired,
86
80
  className: _propTypes.default.string,
87
81
  dataTest: _propTypes.default.string,
88
-
89
82
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
90
83
  modifiers: _propTypes.default.arrayOf(_propTypes.default.shape({
91
84
  name: _propTypes.default.string,
92
85
  options: _propTypes.default.object
93
86
  })),
94
-
95
87
  /** Makes the Popper update position when the **Popper content** changes size */
96
88
  observePopperResize: _propTypes.default.bool,
97
-
98
89
  /** Makes the Popper update position when the **reference element** changes size */
99
90
  observeReferenceResize: _propTypes.default.bool,
100
-
101
91
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
102
92
  placement: _uiConstants.sharedPropTypes.popperPlacementPropType,
103
-
104
93
  /** A React ref, DOM node, or [virtual element](https://popper.js.org/docs/v2/virtual-elements/) for the popper to position itself against */
105
94
  reference: _uiConstants.sharedPropTypes.popperReferencePropType,
106
-
107
95
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
108
96
  strategy: _propTypes.default.oneOf(['absolute', 'fixed']),
109
97
  // defaults to 'absolute'
110
-
111
98
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
112
99
  onFirstUpdate: _propTypes.default.func
113
100
  };
@@ -4,21 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.VirtualElementRef = exports.TopStart = exports.TopEnd = exports.Top = exports.RightStart = exports.RightEnd = exports.Right = exports.RTL = exports.LeftStart = exports.LeftEnd = exports.Left = exports.ElementRef = exports.BottomStart = exports.BottomEnd = exports.Bottom = void 0;
7
-
8
7
  var _uiConstants = require("@dhis2/ui-constants");
9
-
10
8
  var _react = _interopRequireWildcard(require("react"));
11
-
12
9
  var _popper = require("./popper.js");
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
13
+ const description = `
14
+ A tool for adding additional information or content outside of the document flow, used for example in the Tooltip or Popover components.
13
15
 
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+ Since it's built using [Popper.js](https://popper.js.org/docs/v2/) and [react-popper](https://popper.js.org/react-popper/), some of that functionality can be accessed through the props of this component, like modifiers.
15
17
 
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
+ \`\`\`js
19
+ import { Popper } from '@dhis2/ui'
20
+ \`\`\`
17
21
 
18
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
19
-
20
- const description = "\nA tool for adding additional information or content outside of the document flow, used for example in the Tooltip or Popover components.\n\nSince it's built using [Popper.js](https://popper.js.org/docs/v2/) and [react-popper](https://popper.js.org/react-popper/), some of that functionality can be accessed through the props of this component, like modifiers.\n\n```js\nimport { Popper } from '@dhis2/ui'\n```\n\n_**Note**: Some of the stories may not look right on this page. View those examples in the 'Canvas' tab instead._\n";
21
- var _default = {
22
+ _**Note**: Some of the stories may not look right on this page. View those examples in the 'Canvas' tab instead._
23
+ `;
24
+ var _default = exports.default = {
22
25
  title: 'Popper',
23
26
  component: _popper.Popper,
24
27
  parameters: {
@@ -29,13 +32,14 @@ var _default = {
29
32
  }
30
33
  },
31
34
  argTypes: {
32
- placement: { ..._uiConstants.sharedPropTypes.popperPlacementArgType
35
+ placement: {
36
+ ..._uiConstants.sharedPropTypes.popperPlacementArgType
33
37
  },
34
- reference: { ..._uiConstants.sharedPropTypes.popperReferenceArgType
38
+ reference: {
39
+ ..._uiConstants.sharedPropTypes.popperReferenceArgType
35
40
  }
36
41
  }
37
42
  };
38
- exports.default = _default;
39
43
  const boxStyle = {
40
44
  display: 'flex',
41
45
  alignItems: 'center',
@@ -58,7 +62,6 @@ const popperStyle = {
58
62
  textAlign: 'center',
59
63
  padding: 6
60
64
  };
61
-
62
65
  const Template = args => {
63
66
  const ref = (0, _react.useRef)(null);
64
67
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -74,74 +77,61 @@ const Template = args => {
74
77
  style: popperStyle
75
78
  }, args.placement)));
76
79
  };
77
-
78
- const Top = Template.bind({});
79
- exports.Top = Top;
80
+ const Top = exports.Top = Template.bind({});
80
81
  Top.args = {
81
82
  placement: 'top'
82
83
  };
83
- const TopStart = Template.bind({});
84
- exports.TopStart = TopStart;
84
+ const TopStart = exports.TopStart = Template.bind({});
85
85
  TopStart.args = {
86
86
  placement: 'top-start'
87
87
  };
88
- const TopEnd = Template.bind({});
89
- exports.TopEnd = TopEnd;
88
+ const TopEnd = exports.TopEnd = Template.bind({});
90
89
  TopEnd.args = {
91
90
  placement: 'top-end'
92
91
  };
93
- const Bottom = Template.bind({});
94
- exports.Bottom = Bottom;
92
+ const Bottom = exports.Bottom = Template.bind({});
95
93
  Bottom.args = {
96
94
  placement: 'bottom'
97
95
  };
98
- const BottomStart = Template.bind({});
99
- exports.BottomStart = BottomStart;
96
+ const BottomStart = exports.BottomStart = Template.bind({});
100
97
  BottomStart.args = {
101
98
  placement: 'bottom-start'
102
99
  };
103
- const BottomEnd = Template.bind({});
104
- exports.BottomEnd = BottomEnd;
100
+ const BottomEnd = exports.BottomEnd = Template.bind({});
105
101
  BottomEnd.args = {
106
102
  placement: 'bottom-end'
107
103
  };
108
- const Right = Template.bind({});
109
- exports.Right = Right;
104
+ const Right = exports.Right = Template.bind({});
110
105
  Right.args = {
111
106
  placement: 'right'
112
107
  };
113
- const RightStart = Template.bind({});
114
- exports.RightStart = RightStart;
108
+ const RightStart = exports.RightStart = Template.bind({});
115
109
  RightStart.args = {
116
110
  placement: 'right-start'
117
111
  };
118
- const RightEnd = Template.bind({});
119
- exports.RightEnd = RightEnd;
112
+ const RightEnd = exports.RightEnd = Template.bind({});
120
113
  RightEnd.args = {
121
114
  placement: 'right-end'
122
115
  };
123
- const Left = Template.bind({});
124
- exports.Left = Left;
116
+ const Left = exports.Left = Template.bind({});
125
117
  Left.args = {
126
118
  placement: 'left'
127
119
  };
128
- const LeftStart = Template.bind({});
129
- exports.LeftStart = LeftStart;
120
+ const LeftStart = exports.LeftStart = Template.bind({});
130
121
  LeftStart.args = {
131
122
  placement: 'left-start'
132
123
  };
133
- const LeftEnd = Template.bind({});
134
- exports.LeftEnd = LeftEnd;
124
+ const LeftEnd = exports.LeftEnd = Template.bind({});
135
125
  LeftEnd.args = {
136
126
  placement: 'left-end'
137
127
  };
138
-
139
128
  const ElementRef = args => {
140
129
  const anchor = document.createElement('div');
141
130
  document.body.appendChild(anchor);
142
131
  return /*#__PURE__*/_react.default.createElement("div", {
143
132
  className: "box",
144
- style: { ...boxStyle,
133
+ style: {
134
+ ...boxStyle,
145
135
  marginBottom: '500px'
146
136
  }
147
137
  }, /*#__PURE__*/_react.default.createElement(_popper.Popper, _extends({}, args, {
@@ -150,7 +140,6 @@ const ElementRef = args => {
150
140
  style: popperStyle
151
141
  }, args.placement)));
152
142
  };
153
-
154
143
  exports.ElementRef = ElementRef;
155
144
  ElementRef.args = {
156
145
  placement: 'left-end'
@@ -162,7 +151,6 @@ ElementRef.parameters = {
162
151
  }
163
152
  }
164
153
  };
165
-
166
154
  const VirtualElementRef = args => {
167
155
  const virtualElement = {
168
156
  getBoundingClientRect: () => ({
@@ -178,7 +166,8 @@ const VirtualElementRef = args => {
178
166
  };
179
167
  return /*#__PURE__*/_react.default.createElement("div", {
180
168
  className: "box",
181
- style: { ...boxStyle,
169
+ style: {
170
+ ...boxStyle,
182
171
  marginBottom: '500px'
183
172
  }
184
173
  }, /*#__PURE__*/_react.default.createElement(_popper.Popper, _extends({}, args, {
@@ -187,7 +176,6 @@ const VirtualElementRef = args => {
187
176
  style: popperStyle
188
177
  }, args.placement)));
189
178
  };
190
-
191
179
  exports.VirtualElementRef = VirtualElementRef;
192
180
  VirtualElementRef.args = {
193
181
  placement: 'left-end'
@@ -199,7 +187,6 @@ VirtualElementRef.parameters = {
199
187
  }
200
188
  }
201
189
  };
202
-
203
190
  const RTL = args => {
204
191
  (0, _react.useEffect)(() => {
205
192
  document.documentElement.setAttribute('dir', 'rtl');
@@ -215,5 +202,4 @@ const RTL = args => {
215
202
  placement: "right-start"
216
203
  })));
217
204
  };
218
-
219
205
  exports.RTL = RTL;
@@ -9,25 +9,25 @@ Given('a Popper with placement bottom-start has a virtual element as its referen
9
9
  cy.visitStory('Popper', 'Virtual Element As Reference');
10
10
  });
11
11
  Then('the left of the popper is aligned with the left of the reference element', () => {
12
- cy.all(() => cy.get('button'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref => {
12
+ cy.all(() => cy.get('button:contains("Reference")'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref => {
13
13
  let [$reference, $popper] = _ref;
14
14
  const referenceRect = $reference.get(0).getBoundingClientRect();
15
15
  const popperRect = $popper.get(0).getBoundingClientRect();
16
- expect(referenceRect.left).to.equal(popperRect.left);
16
+ expect(referenceRect.left).to.be.closeTo(popperRect.left, 1);
17
17
  });
18
18
  });
19
19
  Then('the top of the popper is adjacent to the bottom of the reference element', () => {
20
- cy.all(() => cy.get('button'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref2 => {
21
- let [$reference, $popper] = _ref2;
22
- const referenceRect = $reference.get(0).getBoundingClientRect();
20
+ cy.all(() => cy.get('button:contains("Reference")'), () => cy.get('[data-test="dhis2-uicore-popper"]')).should(_ref2 => {
21
+ let [$button, $popper] = _ref2;
22
+ const buttonRect = $button.get(0).getBoundingClientRect();
23
23
  const popperRect = $popper.get(0).getBoundingClientRect();
24
- expect(Math.round(referenceRect.bottom)).to.equal(Math.round(popperRect.top));
24
+ expect(buttonRect.bottom).to.be.closeTo(popperRect.top, 1);
25
25
  });
26
26
  });
27
27
  Then('the top and left of the popper correspond with the virtualElement', () => {
28
28
  cy.get('[data-test="dhis2-uicore-popper"]').should($popper => {
29
29
  const popperRect = $popper.get(0).getBoundingClientRect();
30
- expect(popperRect.top).to.equal(200);
31
- expect(popperRect.left).to.equal(200);
30
+ expect(popperRect.top).to.be.closeTo(200, 1);
31
+ expect(popperRect.left).to.be.closeTo(200, 1);
32
32
  });
33
33
  });
@@ -13,4 +13,3 @@ Feature: Accept different reference types
13
13
  Scenario: Accepts a virtual element
14
14
  Given a Popper with placement bottom-start has a virtual element as its reference
15
15
  Then the top and left of the popper correspond with the virtualElement
16
-
@@ -1,5 +1,6 @@
1
- import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'; // Visit stories with different placements
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
2
2
 
3
+ // Visit stories with different placements
3
4
  Given('the Popper is rendered with placement top', () => {
4
5
  cy.visitStory('Popper', 'top');
5
6
  });
@@ -35,45 +36,47 @@ Given('the Popper is rendered with placement left-start', () => {
35
36
  });
36
37
  Given('the Popper is rendered with placement left-end', () => {
37
38
  cy.visitStory('Popper', 'left-end');
38
- }); // Directional assertions
39
- // top
39
+ });
40
40
 
41
+ // Directional assertions
42
+ // top
41
43
  Then('the bottom of the popper is adjacent to the top of the reference element', () => {
42
44
  getRefAndPopperPositions().should(_ref => {
43
45
  let [refPos, popperPos] = _ref;
44
46
  expect(refPos.top).to.equal(popperPos.bottom);
45
47
  });
46
- }); // right
47
-
48
+ });
49
+ // right
48
50
  Then('the left of the popper is adjacent to the right of the reference element', () => {
49
51
  getRefAndPopperPositions().should(_ref2 => {
50
52
  let [refPos, popperPos] = _ref2;
51
53
  expect(refPos.right).to.equal(popperPos.left);
52
54
  });
53
- }); // bottom
54
-
55
+ });
56
+ // bottom
55
57
  Then('the top of the popper is adjacent to the bottom of the reference element', () => {
56
58
  getRefAndPopperPositions().should(_ref3 => {
57
59
  let [refPos, popperPos] = _ref3;
58
60
  expect(refPos.bottom).to.equal(popperPos.top);
59
61
  });
60
- }); // left
61
-
62
+ });
63
+ // left
62
64
  Then('the right of the popper is adjacent to the left of the reference element', () => {
63
65
  getRefAndPopperPositions().should(_ref4 => {
64
66
  let [refPos, popperPos] = _ref4;
65
67
  expect(refPos.left).to.equal(popperPos.right);
66
68
  });
67
- }); // Horizontal alignments
68
- // *-start
69
+ });
69
70
 
71
+ // Horizontal alignments
72
+ // *-start
70
73
  Then('it is horizontally left aligned with the reference element', () => {
71
74
  getRefAndPopperPositions().should(_ref5 => {
72
75
  let [refPos, popperPos] = _ref5;
73
76
  expect(refPos.left).to.equal(popperPos.left);
74
77
  });
75
- }); // * (no suffix)
76
-
78
+ });
79
+ // * (no suffix)
77
80
  Then('it is horizontally center aligned with the reference element', () => {
78
81
  getRefAndPopperPositions().should(_ref6 => {
79
82
  let [refPos, popperPos] = _ref6;
@@ -81,23 +84,24 @@ Then('it is horizontally center aligned with the reference element', () => {
81
84
  const popperCenterX = popperPos.left + popperPos.width / 2;
82
85
  expect(refCenterX).to.equal(popperCenterX);
83
86
  });
84
- }); // *-end
85
-
87
+ });
88
+ // *-end
86
89
  Then('it is horizontally right aligned with the reference element', () => {
87
90
  getRefAndPopperPositions().should(_ref7 => {
88
91
  let [refPos, popperPos] = _ref7;
89
92
  expect(refPos.right).to.equal(popperPos.right);
90
93
  });
91
- }); // Vertical alignments
92
- // *-start
94
+ });
93
95
 
96
+ // Vertical alignments
97
+ // *-start
94
98
  Then('it is vertically top aligned with the reference element', () => {
95
99
  getRefAndPopperPositions().should(_ref8 => {
96
100
  let [refPos, popperPos] = _ref8;
97
101
  expect(refPos.top).to.equal(popperPos.top);
98
102
  });
99
- }); // * (no suffix)
100
-
103
+ });
104
+ // * (no suffix)
101
105
  Then('it is vertically center aligned with the reference element', () => {
102
106
  getRefAndPopperPositions().should(_ref9 => {
103
107
  let [refPos, popperPos] = _ref9;
@@ -105,15 +109,16 @@ Then('it is vertically center aligned with the reference element', () => {
105
109
  const popperCenterY = popperPos.top + popperPos.height / 2;
106
110
  expect(refCenterY).to.equal(popperCenterY);
107
111
  });
108
- }); // *-end
109
-
112
+ });
113
+ // *-end
110
114
  Then('it is vertically bottom aligned with the reference element', () => {
111
115
  getRefAndPopperPositions().should(_ref10 => {
112
116
  let [refPos, popperPos] = _ref10;
113
117
  expect(refPos.bottom).to.equal(popperPos.bottom);
114
118
  });
115
- }); // helper
119
+ });
116
120
 
121
+ // helper
117
122
  function getRefAndPopperPositions() {
118
123
  return cy.getPositionsBySelectors('.reference-element', '[data-test="dhis2-uicore-popper"]');
119
124
  }
@@ -2,12 +2,11 @@ export const getReferenceElement = reference => {
2
2
  // Elements or virtualElements
3
3
  if (reference instanceof Element || reference && 'getBoundingClientRect' in reference) {
4
4
  return reference;
5
- } // react refs
6
-
5
+ }
7
6
 
7
+ // react refs
8
8
  if (reference && 'current' in reference) {
9
9
  return reference.current;
10
10
  }
11
-
12
11
  return null;
13
12
  };
@@ -1,5 +1,4 @@
1
1
  import ResizeObserver from 'resize-observer-polyfill';
2
-
3
2
  const attachResizeObservers = _ref => {
4
3
  let {
5
4
  state: {
@@ -16,7 +15,6 @@ const attachResizeObservers = _ref => {
16
15
  observer.observe(elements[elementKey]);
17
16
  acc.push(observer);
18
17
  }
19
-
20
18
  return acc;
21
19
  }, []);
22
20
  return () => {
@@ -25,7 +23,6 @@ const attachResizeObservers = _ref => {
25
23
  });
26
24
  };
27
25
  };
28
-
29
26
  export const getBaseModifiers = _ref2 => {
30
27
  let {
31
28
  observePopperResize,
@@ -88,7 +85,6 @@ export const resizeObserver = {
88
85
  observer.observe(elements[elementKey]);
89
86
  acc.push(observer);
90
87
  }
91
-
92
88
  return acc;
93
89
  }, []);
94
90
  return () => {
@@ -2,7 +2,6 @@ import _JSXStyle from "styled-jsx/style";
2
2
  import PropTypes from 'prop-types';
3
3
  import React, { useRef, useState } from 'react';
4
4
  import { Popper } from './popper.js';
5
-
6
5
  const PopperPlacement = _ref => {
7
6
  let {
8
7
  placement
@@ -22,7 +21,6 @@ const PopperPlacement = _ref => {
22
21
  id: "305551169"
23
22
  }, [".box.jsx-305551169{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;width:400px;height:400px;margin-bottom:1000px;background-color:aliceblue;}", ".reference-element.jsx-305551169{width:100px;height:50px;background-color:cadetblue;text-align:center;padding:6px;}", ".popper-content.jsx-305551169{width:80px;height:30px;background-color:lightblue;text-align:center;padding:6px;}"]));
24
23
  };
25
-
26
24
  PopperPlacement.propTypes = {
27
25
  placement: PropTypes.string
28
26
  };
@@ -1,24 +1,19 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
2
  import { sharedPropTypes } from '@dhis2/ui-constants';
4
3
  import PropTypes from 'prop-types';
5
- import React, { useState, useMemo } from 'react';
4
+ import React, { useState, useMemo, useEffect } from 'react';
6
5
  import { usePopper } from 'react-popper';
7
6
  import { getReferenceElement } from './get-reference-element.js';
8
7
  import { deduplicateModifiers } from './modifiers.js';
9
-
10
8
  const flipPlacement = placement => {
11
9
  if (placement.startsWith('right')) {
12
10
  return placement.replace('right', 'left');
13
11
  }
14
-
15
12
  if (placement.startsWith('left')) {
16
13
  return placement.replace('left', 'right');
17
14
  }
18
-
19
15
  return placement;
20
16
  };
21
-
22
17
  const Popper = _ref => {
23
18
  let {
24
19
  children,
@@ -47,48 +42,49 @@ const Popper = _ref => {
47
42
  placement: document.documentElement.dir === 'rtl' ? flipPlacement(placement) : placement,
48
43
  modifiers: deduplicatedModifiers
49
44
  });
45
+ useEffect(() => {
46
+ if (popperElement) {
47
+ var _popperElement$firstE;
48
+ popperElement === null || popperElement === void 0 ? void 0 : (_popperElement$firstE = popperElement.firstElementChild) === null || _popperElement$firstE === void 0 ? void 0 : _popperElement$firstE.focus();
49
+ }
50
+ }, [popperElement]);
50
51
  return /*#__PURE__*/React.createElement("div", _extends({
51
52
  className: className,
52
53
  "data-test": dataTest,
53
54
  ref: setPopperElement,
54
55
  style: styles.popper
55
- }, attributes.popper), children);
56
+ }, attributes.popper, {
57
+ tabIndex: 0
58
+ }), children);
56
59
  };
57
-
58
60
  Popper.defaultProps = {
59
61
  dataTest: 'dhis2-uicore-popper',
60
62
  modifiers: [],
61
63
  placement: 'auto'
62
- }; // Prop names follow the names here: https://popper.js.org/docs/v2/constructors/
64
+ };
63
65
 
66
+ // Prop names follow the names here: https://popper.js.org/docs/v2/constructors/
64
67
  Popper.propTypes = {
65
68
  /** Content inside the Popper */
66
69
  children: PropTypes.node.isRequired,
67
70
  className: PropTypes.string,
68
71
  dataTest: PropTypes.string,
69
-
70
72
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
71
73
  modifiers: PropTypes.arrayOf(PropTypes.shape({
72
74
  name: PropTypes.string,
73
75
  options: PropTypes.object
74
76
  })),
75
-
76
77
  /** Makes the Popper update position when the **Popper content** changes size */
77
78
  observePopperResize: PropTypes.bool,
78
-
79
79
  /** Makes the Popper update position when the **reference element** changes size */
80
80
  observeReferenceResize: PropTypes.bool,
81
-
82
81
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
83
82
  placement: sharedPropTypes.popperPlacementPropType,
84
-
85
83
  /** A React ref, DOM node, or [virtual element](https://popper.js.org/docs/v2/virtual-elements/) for the popper to position itself against */
86
84
  reference: sharedPropTypes.popperReferencePropType,
87
-
88
85
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
89
86
  strategy: PropTypes.oneOf(['absolute', 'fixed']),
90
87
  // defaults to 'absolute'
91
-
92
88
  /** A property of the `createPopper` options. See [popper docs](https://popper.js.org/docs/v2/constructors/) */
93
89
  onFirstUpdate: PropTypes.func
94
90
  };
@@ -1,9 +1,18 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
2
  import { sharedPropTypes } from '@dhis2/ui-constants';
4
3
  import React, { useEffect, useRef } from 'react';
5
4
  import { Popper } from './popper.js';
6
- const description = "\nA tool for adding additional information or content outside of the document flow, used for example in the Tooltip or Popover components.\n\nSince it's built using [Popper.js](https://popper.js.org/docs/v2/) and [react-popper](https://popper.js.org/react-popper/), some of that functionality can be accessed through the props of this component, like modifiers.\n\n```js\nimport { Popper } from '@dhis2/ui'\n```\n\n_**Note**: Some of the stories may not look right on this page. View those examples in the 'Canvas' tab instead._\n";
5
+ const description = `
6
+ A tool for adding additional information or content outside of the document flow, used for example in the Tooltip or Popover components.
7
+
8
+ Since it's built using [Popper.js](https://popper.js.org/docs/v2/) and [react-popper](https://popper.js.org/react-popper/), some of that functionality can be accessed through the props of this component, like modifiers.
9
+
10
+ \`\`\`js
11
+ import { Popper } from '@dhis2/ui'
12
+ \`\`\`
13
+
14
+ _**Note**: Some of the stories may not look right on this page. View those examples in the 'Canvas' tab instead._
15
+ `;
7
16
  export default {
8
17
  title: 'Popper',
9
18
  component: Popper,
@@ -15,9 +24,11 @@ export default {
15
24
  }
16
25
  },
17
26
  argTypes: {
18
- placement: { ...sharedPropTypes.popperPlacementArgType
27
+ placement: {
28
+ ...sharedPropTypes.popperPlacementArgType
19
29
  },
20
- reference: { ...sharedPropTypes.popperReferenceArgType
30
+ reference: {
31
+ ...sharedPropTypes.popperReferenceArgType
21
32
  }
22
33
  }
23
34
  };
@@ -43,7 +54,6 @@ const popperStyle = {
43
54
  textAlign: 'center',
44
55
  padding: 6
45
56
  };
46
-
47
57
  const Template = args => {
48
58
  const ref = useRef(null);
49
59
  return /*#__PURE__*/React.createElement("div", {
@@ -59,7 +69,6 @@ const Template = args => {
59
69
  style: popperStyle
60
70
  }, args.placement)));
61
71
  };
62
-
63
72
  export const Top = Template.bind({});
64
73
  Top.args = {
65
74
  placement: 'top'
@@ -113,7 +122,8 @@ export const ElementRef = args => {
113
122
  document.body.appendChild(anchor);
114
123
  return /*#__PURE__*/React.createElement("div", {
115
124
  className: "box",
116
- style: { ...boxStyle,
125
+ style: {
126
+ ...boxStyle,
117
127
  marginBottom: '500px'
118
128
  }
119
129
  }, /*#__PURE__*/React.createElement(Popper, _extends({}, args, {
@@ -147,7 +157,8 @@ export const VirtualElementRef = args => {
147
157
  };
148
158
  return /*#__PURE__*/React.createElement("div", {
149
159
  className: "box",
150
- style: { ...boxStyle,
160
+ style: {
161
+ ...boxStyle,
151
162
  marginBottom: '500px'
152
163
  }
153
164
  }, /*#__PURE__*/React.createElement(Popper, _extends({}, args, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/popper",
3
- "version": "9.10.3",
3
+ "version": "9.11.1-beta.1",
4
4
  "description": "UI Popper",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,18 +22,18 @@
22
22
  "access": "public"
23
23
  },
24
24
  "scripts": {
25
- "start": "start-storybook -c ../../storybook/config --port 5000",
25
+ "start": "storybook dev -c ../../storybook/config --port 5000",
26
26
  "build": "d2-app-scripts build",
27
27
  "test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
28
28
  },
29
29
  "peerDependencies": {
30
- "react": "^16.8",
31
- "react-dom": "^16.8",
30
+ "react": "^16.13",
31
+ "react-dom": "^16.13",
32
32
  "styled-jsx": "^4"
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2/ui-constants": "9.10.3",
36
+ "@dhis2/ui-constants": "9.11.1-beta.1",
37
37
  "@popperjs/core": "^2.10.1",
38
38
  "classnames": "^2.3.1",
39
39
  "prop-types": "^15.7.2",