@sb1/ffe-feedback-react 1.1.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 SpareBank 1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @sb1/ffe-feedback-react
2
+
3
+ React module for FFE feedback element.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ npm install --save @sb1/ffe-feedback-react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Full documentation is not yet available, but will be added to https://design.sparebank1.no/komponenter.
14
+
15
+ ## TypeScript definition files
16
+
17
+ This component supports TypeScript - please update `index.d.ts` if you change any
18
+ of the external methods or properties in this component.
19
+
20
+ ## Development
21
+
22
+ To start a local development server, run the following from the designsystem root folder:
23
+
24
+ ```bash
25
+ npm install
26
+ npm run build
27
+ npm start
28
+ ```
29
+
30
+ A local instance of `component-overview` with live reloading will run at http://localhost:1234/.
31
+
32
+ Example implementations using the latest versions of all components are also available at https://sparebank1.github.io/designsystem.
@@ -0,0 +1,22 @@
1
+ import lottie from 'lottie-web';
2
+ import React, { useEffect, useRef } from 'react';
3
+ import highFiveAnimation from './high-five-animation.js';
4
+ export var Animation = function Animation() {
5
+ var containerRef = useRef();
6
+ useEffect(function () {
7
+ lottie.loadAnimation({
8
+ container: containerRef.current,
9
+ renderer: 'svg',
10
+ loop: false,
11
+ autoplay: true,
12
+ animationData: highFiveAnimation
13
+ });
14
+ }, []);
15
+ return /*#__PURE__*/React.createElement("div", {
16
+ ref: containerRef,
17
+ style: {
18
+ width: '180px',
19
+ height: '180px'
20
+ }
21
+ });
22
+ };
@@ -0,0 +1,84 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import React, { useState } from 'react';
8
+ import { Paragraph } from '@sb1/ffe-core-react';
9
+ import i18n from './i18n/i18n';
10
+ import { InputGroup, TextArea } from '@sb1/ffe-form-react';
11
+ import { ActionButton, ButtonGroup, TertiaryButton } from '@sb1/ffe-buttons-react';
12
+ import { func, oneOf, shape, string } from 'prop-types';
13
+ var FeedbackExpanded = function FeedbackExpanded(_ref) {
14
+ var language = _ref.language,
15
+ onSend = _ref.onSend,
16
+ onCancel = _ref.onCancel,
17
+ contactLink = _ref.contactLink;
18
+ var _useState = useState(''),
19
+ _useState2 = _slicedToArray(_useState, 2),
20
+ feedbackText = _useState2[0],
21
+ setFeedbackText = _useState2[1];
22
+ var _useState3 = useState(undefined),
23
+ _useState4 = _slicedToArray(_useState3, 2),
24
+ fieldMessage = _useState4[0],
25
+ setFieldMessage = _useState4[1];
26
+ var validateMessage = function validateMessage() {
27
+ if (feedbackText.length < 3) {
28
+ setFieldMessage(i18n[language].FEEDBACK_SHORT);
29
+ return false;
30
+ }
31
+ setFieldMessage(undefined);
32
+ return true;
33
+ };
34
+ var isValidContactLink = contactLink && (contactLink.url || contactLink.onClick);
35
+ var getLinkButton = function getLinkButton() {
36
+ var _contactLink$linkText;
37
+ return /*#__PURE__*/React.createElement(TertiaryButton, {
38
+ element: 'a',
39
+ href: contactLink.url,
40
+ className: "ffe-feedback__link-button",
41
+ onClick: contactLink.onClick
42
+ }, (_contactLink$linkText = contactLink.linkText) !== null && _contactLink$linkText !== void 0 ? _contactLink$linkText : i18n[language].FEEDBACK_LINKTEXT);
43
+ };
44
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Paragraph, null, i18n[language].FEEDBACK_ANSWER, isValidContactLink && i18n[language].QUESTIONS, isValidContactLink && getLinkButton()), /*#__PURE__*/React.createElement(Paragraph, null, i18n[language].FEEDBACK_SENSITIVE), /*#__PURE__*/React.createElement(InputGroup, {
45
+ className: "ffe-feedback__textarea-container",
46
+ fieldMessage: fieldMessage
47
+ }, /*#__PURE__*/React.createElement(TextArea, {
48
+ "data-testid": "feedbackTextArea",
49
+ onChange: function onChange(event) {
50
+ return setFeedbackText(event.target.value);
51
+ },
52
+ value: feedbackText,
53
+ rows: 6,
54
+ maxLength: 1000,
55
+ id: "textarea-feedback",
56
+ onBlur: validateMessage,
57
+ title: i18n[language].FEEDBACK_IMPROVE
58
+ })), /*#__PURE__*/React.createElement(ButtonGroup, {
59
+ className: "ffe-feedback__button-group"
60
+ }, /*#__PURE__*/React.createElement(ActionButton, {
61
+ onClick: function onClick() {
62
+ if (validateMessage()) {
63
+ onSend(feedbackText);
64
+ }
65
+ }
66
+ }, i18n[language].FEEDBACK_BUTTON_SEND), /*#__PURE__*/React.createElement(TertiaryButton, {
67
+ onClick: onCancel
68
+ }, i18n[language].FEEDBACK_BUTTON_CANCEL)));
69
+ };
70
+ export default FeedbackExpanded;
71
+ FeedbackExpanded.propTypes = {
72
+ language: oneOf(['nb', 'nn', 'en']),
73
+ onSend: func.isRequired,
74
+ onCancel: func.isRequired,
75
+ contactLink: shape({
76
+ url: string,
77
+ linkText: string,
78
+ onClick: func
79
+ })
80
+ };
81
+ FeedbackExpanded.defaultProps = {
82
+ language: 'nb',
83
+ contactLink: null
84
+ };
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import _Symbol from '@sb1/ffe-symbols-react';
3
+ import i18n from './i18n/i18n';
4
+ import { func, oneOf } from 'prop-types';
5
+ export var Thumbs = {
6
+ UP: 'THUMB_UP',
7
+ DOWN: 'THUMB_DOWN'
8
+ };
9
+ var THUMB_SIZE = '2xl';
10
+ var FeedbackThumbs = function FeedbackThumbs(_ref) {
11
+ var language = _ref.language,
12
+ _onClick = _ref.onClick;
13
+ var handleMouseEnter = function handleMouseEnter(event) {
14
+ // eslint-disable-next-line no-param-reassign
15
+ event.target.className = "ffe-symbol ffe-symbol--filled-400 ffe-symbol--".concat(THUMB_SIZE);
16
+ };
17
+ var handleMouseLeave = function handleMouseLeave(event) {
18
+ // eslint-disable-next-line no-param-reassign
19
+ event.target.className = "ffe-symbol ffe-symbol--400 ffe-symbol--".concat(THUMB_SIZE);
20
+ };
21
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
22
+ "aria-label": i18n[language].ARIA_LABEL_THUMB_UP,
23
+ "aria-describedby": "feedback-heading",
24
+ className: "ffe-feedback__thumb",
25
+ onClick: function onClick() {
26
+ return _onClick(Thumbs.UP);
27
+ }
28
+ }, /*#__PURE__*/React.createElement(_Symbol, {
29
+ onMouseEnter: handleMouseEnter,
30
+ onMouseLeave: handleMouseLeave,
31
+ size: THUMB_SIZE,
32
+ icon: "thumb_up"
33
+ })), /*#__PURE__*/React.createElement("button", {
34
+ "aria-label": i18n[language].ARIA_LABEL_THUMB_DOWN,
35
+ "aria-describedby": "feedback-heading",
36
+ className: "ffe-feedback__thumb",
37
+ onClick: function onClick() {
38
+ return _onClick(Thumbs.DOWN);
39
+ }
40
+ }, /*#__PURE__*/React.createElement(_Symbol, {
41
+ onMouseEnter: handleMouseEnter,
42
+ onMouseLeave: handleMouseLeave,
43
+ size: THUMB_SIZE,
44
+ icon: "thumb_down"
45
+ })));
46
+ };
47
+ export default FeedbackThumbs;
48
+ FeedbackThumbs.propTypes = {
49
+ language: oneOf(['nb', 'nn', 'en']),
50
+ onClick: func.isRequired
51
+ };
52
+ FeedbackThumbs.defaultProps = {
53
+ language: 'nb'
54
+ };
package/es/feedback.js ADDED
@@ -0,0 +1,105 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import React, { useState } from 'react';
12
+ import { Heading2 } from '@sb1/ffe-core-react';
13
+ import { Animation } from './animation';
14
+ import { func, oneOf, shape, string } from 'prop-types';
15
+ import i18n from './i18n/i18n';
16
+ import FeedbackThumbs, { Thumbs } from './feedback-thumbs';
17
+ import classNames from 'classnames';
18
+ import FeedbackExpanded from './feedback-expanded';
19
+ export var Feedback = function Feedback(_ref) {
20
+ var language = _ref.language,
21
+ onThumbClick = _ref.onThumbClick,
22
+ onFeedbackSend = _ref.onFeedbackSend,
23
+ bgColor = _ref.bgColor,
24
+ bgDarkmodeColor = _ref.bgDarkmodeColor,
25
+ contactLink = _ref.contactLink;
26
+ var _useState = useState(),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ feedbackThumbClicked = _useState2[0],
29
+ setFeedbackThumbClicked = _useState2[1];
30
+ var _useState3 = useState(false),
31
+ _useState4 = _slicedToArray(_useState3, 2),
32
+ expanded = _useState4[0],
33
+ setExpanded = _useState4[1];
34
+ var _useState5 = useState(false),
35
+ _useState6 = _slicedToArray(_useState5, 2),
36
+ feedbackSent = _useState6[0],
37
+ setFeedbackSent = _useState6[1];
38
+ var feedbackClassnames = classNames('ffe-feedback', _defineProperty(_defineProperty({}, "ffe-feedback--bg-".concat(bgColor), bgColor), "ffe-feedback--dm-bg-".concat(bgDarkmodeColor), bgDarkmodeColor));
39
+ var handleThumbClicked = function handleThumbClicked(thumb) {
40
+ setFeedbackThumbClicked(thumb);
41
+ setExpanded(!expanded);
42
+ onThumbClick(thumb);
43
+ };
44
+ var handleFeedbackSent = function handleFeedbackSent(feedbackText) {
45
+ setFeedbackSent(true);
46
+ onFeedbackSend(feedbackText);
47
+ };
48
+ if (feedbackSent) {
49
+ return /*#__PURE__*/React.createElement("div", {
50
+ className: feedbackClassnames
51
+ }, /*#__PURE__*/React.createElement("div", {
52
+ className: "ffe-feedback__content"
53
+ }, /*#__PURE__*/React.createElement(Heading2, {
54
+ lookLike: 4
55
+ }, i18n[language].FEEDBACK_SENT_HEADING), /*#__PURE__*/React.createElement(Animation, null)));
56
+ }
57
+ if (expanded) {
58
+ return /*#__PURE__*/React.createElement("div", {
59
+ className: feedbackClassnames
60
+ }, /*#__PURE__*/React.createElement("div", {
61
+ className: "ffe-feedback__content"
62
+ }, feedbackThumbClicked === Thumbs.UP ? /*#__PURE__*/React.createElement(Heading2, {
63
+ lookLike: 5
64
+ }, i18n[language].FEEDBACK_GOOD) : /*#__PURE__*/React.createElement(Heading2, {
65
+ lookLike: 5
66
+ }, i18n[language].FEEDBACK_IMPROVE), /*#__PURE__*/React.createElement(FeedbackExpanded, {
67
+ language: language,
68
+ onSend: handleFeedbackSent,
69
+ onCancel: function onCancel() {
70
+ return setExpanded(false);
71
+ },
72
+ contactLink: contactLink
73
+ })));
74
+ }
75
+ return /*#__PURE__*/React.createElement("div", {
76
+ className: feedbackClassnames
77
+ }, /*#__PURE__*/React.createElement("div", {
78
+ className: "ffe-feedback__content"
79
+ }, /*#__PURE__*/React.createElement(Heading2, {
80
+ id: "feedback-heading",
81
+ lookLike: 4
82
+ }, i18n[language].FEEDBACK_NOT_SENT_HEADING), /*#__PURE__*/React.createElement(FeedbackThumbs, {
83
+ onClick: handleThumbClicked,
84
+ language: language
85
+ })));
86
+ };
87
+ export default Feedback;
88
+ Feedback.propTypes = {
89
+ language: oneOf(['nb', 'nn', 'en']),
90
+ onThumbClick: func.isRequired,
91
+ onFeedbackSend: func.isRequired,
92
+ /** Set the background color of the feedback container. Accepts ffe-color variables without the "ffe-farge-" bit of the name. */
93
+ bgColor: oneOf(['hvit', 'frost-30', 'sand-30', 'syrin-30', 'vann-30']),
94
+ /** Set the background color of the feedback container in darkmode */
95
+ bgDarkmodeColor: oneOf(['svart', 'natt']),
96
+ contactLink: shape({
97
+ url: string,
98
+ linkText: string,
99
+ onClick: func
100
+ })
101
+ };
102
+ Feedback.defaultProps = {
103
+ language: 'nb',
104
+ contactLink: null
105
+ };