@financial-times/qanda-ui 1.0.1 → 1.0.3
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/dist/cjs/components/ExpertDrawer/index.js +1 -1
- package/dist/cjs/components/FloatingActionBar/index.js +1 -22
- package/dist/cjs/components/Overlay/index.js +2 -1
- package/dist/esm/components/ExpertDrawer/index.js +1 -1
- package/dist/esm/components/FloatingActionBar/index.js +2 -23
- package/dist/esm/components/Overlay/index.js +2 -1
- package/dist/qanda.scss +18 -6
- package/dist/types/components/Overlay/index.d.ts +2 -1
- package/package.json +2 -3
|
@@ -30,7 +30,7 @@ function ExpertDrawer() {
|
|
|
30
30
|
if (!isExpertFormOpen) {
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
|
-
return ((0, jsx_runtime_1.jsx)(Overlay_1.default, { title: qanda_1.PRODUCT_NAME, closeCallback: () => {
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(Overlay_1.default, { title: qanda_1.PRODUCT_NAME, className: "expert-drawer", closeCallback: () => {
|
|
34
34
|
dispatch((0, expertSlice_1.closeExpertForm)());
|
|
35
35
|
focusDialogOpener?.();
|
|
36
36
|
}, options: {
|
|
@@ -9,30 +9,11 @@ const useIsMobile_1 = require("../../hooks/useIsMobile");
|
|
|
9
9
|
const comments_api_1 = require("../../services/comments-api");
|
|
10
10
|
const updateComments_1 = require("../../store/updateComments");
|
|
11
11
|
const react_1 = require("react");
|
|
12
|
-
const o_utils_1 = require("@financial-times/o-utils");
|
|
13
12
|
const QandaProvider_1 = require("../QandaProvider");
|
|
14
13
|
const tracking_1 = require("../../utils/tracking");
|
|
15
14
|
function LiveIndicator() {
|
|
16
15
|
return ((0, jsx_runtime_1.jsx)("div", { className: "o-labels-indicator--live o3-type-label floating-action-bar__live-container", children: (0, jsx_runtime_1.jsx)("span", { className: "o-labels-indicator__status floating-action-bar__live-label", children: "Live" }) }));
|
|
17
16
|
}
|
|
18
|
-
function useAlignToQanda(ref) {
|
|
19
|
-
(0, react_1.useEffect)(() => {
|
|
20
|
-
const align = () => {
|
|
21
|
-
const container = ref.current;
|
|
22
|
-
const qandaRoot = container?.closest('.qanda-container');
|
|
23
|
-
const target = qandaRoot?.querySelector('.qanda__blocks-container');
|
|
24
|
-
if (!target || !container)
|
|
25
|
-
return;
|
|
26
|
-
const rect = target.getBoundingClientRect();
|
|
27
|
-
container.style.left = `${rect.left}px`;
|
|
28
|
-
container.style.width = `${rect.width}px`;
|
|
29
|
-
};
|
|
30
|
-
align();
|
|
31
|
-
const debounced = (0, o_utils_1.debounce)(align, 100);
|
|
32
|
-
window.addEventListener('resize', debounced);
|
|
33
|
-
return () => window.removeEventListener('resize', debounced);
|
|
34
|
-
}, [ref]);
|
|
35
|
-
}
|
|
36
17
|
function FloatingActionBar({ isLive = true }) {
|
|
37
18
|
const dispatch = (0, react_redux_1.useDispatch)();
|
|
38
19
|
const isMobile = (0, useIsMobile_1.useIsMobile)();
|
|
@@ -77,9 +58,7 @@ function FloatingActionBar({ isLive = true }) {
|
|
|
77
58
|
dataTrackable: 'open_expert_drawer',
|
|
78
59
|
};
|
|
79
60
|
const view = showExpertView ? expertConfig : userConfig;
|
|
80
|
-
|
|
81
|
-
useAlignToQanda(containerRef);
|
|
82
|
-
return ((0, jsx_runtime_1.jsxs)("div", { ref: containerRef, className: "floating-action-bar__container", "data-trackable": (0, tracking_1.trackingNS)('floating-action-bar'), children: [(0, jsx_runtime_1.jsx)("div", { className: "floating-action-bar__fade-overlay" }), (0, jsx_runtime_1.jsxs)("div", { className: "floating-action-bar", "data-testid": "floating-action-bar", children: [(0, jsx_runtime_1.jsx)("span", { className: "o3-visually-hidden", "aria-live": "polite", role: "alert", children: isLive ? 'This session is now live' : '' }), isLive && (0, jsx_runtime_1.jsx)(LiveIndicator, {}), (0, jsx_runtime_1.jsxs)("div", { className: "floating-action-bar__buttons", ref: modalOpenerRef, children: [(0, jsx_runtime_1.jsx)(o3_button_1.Button, { attributes: {
|
|
61
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "floating-action-bar__container", "data-trackable": (0, tracking_1.trackingNS)('floating-action-bar'), children: [(0, jsx_runtime_1.jsx)("div", { className: "floating-action-bar__fade-overlay" }), (0, jsx_runtime_1.jsxs)("div", { className: "floating-action-bar", "data-testid": "floating-action-bar", children: [(0, jsx_runtime_1.jsx)("span", { className: "o3-visually-hidden", "aria-live": "polite", role: "alert", children: isLive ? 'This session is now live' : '' }), isLive && (0, jsx_runtime_1.jsx)(LiveIndicator, {}), (0, jsx_runtime_1.jsxs)("div", { className: "floating-action-bar__buttons", ref: modalOpenerRef, children: [(0, jsx_runtime_1.jsx)(o3_button_1.Button, { attributes: {
|
|
83
62
|
ariaLabel: view.description,
|
|
84
63
|
'data-trackable': (0, tracking_1.trackingNS)(view.dataTrackable),
|
|
85
64
|
'data-trackable-context-action': view.description,
|
|
@@ -7,7 +7,7 @@ const jsx_runtime_1 = require("preact/jsx-runtime");
|
|
|
7
7
|
const react_1 = require("react");
|
|
8
8
|
const o3_button_1 = require("@financial-times/o3-button");
|
|
9
9
|
const classnames_1 = __importDefault(require("classnames"));
|
|
10
|
-
function Overlay({ title, children, closeCallback, options = {}, }) {
|
|
10
|
+
function Overlay({ title, className, children, closeCallback, options = {}, }) {
|
|
11
11
|
// Trap keyboard focus within the overlay for accessibility
|
|
12
12
|
const trapFocus = (event) => {
|
|
13
13
|
if (event.key !== 'Tab')
|
|
@@ -27,6 +27,7 @@ function Overlay({ title, children, closeCallback, options = {}, }) {
|
|
|
27
27
|
return ((0, jsx_runtime_1.jsxs)("div", { className: "overlay", role: "dialog", "aria-modal": "true", "aria-labelledby": "overlay-title", children: [!options.allowInteraction && (0, jsx_runtime_1.jsx)("div", { className: "overlay__outer" }), (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)([
|
|
28
28
|
'overlay__inner',
|
|
29
29
|
{ 'overlay__inner--shadow': options.shadow },
|
|
30
|
+
className,
|
|
30
31
|
]), children: [(0, jsx_runtime_1.jsx)("div", { className: "overlay__header", children: (0, jsx_runtime_1.jsxs)("div", { className: "overlay__header-bar", children: [(0, jsx_runtime_1.jsx)("span", { className: "o3-type-body-highlight overlay__header-title", id: "overlay-title", tabIndex: 0, ref: titleRef, onKeyDown: trapFocus, children: title }), (0, jsx_runtime_1.jsx)(o3_button_1.Button, { attributes: { className: 'overlay__header-close' }, iconOnly: true, icon: "cross", label: "Close", type: "ghost", theme: "mono", onClick: () => closeCallback() })] }) }), (0, jsx_runtime_1.jsx)("div", { className: "overlay__content", children: children })] }), (0, jsx_runtime_1.jsx)("button", { className: "o3-visually-hidden", "aria-label": "Close", onClick: () => closeCallback(), ref: endFocusBtn, onKeyDown: trapFocus, type: "button", children: "Close" })] }));
|
|
31
32
|
}
|
|
32
33
|
exports.default = Overlay;
|
|
@@ -25,7 +25,7 @@ function ExpertDrawer() {
|
|
|
25
25
|
if (!isExpertFormOpen) {
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
|
-
return (_jsx(Overlay, { title: PRODUCT_NAME, closeCallback: () => {
|
|
28
|
+
return (_jsx(Overlay, { title: PRODUCT_NAME, className: "expert-drawer", closeCallback: () => {
|
|
29
29
|
dispatch(closeExpertForm());
|
|
30
30
|
focusDialogOpener?.();
|
|
31
31
|
}, options: {
|
|
@@ -6,31 +6,12 @@ import { openExpertForm } from '../../store/expertSlice';
|
|
|
6
6
|
import { useIsMobile } from '../../hooks/useIsMobile';
|
|
7
7
|
import { useUpdatedComments } from '../../services/comments-api';
|
|
8
8
|
import { updateComments } from '../../store/updateComments';
|
|
9
|
-
import { useContext, useRef
|
|
10
|
-
import { debounce } from '@financial-times/o-utils';
|
|
9
|
+
import { useContext, useRef } from 'react';
|
|
11
10
|
import { QandaContext } from '../QandaProvider';
|
|
12
11
|
import { trackingNS } from '../../utils/tracking';
|
|
13
12
|
function LiveIndicator() {
|
|
14
13
|
return (_jsx("div", { className: "o-labels-indicator--live o3-type-label floating-action-bar__live-container", children: _jsx("span", { className: "o-labels-indicator__status floating-action-bar__live-label", children: "Live" }) }));
|
|
15
14
|
}
|
|
16
|
-
function useAlignToQanda(ref) {
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const align = () => {
|
|
19
|
-
const container = ref.current;
|
|
20
|
-
const qandaRoot = container?.closest('.qanda-container');
|
|
21
|
-
const target = qandaRoot?.querySelector('.qanda__blocks-container');
|
|
22
|
-
if (!target || !container)
|
|
23
|
-
return;
|
|
24
|
-
const rect = target.getBoundingClientRect();
|
|
25
|
-
container.style.left = `${rect.left}px`;
|
|
26
|
-
container.style.width = `${rect.width}px`;
|
|
27
|
-
};
|
|
28
|
-
align();
|
|
29
|
-
const debounced = debounce(align, 100);
|
|
30
|
-
window.addEventListener('resize', debounced);
|
|
31
|
-
return () => window.removeEventListener('resize', debounced);
|
|
32
|
-
}, [ref]);
|
|
33
|
-
}
|
|
34
15
|
function FloatingActionBar({ isLive = true }) {
|
|
35
16
|
const dispatch = useDispatch();
|
|
36
17
|
const isMobile = useIsMobile();
|
|
@@ -75,9 +56,7 @@ function FloatingActionBar({ isLive = true }) {
|
|
|
75
56
|
dataTrackable: 'open_expert_drawer',
|
|
76
57
|
};
|
|
77
58
|
const view = showExpertView ? expertConfig : userConfig;
|
|
78
|
-
|
|
79
|
-
useAlignToQanda(containerRef);
|
|
80
|
-
return (_jsxs("div", { ref: containerRef, className: "floating-action-bar__container", "data-trackable": trackingNS('floating-action-bar'), children: [_jsx("div", { className: "floating-action-bar__fade-overlay" }), _jsxs("div", { className: "floating-action-bar", "data-testid": "floating-action-bar", children: [_jsx("span", { className: "o3-visually-hidden", "aria-live": "polite", role: "alert", children: isLive ? 'This session is now live' : '' }), isLive && _jsx(LiveIndicator, {}), _jsxs("div", { className: "floating-action-bar__buttons", ref: modalOpenerRef, children: [_jsx(Button, { attributes: {
|
|
59
|
+
return (_jsxs("div", { className: "floating-action-bar__container", "data-trackable": trackingNS('floating-action-bar'), children: [_jsx("div", { className: "floating-action-bar__fade-overlay" }), _jsxs("div", { className: "floating-action-bar", "data-testid": "floating-action-bar", children: [_jsx("span", { className: "o3-visually-hidden", "aria-live": "polite", role: "alert", children: isLive ? 'This session is now live' : '' }), isLive && _jsx(LiveIndicator, {}), _jsxs("div", { className: "floating-action-bar__buttons", ref: modalOpenerRef, children: [_jsx(Button, { attributes: {
|
|
81
60
|
ariaLabel: view.description,
|
|
82
61
|
'data-trackable': trackingNS(view.dataTrackable),
|
|
83
62
|
'data-trackable-context-action': view.description,
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
3
|
import { Button } from '@financial-times/o3-button';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
|
-
function Overlay({ title, children, closeCallback, options = {}, }) {
|
|
5
|
+
function Overlay({ title, className, children, closeCallback, options = {}, }) {
|
|
6
6
|
// Trap keyboard focus within the overlay for accessibility
|
|
7
7
|
const trapFocus = (event) => {
|
|
8
8
|
if (event.key !== 'Tab')
|
|
@@ -22,6 +22,7 @@ function Overlay({ title, children, closeCallback, options = {}, }) {
|
|
|
22
22
|
return (_jsxs("div", { className: "overlay", role: "dialog", "aria-modal": "true", "aria-labelledby": "overlay-title", children: [!options.allowInteraction && _jsx("div", { className: "overlay__outer" }), _jsxs("div", { className: classNames([
|
|
23
23
|
'overlay__inner',
|
|
24
24
|
{ 'overlay__inner--shadow': options.shadow },
|
|
25
|
+
className,
|
|
25
26
|
]), children: [_jsx("div", { className: "overlay__header", children: _jsxs("div", { className: "overlay__header-bar", children: [_jsx("span", { className: "o3-type-body-highlight overlay__header-title", id: "overlay-title", tabIndex: 0, ref: titleRef, onKeyDown: trapFocus, children: title }), _jsx(Button, { attributes: { className: 'overlay__header-close' }, iconOnly: true, icon: "cross", label: "Close", type: "ghost", theme: "mono", onClick: () => closeCallback() })] }) }), _jsx("div", { className: "overlay__content", children: children })] }), _jsx("button", { className: "o3-visually-hidden", "aria-label": "Close", onClick: () => closeCallback(), ref: endFocusBtn, onKeyDown: trapFocus, type: "button", children: "Close" })] }));
|
|
26
27
|
}
|
|
27
28
|
export default Overlay;
|
package/dist/qanda.scss
CHANGED
|
@@ -173,9 +173,9 @@ $app-header-color: #007acc;
|
|
|
173
173
|
.floating-action-bar__container {
|
|
174
174
|
position: fixed;
|
|
175
175
|
bottom: 0;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
left: 0;
|
|
177
|
+
right: 0;
|
|
178
|
+
display: flex;
|
|
179
179
|
/* Ensure FAB is on top of ...
|
|
180
180
|
1. some dinamically loaded teasers at the bottom of the article
|
|
181
181
|
2. the sharing bar on mobile
|
|
@@ -204,9 +204,8 @@ $app-header-color: #007acc;
|
|
|
204
204
|
height: 48px;
|
|
205
205
|
background: var(--o3-color-palette-white-60);
|
|
206
206
|
border-radius: 100px;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
margin: 0 auto var(--o3-spacing-s);
|
|
207
|
+
margin: auto;
|
|
208
|
+
margin-bottom: var(--o3-spacing-s);
|
|
210
209
|
padding: 0 var(--o3-spacing-2xs);
|
|
211
210
|
display: flex;
|
|
212
211
|
align-items: center;
|
|
@@ -520,6 +519,19 @@ $app-header-color: #007acc;
|
|
|
520
519
|
}
|
|
521
520
|
}
|
|
522
521
|
|
|
522
|
+
/* Inlined from ../components/ExpertDrawer/styles.css */
|
|
523
|
+
@media (min-width: 740px) {
|
|
524
|
+
.overlay__inner--shadow.expert-drawer {
|
|
525
|
+
width: 45vw;
|
|
526
|
+
min-width: 420px;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/* Currently, although it also works on FT-app, we optimise the expert drawer for usage on tablet/desktop on FT.com only (where the 'article-content' selector is) */
|
|
530
|
+
.article-content:has(.expert-drawer) {
|
|
531
|
+
max-width: 50vw;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
523
535
|
/* Inlined from ../components/QandaBlock/styles.css */
|
|
524
536
|
@import '@financial-times/o3-foundation/css/core.css';
|
|
525
537
|
|
|
@@ -4,9 +4,10 @@ type OverlayOptions = {
|
|
|
4
4
|
};
|
|
5
5
|
type OverlayProps = {
|
|
6
6
|
title: string;
|
|
7
|
+
className?: string;
|
|
7
8
|
children: React.ReactNode;
|
|
8
9
|
closeCallback: () => void;
|
|
9
10
|
options?: OverlayOptions;
|
|
10
11
|
};
|
|
11
|
-
declare function Overlay({ title, children, closeCallback, options, }: OverlayProps): import("react").JSX.Element;
|
|
12
|
+
declare function Overlay({ title, className, children, closeCallback, options, }: OverlayProps): import("react").JSX.Element;
|
|
12
13
|
export default Overlay;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@financial-times/qanda-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Components for the Live Q&A (AKA Ask an Expert) UI",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/Financial-Times/qanda-ui#readme",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@financial-times/o-utils": "^2.2.1",
|
|
44
43
|
"@reduxjs/toolkit": "^1.9.5",
|
|
45
44
|
"classnames": "^2.5.1"
|
|
46
45
|
},
|
|
@@ -50,6 +49,7 @@
|
|
|
50
49
|
"@babel/preset-env": "^7.26.0",
|
|
51
50
|
"@babel/preset-react": "^7.26.3",
|
|
52
51
|
"@babel/preset-typescript": "^7.26.0",
|
|
52
|
+
"@types/react-redux": "^7.1.34",
|
|
53
53
|
"@dotcom-tool-kit/component": "^5.1.12",
|
|
54
54
|
"@dotcom-tool-kit/jest": "^4.3.1",
|
|
55
55
|
"@financial-times/o-colors": "^6.7.0",
|
|
@@ -59,7 +59,6 @@
|
|
|
59
59
|
"@testing-library/preact": "^3.2.4",
|
|
60
60
|
"@types/jest": "^29.5.14",
|
|
61
61
|
"@types/jest-axe": "^3.5.9",
|
|
62
|
-
"@types/react-redux": "^7.1.34",
|
|
63
62
|
"@typescript-eslint/eslint-plugin": "^8.18.0",
|
|
64
63
|
"@typescript-eslint/parser": "^8.18.0",
|
|
65
64
|
"babel-jest": "^29.7.0",
|