-
Notifications
You must be signed in to change notification settings - Fork 14
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
chore(schedule): refactor storybook #431
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Meta, Description } from '@storybook/addon-docs'; | ||
import README from '../README.md'; | ||
|
||
<Meta title="Packages/Schedule/README" /> | ||
|
||
<Description>{README}</Description> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Meta, ArgsTable, Canvas, Story } from '@storybook/addon-docs'; | ||
import { ScheduleContainer } from '@zendeskgarden/container-schedule'; | ||
import { ScheduleStory } from './stories/ScheduleStory'; | ||
|
||
<Meta title="Packages/Schedule" component={ScheduleContainer} /> | ||
|
||
# API | ||
|
||
<ArgsTable /> | ||
|
||
# Demo | ||
|
||
<Canvas> | ||
<Story | ||
name="Schedule" | ||
args={{ as: 'hook', delayMS: 750, duration: 1250, loop: true }} | ||
argTypes={{ | ||
as: { options: ['container', 'hook'], control: 'radio', table: { category: 'Story' } } | ||
}} | ||
> | ||
{args => <ScheduleStory {...args} />} | ||
</Story> | ||
</Canvas> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright Zendesk, Inc. | ||
* | ||
* Use of this source code is governed under the Apache License, Version 2.0 | ||
* found at http://www.apache.org/licenses/LICENSE-2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Story } from '@storybook/react'; | ||
import { | ||
IScheduleContainerProps, | ||
IUseScheduleProps, | ||
IUseScheduleReturnValue, | ||
ScheduleContainer, | ||
useSchedule | ||
} from '@zendeskgarden/container-schedule'; | ||
|
||
interface IComponentProps extends IUseScheduleReturnValue { | ||
duration?: IUseScheduleProps['duration']; | ||
loop?: IUseScheduleProps['loop']; | ||
} | ||
|
||
const Component = ({ delayMS, delayComplete, elapsed, loop, duration = 1250 }: IComponentProps) => ( | ||
<div> | ||
<label> | ||
<span> | ||
Schedule {delayMS / 1000}s delay followed by {duration / 1000}s{' '} | ||
{loop ? 'looped' : 'elapsed'} progress | ||
</span> | ||
<progress className="block w-full" value={delayComplete ? elapsed : undefined} /> | ||
</label> | ||
</div> | ||
); | ||
|
||
const Container = ({ loop, ...props }: IScheduleContainerProps) => ( | ||
<ScheduleContainer loop={loop} {...props}> | ||
{containerProps => <Component {...containerProps} loop={loop} />} | ||
</ScheduleContainer> | ||
); | ||
|
||
const Hook = (props: IUseScheduleProps) => { | ||
const hookProps = useSchedule(props); | ||
|
||
return <Component {...hookProps} {...props} />; | ||
}; | ||
|
||
interface IArgs extends IScheduleContainerProps { | ||
as: 'hook' | 'container'; | ||
} | ||
|
||
export const ScheduleStory: Story<IArgs> = ({ as, ...props }) => { | ||
const Schedule = () => { | ||
switch (as) { | ||
case 'container': | ||
return <Container {...props} />; | ||
|
||
case 'hook': | ||
default: | ||
return <Hook {...props} />; | ||
} | ||
}; | ||
|
||
return <Schedule />; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
containerProps
also pass thruloop
from the container with no need to manually passloop
toComponent
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the
loop
prop is not reconstituted in thecontainerProps
. (In going through this exercise, I'm noting API discontinuity between the packages βΒ this is one area where we could improve consistency.) So, I'm feeding it through. But worth noting that a) it is simply for string display, and b) these particular (overly) abstracted examples are a bit contrived since IRL one would either use the container or the hook and all the props would likely be available in one place.