From 281975da36933b30894aba2210d80c5bc9ff4002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kry=C5=A1p=C3=ADn?= Date: Thu, 10 Oct 2024 11:05:51 +0200 Subject: [PATCH] Refactor(web-react): No longer use default props in the rest of the components --- .../FileUploader/AttachmentImagePreview.tsx | 19 +++++++------------ .../web-react/src/components/Tabs/TabLink.tsx | 11 ++++++----- .../src/components/Tooltip/TooltipTrigger.tsx | 13 +++++++------ packages/web-react/src/types/fileUploader.ts | 7 +++++++ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx b/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx index b6fcbe0968..64fc1be165 100644 --- a/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx +++ b/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx @@ -1,18 +1,18 @@ 'use client'; import React from 'react'; -import { FileMetadata } from '../../types/fileUploader'; +import { AttachmentImagePreviewProps } from '../../types'; import { IMAGE_DIMENSION } from './constants'; import { useFileUploaderStyleProps } from './useFileUploaderStyleProps'; -type AttachmentImagePreviewProps = { - imagePreview: string; - label: string; - meta?: FileMetadata; - imageObjectFit?: 'contain' | 'cover'; +const defaultProps: Partial = { + meta: undefined, + imageObjectFit: 'cover', }; -const AttachmentImagePreview = ({ label, imagePreview, meta, imageObjectFit }: AttachmentImagePreviewProps) => { +const AttachmentImagePreview = (props: AttachmentImagePreviewProps) => { + const propsWithDefaults = { ...defaultProps, ...props }; + const { label, imagePreview, meta, imageObjectFit } = propsWithDefaults; const { classProps } = useFileUploaderStyleProps({ meta, imageObjectFit }); const { imageCropStyles, attachmentStyles } = classProps; @@ -29,9 +29,4 @@ const AttachmentImagePreview = ({ label, imagePreview, meta, imageObjectFit }: A ); }; -AttachmentImagePreview.defaultProps = { - meta: undefined, - imageObjectFit: 'cover', -}; - export default AttachmentImagePreview; diff --git a/packages/web-react/src/components/Tabs/TabLink.tsx b/packages/web-react/src/components/Tabs/TabLink.tsx index 8740b2743e..2a0b4d342f 100644 --- a/packages/web-react/src/components/Tabs/TabLink.tsx +++ b/packages/web-react/src/components/Tabs/TabLink.tsx @@ -6,10 +6,15 @@ import { useStyleProps } from '../../hooks'; import { PolymorphicRef, SpiritTabLinkProps } from '../../types'; import { useTabsStyleProps } from './useTabsStyleProps'; +const defaultProps: SpiritTabLinkProps = { + itemProps: {}, +}; + /* We need an exception for components exported with forwardRef */ /* eslint no-underscore-dangle: ['error', { allow: ['_TabLink'] }] */ const _TabLink = (props: SpiritTabLinkProps, ref: PolymorphicRef): JSX.Element => { - const { elementType: ElementTag = 'a', children, itemProps = {}, ...restProps } = props; + const propsWithDefaults = { ...defaultProps, ...props }; + const { elementType: ElementTag = 'a', children, itemProps = {}, ...restProps } = propsWithDefaults; const { classProps } = useTabsStyleProps(); const { styleProps: itemStyleProps, props: itemTransferProps } = useStyleProps(itemProps); @@ -24,8 +29,4 @@ const _TabLink = (props: SpiritTabLinkProps, ref export const TabLink = forwardRef>(_TabLink); -TabLink.defaultProps = { - itemProps: {}, -}; - export default TabLink; diff --git a/packages/web-react/src/components/Tooltip/TooltipTrigger.tsx b/packages/web-react/src/components/Tooltip/TooltipTrigger.tsx index 14ecb3ce76..b8b86e98f9 100644 --- a/packages/web-react/src/components/Tooltip/TooltipTrigger.tsx +++ b/packages/web-react/src/components/Tooltip/TooltipTrigger.tsx @@ -10,8 +10,14 @@ interface TooltipTriggerProps extends StyleProps, TransferProps { children?: string | ReactNode | ((props: { isOpen: boolean }) => ReactNode); } +const defaultProps: TooltipTriggerProps = { + elementType: 'button', + children: null, +}; + const TooltipTrigger = (props: TooltipTriggerProps) => { - const { elementType = 'button', children, ...rest } = props; + const propsWithDefaults = { ...defaultProps, ...props }; + const { elementType = 'button', children, ...rest } = propsWithDefaults; const { id, isOpen, triggerRef, getReferenceProps } = useTooltipContext(); const Component = elementType; @@ -25,9 +31,4 @@ const TooltipTrigger = (props: TooltipTriggerProps) => { ); }; -TooltipTrigger.defaultProps = { - elementType: 'button', - children: null, -}; - export default TooltipTrigger; diff --git a/packages/web-react/src/types/fileUploader.ts b/packages/web-react/src/types/fileUploader.ts index ea7acd78c0..f70aa24741 100644 --- a/packages/web-react/src/types/fileUploader.ts +++ b/packages/web-react/src/types/fileUploader.ts @@ -65,6 +65,13 @@ export interface AttachmentActionButtonBaseProps extends SpiritButtonElementProp export interface AttachmentDismissButtonBaseProps extends SpiritButtonElementProps {} +export interface AttachmentImagePreviewProps { + imagePreview: string; + label: string; + meta?: FileMetadata; + imageObjectFit?: 'contain' | 'cover'; +} + export interface FileUploaderInputBaseProps extends Omit, FileUploaderIntermediateProps,