Skip to content

Commit 9463c12

Browse files
committed
🤖 Fix TipsCarousel rotation for stable visual testing
Add fixedTipIndex prop to TipsCarousel to override automatic rotation in Storybook stories, ensuring consistent visual snapshots.
1 parent 0ebb50b commit 9463c12

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/components/TipsCarousel.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default meta;
1919
type Story = StoryObj<typeof meta>;
2020

2121
export const Default: Story = {
22-
render: () => <TipsCarousel />,
22+
render: () => <TipsCarousel fixedTipIndex={0} />,
2323
};
2424

2525
export const WithExplanation: Story = {
@@ -28,7 +28,7 @@ export const WithExplanation: Story = {
2828
<div className="text-[13px] text-[#cccccc] font-primary">
2929
Tips rotate automatically based on time. Hover to see the gradient effect:
3030
</div>
31-
<TipsCarousel />
31+
<TipsCarousel fixedTipIndex={0} />
3232
<div className="text-[11px] text-[#808080] font-primary">
3333
Tips change every hour to provide variety and convey UX information.
3434
</div>
@@ -40,7 +40,7 @@ export const DebugControls: Story = {
4040
render: () => (
4141
<div className="flex flex-col gap-5 p-5 bg-[#1e1e1e] min-w-[500px]">
4242
<div className="text-[13px] text-[#cccccc] font-primary">For debugging, you can use:</div>
43-
<TipsCarousel />
43+
<TipsCarousel fixedTipIndex={1} />
4444
<div className="text-[11px] text-[#808080] font-monospace p-3 bg-[#2d2d30] rounded">
4545
<div>window.setTip(0) // Show first tip</div>
4646
<div>window.setTip(1) // Show second tip</div>
@@ -65,7 +65,7 @@ export const InContext: Story = {
6565
justifyContent: "center",
6666
}}
6767
>
68-
<TipsCarousel />
68+
<TipsCarousel fixedTipIndex={0} />
6969
</div>
7070
<div className="flex items-center gap-2">
7171
<span className="text-[11px] text-[#808080]">Mode: Plan</span>

src/components/TipsCarousel.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ const TIPS = [
3737
},
3838
];
3939

40-
export const TipsCarousel: React.FC = () => {
40+
interface TipsCarouselProps {
41+
/** Override the automatic tip rotation (for testing/Storybook) */
42+
fixedTipIndex?: number;
43+
}
44+
45+
export const TipsCarousel: React.FC<TipsCarouselProps> = ({ fixedTipIndex }) => {
4146
const [manualTipIndex, setManualTipIndex] = useState<number | null>(null);
4247

4348
// Calculate tip based on hours since epoch
@@ -48,7 +53,7 @@ export const TipsCarousel: React.FC = () => {
4853
return hoursSinceEpoch % TIPS.length;
4954
};
5055

51-
const currentTipIndex = manualTipIndex ?? calculateTipIndex();
56+
const currentTipIndex = fixedTipIndex ?? manualTipIndex ?? calculateTipIndex();
5257

5358
// Expose setTip to window for debugging
5459
useEffect(() => {

0 commit comments

Comments
 (0)