@dhis2-ui/alert 9.11.0 → 9.11.1-beta.10
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.
- package/build/cjs/alert-bar/action.js +7 -18
- package/build/cjs/alert-bar/actions.js +5 -18
- package/build/cjs/alert-bar/alert-bar.e2e.stories.js +67 -0
- package/build/cjs/alert-bar/alert-bar.js +6 -40
- package/build/cjs/alert-bar/{alert-bar.stories.js → alert-bar.prod.stories.js} +34 -39
- package/build/cjs/alert-bar/alert-bar.styles.js +3 -7
- package/build/cjs/alert-bar/dismiss.js +2 -10
- package/build/cjs/alert-bar/features/api/index.js +1 -2
- package/build/cjs/alert-bar/features/common/index.js +0 -1
- package/build/cjs/alert-bar/features/hide/index.js +5 -3
- package/build/cjs/alert-bar/features/hide.feature +2 -2
- package/build/cjs/alert-bar/icon.js +3 -24
- package/build/cjs/alert-bar/index.js +0 -1
- package/build/cjs/alert-bar/message.js +1 -7
- package/build/cjs/alert-stack/alert-stack.e2e.stories.js +21 -0
- package/build/cjs/alert-stack/alert-stack.js +3 -12
- package/build/cjs/alert-stack/{alert-stack.stories.js → alert-stack.prod.stories.js} +10 -13
- package/build/cjs/alert-stack/features/render_children/alertbars.js +0 -1
- package/build/cjs/alert-stack/index.js +0 -1
- package/build/cjs/index.js +0 -2
- package/build/es/alert-bar/action.js +4 -9
- package/build/es/alert-bar/actions.js +3 -9
- package/build/es/alert-bar/{alert-bar.stories.e2e.js → alert-bar.e2e.stories.js} +19 -11
- package/build/es/alert-bar/alert-bar.js +3 -24
- package/build/es/alert-bar/{alert-bar.stories.js → alert-bar.prod.stories.js} +30 -10
- package/build/es/alert-bar/alert-bar.styles.js +1 -1
- package/build/es/alert-bar/dismiss.js +1 -3
- package/build/es/alert-bar/features/api/index.js +1 -1
- package/build/es/alert-bar/features/hide/index.js +5 -2
- package/build/es/alert-bar/features/hide.feature +2 -2
- package/build/es/alert-bar/icon.js +1 -12
- package/build/es/alert-bar/message.js +0 -2
- package/build/es/alert-stack/{alert-stack.stories.e2e.js → alert-stack.e2e.stories.js} +5 -3
- package/build/es/alert-stack/alert-stack.js +2 -2
- package/build/es/alert-stack/{alert-stack.stories.js → alert-stack.prod.stories.js} +9 -1
- package/package.json +7 -7
- package/build/cjs/alert-bar/alert-bar.stories.e2e.js +0 -51
- package/build/cjs/alert-stack/alert-stack.stories.e2e.js +0 -19
@@ -19,8 +19,8 @@ Feature: Hiding the AlertBar
|
|
19
19
|
Given a permanent AlertBar with hidden and onHidden is rendered
|
20
20
|
Then the AlertBar is not rendered
|
21
21
|
And the onHidden handler is not called
|
22
|
-
When the user click a button which toggles the hidden prop
|
22
|
+
When the user click a button which toggles the hidden prop to false
|
23
23
|
Then the AlertBar is rendered
|
24
|
-
When the user click a button which toggles the hidden prop
|
24
|
+
When the user click a button which toggles the hidden prop to true
|
25
25
|
Then the AlertBar is not rendered
|
26
26
|
And the onHidden handler is called
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.iconPropType = exports.Icon = void 0;
|
7
|
-
|
8
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
9
|
-
|
10
8
|
var _propTypes = require("@dhis2/prop-types");
|
11
|
-
|
12
9
|
var _uiConstants = require("@dhis2/ui-constants");
|
13
|
-
|
14
10
|
var _uiIcons = require("@dhis2/ui-icons");
|
15
|
-
|
16
11
|
var _propTypes2 = _interopRequireDefault(require("prop-types"));
|
17
|
-
|
18
12
|
var _react = _interopRequireDefault(require("react"));
|
19
|
-
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
|
-
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
22
14
|
const StatusIcon = _ref => {
|
23
15
|
let {
|
24
16
|
error,
|
@@ -27,34 +19,28 @@ const StatusIcon = _ref => {
|
|
27
19
|
info,
|
28
20
|
defaultTo
|
29
21
|
} = _ref;
|
30
|
-
|
31
22
|
if (error) {
|
32
23
|
return /*#__PURE__*/_react.default.createElement(_uiIcons.IconErrorFilled24, {
|
33
24
|
color: _uiConstants.colors.white
|
34
25
|
});
|
35
26
|
}
|
36
|
-
|
37
27
|
if (warning) {
|
38
28
|
return /*#__PURE__*/_react.default.createElement(_uiIcons.IconWarningFilled24, {
|
39
29
|
color: _uiConstants.colors.yellow900
|
40
30
|
});
|
41
31
|
}
|
42
|
-
|
43
32
|
if (valid) {
|
44
33
|
return /*#__PURE__*/_react.default.createElement(_uiIcons.IconCheckmark24, {
|
45
34
|
color: _uiConstants.colors.white
|
46
35
|
});
|
47
36
|
}
|
48
|
-
|
49
37
|
if (info) {
|
50
38
|
return /*#__PURE__*/_react.default.createElement(_uiIcons.IconInfoFilled24, {
|
51
39
|
color: _uiConstants.colors.white
|
52
40
|
});
|
53
41
|
}
|
54
|
-
|
55
42
|
return defaultTo;
|
56
43
|
};
|
57
|
-
|
58
44
|
StatusIcon.defaultProps = {
|
59
45
|
defaultTo: null
|
60
46
|
};
|
@@ -65,7 +51,6 @@ StatusIcon.propTypes = {
|
|
65
51
|
valid: _propTypes2.default.bool,
|
66
52
|
warning: _propTypes2.default.bool
|
67
53
|
};
|
68
|
-
|
69
54
|
const Icon = _ref2 => {
|
70
55
|
let {
|
71
56
|
icon,
|
@@ -75,11 +60,9 @@ const Icon = _ref2 => {
|
|
75
60
|
info,
|
76
61
|
dataTest
|
77
62
|
} = _ref2;
|
78
|
-
|
79
63
|
if (icon === false) {
|
80
64
|
return null;
|
81
65
|
}
|
82
|
-
|
83
66
|
return /*#__PURE__*/_react.default.createElement("div", {
|
84
67
|
"data-test": dataTest,
|
85
68
|
className: _style.default.dynamic([["719386130", [_uiConstants.spacers.dp16]]])
|
@@ -91,14 +74,10 @@ const Icon = _ref2 => {
|
|
91
74
|
}), /*#__PURE__*/_react.default.createElement(_style.default, {
|
92
75
|
id: "719386130",
|
93
76
|
dynamic: [_uiConstants.spacers.dp16]
|
94
|
-
}, [
|
77
|
+
}, [`div.__jsx-style-dynamic-selector{margin-inline-end:${_uiConstants.spacers.dp16};}`]));
|
95
78
|
};
|
96
|
-
|
97
79
|
exports.Icon = Icon;
|
98
|
-
|
99
|
-
const iconPropType = _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.element]);
|
100
|
-
|
101
|
-
exports.iconPropType = iconPropType;
|
80
|
+
const iconPropType = exports.iconPropType = _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.element]);
|
102
81
|
const alertStatePropType = (0, _propTypes.mutuallyExclusive)(['success', 'warning', 'critical', 'info'], _propTypes2.default.bool);
|
103
82
|
Icon.propTypes = {
|
104
83
|
dataTest: _propTypes2.default.string.isRequired,
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.Message = 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 = _interopRequireDefault(require("react"));
|
13
|
-
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
-
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
16
11
|
const Message = _ref => {
|
17
12
|
let {
|
18
13
|
children
|
@@ -23,7 +18,6 @@ const Message = _ref => {
|
|
23
18
|
id: "2181391309"
|
24
19
|
}, ["div.jsx-2181391309{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}"]));
|
25
20
|
};
|
26
|
-
|
27
21
|
exports.Message = Message;
|
28
22
|
Message.propTypes = {
|
29
23
|
children: _propTypes.default.string.isRequired
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = exports.Default = void 0;
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
8
|
+
var _index = require("../alert-bar/index.js");
|
9
|
+
var _alertStack = require("./alert-stack.js");
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
11
|
+
var _default = exports.default = {
|
12
|
+
title: 'AlertStack'
|
13
|
+
};
|
14
|
+
const Default = () => /*#__PURE__*/_react.default.createElement(_alertStack.AlertStack, null, /*#__PURE__*/_react.default.createElement(_index.AlertBar, {
|
15
|
+
permanent: true
|
16
|
+
}, "Message"), /*#__PURE__*/_react.default.createElement(_index.AlertBar, {
|
17
|
+
permanent: true
|
18
|
+
}, "Message"), /*#__PURE__*/_react.default.createElement(_index.AlertBar, {
|
19
|
+
permanent: true
|
20
|
+
}, "Message"));
|
21
|
+
exports.Default = Default;
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.AlertStack = void 0;
|
7
|
-
|
8
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
9
|
-
|
10
|
-
var _portal = require("@dhis2-ui/portal");
|
11
|
-
|
12
8
|
var _uiConstants = require("@dhis2/ui-constants");
|
13
|
-
|
9
|
+
var _portal = require("@dhis2-ui/portal");
|
14
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
15
|
-
|
16
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
17
|
-
|
18
12
|
var _react = _interopRequireDefault(require("react"));
|
19
|
-
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
|
-
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
22
14
|
const AlertStack = _ref => {
|
23
15
|
let {
|
24
16
|
className,
|
@@ -31,9 +23,8 @@ const AlertStack = _ref => {
|
|
31
23
|
}, children, /*#__PURE__*/_react.default.createElement(_style.default, {
|
32
24
|
id: "1009591311",
|
33
25
|
dynamic: [_uiConstants.layers.alert]
|
34
|
-
}, [
|
26
|
+
}, [`div.__jsx-style-dynamic-selector{position:fixed;top:auto;inset-inline-end:auto;bottom:0;inset-inline-start:50%;-webkit-transform:translateX(-50%);-ms-transform:translateX(-50%);transform:translateX(-50%);z-index:${_uiConstants.layers.alert};display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse;pointer-events:none;}`, "div.__jsx-style-dynamic-selector:dir(rtl){-webkit-transform:translateX(50%);-ms-transform:translateX(50%);transform:translateX(50%);}"])));
|
35
27
|
};
|
36
|
-
|
37
28
|
exports.AlertStack = AlertStack;
|
38
29
|
AlertStack.defaultProps = {
|
39
30
|
dataTest: 'dhis2-uicore-alertstack'
|
@@ -4,19 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = exports.RTL = exports.Default = void 0;
|
7
|
-
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
9
|
-
|
10
8
|
var _index = require("../alert-bar/index.js");
|
11
|
-
|
12
9
|
var _alertStack = require("./alert-stack.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
|
+
const description = `
|
13
|
+
A container for Alert Bars.
|
13
14
|
|
14
|
-
|
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; }
|
15
|
+
_**Note:** The demos on this page may be slow._
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
\`\`\`js
|
18
|
+
import { AlertStack } from '@dhis2/ui'
|
19
|
+
\`\`\`
|
20
|
+
`;
|
21
|
+
var _default = exports.default = {
|
20
22
|
title: 'Alert Stack',
|
21
23
|
component: _alertStack.AlertStack,
|
22
24
|
// Use an iframe in docs to contain 'portal'
|
@@ -30,8 +32,6 @@ var _default = {
|
|
30
32
|
}
|
31
33
|
}
|
32
34
|
};
|
33
|
-
exports.default = _default;
|
34
|
-
|
35
35
|
const Default = args => /*#__PURE__*/_react.default.createElement(_alertStack.AlertStack, args, /*#__PURE__*/_react.default.createElement(_index.AlertBar, {
|
36
36
|
permanent: true
|
37
37
|
}, "First notification - I am at the bottom"), /*#__PURE__*/_react.default.createElement(_index.AlertBar, {
|
@@ -44,9 +44,7 @@ const Default = args => /*#__PURE__*/_react.default.createElement(_alertStack.Al
|
|
44
44
|
permanent: true,
|
45
45
|
success: true
|
46
46
|
}, "Fourth notification - I am at the top"));
|
47
|
-
|
48
47
|
exports.Default = Default;
|
49
|
-
|
50
48
|
const RTL = args => {
|
51
49
|
(0, _react.useEffect)(() => {
|
52
50
|
document.body.dir = 'rtl';
|
@@ -69,5 +67,4 @@ const RTL = args => {
|
|
69
67
|
success: true
|
70
68
|
}, "Fourth notification - I am at the top")));
|
71
69
|
};
|
72
|
-
|
73
70
|
exports.RTL = RTL;
|
@@ -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)('an AlertStack with multiple AlertBars is rendered', () => {
|
6
5
|
cy.visitStory('Alertstack', 'Default');
|
7
6
|
cy.get('[data-test="dhis2-uicore-alertstack"]').should('be.visible');
|
package/build/cjs/index.js
CHANGED
@@ -1,21 +1,18 @@
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
2
|
-
|
3
|
-
function
|
4
|
-
|
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 { spacers } from '@dhis2/ui-constants';
|
6
6
|
import PropTypes from 'prop-types';
|
7
7
|
import React, { Component } from 'react';
|
8
|
-
|
9
8
|
class Action extends Component {
|
10
9
|
constructor() {
|
11
10
|
super(...arguments);
|
12
|
-
|
13
11
|
_defineProperty(this, "onClick", event => {
|
14
12
|
this.props.onClick(event);
|
15
13
|
this.props.hide(event);
|
16
14
|
});
|
17
15
|
}
|
18
|
-
|
19
16
|
render() {
|
20
17
|
return /*#__PURE__*/React.createElement("span", {
|
21
18
|
onClick: this.onClick,
|
@@ -24,11 +21,9 @@ class Action extends Component {
|
|
24
21
|
}, this.props.label, /*#__PURE__*/React.createElement(_JSXStyle, {
|
25
22
|
id: "918162538",
|
26
23
|
dynamic: [spacers.dp12]
|
27
|
-
}, [
|
24
|
+
}, [`span.__jsx-style-dynamic-selector{margin-inline-end:${spacers.dp12};-webkit-text-decoration:underline;text-decoration:underline;white-space:nowrap;}`, "span.__jsx-style-dynamic-selector:hover{cursor:pointer;}"]));
|
28
25
|
}
|
29
|
-
|
30
26
|
}
|
31
|
-
|
32
27
|
Action.propTypes = {
|
33
28
|
dataTest: PropTypes.string.isRequired,
|
34
29
|
hide: PropTypes.func.isRequired,
|
@@ -1,37 +1,31 @@
|
|
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); }
|
5
3
|
import { arrayWithLength } from '@dhis2/prop-types';
|
6
4
|
import { spacers } from '@dhis2/ui-constants';
|
7
5
|
import PropTypes from 'prop-types';
|
8
6
|
import React from 'react';
|
9
7
|
import { Action } from './action.js';
|
10
|
-
|
11
8
|
const Actions = _ref => {
|
12
9
|
let {
|
13
10
|
actions,
|
14
11
|
hide,
|
15
12
|
dataTest
|
16
13
|
} = _ref;
|
17
|
-
|
18
14
|
if (!actions) {
|
19
15
|
return null;
|
20
16
|
}
|
21
|
-
|
22
17
|
return /*#__PURE__*/React.createElement("div", {
|
23
18
|
className: _JSXStyle.dynamic([["793807948", [spacers.dp48, spacers.dp12]]])
|
24
19
|
}, actions.map(action => /*#__PURE__*/React.createElement(Action, _extends({
|
25
20
|
key: action.label
|
26
21
|
}, action, {
|
27
22
|
hide: hide,
|
28
|
-
dataTest:
|
23
|
+
dataTest: `${dataTest}-action`
|
29
24
|
}))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
30
25
|
id: "793807948",
|
31
26
|
dynamic: [spacers.dp48, spacers.dp12]
|
32
|
-
}, [
|
27
|
+
}, [`div.__jsx-style-dynamic-selector{margin-inline-start:${spacers.dp48};margin-inline-end:-${spacers.dp12};}`]));
|
33
28
|
};
|
34
|
-
|
35
29
|
const actionsPropType = arrayWithLength(0, 2, PropTypes.shape({
|
36
30
|
label: PropTypes.string.isRequired,
|
37
31
|
onClick: PropTypes.func.isRequired
|
@@ -1,10 +1,14 @@
|
|
1
|
-
import { storiesOf } from '@storybook/react';
|
2
1
|
import React, { useState } from 'react';
|
3
2
|
import { AlertBar } from './index.js';
|
4
3
|
window.onHidden = window.Cypress && window.Cypress.cy.stub();
|
5
|
-
|
4
|
+
export default {
|
5
|
+
title: 'AlertBar'
|
6
|
+
};
|
7
|
+
export const Default = () => /*#__PURE__*/React.createElement(AlertBar, null, "Default");
|
8
|
+
export const CustomDuration = () => /*#__PURE__*/React.createElement(AlertBar, {
|
6
9
|
duration: 2000
|
7
|
-
}, "Custom duration")
|
10
|
+
}, "Custom duration");
|
11
|
+
export const PermanentWithActions = () => /*#__PURE__*/React.createElement(AlertBar, {
|
8
12
|
permanent: true,
|
9
13
|
actions: [{
|
10
14
|
label: 'Save',
|
@@ -13,19 +17,23 @@ storiesOf('AlertBar', module).add('Default', () => /*#__PURE__*/React.createElem
|
|
13
17
|
label: 'Cancel',
|
14
18
|
onClick: () => {}
|
15
19
|
}]
|
16
|
-
}, "With Actions")
|
20
|
+
}, "With Actions");
|
21
|
+
export const DisabledIcon = () => /*#__PURE__*/React.createElement(AlertBar, {
|
17
22
|
icon: false
|
18
|
-
}, "Message")
|
23
|
+
}, "Message");
|
24
|
+
export const CustomIcon = () => /*#__PURE__*/React.createElement(AlertBar, {
|
19
25
|
icon: /*#__PURE__*/React.createElement("span", null, "Custom icon")
|
20
|
-
}, "Message")
|
26
|
+
}, "Message");
|
27
|
+
export const WithMessage = () => /*#__PURE__*/React.createElement(AlertBar, null, "With a message");
|
28
|
+
export const WithOnHidden = () => /*#__PURE__*/React.createElement(AlertBar, {
|
21
29
|
onHidden: window.onHidden
|
22
|
-
}, "Message")
|
30
|
+
}, "Message");
|
31
|
+
export const Permanent = () => /*#__PURE__*/React.createElement(AlertBar, {
|
23
32
|
permanent: true
|
24
|
-
}, "Message")
|
33
|
+
}, "Message");
|
34
|
+
export const HiddenProp = () => {
|
25
35
|
const [hidden, setHidden] = useState(true);
|
26
|
-
|
27
36
|
const toggleVisibility = () => setHidden(prevHidden => !prevHidden);
|
28
|
-
|
29
37
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
30
38
|
style: {
|
31
39
|
display: 'block',
|
@@ -39,4 +47,4 @@ storiesOf('AlertBar', module).add('Default', () => /*#__PURE__*/React.createElem
|
|
39
47
|
hidden: hidden,
|
40
48
|
onHidden: window.onHidden
|
41
49
|
}, "Short text"));
|
42
|
-
}
|
50
|
+
};
|
@@ -8,7 +8,6 @@ import styles, { ANIMATION_TIME } from './alert-bar.styles.js';
|
|
8
8
|
import { Dismiss } from './dismiss.js';
|
9
9
|
import { Icon, iconPropType } from './icon.js';
|
10
10
|
import { Message } from './message.js';
|
11
|
-
|
12
11
|
const AlertBar = _ref => {
|
13
12
|
let {
|
14
13
|
actions,
|
@@ -33,35 +32,29 @@ const AlertBar = _ref => {
|
|
33
32
|
const displayTimeRemaining = useRef(null);
|
34
33
|
const info = !critical && !success && !warning;
|
35
34
|
const shouldAutoHide = !(permanent || warning || critical);
|
36
|
-
|
37
35
|
const show = () => {
|
38
36
|
setInDOM(true);
|
39
37
|
setInViewport(true);
|
40
38
|
};
|
41
|
-
|
42
39
|
const hide = () => {
|
43
40
|
setInDOM(true);
|
44
41
|
setInViewport(false);
|
45
42
|
};
|
46
|
-
|
47
43
|
const remove = () => {
|
48
44
|
setInDOM(false);
|
49
45
|
setInViewport(false);
|
50
46
|
onHidden && onHidden({}, null);
|
51
47
|
};
|
52
|
-
|
53
48
|
const clearAllTimeouts = () => {
|
54
49
|
clearTimeout(showTimeout.current);
|
55
50
|
clearTimeout(displayTimeout.current);
|
56
51
|
clearTimeout(hideTimeout.current);
|
57
52
|
};
|
58
|
-
|
59
53
|
const runHideAnimation = () => {
|
60
54
|
clearAllTimeouts();
|
61
55
|
hide();
|
62
56
|
hideTimeout.current = setTimeout(remove, ANIMATION_TIME);
|
63
57
|
};
|
64
|
-
|
65
58
|
const startDisplayTimeout = () => {
|
66
59
|
if (shouldAutoHide) {
|
67
60
|
clearAllTimeouts();
|
@@ -70,13 +63,11 @@ const AlertBar = _ref => {
|
|
70
63
|
displayTimeout.current = setTimeout(runHideAnimation, displayTimeRemaining.current);
|
71
64
|
}
|
72
65
|
};
|
73
|
-
|
74
66
|
const runShowAnimation = () => {
|
75
67
|
clearAllTimeouts();
|
76
68
|
show();
|
77
69
|
showTimeout.current = setTimeout(startDisplayTimeout, ANIMATION_TIME);
|
78
70
|
};
|
79
|
-
|
80
71
|
const pauseDisplayTimeout = () => {
|
81
72
|
if (shouldAutoHide) {
|
82
73
|
clearAllTimeouts();
|
@@ -84,32 +75,28 @@ const AlertBar = _ref => {
|
|
84
75
|
displayTimeRemaining.current -= elapsedTime;
|
85
76
|
}
|
86
77
|
};
|
87
|
-
|
88
78
|
const resumeDisplayTimeout = () => {
|
89
79
|
if (shouldAutoHide) {
|
90
80
|
clearAllTimeouts();
|
91
81
|
displayTimeout.current = setTimeout(runHideAnimation, displayTimeRemaining.current);
|
92
82
|
}
|
93
83
|
};
|
94
|
-
|
95
84
|
useEffect(() => {
|
96
85
|
// Additional check on inDOM prevents the AlertBar from briefly showing
|
97
86
|
// when it is mounted with a hidden prop set to true
|
98
87
|
if (hidden && inDOM) {
|
99
88
|
runHideAnimation();
|
100
89
|
}
|
101
|
-
|
102
90
|
if (!hidden) {
|
103
91
|
runShowAnimation();
|
104
92
|
}
|
105
|
-
|
106
93
|
return clearAllTimeouts;
|
107
94
|
}, [hidden]);
|
108
95
|
return !inDOM ? null : /*#__PURE__*/React.createElement("div", {
|
109
96
|
"data-test": dataTest,
|
110
97
|
onMouseEnter: pauseDisplayTimeout,
|
111
98
|
onMouseLeave: resumeDisplayTimeout,
|
112
|
-
className:
|
99
|
+
className: `jsx-${styles.__hash}` + " " + (cx(className, {
|
113
100
|
info,
|
114
101
|
success,
|
115
102
|
warning,
|
@@ -117,7 +104,7 @@ const AlertBar = _ref => {
|
|
117
104
|
inViewport
|
118
105
|
}) || "")
|
119
106
|
}, /*#__PURE__*/React.createElement(Icon, {
|
120
|
-
dataTest:
|
107
|
+
dataTest: `${dataTest}-icon`,
|
121
108
|
icon: icon,
|
122
109
|
critical: critical,
|
123
110
|
success: success,
|
@@ -129,12 +116,11 @@ const AlertBar = _ref => {
|
|
129
116
|
dataTest: dataTest
|
130
117
|
}), /*#__PURE__*/React.createElement(Dismiss, {
|
131
118
|
onClick: runHideAnimation,
|
132
|
-
dataTest:
|
119
|
+
dataTest: `${dataTest}-dismiss`
|
133
120
|
}), /*#__PURE__*/React.createElement(_JSXStyle, {
|
134
121
|
id: styles.__hash
|
135
122
|
}, styles));
|
136
123
|
};
|
137
|
-
|
138
124
|
const alertTypePropType = mutuallyExclusive(['success', 'warning', 'critical'], PropTypes.bool);
|
139
125
|
AlertBar.defaultProps = {
|
140
126
|
duration: 8000,
|
@@ -145,31 +131,24 @@ AlertBar.propTypes = {
|
|
145
131
|
/** An array of 0-2 action objects
|
146
132
|
`[{label: "Save", onClick: clickHandler}]`*/
|
147
133
|
actions: actionsPropType,
|
148
|
-
|
149
134
|
/** The message string for the alert */
|
150
135
|
children: PropTypes.string,
|
151
136
|
className: PropTypes.string,
|
152
|
-
|
153
137
|
/** Alert bars with `critical` will not autohide */
|
154
138
|
critical: alertTypePropType,
|
155
139
|
dataTest: PropTypes.string,
|
156
|
-
|
157
140
|
/** How long you want the notification to display, in `ms`, when it's not permanent */
|
158
141
|
duration: PropTypes.number,
|
159
|
-
|
160
142
|
/** AlertBar will be hidden on creation when this is set to true */
|
161
143
|
hidden: PropTypes.bool,
|
162
|
-
|
163
144
|
/**
|
164
145
|
* A specific icon to override the default icon in the bar.
|
165
146
|
* If `false` is provided, no icon will be shown.
|
166
147
|
*/
|
167
148
|
icon: iconPropType,
|
168
|
-
|
169
149
|
/** When set, AlertBar will not autohide */
|
170
150
|
permanent: PropTypes.bool,
|
171
151
|
success: alertTypePropType,
|
172
|
-
|
173
152
|
/** Alert bars with `warning` will not autohide */
|
174
153
|
warning: alertTypePropType,
|
175
154
|
onHidden: PropTypes.func
|
@@ -1,9 +1,27 @@
|
|
1
1
|
import { IconFile16 } from '@dhis2/ui-icons';
|
2
2
|
import React, { useState } from 'react';
|
3
3
|
import { AlertBar } from './index.js';
|
4
|
-
const subtitle =
|
5
|
-
|
4
|
+
const subtitle = `
|
5
|
+
A floating alert that informs the user about temporary information
|
6
|
+
in the context of the current screen.
|
7
|
+
`;
|
8
|
+
const description = `
|
9
|
+
Alert bars notify a user of some information. There are different types of
|
10
|
+
alert bar for displaying different types of content. Use the alert bar type
|
11
|
+
that matches your content type and importance. Note that alert bar can be
|
12
|
+
ignored by the user, so they shouldn't be used for content that needs to
|
13
|
+
block an app flow, use a modal instead.
|
6
14
|
|
15
|
+
Alert bars are always displayed at centered and fixed at the bottom of the
|
16
|
+
screen. Some types of alert bar dismiss after a set time, others must be
|
17
|
+
dismissed by the user.
|
18
|
+
|
19
|
+
See specification: [Design System](https://github.com/dhis2/design-system/blob/master/molecules/alertbar.md)
|
20
|
+
|
21
|
+
\`\`\`js
|
22
|
+
import { AlertBar } from '@dhis2/ui'
|
23
|
+
\`\`\`
|
24
|
+
`;
|
7
25
|
const Wrapper = fn => /*#__PURE__*/React.createElement("div", {
|
8
26
|
style: {
|
9
27
|
height: '260px'
|
@@ -18,7 +36,6 @@ const Wrapper = fn => /*#__PURE__*/React.createElement("div", {
|
|
18
36
|
paddingLeft: 16
|
19
37
|
}
|
20
38
|
}, fn()));
|
21
|
-
|
22
39
|
const alertTypeArgType = {
|
23
40
|
table: {
|
24
41
|
type: {
|
@@ -57,15 +74,20 @@ export default {
|
|
57
74
|
}
|
58
75
|
},
|
59
76
|
argTypes: {
|
60
|
-
actions: {
|
77
|
+
actions: {
|
78
|
+
...actionsArgType
|
61
79
|
},
|
62
|
-
critical: {
|
80
|
+
critical: {
|
81
|
+
...alertTypeArgType
|
63
82
|
},
|
64
|
-
success: {
|
83
|
+
success: {
|
84
|
+
...alertTypeArgType
|
65
85
|
},
|
66
|
-
warning: {
|
86
|
+
warning: {
|
87
|
+
...alertTypeArgType
|
67
88
|
},
|
68
|
-
icon: {
|
89
|
+
icon: {
|
90
|
+
...iconArgType
|
69
91
|
}
|
70
92
|
}
|
71
93
|
};
|
@@ -154,9 +176,7 @@ export const TextOverflow = () => /*#__PURE__*/React.createElement(React.Fragmen
|
|
154
176
|
TextOverflow.storyName = 'Text overflow';
|
155
177
|
export const HiddenProp = () => {
|
156
178
|
const [hidden, setHidden] = useState(true);
|
157
|
-
|
158
179
|
const toggleVisibility = () => setHidden(prevHidden => !prevHidden);
|
159
|
-
|
160
180
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
161
181
|
style: {
|
162
182
|
display: 'block',
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { colors, spacers, elevations } from '@dhis2/ui-constants';
|
2
2
|
export const ANIMATION_TIME = 350;
|
3
|
-
const _defaultExport = [
|
3
|
+
const _defaultExport = [`div.jsx-1114274882{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;border-radius:4px;box-shadow:${elevations.e300};padding-top:${spacers.dp8};padding-inline-end:${spacers.dp8};padding-bottom:${spacers.dp8};padding-inline-start:${spacers.dp24};margin-bottom:${spacers.dp16};max-width:600px;min-width:300px;font-size:14px;pointer-events:all;}`, `div.info.jsx-1114274882{background-color:${colors.grey900};color:${colors.white};}`, `div.success.jsx-1114274882{background-color:${colors.green800};color:${colors.white};}`, `div.warning.jsx-1114274882{background-color:${colors.yellow300};color:${colors.yellow900};}`, `div.critical.jsx-1114274882{background-color:${colors.red800};color:${colors.white};}`, "@-webkit-keyframes slidein-jsx-1114274882{from{-webkit-transform:translateY(1000px);-ms-transform:translateY(1000px);transform:translateY(1000px);}to{-webkit-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0);}}", "@keyframes slidein-jsx-1114274882{from{-webkit-transform:translateY(1000px);-ms-transform:translateY(1000px);transform:translateY(1000px);}to{-webkit-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0);}}", "@-webkit-keyframes slideout-jsx-1114274882{from{-webkit-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0);}to{-webkit-transform:translateY(1000px);-ms-transform:translateY(1000px);transform:translateY(1000px);}}", "@keyframes slideout-jsx-1114274882{from{-webkit-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0);}to{-webkit-transform:translateY(1000px);-ms-transform:translateY(1000px);transform:translateY(1000px);}}", `div.inViewport.jsx-1114274882{-webkit-animation-duration:${ANIMATION_TIME}ms;animation-duration:${ANIMATION_TIME}ms;-webkit-animation-name:slidein-jsx-1114274882;animation-name:slidein-jsx-1114274882;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-timing-function:cubic-bezier(0.4,0,0.6,1);animation-timing-function:cubic-bezier(0.4,0,0.6,1);}`, `div.jsx-1114274882{-webkit-animation-duration:${ANIMATION_TIME}ms;animation-duration:${ANIMATION_TIME}ms;-webkit-animation-name:slideout-jsx-1114274882;animation-name:slideout-jsx-1114274882;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-timing-function:cubic-bezier(0.4,0,0.6,1);animation-timing-function:cubic-bezier(0.4,0,0.6,1);}`];
|
4
4
|
_defaultExport.__hash = "1114274882";
|
5
5
|
export default _defaultExport;
|