Skip to content

Commit

Permalink
chore: avoid memo override exported component displayName
Browse files Browse the repository at this point in the history
  • Loading branch information
unix committed Apr 29, 2020
1 parent c53abec commit 8691541
Show file tree
Hide file tree
Showing 78 changed files with 322 additions and 236 deletions.
10 changes: 5 additions & 5 deletions components/avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const safeText = (text: string): string => {
return text.slice(0, 3)
}

const Avatar: React.FC<AvatarProps> = React.memo(({
const Avatar: React.FC<AvatarProps> = ({
src, stacked, text, size, isSquare, className, ...props
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -91,14 +91,14 @@ const Avatar: React.FC<AvatarProps> = React.memo(({
`}</style>
</span>
)
})
}

type AvatarComponent<P = {}> = React.FC<P> & {
type MemoAvatarComponent<P = {}> = React.NamedExoticComponent<P> & {
Group: typeof AvatarGroup
}

type ComponentProps = Partial<typeof defaultProps> & Omit<Props, keyof typeof defaultProps> & NativeAttrs

(Avatar as AvatarComponent<ComponentProps>).defaultProps = defaultProps
Avatar.defaultProps = defaultProps

export default Avatar as AvatarComponent<ComponentProps>
export default React.memo(Avatar) as MemoAvatarComponent<ComponentProps>
8 changes: 5 additions & 3 deletions components/badge/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getBgColor = (type: NormalTypes, palette: ZeitUIThemesPalette) => {
return colors[type]
}

const Badge: React.FC<React.PropsWithChildren<BadgeProps>> = React.memo(({
const Badge: React.FC<React.PropsWithChildren<BadgeProps>> = ({
type, size, className, children, ...props
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -70,6 +70,8 @@ const Badge: React.FC<React.PropsWithChildren<BadgeProps>> = React.memo(({
`}</style>
</span>
)
})
}

const MemoBadge = React.memo<React.PropsWithChildren<BadgeProps>>(Badge)

export default withDefaults(Badge, defaultProps)
export default withDefaults(MemoBadge, defaultProps)
8 changes: 5 additions & 3 deletions components/button-dropdown/button-dropdown-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.ButtonHTMLAttributes<any>, keyof Props>
export type ButtonDropdownItemProps = Props & typeof defaultProps & NativeAttrs

const ButtonDropdownItem: React.FC<React.PropsWithChildren<ButtonDropdownItemProps>> = React.memo(({
const ButtonDropdownItem: React.FC<React.PropsWithChildren<ButtonDropdownItemProps>> = ({
children, onClick, className, main, type: selfType, ...props
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -76,6 +76,8 @@ const ButtonDropdownItem: React.FC<React.PropsWithChildren<ButtonDropdownItemPro
`}</style>
</button>
)
})
}

const MemoButtonDropdownItem = React.memo(ButtonDropdownItem)

export default withDefaults(ButtonDropdownItem, defaultProps)
export default withDefaults(MemoButtonDropdownItem, defaultProps)
13 changes: 6 additions & 7 deletions components/button-dropdown/button-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const stopPropagation = (event: MouseEvent<HTMLElement>) => {
event.nativeEvent.stopImmediatePropagation()
}

const ButtonDropdown: React.FC<React.PropsWithChildren<ButtonDropdownProps>> = React.memo(({
const ButtonDropdown: React.FC<React.PropsWithChildren<ButtonDropdownProps>> = ({
children, type, size, auto, className, disabled, loading, ...props
}) => {
const ref = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -137,15 +137,14 @@ const ButtonDropdown: React.FC<React.PropsWithChildren<ButtonDropdownProps>> = R
</div>
</ButtonDropdownContext.Provider>
)
})

ButtonDropdown.defaultProps = defaultProps
}

type ButtonDropdownComponent<P = {}> = React.FC<P> & {
type MemoButtonDropdownComponent<P = {}> = React.NamedExoticComponent<P> & {
Item: typeof ButtonDropdownItem
}

type ComponentProps = Partial<typeof defaultProps> & Omit<Props, keyof typeof defaultProps> & NativeAttrs

export default ButtonDropdown as ButtonDropdownComponent<ComponentProps>
ButtonDropdown.defaultProps = defaultProps

export default React.memo(ButtonDropdown) as MemoButtonDropdownComponent<ComponentProps>

8 changes: 5 additions & 3 deletions components/button-dropdown/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface Props {
height?: string
}

const ButtonDropdownIcon: React.FC<Props> = React.memo(({
const ButtonDropdownIcon: React.FC<Props> = ({
color, height,
}) => {
return (
Expand All @@ -20,6 +20,8 @@ const ButtonDropdownIcon: React.FC<Props> = React.memo(({
`}</style>
</svg>
)
})
}

const MemoButtonDropdownIcon = React.memo(ButtonDropdownIcon)

export default ButtonDropdownIcon
export default MemoButtonDropdownIcon
6 changes: 3 additions & 3 deletions components/button/__tests__/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Button should render empty button correctly 1`] = `
<Memo
<Memo(Button)
auto={false}
className=""
disabled={false}
Expand All @@ -17,7 +17,7 @@ exports[`Button should render empty button correctly 1`] = `
exports[`Button should render special styles 1`] = `ReactWrapper {}`;

exports[`Button should render special styles 2`] = `
<Memo
<Memo(Button)
auto={false}
className=""
disabled={false}
Expand All @@ -29,5 +29,5 @@ exports[`Button should render special styles 2`] = `
type="default"
>
button
</Memo>
</Memo(Button)>
`;
8 changes: 5 additions & 3 deletions components/button/button.drip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const defaultProps = {

export type ButtonDrip = Props & typeof defaultProps

const ButtonDrip: React.FC<ButtonDrip> = React.memo(({
const ButtonDrip: React.FC<ButtonDrip> = ({
x, y, color, onCompleted
}) => {
const dripRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -80,7 +80,9 @@ const ButtonDrip: React.FC<ButtonDrip> = React.memo(({
`}</style>
</div>
)
})
}

const MemoButtonDrip = React.memo<ButtonDrip>(ButtonDrip)

export default withDefaults(ButtonDrip, defaultProps)
export default withDefaults(MemoButtonDrip, defaultProps)

8 changes: 5 additions & 3 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.ButtonHTMLAttributes<any>, keyof Props>
export type ButtonProps = Props & typeof defaultProps & NativeAttrs

const Button: React.FC<React.PropsWithChildren<ButtonProps>> = React.memo(({
const Button: React.FC<React.PropsWithChildren<ButtonProps>> = ({
children, disabled, type, loading, shadow, ghost, effect, onClick,
auto, size, className, ...props
}) => {
Expand Down Expand Up @@ -145,6 +145,8 @@ const Button: React.FC<React.PropsWithChildren<ButtonProps>> = React.memo(({
`}</style>
</button>
)
})
}

const MemoButton = React.memo<React.PropsWithChildren<ButtonProps>>(Button)

export default withDefaults(Button, defaultProps)
export default withDefaults(MemoButton, defaultProps)
8 changes: 5 additions & 3 deletions components/capacity/capacity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const getColor = (val: number, palette: ZeitUIThemesPalette): string => {
return palette.errorDark
}

const Capacity: React.FC<CapacityProps> = React.memo(({
const Capacity: React.FC<CapacityProps> = ({
value, limit, color: userColor, className, ...props
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -60,6 +60,8 @@ const Capacity: React.FC<CapacityProps> = React.memo(({
`}</style>
</div>
)
})
}

const MemoCapacity = React.memo(Capacity)

export default withDefaults(Capacity, defaultProps)
export default withDefaults(MemoCapacity, defaultProps)
4 changes: 3 additions & 1 deletion components/card/card-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ const CardContent: React.FC<React.PropsWithChildren<CardContentProps>> = ({
)
}

export default withDefaults(CardContent, defaultProps)
const MemoCardContent = React.memo(CardContent)

export default withDefaults(MemoCardContent, defaultProps)
4 changes: 3 additions & 1 deletion components/card/card-footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ const CardFooter: React.FC<React.PropsWithChildren<CardFooterProps>> = ({
)
}

export default withDefaults(CardFooter, defaultProps)
const MemoCardFooter = React.memo(CardFooter)

export default withDefaults(MemoCardFooter, defaultProps)
11 changes: 5 additions & 6 deletions components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type CardProps = Props & typeof defaultProps & NativeAttrs

const Card: React.FC<React.PropsWithChildren<CardProps>> = React.memo(({
const Card: React.FC<React.PropsWithChildren<CardProps>> = ({
children, hoverable, className, shadow, type, width, ...props
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -88,17 +88,16 @@ const Card: React.FC<React.PropsWithChildren<CardProps>> = React.memo(({
`}</style>
</div>
)
})
}

type CardComponent<P = {}> = React.FC<P> & {
type MemoCardComponent<P = {}> = React.NamedExoticComponent<P> & {
Footer: typeof CardFooter
Actions: typeof CardFooter
Content: typeof CardContent
Body: typeof CardContent
}

type ComponentProps = Partial<typeof defaultProps> & Omit<Props, keyof typeof defaultProps> & NativeAttrs

(Card as CardComponent<ComponentProps>).defaultProps = defaultProps
Card.defaultProps = defaultProps

export default Card as CardComponent<ComponentProps>
export default React.memo(Card) as MemoCardComponent<ComponentProps>
4 changes: 2 additions & 2 deletions components/checkbox/checkbox-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type CheckboxGroupProps = Props & typeof defaultProps & NativeAttrs

const CheckboxGroup: React.FC<React.PropsWithChildren<CheckboxGroupProps>> = React.memo(({
const CheckboxGroup: React.FC<React.PropsWithChildren<CheckboxGroupProps>> = ({
disabled, onChange, value, children, className, ...props
}) => {
const [selfVal, setSelfVal] = useState<string[]>([])
Expand Down Expand Up @@ -59,6 +59,6 @@ const CheckboxGroup: React.FC<React.PropsWithChildren<CheckboxGroupProps>> = Rea
</div>
</CheckboxContext.Provider>
)
})
}

export default withDefaults(CheckboxGroup, defaultProps)
8 changes: 5 additions & 3 deletions components/checkbox/checkbox.icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface Props {
checked?: boolean
}

const CheckboxIcon: React.FC<Props> = React.memo(({
const CheckboxIcon: React.FC<Props> = ({
disabled, checked,
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -47,6 +47,8 @@ const CheckboxIcon: React.FC<Props> = React.memo(({
`}</style>
</>
)
})
}

const MemoCheckboxIcon = React.memo(CheckboxIcon)

export default CheckboxIcon
export default MemoCheckboxIcon
5 changes: 2 additions & 3 deletions components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.LabelHTMLAttributes<any>, keyof Props>
export type CheckboxProps = Props & typeof defaultProps & NativeAttrs

const Checkbox: React.FC<CheckboxProps> = React.memo(({
const Checkbox: React.FC<CheckboxProps> = ({
checked, initialChecked, disabled, onChange, className, children, value, ...props
}) => {
const [selfChecked, setSelfChecked] = useState<boolean>(initialChecked)
Expand Down Expand Up @@ -119,8 +119,7 @@ const Checkbox: React.FC<CheckboxProps> = React.memo(({
`}</style>
</label>
)
})

}

Checkbox.defaultProps = defaultProps

Expand Down
8 changes: 5 additions & 3 deletions components/code/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type CodeProps = Props & typeof defaultProps & NativeAttrs

const Code: React.FC<React.PropsWithChildren<CodeProps>> = React.memo(({
const Code: React.FC<React.PropsWithChildren<CodeProps>> = ({
children, block, bash, darkBash, className, width, ...props
}) => {
if (bash) {
Expand Down Expand Up @@ -65,6 +65,8 @@ const Code: React.FC<React.PropsWithChildren<CodeProps>> = React.memo(({
`}</style>
</>
)
})
}

const MemoCode = React.memo(Code)

export default withDefaults(Code, defaultProps)
export default withDefaults(MemoCode, defaultProps)
8 changes: 5 additions & 3 deletions components/col/col.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type ColProps = Props & typeof defaultProps & NativeAttrs

const Col: React.FC<React.PropsWithChildren<ColProps>> = React.memo(({
const Col: React.FC<React.PropsWithChildren<ColProps>> = ({
component, children, span, offset, className, ...props
}) => {
const Component = component
Expand All @@ -38,6 +38,8 @@ const Col: React.FC<React.PropsWithChildren<ColProps>> = React.memo(({
`}</style>
</Component>
)
})
}

const MemoCol = React.memo(Col)

export default withDefaults(Col, defaultProps)
export default withDefaults(MemoCol, defaultProps)
4 changes: 3 additions & 1 deletion components/collapse/collapse-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ const CollapseIcon: React.FC<Props> = ({ active }) => {
)
}

export default CollapseIcon
const MemoCollapseIcon = React.memo(CollapseIcon)

export default MemoCollapseIcon
8 changes: 5 additions & 3 deletions components/description/description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type DescriptionProps = Props & typeof defaultProps & NativeAttrs

const Description: React.FC<DescriptionProps> = React.memo(({
const Description: React.FC<DescriptionProps> = ({
title, content, className, ...props
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -56,6 +56,8 @@ const Description: React.FC<DescriptionProps> = React.memo(({
`}</style>
</dl>
)
})
}

const MemoDescription = React.memo(Description)

export default withDefaults(Description, defaultProps)
export default withDefaults(MemoDescription, defaultProps)
8 changes: 5 additions & 3 deletions components/display/display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const defaultProps = {
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type DisplayProps = Props & typeof defaultProps & NativeAttrs

const Display: React.FC<React.PropsWithChildren<DisplayProps>> = React.memo(({
const Display: React.FC<React.PropsWithChildren<DisplayProps>> = ({
children, caption, shadow, className, width, ...props
}) => {
const theme = useTheme()
Expand Down Expand Up @@ -66,6 +66,8 @@ const Display: React.FC<React.PropsWithChildren<DisplayProps>> = React.memo(({
`}</style>
</div>
)
})
}

const MemoDisplay = React.memo(Display)

export default withDefaults(Display, defaultProps)
export default withDefaults(MemoDisplay, defaultProps)
Loading

0 comments on commit 8691541

Please sign in to comment.