-
Notifications
You must be signed in to change notification settings - Fork 93
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
feat: add previous and next toggle to toolbar #320
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
src/Preview.tsx
Outdated
onSwitchLeft?: () => void; | ||
onSwitchRight?: () => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onSwitchPrev
onSwitchNext
这样好点
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OTP 里叫 onActive,感觉可以复用这个名字?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好,保持统一
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
前一个、后一个跟 active 语义上应该是没有关系的,我觉得 onSwitchPrev、onSwitchNext 好点
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #320 +/- ##
=======================================
Coverage 99.78% 99.78%
=======================================
Files 15 15
Lines 457 469 +12
Branches 128 134 +6
=======================================
+ Hits 456 468 +12
Misses 1 1 ☔ View full report in Codecov by Sentry. |
onSwitchPrev
and onSwitchNext
to toolbar
onSwitchPrev
and onSwitchNext
to toolbaronSwitchPrev
and onSwitchNext
to toolbar
onSwitchPrev
and onSwitchNext
to toolbaronActivePrev
and onActiveNext
to toolbar
README.md
Outdated
@@ -180,6 +182,8 @@ type TransformAction = | |||
zoomInIcon: React.ReactNode; | |||
}; | |||
actions: { | |||
onActivePrev?: () => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type OnActive = (offset: number) -> void;
不需要前后,一个就够了。提供 offset 作为偏移量。这样如果是未来一次性翻10个也是同一个 API
5d89bcf
to
4a36f82
Compare
|
onActivePrev
and onActiveNext
to toolbar
src/common.ts
Outdated
@@ -11,3 +11,7 @@ export const COMMON_PROPS: (keyof Omit<ImageElementProps, 'src'>)[] = [ | |||
'useMap', | |||
'alt', | |||
]; | |||
|
|||
export const DEFAULT_PREV_OFFSET = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没必要抽常量,徒增 bundle size 哈~~
src/Preview.tsx
Outdated
setEnableTransition(false); | ||
resetTransform('next'); | ||
onChange?.(current + 1, current); | ||
if (!Number.isInteger(offset) || offset === 0 || position < 0 || position > count - 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个时序看起来有问题,上面已经拿 offset 做计算了,下面再判断 offset 没什么必要。只要看 position 是否是合法的在范围内即可
src/Operations.tsx
Outdated
|
||
const toolsNodeMap = new Map<ToolType, React.ReactNode>() | ||
|
||
const toolsNode = tools.map(({ icon, onClick, type, disabled }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要遍历生成,直接搞个 renderOperation
方法就行了。以前的 tools
搞个数组看起来也没什么必要。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没太明白,看看是这个意思不
c9dcc70
to
c080730
Compare
c080730
to
b6c0b89
Compare
ref: ant-design/ant-design#47948