From 7dc7619007ec423a2d31a126ff143de12daccea9 Mon Sep 17 00:00:00 2001 From: Shaun Lloyd Date: Fri, 12 Jan 2024 15:12:34 -0500 Subject: [PATCH 1/8] Remove use of React.FC --- .../src/components/ActionBar/ActionBar.tsx | 4 +-- .../components/src/components/Badge/Badge.tsx | 6 ++--- .../ErrorFormatter/ErrorFormatter.tsx | 9 +++++-- .../src/components/Loader/Loader.tsx | 11 +++----- .../src/components/ScrollArea/ScrollArea.tsx | 5 ++-- code/ui/components/src/components/bar/bar.tsx | 25 ++++++++++++------- .../components/src/components/bar/button.tsx | 3 +-- .../src/components/bar/separator.tsx | 7 +++--- .../src/components/brand/StorybookIcon.tsx | 3 +-- .../src/components/brand/StorybookLogo.tsx | 7 +++--- .../src/components/form/field/field.tsx | 4 +-- .../src/components/form/input/input.tsx | 4 +-- .../components/placeholder/placeholder.tsx | 3 +-- .../src/components/spaced/Spaced.tsx | 3 +-- .../syntaxhighlighter/syntaxhighlighter.tsx | 4 +-- .../src/components/tooltip/ListItem.tsx | 8 +++--- .../components/tooltip/TooltipLinkList.tsx | 16 +++++++----- .../src/components/tooltip/TooltipMessage.tsx | 4 +-- .../src/components/tooltip/TooltipNote.tsx | 3 +-- .../src/components/tooltip/WithTooltip.tsx | 22 +++++++++------- .../components/typography/elements/Link.tsx | 11 ++++---- .../src/components/typography/link/link.tsx | 8 +++--- 22 files changed, 90 insertions(+), 80 deletions(-) diff --git a/code/ui/components/src/components/ActionBar/ActionBar.tsx b/code/ui/components/src/components/ActionBar/ActionBar.tsx index 8519b47e47c1..c97d09598e83 100644 --- a/code/ui/components/src/components/ActionBar/ActionBar.tsx +++ b/code/ui/components/src/components/ActionBar/ActionBar.tsx @@ -1,4 +1,4 @@ -import type { FC, MouseEvent, ReactElement } from 'react'; +import type { MouseEvent, ReactElement } from 'react'; import React from 'react'; import { styled } from '@storybook/theming'; @@ -66,7 +66,7 @@ export interface ActionBarProps { actionItems: ActionItem[]; } -export const ActionBar: FC = ({ actionItems, ...props }) => ( +export const ActionBar = ({ actionItems, ...props }: ActionBarProps) => ( {actionItems.map(({ title, className, onClick, disabled }, index: number) => ( // eslint-disable-next-line react/no-array-index-key diff --git a/code/ui/components/src/components/Badge/Badge.tsx b/code/ui/components/src/components/Badge/Badge.tsx index bcb4d3b01b50..f9d1c9b91ebb 100644 --- a/code/ui/components/src/components/Badge/Badge.tsx +++ b/code/ui/components/src/components/Badge/Badge.tsx @@ -1,4 +1,3 @@ -import type { FC, PropsWithChildren } from 'react'; import React from 'react'; import { styled } from '@storybook/theming'; import { transparentize } from 'polished'; @@ -80,10 +79,11 @@ const BadgeWrapper = styled.div( } ); -export interface BadgeProps extends PropsWithChildren { +export interface BadgeProps { status: 'positive' | 'negative' | 'neutral' | 'warning' | 'critical'; + children?: React.ReactNode; } -export const Badge: FC = ({ ...props }) => { +export const Badge = ({ ...props }: BadgeProps) => { return ; }; diff --git a/code/ui/components/src/components/ErrorFormatter/ErrorFormatter.tsx b/code/ui/components/src/components/ErrorFormatter/ErrorFormatter.tsx index 5204ceb6f9aa..99a97f33871f 100644 --- a/code/ui/components/src/components/ErrorFormatter/ErrorFormatter.tsx +++ b/code/ui/components/src/components/ErrorFormatter/ErrorFormatter.tsx @@ -1,5 +1,5 @@ import { global } from '@storybook/global'; -import type { FC } from 'react'; + import React, { Fragment } from 'react'; import { styled } from '@storybook/theming'; @@ -20,7 +20,12 @@ const firstLineRegex = /(Error): (.*)\n/; const linesRegexChromium = /at (?:(.*) )?\(?(.+)\)?/; const linesRegexFirefox = /([^@]+)?(?:\/<)?@(.+)?/; const linesRegexSafari = /([^@]+)?@(.+)?/; -export const ErrorFormatter: FC<{ error: Error }> = ({ error }) => { + +export interface ErrorFormatterProps { + error: Error; +} + +export const ErrorFormatter = ({ error }: ErrorFormatterProps) => { if (!error) { return This error has no stack or message; } diff --git a/code/ui/components/src/components/Loader/Loader.tsx b/code/ui/components/src/components/Loader/Loader.tsx index c4f89c572a5d..537063c48fd5 100644 --- a/code/ui/components/src/components/Loader/Loader.tsx +++ b/code/ui/components/src/components/Loader/Loader.tsx @@ -1,5 +1,5 @@ import { transparentize } from 'polished'; -import type { ComponentProps, FC } from 'react'; +import type { ComponentProps } from 'react'; import React from 'react'; import { styled, keyframes } from '@storybook/theming'; import { Icons } from '../icon/icon'; @@ -98,18 +98,13 @@ interface Progress { }; } -interface LoaderProps { +interface LoaderProps extends ComponentProps { progress?: Progress; error?: Error; size?: number; } -export const Loader: FC> = ({ - progress, - error, - size, - ...props -}) => { +export const Loader = ({ progress, error, size, ...props }: LoaderProps) => { if (error) { return ( diff --git a/code/ui/components/src/components/ScrollArea/ScrollArea.tsx b/code/ui/components/src/components/ScrollArea/ScrollArea.tsx index b06fff3f5ec4..f3f965af8783 100644 --- a/code/ui/components/src/components/ScrollArea/ScrollArea.tsx +++ b/code/ui/components/src/components/ScrollArea/ScrollArea.tsx @@ -1,4 +1,3 @@ -import type { FC } from 'react'; import React from 'react'; import { styled } from '@storybook/theming'; import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area'; @@ -76,14 +75,14 @@ const ScrollAreaThumb = styled(ScrollAreaPrimitive.Thumb)(({ theme }) => ({ }, })); -export const ScrollArea: FC = ({ +export const ScrollArea = ({ children, horizontal = false, vertical = false, offset = 2, scrollbarSize = 6, className, -}) => ( +}: ScrollAreaProps) => ( {children} {horizontal && ( diff --git a/code/ui/components/src/components/bar/bar.tsx b/code/ui/components/src/components/bar/bar.tsx index bdbb60757f38..e431a7dccd92 100644 --- a/code/ui/components/src/components/bar/bar.tsx +++ b/code/ui/components/src/components/bar/bar.tsx @@ -1,4 +1,4 @@ -import type { ComponentProps, FC } from 'react'; +import type { ComponentProps } from 'react'; import React, { Children } from 'react'; import { styled } from '@storybook/theming'; @@ -39,11 +39,11 @@ export const Side = styled.div( ); Side.displayName = 'Side'; -const UnstyledBar: FC & { scrollable?: boolean }> = ({ - children, - className, - scrollable, -}) => +interface UnstyledBarProps extends ComponentProps { + scrollable?: boolean; +} + +const UnstyledBar = ({ children, className, scrollable }: UnstyledBarProps) => scrollable ? ( {children} @@ -51,7 +51,11 @@ const UnstyledBar: FC & { scrollable?: boolean ) : (
{children}
); -export const Bar = styled(UnstyledBar)<{ border?: boolean; scrollable?: boolean }>( + +export interface BarProps extends UnstyledBarProps { + border?: boolean; +} +export const Bar = styled(UnstyledBar)( ({ theme, scrollable = true }) => ({ color: theme.barTextColor, width: '100%', @@ -70,7 +74,10 @@ export const Bar = styled(UnstyledBar)<{ border?: boolean; scrollable?: boolean ); Bar.displayName = 'Bar'; -const BarInner = styled.div<{ bgColor: string }>(({ bgColor }) => ({ +interface BarInnerProps { + bgColor?: string; +} +const BarInner = styled.div(({ bgColor }) => ({ display: 'flex', justifyContent: 'space-between', position: 'relative', @@ -85,7 +92,7 @@ export interface FlexBarProps extends ComponentProps { backgroundColor?: string; } -export const FlexBar: FC = ({ children, backgroundColor, ...rest }) => { +export const FlexBar = ({ children, backgroundColor, ...rest }: FlexBarProps) => { const [left, right] = Children.toArray(children); return ( diff --git a/code/ui/components/src/components/bar/button.tsx b/code/ui/components/src/components/bar/button.tsx index 0c45c0ba3fa6..68ce83036b59 100644 --- a/code/ui/components/src/components/bar/button.tsx +++ b/code/ui/components/src/components/bar/button.tsx @@ -2,7 +2,6 @@ import type { AnchorHTMLAttributes, ButtonHTMLAttributes, DetailedHTMLProps, - FC, ForwardedRef, ForwardRefExoticComponent, ReactElement, @@ -147,7 +146,7 @@ const IconButtonSkeletonWrapper = styled.div(() => ({ * @deprecated * This component will be removed in Storybook 9.0 * */ -export const IconButtonSkeleton: FC = () => ( +export const IconButtonSkeleton = () => ( diff --git a/code/ui/components/src/components/bar/separator.tsx b/code/ui/components/src/components/bar/separator.tsx index 6a24a11d3386..66ade31f3241 100644 --- a/code/ui/components/src/components/bar/separator.tsx +++ b/code/ui/components/src/components/bar/separator.tsx @@ -1,6 +1,10 @@ import React, { Fragment } from 'react'; import { styled } from '@storybook/theming'; +export interface SeparatorProps { + force?: boolean; +} + export const Separator = styled.span( ({ theme }) => ({ width: 1, @@ -35,6 +39,3 @@ export const interleaveSeparators = (list: any[]) => ), null ); -export interface SeparatorProps { - force?: boolean; -} diff --git a/code/ui/components/src/components/brand/StorybookIcon.tsx b/code/ui/components/src/components/brand/StorybookIcon.tsx index 5b756ea3afc6..fc3ec8c00033 100644 --- a/code/ui/components/src/components/brand/StorybookIcon.tsx +++ b/code/ui/components/src/components/brand/StorybookIcon.tsx @@ -1,7 +1,6 @@ -import type { FC } from 'react'; import React from 'react'; -export const StorybookIcon: FC = ({ ...props }) => ( +export const StorybookIcon = ({ ...props }): React.ReactNode => ( Storybook icon diff --git a/code/ui/components/src/components/brand/StorybookLogo.tsx b/code/ui/components/src/components/brand/StorybookLogo.tsx index b94c9e37f144..c83453436e20 100644 --- a/code/ui/components/src/components/brand/StorybookLogo.tsx +++ b/code/ui/components/src/components/brand/StorybookLogo.tsx @@ -1,9 +1,10 @@ -import type { FC } from 'react'; import React from 'react'; -export const StorybookLogo: FC<{ +export interface StorybookLogoProps extends React.SVGAttributes { alt: string; -}> = ({ alt, ...props }) => ( +} + +export const StorybookLogo = ({ alt, ...props }: StorybookLogoProps) => ( {alt ? {alt} : null} diff --git a/code/ui/components/src/components/form/field/field.tsx b/code/ui/components/src/components/form/field/field.tsx index 6452a31e3444..19b21ae8d2f7 100644 --- a/code/ui/components/src/components/form/field/field.tsx +++ b/code/ui/components/src/components/form/field/field.tsx @@ -1,4 +1,4 @@ -import type { FC, ReactNode } from 'react'; +import type { ReactNode } from 'react'; import React from 'react'; import { styled } from '@storybook/theming'; @@ -28,7 +28,7 @@ export interface FieldProps { label?: ReactNode; } -export const Field: FC = ({ label, children, ...props }) => ( +export const Field = ({ label, children, ...props }: FieldProps) => ( {label ? (