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

[TS migration] Migrate G14 stories from storybook to Typescript #38056

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,4 @@ function AddressSearch(
AddressSearch.displayName = 'AddressSearchWithRef';

export default forwardRef(AddressSearch);
export type {AddressSearchProps};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type {AddressSearchProps};
export type {AddressSearchProps};

2 changes: 1 addition & 1 deletion src/components/AddressSearch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ type AddressSearchProps = {

type IsCurrentTargetInsideContainerType = (event: FocusEvent | NativeSyntheticEvent<TextInputFocusEventData>, containerRef: RefObject<View | HTMLElement>) => boolean;

export type {CurrentLocationButtonProps, AddressSearchProps, RenamedInputKeysProps, IsCurrentTargetInsideContainerType};
export type {CurrentLocationButtonProps, AddressSearchProps, RenamedInputKeysProps, IsCurrentTargetInsideContainerType, StreetValue};
1 change: 1 addition & 0 deletions src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ function Banner({text, onClose, onPress, containerStyles, textStyles, shouldRend
Banner.displayName = 'Banner';

export default memo(Banner);
export type {BannerProps}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type {BannerProps}
export type {BannerProps}

1 change: 1 addition & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ function Button(
Button.displayName = 'Button';

export default withNavigationFallback(React.forwardRef(Button));
export type {ButtonProps};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type {ButtonProps};
export type {ButtonProps};

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: {
Expand All @@ -15,12 +20,12 @@ export default {
},
};

function Template(args) {
const [value, setValue] = useState('');
function Template(args: AddressSearchProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function Template(args: AddressSearchProps) {
function Template(props: AddressSearchProps) {

const [value, setValue] = useState<string | number | RenamedInputKeysProps | StreetValue>('');
return (
<AddressSearch
value={value}
onInputChange={({street}) => setValue(street)}
value={value as string}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this assertion here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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}
/>
Expand All @@ -29,11 +34,12 @@ function Template(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({});
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,6 +1,10 @@
import type {ComponentStory} from '@storybook/react';
import React from 'react';
import type {BannerProps} from '@components/Banner';
import Banner from '@components/Banner';

type BannerStory = ComponentStory<typeof Banner>;

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

function Template(args) {
function Template(args: BannerProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function Template(args: BannerProps) {
function Template(props: BannerProps) {

// eslint-disable-next-line react/jsx-props-no-spreading
return <Banner {...args} />;
}

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const InfoBanner = Template.bind({});
const InfoBanner: BannerStory = Template.bind({});
InfoBanner.args = {
text: 'This is an informational banner',
};

const HTMLBanner = Template.bind({});
const HTMLBanner: BannerStory = Template.bind({});
HTMLBanner.args = {
text: 'This is a informational banner containing <strong><em>HTML</em></strong>',
shouldRenderHTML: true,
};

const BannerWithLink = Template.bind({});
const BannerWithLink: BannerStory = Template.bind({});
BannerWithLink.args = {
text: 'This is a informational banner containing <a href="https://new.expensify.com/settings">internal Link</a> and <a href=" https://google.com">public link</a>',
shouldRenderHTML: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
/* eslint-disable react/jsx-props-no-spreading */
import type {ComponentMeta, ComponentStory} from '@storybook/react';
import React, {useCallback, useState} from 'react';
import {View} from 'react-native';
import type {ButtonProps} from '@components/Button';
import Button from '@components/Button';
import Text from '@components/Text';

type ButtonStory = ComponentStory<typeof Button>;

/**
* 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
*/
const story = {
const story: ComponentMeta<typeof Button> = {
title: 'Components/Button',
component: Button,
};

function Template(args) {
function Template(args: ButtonProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function Template(args: ButtonProps) {
function Template(props: ButtonProps) {

// eslint-disable-next-line react/jsx-props-no-spreading
return <Button {...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({});
const Loading = Template.bind({});
function PressOnEnter(props) {
const Default: ButtonStory = Template.bind({});
const Loading: ButtonStory = Template.bind({});
function PressOnEnter(props: ButtonProps) {
const [text, setText] = useState('');
const onPress = useCallback(() => {
setText('Button Pressed!');
Expand All @@ -33,13 +37,13 @@ function PressOnEnter(props) {
<Button
{...props}
// eslint-disable-next-line react/prop-types
text={text || props.text}
text={text}
onPress={onPress}
/>
);
}

function PressOnEnterWithBubbling(props) {
function PressOnEnterWithBubbling(props: ButtonProps) {
return (
<>
<Text>Both buttons will trigger on press of Enter as the Enter event will bubble across all instances of button.</Text>
Expand Down
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:
Expand All @@ -11,23 +15,23 @@ const story = {
component: ButtonWithDropdownMenu,
};

function Template(args) {
function Template(args: ButtonWithDropdownMenuProps<unknown>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function Template(args: ButtonWithDropdownMenuProps<unknown>) {
function Template(props: ButtonWithDropdownMenuProps<unknown>) {

// eslint-disable-next-line react/jsx-props-no-spreading
return <ButtonWithDropdownMenu {...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({});
const Default: ButtonWithDropdownMenuStory = Template.bind({});
Default.args = {
buttonText: 'Pay using Expensify',
customText: 'Pay using Expensify',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruben-rebelo Why do you change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it is added here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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},
],
};

Expand Down
Loading