Skip to content

Commit

Permalink
fix: 移除 defaultProps(2) (#2254)
Browse files Browse the repository at this point in the history
* fix: 移除 defaultProps

* fix: remove defaultProps
  • Loading branch information
eiinu authored May 16, 2024
1 parent a0c2033 commit d4c0049
Show file tree
Hide file tree
Showing 117 changed files with 93 additions and 192 deletions.
1 change: 0 additions & 1 deletion scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const ${name}: FunctionComponent<Partial<${name}Props> & React.HTMLAttrib
return <div className="nut-${name.toLowerCase()}">${name}</div>
}
${name}.defaultProps = defaultProps
${name}.displayName = 'Nut${name}'
`,
doc: `# ${name}组件
Expand Down
1 change: 0 additions & 1 deletion src/packages/actionsheet/actionsheet.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@ export const ActionSheet: FunctionComponent<
)
}

ActionSheet.defaultProps = defaultProps
ActionSheet.displayName = 'NutActionSheet'
1 change: 0 additions & 1 deletion src/packages/actionsheet/actionsheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@ export const ActionSheet: FunctionComponent<
)
}

ActionSheet.defaultProps = defaultProps
ActionSheet.displayName = 'NutActionSheet'
1 change: 0 additions & 1 deletion src/packages/address/address.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,4 @@ const InternalAddress: ForwardRefRenderFunction<

export const Address = forwardRef(InternalAddress)

Address.defaultProps = defaultProps
Address.displayName = 'NutAddress'
1 change: 0 additions & 1 deletion src/packages/address/address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,4 @@ export const InternalAddress: ForwardRefRenderFunction<

export const Address = forwardRef(InternalAddress)

Address.defaultProps = defaultProps
Address.displayName = 'NutAddress'
1 change: 0 additions & 1 deletion src/packages/animate/animate.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ export const Animate: FunctionComponent<
)
}

Animate.defaultProps = defaultProps
Animate.displayName = 'NutAnimate'
1 change: 0 additions & 1 deletion src/packages/animate/animate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ export const Animate: FunctionComponent<
)
}

Animate.defaultProps = defaultProps
Animate.displayName = 'NutAnimate'
5 changes: 2 additions & 3 deletions src/packages/avatar/avatar.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export const Avatar: FunctionComponent<
}

const errorEvent = () => {
if (props.onError) {
props.onError()
if (onError) {
onError()
}
}

Expand Down Expand Up @@ -202,6 +202,5 @@ export const Avatar: FunctionComponent<
)
}

Avatar.defaultProps = defaultProps
Avatar.displayName = 'NutAvatar'
Avatar.Group = AvatarGroup
5 changes: 2 additions & 3 deletions src/packages/avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export const Avatar: FunctionComponent<
}

const errorEvent = () => {
if (props.onError) {
props.onError()
if (onError) {
onError()
}
}

Expand Down Expand Up @@ -188,6 +188,5 @@ export const Avatar: FunctionComponent<
)
}

Avatar.defaultProps = defaultProps
Avatar.displayName = 'NutAvatar'
Avatar.Group = AvatarGroup
1 change: 0 additions & 1 deletion src/packages/avatarcropper/avatarcropper.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -719,5 +719,4 @@ export const AvatarCropper: FunctionComponent<Partial<AvatarCropperProps>> = (
</>
)
}
AvatarCropper.defaultProps = defaultProps
AvatarCropper.displayName = 'NutAvatarCropper'
1 change: 0 additions & 1 deletion src/packages/avatarcropper/avatarcropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,4 @@ export const AvatarCropper: FunctionComponent<Partial<AvatarCropperProps>> = (
)
}

AvatarCropper.defaultProps = defaultProps
AvatarCropper.displayName = 'NutAvatarCropper'
1 change: 0 additions & 1 deletion src/packages/avatargroup/avatargroup.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ export const AvatarGroup: FunctionComponent<
)
}

AvatarGroup.defaultProps = defaultProps
AvatarGroup.displayName = 'NutAvatarGroup'
1 change: 0 additions & 1 deletion src/packages/avatargroup/avatargroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ export const AvatarGroup: FunctionComponent<
)
}

AvatarGroup.defaultProps = defaultProps
AvatarGroup.displayName = 'NutAvatarGroup'
1 change: 0 additions & 1 deletion src/packages/badge/badge.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,4 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
)
}

Badge.defaultProps = defaultProps
Badge.displayName = 'NutBadge'
1 change: 0 additions & 1 deletion src/packages/badge/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
)
}

Badge.defaultProps = defaultProps
Badge.displayName = 'NutBadge'
1 change: 0 additions & 1 deletion src/packages/barrage/barrage.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,4 @@ export const Barrage = React.forwardRef<unknown, Partial<BarrageProps>>(
InternalBarrage
)

Barrage.defaultProps = defaultProps
Barrage.displayName = 'NutBarrage'
1 change: 0 additions & 1 deletion src/packages/barrage/barrage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,4 @@ export const Barrage = React.forwardRef<unknown, Partial<BarrageProps>>(
InternalBarrage
)

Barrage.defaultProps = defaultProps
Barrage.displayName = 'NutBarrage'
1 change: 0 additions & 1 deletion src/packages/calendar/calendar.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,4 @@ export const Calendar = React.forwardRef<
)
})

Calendar.defaultProps = defaultProps
Calendar.displayName = 'NutCalendar'
1 change: 0 additions & 1 deletion src/packages/calendar/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,4 @@ export const Calendar = React.forwardRef<
)
})

Calendar.defaultProps = defaultProps
Calendar.displayName = 'NutCalendar'
1 change: 0 additions & 1 deletion src/packages/calendarcard/calendarcard.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,4 @@ export const CalendarCard = React.forwardRef<
) : null
})

CalendarCard.defaultProps = defaultProps as CalendarCardProps
CalendarCard.displayName = 'NutCalendarCard'
1 change: 0 additions & 1 deletion src/packages/calendarcard/calendarcard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,4 @@ export const CalendarCard = React.forwardRef<
) : null
})

CalendarCard.defaultProps = defaultProps as CalendarCardProps
CalendarCard.displayName = 'NutCalendarCard'
6 changes: 3 additions & 3 deletions src/packages/calendaritem/calendaritem.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const CalendarItem = React.forwardRef<
renderDay,
renderDayTop,
renderDayBottom,
value,
onConfirm,
onUpdate,
onDayClick,
Expand Down Expand Up @@ -172,7 +173,7 @@ export const CalendarItem = React.forwardRef<
}

const [currentDate, setCurrentDate] = usePropsValue<CalendarValue>({
value: props.value,
value,
defaultValue: resetDefaultValue(),
finalValue: [],
onChange: (val) => {},
Expand Down Expand Up @@ -412,7 +413,7 @@ export const CalendarItem = React.forwardRef<
monthsData[current.lastCurrent],
true
)
} else if (props.type === 'week') {
} else if (type === 'week') {
chooseDay(
{ day: defaultData[2], type: 'curr' },
monthsData[current.current],
Expand Down Expand Up @@ -890,5 +891,4 @@ export const CalendarItem = React.forwardRef<
)
})

CalendarItem.defaultProps = defaultProps
CalendarItem.displayName = 'NutCalendarItem'
6 changes: 3 additions & 3 deletions src/packages/calendaritem/calendaritem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const CalendarItem = React.forwardRef<
renderDay,
renderDayTop,
renderDayBottom,
value,
onConfirm,
onUpdate,
onDayClick,
Expand Down Expand Up @@ -170,7 +171,7 @@ export const CalendarItem = React.forwardRef<
}

const [currentDate, setCurrentDate] = usePropsValue<CalendarValue>({
value: props.value,
value,
defaultValue: resetDefaultValue(),
finalValue: [],
onChange: (val) => {},
Expand Down Expand Up @@ -412,7 +413,7 @@ export const CalendarItem = React.forwardRef<
monthsData[current.lastCurrent],
true
)
} else if (props.type === 'week') {
} else if (type === 'week') {
chooseDay(
{ day: defaultData[2], type: 'curr' },
monthsData[current.current],
Expand Down Expand Up @@ -888,5 +889,4 @@ export const CalendarItem = React.forwardRef<
)
})

CalendarItem.defaultProps = defaultProps
CalendarItem.displayName = 'NutCalendarItem'
1 change: 0 additions & 1 deletion src/packages/card/card.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,4 @@ export const Card: FunctionComponent<
)
}

Card.defaultProps = defaultProps
Card.displayName = 'NutCard'
1 change: 0 additions & 1 deletion src/packages/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,4 @@ export const Card: FunctionComponent<
)
}

Card.defaultProps = defaultProps
Card.displayName = 'NutCard'
9 changes: 5 additions & 4 deletions src/packages/cascader/cascader.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const InternalCascader: ForwardRefRenderFunction<
closeIconPosition,
closeIcon,
lazy,
title,
left,
onLoad,
onClose,
onChange,
Expand All @@ -124,7 +126,7 @@ const InternalCascader: ForwardRefRenderFunction<
finalValue: defaultValue,
})
const [innerVisible, setInnerVisible] = usePropsValue<boolean>({
value: props.visible,
value: visible,
defaultValue: undefined,
finalValue: false,
})
Expand Down Expand Up @@ -481,8 +483,8 @@ const InternalCascader: ForwardRefRenderFunction<
closeIcon={closeIcon}
closeable={closeable}
closeIconPosition={closeIconPosition}
title={popup && (props.title as ReactNode)}
left={props.left}
title={popup && (title as ReactNode)}
left={left}
// todo 只关闭,不处理逻辑。和popup的逻辑不一致。关闭时需要增加是否要处理回调
onOverlayClick={closePopup}
onCloseIconClick={closePopup}
Expand All @@ -498,5 +500,4 @@ const InternalCascader: ForwardRefRenderFunction<

export const Cascader = React.forwardRef(InternalCascader)

Cascader.defaultProps = defaultProps
Cascader.displayName = 'NutCascader'
9 changes: 5 additions & 4 deletions src/packages/cascader/cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ const InternalCascader: ForwardRefRenderFunction<
closeIconPosition,
closeIcon,
lazy,
title,
left,
onLoad,
onClose,
onChange,
Expand All @@ -123,7 +125,7 @@ const InternalCascader: ForwardRefRenderFunction<
finalValue: defaultValue,
})
const [innerVisible, setInnerVisible] = usePropsValue<boolean>({
value: props.visible,
value: visible,
defaultValue: undefined,
finalValue: false,
})
Expand Down Expand Up @@ -479,8 +481,8 @@ const InternalCascader: ForwardRefRenderFunction<
closeIcon={closeIcon}
closeable={closeable}
closeIconPosition={closeIconPosition}
title={popup && (props.title as ReactNode)}
left={props.left}
title={popup && (title as ReactNode)}
left={left}
// todo 只关闭,不处理逻辑。和popup的逻辑不一致。关闭时需要增加是否要处理回调
onOverlayClick={closePopup}
onCloseIconClick={closePopup}
Expand All @@ -496,5 +498,4 @@ const InternalCascader: ForwardRefRenderFunction<

export const Cascader = React.forwardRef(InternalCascader)

Cascader.defaultProps = defaultProps
Cascader.displayName = 'NutCascader'
5 changes: 2 additions & 3 deletions src/packages/checkbox/checkbox.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export const Checkbox: FunctionComponent<
const ctx = useContext(Context)

let [innerChecked, setChecked] = usePropsValue<boolean>({
value: props.checked,
defaultValue: props.defaultChecked,
value: checked,
defaultValue: defaultChecked,
finalValue: defaultChecked,
onChange,
})
Expand Down Expand Up @@ -230,6 +230,5 @@ export const Checkbox: FunctionComponent<
)
}

Checkbox.defaultProps = defaultProps
Checkbox.displayName = 'NutCheckBox'
Checkbox.Group = CheckboxGroup
5 changes: 2 additions & 3 deletions src/packages/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const Checkbox: FunctionComponent<
const ctx = useContext(Context)

let [innerChecked, setChecked] = usePropsValue<boolean>({
value: props.checked,
defaultValue: props.defaultChecked,
value: checked,
defaultValue: defaultChecked,
finalValue: defaultChecked,
onChange,
})
Expand Down Expand Up @@ -229,6 +229,5 @@ export const Checkbox: FunctionComponent<
)
}

Checkbox.defaultProps = defaultProps
Checkbox.displayName = 'NutCheckBox'
Checkbox.Group = CheckboxGroup
14 changes: 6 additions & 8 deletions src/packages/circleprogress/circleprogress.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ export const CircleProgress: FunctionComponent<
}, [percent])

const stop = () => {
if (!isObject(props.color)) {
if (!isObject(color)) {
return []
}
const color = props.color as Color
const colorArr = Object.keys(color).sort(
(a, b) => parseFloat(a) - parseFloat(b)
)
Expand Down Expand Up @@ -126,17 +125,17 @@ export const CircleProgress: FunctionComponent<
const progress = +oldValue.current
const offset =
(perimeter * Number(format(parseFloat(progress.toFixed(1))))) / 100
const isWise = props.clockwise ? 1 : 0
const color = isObject(props.color)
const isWise = clockwise ? 1 : 0
const realColor = isObject(color)
? `url(%23${refRandomId})`
: transColor(props.color)
: transColor(color)
const d = `M 50 50 m 0 -45 a 45 45 0 1 ${isWise} 0 90 a 45 45 0 1, ${isWise} 0 -90`
const pa = `%3Cdefs%3E%3ClinearGradient id='${refRandomId}' x1='100%25' y1='0%25' x2='0%25' y2='0%25'%3E${stopDom}%3C/linearGradient%3E%3C/defs%3E`
const path = `%3Cpath d='${d}' stroke-width='${strokeWidth}' stroke='${transColor(
props.background
background
)}' fill='none'/%3E`
const path1 = `%3Cpath d='${d}' stroke-width='${strokeWidth}' stroke-dasharray='${offset},${perimeter}' stroke-linecap='round' stroke='${transColor(
color
realColor
)}' fill='none'/%3E`
return {
background: `url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E${pa}${path}${path1}%3C/svg%3E")`,
Expand All @@ -153,5 +152,4 @@ export const CircleProgress: FunctionComponent<
)
}

CircleProgress.defaultProps = defaultProps
CircleProgress.displayName = 'NutCircleProgress'
4 changes: 1 addition & 3 deletions src/packages/circleprogress/circleprogress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ export const CircleProgress: FunctionComponent<
}

const stop = () => {
if (!isObject(props.color)) {
if (!isObject(color)) {
return
}
const color = props.color as Color
const colorArr = Object.keys(color).sort(
(a, b) => parseFloat(a) - parseFloat(b)
)
Expand Down Expand Up @@ -129,5 +128,4 @@ export const CircleProgress: FunctionComponent<
)
}

CircleProgress.defaultProps = defaultProps
CircleProgress.displayName = 'NutCircleProgress'
1 change: 0 additions & 1 deletion src/packages/collapse/collapse.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,5 @@ export const Collapse: FunctionComponent<Partial<CollapseProps>> & {
)
}

Collapse.defaultProps = defaultProps
Collapse.displayName = 'NutCollapse'
Collapse.Item = CollapseItem
Loading

0 comments on commit d4c0049

Please sign in to comment.