@cratis/showrunner.marquee.react 2.10.1 → 2.11.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.
Files changed (118) hide show
  1. package/Banner/MarqueeBanner.tsx +76 -19
  2. package/Dialog/MarqueeDialog.tsx +14 -3
  3. package/Icons.tsx +24 -0
  4. package/Labels/MarqueeLabels.ts +6 -0
  5. package/Labels/defaultMarqueeLabels.ts +2 -0
  6. package/Markdown/MarqueeInlineMarkdown.tsx +37 -0
  7. package/Markdown/MarqueeLink.tsx +14 -0
  8. package/Markdown/MarqueeMarkdown.tsx +3 -8
  9. package/Markdown/index.ts +2 -0
  10. package/Markdown/markdownText.ts +46 -0
  11. package/README.md +18 -4
  12. package/Selection/announcementSelection.ts +18 -3
  13. package/dist/cjs/Banner/MarqueeBanner.d.ts +1 -1
  14. package/dist/cjs/Banner/MarqueeBanner.d.ts.map +1 -1
  15. package/dist/cjs/Banner/MarqueeBanner.js +81 -24
  16. package/dist/cjs/Banner/MarqueeBanner.js.map +1 -1
  17. package/dist/cjs/Banner/MarqueeBanner.stories.d.ts +6 -0
  18. package/dist/cjs/Banner/MarqueeBanner.stories.d.ts.map +1 -1
  19. package/dist/cjs/Dialog/MarqueeDialog.d.ts.map +1 -1
  20. package/dist/cjs/Dialog/MarqueeDialog.js +16 -2
  21. package/dist/cjs/Dialog/MarqueeDialog.js.map +1 -1
  22. package/dist/cjs/Dialog/MarqueeDialog.stories.d.ts +2 -0
  23. package/dist/cjs/Dialog/MarqueeDialog.stories.d.ts.map +1 -1
  24. package/dist/cjs/Examples/LocalizedMarquee.d.ts.map +1 -1
  25. package/dist/cjs/Icons.d.ts +4 -0
  26. package/dist/cjs/Icons.d.ts.map +1 -1
  27. package/dist/cjs/Icons.js +16 -0
  28. package/dist/cjs/Icons.js.map +1 -1
  29. package/dist/cjs/Labels/MarqueeLabels.d.ts +2 -0
  30. package/dist/cjs/Labels/MarqueeLabels.d.ts.map +1 -1
  31. package/dist/cjs/Labels/defaultMarqueeLabels.d.ts.map +1 -1
  32. package/dist/cjs/Labels/defaultMarqueeLabels.js +2 -0
  33. package/dist/cjs/Labels/defaultMarqueeLabels.js.map +1 -1
  34. package/dist/cjs/Markdown/MarqueeInlineMarkdown.d.ts +6 -0
  35. package/dist/cjs/Markdown/MarqueeInlineMarkdown.d.ts.map +1 -0
  36. package/dist/cjs/Markdown/MarqueeInlineMarkdown.js +37 -0
  37. package/dist/cjs/Markdown/MarqueeInlineMarkdown.js.map +1 -0
  38. package/dist/cjs/Markdown/MarqueeLink.d.ts +5 -0
  39. package/dist/cjs/Markdown/MarqueeLink.d.ts.map +1 -0
  40. package/dist/cjs/Markdown/MarqueeLink.js +21 -0
  41. package/dist/cjs/Markdown/MarqueeLink.js.map +1 -0
  42. package/dist/cjs/Markdown/MarqueeMarkdown.d.ts.map +1 -1
  43. package/dist/cjs/Markdown/MarqueeMarkdown.js +2 -10
  44. package/dist/cjs/Markdown/MarqueeMarkdown.js.map +1 -1
  45. package/dist/cjs/Markdown/index.d.ts +2 -0
  46. package/dist/cjs/Markdown/index.d.ts.map +1 -1
  47. package/dist/cjs/Markdown/markdownText.d.ts +3 -0
  48. package/dist/cjs/Markdown/markdownText.d.ts.map +1 -0
  49. package/dist/cjs/Markdown/markdownText.js +35 -0
  50. package/dist/cjs/Markdown/markdownText.js.map +1 -0
  51. package/dist/cjs/Marquee.js +1 -0
  52. package/dist/cjs/Marquee.js.map +1 -1
  53. package/dist/cjs/Selection/announcementSelection.d.ts.map +1 -1
  54. package/dist/cjs/Selection/announcementSelection.js +15 -3
  55. package/dist/cjs/Selection/announcementSelection.js.map +1 -1
  56. package/dist/cjs/index.js +6 -0
  57. package/dist/cjs/index.js.map +1 -1
  58. package/dist/esm/Banner/MarqueeBanner.d.ts +1 -1
  59. package/dist/esm/Banner/MarqueeBanner.d.ts.map +1 -1
  60. package/dist/esm/Banner/MarqueeBanner.js +82 -25
  61. package/dist/esm/Banner/MarqueeBanner.js.map +1 -1
  62. package/dist/esm/Banner/MarqueeBanner.stories.d.ts +6 -0
  63. package/dist/esm/Banner/MarqueeBanner.stories.d.ts.map +1 -1
  64. package/dist/esm/Banner/MarqueeBanner.stories.js +18 -1
  65. package/dist/esm/Banner/MarqueeBanner.stories.js.map +1 -1
  66. package/dist/esm/Dialog/MarqueeDialog.d.ts.map +1 -1
  67. package/dist/esm/Dialog/MarqueeDialog.js +16 -2
  68. package/dist/esm/Dialog/MarqueeDialog.js.map +1 -1
  69. package/dist/esm/Dialog/MarqueeDialog.stories.d.ts +2 -0
  70. package/dist/esm/Dialog/MarqueeDialog.stories.d.ts.map +1 -1
  71. package/dist/esm/Dialog/MarqueeDialog.stories.js +3 -0
  72. package/dist/esm/Dialog/MarqueeDialog.stories.js.map +1 -1
  73. package/dist/esm/Examples/CustomBanner.js +2 -2
  74. package/dist/esm/Examples/CustomBanner.js.map +1 -1
  75. package/dist/esm/Examples/CustomDialog.js +2 -2
  76. package/dist/esm/Examples/CustomDialog.js.map +1 -1
  77. package/dist/esm/Examples/LocalizedMarquee.d.ts.map +1 -1
  78. package/dist/esm/Examples/LocalizedMarquee.js +2 -0
  79. package/dist/esm/Examples/LocalizedMarquee.js.map +1 -1
  80. package/dist/esm/Examples/OwnSurface.js +2 -2
  81. package/dist/esm/Examples/OwnSurface.js.map +1 -1
  82. package/dist/esm/Icons.d.ts +4 -0
  83. package/dist/esm/Icons.d.ts.map +1 -1
  84. package/dist/esm/Icons.js +16 -1
  85. package/dist/esm/Icons.js.map +1 -1
  86. package/dist/esm/Labels/MarqueeLabels.d.ts +2 -0
  87. package/dist/esm/Labels/MarqueeLabels.d.ts.map +1 -1
  88. package/dist/esm/Labels/defaultMarqueeLabels.d.ts.map +1 -1
  89. package/dist/esm/Labels/defaultMarqueeLabels.js +2 -0
  90. package/dist/esm/Labels/defaultMarqueeLabels.js.map +1 -1
  91. package/dist/esm/Markdown/MarqueeInlineMarkdown.d.ts +6 -0
  92. package/dist/esm/Markdown/MarqueeInlineMarkdown.d.ts.map +1 -0
  93. package/dist/esm/Markdown/MarqueeInlineMarkdown.js +35 -0
  94. package/dist/esm/Markdown/MarqueeInlineMarkdown.js.map +1 -0
  95. package/dist/esm/Markdown/MarqueeLink.d.ts +5 -0
  96. package/dist/esm/Markdown/MarqueeLink.d.ts.map +1 -0
  97. package/dist/esm/Markdown/MarqueeLink.js +19 -0
  98. package/dist/esm/Markdown/MarqueeLink.js.map +1 -0
  99. package/dist/esm/Markdown/MarqueeMarkdown.d.ts.map +1 -1
  100. package/dist/esm/Markdown/MarqueeMarkdown.js +2 -10
  101. package/dist/esm/Markdown/MarqueeMarkdown.js.map +1 -1
  102. package/dist/esm/Markdown/index.d.ts +2 -0
  103. package/dist/esm/Markdown/index.d.ts.map +1 -1
  104. package/dist/esm/Markdown/index.js +2 -0
  105. package/dist/esm/Markdown/index.js.map +1 -1
  106. package/dist/esm/Markdown/markdownText.d.ts +3 -0
  107. package/dist/esm/Markdown/markdownText.d.ts.map +1 -0
  108. package/dist/esm/Markdown/markdownText.js +32 -0
  109. package/dist/esm/Markdown/markdownText.js.map +1 -0
  110. package/dist/esm/Marquee.js +1 -0
  111. package/dist/esm/Marquee.js.map +1 -1
  112. package/dist/esm/Selection/announcementSelection.d.ts.map +1 -1
  113. package/dist/esm/Selection/announcementSelection.js +15 -3
  114. package/dist/esm/Selection/announcementSelection.js.map +1 -1
  115. package/dist/esm/index.js +3 -1
  116. package/dist/esm/index.js.map +1 -1
  117. package/package.json +2 -2
  118. package/styles.css +106 -7
@@ -2,10 +2,10 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import { AnnouncementForMe } from '@cratis/showrunner.marquee';
5
- import { ComponentType } from 'react';
6
- import { ImportanceIcon } from '../Icons.js';
5
+ import { ComponentType, KeyboardEvent, useId, useState } from 'react';
6
+ import { ChevronIcon, ImportanceIcon } from '../Icons.js';
7
7
  import { MarqueeLabels } from '../Labels/index.js';
8
- import { MarqueeMarkdown, MarqueeMarkdownProps } from '../Markdown/index.js';
8
+ import { hasMarkdown, MarqueeInlineMarkdown, MarqueeMarkdown, MarqueeMarkdownProps } from '../Markdown/index.js';
9
9
  import { importancePresentation } from '../Selection/index.js';
10
10
 
11
11
  /**
@@ -18,32 +18,89 @@ export interface MarqueeBannerProps {
18
18
  /** The texts to show. */
19
19
  labels: MarqueeLabels;
20
20
 
21
- /** Renders the Markdown of a body; the `markdown` slot of {@link Marquee}. */
21
+ /** Renders the Markdown of a message; the `markdown` slot of {@link Marquee}. */
22
22
  markdown?: ComponentType<MarqueeMarkdownProps>;
23
23
  }
24
24
 
25
+ interface MarqueeBannerItemProps {
26
+ announcement: AnnouncementForMe;
27
+ labels: MarqueeLabels;
28
+ markdown: ComponentType<MarqueeMarkdownProps>;
29
+ }
30
+
31
+ const MarqueeBannerItem = ({ announcement, labels, markdown: Markdown }: MarqueeBannerItemProps) => {
32
+ const presentation = importancePresentation(announcement.importance, labels);
33
+ const identifier = useId();
34
+ const messageId = `${identifier}-message`;
35
+ const tooltipId = `${identifier}-tooltip`;
36
+ const [expanded, setExpanded] = useState(false);
37
+ const [tooltipVisible, setTooltipVisible] = useState(false);
38
+ const hasMessage = hasMarkdown(announcement.body);
39
+
40
+ const handleKeyDown = (event: KeyboardEvent) => {
41
+ if (event.key === 'Escape') {
42
+ setTooltipVisible(false);
43
+ }
44
+ };
45
+
46
+ return (
47
+ <div className={`marquee-banner__item marquee-banner__item--${presentation.modifier}`}>
48
+ <div className='marquee-banner__row'>
49
+ <ImportanceIcon presentation={presentation} />
50
+ <span className='marquee-banner__title'>
51
+ <MarqueeInlineMarkdown source={announcement.title} />
52
+ </span>
53
+ {hasMessage && (
54
+ <span
55
+ className='marquee-banner__more'
56
+ onMouseEnter={() => setTooltipVisible(true)}
57
+ onMouseLeave={() => setTooltipVisible(false)}
58
+ onFocus={() => setTooltipVisible(true)}
59
+ onBlur={() => setTooltipVisible(false)}
60
+ onKeyDown={handleKeyDown}>
61
+ <button
62
+ type='button'
63
+ className='marquee-banner__toggle'
64
+ aria-expanded={expanded}
65
+ aria-controls={messageId}
66
+ aria-describedby={tooltipId}
67
+ aria-label={expanded ? labels.collapse : labels.expand}
68
+ onClick={() => setExpanded(!expanded)}>
69
+ <ChevronIcon expanded={expanded} />
70
+ </button>
71
+ <span
72
+ id={tooltipId}
73
+ role='tooltip'
74
+ className={tooltipVisible && !expanded ? 'marquee-banner__tooltip marquee-banner__tooltip--visible' : 'marquee-banner__tooltip'}>
75
+ <Markdown source={announcement.body} compact />
76
+ </span>
77
+ </span>
78
+ )}
79
+ </div>
80
+ {hasMessage && (
81
+ <div id={messageId} className='marquee-banner__message' hidden={!expanded}>
82
+ <Markdown source={announcement.body} />
83
+ </div>
84
+ )}
85
+ </div>
86
+ );
87
+ };
88
+
25
89
  /**
26
90
  * The banners at the top of the application, one row for each, with the icon and the color of its importance.
27
91
  *
92
+ * A banner shows its title only, with inline Markdown such as a link. When the announcement has a message, the row ends
93
+ * in a button that shows the message inline below the title, or hides it again, and hovering or focusing the button
94
+ * shows the message in a tooltip. Without a message there is no button and no tooltip.
95
+ *
28
96
  * The region is announced politely when a row appears, and is always rendered, because a live region that is added
29
97
  * with its content is not reliably announced. It takes no space while it is empty. A banner has no close button: it
30
98
  * stays until it is withdrawn or its window ends.
31
99
  */
32
- export const MarqueeBanner = ({ announcements, labels, markdown: Markdown = MarqueeMarkdown }: MarqueeBannerProps) => (
100
+ export const MarqueeBanner = ({ announcements, labels, markdown = MarqueeMarkdown }: MarqueeBannerProps) => (
33
101
  <div className='marquee-banner' role='status' aria-live='polite' aria-label={labels.banners}>
34
- {announcements.map(announcement => {
35
- const presentation = importancePresentation(announcement.importance, labels);
36
- return (
37
- <div key={announcement.id.toString()} className={`marquee-banner__item marquee-banner__item--${presentation.modifier}`}>
38
- <ImportanceIcon presentation={presentation} />
39
- <div className='marquee-banner__text'>
40
- <span className='marquee-banner__title'>{announcement.title}</span>
41
- <div className='marquee-banner__body'>
42
- <Markdown source={announcement.body} compact />
43
- </div>
44
- </div>
45
- </div>
46
- );
47
- })}
102
+ {announcements.map(announcement => (
103
+ <MarqueeBannerItem key={announcement.id.toString()} announcement={announcement} labels={labels} markdown={markdown} />
104
+ ))}
48
105
  </div>
49
106
  );
@@ -7,7 +7,7 @@ import { AnnouncementForMe } from '@cratis/showrunner.marquee';
7
7
  import { ComponentType } from 'react';
8
8
  import { ImportanceIcon } from '../Icons.js';
9
9
  import { MarqueeLabels } from '../Labels/index.js';
10
- import { MarqueeMarkdown, MarqueeMarkdownProps } from '../Markdown/index.js';
10
+ import { hasMarkdown, markdownToPlainText, MarqueeInlineMarkdown, MarqueeMarkdown, MarqueeMarkdownProps } from '../Markdown/index.js';
11
11
  import { importancePresentation } from '../Selection/index.js';
12
12
 
13
13
  /**
@@ -33,13 +33,19 @@ export interface MarqueeDialogProps {
33
33
  /**
34
34
  * One announcement in a dialog. Focus moves into the dialog and is kept in it until it is closed, and lands on the
35
35
  * title instead of the button, so the Enter or Space that was being pressed when it opened does not close it unread.
36
+ *
37
+ * The heading is the title as plain text, with the Markdown taken out, as a dialog heading is a string. A title that
38
+ * uses Markdown, such as a link, is shown again with its formatting at the top of the content. The message is optional
39
+ * and is left out when there is none.
36
40
  */
37
41
  export const MarqueeDialog = ({ announcement, hasMore, onClose, labels, markdown: Markdown = MarqueeMarkdown }: MarqueeDialogProps) => {
38
42
  const presentation = importancePresentation(announcement.importance, labels);
43
+ const plainTitle = markdownToPlainText(announcement.title);
44
+ const titleHasMarkdown = announcement.title.trim() !== plainTitle;
39
45
 
40
46
  return (
41
47
  <Dialog
42
- title={announcement.title}
48
+ title={plainTitle}
43
49
  width='34rem'
44
50
  buttons={DialogButtons.Ok}
45
51
  okLabel={hasMore ? labels.next : labels.acknowledge}
@@ -51,7 +57,12 @@ export const MarqueeDialog = ({ announcement, hasMore, onClose, labels, markdown
51
57
  <div className={`marquee-dialog__importance marquee-dialog__importance--${presentation.modifier}`}>
52
58
  <ImportanceIcon presentation={presentation} />
53
59
  </div>
54
- <Markdown source={announcement.body} />
60
+ {titleHasMarkdown && (
61
+ <p className='marquee-dialog__title'>
62
+ <MarqueeInlineMarkdown source={announcement.title} />
63
+ </p>
64
+ )}
65
+ {hasMarkdown(announcement.body) && <Markdown source={announcement.body} />}
55
66
  </div>
56
67
  </Dialog>
57
68
  );
package/Icons.tsx CHANGED
@@ -9,6 +9,30 @@ const paths: Record<ImportancePresentation['modifier'], string> = {
9
9
  critical: 'M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'
10
10
  };
11
11
 
12
+ /**
13
+ * Props for {@link ChevronIcon}.
14
+ */
15
+ export interface ChevronIconProps {
16
+ /** Whether the message it controls is shown; the chevron then points up instead of down. */
17
+ expanded: boolean;
18
+ }
19
+
20
+ /**
21
+ * The chevron on the button of a banner that shows or hides its message. It is decorative: the button is named by its
22
+ * label and says whether it is expanded.
23
+ */
24
+ export const ChevronIcon = ({ expanded }: ChevronIconProps) => (
25
+ <svg
26
+ className={expanded ? 'marquee-chevron marquee-chevron--expanded' : 'marquee-chevron'}
27
+ viewBox='0 0 24 24'
28
+ width='1em'
29
+ height='1em'
30
+ aria-hidden='true'
31
+ focusable='false'>
32
+ <path fill='currentColor' d='M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z' />
33
+ </svg>
34
+ );
35
+
12
36
  /**
13
37
  * Props for {@link ImportanceIcon}.
14
38
  */
@@ -17,6 +17,12 @@ export interface MarqueeLabels {
17
17
  /** The accessible name of the close button in the header of a dialog. */
18
18
  close: string;
19
19
 
20
+ /** The accessible name of the button of a banner that shows its message, when the message is hidden. */
21
+ expand: string;
22
+
23
+ /** The accessible name of the button of a banner that hides its message, when the message is shown. */
24
+ collapse: string;
25
+
20
26
  /** The accessible name of the icon of an announcement of information importance. */
21
27
  information: string;
22
28
 
@@ -11,6 +11,8 @@ export const defaultMarqueeLabels: MarqueeLabels = {
11
11
  acknowledge: 'Got it',
12
12
  next: 'Next',
13
13
  close: 'Close',
14
+ expand: 'Show the message',
15
+ collapse: 'Hide the message',
14
16
  information: 'Information',
15
17
  warning: 'Warning',
16
18
  critical: 'Critical'
@@ -0,0 +1,37 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ComponentType } from 'react';
5
+ import ReactMarkdown from 'react-markdown';
6
+ import { MarqueeLink } from './MarqueeLink.js';
7
+ import { safeLinkOrEmpty } from './safeLink.js';
8
+
9
+ /**
10
+ * Props for {@link MarqueeInlineMarkdown}.
11
+ */
12
+ export interface MarqueeInlineMarkdownProps {
13
+ /** The inline Markdown source, such as the title of an announcement. */
14
+ source: string;
15
+ }
16
+
17
+ const inlineElements = ['a', 'em', 'strong', 'code'];
18
+
19
+ /**
20
+ * Renders the inline Markdown of an announcement title, `Maintenance tonight. [Read more here.](https://status.example.com)`,
21
+ * as React elements inside a `span`: links, emphasis and code only. Block elements, such as paragraphs, headings, lists
22
+ * and code blocks, are not rendered, and their text runs on in the line. It follows the same safety rules as
23
+ * {@link MarqueeMarkdown}: raw HTML is dropped, images are left out, a link opens in a new tab with `noopener noreferrer`,
24
+ * and only `https`, `mailto` and `tel` links are links at all.
25
+ */
26
+ export const MarqueeInlineMarkdown: ComponentType<MarqueeInlineMarkdownProps> = ({ source }: MarqueeInlineMarkdownProps) => (
27
+ <span className='marquee-inline-markdown'>
28
+ <ReactMarkdown
29
+ skipHtml
30
+ allowedElements={inlineElements}
31
+ unwrapDisallowed
32
+ urlTransform={safeLinkOrEmpty}
33
+ components={{ a: MarqueeLink }}>
34
+ {source}
35
+ </ReactMarkdown>
36
+ </span>
37
+ );
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ComponentProps } from 'react';
5
+
6
+ type LinkProps = ComponentProps<'a'>;
7
+
8
+ /**
9
+ * A link in an announcement: it opens in a new tab with `noopener noreferrer`. A link that is not safe has no `href`
10
+ * left, because the URL transform emptied it, and is only its text.
11
+ */
12
+ export const MarqueeLink = ({ href, title, children }: LinkProps) => href
13
+ ? <a href={href} title={title} target='_blank' rel='noopener noreferrer'>{children}</a>
14
+ : <span>{children}</span>;
@@ -1,8 +1,9 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
- import { ComponentProps, ComponentType } from 'react';
4
+ import { ComponentType } from 'react';
5
5
  import ReactMarkdown from 'react-markdown';
6
+ import { MarqueeLink } from './MarqueeLink.js';
6
7
  import { safeLinkOrEmpty } from './safeLink.js';
7
8
 
8
9
  /**
@@ -17,12 +18,6 @@ export interface MarqueeMarkdownProps {
17
18
  compact?: boolean;
18
19
  }
19
20
 
20
- type LinkProps = ComponentProps<'a'>;
21
-
22
- const Link = ({ href, title, children }: LinkProps) => href
23
- ? <a href={href} title={title} target='_blank' rel='noopener noreferrer'>{children}</a>
24
- : <span>{children}</span>;
25
-
26
21
  /**
27
22
  * Renders the Markdown of an announcement as React elements, never as injected HTML: raw HTML in the source is
28
23
  * dropped, images are left out, a link opens in a new tab with `noopener noreferrer`, and only `https`, `mailto`
@@ -34,7 +29,7 @@ export const MarqueeMarkdown: ComponentType<MarqueeMarkdownProps> = ({ source, c
34
29
  skipHtml
35
30
  disallowedElements={['img']}
36
31
  urlTransform={safeLinkOrEmpty}
37
- components={{ a: Link }}>
32
+ components={{ a: MarqueeLink }}>
38
33
  {source}
39
34
  </ReactMarkdown>
40
35
  </div>
package/Markdown/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
+ export * from './MarqueeInlineMarkdown.js';
4
5
  export * from './MarqueeMarkdown.js';
6
+ export * from './markdownText.js';
5
7
  export * from './safeLink.js';
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ const codeMarker = '\u0000';
5
+ const codeSpan = /(`+)([\s\S]*?[^`])\1(?!`)/g;
6
+ const urlInParentheses = String.raw`\((?:[^()]|\([^()]*\))*\)`;
7
+
8
+ /**
9
+ * Turns the inline Markdown of an announcement title into the plain text a screen reader, a document title or an
10
+ * `aria-label` should get: a link keeps its text and loses its address, emphasis and code lose their markers, an image
11
+ * keeps its alternative text, and raw HTML tags are dropped.
12
+ * @param source The title as written, possibly with inline Markdown.
13
+ * @returns The text without Markdown, with white space collapsed.
14
+ */
15
+ export const markdownToPlainText = (source: string | null | undefined): string => {
16
+ if (!source) {
17
+ return '';
18
+ }
19
+
20
+ const codes: string[] = [];
21
+ const withoutCode = source.replace(codeSpan, (_, __, code: string) => {
22
+ codes.push(code.trim());
23
+ return `${codeMarker}${codes.length - 1}${codeMarker}`;
24
+ });
25
+
26
+ const plain = withoutCode
27
+ .replace(new RegExp(String.raw`!\[([^\]]*)\]${urlInParentheses}`, 'g'), '$1')
28
+ .replace(new RegExp(String.raw`\[([^\]]*)\]${urlInParentheses}`, 'g'), '$1')
29
+ .replace(/<((?:https?:\/\/|mailto:|tel:)[^>\s]+)>/g, '$1')
30
+ .replace(/<\/?[a-zA-Z][^>]*>/g, '')
31
+ .replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, '$2')
32
+ .replace(/(\*)(?=\S)([\s\S]*?\S)\1/g, '$2')
33
+ .replace(/(^|[^\p{L}\p{N}_])_(?=\S)([\s\S]*?\S)_(?![\p{L}\p{N}_])/gu, '$1$2')
34
+ .replace(/\\([\\`*_{}[\]()#+\-.!~<>|])/g, '$1')
35
+ .replace(new RegExp(`${codeMarker}(\\d+)${codeMarker}`, 'g'), (_, index: string) => codes[Number(index)]);
36
+
37
+ return plain.replace(/\s+/g, ' ').trim();
38
+ };
39
+
40
+ /**
41
+ * Whether there is anything to show in a Markdown text: the message of an announcement is optional, and a message of
42
+ * only white space is the same as none.
43
+ * @param source The Markdown as written, or nothing.
44
+ * @returns True when there is text.
45
+ */
46
+ export const hasMarkdown = (source: string | null | undefined): source is string => !!source && source.trim().length > 0;
package/README.md CHANGED
@@ -8,10 +8,12 @@ banners at the top and dialogs one at a time. Built on `@cratis/components` and
8
8
 
9
9
  ```
10
10
  Marquee useAnnouncements, then the banner and one dialog
11
- ├── MarqueeBanner role='status' live region, one row for each banner
12
- │ └── MarqueeMarkdown compact
11
+ ├── MarqueeBanner role='status' live region, one row for each banner: the title only
12
+ │ ├── MarqueeInlineMarkdown the title; links, emphasis and code
13
+ │ └── MarqueeMarkdown the message, when there is one: in a tooltip (compact) and when expanded
13
14
  └── MarqueeDialog Cratis Components Dialog, one announcement at a time
14
- └── MarqueeMarkdown
15
+ ├── MarqueeInlineMarkdown a title that uses Markdown, shown again with its links
16
+ └── MarqueeMarkdown the message, when there is one
15
17
  ```
16
18
 
17
19
  `banner`, `dialog` and `markdown` are slots: a product replaces any of them. `useAnnouncements` gives a product the
@@ -26,6 +28,7 @@ announcements to draw a surface of its own.
26
28
  | `Selection/announcementSelection.ts` | which announcements are inside their window, which dialogs are still due, in which order |
27
29
  | `Selection/importancePresentation.ts` | the modifier and the icon name of an importance |
28
30
  | `Markdown/safeLink.ts` | which links may be followed |
31
+ | `Markdown/markdownText.ts` | the plain text of a title (`markdownToPlainText`), and whether there is a message (`hasMarkdown`) |
29
32
  | `Labels/` | English defaults and overrides |
30
33
 
31
34
  - **The backend does not apply the window.** The query returns announcements scheduled for later, and
@@ -34,6 +37,16 @@ announcements to draw a surface of its own.
34
37
  not offered again if the observable query sends its list again. `DialogOnce` is also acknowledged through the
35
38
  command, which is what keeps it from coming back on any device. A failed acknowledgement does not keep the dialog
36
39
  open; it returns in the next session.
40
+ - **The title is inline Markdown and the message is optional.** `MarqueeInlineMarkdown` renders links, emphasis and code
41
+ only, under the same safety rules as `MarqueeMarkdown`. A string that must be plain, such as the heading of the dialog
42
+ (its `title` is a string), an `aria-label` or a document title, goes through `markdownToPlainText`. A message that is
43
+ empty or only white space is none: the banner has no button and no tooltip, and the dialog draws no message.
44
+ - **A banner shows the title only, and the message behind a button.** The button has `aria-expanded`, `aria-controls`
45
+ and a name from the `expand` and `collapse` labels. Hovering or focusing it shows the message in a `role='tooltip'`
46
+ that the button is described by, and Escape dismisses it. The tooltip is a few lines of React and CSS, with no extra
47
+ dependency, and is not shown while the message is expanded.
48
+ - **Both ends of the window are optional.** `ActiveFrom.Immediately` and `ActiveUntil.Indefinitely` arrive as the earliest
49
+ and latest dates; a date that is missing is read the same way. An announcement with no end is permanent.
37
50
  - **Markdown is rendered as elements, never as HTML.** `react-markdown` with `skipHtml`, images disallowed, and every
38
51
  link passed through `isSafeLink` (`https`, `mailto`, `tel`). A link opens in a new tab with `noopener noreferrer`.
39
52
  - **The banner region is always rendered**, because a live region that is added with its content is not reliably
@@ -46,4 +59,5 @@ announcements to draw a surface of its own.
46
59
 
47
60
  `Examples/` holds the code shown in the documentation. It is compiled with the package, and a specification fails when a
48
61
  documentation page no longer contains an example exactly as it builds. `yarn storybook` runs the stories of the banner
49
- and the dialog, one for each importance and display.
62
+ and the dialog, one for each importance and display, and the banner with and without a message, expanded, with its
63
+ tooltip, with a Markdown title and permanent.
@@ -14,19 +14,34 @@ export interface AnnouncementSelection {
14
14
  dialogs: AnnouncementForMe[];
15
15
  }
16
16
 
17
+ // Both ends of the window are optional. The backend sends the earliest date for an announcement that starts
18
+ // immediately and the latest for one that never ends; a date that is missing or not a date is read the same way.
19
+ const startOf = (announcement: AnnouncementForMe): number => {
20
+ const time = announcement.activeFrom?.getTime();
21
+ return time === undefined || Number.isNaN(time) ? Number.NEGATIVE_INFINITY : time;
22
+ };
23
+
24
+ const endOf = (announcement: AnnouncementForMe): number => {
25
+ const time = announcement.activeUntil?.getTime();
26
+ return time === undefined || Number.isNaN(time) ? Number.POSITIVE_INFINITY : time;
27
+ };
28
+
29
+ const compareTimes = (first: number, second: number): number => first === second ? 0 : first < second ? -1 : 1;
30
+
17
31
  /**
18
32
  * Whether an announcement is inside its window at a moment. The window starts at `activeFrom` and ends just before
19
- * `activeUntil`, so an announcement that ends at 18:00 is gone at 18:00.
33
+ * `activeUntil`, so an announcement that ends at 18:00 is gone at 18:00. An announcement without a start is shown from
34
+ * the beginning, and one without an end is shown until it is withdrawn: it is permanent.
20
35
  * @param announcement The announcement.
21
36
  * @param now The moment.
22
37
  * @returns True when it is to be shown.
23
38
  */
24
39
  export const isActiveAt = (announcement: AnnouncementForMe, now: Date): boolean =>
25
- announcement.activeFrom.getTime() <= now.getTime() && now.getTime() < announcement.activeUntil.getTime();
40
+ startOf(announcement) <= now.getTime() && now.getTime() < endOf(announcement);
26
41
 
27
42
  const byImportanceThenWindow = (first: AnnouncementForMe, second: AnnouncementForMe): number =>
28
43
  (second.importance - first.importance)
29
- || (first.activeFrom.getTime() - second.activeFrom.getTime())
44
+ || compareTimes(startOf(first), startOf(second))
30
45
  || first.id.toString().localeCompare(second.id.toString());
31
46
 
32
47
  /**
@@ -7,5 +7,5 @@ export interface MarqueeBannerProps {
7
7
  labels: MarqueeLabels;
8
8
  markdown?: ComponentType<MarqueeMarkdownProps>;
9
9
  }
10
- export declare const MarqueeBanner: ({ announcements, labels, markdown: Markdown }: MarqueeBannerProps) => import("react").JSX.Element;
10
+ export declare const MarqueeBanner: ({ announcements, labels, markdown }: MarqueeBannerProps) => import("react").JSX.Element;
11
11
  //# sourceMappingURL=MarqueeBanner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MarqueeBanner.d.ts","sourceRoot":"","sources":["../../../Banner/MarqueeBanner.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAmB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAM7E,MAAM,WAAW,kBAAkB;IAE/B,aAAa,EAAE,iBAAiB,EAAE,CAAC;IAGnC,MAAM,EAAE,aAAa,CAAC;IAGtB,QAAQ,CAAC,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;CAClD;AASD,eAAO,MAAM,aAAa,GAAI,+CAAiE,kBAAkB,gCAiBhH,CAAC"}
1
+ {"version":3,"file":"MarqueeBanner.d.ts","sourceRoot":"","sources":["../../../Banner/MarqueeBanner.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAkC,MAAM,OAAO,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAuD,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAMjH,MAAM,WAAW,kBAAkB;IAE/B,aAAa,EAAE,iBAAiB,EAAE,CAAC;IAGnC,MAAM,EAAE,aAAa,CAAC;IAGtB,QAAQ,CAAC,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;CAClD;AA6ED,eAAO,MAAM,aAAa,GAAI,qCAAuD,kBAAkB,gCAMtG,CAAC"}
@@ -1,41 +1,68 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
4
5
  var Icons = require('../Icons.js');
6
+ var MarqueeInlineMarkdown = require('../Markdown/MarqueeInlineMarkdown.js');
5
7
  var MarqueeMarkdown = require('../Markdown/MarqueeMarkdown.js');
8
+ var markdownText = require('../Markdown/markdownText.js');
6
9
  require('@cratis/showrunner.marquee');
7
10
  var importancePresentation = require('../Selection/importancePresentation.js');
8
11
 
9
12
  // Copyright (c) Cratis. All rights reserved.
10
13
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
11
- /**
12
- * The banners at the top of the application, one row for each, with the icon and the color of its importance.
13
- *
14
- * The region is announced politely when a row appears, and is always rendered, because a live region that is added
15
- * with its content is not reliably announced. It takes no space while it is empty. A banner has no close button: it
16
- * stays until it is withdrawn or its window ends.
17
- */ const MarqueeBanner = ({ announcements, labels, markdown: Markdown = MarqueeMarkdown.MarqueeMarkdown })=>/*#__PURE__*/ jsxRuntime.jsx("div", {
18
- className: "marquee-banner",
19
- role: "status",
20
- "aria-live": "polite",
21
- "aria-label": labels.banners,
22
- children: announcements.map((announcement)=>{
23
- const presentation = importancePresentation.importancePresentation(announcement.importance, labels);
24
- return /*#__PURE__*/ jsxRuntime.jsxs("div", {
25
- className: `marquee-banner__item marquee-banner__item--${presentation.modifier}`,
14
+ const MarqueeBannerItem = ({ announcement, labels, markdown: Markdown })=>{
15
+ const presentation = importancePresentation.importancePresentation(announcement.importance, labels);
16
+ const identifier = react.useId();
17
+ const messageId = `${identifier}-message`;
18
+ const tooltipId = `${identifier}-tooltip`;
19
+ const [expanded, setExpanded] = react.useState(false);
20
+ const [tooltipVisible, setTooltipVisible] = react.useState(false);
21
+ const hasMessage = markdownText.hasMarkdown(announcement.body);
22
+ const handleKeyDown = (event)=>{
23
+ if (event.key === 'Escape') {
24
+ setTooltipVisible(false);
25
+ }
26
+ };
27
+ return /*#__PURE__*/ jsxRuntime.jsxs("div", {
28
+ className: `marquee-banner__item marquee-banner__item--${presentation.modifier}`,
29
+ children: [
30
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
31
+ className: "marquee-banner__row",
26
32
  children: [
27
33
  /*#__PURE__*/ jsxRuntime.jsx(Icons.ImportanceIcon, {
28
34
  presentation: presentation
29
35
  }),
30
- /*#__PURE__*/ jsxRuntime.jsxs("div", {
31
- className: "marquee-banner__text",
36
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
37
+ className: "marquee-banner__title",
38
+ children: /*#__PURE__*/ jsxRuntime.jsx(MarqueeInlineMarkdown.MarqueeInlineMarkdown, {
39
+ source: announcement.title
40
+ })
41
+ }),
42
+ hasMessage && /*#__PURE__*/ jsxRuntime.jsxs("span", {
43
+ className: "marquee-banner__more",
44
+ onMouseEnter: ()=>setTooltipVisible(true),
45
+ onMouseLeave: ()=>setTooltipVisible(false),
46
+ onFocus: ()=>setTooltipVisible(true),
47
+ onBlur: ()=>setTooltipVisible(false),
48
+ onKeyDown: handleKeyDown,
32
49
  children: [
33
- /*#__PURE__*/ jsxRuntime.jsx("span", {
34
- className: "marquee-banner__title",
35
- children: announcement.title
50
+ /*#__PURE__*/ jsxRuntime.jsx("button", {
51
+ type: "button",
52
+ className: "marquee-banner__toggle",
53
+ "aria-expanded": expanded,
54
+ "aria-controls": messageId,
55
+ "aria-describedby": tooltipId,
56
+ "aria-label": expanded ? labels.collapse : labels.expand,
57
+ onClick: ()=>setExpanded(!expanded),
58
+ children: /*#__PURE__*/ jsxRuntime.jsx(Icons.ChevronIcon, {
59
+ expanded: expanded
60
+ })
36
61
  }),
37
- /*#__PURE__*/ jsxRuntime.jsx("div", {
38
- className: "marquee-banner__body",
62
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
63
+ id: tooltipId,
64
+ role: "tooltip",
65
+ className: tooltipVisible && !expanded ? 'marquee-banner__tooltip marquee-banner__tooltip--visible' : 'marquee-banner__tooltip',
39
66
  children: /*#__PURE__*/ jsxRuntime.jsx(Markdown, {
40
67
  source: announcement.body,
41
68
  compact: true
@@ -44,8 +71,38 @@ var importancePresentation = require('../Selection/importancePresentation.js');
44
71
  ]
45
72
  })
46
73
  ]
47
- }, announcement.id.toString());
48
- })
74
+ }),
75
+ hasMessage && /*#__PURE__*/ jsxRuntime.jsx("div", {
76
+ id: messageId,
77
+ className: "marquee-banner__message",
78
+ hidden: !expanded,
79
+ children: /*#__PURE__*/ jsxRuntime.jsx(Markdown, {
80
+ source: announcement.body
81
+ })
82
+ })
83
+ ]
84
+ });
85
+ };
86
+ /**
87
+ * The banners at the top of the application, one row for each, with the icon and the color of its importance.
88
+ *
89
+ * A banner shows its title only, with inline Markdown such as a link. When the announcement has a message, the row ends
90
+ * in a button that shows the message inline below the title, or hides it again, and hovering or focusing the button
91
+ * shows the message in a tooltip. Without a message there is no button and no tooltip.
92
+ *
93
+ * The region is announced politely when a row appears, and is always rendered, because a live region that is added
94
+ * with its content is not reliably announced. It takes no space while it is empty. A banner has no close button: it
95
+ * stays until it is withdrawn or its window ends.
96
+ */ const MarqueeBanner = ({ announcements, labels, markdown = MarqueeMarkdown.MarqueeMarkdown })=>/*#__PURE__*/ jsxRuntime.jsx("div", {
97
+ className: "marquee-banner",
98
+ role: "status",
99
+ "aria-live": "polite",
100
+ "aria-label": labels.banners,
101
+ children: announcements.map((announcement)=>/*#__PURE__*/ jsxRuntime.jsx(MarqueeBannerItem, {
102
+ announcement: announcement,
103
+ labels: labels,
104
+ markdown: markdown
105
+ }, announcement.id.toString()))
49
106
  });
50
107
 
51
108
  exports.MarqueeBanner = MarqueeBanner;
@@ -1 +1 @@
1
- {"version":3,"file":"MarqueeBanner.js","sources":["../../../Banner/MarqueeBanner.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { AnnouncementForMe } from '@cratis/showrunner.marquee';\nimport { ComponentType } from 'react';\nimport { ImportanceIcon } from '../Icons.js';\nimport { MarqueeLabels } from '../Labels/index.js';\nimport { MarqueeMarkdown, MarqueeMarkdownProps } from '../Markdown/index.js';\nimport { importancePresentation } from '../Selection/index.js';\n\n/**\n * Props for {@link MarqueeBanner}, and for the component given to the `banner` slot of {@link Marquee}.\n */\nexport interface MarqueeBannerProps {\n /** The banners to show, the most important first. Empty when there is none. */\n announcements: AnnouncementForMe[];\n\n /** The texts to show. */\n labels: MarqueeLabels;\n\n /** Renders the Markdown of a body; the `markdown` slot of {@link Marquee}. */\n markdown?: ComponentType<MarqueeMarkdownProps>;\n}\n\n/**\n * The banners at the top of the application, one row for each, with the icon and the color of its importance.\n *\n * The region is announced politely when a row appears, and is always rendered, because a live region that is added\n * with its content is not reliably announced. It takes no space while it is empty. A banner has no close button: it\n * stays until it is withdrawn or its window ends.\n */\nexport const MarqueeBanner = ({ announcements, labels, markdown: Markdown = MarqueeMarkdown }: MarqueeBannerProps) => (\n <div className='marquee-banner' role='status' aria-live='polite' aria-label={labels.banners}>\n {announcements.map(announcement => {\n const presentation = importancePresentation(announcement.importance, labels);\n return (\n <div key={announcement.id.toString()} className={`marquee-banner__item marquee-banner__item--${presentation.modifier}`}>\n <ImportanceIcon presentation={presentation} />\n <div className='marquee-banner__text'>\n <span className='marquee-banner__title'>{announcement.title}</span>\n <div className='marquee-banner__body'>\n <Markdown source={announcement.body} compact />\n </div>\n </div>\n </div>\n );\n })}\n </div>\n);\n"],"names":["MarqueeBanner","announcements","labels","markdown","Markdown","MarqueeMarkdown","_jsx","div","className","role","aria-live","aria-label","banners","map","announcement","presentation","importancePresentation","importance","_jsxs","modifier","ImportanceIcon","span","title","source","body","compact","id","toString"],"mappings":";;;;;;;;AAAA;AACA;AAuBA;;;;;;AAMC,IACM,MAAMA,aAAAA,GAAgB,CAAC,EAAEC,aAAa,EAAEC,MAAM,EAAEC,QAAAA,EAAUC,QAAAA,GAAWC,+BAAe,EAAsB,iBAC7GC,cAAA,CAACC,KAAAA,EAAAA;QAAIC,SAAAA,EAAU,gBAAA;QAAiBC,IAAAA,EAAK,QAAA;QAASC,WAAAA,EAAU,QAAA;AAASC,QAAAA,YAAAA,EAAYT,OAAOU,OAAO;kBACtFX,aAAAA,CAAcY,GAAG,CAACC,CAAAA,YAAAA,GAAAA;AACf,YAAA,MAAMC,YAAAA,GAAeC,6CAAAA,CAAuBF,YAAAA,CAAaG,UAAU,EAAEf,MAAAA,CAAAA;AACrE,YAAA,qBACIgB,eAAA,CAACX,KAAAA,EAAAA;AAAqCC,gBAAAA,SAAAA,EAAW,CAAC,2CAA2C,EAAEO,YAAAA,CAAaI,QAAQ,CAAA,CAAE;;kCAClHb,cAAA,CAACc,oBAAAA,EAAAA;wBAAeL,YAAAA,EAAcA;;kCAC9BG,eAAA,CAACX,KAAAA,EAAAA;wBAAIC,SAAAA,EAAU,sBAAA;;0CACXF,cAAA,CAACe,MAAAA,EAAAA;gCAAKb,SAAAA,EAAU,uBAAA;AAAyBM,gCAAAA,QAAAA,EAAAA,YAAAA,CAAaQ;;0CACtDhB,cAAA,CAACC,KAAAA,EAAAA;gCAAIC,SAAAA,EAAU,sBAAA;AACX,gCAAA,QAAA,gBAAAF,cAAA,CAACF,QAAAA,EAAAA;AAASmB,oCAAAA,MAAAA,EAAQT,aAAaU,IAAI;oCAAEC,OAAO,EAAA;;;;;;eAL9CX,YAAAA,CAAaY,EAAE,CAACC,QAAQ,EAAA,CAAA;AAU1C,QAAA,CAAA;AAEN,KAAA;;"}
1
+ {"version":3,"file":"MarqueeBanner.js","sources":["../../../Banner/MarqueeBanner.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { AnnouncementForMe } from '@cratis/showrunner.marquee';\nimport { ComponentType, KeyboardEvent, useId, useState } from 'react';\nimport { ChevronIcon, ImportanceIcon } from '../Icons.js';\nimport { MarqueeLabels } from '../Labels/index.js';\nimport { hasMarkdown, MarqueeInlineMarkdown, MarqueeMarkdown, MarqueeMarkdownProps } from '../Markdown/index.js';\nimport { importancePresentation } from '../Selection/index.js';\n\n/**\n * Props for {@link MarqueeBanner}, and for the component given to the `banner` slot of {@link Marquee}.\n */\nexport interface MarqueeBannerProps {\n /** The banners to show, the most important first. Empty when there is none. */\n announcements: AnnouncementForMe[];\n\n /** The texts to show. */\n labels: MarqueeLabels;\n\n /** Renders the Markdown of a message; the `markdown` slot of {@link Marquee}. */\n markdown?: ComponentType<MarqueeMarkdownProps>;\n}\n\ninterface MarqueeBannerItemProps {\n announcement: AnnouncementForMe;\n labels: MarqueeLabels;\n markdown: ComponentType<MarqueeMarkdownProps>;\n}\n\nconst MarqueeBannerItem = ({ announcement, labels, markdown: Markdown }: MarqueeBannerItemProps) => {\n const presentation = importancePresentation(announcement.importance, labels);\n const identifier = useId();\n const messageId = `${identifier}-message`;\n const tooltipId = `${identifier}-tooltip`;\n const [expanded, setExpanded] = useState(false);\n const [tooltipVisible, setTooltipVisible] = useState(false);\n const hasMessage = hasMarkdown(announcement.body);\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n setTooltipVisible(false);\n }\n };\n\n return (\n <div className={`marquee-banner__item marquee-banner__item--${presentation.modifier}`}>\n <div className='marquee-banner__row'>\n <ImportanceIcon presentation={presentation} />\n <span className='marquee-banner__title'>\n <MarqueeInlineMarkdown source={announcement.title} />\n </span>\n {hasMessage && (\n <span\n className='marquee-banner__more'\n onMouseEnter={() => setTooltipVisible(true)}\n onMouseLeave={() => setTooltipVisible(false)}\n onFocus={() => setTooltipVisible(true)}\n onBlur={() => setTooltipVisible(false)}\n onKeyDown={handleKeyDown}>\n <button\n type='button'\n className='marquee-banner__toggle'\n aria-expanded={expanded}\n aria-controls={messageId}\n aria-describedby={tooltipId}\n aria-label={expanded ? labels.collapse : labels.expand}\n onClick={() => setExpanded(!expanded)}>\n <ChevronIcon expanded={expanded} />\n </button>\n <span\n id={tooltipId}\n role='tooltip'\n className={tooltipVisible && !expanded ? 'marquee-banner__tooltip marquee-banner__tooltip--visible' : 'marquee-banner__tooltip'}>\n <Markdown source={announcement.body} compact />\n </span>\n </span>\n )}\n </div>\n {hasMessage && (\n <div id={messageId} className='marquee-banner__message' hidden={!expanded}>\n <Markdown source={announcement.body} />\n </div>\n )}\n </div>\n );\n};\n\n/**\n * The banners at the top of the application, one row for each, with the icon and the color of its importance.\n *\n * A banner shows its title only, with inline Markdown such as a link. When the announcement has a message, the row ends\n * in a button that shows the message inline below the title, or hides it again, and hovering or focusing the button\n * shows the message in a tooltip. Without a message there is no button and no tooltip.\n *\n * The region is announced politely when a row appears, and is always rendered, because a live region that is added\n * with its content is not reliably announced. It takes no space while it is empty. A banner has no close button: it\n * stays until it is withdrawn or its window ends.\n */\nexport const MarqueeBanner = ({ announcements, labels, markdown = MarqueeMarkdown }: MarqueeBannerProps) => (\n <div className='marquee-banner' role='status' aria-live='polite' aria-label={labels.banners}>\n {announcements.map(announcement => (\n <MarqueeBannerItem key={announcement.id.toString()} announcement={announcement} labels={labels} markdown={markdown} />\n ))}\n </div>\n);\n"],"names":["MarqueeBannerItem","announcement","labels","markdown","Markdown","presentation","importancePresentation","importance","identifier","useId","messageId","tooltipId","expanded","setExpanded","useState","tooltipVisible","setTooltipVisible","hasMessage","hasMarkdown","body","handleKeyDown","event","key","_jsxs","div","className","modifier","_jsx","ImportanceIcon","span","MarqueeInlineMarkdown","source","title","onMouseEnter","onMouseLeave","onFocus","onBlur","onKeyDown","button","type","aria-expanded","aria-controls","aria-describedby","aria-label","collapse","expand","onClick","ChevronIcon","id","role","compact","hidden","MarqueeBanner","announcements","MarqueeMarkdown","aria-live","banners","map","toString"],"mappings":"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"}