Skip to content

Commit 026d97a

Browse files
committed
Update getStyles to support floaterProps styles.arrow.color
- add CustomOptions test
1 parent 1035763 commit 026d97a

File tree

5 files changed

+744
-9
lines changed

5 files changed

+744
-9
lines changed

src/modules/step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function getMergedStep(currentStep: Step | undefined, props: Props): Step
3939
isMergeableObject: is.plainObject,
4040
}) as StepMerged;
4141

42-
const mergedStyles = getStyles(props.styles, mergedStep.styles);
42+
const mergedStyles = getStyles(props, mergedStep);
4343
const scrollParent = hasCustomScrollParent(
4444
getElement(mergedStep.target),
4545
mergedStep.disableScrollParentFix,

src/styles.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import deepmerge from 'deepmerge';
2-
import { PartialDeep } from 'type-fest';
32

43
import { hexToRGB } from './modules/helpers';
5-
import { Styles, StylesOptions } from './types';
4+
import { Props, StepMerged, StylesOptions } from './types';
65

76
const defaultOptions = {
87
arrowColor: '#fff',
@@ -33,11 +32,9 @@ const spotlight = {
3332
position: 'absolute' as const,
3433
};
3534

36-
export default function getStyles(
37-
propsStyles?: PartialDeep<Styles>,
38-
stepStyles?: PartialDeep<Styles>,
39-
) {
40-
const mergedStyles = deepmerge(propsStyles ?? {}, stepStyles ?? {});
35+
export default function getStyles(props: Props, step: StepMerged) {
36+
const { floaterProps, styles } = props;
37+
const mergedStyles = deepmerge(styles ?? {}, step?.styles ?? {});
4138
const options = deepmerge(defaultOptions, mergedStyles.options || {}) satisfies StylesOptions;
4239
let { width } = options;
4340

@@ -179,7 +176,7 @@ export default function getStyles(
179176
},
180177
floaterStyles: {
181178
arrow: {
182-
color: options.arrowColor,
179+
color: floaterProps?.styles?.arrow?.color ?? options.arrowColor,
183180
},
184181
options: {
185182
zIndex: options.zIndex + 100,

test/__fixtures__/CustomOptions.tsx

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { useReducer } from 'react';
2+
3+
import { standardSteps } from './steps';
4+
5+
import Joyride, { STATUS, Status } from '../../src';
6+
import { CallBackProps, Props, Step } from '../../src/types';
7+
8+
interface CustomOptionsProps extends Omit<Props, 'run' | 'steps'> {}
9+
10+
interface State {
11+
index: number;
12+
run: boolean;
13+
steps: Array<Step>;
14+
}
15+
16+
const tourSteps = [
17+
...standardSteps.slice(0, 3).map(step => {
18+
if (step.target === '.mission button') {
19+
return {
20+
...step,
21+
target: '.mission h2 span',
22+
};
23+
}
24+
25+
return step;
26+
}),
27+
{
28+
target: '.outro h2 span',
29+
placement: 'top' as const,
30+
content: "Text only steps — Because sometimes you don't really need a proper heading",
31+
},
32+
];
33+
34+
export default function CutomOptionss(props: Omit<CustomOptionsProps, 'run' | 'steps'>) {
35+
const { callback, ...rest } = props;
36+
const [{ run, steps }, setState] = useReducer(
37+
(previousState: State, nextState: Partial<State>) => ({
38+
...previousState,
39+
...nextState,
40+
}),
41+
{
42+
index: 0,
43+
run: false,
44+
steps: tourSteps,
45+
},
46+
);
47+
48+
const handleClickStart = () => {
49+
setState({ run: true });
50+
};
51+
52+
const handleJoyrideCallback = (data: CallBackProps) => {
53+
const { status } = data;
54+
55+
if (([STATUS.FINISHED, STATUS.SKIPPED] as Array<Status>).includes(status)) {
56+
setState({ run: false });
57+
}
58+
59+
setState({ index: data.index });
60+
61+
callback?.(data);
62+
};
63+
64+
return (
65+
<div data-test-id="demo">
66+
<Joyride
67+
callback={handleJoyrideCallback}
68+
continuous
69+
run={run}
70+
scrollToFirstStep
71+
showSkipButton
72+
steps={steps}
73+
styles={{
74+
buttonClose: {
75+
color: '#000',
76+
},
77+
buttonNext: {
78+
backgroundColor: '#a947ff',
79+
},
80+
options: {
81+
arrowColor: '#5cff47',
82+
primaryColor: '#ff0000',
83+
overlayColor: 'rgba(0, 0, 0, 0.3)',
84+
},
85+
tooltip: {
86+
borderRadius: 8,
87+
padding: 12,
88+
},
89+
tooltipContent: {
90+
padding: '1px 8px',
91+
},
92+
}}
93+
{...rest}
94+
/>
95+
<main>
96+
<div className="hero">
97+
<div className="container">
98+
<div className="hero__content">
99+
<h1>
100+
<span>Create walkthroughs and guided tours for your ReactJS apps.</span>
101+
</h1>
102+
<button data-test-id="start" onClick={handleClickStart} type="button">
103+
Let's Go!
104+
</button>
105+
</div>
106+
</div>
107+
</div>
108+
<div className="demo__section projects">
109+
<div className="container">
110+
<h2>
111+
<span>Projects</span>
112+
</h2>
113+
<div className="list">
114+
<div>Installation</div>
115+
<div>Documentation</div>
116+
<div>Support </div>
117+
</div>
118+
</div>
119+
</div>
120+
121+
<div className="demo__section mission">
122+
<div className="container">
123+
<h2>
124+
<span>Mission</span>
125+
</h2>
126+
</div>
127+
</div>
128+
<div className="demo__section about">
129+
<div className="container">
130+
<h2>
131+
<span>About</span>
132+
</h2>
133+
</div>
134+
</div>
135+
<div className="demo__section outro">
136+
<div className="container">
137+
<h2>
138+
<span>Outro</span>
139+
</h2>
140+
</div>
141+
</div>
142+
</main>
143+
</div>
144+
);
145+
}

0 commit comments

Comments
 (0)