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 'Composer.stories.js', 'DragAndDrop.stories.js', 'Form.stories.js' and 'RadioButtonWithLabel.stories.js' stories to TypeScript #37820

Merged
merged 7 commits into from
Mar 12, 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
2 changes: 1 addition & 1 deletion src/components/DragAndDrop/Provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type DragAndDropProviderProps = {
isDisabled?: boolean;

/** Indicate that users are dragging file or not */
setIsDraggingOver: (value: boolean) => void;
setIsDraggingOver?: (value: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this should be optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@blazejkustra Yep, it's already so on the main. Report screen uses DragAndDropProvider without setIsDraggingOver as well.

};

type SetOnDropHandlerCallback = (event: DragEvent) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type {ComponentMeta} from '@storybook/react';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import React, {useState} from 'react';
import {Image, View} from 'react-native';
import Composer from '@components/Composer';
import type {ComposerProps} from '@components/Composer/types';
import RenderHTML from '@components/RenderHTML';
import Text from '@components/Text';
import withNavigationFallback from '@components/withNavigationFallback';
import useStyleUtils from '@hooks/useStyleUtils';
// eslint-disable-next-line no-restricted-imports
import {defaultStyles} from '@styles/index';
// eslint-disable-next-line no-restricted-imports
import {defaultTheme} from '@styles/theme';
import CONST from '@src/CONST';
import {defaultStyles} from '@src/styles';

const ComposerWithNavigation = withNavigationFallback(Composer);

Expand All @@ -19,43 +19,40 @@ const ComposerWithNavigation = withNavigationFallback(Composer);
*
* https://storybook.js.org/docs/react/writing-stories/introduction#component-story-format
*/
const story = {
const story: ComponentMeta<typeof ComposerWithNavigation> = {
title: 'Components/Composer',
component: ComposerWithNavigation,
};

const parser = new ExpensiMark();

function Default(args) {
function Default(props: ComposerProps) {
const StyleUtils = useStyleUtils();
const [pastedFile, setPastedFile] = useState(null);
const [comment, setComment] = useState(args.defaultValue);
const renderedHTML = parser.replace(comment);
const [pastedFile, setPastedFile] = useState<File | null>(null);
const [comment, setComment] = useState(props.defaultValue);
const renderedHTML = parser.replace(comment ?? '');

return (
<View>
<View style={[defaultStyles.border, defaultStyles.p4]}>
<ComposerWithNavigation
// eslint-disable-next-line react/jsx-props-no-spreading
{...args}
{...props}
multiline
onChangeText={setComment}
onPasteFile={setPastedFile}
style={[defaultStyles.textInputCompose, defaultStyles.w100, defaultStyles.verticalAlignTop]}
/>
</View>
<View style={[defaultStyles.flexRow, defaultStyles.mv5, defaultStyles.flexWrap, defaultStyles.w100]}>
<View
style={[defaultStyles.border, defaultStyles.noLeftBorderRadius, defaultStyles.noRightBorderRadius, defaultStyles.p5, defaultStyles.flex1]}
id={CONST.REPORT.DROP_NATIVE_ID}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DROP_NATIVE_ID doesn't exist in CONST.REPORT

>
<View style={[defaultStyles.border, defaultStyles.noLeftBorderRadius, defaultStyles.noRightBorderRadius, defaultStyles.p5, defaultStyles.flex1]}>
<Text style={[defaultStyles.mb2, defaultStyles.textLabelSupporting]}>Entered Comment (Drop Enabled)</Text>
<Text>{comment}</Text>
</View>
<View style={[defaultStyles.p5, defaultStyles.borderBottom, defaultStyles.borderRight, defaultStyles.borderTop, defaultStyles.flex1]}>
<Text style={[defaultStyles.mb2, defaultStyles.textLabelSupporting]}>Rendered Comment</Text>
{Boolean(renderedHTML) && <RenderHTML html={renderedHTML} />}
{Boolean(pastedFile) && (
{!!renderedHTML && <RenderHTML html={renderedHTML} />}
{!!pastedFile && (
<View style={defaultStyles.mv3}>
<Image
source={{uri: URL.createObjectURL(pastedFile)}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import lodashGet from 'lodash/get';
import type {ComponentMeta} from '@storybook/react';
import React, {useState} from 'react';
import {Image, View} from 'react-native';
import DragAndDropConsumer from '@components/DragAndDrop/Consumer';
import DragAndDropProvider from '@components/DragAndDrop/Provider';
import Text from '@components/Text';
// eslint-disable-next-line no-restricted-imports
import {defaultStyles} from '@styles/index';
import {defaultStyles} from '@src/styles';

/**
* 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 DragAndDropConsumer> = {
title: 'Components/DragAndDrop',
component: DragAndDropConsumer,
};

function Default() {
const [fileURL, setFileURL] = useState('');

return (
<View
style={[
Expand Down Expand Up @@ -46,11 +46,11 @@ function Default() {
)}
</View>
<DragAndDropConsumer
onDrop={(e) => {
const file = lodashGet(e, ['dataTransfer', 'files', 0]);
if (file && file.type.includes('image')) {
onDrop={(event) => {
const file = event.dataTransfer?.files?.[0];
if (file?.type.includes('image')) {
const reader = new FileReader();
reader.addEventListener('load', () => setFileURL(reader.result));
reader.addEventListener('load', () => setFileURL(reader.result as string));
reader.readAsDataURL(file);
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ function getBackgroundColorWithOpacityStyle(backgroundColor: string, opacity: nu
return {};
}

function getWidthAndHeightStyle(width: number, height?: number): ViewStyle {
function getWidthAndHeightStyle(width: number, height?: number): Pick<ViewStyle, 'height' | 'width'> {
return {
width,
height: height ?? width,
Expand Down
Loading