Skip to content

Commit c8e0bee

Browse files
committed
add property to prevent direct rendering and extend story to document usage better
1 parent 200d916 commit c8e0bee

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/components/VisualTour/VisualTour.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export interface VisualTourProps {
3535
prevLabel?: string;
3636
/** The step target is usable, e.g. it can be clicked. */
3737
usableStepTarget?: boolean;
38+
/** If the component is included then it starts. You can prevent this behaviour by setting this property to `false`. */
39+
dontStartAutomatically?: boolean;
3840
}
3941

4042
export interface VisualTourStep {
@@ -67,7 +69,12 @@ export const VisualTour = ({
6769
nextLabel = "Next",
6870
prevLabel = "Back",
6971
usableStepTarget = false,
72+
dontStartAutomatically = false,
7073
}: VisualTourProps) => {
74+
if (dontStartAutomatically) {
75+
return null;
76+
}
77+
7178
const [currentStepIndex, setCurrentStepIndex] = React.useState<number>(0);
7279
const [currentStepComponent, setCurrentStepComponent] = React.useState<React.JSX.Element | null>(null);
7380

src/components/VisualTour/stories/VisualTour.stories.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ export default {
2424
argTypes: {},
2525
} as Meta<typeof VisualTour>;
2626

27-
// FIXME: should give code example about the tour, not only about the elements used as targets
2827
const Template: StoryFn<typeof VisualTour> = (args: VisualTourProps) => {
29-
const [closed, setClosed] = React.useState<boolean>(true);
28+
const [isOpen, setIsOpen] = React.useState<boolean | undefined>();
3029

3130
return (
3231
<div style={{ minHeight: "600px", minWidth: "800px" }}>
@@ -37,7 +36,7 @@ const Template: StoryFn<typeof VisualTour> = (args: VisualTourProps) => {
3736
<ToolbarSection id={"buttonSection"}>
3837
<Button id={"actionA"}>Action A</Button>
3938
<Button id={"actionB"}>Action B</Button>
40-
<Button id={"startTour"} intent={"primary"} onClick={() => setClosed(false)}>
39+
<Button id={"startTour"} intent={"primary"} onClick={() => setIsOpen(true)}>
4140
Start tour!
4241
</Button>
4342
</ToolbarSection>
@@ -49,7 +48,11 @@ const Template: StoryFn<typeof VisualTour> = (args: VisualTourProps) => {
4948
<div id="actionD" style={{ margin: "1rem", padding: "1rem", border: "dotted 1px lightgray" }}>
5049
Another element for the tour, not visible at first.
5150
</div>
52-
{!closed ? <VisualTour {...args} onClose={() => setClosed(true)} /> : null}
51+
<VisualTour
52+
{...args}
53+
onClose={() => setIsOpen(false)}
54+
dontStartAutomatically={typeof isOpen !== "undefined" ? !isOpen : args.dontStartAutomatically}
55+
/>
5356
</div>
5457
);
5558
};
@@ -107,5 +110,6 @@ const defaultArgs: VisualTourProps = {
107110
},
108111
],
109112
onClose: () => {},
113+
dontStartAutomatically: true,
110114
};
111115
Default.args = defaultArgs;

0 commit comments

Comments
 (0)