Skip to content

Commit

Permalink
site: update site type { children: React.ReactNode } => `React.Prop…
Browse files Browse the repository at this point in the history
…sWithChildren` (#48770)

* site: update site type React.ReactNode => React.PropsWithChildren

* fix: fix

* fix: fix
  • Loading branch information
li-jia-nan committed May 6, 2024
1 parent 06d78e6 commit ddf7028
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .dumi/pages/index/components/Theme/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ const useStyle = createStyles(({ token, css }) => ({

export interface ColorPickerProps {
id?: string;
children?: React.ReactNode;
value?: string | Color;
onChange?: (value?: Color | string) => void;
}

const DebouncedColorPicker: React.FC<ColorPickerProps> = (props) => {
const DebouncedColorPicker: React.FC<React.PropsWithChildren<ColorPickerProps>> = (props) => {
const { value: color, children, onChange } = props;
const [value, setValue] = useState(color);

Expand Down
11 changes: 5 additions & 6 deletions .dumi/theme/builtins/ColorChunk/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import type { ColorInput } from '@ctrl/tinycolor';
import { TinyColor } from '@ctrl/tinycolor';
import { createStyles } from 'antd-style';

interface ColorChunkProps {
children?: React.ReactNode;
value?: ColorInput;
}

const useStyle = createStyles(({ token, css }) => ({
codeSpan: css`
padding: 0.2em 0.4em;
Expand All @@ -26,7 +21,11 @@ const useStyle = createStyles(({ token, css }) => ({
`,
}));

const ColorChunk: React.FC<ColorChunkProps> = (props) => {
interface ColorChunkProps {
value?: ColorInput;
}

const ColorChunk: React.FC<React.PropsWithChildren<ColorChunkProps>> = (props) => {
const { styles } = useStyle();
const { value, children } = props;

Expand Down
12 changes: 8 additions & 4 deletions .dumi/theme/builtins/Container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
* copied: https://github.com/arvinxx/dumi-theme-antd-style/tree/master/src/builtins/Container
*/
import * as React from 'react';
import type { FC, ReactNode } from 'react';
import { Alert } from 'antd';

import useStyles from './style';

const Container: FC<{
interface ContainerProps {
type: 'info' | 'warning' | 'success' | 'error';
title?: string;
children: ReactNode;
}> = ({ type, title, children }) => {
}

const Container: React.FC<React.PropsWithChildren<ContainerProps>> = ({
type,
title,
children,
}) => {
const { styles, cx } = useStyles();

return (
Expand Down
20 changes: 15 additions & 5 deletions .dumi/theme/builtins/ImagePreview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import { Image } from 'antd';
import classNames from 'classnames';
import toArray from 'rc-util/lib/Children/toArray';
import { Image } from 'antd';

interface ImagePreviewProps {
children: React.ReactNode[];
className?: string;
/** Do not show padding & background */
pure?: boolean;
Expand All @@ -29,11 +28,22 @@ function isGoodBadImg(imgMeta: any): boolean {
function isCompareImg(imgMeta: any): boolean {
return isGoodBadImg(imgMeta) || imgMeta.inline;
}
const ImagePreview: React.FC<ImagePreviewProps> = (props) => {

interface MateType {
className: string;
alt: string;
description: string;
src: string;
isGood: boolean;
isBad: boolean;
inline: boolean;
}

const ImagePreview: React.FC<React.PropsWithChildren<ImagePreviewProps>> = (props) => {
const { children, className: rootClassName, pure } = props;
const imgs = toArray(children).filter((ele) => ele.type === 'img');

const imgsMeta = imgs.map((img) => {
const imgsMeta = imgs.map<Partial<MateType>>((img) => {
const { alt, description, src, className } = img.props;
return {
className,
Expand Down Expand Up @@ -107,7 +117,7 @@ const ImagePreview: React.FC<ImagePreviewProps> = (props) => {
<div className="preview-image-title">{coverMeta.alt}</div>
<div
className="preview-image-description"
dangerouslySetInnerHTML={{ __html: coverMeta.description }}
dangerouslySetInnerHTML={{ __html: coverMeta.description ?? '' }}
/>
</div>
);
Expand Down
7 changes: 5 additions & 2 deletions .dumi/theme/builtins/LocaleLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ type LinkProps = Parameters<typeof Link>[0];

export interface LocaleLinkProps extends LinkProps {
sourceType: 'a' | 'Link';
children?: React.ReactNode;
}

const LocaleLink: React.FC<LocaleLinkProps> = ({ sourceType, to, ...props }) => {
const LocaleLink: React.FC<React.PropsWithChildren<LocaleLinkProps>> = ({
sourceType,
to,
...props
}) => {
const Component = sourceType === 'a' ? 'a' : Link;

const [, localeType] = useLocale();
Expand Down
4 changes: 1 addition & 3 deletions .dumi/theme/builtins/Sandpack/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { FC, ReactNode } from 'react';
import React, { Suspense } from 'react';
import { Skeleton } from 'antd';
import { createStyles } from 'antd-style';
Expand Down Expand Up @@ -42,13 +41,12 @@ const SandpackFallback = () => {
};

interface SandpackProps {
children?: ReactNode;
dark?: boolean;
autorun?: boolean;
dependencies?: string;
}

const Sandpack: FC<SandpackProps> = ({
const Sandpack: React.FC<React.PropsWithChildren<SandpackProps>> = ({
children,
dark,
dependencies: extraDeps,
Expand Down
3 changes: 1 addition & 2 deletions .dumi/theme/common/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import nprogress from 'nprogress';

export interface LinkProps {
to: string | { pathname?: string; search?: string; hash?: string };
children?: React.ReactNode;
style?: React.CSSProperties;
className?: string;
onClick?: MouseEventHandler;
}

const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
const Link = forwardRef<HTMLAnchorElement, React.PropsWithChildren<LinkProps>>((props, ref) => {
const { to, children, ...rest } = props;
const [isPending, startTransition] = useTransition();
const navigate = useNavigate();
Expand Down
3 changes: 1 addition & 2 deletions .dumi/theme/slots/Content/InViewSuspense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import type { IntersectionObserverProps } from 'react-intersection-observer';

type InViewSuspenseProps = Pick<IntersectionObserverProps, 'delay'> & {
fallback?: React.ReactNode;
children?: React.ReactNode;
};

const InViewSuspense: React.FC<InViewSuspenseProps> = ({
const InViewSuspense: React.FC<React.PropsWithChildren<InViewSuspenseProps>> = ({
children,
fallback = <Skeleton.Input active size="small" />,
delay = 200,
Expand Down
4 changes: 1 addition & 3 deletions components/watermark/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ describe('Watermark', () => {

const watermark = getWatermarkElement();

expect(watermark).toHaveStyle({
zIndex: '9',
});
expect(watermark).toHaveStyle({ zIndex: '9' });

// Not crash when children removed
rerender(<Watermark className="test" />);
Expand Down

0 comments on commit ddf7028

Please sign in to comment.