@financial-times/qanda-ui 1.0.0 → 1.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.
@@ -40,13 +40,17 @@ function Expander({ className = '', children = [], expandLabel = 'Expand', colla
40
40
  }
41
41
  const numberOfCharacters = element.textContent?.length || 300;
42
42
  const windowWidth = window.visualViewport?.width || window.innerWidth || 1200; // Fallback to desktop configuration.
43
- // Check if the element's height exceeds 3 lines for mobile or 1 line for above mobile
44
- // Note: This need to stay aligned with the CSS for the expander
45
- const mobileNumberOfCharacters = 100;
46
- const desktopNumberOfCharacters = 200;
43
+ // Approximate cut-off using character counts
44
+ // On average: ~176 characters on mobile (4 lines) and ~374 on desktop (5 lines)
45
+ // We set thresholds slightly higher (250 / 425) to ensure some text is hidden
46
+ // before showing the expander
47
+ // Note: This needs to stay aligned with the CSS for the expander
48
+ const mobileNumberOfCharacters = 225;
49
+ const desktopNumberOfCharacters = 425;
47
50
  const characterForExpander = windowWidth <= 490
48
51
  ? mobileNumberOfCharacters
49
52
  : desktopNumberOfCharacters;
53
+ // Show the expander if character count exceeds the threshold
50
54
  setExpander(numberOfCharacters > characterForExpander);
51
55
  };
52
56
  const debouncedCheck = debounce(checkNeedForExpanderButton, 250);
@@ -86,10 +86,10 @@ function FloatingActionBar({ isLive = true }) {
86
86
  'data-testid': `floating-action-bar__${view.testIdSuffix}`,
87
87
  ariaHasPopup: 'dialog',
88
88
  }, label: view.description, type: "ghost", theme: "mono", icon: "edit", iconOnly: isMobile, onClick: view.onClick }), (0, jsx_runtime_1.jsx)(o3_button_1.Button, { attributes: {
89
- ariaLabel: 'Back to top',
90
- 'data-trackable': (0, tracking_1.trackingNS)('back_to_top'),
91
- 'data-trackable-context-trigger_action': 'Back to top',
92
- 'data-testid': 'floating-action-bar__back-to-top-button',
93
- }, label: "Back to top", type: "ghost", theme: "mono", icon: "scroll-to", iconOnly: isMobile, onClick: handleShowUpdates })] }), updatedComments?.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "floating-action-bar__updates-counter o3-type-detail", "aria-label": `${updatedComments.length} new ${updatedComments.length === 1 ? 'update' : 'updates'} available`, role: "status", "aria-live": "polite", children: updatedComments.length }))] })] }));
89
+ ariaLabel: 'Latest answers',
90
+ 'data-trackable': (0, tracking_1.trackingNS)('latest-answers'),
91
+ 'data-trackable-context-trigger_action': 'Latest answers',
92
+ 'data-testid': 'floating-action-bar__latest-answers-button',
93
+ }, label: "Latest answers", type: "ghost", theme: "mono", icon: "scroll-to", iconOnly: isMobile, onClick: handleShowUpdates })] }), updatedComments?.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "floating-action-bar__updates-counter o3-type-detail", "aria-label": `${updatedComments.length} new ${updatedComments.length === 1 ? 'update' : 'updates'} available`, role: "status", "aria-live": "polite", children: updatedComments.length }))] })] }));
94
94
  }
95
95
  exports.default = FloatingActionBar;
@@ -38,13 +38,17 @@ function Expander({ className = '', children = [], expandLabel = 'Expand', colla
38
38
  }
39
39
  const numberOfCharacters = element.textContent?.length || 300;
40
40
  const windowWidth = window.visualViewport?.width || window.innerWidth || 1200; // Fallback to desktop configuration.
41
- // Check if the element's height exceeds 3 lines for mobile or 1 line for above mobile
42
- // Note: This need to stay aligned with the CSS for the expander
43
- const mobileNumberOfCharacters = 100;
44
- const desktopNumberOfCharacters = 200;
41
+ // Approximate cut-off using character counts
42
+ // On average: ~176 characters on mobile (4 lines) and ~374 on desktop (5 lines)
43
+ // We set thresholds slightly higher (250 / 425) to ensure some text is hidden
44
+ // before showing the expander
45
+ // Note: This needs to stay aligned with the CSS for the expander
46
+ const mobileNumberOfCharacters = 225;
47
+ const desktopNumberOfCharacters = 425;
45
48
  const characterForExpander = windowWidth <= 490
46
49
  ? mobileNumberOfCharacters
47
50
  : desktopNumberOfCharacters;
51
+ // Show the expander if character count exceeds the threshold
48
52
  setExpander(numberOfCharacters > characterForExpander);
49
53
  };
50
54
  const debouncedCheck = debounce(checkNeedForExpanderButton, 250);
@@ -84,10 +84,10 @@ function FloatingActionBar({ isLive = true }) {
84
84
  'data-testid': `floating-action-bar__${view.testIdSuffix}`,
85
85
  ariaHasPopup: 'dialog',
86
86
  }, label: view.description, type: "ghost", theme: "mono", icon: "edit", iconOnly: isMobile, onClick: view.onClick }), _jsx(Button, { attributes: {
87
- ariaLabel: 'Back to top',
88
- 'data-trackable': trackingNS('back_to_top'),
89
- 'data-trackable-context-trigger_action': 'Back to top',
90
- 'data-testid': 'floating-action-bar__back-to-top-button',
91
- }, label: "Back to top", type: "ghost", theme: "mono", icon: "scroll-to", iconOnly: isMobile, onClick: handleShowUpdates })] }), updatedComments?.length > 0 && (_jsx("div", { className: "floating-action-bar__updates-counter o3-type-detail", "aria-label": `${updatedComments.length} new ${updatedComments.length === 1 ? 'update' : 'updates'} available`, role: "status", "aria-live": "polite", children: updatedComments.length }))] })] }));
87
+ ariaLabel: 'Latest answers',
88
+ 'data-trackable': trackingNS('latest-answers'),
89
+ 'data-trackable-context-trigger_action': 'Latest answers',
90
+ 'data-testid': 'floating-action-bar__latest-answers-button',
91
+ }, label: "Latest answers", type: "ghost", theme: "mono", icon: "scroll-to", iconOnly: isMobile, onClick: handleShowUpdates })] }), updatedComments?.length > 0 && (_jsx("div", { className: "floating-action-bar__updates-counter o3-type-detail", "aria-label": `${updatedComments.length} new ${updatedComments.length === 1 ? 'update' : 'updates'} available`, role: "status", "aria-live": "polite", children: updatedComments.length }))] })] }));
92
92
  }
93
93
  export default FloatingActionBar;
package/dist/qanda.scss CHANGED
@@ -608,33 +608,24 @@ $app-header-color: #007acc;
608
608
  }
609
609
  }
610
610
 
611
- /* Mobile will show 3 lines of text before ellipse */
612
- @container (max-width: 490px) {
613
- .qanda-block__text.expander--collapsed
614
- .expander__text--multiline
615
- > p:first-of-type {
616
- display: block;
617
- display: -webkit-box;
618
- /* Note: This need to stay aligned with the JS for the expander */
619
- line-clamp: 3;
620
- -webkit-line-clamp: 3;
621
- -webkit-box-orient: vertical;
622
- overflow: hidden;
623
- text-overflow: ellipsis;
624
- /* Without this the letter like `g` may be visually cut.
611
+ .qanda-block__text.expander--collapsed
612
+ .expander__text--multiline
613
+ > p:first-of-type {
614
+ display: block;
615
+ display: -webkit-box;
616
+ /* Note: This need to stay aligned with the JS for the expander */
617
+ line-clamp: 4;
618
+ -webkit-line-clamp: 4;
619
+ -webkit-box-orient: vertical;
620
+ overflow: hidden;
621
+ text-overflow: ellipsis;
622
+ /* Without this the letter like `g` may be visually cut.
625
623
  To be tested with final font */
626
- padding-bottom: 1px;
627
- }
628
- }
629
-
630
- /* Above mobile it will show 1 line of text before ellipse */
631
- @container (min-width: 491px) {
632
- .qanda-block__text.expander--collapsed
633
- .expander__text--multiline
634
- > p:first-of-type {
635
- white-space: nowrap;
636
- text-overflow: ellipsis;
637
- overflow: hidden;
624
+ padding-bottom: 1px;
625
+ @container (min-width: 491px) {
626
+ /* Note: This need to stay aligned with the JS for the expander */
627
+ line-clamp: 5;
628
+ -webkit-line-clamp: 5;
638
629
  }
639
630
  }
640
631
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/qanda-ui",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",