Skip to content

Commit 9109f5f

Browse files
Add texts property for text copy of custom components; Show how to use external files for tour definitions in different languages
1 parent 141d407 commit 9109f5f

4 files changed

Lines changed: 100 additions & 29 deletions

File tree

src/components/VisualTour/VisualTour.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ export interface VisualTourProps {
2323
prevLabel?: string;
2424
}
2525

26-
interface VisualTourStep {
27-
/** (Short) Title of the current step. */
26+
export interface VisualTourStep {
2827
title: string;
2928
/** The description or more elaborate content element that is shown in the modal/overlay. */
3029
content: string | (() => React.JSX.Element);
3130
/** Optional element that should be highlighted, every other element in the container element is greyed out. */
3231
highlightElementQuery?: string;
32+
/** The texts used in the step, e.g. when custom layouts are rendered, these will be used for the text strings. */
33+
texts?: Record<string, string>;
3334
}
3435

36+
/** This should be used for defining steps in a separate object/file. Use with 'satisfies' after the object definition. */
37+
export type VisualTourStepDefinitions = Record<string, Partial<VisualTourStep>>;
38+
3539
const containerHighlightClass = `${eccgui}-visual-tour__container`;
3640
const highlightElementClass = `${eccgui}-visual-tour__highlighted-element`;
3741

src/components/VisualTour/VisualTour.stories.tsx renamed to src/components/VisualTour/stories/VisualTour.stories.tsx

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import {
1111
Toolbar,
1212
ToolbarSection,
1313
VisualTourProps,
14-
} from "../../../index";
14+
} from "../../../../index";
15+
import VisualTour from "../VisualTour";
1516

16-
import VisualTour from "./VisualTour";
17+
import stepDefinitionsEn from "./defaultTour";
18+
import stepDefinitionsDe from "./defaultTour.de";
1719

1820
export default {
1921
title: "Components/VisualTour",
@@ -50,49 +52,46 @@ const Template: StoryFn<typeof VisualTour> = (args: VisualTourProps) => {
5052
);
5153
};
5254

55+
const stepDefinitions = Math.random() < 0.5 ? stepDefinitionsEn : stepDefinitionsDe;
56+
5357
export const Default = Template.bind({});
5458
const defaultArgs: VisualTourProps = {
5559
containerElementQuery: "#tourContainer",
5660
steps: [
5761
{
58-
title: "First step",
59-
content: "This is a demonstration of a visual tour. A step can be simple text.",
62+
...stepDefinitions.firstStep,
6063
},
6164
{
62-
title: "Custom content",
63-
content: () => (
64-
<OverviewItem>
65-
<OverviewItemDepiction>
66-
<Icon name={"item-info"} />
67-
</OverviewItemDepiction>
68-
<OverviewItemDescription>
69-
<OverviewItemLine>
70-
Or a step can be arbitrary content that is displayed in a modal by default.
71-
</OverviewItemLine>
72-
<OverviewItemLine>The developer can choose what's appropriate.</OverviewItemLine>
73-
</OverviewItemDescription>
74-
</OverviewItem>
75-
),
65+
...stepDefinitions.customContent,
66+
content: () => {
67+
const texts = stepDefinitions.customContent.texts;
68+
return (
69+
<OverviewItem>
70+
<OverviewItemDepiction>
71+
<Icon name={"item-info"} />
72+
</OverviewItemDepiction>
73+
<OverviewItemDescription>
74+
<OverviewItemLine>{texts.firstLine}</OverviewItemLine>
75+
<OverviewItemLine>{texts.secondLine}</OverviewItemLine>
76+
</OverviewItemDescription>
77+
</OverviewItem>
78+
);
79+
},
7680
},
7781
{
78-
title: "Highlight element A",
79-
content:
80-
"It's possible to highlight specific elements on a page. The step content is then displayed in a kind of tooltip instead of a modal.",
82+
...stepDefinitions.highlightElementA,
8183
highlightElementQuery: "#actionA",
8284
},
8385
{
84-
title: "Highlight element B",
85-
content: "Context overlay for another highlighted element.",
86+
...stepDefinitions.highlightElementB,
8687
highlightElementQuery: "#actionB",
8788
},
8889
{
89-
title: "Highlight element C",
90-
content: "Element outside tour container.",
90+
...stepDefinitions.highlightElementC,
9191
highlightElementQuery: "#actionC",
9292
},
9393
{
94-
title: "Highlight element D",
95-
content: "Element not visible at first.",
94+
...stepDefinitions.highlightElementD,
9695
highlightElementQuery: "#actionD",
9796
},
9897
],
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { VisualTourStepDefinitions } from "../VisualTour";
2+
3+
const definition = {
4+
firstStep: {
5+
title: "Erter Schritt",
6+
content: "Dies ist eine Demonstration einer Visuellen Tour. Ein Schritt kann aus einfachen Text bestehen.",
7+
},
8+
customContent: {
9+
title: "Benutzerspezifizierter Inhalt",
10+
texts: {
11+
firstLine: "Ein Schritt kann aber auch beliebigen Inhalt anbieten, der in einem Dialog angezeigt wird.",
12+
secondLine: "Der Entwickler kann bestimmen wie etwas angezeigt werden soll.",
13+
},
14+
},
15+
highlightElementA: {
16+
title: "Element A hervorheben",
17+
content:
18+
"Es ist möglich spezifische Elemente auf der Seite hervorzuheben. Der Inhalt des Schrittes ist dann als eine Art Tooltip um das Element herum dargestellt.",
19+
},
20+
highlightElementB: {
21+
title: "Element B hervorheben",
22+
content: "Kontextoverlay für ein anderes hervorgehobenes Element.",
23+
},
24+
highlightElementC: {
25+
title: "Element C hervorheben",
26+
content: "Element ist außerhalb des Tourcontainers.",
27+
},
28+
highlightElementD: {
29+
title: "Element D hervorheben",
30+
content: "Element ist nucht sichtbar am Anfang.",
31+
},
32+
} satisfies VisualTourStepDefinitions;
33+
34+
export default definition;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { VisualTourStepDefinitions } from "../VisualTour";
2+
3+
const definition = {
4+
firstStep: {
5+
title: "First step",
6+
content: "This is a demonstration of a visual tour. A step can be simple text.",
7+
},
8+
customContent: {
9+
title: "Custom content",
10+
texts: {
11+
firstLine: "Or a step can be arbitrary content that is displayed in a modal by default.",
12+
secondLine: "The developer can choose what's appropriate.",
13+
},
14+
},
15+
highlightElementA: {
16+
title: "Highlight element A",
17+
content:
18+
"It's possible to highlight specific elements on a page. The step content is then displayed in a kind of tooltip instead of a modal.",
19+
},
20+
highlightElementB: {
21+
title: "Highlight element B",
22+
content: "Context overlay for another highlighted element.",
23+
},
24+
highlightElementC: {
25+
title: "Highlight element C",
26+
content: "Element outside tour container.",
27+
},
28+
highlightElementD: {
29+
title: "Highlight element D",
30+
content: "Element not visible at first.",
31+
},
32+
} satisfies VisualTourStepDefinitions;
33+
34+
export default definition;

0 commit comments

Comments
 (0)