Skip to content
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

feat: migrated interactiveStepSubHeader story to ts #12

Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/components/InteractiveStepSubHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ function InteractiveStepSubHeader({stepNames, startStepIndex = 0, onStepSelected

InteractiveStepSubHeader.displayName = 'InteractiveStepSubHeader';

export type {InteractiveStepSubHeaderProps, InteractiveStepSubHeaderHandle};

export default forwardRef(InteractiveStepSubHeader);
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable react/jsx-props-no-spreading */
import React, {useRef} from 'react';
import type {ForwardedRef} from 'react';
import {Button, View} from 'react-native';
import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader';
import type {InteractiveStepSubHeaderHandle, InteractiveStepSubHeaderProps} from '@components/InteractiveStepSubHeader';

/**
* We use the Component Story Format for writing stories. Follow the docs here:
Expand All @@ -13,39 +15,42 @@ const story = {
component: InteractiveStepSubHeader,
};

function Template(args) {
type StoryType = typeof Template & {args?: Partial<InteractiveStepSubHeaderProps>};

function Template(args: InteractiveStepSubHeaderProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <InteractiveStepSubHeader {...args} />;
}

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Default = Template.bind({});
function BaseInteractiveStepSubHeader(props: InteractiveStepSubHeaderProps) {
const ref: ForwardedRef<InteractiveStepSubHeaderHandle> = useRef(null);

function BaseInteractiveStepSubHeader(props) {
const ref = useRef(null);
return (
<View>
<InteractiveStepSubHeader
{...props}
ref={ref}
/>
<Button
onPress={() => ref.current.moveNext()}
onPress={() => ref.current?.moveNext()}
title="Next"
/>
</View>
);
}

const Default: StoryType = Template.bind({});
Default.args = {
stepNames: ['Initial', 'Step 1', 'Step 2', 'Step 3'],
startStep: 1,
startStepIndex: 1,
onStepSelected: () => {},
};

BaseInteractiveStepSubHeader.args = {
stepNames: ['Initial', 'Step 1', 'Step 2', 'Step 3', 'Confirmation'],
startStep: 0,
startStepIndex: 0,
onStepSelected: () => {},
};

Expand Down
Loading