-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[TS migration] Migrate G14 stories from storybook to Typescript #38056
Changes from 2 commits
ff0c54f
90d87e9
c988f96
cc466d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -348,3 +348,5 @@ function Button( | |||||||
Button.displayName = 'Button'; | ||||||||
|
||||||||
export default withNavigationFallback(React.forwardRef(Button)); | ||||||||
|
||||||||
export type {ButtonProps}; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import type {ComponentMeta, ComponentStory} from '@storybook/react'; | ||
import React, {useState} from 'react'; | ||
import type {AddressSearchProps} from '@components/AddressSearch'; | ||
import AddressSearch from '@components/AddressSearch'; | ||
import type {RenamedInputKeysProps, StreetValue} from '@components/AddressSearch/types'; | ||
|
||
type AddressSearchStory = ComponentStory<typeof AddressSearch>; | ||
|
||
/** | ||
* We use the Component Story Format for writing stories. Follow the docs here: | ||
* | ||
* https://storybook.js.org/docs/react/writing-stories/introduction#component-story-format | ||
*/ | ||
export default { | ||
const story: ComponentMeta<typeof AddressSearch> = { | ||
title: 'Components/AddressSearch', | ||
component: AddressSearch, | ||
args: { | ||
|
@@ -15,25 +20,26 @@ export default { | |
}, | ||
}; | ||
|
||
function Template(args) { | ||
const [value, setValue] = useState(''); | ||
function Template(props: AddressSearchProps) { | ||
const [value, setValue] = useState<string | number | RenamedInputKeysProps | StreetValue>(''); | ||
return ( | ||
<AddressSearch | ||
value={value} | ||
onInputChange={({street}) => setValue(street)} | ||
value={value as string} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this assertion here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed because value can only be string but InputChange has multiple types that can be used. |
||
onInputChange={(inputValue) => setValue(inputValue)} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...args} | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
// 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({}); | ||
const Default: AddressSearchStory = Template.bind({}); | ||
|
||
const ErrorStory = Template.bind({}); | ||
const ErrorStory: AddressSearchStory = Template.bind({}); | ||
ErrorStory.args = { | ||
errorText: 'The street you are looking for does not exist', | ||
}; | ||
|
||
export default story; | ||
export {Default, ErrorStory}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import type {ComponentStory} from '@storybook/react'; | ||
import React from 'react'; | ||
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu'; | ||
import type {ButtonWithDropdownMenuProps} from '@components/ButtonWithDropdownMenu/types'; | ||
|
||
type ButtonWithDropdownMenuStory = ComponentStory<typeof ButtonWithDropdownMenu>; | ||
|
||
/** | ||
* We use the Component Story Format for writing stories. Follow the docs here: | ||
|
@@ -11,23 +15,23 @@ const story = { | |
component: ButtonWithDropdownMenu, | ||
}; | ||
|
||
function Template(args) { | ||
function Template(props: ButtonWithDropdownMenuProps<unknown>) { | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return <ButtonWithDropdownMenu {...args} />; | ||
return <ButtonWithDropdownMenu {...props} />; | ||
} | ||
|
||
// 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({}); | ||
const Default: ButtonWithDropdownMenuStory = Template.bind({}); | ||
Default.args = { | ||
buttonText: 'Pay using Expensify', | ||
customText: 'Pay using Expensify', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ruben-rebelo Why do you change here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DylanDylann This was changed because the actual prop which sets the text of the button is now customText instead of buttonText. |
||
onPress: (e, item) => { | ||
alert(`Button ${item} is pressed.`); | ||
alert(`Button ${item as string} is pressed.`); | ||
}, | ||
pressOnEnter: true, | ||
options: [ | ||
{value: 'One', text: 'One'}, | ||
{value: 'Two', text: 'Two'}, | ||
{value: 'One', text: 'One', icon: Expensicons.Wallet}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why it is added here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Options has the mandatory icon param. |
||
{value: 'Two', text: 'Two', icon: Expensicons.Wallet}, | ||
], | ||
}; | ||
|
||
|
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.