Skip to content

Commit

Permalink
Merge pull request #38056 from ruben-rebelo/ts-migration/g14
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisl authored Mar 22, 2024
2 parents 4807318 + cc466d2 commit 7f5cf61
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,5 @@ function AddressSearch(
AddressSearch.displayName = 'AddressSearchWithRef';

export default forwardRef(AddressSearch);

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};
2 changes: 2 additions & 0 deletions src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ function Banner({text, onClose, onPress, containerStyles, textStyles, shouldRend
Banner.displayName = 'Banner';

export default memo(Banner);

export type {BannerProps};
2 changes: 2 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,5 @@ function Button(
Button.displayName = 'Button';

export default withNavigationFallback(React.forwardRef(Button));

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,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}
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};
14 changes: 9 additions & 5 deletions src/stories/Banner.stories.js → src/stories/Banner.stories.tsx
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(props: BannerProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <Banner {...args} />;
return <Banner {...props} />;
}

// 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
20 changes: 12 additions & 8 deletions src/stories/Button.stories.js → src/stories/Button.stories.tsx
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(props: ButtonProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <Button {...args} />;
return <Button {...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 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,10 @@
import type {ComponentStory} from '@storybook/react';
import React from 'react';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
import type {ButtonWithDropdownMenuProps} from '@components/ButtonWithDropdownMenu/types';
import * as Expensicons from '@components/Icon/Expensicons';

type ButtonWithDropdownMenuStory = ComponentStory<typeof ButtonWithDropdownMenu>;

/**
* We use the Component Story Format for writing stories. Follow the docs here:
Expand All @@ -11,23 +16,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',
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},
{value: 'Two', text: 'Two', icon: Expensicons.Wallet},
],
};

Expand Down

0 comments on commit 7f5cf61

Please sign in to comment.