Skip to content

feat(#246): Add onChange and initialSlideIndex props to CH.Slideshow #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Limit what we are exposing from internal state
  • Loading branch information
brianespinosa committed Jul 29, 2022
commit ef2a0f0d1f76dedc09d5f6ff9cfe8b1b6ad6f361
18 changes: 13 additions & 5 deletions packages/mdx/src/mdx-client/slideshow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ export function Slideshow({
stepIndex: initialSlide,
step: editorSteps[initialSlide],
})
const tab = state.step

// Destructure these values and give them more semantic names for use below
const {
stepIndex: currentSlideIndex,
step: tab,
} = state;

// Run any time our Slideshow state changes
React.useEffect(() => {
// Return our state object to the Slideshow onChange function
onSlideshowChange(state);
}, [state]);
onSlideshowChange({
index: currentSlideIndex
});
// We are only calling this effect if the current slide changes.
}, [currentSlideIndex]);

function onTabClick(filename: string) {
const newStep = updateEditorStep(
Expand Down Expand Up @@ -95,7 +103,7 @@ export function Slideshow({
) : hasPreviewSteps ? (
<Preview
className="ch-slideshow-preview"
{...previewChildren[state.stepIndex]["props"]}
{...previewChildren[currentSlideIndex]["props"]}
/>
) : null}
</div>
Expand Down Expand Up @@ -151,7 +159,7 @@ export function Slideshow({

{hasNotes && (
<div className="ch-slideshow-note">
{stepsChildren[state.stepIndex]}
{stepsChildren[currentSlideIndex]}
</div>
)}
</div>
Expand Down