@dhis2-ui/popover 9.11.0 → 9.11.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,28 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Arrow = exports.ARROW_SIZE = void 0;
7
-
8
7
  var _style = _interopRequireDefault(require("styled-jsx/style"));
9
-
10
8
  var _uiConstants = require("@dhis2/ui-constants");
11
-
12
9
  var _classnames = _interopRequireDefault(require("classnames"));
13
-
14
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
15
-
16
11
  var _react = _interopRequireWildcard(require("react"));
17
-
18
12
  var _getArrowPosition = require("./get-arrow-position.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
- const ARROW_SIZE = 8;
27
- exports.ARROW_SIZE = ARROW_SIZE;
28
- const Arrow = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
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
+ const ARROW_SIZE = exports.ARROW_SIZE = 8;
17
+ const Arrow = exports.Arrow = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
29
18
  let {
30
19
  hidden,
31
20
  popperPlacement,
@@ -41,9 +30,8 @@ const Arrow = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
41
30
  }, /*#__PURE__*/_react.default.createElement(_style.default, {
42
31
  id: "1397459397",
43
32
  dynamic: [ARROW_SIZE, ARROW_SIZE, ARROW_SIZE / 2, ARROW_SIZE / 2, ARROW_SIZE / 2, ARROW_SIZE / 2, ARROW_SIZE / 2, _uiConstants.colors.white, _uiConstants.colors.white]
44
- }, ["div.__jsx-style-dynamic-selector{width:".concat(ARROW_SIZE, "px;height:").concat(ARROW_SIZE, "px;position:absolute;}"), "div.top.__jsx-style-dynamic-selector{top:-".concat(ARROW_SIZE / 2, "px;}"), "div.right.__jsx-style-dynamic-selector{right:-".concat(ARROW_SIZE / 2, "px;}"), "div.bottom.__jsx-style-dynamic-selector{bottom:-".concat(ARROW_SIZE / 2, "px;}"), "div.left.__jsx-style-dynamic-selector{left:-".concat(ARROW_SIZE / 2, "px;}"), "div.hidden.__jsx-style-dynamic-selector{visibility:hidden;}", "div.__jsx-style-dynamic-selector::after{content:'';position:absolute;pointer-events:none;box-sizing:border-box;border-style:solid;border-width:".concat(ARROW_SIZE / 2, "px;border-color:transparent transparent ").concat(_uiConstants.colors.white, " ").concat(_uiConstants.colors.white, ";box-shadow:-1px 1px 1px 0 rgba(64,75,90,0.08), -3px 3px 8px -6px rgba(64,75,90,0.15);}"), "div.bottom.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-45deg);-ms-transform:rotate(-45deg);transform:rotate(-45deg);}", "div.top.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(135deg);-ms-transform:rotate(135deg);transform:rotate(135deg);}", "div.right.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-135deg);-ms-transform:rotate(-135deg);transform:rotate(-135deg);}", "div.left.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);}"]));
33
+ }, [`div.__jsx-style-dynamic-selector{width:${ARROW_SIZE}px;height:${ARROW_SIZE}px;position:absolute;}`, `div.top.__jsx-style-dynamic-selector{top:-${ARROW_SIZE / 2}px;}`, `div.right.__jsx-style-dynamic-selector{right:-${ARROW_SIZE / 2}px;}`, `div.bottom.__jsx-style-dynamic-selector{bottom:-${ARROW_SIZE / 2}px;}`, `div.left.__jsx-style-dynamic-selector{left:-${ARROW_SIZE / 2}px;}`, "div.hidden.__jsx-style-dynamic-selector{visibility:hidden;}", `div.__jsx-style-dynamic-selector::after{content:'';position:absolute;pointer-events:none;box-sizing:border-box;border-style:solid;border-width:${ARROW_SIZE / 2}px;border-color:transparent transparent ${_uiConstants.colors.white} ${_uiConstants.colors.white};box-shadow:-1px 1px 1px 0 rgba(64,75,90,0.08), -3px 3px 8px -6px rgba(64,75,90,0.15);}`, "div.bottom.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-45deg);-ms-transform:rotate(-45deg);transform:rotate(-45deg);}", "div.top.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(135deg);-ms-transform:rotate(135deg);transform:rotate(135deg);}", "div.right.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-135deg);-ms-transform:rotate(-135deg);transform:rotate(-135deg);}", "div.left.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);}"]));
45
34
  });
46
- exports.Arrow = Arrow;
47
35
  Arrow.displayName = 'Arrow';
48
36
  Arrow.propTypes = {
49
37
  hidden: _propTypes.default.bool,
@@ -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 Popover is rendered with placement top', () => {
6
5
  cy.visitStory('Popover', 'Placement Top');
7
6
  });
@@ -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 default Popper is rendered with arrow set to true', () => {
6
5
  cy.visitStory('Popover', 'Default');
7
6
  });
@@ -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 default Popper is rendered with arrow set to true', () => {
6
5
  cy.visitStory('Popover', 'Default');
7
6
  });
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
4
+ const CLOSE_TO_DELTA = 1;
4
5
 
5
- const CLOSE_TO_DELTA = 1; // Stories
6
-
6
+ // Stories
7
7
  (0, _cypressCucumberPreprocessor.Given)('there is sufficient space to place the Popover above the reference element', () => {
8
8
  cy.visitStory('Popover', 'Default');
9
9
  });
@@ -12,8 +12,9 @@ const CLOSE_TO_DELTA = 1; // Stories
12
12
  });
13
13
  (0, _cypressCucumberPreprocessor.Given)('there is very little space between the top of the reference element and the top of the body', () => {
14
14
  cy.visitStory('Popover', 'Hidden Arrow');
15
- }); // Window height manipulation to control the space below the reference element
15
+ });
16
16
 
17
+ // Window height manipulation to control the space below the reference element
17
18
  (0, _cypressCucumberPreprocessor.Given)('there is sufficient space between the reference element bottom and the body bottom to fit the Popover', () => {
18
19
  cy.viewport(1000, 660);
19
20
  });
@@ -22,8 +23,9 @@ const CLOSE_TO_DELTA = 1; // Stories
22
23
  });
23
24
  (0, _cypressCucumberPreprocessor.Given)('there is not enough space between the top of the reference element and the top of the Popover to show the arrow', () => {
24
25
  cy.viewport(1000, 380);
25
- }); // Assertions
26
+ });
26
27
 
28
+ // Assertions
27
29
  (0, _cypressCucumberPreprocessor.Given)('there is sufficient space between the bottom of the reference element and the bottom of the Popover to show the arrow', () => {
28
30
  compareRefAndPopoverPositions((refPos, popoverPos) => {
29
31
  expect(refPos.bottom).to.be.greaterThan(popoverPos.bottom + 8);
@@ -62,8 +64,9 @@ const CLOSE_TO_DELTA = 1; // Stories
62
64
  compareRefAndPopoverPositions((refPos, popoverPos) => {
63
65
  expect(popoverPos.bottom + 8).to.be.closeTo(refPos.top, CLOSE_TO_DELTA);
64
66
  });
65
- }); // helper
67
+ });
66
68
 
69
+ // helper
67
70
  const compareRefAndPopoverPositions = callback => {
68
71
  // this needs to be done as the cypress reference to the popover is lost
69
72
  // once react re-renders it to adjust to the changed viewport size,
@@ -4,26 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getArrowPosition = void 0;
7
-
8
7
  const getArrowPosition = popperPlacement => {
9
8
  const direction = typeof popperPlacement === 'string' ? popperPlacement.split('-')[0] : '';
10
-
11
9
  switch (direction) {
12
10
  case 'top':
13
11
  return 'bottom';
14
-
15
12
  case 'right':
16
13
  return 'left';
17
-
18
14
  case 'bottom':
19
15
  return 'top';
20
-
21
16
  case 'left':
22
17
  return 'right';
23
-
24
18
  default:
25
19
  return '';
26
20
  }
27
21
  };
28
-
29
22
  exports.getArrowPosition = getArrowPosition;
@@ -9,5 +9,4 @@ Object.defineProperty(exports, "Popover", {
9
9
  return _popover.Popover;
10
10
  }
11
11
  });
12
-
13
12
  var _popover = require("./popover.js");
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.combineModifiers = void 0;
7
-
8
7
  var _popper = require("@dhis2-ui/popper");
9
-
10
8
  var _arrow = require("./arrow.js");
11
-
12
9
  const BORDER_RADIUS = 4;
13
-
14
10
  const computeArrowPadding = () => {
15
11
  // pythagoras
16
12
  const diagonal = Math.sqrt(2 * Math.pow(_arrow.ARROW_SIZE, 2));
@@ -18,7 +14,6 @@ const computeArrowPadding = () => {
18
14
  const padding = BORDER_RADIUS + overflowInPx;
19
15
  return Math.ceil(padding);
20
16
  };
21
-
22
17
  const hideArrowWhenDisplaced = _ref => {
23
18
  let {
24
19
  state
@@ -27,22 +22,17 @@ const hideArrowWhenDisplaced = _ref => {
27
22
  const displacement = state.modifiersData.preventOverflow;
28
23
  const referenceRect = state.rects.reference;
29
24
  const shouldHideArrow = Math.abs(displacement.x) >= referenceRect.width + halfArrow || Math.abs(displacement.y) >= referenceRect.height + halfArrow;
30
-
31
25
  if (typeof state.attributes.arrow !== 'object') {
32
26
  state.attributes.arrow = {};
33
27
  }
34
-
35
28
  state.attributes.arrow['data-arrow-hidden'] = shouldHideArrow;
36
29
  return state;
37
30
  };
38
-
39
31
  const combineModifiers = (arrow, arrowElement, resizeObservers) => {
40
32
  const baseModifiers = (0, _popper.getBaseModifiers)(resizeObservers);
41
-
42
33
  if (!arrow) {
43
34
  return baseModifiers;
44
35
  }
45
-
46
36
  return [...baseModifiers, {
47
37
  name: 'offset',
48
38
  options: {
@@ -62,5 +52,4 @@ const combineModifiers = (arrow, arrowElement, resizeObservers) => {
62
52
  requires: ['preventOverflow']
63
53
  }];
64
54
  };
65
-
66
55
  exports.combineModifiers = combineModifiers;
@@ -4,23 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.WithOnClickOutside = exports.ShiftedArrow = exports.PlacementTop = exports.PlacementRight = exports.PlacementLeft = exports.PlacementBottom = exports.NoArrow = exports.HiddenArrow = exports.Flipped = exports.Default = void 0;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  var _react = _interopRequireWildcard(require("react"));
11
-
12
9
  var _popover = require("./popover.js");
13
-
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); }
15
-
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; }
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- 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); }
21
-
22
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
-
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 _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ 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); }
14
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
16
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
24
17
  const boxStyle = {
25
18
  display: 'flex',
26
19
  justifyContent: 'center',
@@ -34,14 +27,11 @@ const referenceElementStyle = {
34
27
  textAlign: 'center',
35
28
  padding: 6
36
29
  };
37
-
38
30
  class PopperInBoxWithCenteredReferenceElement extends _react.Component {
39
31
  constructor() {
40
32
  super(...arguments);
41
-
42
33
  _defineProperty(this, "ref", /*#__PURE__*/(0, _react.createRef)());
43
34
  }
44
-
45
35
  render() {
46
36
  const {
47
37
  paddingTop,
@@ -50,7 +40,8 @@ class PopperInBoxWithCenteredReferenceElement extends _react.Component {
50
40
  ...popoverProps
51
41
  } = this.props;
52
42
  return /*#__PURE__*/_react.default.createElement("div", {
53
- style: { ...boxStyle,
43
+ style: {
44
+ ...boxStyle,
54
45
  paddingTop,
55
46
  height: paddingTop + 100
56
47
  }
@@ -68,9 +59,7 @@ class PopperInBoxWithCenteredReferenceElement extends _react.Component {
68
59
  }
69
60
  }, "I am in a box with width: ", popoverWidth, "px and height:", ' ', popoverHeight, "px")));
70
61
  }
71
-
72
62
  }
73
-
74
63
  PopperInBoxWithCenteredReferenceElement.defaultProps = {
75
64
  paddingTop: 220,
76
65
  popoverHeight: 200,
@@ -82,16 +71,12 @@ PopperInBoxWithCenteredReferenceElement.propTypes = {
82
71
  popoverWidth: _propTypes.default.number
83
72
  };
84
73
  window.onClickOutside = window.Cypress && window.Cypress.cy.stub();
85
- var _default = {
74
+ var _default = exports.default = {
86
75
  title: 'Popover',
87
76
  component: _popover.Popover
88
77
  };
89
- exports.default = _default;
90
-
91
78
  const Default = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, null);
92
-
93
79
  exports.Default = Default;
94
-
95
80
  const Flipped = () =>
96
81
  /*#__PURE__*/
97
82
  // default viewport-height for flipped popover
@@ -99,71 +84,54 @@ const Flipped = () =>
99
84
  _react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
100
85
  paddingTop: 160
101
86
  });
102
-
103
87
  exports.Flipped = Flipped;
104
-
105
88
  const HiddenArrow = () =>
106
89
  /*#__PURE__*/
107
90
  // viewPort height 325px
108
91
  _react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
109
92
  paddingTop: 110
110
93
  });
111
-
112
94
  exports.HiddenArrow = HiddenArrow;
113
-
114
95
  const NoArrow = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
115
96
  arrow: false
116
97
  });
117
-
118
98
  exports.NoArrow = NoArrow;
119
-
120
99
  const WithOnClickOutside = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
121
100
  onClickOutside: window.onClickOutside
122
101
  });
123
-
124
102
  exports.WithOnClickOutside = WithOnClickOutside;
125
-
126
103
  const PlacementTop = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
127
104
  popoverHeight: 40,
128
105
  popoverWidth: 180,
129
106
  paddingTop: 50,
130
107
  placement: "top"
131
108
  });
132
-
133
109
  exports.PlacementTop = PlacementTop;
134
-
135
110
  const PlacementRight = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
136
111
  popoverHeight: 60,
137
112
  popoverWidth: 130,
138
113
  paddingTop: 50,
139
114
  placement: "right"
140
115
  });
141
-
142
116
  exports.PlacementRight = PlacementRight;
143
-
144
117
  const PlacementBottom = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
145
118
  popoverHeight: 40,
146
119
  popoverWidth: 180,
147
120
  paddingTop: 50,
148
121
  placement: "bottom"
149
122
  });
150
-
151
123
  exports.PlacementBottom = PlacementBottom;
152
-
153
124
  const PlacementLeft = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
154
125
  popoverHeight: 60,
155
126
  popoverWidth: 130,
156
127
  paddingTop: 50,
157
128
  placement: "left"
158
129
  });
159
-
160
130
  exports.PlacementLeft = PlacementLeft;
161
-
162
131
  const ShiftedArrow = () => /*#__PURE__*/_react.default.createElement(PopperInBoxWithCenteredReferenceElement, {
163
132
  popoverHeight: 160,
164
133
  popoverWidth: 130,
165
134
  paddingTop: 1,
166
135
  placement: "left"
167
136
  });
168
-
169
137
  exports.ShiftedArrow = ShiftedArrow;
@@ -4,31 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Popover = void 0;
7
-
8
7
  var _style = _interopRequireDefault(require("styled-jsx/style"));
9
-
8
+ var _uiConstants = require("@dhis2/ui-constants");
10
9
  var _layer = require("@dhis2-ui/layer");
11
-
12
10
  var _popper = require("@dhis2-ui/popper");
13
-
14
- var _uiConstants = require("@dhis2/ui-constants");
15
-
16
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
17
-
18
12
  var _react = _interopRequireWildcard(require("react"));
19
-
20
13
  var _arrow = require("./arrow.js");
21
-
22
14
  var _modifiers = require("./modifiers.js");
23
-
24
- 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); }
25
-
26
- 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; }
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- 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); }
31
-
15
+ 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); }
16
+ 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; }
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
+ 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); }
32
19
  const Popover = _ref => {
33
20
  let {
34
21
  children,
@@ -73,9 +60,8 @@ const Popover = _ref => {
73
60
  }), /*#__PURE__*/_react.default.createElement(_style.default, {
74
61
  id: "632767479",
75
62
  dynamic: [maxWidth, elevation, _uiConstants.colors.white]
76
- }, ["div.__jsx-style-dynamic-selector{max-width:".concat(maxWidth, "px;box-shadow:").concat(elevation, ";background-color:").concat(_uiConstants.colors.white, ";border-radius:4px;}")])));
63
+ }, [`div.__jsx-style-dynamic-selector{max-width:${maxWidth}px;box-shadow:${elevation};background-color:${_uiConstants.colors.white};border-radius:4px;}`])));
77
64
  };
78
-
79
65
  exports.Popover = Popover;
80
66
  Popover.defaultProps = {
81
67
  arrow: true,
@@ -86,19 +72,16 @@ Popover.defaultProps = {
86
72
  };
87
73
  Popover.propTypes = {
88
74
  children: _propTypes.default.node.isRequired,
89
-
90
75
  /** Show or hide the arrow */
91
76
  arrow: _propTypes.default.bool,
92
77
  className: _propTypes.default.string,
93
78
  dataTest: _propTypes.default.string,
94
-
95
79
  /** Box-shadow to create appearance of elevation. Use `elevations` constants from the UI library. */
96
80
  elevation: _propTypes.default.string,
97
81
  maxWidth: _propTypes.default.number,
98
82
  observePopperResize: _propTypes.default.bool,
99
83
  observeReferenceResize: _propTypes.default.bool,
100
84
  placement: _uiConstants.sharedPropTypes.popperPlacementPropType,
101
-
102
85
  /** A React ref that refers to the element the Popover should position against */
103
86
  reference: _uiConstants.sharedPropTypes.popperReferencePropType,
104
87
  onClickOutside: _propTypes.default.func
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.NoArrow = exports.Default = exports.Customization = void 0;
7
+ var _uiConstants = require("@dhis2/ui-constants");
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _popover = require("./popover.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 subtitle = `Useful to give a user more information or possible actions without disrupting a page or flow`;
14
+ const description = `
15
+ Popovers are similar to tooltips: they are for displaying extra information, but popovers are intended for richer information and actions.
16
+
17
+ Popovers are triggered by hovering or tapping on an element. Clicking on a element keeps the popover open until the user clicks or interacts elsewhere on the page.
18
+
19
+ Popovers can contain information in the form of rich markup, as well as actions. Critical actions, or the only action on a page, should not be hidden inside a popover.
20
+
21
+ Before using a popover, consider that some users may never see the information contained within. If that is a problem, display the information right on the page instead. Do not use a popover for content that is essential to the user experience or application.
22
+
23
+ See more about Popovers at [Design System: Popover](https://github.com/dhis2/design-system/blob/master/molecules/popover.md).
24
+
25
+ \`\`\`js
26
+ import { Popover } from '@dhis2/ui'
27
+ \`\`\`
28
+
29
+ _**Note**: Due to the full-page interaction of this component, only one representative example in an iframe sandbox is shown here. See more (interactive) examples in the 'Canvas' tab._
30
+ `;
31
+ var _default = exports.default = {
32
+ title: 'Popover',
33
+ component: _popover.Popover,
34
+ parameters: {
35
+ componentSubtitle: subtitle,
36
+ docs: {
37
+ description: {
38
+ component: description
39
+ },
40
+ // Contain the popovers in iframes in the docs page
41
+ inlineStories: false,
42
+ iframeHeight: '500px',
43
+ // Disable stories in docs page by default to use one representative example
44
+ disable: true
45
+ }
46
+ },
47
+ // Handles weird treatment of non-literal args (`elevation: elevations.e200`)
48
+ args: {
49
+ ..._popover.Popover.defaultProps
50
+ },
51
+ argTypes: {
52
+ reference: {
53
+ ..._uiConstants.sharedPropTypes.popperReferenceArgType
54
+ },
55
+ placement: {
56
+ ..._uiConstants.sharedPropTypes.popperPlacementArgType
57
+ }
58
+ }
59
+ };
60
+ const boxStyle = {
61
+ display: 'flex',
62
+ justifyContent: 'center',
63
+ width: 400,
64
+ paddingTop: 280,
65
+ backgroundColor: 'aliceblue'
66
+ };
67
+ const referenceElementStyle = {
68
+ width: 100,
69
+ height: 50,
70
+ backgroundColor: 'cadetblue',
71
+ textAlign: 'center',
72
+ padding: 6
73
+ };
74
+ const Template = args => {
75
+ const ref = (0, _react.useRef)(null);
76
+ return /*#__PURE__*/_react.default.createElement("div", {
77
+ style: boxStyle
78
+ }, /*#__PURE__*/_react.default.createElement("div", {
79
+ style: referenceElementStyle,
80
+ ref: ref
81
+ }, "Reference element"), /*#__PURE__*/_react.default.createElement(_popover.Popover, _extends({}, args, {
82
+ reference: ref
83
+ }), /*#__PURE__*/_react.default.createElement("div", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Consectetur purus ut faucibus pulvinar elementum. Dignissim diam quis enim lobortis scelerisque fermentum dui faucibus. Rhoncus aenean vel elit scelerisque mauris pellentesque. Non sodales neque sodales ut etiam sit amet. Volutpat sed cras ornare arcu dui. Quis imperdiet massa tincidunt nunc pulvinar sapien et ligula. Convallis posuere morbi leo urna molestie at. Mauris cursus mattis molestie a iaculis at.")));
84
+ };
85
+ const Default = exports.Default = Template.bind({});
86
+ Default.parameters = {
87
+ docs: {
88
+ // Enable this story for the docs page
89
+ disable: false,
90
+ // Show source, including 'ref' hooks
91
+ source: {
92
+ type: 'code'
93
+ }
94
+ }
95
+ };
96
+ const NoArrow = exports.NoArrow = Template.bind({});
97
+ NoArrow.args = {
98
+ arrow: false
99
+ };
100
+ const Customization = exports.Customization = Template.bind({});
101
+ Customization.args = {
102
+ arrow: true,
103
+ className: 'custom-classname',
104
+ dataTest: 'custom-data-test-id',
105
+ elevation: _uiConstants.elevations.e200,
106
+ maxWidth: 400,
107
+ placement: 'bottom-start',
108
+ onClickOutside: () => console.log('backdrop was clicked...')
109
+ };
package/build/es/arrow.js CHANGED
@@ -21,7 +21,7 @@ const Arrow = /*#__PURE__*/forwardRef((_ref, ref) => {
21
21
  }, /*#__PURE__*/React.createElement(_JSXStyle, {
22
22
  id: "1397459397",
23
23
  dynamic: [ARROW_SIZE, ARROW_SIZE, ARROW_SIZE / 2, ARROW_SIZE / 2, ARROW_SIZE / 2, ARROW_SIZE / 2, ARROW_SIZE / 2, colors.white, colors.white]
24
- }, ["div.__jsx-style-dynamic-selector{width:".concat(ARROW_SIZE, "px;height:").concat(ARROW_SIZE, "px;position:absolute;}"), "div.top.__jsx-style-dynamic-selector{top:-".concat(ARROW_SIZE / 2, "px;}"), "div.right.__jsx-style-dynamic-selector{right:-".concat(ARROW_SIZE / 2, "px;}"), "div.bottom.__jsx-style-dynamic-selector{bottom:-".concat(ARROW_SIZE / 2, "px;}"), "div.left.__jsx-style-dynamic-selector{left:-".concat(ARROW_SIZE / 2, "px;}"), "div.hidden.__jsx-style-dynamic-selector{visibility:hidden;}", "div.__jsx-style-dynamic-selector::after{content:'';position:absolute;pointer-events:none;box-sizing:border-box;border-style:solid;border-width:".concat(ARROW_SIZE / 2, "px;border-color:transparent transparent ").concat(colors.white, " ").concat(colors.white, ";box-shadow:-1px 1px 1px 0 rgba(64,75,90,0.08), -3px 3px 8px -6px rgba(64,75,90,0.15);}"), "div.bottom.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-45deg);-ms-transform:rotate(-45deg);transform:rotate(-45deg);}", "div.top.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(135deg);-ms-transform:rotate(135deg);transform:rotate(135deg);}", "div.right.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-135deg);-ms-transform:rotate(-135deg);transform:rotate(-135deg);}", "div.left.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);}"]));
24
+ }, [`div.__jsx-style-dynamic-selector{width:${ARROW_SIZE}px;height:${ARROW_SIZE}px;position:absolute;}`, `div.top.__jsx-style-dynamic-selector{top:-${ARROW_SIZE / 2}px;}`, `div.right.__jsx-style-dynamic-selector{right:-${ARROW_SIZE / 2}px;}`, `div.bottom.__jsx-style-dynamic-selector{bottom:-${ARROW_SIZE / 2}px;}`, `div.left.__jsx-style-dynamic-selector{left:-${ARROW_SIZE / 2}px;}`, "div.hidden.__jsx-style-dynamic-selector{visibility:hidden;}", `div.__jsx-style-dynamic-selector::after{content:'';position:absolute;pointer-events:none;box-sizing:border-box;border-style:solid;border-width:${ARROW_SIZE / 2}px;border-color:transparent transparent ${colors.white} ${colors.white};box-shadow:-1px 1px 1px 0 rgba(64,75,90,0.08), -3px 3px 8px -6px rgba(64,75,90,0.15);}`, "div.bottom.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-45deg);-ms-transform:rotate(-45deg);transform:rotate(-45deg);}", "div.top.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(135deg);-ms-transform:rotate(135deg);transform:rotate(135deg);}", "div.right.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(-135deg);-ms-transform:rotate(-135deg);transform:rotate(-135deg);}", "div.left.__jsx-style-dynamic-selector::after{-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);}"]));
25
25
  });
26
26
  Arrow.displayName = 'Arrow';
27
27
  Arrow.propTypes = {
@@ -1,6 +1,7 @@
1
1
  import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
2
- const CLOSE_TO_DELTA = 1; // Stories
2
+ const CLOSE_TO_DELTA = 1;
3
3
 
4
+ // Stories
4
5
  Given('there is sufficient space to place the Popover above the reference element', () => {
5
6
  cy.visitStory('Popover', 'Default');
6
7
  });
@@ -9,8 +10,9 @@ Given('there is not enough space between the reference element top and the body
9
10
  });
10
11
  Given('there is very little space between the top of the reference element and the top of the body', () => {
11
12
  cy.visitStory('Popover', 'Hidden Arrow');
12
- }); // Window height manipulation to control the space below the reference element
13
+ });
13
14
 
15
+ // Window height manipulation to control the space below the reference element
14
16
  Given('there is sufficient space between the reference element bottom and the body bottom to fit the Popover', () => {
15
17
  cy.viewport(1000, 660);
16
18
  });
@@ -19,8 +21,9 @@ Given('there is not enough space between the reference element bottom and the bo
19
21
  });
20
22
  Given('there is not enough space between the top of the reference element and the top of the Popover to show the arrow', () => {
21
23
  cy.viewport(1000, 380);
22
- }); // Assertions
24
+ });
23
25
 
26
+ // Assertions
24
27
  Given('there is sufficient space between the bottom of the reference element and the bottom of the Popover to show the arrow', () => {
25
28
  compareRefAndPopoverPositions((refPos, popoverPos) => {
26
29
  expect(refPos.bottom).to.be.greaterThan(popoverPos.bottom + 8);
@@ -59,8 +62,9 @@ Then('there is some space between the anchor and the popover', () => {
59
62
  compareRefAndPopoverPositions((refPos, popoverPos) => {
60
63
  expect(popoverPos.bottom + 8).to.be.closeTo(refPos.top, CLOSE_TO_DELTA);
61
64
  });
62
- }); // helper
65
+ });
63
66
 
67
+ // helper
64
68
  const compareRefAndPopoverPositions = callback => {
65
69
  // this needs to be done as the cypress reference to the popover is lost
66
70
  // once react re-renders it to adjust to the changed viewport size,
@@ -1,22 +1,16 @@
1
1
  const getArrowPosition = popperPlacement => {
2
2
  const direction = typeof popperPlacement === 'string' ? popperPlacement.split('-')[0] : '';
3
-
4
3
  switch (direction) {
5
4
  case 'top':
6
5
  return 'bottom';
7
-
8
6
  case 'right':
9
7
  return 'left';
10
-
11
8
  case 'bottom':
12
9
  return 'top';
13
-
14
10
  case 'left':
15
11
  return 'right';
16
-
17
12
  default:
18
13
  return '';
19
14
  }
20
15
  };
21
-
22
16
  export { getArrowPosition };
@@ -1,7 +1,6 @@
1
1
  import { getBaseModifiers } from '@dhis2-ui/popper';
2
2
  import { ARROW_SIZE } from './arrow.js';
3
3
  const BORDER_RADIUS = 4;
4
-
5
4
  const computeArrowPadding = () => {
6
5
  // pythagoras
7
6
  const diagonal = Math.sqrt(2 * Math.pow(ARROW_SIZE, 2));
@@ -9,7 +8,6 @@ const computeArrowPadding = () => {
9
8
  const padding = BORDER_RADIUS + overflowInPx;
10
9
  return Math.ceil(padding);
11
10
  };
12
-
13
11
  const hideArrowWhenDisplaced = _ref => {
14
12
  let {
15
13
  state
@@ -18,22 +16,17 @@ const hideArrowWhenDisplaced = _ref => {
18
16
  const displacement = state.modifiersData.preventOverflow;
19
17
  const referenceRect = state.rects.reference;
20
18
  const shouldHideArrow = Math.abs(displacement.x) >= referenceRect.width + halfArrow || Math.abs(displacement.y) >= referenceRect.height + halfArrow;
21
-
22
19
  if (typeof state.attributes.arrow !== 'object') {
23
20
  state.attributes.arrow = {};
24
21
  }
25
-
26
22
  state.attributes.arrow['data-arrow-hidden'] = shouldHideArrow;
27
23
  return state;
28
24
  };
29
-
30
25
  export const combineModifiers = (arrow, arrowElement, resizeObservers) => {
31
26
  const baseModifiers = getBaseModifiers(resizeObservers);
32
-
33
27
  if (!arrow) {
34
28
  return baseModifiers;
35
29
  }
36
-
37
30
  return [...baseModifiers, {
38
31
  name: 'offset',
39
32
  options: {
@@ -1,7 +1,7 @@
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
-
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
-
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); }
2
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
5
  import PropTypes from 'prop-types';
6
6
  import React, { Component, createRef } from 'react';
7
7
  import { Popover } from './popover.js';
@@ -18,14 +18,11 @@ const referenceElementStyle = {
18
18
  textAlign: 'center',
19
19
  padding: 6
20
20
  };
21
-
22
21
  class PopperInBoxWithCenteredReferenceElement extends Component {
23
22
  constructor() {
24
23
  super(...arguments);
25
-
26
24
  _defineProperty(this, "ref", /*#__PURE__*/createRef());
27
25
  }
28
-
29
26
  render() {
30
27
  const {
31
28
  paddingTop,
@@ -34,7 +31,8 @@ class PopperInBoxWithCenteredReferenceElement extends Component {
34
31
  ...popoverProps
35
32
  } = this.props;
36
33
  return /*#__PURE__*/React.createElement("div", {
37
- style: { ...boxStyle,
34
+ style: {
35
+ ...boxStyle,
38
36
  paddingTop,
39
37
  height: paddingTop + 100
40
38
  }
@@ -52,9 +50,7 @@ class PopperInBoxWithCenteredReferenceElement extends Component {
52
50
  }
53
51
  }, "I am in a box with width: ", popoverWidth, "px and height:", ' ', popoverHeight, "px")));
54
52
  }
55
-
56
53
  }
57
-
58
54
  PopperInBoxWithCenteredReferenceElement.defaultProps = {
59
55
  paddingTop: 220,
60
56
  popoverHeight: 200,
@@ -1,15 +1,12 @@
1
1
  import _JSXStyle from "styled-jsx/style";
2
-
3
- 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); }
4
-
2
+ 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
+ import { colors, elevations, sharedPropTypes } from '@dhis2/ui-constants';
5
4
  import { Layer } from '@dhis2-ui/layer';
6
5
  import { getReferenceElement, usePopper } from '@dhis2-ui/popper';
7
- import { colors, elevations, sharedPropTypes } from '@dhis2/ui-constants';
8
6
  import PropTypes from 'prop-types';
9
7
  import React, { useState, useMemo } from 'react';
10
8
  import { Arrow } from './arrow.js';
11
9
  import { combineModifiers } from './modifiers.js';
12
-
13
10
  const Popover = _ref => {
14
11
  let {
15
12
  children,
@@ -54,9 +51,8 @@ const Popover = _ref => {
54
51
  }), /*#__PURE__*/React.createElement(_JSXStyle, {
55
52
  id: "632767479",
56
53
  dynamic: [maxWidth, elevation, colors.white]
57
- }, ["div.__jsx-style-dynamic-selector{max-width:".concat(maxWidth, "px;box-shadow:").concat(elevation, ";background-color:").concat(colors.white, ";border-radius:4px;}")])));
54
+ }, [`div.__jsx-style-dynamic-selector{max-width:${maxWidth}px;box-shadow:${elevation};background-color:${colors.white};border-radius:4px;}`])));
58
55
  };
59
-
60
56
  Popover.defaultProps = {
61
57
  arrow: true,
62
58
  dataTest: 'dhis2-uicore-popover',
@@ -66,19 +62,16 @@ Popover.defaultProps = {
66
62
  };
67
63
  Popover.propTypes = {
68
64
  children: PropTypes.node.isRequired,
69
-
70
65
  /** Show or hide the arrow */
71
66
  arrow: PropTypes.bool,
72
67
  className: PropTypes.string,
73
68
  dataTest: PropTypes.string,
74
-
75
69
  /** Box-shadow to create appearance of elevation. Use `elevations` constants from the UI library. */
76
70
  elevation: PropTypes.string,
77
71
  maxWidth: PropTypes.number,
78
72
  observePopperResize: PropTypes.bool,
79
73
  observeReferenceResize: PropTypes.bool,
80
74
  placement: sharedPropTypes.popperPlacementPropType,
81
-
82
75
  /** A React ref that refers to the element the Popover should position against */
83
76
  reference: sharedPropTypes.popperReferencePropType,
84
77
  onClickOutside: PropTypes.func
@@ -1,10 +1,25 @@
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 { elevations, sharedPropTypes } from '@dhis2/ui-constants';
4
3
  import React, { useRef } from 'react';
5
4
  import { Popover } from './popover.js';
6
- const subtitle = "Useful to give a user more information or possible actions without disrupting a page or flow";
7
- const description = "\nPopovers are similar to tooltips: they are for displaying extra information, but popovers are intended for richer information and actions.\n\nPopovers are triggered by hovering or tapping on an element. Clicking on a element keeps the popover open until the user clicks or interacts elsewhere on the page.\n\nPopovers can contain information in the form of rich markup, as well as actions. Critical actions, or the only action on a page, should not be hidden inside a popover.\n\nBefore using a popover, consider that some users may never see the information contained within. If that is a problem, display the information right on the page instead. Do not use a popover for content that is essential to the user experience or application.\n\nSee more about Popovers at [Design System: Popover](https://github.com/dhis2/design-system/blob/master/molecules/popover.md).\n\n```js\nimport { Popover } from '@dhis2/ui'\n```\n\n_**Note**: Due to the full-page interaction of this component, only one representative example in an iframe sandbox is shown here. See more (interactive) examples in the 'Canvas' tab._\n";
5
+ const subtitle = `Useful to give a user more information or possible actions without disrupting a page or flow`;
6
+ const description = `
7
+ Popovers are similar to tooltips: they are for displaying extra information, but popovers are intended for richer information and actions.
8
+
9
+ Popovers are triggered by hovering or tapping on an element. Clicking on a element keeps the popover open until the user clicks or interacts elsewhere on the page.
10
+
11
+ Popovers can contain information in the form of rich markup, as well as actions. Critical actions, or the only action on a page, should not be hidden inside a popover.
12
+
13
+ Before using a popover, consider that some users may never see the information contained within. If that is a problem, display the information right on the page instead. Do not use a popover for content that is essential to the user experience or application.
14
+
15
+ See more about Popovers at [Design System: Popover](https://github.com/dhis2/design-system/blob/master/molecules/popover.md).
16
+
17
+ \`\`\`js
18
+ import { Popover } from '@dhis2/ui'
19
+ \`\`\`
20
+
21
+ _**Note**: Due to the full-page interaction of this component, only one representative example in an iframe sandbox is shown here. See more (interactive) examples in the 'Canvas' tab._
22
+ `;
8
23
  export default {
9
24
  title: 'Popover',
10
25
  component: Popover,
@@ -22,12 +37,15 @@ export default {
22
37
  }
23
38
  },
24
39
  // Handles weird treatment of non-literal args (`elevation: elevations.e200`)
25
- args: { ...Popover.defaultProps
40
+ args: {
41
+ ...Popover.defaultProps
26
42
  },
27
43
  argTypes: {
28
- reference: { ...sharedPropTypes.popperReferenceArgType
44
+ reference: {
45
+ ...sharedPropTypes.popperReferenceArgType
29
46
  },
30
- placement: { ...sharedPropTypes.popperPlacementArgType
47
+ placement: {
48
+ ...sharedPropTypes.popperPlacementArgType
31
49
  }
32
50
  }
33
51
  };
@@ -45,7 +63,6 @@ const referenceElementStyle = {
45
63
  textAlign: 'center',
46
64
  padding: 6
47
65
  };
48
-
49
66
  const Template = args => {
50
67
  const ref = useRef(null);
51
68
  return /*#__PURE__*/React.createElement("div", {
@@ -57,7 +74,6 @@ const Template = args => {
57
74
  reference: ref
58
75
  }), /*#__PURE__*/React.createElement("div", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Consectetur purus ut faucibus pulvinar elementum. Dignissim diam quis enim lobortis scelerisque fermentum dui faucibus. Rhoncus aenean vel elit scelerisque mauris pellentesque. Non sodales neque sodales ut etiam sit amet. Volutpat sed cras ornare arcu dui. Quis imperdiet massa tincidunt nunc pulvinar sapien et ligula. Convallis posuere morbi leo urna molestie at. Mauris cursus mattis molestie a iaculis at.")));
59
76
  };
60
-
61
77
  export const Default = Template.bind({});
62
78
  Default.parameters = {
63
79
  docs: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/popover",
3
- "version": "9.11.0",
3
+ "version": "9.11.1-beta.2",
4
4
  "description": "UI Popover",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,20 +22,20 @@
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/layer": "9.11.0",
37
- "@dhis2-ui/popper": "9.11.0",
38
- "@dhis2/ui-constants": "9.11.0",
36
+ "@dhis2-ui/layer": "9.11.1-beta.2",
37
+ "@dhis2-ui/popper": "9.11.1-beta.2",
38
+ "@dhis2/ui-constants": "9.11.1-beta.2",
39
39
  "classnames": "^2.3.1",
40
40
  "prop-types": "^15.7.2"
41
41
  },
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.NoArrow = exports.Default = exports.Customization = void 0;
7
-
8
- var _uiConstants = require("@dhis2/ui-constants");
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _popover = require("./popover.js");
13
-
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); }
15
-
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; }
17
-
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 subtitle = "Useful to give a user more information or possible actions without disrupting a page or flow";
21
- const description = "\nPopovers are similar to tooltips: they are for displaying extra information, but popovers are intended for richer information and actions.\n\nPopovers are triggered by hovering or tapping on an element. Clicking on a element keeps the popover open until the user clicks or interacts elsewhere on the page.\n\nPopovers can contain information in the form of rich markup, as well as actions. Critical actions, or the only action on a page, should not be hidden inside a popover.\n\nBefore using a popover, consider that some users may never see the information contained within. If that is a problem, display the information right on the page instead. Do not use a popover for content that is essential to the user experience or application.\n\nSee more about Popovers at [Design System: Popover](https://github.com/dhis2/design-system/blob/master/molecules/popover.md).\n\n```js\nimport { Popover } from '@dhis2/ui'\n```\n\n_**Note**: Due to the full-page interaction of this component, only one representative example in an iframe sandbox is shown here. See more (interactive) examples in the 'Canvas' tab._\n";
22
- var _default = {
23
- title: 'Popover',
24
- component: _popover.Popover,
25
- parameters: {
26
- componentSubtitle: subtitle,
27
- docs: {
28
- description: {
29
- component: description
30
- },
31
- // Contain the popovers in iframes in the docs page
32
- inlineStories: false,
33
- iframeHeight: '500px',
34
- // Disable stories in docs page by default to use one representative example
35
- disable: true
36
- }
37
- },
38
- // Handles weird treatment of non-literal args (`elevation: elevations.e200`)
39
- args: { ..._popover.Popover.defaultProps
40
- },
41
- argTypes: {
42
- reference: { ..._uiConstants.sharedPropTypes.popperReferenceArgType
43
- },
44
- placement: { ..._uiConstants.sharedPropTypes.popperPlacementArgType
45
- }
46
- }
47
- };
48
- exports.default = _default;
49
- const boxStyle = {
50
- display: 'flex',
51
- justifyContent: 'center',
52
- width: 400,
53
- paddingTop: 280,
54
- backgroundColor: 'aliceblue'
55
- };
56
- const referenceElementStyle = {
57
- width: 100,
58
- height: 50,
59
- backgroundColor: 'cadetblue',
60
- textAlign: 'center',
61
- padding: 6
62
- };
63
-
64
- const Template = args => {
65
- const ref = (0, _react.useRef)(null);
66
- return /*#__PURE__*/_react.default.createElement("div", {
67
- style: boxStyle
68
- }, /*#__PURE__*/_react.default.createElement("div", {
69
- style: referenceElementStyle,
70
- ref: ref
71
- }, "Reference element"), /*#__PURE__*/_react.default.createElement(_popover.Popover, _extends({}, args, {
72
- reference: ref
73
- }), /*#__PURE__*/_react.default.createElement("div", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Consectetur purus ut faucibus pulvinar elementum. Dignissim diam quis enim lobortis scelerisque fermentum dui faucibus. Rhoncus aenean vel elit scelerisque mauris pellentesque. Non sodales neque sodales ut etiam sit amet. Volutpat sed cras ornare arcu dui. Quis imperdiet massa tincidunt nunc pulvinar sapien et ligula. Convallis posuere morbi leo urna molestie at. Mauris cursus mattis molestie a iaculis at.")));
74
- };
75
-
76
- const Default = Template.bind({});
77
- exports.Default = Default;
78
- Default.parameters = {
79
- docs: {
80
- // Enable this story for the docs page
81
- disable: false,
82
- // Show source, including 'ref' hooks
83
- source: {
84
- type: 'code'
85
- }
86
- }
87
- };
88
- const NoArrow = Template.bind({});
89
- exports.NoArrow = NoArrow;
90
- NoArrow.args = {
91
- arrow: false
92
- };
93
- const Customization = Template.bind({});
94
- exports.Customization = Customization;
95
- Customization.args = {
96
- arrow: true,
97
- className: 'custom-classname',
98
- dataTest: 'custom-data-test-id',
99
- elevation: _uiConstants.elevations.e200,
100
- maxWidth: 400,
101
- placement: 'bottom-start',
102
- onClickOutside: () => console.log('backdrop was clicked...')
103
- };