@elliemae/ds-banner 2.3.0-alpha.9 → 2.3.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/DSBanner.js +132 -0
- package/cjs/defaultProps.js +22 -0
- package/cjs/index.d.js +2 -0
- package/cjs/index.js +12 -0
- package/cjs/propTypes.js +24 -0
- package/cjs/styles.js +146 -0
- package/cjs/utils/bannerTypes.js +12 -0
- package/cjs/utils/icons.js +36 -0
- package/cjs/utils/styleHelpers.js +53 -0
- package/esm/DSBanner.js +121 -0
- package/esm/defaultProps.js +18 -0
- package/esm/index.d.js +1 -0
- package/esm/index.js +2 -0
- package/esm/propTypes.js +20 -0
- package/esm/styles.js +131 -0
- package/esm/utils/bannerTypes.js +8 -0
- package/esm/utils/icons.js +28 -0
- package/esm/utils/styleHelpers.js +44 -0
- package/package.json +35 -37
- package/{dist/types → types}/DSBanner.d.ts +1 -1
- package/{dist/types → types}/defaultProps.d.ts +0 -0
- package/{dist/types → types}/index.d.ts +0 -0
- package/{dist/types → types}/propTypes.d.ts +0 -0
- package/{dist/types → types}/styles.d.ts +7 -7
- package/{dist/types → types}/tests/DSBanner.events.test.d.ts +0 -0
- package/{dist/types → types}/tests/DSBanner.test.d.ts +0 -0
- package/{dist/types → types}/utils/bannerTypes.d.ts +0 -0
- package/{dist/types → types}/utils/icons.d.ts +0 -0
- package/{dist/types → types}/utils/styleHelpers.d.ts +0 -0
- package/dist/cjs/DSBanner.js +0 -138
- package/dist/cjs/DSBanner.js.map +0 -7
- package/dist/cjs/defaultProps.js +0 -45
- package/dist/cjs/defaultProps.js.map +0 -7
- package/dist/cjs/index.d.js +0 -27
- package/dist/cjs/index.d.js.map +0 -7
- package/dist/cjs/index.js +0 -37
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/propTypes.js +0 -55
- package/dist/cjs/propTypes.js.map +0 -7
- package/dist/cjs/styles.js +0 -107
- package/dist/cjs/styles.js.map +0 -7
- package/dist/cjs/utils/bannerTypes.js +0 -40
- package/dist/cjs/utils/bannerTypes.js.map +0 -7
- package/dist/cjs/utils/icons.js +0 -58
- package/dist/cjs/utils/icons.js.map +0 -7
- package/dist/cjs/utils/styleHelpers.js +0 -99
- package/dist/cjs/utils/styleHelpers.js.map +0 -7
- package/dist/esm/DSBanner.js +0 -117
- package/dist/esm/DSBanner.js.map +0 -7
- package/dist/esm/defaultProps.js +0 -16
- package/dist/esm/defaultProps.js.map +0 -7
- package/dist/esm/index.d.js +0 -2
- package/dist/esm/index.d.js.map +0 -7
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/propTypes.js +0 -26
- package/dist/esm/propTypes.js.map +0 -7
- package/dist/esm/styles.js +0 -78
- package/dist/esm/styles.js.map +0 -7
- package/dist/esm/utils/bannerTypes.js +0 -11
- package/dist/esm/utils/bannerTypes.js.map +0 -7
- package/dist/esm/utils/icons.js +0 -29
- package/dist/esm/utils/icons.js.map +0 -7
- package/dist/esm/utils/styleHelpers.js +0 -70
- package/dist/esm/utils/styleHelpers.js.map +0 -7
package/cjs/DSBanner.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
7
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
11
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
12
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
13
|
+
var React = require('react');
|
|
14
|
+
var dsIcons = require('@elliemae/ds-icons');
|
|
15
|
+
var reactDesc = require('react-desc');
|
|
16
|
+
var icons = require('./utils/icons.js');
|
|
17
|
+
var propTypes = require('./propTypes.js');
|
|
18
|
+
var defaultProps = require('./defaultProps.js');
|
|
19
|
+
var styles = require('./styles.js');
|
|
20
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
21
|
+
|
|
22
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
|
+
|
|
24
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
25
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
26
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
27
|
+
|
|
28
|
+
var _CloseX, _span;
|
|
29
|
+
|
|
30
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
+
|
|
32
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
+
|
|
34
|
+
const DSBanner = _ref => {
|
|
35
|
+
let {
|
|
36
|
+
type,
|
|
37
|
+
isOpen,
|
|
38
|
+
onClose,
|
|
39
|
+
label,
|
|
40
|
+
body,
|
|
41
|
+
actionLink,
|
|
42
|
+
showCloseButton,
|
|
43
|
+
containerProps,
|
|
44
|
+
actionRef
|
|
45
|
+
} = _ref;
|
|
46
|
+
const innerContainerRef = React.useRef(null);
|
|
47
|
+
const linkRef = React.useRef(null);
|
|
48
|
+
const [current, setCurrent] = React.useState(isOpen);
|
|
49
|
+
const [isAnimating, setIsAnimating] = React.useState(false);
|
|
50
|
+
const [alertTabIndex, setAlertTabIndex] = React.useState(undefined);
|
|
51
|
+
const ownerState = {
|
|
52
|
+
type
|
|
53
|
+
};
|
|
54
|
+
React__default["default"].useEffect(() => {
|
|
55
|
+
if (actionRef && actionRef.current) {
|
|
56
|
+
actionRef.current.focusOnWrapper = () => {
|
|
57
|
+
if (innerContainerRef.current) {
|
|
58
|
+
setAlertTabIndex(0);
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
innerContainerRef.current.focus();
|
|
61
|
+
}, 100);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
actionRef.current.focusOnLink = () => {
|
|
66
|
+
if (linkRef.current) {
|
|
67
|
+
linkRef.current.focus();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}, [actionRef]);
|
|
72
|
+
React.useLayoutEffect(() => {
|
|
73
|
+
if (isOpen !== current || isOpen) setIsAnimating(true);else setIsAnimating(false);
|
|
74
|
+
}, [isOpen, current]);
|
|
75
|
+
const handleBlur = React.useCallback(() => {
|
|
76
|
+
setAlertTabIndex(undefined);
|
|
77
|
+
}, []);
|
|
78
|
+
const handleOnKeyDown = React.useCallback(e => {
|
|
79
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
if (linkRef.current) linkRef.current.click();
|
|
82
|
+
}
|
|
83
|
+
}, []);
|
|
84
|
+
if (!isAnimating && !isOpen) return null;
|
|
85
|
+
return /*#__PURE__*/jsxRuntime.jsx(styles.StyledBannerContainer, _objectSpread(_objectSpread({
|
|
86
|
+
type: type,
|
|
87
|
+
isOpen: isOpen,
|
|
88
|
+
isAnimating: isAnimating,
|
|
89
|
+
onAnimationEnd: () => setCurrent(isOpen),
|
|
90
|
+
"data-testid": "ds-banner-container"
|
|
91
|
+
}, containerProps), {}, {
|
|
92
|
+
ownerState: ownerState,
|
|
93
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(styles.StyledInnerContainer, {
|
|
94
|
+
type: type,
|
|
95
|
+
isOpen: isOpen,
|
|
96
|
+
ref: innerContainerRef,
|
|
97
|
+
isAnimating: isAnimating,
|
|
98
|
+
"data-testid": "ds-banner",
|
|
99
|
+
role: "alert",
|
|
100
|
+
tabIndex: alertTabIndex,
|
|
101
|
+
onBlur: handleBlur,
|
|
102
|
+
children: [/*#__PURE__*/_jsx__default["default"](styles.StyledIconContainer, {
|
|
103
|
+
"data-testid": "ds-banner-icon"
|
|
104
|
+
}, void 0, icons.icons[type]), /*#__PURE__*/_jsx__default["default"](styles.StyledTitle, {}, void 0, label), /*#__PURE__*/_jsx__default["default"](styles.StyledSubTitle, {}, void 0, /*#__PURE__*/_jsx__default["default"]("span", {}, void 0, body), actionLink && /*#__PURE__*/jsxRuntime.jsx(styles.StyledActionLink, {
|
|
105
|
+
"data-testid": "ds-banner-action-link",
|
|
106
|
+
onClick: actionLink.onClick,
|
|
107
|
+
href: actionLink.href,
|
|
108
|
+
ref: linkRef,
|
|
109
|
+
onKeyDown: handleOnKeyDown,
|
|
110
|
+
tabIndex: 0,
|
|
111
|
+
isBodyEmpty: body,
|
|
112
|
+
children: actionLink.label
|
|
113
|
+
})), showCloseButton ? /*#__PURE__*/_jsx__default["default"](styles.StyledCloseButton, {
|
|
114
|
+
"data-testid": "ds-banner-close-button",
|
|
115
|
+
buttonType: "secondary",
|
|
116
|
+
onClick: onClose,
|
|
117
|
+
"aria-label": "Close icon",
|
|
118
|
+
icon: _CloseX || (_CloseX = /*#__PURE__*/_jsx__default["default"](dsIcons.CloseX, {
|
|
119
|
+
width: "12px",
|
|
120
|
+
height: "12px"
|
|
121
|
+
}))
|
|
122
|
+
}) : _span || (_span = /*#__PURE__*/_jsx__default["default"]("span", {}))]
|
|
123
|
+
})
|
|
124
|
+
}));
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
DSBanner.defaultProps = defaultProps.defaultProps;
|
|
128
|
+
const DSBannerWithSchema = reactDesc.describe(DSBanner);
|
|
129
|
+
DSBannerWithSchema.propTypes = propTypes.propTypes;
|
|
130
|
+
|
|
131
|
+
exports.DSBannerWithSchema = DSBannerWithSchema;
|
|
132
|
+
exports["default"] = DSBanner;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var bannerTypes = require('./utils/bannerTypes.js');
|
|
6
|
+
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
containerProps: {},
|
|
9
|
+
label: '',
|
|
10
|
+
body: '',
|
|
11
|
+
type: bannerTypes.BANNER_TYPES.INFO,
|
|
12
|
+
isOpen: true,
|
|
13
|
+
onClose: () => null,
|
|
14
|
+
showCloseButton: true,
|
|
15
|
+
actionLink: {
|
|
16
|
+
label: '',
|
|
17
|
+
onClick: () => null,
|
|
18
|
+
href: ''
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.defaultProps = defaultProps;
|
package/cjs/index.d.js
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var DSBanner = require('./DSBanner.js');
|
|
6
|
+
var bannerTypes = require('./utils/bannerTypes.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.DSBannerWithSchema = DSBanner.DSBannerWithSchema;
|
|
11
|
+
exports["default"] = DSBanner["default"];
|
|
12
|
+
exports.BANNER_TYPES = bannerTypes.BANNER_TYPES;
|
package/cjs/propTypes.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var reactDesc = require('react-desc');
|
|
6
|
+
var bannerTypes = require('./utils/bannerTypes.js');
|
|
7
|
+
|
|
8
|
+
const propTypes = {
|
|
9
|
+
containerProps: reactDesc.PropTypes.object.description('Set of Properties attached to the main container').defaultValue({}),
|
|
10
|
+
label: reactDesc.PropTypes.string.description('banner s label').defaultValue(''),
|
|
11
|
+
body: reactDesc.PropTypes.string.description('banner s body content').defaultValue(''),
|
|
12
|
+
type: reactDesc.PropTypes.oneOf(Object.values(bannerTypes.BANNER_TYPES)).description('banner s type').defaultValue(bannerTypes.BANNER_TYPES.INFO),
|
|
13
|
+
onClose: reactDesc.PropTypes.func.description('function executed when the banner closes'),
|
|
14
|
+
isOpen: reactDesc.PropTypes.bool.description('whether the banner is open or closed').defaultValue(true),
|
|
15
|
+
showCloseButton: reactDesc.PropTypes.bool.description('whether to show close button or not').defaultValue(true),
|
|
16
|
+
actionLink: reactDesc.PropTypes.shape({
|
|
17
|
+
label: reactDesc.PropTypes.string,
|
|
18
|
+
onClick: reactDesc.PropTypes.func,
|
|
19
|
+
href: reactDesc.PropTypes.string
|
|
20
|
+
}).description('Properties of the ActionLink component').defaultValue({}),
|
|
21
|
+
actionRef: reactDesc.PropTypes.object.description("\n Reference to use actions:\n - focusOnLink: function to focus the banner\n - focusOnWrapper: function to focus the link\n ").defaultValue({})
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.propTypes = propTypes;
|
package/cjs/styles.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
|
|
6
|
+
var dsSystem = require('@elliemae/ds-system');
|
|
7
|
+
var DSButton = require('@elliemae/ds-button');
|
|
8
|
+
var styleHelpers = require('./utils/styleHelpers.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultLegacy(_taggedTemplateLiteral);
|
|
13
|
+
var DSButton__default = /*#__PURE__*/_interopDefaultLegacy(DSButton);
|
|
14
|
+
|
|
15
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|
16
|
+
const StyledBannerContainer = dsSystem.styled('div', {
|
|
17
|
+
name: 'DS-Banner',
|
|
18
|
+
slot: 'root'
|
|
19
|
+
})(_templateObject || (_templateObject = _taggedTemplateLiteral__default["default"](["\n overflow: hidden;\n height: ", ";\n ", ";\n"])), _ref => {
|
|
20
|
+
let {
|
|
21
|
+
isOpen
|
|
22
|
+
} = _ref;
|
|
23
|
+
return isOpen ? 'auto' : '0px';
|
|
24
|
+
}, _ref2 => {
|
|
25
|
+
let {
|
|
26
|
+
isAnimating,
|
|
27
|
+
isOpen,
|
|
28
|
+
height
|
|
29
|
+
} = _ref2;
|
|
30
|
+
return styleHelpers.handleAnimation(isAnimating, isOpen, height);
|
|
31
|
+
});
|
|
32
|
+
const StyledInnerContainer = dsSystem.styled('div', {
|
|
33
|
+
name: 'DS-Banner',
|
|
34
|
+
slot: 'innerContainer'
|
|
35
|
+
})(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral__default["default"](["\n padding-right: 6px;\n display: grid;\n align-items: center;\n min-height: 41px;\n width: 100%;\n background-color: ", ";\n border-bottom: 5px solid ", ";\n ", ";\n &:focus {\n position: relative;\n &:after {\n content: '';\n display: block;\n position: absolute;\n top: 0;\n left: 0;\n pointer-events: none;\n border-radius: 2px;\n width: calc(100%);\n border: 2px solid #1e79c2;\n height: calc(100% + 4px);\n }\n }\n grid-template-columns: auto minmax(auto, auto) minmax(auto, 1fr) auto;\n"])), _ref3 => {
|
|
36
|
+
let {
|
|
37
|
+
theme
|
|
38
|
+
} = _ref3;
|
|
39
|
+
return theme.colors.neutral['000'];
|
|
40
|
+
}, _ref4 => {
|
|
41
|
+
let {
|
|
42
|
+
type,
|
|
43
|
+
theme
|
|
44
|
+
} = _ref4;
|
|
45
|
+
return styleHelpers.handleBorderColor(type, theme);
|
|
46
|
+
}, _ref5 => {
|
|
47
|
+
let {
|
|
48
|
+
isAnimating,
|
|
49
|
+
isOpen
|
|
50
|
+
} = _ref5;
|
|
51
|
+
return styleHelpers.handleAnimation(isAnimating, isOpen);
|
|
52
|
+
});
|
|
53
|
+
const StyledIconContainer = dsSystem.styled('div', {
|
|
54
|
+
name: 'DS-Banner',
|
|
55
|
+
slot: 'iconContainer'
|
|
56
|
+
})(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral__default["default"](["\n margin-right: ", ";\n margin-left: ", ";\n"])), _ref6 => {
|
|
57
|
+
let {
|
|
58
|
+
theme
|
|
59
|
+
} = _ref6;
|
|
60
|
+
return theme.space.xxs;
|
|
61
|
+
}, _ref7 => {
|
|
62
|
+
let {
|
|
63
|
+
theme
|
|
64
|
+
} = _ref7;
|
|
65
|
+
return theme.space.xs;
|
|
66
|
+
});
|
|
67
|
+
const StyledTitle = dsSystem.styled('div', {
|
|
68
|
+
name: 'DS-Banner',
|
|
69
|
+
slot: 'title'
|
|
70
|
+
})(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral__default["default"](["\n color: ", ";\n font-size: ", ";\n font-weight: ", ";\n"])), _ref8 => {
|
|
71
|
+
let {
|
|
72
|
+
theme
|
|
73
|
+
} = _ref8;
|
|
74
|
+
return theme.colors.neutral[700];
|
|
75
|
+
}, _ref9 => {
|
|
76
|
+
let {
|
|
77
|
+
theme
|
|
78
|
+
} = _ref9;
|
|
79
|
+
return theme.fontSizes.label[400];
|
|
80
|
+
}, _ref10 => {
|
|
81
|
+
let {
|
|
82
|
+
theme
|
|
83
|
+
} = _ref10;
|
|
84
|
+
return theme.fontWeights.semibold;
|
|
85
|
+
});
|
|
86
|
+
const StyledSubTitle = dsSystem.styled('div', {
|
|
87
|
+
name: 'DS-Banner',
|
|
88
|
+
slot: 'subtitle'
|
|
89
|
+
})(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral__default["default"](["\n width: 100%;\n margin-left: ", ";\n font-size: ", ";\n font-weight: ", ";\n"])), _ref11 => {
|
|
90
|
+
let {
|
|
91
|
+
theme
|
|
92
|
+
} = _ref11;
|
|
93
|
+
return theme.space.xs;
|
|
94
|
+
}, _ref12 => {
|
|
95
|
+
let {
|
|
96
|
+
theme
|
|
97
|
+
} = _ref12;
|
|
98
|
+
return theme.fontSizes.subTitle[400];
|
|
99
|
+
}, _ref13 => {
|
|
100
|
+
let {
|
|
101
|
+
theme
|
|
102
|
+
} = _ref13;
|
|
103
|
+
return theme.fontWeights.regular;
|
|
104
|
+
});
|
|
105
|
+
const StyledActionLink = dsSystem.styled('a', {
|
|
106
|
+
name: 'DS-Banner',
|
|
107
|
+
slot: 'action'
|
|
108
|
+
})(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral__default["default"](["\n margin-left: ", ";\n white-space: nowrap;\n text-decoration: none;\n line-height: 1.1;\n font-size: ", ";\n font-weight: ", ";\n color: ", ";\n"])), _ref14 => {
|
|
109
|
+
let {
|
|
110
|
+
theme,
|
|
111
|
+
isBodyEmpty
|
|
112
|
+
} = _ref14;
|
|
113
|
+
return isBodyEmpty ? theme.space.xs : 0;
|
|
114
|
+
}, _ref15 => {
|
|
115
|
+
let {
|
|
116
|
+
theme
|
|
117
|
+
} = _ref15;
|
|
118
|
+
return theme.fontSizes.hyperlink[400];
|
|
119
|
+
}, _ref16 => {
|
|
120
|
+
let {
|
|
121
|
+
theme
|
|
122
|
+
} = _ref16;
|
|
123
|
+
return theme.fontWeights.regular;
|
|
124
|
+
}, _ref17 => {
|
|
125
|
+
let {
|
|
126
|
+
theme
|
|
127
|
+
} = _ref17;
|
|
128
|
+
return theme.colors.brand[600];
|
|
129
|
+
});
|
|
130
|
+
const StyledCloseButton = dsSystem.styled(DSButton__default["default"], {
|
|
131
|
+
name: 'DS-Banner',
|
|
132
|
+
slot: 'closeButton'
|
|
133
|
+
})(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral__default["default"](["\n margin-left: ", ";\n &:not(focus) {\n border: transparent;\n }\n"])), _ref18 => {
|
|
134
|
+
let {
|
|
135
|
+
theme
|
|
136
|
+
} = _ref18;
|
|
137
|
+
return theme.space.xxs;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
exports.StyledActionLink = StyledActionLink;
|
|
141
|
+
exports.StyledBannerContainer = StyledBannerContainer;
|
|
142
|
+
exports.StyledCloseButton = StyledCloseButton;
|
|
143
|
+
exports.StyledIconContainer = StyledIconContainer;
|
|
144
|
+
exports.StyledInnerContainer = StyledInnerContainer;
|
|
145
|
+
exports.StyledSubTitle = StyledSubTitle;
|
|
146
|
+
exports.StyledTitle = StyledTitle;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
require('react');
|
|
7
|
+
var dsIcons = require('@elliemae/ds-icons');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
12
|
+
|
|
13
|
+
const icons = {
|
|
14
|
+
success: /*#__PURE__*/_jsx__default["default"](dsIcons.SuccessFill, {
|
|
15
|
+
fill: "#207e56",
|
|
16
|
+
width: "20px",
|
|
17
|
+
height: "20px"
|
|
18
|
+
}),
|
|
19
|
+
info: /*#__PURE__*/_jsx__default["default"](dsIcons.InfoFill, {
|
|
20
|
+
fill: "#1e79c2",
|
|
21
|
+
width: "20px",
|
|
22
|
+
height: "20px"
|
|
23
|
+
}),
|
|
24
|
+
danger: /*#__PURE__*/_jsx__default["default"](dsIcons.AlertsDetailFill, {
|
|
25
|
+
fill: "#c64252",
|
|
26
|
+
width: "20px",
|
|
27
|
+
height: "20px"
|
|
28
|
+
}),
|
|
29
|
+
warning: /*#__PURE__*/_jsx__default["default"](dsIcons.WarningSquare, {
|
|
30
|
+
fill: "#d17a00",
|
|
31
|
+
width: "20px",
|
|
32
|
+
height: "20px"
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.icons = icons;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
|
|
6
|
+
var dsSystem = require('@elliemae/ds-system');
|
|
7
|
+
var bannerTypes = require('./bannerTypes.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultLegacy(_taggedTemplateLiteral);
|
|
12
|
+
|
|
13
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
14
|
+
const slideIn = dsSystem.kfrm(_templateObject || (_templateObject = _taggedTemplateLiteral__default["default"](["\n 0% {\n transform: translate3d(0, -100%, 0);\n }\n 100% {\n transform: translate3d(0, 0, 0);\n }\n"])));
|
|
15
|
+
const slideOut = dsSystem.kfrm(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral__default["default"](["\n 0% {\n transform: translate3d(0, 0, 0);\n opacity: 1;\n }\n 60% {\n opacity: 0;\n }\n 100% {\n opacity: 0;\n transform: translate3d(0, -100%, 0);\n }\n"])));
|
|
16
|
+
|
|
17
|
+
const spanContainer = height => dsSystem.kfrm(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral__default["default"](["\n 0% {\n height: 0px;\n }\n 100% {\n height: ", "px;\n }\n"])), height);
|
|
18
|
+
|
|
19
|
+
const shrinkContainer = height => dsSystem.kfrm(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral__default["default"](["\n 0% {\n height: ", "px;\n }\n 100% {\n height: 0px;\n }\n"])), height);
|
|
20
|
+
|
|
21
|
+
const handleBorderColor = (type, _ref) => {
|
|
22
|
+
let {
|
|
23
|
+
colors
|
|
24
|
+
} = _ref;
|
|
25
|
+
|
|
26
|
+
switch (type) {
|
|
27
|
+
case bannerTypes.BANNER_TYPES.SUCCESS:
|
|
28
|
+
return colors.success[900];
|
|
29
|
+
|
|
30
|
+
case bannerTypes.BANNER_TYPES.INFO:
|
|
31
|
+
return colors.brand[600];
|
|
32
|
+
|
|
33
|
+
case bannerTypes.BANNER_TYPES.WARNING:
|
|
34
|
+
return colors.warning[900];
|
|
35
|
+
|
|
36
|
+
case bannerTypes.BANNER_TYPES.DANGER:
|
|
37
|
+
return colors.danger[900];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const handleAnimation = function (isAnimating, isOpen) {
|
|
41
|
+
let height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
42
|
+
|
|
43
|
+
if (isAnimating) {
|
|
44
|
+
if (isOpen) {
|
|
45
|
+
return dsSystem.css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral__default["default"](["\n animation: ", " 0.5s ease-in;\n "])), height ? spanContainer(height) : slideIn);
|
|
46
|
+
} else {
|
|
47
|
+
return dsSystem.css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral__default["default"](["\n animation: ", " 0.5s ease-in;\n "])), height ? shrinkContainer(height) : slideOut);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.handleAnimation = handleAnimation;
|
|
53
|
+
exports.handleBorderColor = handleBorderColor;
|
package/esm/DSBanner.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
8
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
9
|
+
import React, { useRef, useState, useLayoutEffect, useCallback } from 'react';
|
|
10
|
+
import { CloseX } from '@elliemae/ds-icons';
|
|
11
|
+
import { describe } from 'react-desc';
|
|
12
|
+
import { icons } from './utils/icons.js';
|
|
13
|
+
import { propTypes } from './propTypes.js';
|
|
14
|
+
import { defaultProps } from './defaultProps.js';
|
|
15
|
+
import { StyledBannerContainer, StyledInnerContainer, StyledIconContainer, StyledTitle, StyledSubTitle, StyledActionLink, StyledCloseButton } from './styles.js';
|
|
16
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
17
|
+
|
|
18
|
+
var _CloseX, _span;
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
|
|
24
|
+
const DSBanner = _ref => {
|
|
25
|
+
let {
|
|
26
|
+
type,
|
|
27
|
+
isOpen,
|
|
28
|
+
onClose,
|
|
29
|
+
label,
|
|
30
|
+
body,
|
|
31
|
+
actionLink,
|
|
32
|
+
showCloseButton,
|
|
33
|
+
containerProps,
|
|
34
|
+
actionRef
|
|
35
|
+
} = _ref;
|
|
36
|
+
const innerContainerRef = useRef(null);
|
|
37
|
+
const linkRef = useRef(null);
|
|
38
|
+
const [current, setCurrent] = useState(isOpen);
|
|
39
|
+
const [isAnimating, setIsAnimating] = useState(false);
|
|
40
|
+
const [alertTabIndex, setAlertTabIndex] = useState(undefined);
|
|
41
|
+
const ownerState = {
|
|
42
|
+
type
|
|
43
|
+
};
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (actionRef && actionRef.current) {
|
|
46
|
+
actionRef.current.focusOnWrapper = () => {
|
|
47
|
+
if (innerContainerRef.current) {
|
|
48
|
+
setAlertTabIndex(0);
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
innerContainerRef.current.focus();
|
|
51
|
+
}, 100);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
actionRef.current.focusOnLink = () => {
|
|
56
|
+
if (linkRef.current) {
|
|
57
|
+
linkRef.current.focus();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}, [actionRef]);
|
|
62
|
+
useLayoutEffect(() => {
|
|
63
|
+
if (isOpen !== current || isOpen) setIsAnimating(true);else setIsAnimating(false);
|
|
64
|
+
}, [isOpen, current]);
|
|
65
|
+
const handleBlur = useCallback(() => {
|
|
66
|
+
setAlertTabIndex(undefined);
|
|
67
|
+
}, []);
|
|
68
|
+
const handleOnKeyDown = useCallback(e => {
|
|
69
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
if (linkRef.current) linkRef.current.click();
|
|
72
|
+
}
|
|
73
|
+
}, []);
|
|
74
|
+
if (!isAnimating && !isOpen) return null;
|
|
75
|
+
return /*#__PURE__*/jsx(StyledBannerContainer, _objectSpread(_objectSpread({
|
|
76
|
+
type: type,
|
|
77
|
+
isOpen: isOpen,
|
|
78
|
+
isAnimating: isAnimating,
|
|
79
|
+
onAnimationEnd: () => setCurrent(isOpen),
|
|
80
|
+
"data-testid": "ds-banner-container"
|
|
81
|
+
}, containerProps), {}, {
|
|
82
|
+
ownerState: ownerState,
|
|
83
|
+
children: /*#__PURE__*/jsxs(StyledInnerContainer, {
|
|
84
|
+
type: type,
|
|
85
|
+
isOpen: isOpen,
|
|
86
|
+
ref: innerContainerRef,
|
|
87
|
+
isAnimating: isAnimating,
|
|
88
|
+
"data-testid": "ds-banner",
|
|
89
|
+
role: "alert",
|
|
90
|
+
tabIndex: alertTabIndex,
|
|
91
|
+
onBlur: handleBlur,
|
|
92
|
+
children: [/*#__PURE__*/_jsx(StyledIconContainer, {
|
|
93
|
+
"data-testid": "ds-banner-icon"
|
|
94
|
+
}, void 0, icons[type]), /*#__PURE__*/_jsx(StyledTitle, {}, void 0, label), /*#__PURE__*/_jsx(StyledSubTitle, {}, void 0, /*#__PURE__*/_jsx("span", {}, void 0, body), actionLink && /*#__PURE__*/jsx(StyledActionLink, {
|
|
95
|
+
"data-testid": "ds-banner-action-link",
|
|
96
|
+
onClick: actionLink.onClick,
|
|
97
|
+
href: actionLink.href,
|
|
98
|
+
ref: linkRef,
|
|
99
|
+
onKeyDown: handleOnKeyDown,
|
|
100
|
+
tabIndex: 0,
|
|
101
|
+
isBodyEmpty: body,
|
|
102
|
+
children: actionLink.label
|
|
103
|
+
})), showCloseButton ? /*#__PURE__*/_jsx(StyledCloseButton, {
|
|
104
|
+
"data-testid": "ds-banner-close-button",
|
|
105
|
+
buttonType: "secondary",
|
|
106
|
+
onClick: onClose,
|
|
107
|
+
"aria-label": "Close icon",
|
|
108
|
+
icon: _CloseX || (_CloseX = /*#__PURE__*/_jsx(CloseX, {
|
|
109
|
+
width: "12px",
|
|
110
|
+
height: "12px"
|
|
111
|
+
}))
|
|
112
|
+
}) : _span || (_span = /*#__PURE__*/_jsx("span", {}))]
|
|
113
|
+
})
|
|
114
|
+
}));
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
DSBanner.defaultProps = defaultProps;
|
|
118
|
+
const DSBannerWithSchema = describe(DSBanner);
|
|
119
|
+
DSBannerWithSchema.propTypes = propTypes;
|
|
120
|
+
|
|
121
|
+
export { DSBannerWithSchema, DSBanner as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BANNER_TYPES } from './utils/bannerTypes.js';
|
|
2
|
+
|
|
3
|
+
const defaultProps = {
|
|
4
|
+
containerProps: {},
|
|
5
|
+
label: '',
|
|
6
|
+
body: '',
|
|
7
|
+
type: BANNER_TYPES.INFO,
|
|
8
|
+
isOpen: true,
|
|
9
|
+
onClose: () => null,
|
|
10
|
+
showCloseButton: true,
|
|
11
|
+
actionLink: {
|
|
12
|
+
label: '',
|
|
13
|
+
onClick: () => null,
|
|
14
|
+
href: ''
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { defaultProps };
|
package/esm/index.d.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/esm/index.js
ADDED
package/esm/propTypes.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PropTypes } from 'react-desc';
|
|
2
|
+
import { BANNER_TYPES } from './utils/bannerTypes.js';
|
|
3
|
+
|
|
4
|
+
const propTypes = {
|
|
5
|
+
containerProps: PropTypes.object.description('Set of Properties attached to the main container').defaultValue({}),
|
|
6
|
+
label: PropTypes.string.description('banner s label').defaultValue(''),
|
|
7
|
+
body: PropTypes.string.description('banner s body content').defaultValue(''),
|
|
8
|
+
type: PropTypes.oneOf(Object.values(BANNER_TYPES)).description('banner s type').defaultValue(BANNER_TYPES.INFO),
|
|
9
|
+
onClose: PropTypes.func.description('function executed when the banner closes'),
|
|
10
|
+
isOpen: PropTypes.bool.description('whether the banner is open or closed').defaultValue(true),
|
|
11
|
+
showCloseButton: PropTypes.bool.description('whether to show close button or not').defaultValue(true),
|
|
12
|
+
actionLink: PropTypes.shape({
|
|
13
|
+
label: PropTypes.string,
|
|
14
|
+
onClick: PropTypes.func,
|
|
15
|
+
href: PropTypes.string
|
|
16
|
+
}).description('Properties of the ActionLink component').defaultValue({}),
|
|
17
|
+
actionRef: PropTypes.object.description("\n Reference to use actions:\n - focusOnLink: function to focus the banner\n - focusOnWrapper: function to focus the link\n ").defaultValue({})
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { propTypes };
|