@sb1/ffe-feedback-react 2.0.45 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -5
- package/es/Animation.js +18 -0
- package/es/Feedback.js +61 -0
- package/es/FeedbackExpanded.js +35 -0
- package/es/FeedbackThumbs.js +13 -0
- package/es/highFiveAnimation.js +24158 -0
- package/es/i18n/en.js +16 -16
- package/es/i18n/nb.js +16 -16
- package/es/i18n/nn.js +16 -16
- package/es/i18n/texts.js +8 -0
- package/es/icons/ThumbDown.js +14 -0
- package/es/icons/ThumbDownFill.js +14 -0
- package/es/icons/ThumbUp.js +14 -0
- package/es/icons/index.js +4 -4
- package/es/icons/thumbUpFill.js +14 -0
- package/es/index.js +1 -4
- package/lib/Animation.js +48 -0
- package/lib/Feedback.js +91 -0
- package/lib/FeedbackExpanded.js +62 -0
- package/lib/FeedbackThumbs.js +20 -0
- package/lib/highFiveAnimation.js +24160 -0
- package/lib/i18n/en.js +18 -21
- package/lib/i18n/nb.js +18 -21
- package/lib/i18n/nn.js +18 -21
- package/lib/i18n/texts.js +11 -0
- package/lib/icons/ThumbDown.js +21 -0
- package/lib/icons/ThumbDownFill.js +21 -0
- package/lib/icons/ThumbUp.js +21 -0
- package/lib/icons/index.js +10 -33
- package/lib/icons/thumbUpFill.js +21 -0
- package/lib/index.js +4 -15
- package/package.json +7 -9
- package/types/Animation.d.ts +2 -0
- package/types/Feedback.d.ts +15 -0
- package/types/FeedbackExpanded.d.ts +12 -0
- package/types/FeedbackThumbs.d.ts +9 -0
- package/types/highFiveAnimation.d.ts +4085 -0
- package/types/i18n/en.d.ts +16 -0
- package/types/i18n/nb.d.ts +16 -0
- package/types/i18n/nn.d.ts +16 -0
- package/types/i18n/texts.d.ts +50 -0
- package/types/icons/ThumbDown.d.ts +2 -0
- package/types/icons/ThumbDownFill.d.ts +2 -0
- package/types/icons/ThumbUp.d.ts +2 -0
- package/types/icons/index.d.ts +4 -0
- package/types/icons/thumbUpFill.d.ts +2 -0
- package/types/index.d.ts +2 -29
- package/es/animation.js +0 -22
- package/es/feedback-expanded.js +0 -82
- package/es/feedback-thumbs.js +0 -45
- package/es/feedback.js +0 -120
- package/es/high-five-animation.js +0 -1
- package/es/i18n/i18n.js +0 -8
- package/es/icons/thumb-down-fill.js +0 -14
- package/es/icons/thumb-down.js +0 -14
- package/es/icons/thumb-up-fill.js +0 -14
- package/es/icons/thumb-up.js +0 -14
- package/es/index.d.js +0 -3
- package/lib/animation.js +0 -32
- package/lib/feedback-expanded.js +0 -92
- package/lib/feedback-thumbs.js +0 -52
- package/lib/feedback.js +0 -129
- package/lib/high-five-animation.js +0 -1
- package/lib/i18n/i18n.js +0 -15
- package/lib/icons/thumb-down-fill.js +0 -23
- package/lib/icons/thumb-down.js +0 -23
- package/lib/icons/thumb-up-fill.js +0 -23
- package/lib/icons/thumb-up.js +0 -23
- package/lib/index.d.js +0 -16
package/README.md
CHANGED
|
@@ -12,11 +12,6 @@ npm install --save @sb1/ffe-feedback-react
|
|
|
12
12
|
|
|
13
13
|
Full documentation is not yet available, but will be added to https://design.sparebank1.no/komponenter.
|
|
14
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
15
|
## Development
|
|
21
16
|
|
|
22
17
|
To start a local development server, run the following from the designsystem root folder:
|
package/es/Animation.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import lottie from 'lottie-web';
|
|
2
|
+
import React, { useEffect, useRef } from 'react';
|
|
3
|
+
import highFiveAnimation from './highFiveAnimation';
|
|
4
|
+
export var Animation = function () {
|
|
5
|
+
var containerRef = useRef(null);
|
|
6
|
+
useEffect(function () {
|
|
7
|
+
if (containerRef.current) {
|
|
8
|
+
lottie.loadAnimation({
|
|
9
|
+
container: containerRef.current,
|
|
10
|
+
renderer: 'svg',
|
|
11
|
+
loop: false,
|
|
12
|
+
autoplay: true,
|
|
13
|
+
animationData: highFiveAnimation,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
return (React.createElement("div", { ref: containerRef, style: { width: '180px', height: '180px' } }));
|
|
18
|
+
};
|
package/es/Feedback.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useState, useRef } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { Animation } from './Animation';
|
|
4
|
+
import { texts } from './i18n/texts';
|
|
5
|
+
import { FeedbackThumbs } from './FeedbackThumbs';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { FeedbackExpanded } from './FeedbackExpanded';
|
|
8
|
+
import { v4 as uuid } from 'uuid';
|
|
9
|
+
export var Feedback = function (_a) {
|
|
10
|
+
var _b;
|
|
11
|
+
var headingLevel = _a.headingLevel, _c = _a.locale, locale = _c === void 0 ? 'nb' : _c, onThumbClick = _a.onThumbClick, onFeedbackSend = _a.onFeedbackSend, bgColor = _a.bgColor, bgDarkmodeColor = _a.bgDarkmodeColor, contactLink = _a.contactLink;
|
|
12
|
+
var feedbackSentRef = useRef();
|
|
13
|
+
var expandedRef = useRef();
|
|
14
|
+
var _d = useState(), feedbackThumbClicked = _d[0], setFeedbackThumbClicked = _d[1];
|
|
15
|
+
var _e = useState(false), expanded = _e[0], setExpanded = _e[1];
|
|
16
|
+
var _f = useState(false), feedbackSent = _f[0], setFeedbackSent = _f[1];
|
|
17
|
+
var headingId = useRef(uuid()).current;
|
|
18
|
+
var feedbackClassnames = classNames('ffe-feedback', (_b = {},
|
|
19
|
+
_b["ffe-feedback--bg-".concat(bgColor)] = bgColor,
|
|
20
|
+
_b["ffe-feedback--dm-bg-".concat(bgDarkmodeColor)] = bgDarkmodeColor,
|
|
21
|
+
_b));
|
|
22
|
+
var handleThumbClicked = function (thumb) {
|
|
23
|
+
var _a;
|
|
24
|
+
setFeedbackThumbClicked(thumb);
|
|
25
|
+
flushSync(function () {
|
|
26
|
+
setExpanded(function (prevState) { return !prevState; });
|
|
27
|
+
});
|
|
28
|
+
(_a = expandedRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
29
|
+
onThumbClick(thumb);
|
|
30
|
+
};
|
|
31
|
+
var handleFeedbackSent = function (feedbackText) {
|
|
32
|
+
var _a;
|
|
33
|
+
flushSync(function () {
|
|
34
|
+
setFeedbackSent(true);
|
|
35
|
+
});
|
|
36
|
+
(_a = feedbackSentRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
37
|
+
onFeedbackSend(feedbackText);
|
|
38
|
+
};
|
|
39
|
+
if (feedbackSent) {
|
|
40
|
+
return (React.createElement("div", { className: feedbackClassnames },
|
|
41
|
+
React.createElement("div", { className: "ffe-feedback__content" },
|
|
42
|
+
React.createElement("h".concat(headingLevel), {
|
|
43
|
+
ref: feedbackSentRef,
|
|
44
|
+
tabIndex: -1,
|
|
45
|
+
className: 'ffe-h4',
|
|
46
|
+
}, texts[locale].FEEDBACK_SENT_HEADING),
|
|
47
|
+
React.createElement(Animation, null))));
|
|
48
|
+
}
|
|
49
|
+
if (expanded) {
|
|
50
|
+
return (React.createElement("div", { className: feedbackClassnames },
|
|
51
|
+
React.createElement("div", { className: "ffe-feedback__content" },
|
|
52
|
+
React.createElement("h".concat(headingLevel), { ref: expandedRef, tabIndex: -1, className: 'ffe-h5' }, feedbackThumbClicked === 'THUMB_UP'
|
|
53
|
+
? texts[locale].FEEDBACK_GOOD
|
|
54
|
+
: texts[locale].FEEDBACK_IMPROVE),
|
|
55
|
+
React.createElement(FeedbackExpanded, { locale: locale, onSend: handleFeedbackSent, onCancel: function () { return setExpanded(false); }, contactLink: contactLink }))));
|
|
56
|
+
}
|
|
57
|
+
return (React.createElement("div", { className: feedbackClassnames },
|
|
58
|
+
React.createElement("div", { className: "ffe-feedback__content" },
|
|
59
|
+
React.createElement("h".concat(headingLevel), { id: headingId, className: 'ffe-h4' }, texts[locale].FEEDBACK_NOT_SENT_HEADING),
|
|
60
|
+
React.createElement(FeedbackThumbs, { onClick: handleThumbClicked, locale: locale, headingId: headingId }))));
|
|
61
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Paragraph } from '@sb1/ffe-core-react';
|
|
3
|
+
import { texts } from './i18n/texts';
|
|
4
|
+
import { InputGroup, TextArea } from '@sb1/ffe-form-react';
|
|
5
|
+
import { ActionButton, ButtonGroup, TertiaryButton, } from '@sb1/ffe-buttons-react';
|
|
6
|
+
export var FeedbackExpanded = function (_a) {
|
|
7
|
+
var _b;
|
|
8
|
+
var locale = _a.locale, onSend = _a.onSend, onCancel = _a.onCancel, contactLink = _a.contactLink;
|
|
9
|
+
var _c = useState(), feedbackText = _c[0], setFeedbackText = _c[1];
|
|
10
|
+
var _d = useState(), fieldMessage = _d[0], setFieldMessage = _d[1];
|
|
11
|
+
var validateMessage = function () {
|
|
12
|
+
if (feedbackText && (feedbackText === null || feedbackText === void 0 ? void 0 : feedbackText.length) >= 3) {
|
|
13
|
+
setFieldMessage(undefined);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
setFieldMessage(texts[locale].FEEDBACK_SHORT);
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
var contactLinkElement = contactLink ? (React.createElement(TertiaryButton, { as: "a", href: contactLink.url, className: "ffe-feedback__link-button", onClick: contactLink === null || contactLink === void 0 ? void 0 : contactLink.onClick }, (_b = contactLink.linkText) !== null && _b !== void 0 ? _b : texts[locale].FEEDBACK_LINKTEXT)) : null;
|
|
20
|
+
return (React.createElement(React.Fragment, null,
|
|
21
|
+
React.createElement(Paragraph, null,
|
|
22
|
+
texts[locale].FEEDBACK_ANSWER,
|
|
23
|
+
contactLinkElement && texts[locale].QUESTIONS,
|
|
24
|
+
contactLinkElement),
|
|
25
|
+
React.createElement(Paragraph, null, texts[locale].FEEDBACK_SENSITIVE),
|
|
26
|
+
React.createElement(InputGroup, { className: "ffe-feedback__textarea-container", fieldMessage: fieldMessage },
|
|
27
|
+
React.createElement(TextArea, { "data-testid": "feedbackTextArea", onChange: function (event) { return setFeedbackText(event.target.value); }, value: feedbackText, rows: 6, maxLength: 1000, id: "textarea-feedback", onBlur: validateMessage, title: texts[locale].FEEDBACK_IMPROVE })),
|
|
28
|
+
React.createElement(ButtonGroup, { className: "ffe-feedback__button-group" },
|
|
29
|
+
React.createElement(ActionButton, { onClick: function () {
|
|
30
|
+
if (validateMessage() && feedbackText) {
|
|
31
|
+
onSend(feedbackText);
|
|
32
|
+
}
|
|
33
|
+
} }, texts[locale].FEEDBACK_BUTTON_SEND),
|
|
34
|
+
React.createElement(TertiaryButton, { onClick: onCancel }, texts[locale].FEEDBACK_BUTTON_CANCEL))));
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { texts } from './i18n/texts';
|
|
3
|
+
import { ThumbUp, ThumbUpFill, ThumbDown, ThumbDownFill } from './icons';
|
|
4
|
+
export var FeedbackThumbs = function (_a) {
|
|
5
|
+
var locale = _a.locale, onClick = _a.onClick, headingId = _a.headingId;
|
|
6
|
+
return (React.createElement("div", null,
|
|
7
|
+
React.createElement("button", { "aria-label": texts[locale].ARIA_LABEL_THUMB_UP, "aria-describedby": headingId, className: "ffe-feedback__thumb", onClick: function () { return onClick('THUMB_UP'); }, type: "button" },
|
|
8
|
+
React.createElement(ThumbUp, { className: "ffe-feedback__thumb-icon" }),
|
|
9
|
+
React.createElement(ThumbUpFill, { className: "ffe-feedback__thumb-icon--fill" })),
|
|
10
|
+
React.createElement("button", { "aria-label": texts[locale].ARIA_LABEL_THUMB_DOWN, "aria-describedby": headingId, className: "ffe-feedback__thumb", onClick: function () { return onClick('THUMB_DOWN'); }, type: "button" },
|
|
11
|
+
React.createElement(ThumbDown, { className: "ffe-feedback__thumb-icon" }),
|
|
12
|
+
React.createElement(ThumbDownFill, { className: "ffe-feedback__thumb-icon--fill" }))));
|
|
13
|
+
};
|