@olenbetong/synergi-course 2.1.0 → 2.2.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 (47) hide show
  1. package/es/document/cues.d.ts +1 -1
  2. package/es/document/cues.js +3 -1
  3. package/es/document/effects.d.ts +3 -3
  4. package/es/document/effects.js +3 -1
  5. package/es/document/schema.d.ts +1778 -190
  6. package/es/document/schema.js +35 -2
  7. package/es/document/validate.js +14 -18
  8. package/es/index.d.ts +3 -2
  9. package/es/index.js +1 -1
  10. package/es/player/CoursePlayer.css +18 -0
  11. package/es/player/CoursePlayer.js +3 -2
  12. package/es/player/PlayerBars.d.ts +32 -0
  13. package/es/player/PlayerBars.js +14 -0
  14. package/es/steps/Blocks.d.ts +24 -3
  15. package/es/steps/Blocks.js +14 -7
  16. package/es/steps/Markdown.js +1 -1
  17. package/es/steps/QuizStepView.d.ts +2 -1
  18. package/es/steps/QuizStepView.js +20 -10
  19. package/es/steps/SlideStepView.d.ts +1 -1
  20. package/es/steps/SlideStepView.js +14 -4
  21. package/es/steps/StepBodyProps.d.ts +9 -0
  22. package/es/steps/StepView.css +65 -7
  23. package/es/steps/StepView.d.ts +29 -3
  24. package/es/steps/StepView.js +21 -5
  25. package/es/types.d.ts +13 -2
  26. package/package.json +1 -1
  27. package/src/document/box.test.ts +234 -0
  28. package/src/document/cues.ts +2 -1
  29. package/src/document/effects.ts +4 -3
  30. package/src/document/schema.ts +44 -2
  31. package/src/document/validate.ts +15 -19
  32. package/src/index.ts +11 -1
  33. package/src/player/CoursePlayer.css +18 -0
  34. package/src/player/CoursePlayer.tsx +38 -58
  35. package/src/player/PlayerBars.tsx +106 -0
  36. package/src/steps/Blocks.tsx +55 -8
  37. package/src/steps/Box.test.tsx +95 -0
  38. package/src/steps/Markdown.test.tsx +3 -0
  39. package/src/steps/Markdown.tsx +1 -1
  40. package/src/steps/QuizStepView.test.tsx +79 -0
  41. package/src/steps/QuizStepView.tsx +34 -12
  42. package/src/steps/SlideStepView.tsx +15 -3
  43. package/src/steps/StepBodyProps.ts +9 -0
  44. package/src/steps/StepView.css +65 -7
  45. package/src/steps/StepView.test.tsx +116 -0
  46. package/src/steps/StepView.tsx +100 -19
  47. package/src/types.ts +13 -2
@@ -2,7 +2,7 @@ import { toJsonSchema } from "@valibot/to-json-schema";
2
2
  import { getDotPath, safeParse } from "valibot";
3
3
  import { getCues, hasTrigger } from "./cues";
4
4
  import { effectTargets, getEffectBlocks } from "./effects";
5
- import { type Media, type SlideStep, type Step, stepSchema, type Timed } from "./schema";
5
+ import { type Block, type Media, type SlideStep, type Step, stepSchema, type Timed } from "./schema";
6
6
 
7
7
  export interface StepIssue {
8
8
  /** Where in the document, as a dot path (`blocks.2.items.0.revealAt`). Empty for the document itself. */
@@ -152,34 +152,30 @@ function* mediaOf(step: Step): Generator<{ media: Media; path: string }> {
152
152
  }
153
153
  }
154
154
 
155
- /** Every timed part of a slide with its path. Columns are walked too, and they have ids of their own. */
156
- function* walk(step: Extract<Step, { type: "slide" }>): Generator<{ part: Timed; path: string }> {
157
- for (let [index, block] of step.blocks.entries()) {
158
- let path = `blocks.${index}`;
155
+ /**
156
+ * Every timed part of a slide with its path. Columns and boxes are walked too, a box in a column
157
+ * included, and columns have ids of their own.
158
+ */
159
+ function walk(step: SlideStep) {
160
+ return walkBlocks(step.blocks, "blocks");
161
+ }
162
+
163
+ function* walkBlocks(blocks: Block[], basePath: string): Generator<{ part: Timed; path: string }> {
164
+ for (let [index, block] of blocks.entries()) {
165
+ let path = `${basePath}.${index}`;
159
166
  yield { part: block, path };
160
167
 
161
- if (block.type === "list") {
168
+ if (block.type === "list" || block.type === "canvas") {
162
169
  for (let [itemIndex, item] of block.items.entries()) yield { part: item, path: `${path}.items.${itemIndex}` };
163
170
  }
164
171
 
165
- if (block.type === "canvas") {
166
- for (let [itemIndex, item] of block.items.entries()) yield { part: item, path: `${path}.items.${itemIndex}` };
167
- }
172
+ if (block.type === "box") yield* walkBlocks(block.blocks, `${path}.blocks`);
168
173
 
169
174
  if (block.type === "columns") {
170
175
  for (let [columnIndex, column] of block.columns.entries()) {
171
176
  let columnPath = `${path}.columns.${columnIndex}`;
172
177
  yield { part: { id: column.id }, path: columnPath };
173
-
174
- for (let [childIndex, child] of column.blocks.entries()) {
175
- let childPath = `${columnPath}.blocks.${childIndex}`;
176
- yield { part: child, path: childPath };
177
- if (child.type === "list") {
178
- for (let [itemIndex, item] of child.items.entries()) {
179
- yield { part: item, path: `${childPath}.items.${itemIndex}` };
180
- }
181
- }
182
- }
178
+ yield* walkBlocks(column.blocks, `${columnPath}.blocks`);
183
179
  }
184
180
  }
185
181
  }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { CoursePlayer, type CoursePlayerProps } from "./player/CoursePlayer";
2
- export { StepView, type StepViewProps } from "./steps/StepView";
2
+ export { type SampleChrome, StepView, type StepViewProps } from "./steps/StepView";
3
+ export type { InsertContainer, InsertPlace } from "./steps/Blocks";
3
4
  export {
4
5
  CourseCompletion,
5
6
  type CourseCompletionProps,
@@ -60,9 +61,15 @@ export {
60
61
  export {
61
62
  type Block,
62
63
  blockSchema,
64
+ type BoxBlock,
65
+ type BoxContentBlock,
66
+ boxBlockSchema,
67
+ boxContentSchema,
63
68
  type CalloutBlock,
69
+ calloutBlockSchema,
64
70
  type ColumnsBlock,
65
71
  type ContentBlock,
72
+ contentBlockSchema,
66
73
  type Cue,
67
74
  type EffectBlock,
68
75
  effectBlockSchema,
@@ -77,6 +84,9 @@ export {
77
84
  type StepTransition,
78
85
  type StepType,
79
86
  stepSchema,
87
+ type SurfaceVariant,
88
+ TONES,
89
+ type Tone,
80
90
  transitionSchema,
81
91
  type Timed,
82
92
  type VideoStep,
@@ -213,3 +213,21 @@
213
213
  line-height: 1.25;
214
214
  }
215
215
  }
216
+
217
+ /* The same slim chrome in an editor's preview of a phone on its side, which the media query cannot see. */
218
+ .ob-course-player.is-compact {
219
+ > .ob-course-player__header {
220
+ padding: 0.125rem var(--ds-size-3, 0.75rem);
221
+ font-size: 0.875rem;
222
+ }
223
+
224
+ > .ob-course-player__controls {
225
+ gap: var(--ds-size-2, 0.5rem);
226
+ padding: 0.25rem var(--ds-size-3, 0.75rem);
227
+ }
228
+
229
+ .ob-course-player__status {
230
+ font-size: 0.75rem;
231
+ line-height: 1.25;
232
+ }
233
+ }
@@ -5,7 +5,7 @@ import { useSwipeable } from "react-swipeable";
5
5
  import { ProgressBar } from "../chrome/ProgressBar";
6
6
  import { getRevealSteps, isNarratedSlide, type RevealNavigation } from "../document/cues";
7
7
  import { getLocalizedString, localize } from "../i18n";
8
- import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, ExitFullscreenIcon, FullscreenIcon } from "../media/icons";
8
+ import { CloseIcon, ExitFullscreenIcon } from "../media/icons";
9
9
  import { StepBody, StepFrame } from "../steps/StepView";
10
10
  import { playStepTransition } from "../transitions/playStepTransition";
11
11
  import type {
@@ -18,6 +18,7 @@ import type {
18
18
  ResolveAsset,
19
19
  } from "../types";
20
20
  import { LanguageMenu } from "./LanguageMenu";
21
+ import { PlayerControls, PlayerHeader } from "./PlayerBars";
21
22
  import { StartScreen } from "./StartScreen";
22
23
  import { useFullScreen } from "./useFullScreen";
23
24
  import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery";
@@ -269,7 +270,7 @@ export function CoursePlayer({
269
270
 
270
271
  let fullScreen = useFullScreen(rootRef);
271
272
  // On a phone on its side the header and the buttons take the small size, to leave the slide the height
272
- let chromeSize = useMediaQuery(COMPACT_QUERY) ? "sm" : undefined;
273
+ let chromeSize = useMediaQuery(COMPACT_QUERY) ? ("sm" as const) : undefined;
273
274
  let fullScreenLabel = fullScreen.active ? getLocalizedString("Leave full screen") : getLocalizedString("Full screen");
274
275
 
275
276
  let nextLabel = isLast && !pendingReveal ? getLocalizedString("Complete") : getLocalizedString("Next");
@@ -297,8 +298,26 @@ export function CoursePlayer({
297
298
  <ExitFullscreenIcon />
298
299
  </Button>
299
300
  )}
300
- <header className="ob-course-player__header" data-size={chromeSize}>
301
- <p className="ob-course-player__title">{course.title}</p>
301
+ <PlayerHeader
302
+ title={course.title}
303
+ size={chromeSize}
304
+ fullScreenLabel={fullScreenLabel}
305
+ onFullScreen={fullScreen.toggle}
306
+ end={
307
+ onExit && (
308
+ <Button
309
+ variant="tertiary"
310
+ data-size="sm"
311
+ icon
312
+ onClick={onExit}
313
+ aria-label={getLocalizedString("Close the course")}
314
+ title={getLocalizedString("Close the course")}
315
+ >
316
+ <CloseIcon />
317
+ </Button>
318
+ )
319
+ }
320
+ >
302
321
  {onCultureChange && course.languages.length > 1 && !showStart && (
303
322
  <LanguageMenu
304
323
  languages={course.languages}
@@ -306,29 +325,7 @@ export function CoursePlayer({
306
325
  onChange={(cultureId) => onCultureChange(cultureId)}
307
326
  />
308
327
  )}
309
- <Button
310
- variant="tertiary"
311
- data-size="sm"
312
- icon
313
- onClick={fullScreen.toggle}
314
- aria-label={fullScreenLabel}
315
- title={fullScreenLabel}
316
- >
317
- <FullscreenIcon />
318
- </Button>
319
- {onExit && (
320
- <Button
321
- variant="tertiary"
322
- data-size="sm"
323
- icon
324
- onClick={onExit}
325
- aria-label={getLocalizedString("Close the course")}
326
- title={getLocalizedString("Close the course")}
327
- >
328
- <CloseIcon />
329
- </Button>
330
- )}
331
- </header>
328
+ </PlayerHeader>
332
329
  <ProgressBar length={steps.length} currentIndex={showStart ? -1 : current} />
333
330
  {showStart ? (
334
331
  <StartScreen course={course} onChoose={chooseLanguage} />
@@ -362,37 +359,20 @@ export function CoursePlayer({
362
359
  />
363
360
  </StepFrame>
364
361
  </section>
365
- <footer className="ob-course-player__controls" data-size={chromeSize}>
366
- <Button
367
- variant="secondary"
368
- onClick={back}
369
- disabled={busy || (current === 0 && (reveals ? reveals.previous === null : stepsShown === 0))}
370
- aria-label={getLocalizedString("Back")}
371
- >
372
- <ArrowLeftIcon />
373
- <span className="ob-course-player__button-text">{getLocalizedString("Back")}</span>
374
- </Button>
375
- <div className="ob-course-player__status">
376
- <span className="ob-course-player__count">
377
- {current + 1} / {steps.length}
378
- </span>
379
- <span className="ob-course-player__note">
380
- <span role="status" className="ob-course-player__message">
381
- {message}
382
- </span>
383
- {hint && <span className="ob-course-player__hint">{hint}</span>}
384
- </span>
385
- </div>
386
- <Button
387
- onClick={next}
388
- loading={busy}
389
- disabled={busy || completed || (!pendingReveal && !canLeave)}
390
- aria-label={nextLabel}
391
- >
392
- <span className="ob-course-player__button-text">{nextLabel}</span>
393
- {!(isLast && !pendingReveal) && <ArrowRightIcon />}
394
- </Button>
395
- </footer>
362
+ <PlayerControls
363
+ size={chromeSize}
364
+ position={current + 1}
365
+ count={steps.length}
366
+ message={message}
367
+ hint={hint}
368
+ backDisabled={busy || (current === 0 && (reveals ? reveals.previous === null : stepsShown === 0))}
369
+ nextDisabled={busy || completed || (!pendingReveal && !canLeave)}
370
+ busy={busy}
371
+ nextLabel={nextLabel}
372
+ nextArrow={!(isLast && !pendingReveal)}
373
+ onBack={back}
374
+ onNext={next}
375
+ />
396
376
  </>
397
377
  )}
398
378
  </div>
@@ -0,0 +1,106 @@
1
+ import { Button } from "@digdir/designsystemet-react";
2
+ import type { ReactNode } from "react";
3
+ import { getLocalizedString } from "../i18n";
4
+ import { ArrowLeftIcon, ArrowRightIcon, FullscreenIcon } from "../media/icons";
5
+
6
+ /*
7
+ * The player's header and buttons, apart from the player, so an editor's preview draws the same
8
+ * bars around a step as the learner gets, and the step is left exactly the room it has there.
9
+ */
10
+
11
+ export function PlayerHeader({
12
+ title,
13
+ size,
14
+ fullScreenLabel,
15
+ onFullScreen,
16
+ children,
17
+ end,
18
+ inert,
19
+ }: {
20
+ title: string;
21
+ /** Drawn but not operable, and hidden from screen readers: a preview's sample. */
22
+ inert?: boolean;
23
+ /** `sm` on a phone on its side, to leave the step the height. */
24
+ size?: "sm";
25
+ fullScreenLabel: string;
26
+ onFullScreen?(): void;
27
+ /** Buttons between the title and the full screen button, such as the language menu. */
28
+ children?: ReactNode;
29
+ /** After the full screen button, such as closing the course. */
30
+ end?: ReactNode;
31
+ }) {
32
+ return (
33
+ <header className="ob-course-player__header" data-size={size} inert={inert} aria-hidden={inert || undefined}>
34
+ <p className="ob-course-player__title">{title}</p>
35
+ {children}
36
+ <Button
37
+ variant="tertiary"
38
+ data-size="sm"
39
+ icon
40
+ onClick={onFullScreen}
41
+ aria-label={fullScreenLabel}
42
+ title={fullScreenLabel}
43
+ >
44
+ <FullscreenIcon />
45
+ </Button>
46
+ {end}
47
+ </header>
48
+ );
49
+ }
50
+
51
+ export function PlayerControls({
52
+ size,
53
+ position,
54
+ count,
55
+ message,
56
+ hint,
57
+ backDisabled,
58
+ nextDisabled,
59
+ busy,
60
+ nextLabel,
61
+ nextArrow,
62
+ onBack,
63
+ onNext,
64
+ inert,
65
+ }: {
66
+ size?: "sm";
67
+ /** Drawn but not operable, and hidden from screen readers: a preview's sample. */
68
+ inert?: boolean;
69
+ /** The step shown, from 1. */
70
+ position: number;
71
+ count: number;
72
+ message?: string | null;
73
+ hint?: string | null;
74
+ backDisabled?: boolean;
75
+ nextDisabled?: boolean;
76
+ busy?: boolean;
77
+ nextLabel: string;
78
+ /** The arrow on Next; left out on Complete. */
79
+ nextArrow: boolean;
80
+ onBack?(): void;
81
+ onNext?(): void;
82
+ }) {
83
+ return (
84
+ <footer className="ob-course-player__controls" data-size={size} inert={inert} aria-hidden={inert || undefined}>
85
+ <Button variant="secondary" onClick={onBack} disabled={backDisabled} aria-label={getLocalizedString("Back")}>
86
+ <ArrowLeftIcon />
87
+ <span className="ob-course-player__button-text">{getLocalizedString("Back")}</span>
88
+ </Button>
89
+ <div className="ob-course-player__status">
90
+ <span className="ob-course-player__count">
91
+ {position} / {count}
92
+ </span>
93
+ <span className="ob-course-player__note">
94
+ <span role="status" className="ob-course-player__message">
95
+ {message}
96
+ </span>
97
+ {hint && <span className="ob-course-player__hint">{hint}</span>}
98
+ </span>
99
+ </div>
100
+ <Button onClick={onNext} loading={busy} disabled={nextDisabled} aria-label={nextLabel}>
101
+ <span className="ob-course-player__button-text">{nextLabel}</span>
102
+ {nextArrow && <ArrowRightIcon />}
103
+ </Button>
104
+ </footer>
105
+ );
106
+ }
@@ -1,10 +1,18 @@
1
1
  import { Button, Dialog } from "@digdir/designsystemet-react";
2
2
  import clsx from "clsx";
3
3
  import type React from "react";
4
- import { useState } from "react";
4
+ import { Fragment, useState } from "react";
5
5
  import { isVisible, type RevealState } from "../document/cues";
6
6
  import type { PartEffect } from "../document/effects";
7
- import type { Block, CanvasItem, ContentBlock, ListItem, Timed } from "../document/schema";
7
+ import type {
8
+ Block,
9
+ BoxContentBlock,
10
+ CanvasItem,
11
+ ContentBlock,
12
+ ListItem,
13
+ SurfaceVariant,
14
+ Timed,
15
+ } from "../document/schema";
8
16
  import { getLocalizedString } from "../i18n";
9
17
  import { PlayIcon } from "../media/icons";
10
18
  import { VideoPlayer } from "../media/VideoPlayer";
@@ -22,14 +30,41 @@ export interface BlocksContext {
22
30
  effects?: ReadonlyMap<string, PartEffect>;
23
31
  /** The learner prefers reduced motion: parts change at once. */
24
32
  calm?: boolean;
33
+ /** For an editor: every part is drawn whatever its timing, marked `is-unrevealed` when it would wait. */
34
+ revealAll?: boolean;
35
+ /** For an editor: drawn at each place a block can be added, before every shown block and at the end. */
36
+ renderInsert?(place: InsertPlace): React.ReactNode;
25
37
  }
26
38
 
27
- export function Blocks({ blocks, context }: { blocks: Array<Block | ContentBlock>; context: BlocksContext }) {
39
+ /** Where blocks stand: on the slide, in a column or in a box. */
40
+ export type InsertContainer = { kind: "slide" } | { kind: "column"; id: string } | { kind: "box"; id: string };
41
+
42
+ /** A place a block can be added: in a container, before the block at `index` (or at the end). */
43
+ export type InsertPlace = { container: InsertContainer; index: number };
44
+
45
+ export function Blocks({
46
+ blocks,
47
+ context,
48
+ container,
49
+ }: {
50
+ blocks: Array<Block | ContentBlock | BoxContentBlock>;
51
+ context: BlocksContext;
52
+ /** Where the blocks stand, for an editor's places to add one. */
53
+ container?: InsertContainer;
54
+ }) {
55
+ let insert = container && context.renderInsert ? context.renderInsert : null;
28
56
  return (
29
57
  <>
30
- {blocks.map((block) => (
31
- <BlockView key={block.id} block={block} context={context} />
58
+ {blocks.map((block, index) => (
59
+ <Fragment key={block.id}>
60
+ {/* An effect draws nothing, so it has no place of its own to add next to */}
61
+ {insert && container && block.type !== "effect" && (
62
+ <div className="ob-course-insert">{insert({ container, index })}</div>
63
+ )}
64
+ <BlockView block={block} context={context} />
65
+ </Fragment>
32
66
  ))}
67
+ {insert && container && <div className="ob-course-insert">{insert({ container, index: blocks.length })}</div>}
33
68
  </>
34
69
  );
35
70
  }
@@ -50,6 +85,11 @@ function lookClasses(block: { caps?: boolean; shadow?: boolean }) {
50
85
  return clsx(block.caps && "ob-course-look--caps", block.shadow && "ob-course-look--shadow");
51
86
  }
52
87
 
88
+ /** A callout and a box share one surface, coloured by `data-color` and drawn by its variant. */
89
+ function surfaceClasses(className: string, block: { variant?: SurfaceVariant }) {
90
+ return clsx(className, "ob-course-surface", `ob-course-surface--${block.variant ?? "bordered"}`);
91
+ }
92
+
53
93
  interface PartShown {
54
94
  state: PartState;
55
95
  /** Came into the page after the slide was first drawn, so it fades in. */
@@ -61,7 +101,7 @@ interface PartShown {
61
101
  * first (`leaving`); the slide lifts it out of the flow meanwhile.
62
102
  */
63
103
  function usePart(part: Timed, context: BlocksContext): PartShown | null {
64
- let visibility = getVisibility(part, context.reveal);
104
+ let visibility = context.revealAll ? "shown" : getVisibility(part, context.reveal);
65
105
  let presence = usePresence(visibility !== "gone", context.calm ?? false);
66
106
  let inPage = presence !== "absent";
67
107
  /*
@@ -88,6 +128,7 @@ function partProps(part: Timed, shown: PartShown, className: string, context: Bl
88
128
  shown.state === "pending" && "is-pending",
89
129
  shown.state === "leaving" && "is-leaving",
90
130
  shown.entering && "is-entering",
131
+ context.revealAll && !isVisible(part, context.reveal) && "is-unrevealed",
91
132
  ),
92
133
  "data-part": part.id,
93
134
  "aria-hidden": hidden || undefined,
@@ -147,10 +188,16 @@ function BlockView({ block, context }: { block: Block | ContentBlock; context: B
147
188
  );
148
189
  case "callout":
149
190
  return (
150
- <div {...props} data-color={block.tone ?? "neutral"}>
191
+ <div {...props} className={surfaceClasses(props.className, block)} data-color={block.tone ?? "neutral"}>
151
192
  <Markdown>{block.text}</Markdown>
152
193
  </div>
153
194
  );
195
+ case "box":
196
+ return (
197
+ <div {...props} className={surfaceClasses(props.className, block)} data-color={block.tone ?? "neutral"}>
198
+ <Blocks blocks={block.blocks} context={context} container={{ kind: "box", id: block.id }} />
199
+ </div>
200
+ );
154
201
  case "video-link":
155
202
  return (
156
203
  <div {...props}>
@@ -177,7 +224,7 @@ function BlockView({ block, context }: { block: Block | ContentBlock; context: B
177
224
  data-part={column.id}
178
225
  style={partStyle({ effect: context.effects?.get(column.id), state: "shown" })}
179
226
  >
180
- <Blocks blocks={column.blocks} context={context} />
227
+ <Blocks blocks={column.blocks} context={context} container={{ kind: "column", id: column.id }} />
181
228
  </div>
182
229
  ))}
183
230
  </div>
@@ -0,0 +1,95 @@
1
+ import { render } from "@testing-library/react";
2
+ import { describe, expect, it } from "vitest";
3
+ import type { Block, Step } from "../document/schema";
4
+ import { StepView } from "./StepView";
5
+
6
+ let resolveAsset = (src: string) => src;
7
+
8
+ function slide(blocks: Block[]): Step {
9
+ return { schemaVersion: 2, type: "slide", blocks };
10
+ }
11
+
12
+ let box: Block = {
13
+ id: "box",
14
+ type: "box",
15
+ tone: "brand",
16
+ variant: "filled",
17
+ blocks: [
18
+ { id: "h", type: "heading", text: "Slik gjør du", level: 2 },
19
+ {
20
+ id: "l",
21
+ type: "list",
22
+ items: [
23
+ { id: "i1", text: "Ta på hjelm", reveal: "step" },
24
+ { id: "i2", text: "Sjekk [stroppen](https://example.com)", reveal: "step" },
25
+ ],
26
+ },
27
+ { id: "img", type: "image", src: "/media/course/a.png", size: "full" },
28
+ ],
29
+ };
30
+
31
+ describe("a box", () => {
32
+ it("draws its blocks inside a surface in its tone and variant", () => {
33
+ let { container } = render(<StepView step={slide([box])} resolveAsset={resolveAsset} />);
34
+
35
+ let element = container.querySelector('[data-part="box"]')!;
36
+ expect(element.classList).toContain("ob-course-block--box");
37
+ expect(element.classList).toContain("ob-course-surface");
38
+ expect(element.classList).toContain("ob-course-surface--filled");
39
+ expect(element.getAttribute("data-color")).toBe("brand");
40
+ expect(element.querySelector(':scope > h3[data-part="h"]')).not.toBeNull();
41
+ expect(element.querySelector(':scope > ul[data-part="l"] > li[data-part="i2"] a')).not.toBeNull();
42
+ expect(element.querySelector(':scope > figure[data-part="img"] img')).not.toBeNull();
43
+ });
44
+
45
+ it("is neutral and bordered by default, like a callout", () => {
46
+ let { container } = render(
47
+ <StepView
48
+ step={slide([
49
+ { id: "b", type: "box", blocks: [{ id: "t", type: "text", text: "Hei" }] },
50
+ { id: "c", type: "callout", text: "Husk" },
51
+ { id: "c2", type: "callout", text: "Husk", tone: "brand", variant: "filled" },
52
+ ])}
53
+ resolveAsset={resolveAsset}
54
+ />,
55
+ );
56
+
57
+ for (let id of ["b", "c"]) {
58
+ let element = container.querySelector(`[data-part="${id}"]`)!;
59
+ expect(element.getAttribute("data-color")).toBe("neutral");
60
+ expect(element.classList).toContain("ob-course-surface--bordered");
61
+ }
62
+ let filled = container.querySelector('[data-part="c2"]')!;
63
+ expect(filled.getAttribute("data-color")).toBe("brand");
64
+ expect(filled.classList).toContain("ob-course-surface--filled");
65
+ });
66
+
67
+ it("reveals its parts one by one, also in a column", () => {
68
+ let blocks: Block[] = [
69
+ {
70
+ id: "cols",
71
+ type: "columns",
72
+ columns: [
73
+ { id: "a", blocks: [box] },
74
+ { id: "b", blocks: [] },
75
+ ],
76
+ },
77
+ ];
78
+ let { container } = render(<StepView step={slide(blocks)} resolveAsset={resolveAsset} stepsShown={1} />);
79
+
80
+ expect(container.querySelector('.ob-course-column [data-part="box"]')).not.toBeNull();
81
+ expect(container.querySelector('[data-part="i1"]')!.classList).not.toContain("is-pending");
82
+ expect(container.querySelector('[data-part="i2"]')!.classList).toContain("is-pending");
83
+ });
84
+
85
+ it("hides its parts with it while it waits", () => {
86
+ let { container } = render(
87
+ <StepView step={slide([{ ...box, reveal: "step" } as Block])} resolveAsset={resolveAsset} stepsShown={0} />,
88
+ );
89
+
90
+ let element = container.querySelector('[data-part="box"]')!;
91
+ expect(element.classList).toContain("is-pending");
92
+ expect(element.getAttribute("aria-hidden")).toBe("true");
93
+ expect(element.hasAttribute("inert")).toBe(true);
94
+ });
95
+ });
@@ -21,6 +21,9 @@ describe("Markdown", () => {
21
21
  expect(html('Det er <span data-color="danger" style="font-size:9em">innånding</span> som er farlig')).toContain(
22
22
  '<span class="ob-course-tone" data-color="danger">innånding</span>',
23
23
  );
24
+ expect(html('<span data-color="brand">Ølen Betong</span>')).toContain(
25
+ '<span class="ob-course-tone" data-color="brand">Ølen Betong</span>',
26
+ );
24
27
  expect(html('<span data-color="url(x)">tekst</span>')).not.toContain("url(x)");
25
28
  });
26
29
 
@@ -12,7 +12,7 @@ const MARKDOWN_TAGS = new Set(
12
12
  export const TEXT_TAGS = new Set(["big", "small", "u", "sup", "sub", "mark"]);
13
13
 
14
14
  /** The colours a `<span data-color>` may name; they come from the theme. */
15
- export const TEXT_TONES = new Set(["info", "success", "warning", "danger"]);
15
+ export const TEXT_TONES = new Set(["info", "success", "warning", "danger", "brand"]);
16
16
 
17
17
  type ElementProps = (Record<string, unknown> & { key?: string | number }) | null;
18
18