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

Refactor(web-react): No longer use default props in the rest of the c… #1694

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -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<AttachmentImagePreviewProps> = {
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;

Expand All @@ -29,9 +29,4 @@ const AttachmentImagePreview = ({ label, imagePreview, meta, imageObjectFit }: A
);
};

AttachmentImagePreview.defaultProps = {
meta: undefined,
imageObjectFit: 'cover',
};

export default AttachmentImagePreview;
11 changes: 6 additions & 5 deletions packages/web-react/src/components/Tabs/TabLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <E extends ElementType = 'a'>(props: SpiritTabLinkProps<E>, ref: PolymorphicRef<E>): 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);

Expand All @@ -24,8 +29,4 @@ const _TabLink = <E extends ElementType = 'a'>(props: SpiritTabLinkProps<E>, ref

export const TabLink = forwardRef<HTMLAnchorElement, SpiritTabLinkProps<ElementType>>(_TabLink);

TabLink.defaultProps = {
itemProps: {},
};

export default TabLink;
13 changes: 7 additions & 6 deletions packages/web-react/src/components/Tooltip/TooltipTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,9 +31,4 @@ const TooltipTrigger = (props: TooltipTriggerProps) => {
);
};

TooltipTrigger.defaultProps = {
elementType: 'button',
children: null,
};

export default TooltipTrigger;
7 changes: 7 additions & 0 deletions packages/web-react/src/types/fileUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpiritInputElementProps, 'onError'>,
FileUploaderIntermediateProps,
Expand Down
Loading