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

feat(comp:carousel): add carousel component #634

Merged
merged 1 commit into from
Dec 22, 2021

Conversation

brenner8023
Copy link
Member

fix #230

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added/updated or not needed
  • Docs and demo have been added/updated or not needed

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Component style update
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Application (the showcase website) / infrastructure changes
  • Other... Please describe:

What is the current behavior?

add carousel component

What is the new behavior?

IxCarousel

CarouselProps

名称 说明 类型 默认值 全局配置 备注
autoplayTime 控制自动轮播的时间间隔 number 0 值为0时不开启自动轮播
dotPlacement 面板指示点的位置 'top' | 'start' | 'bottom' | 'end' | 'none' 'bottom' 'none'时不显示面板指示点
showArrow 是否显示prevnext按钮 boolean false -
trigger 面板指示点的触发方式 'click' | 'hover' 'click' -
onChange 面板切换时会触发的回调函数 (prevIndex: number, nextIndex: number) => void - - -

CarouselSlots

名称 说明 参数类型 备注
default 面板的内容 - -
dot 面板指示点 activeIndex: number activeIndex表示当前激活的面板索引
arrow 自定义切换按钮 type: 'prev' | 'next' -

CarseouselMethods

名称 说明 参数类型 备注
goTo(slideIndex: number) 切换到指定面板 (slideIndex: number) => void -
next() 切换到下一面板 - -
prev() 切换到上一面板 - -

Other information

@idux-bot
Copy link

idux-bot bot commented Dec 19, 2021

This preview will be available after the AzureCI is passed.

@codecov
Copy link

codecov bot commented Dec 19, 2021

Codecov Report

Merging #634 (8ace65d) into main (4e446fc) will increase coverage by 0.55%.
The diff coverage is 92.70%.

❗ Current head 8ace65d differs from pull request most recent head 29ae7a2. Consider uploading reports for the commit 29ae7a2 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #634      +/-   ##
==========================================
+ Coverage   83.09%   83.64%   +0.55%     
==========================================
  Files         370      393      +23     
  Lines        9338     9849     +511     
  Branches     2154     2268     +114     
==========================================
+ Hits         7759     8238     +479     
- Misses       1579     1611      +32     
Impacted Files Coverage Δ
packages/components/icon/src/dependencies.ts 100.00% <ø> (ø)
...ackages/components/message/src/MessageProvider.tsx 96.66% <ø> (ø)
packages/components/tree/src/types.ts 85.71% <ø> (ø)
packages/components/tree-select/src/types.ts 66.66% <66.66%> (ø)
...ges/components/tree-select/src/content/Content.tsx 73.43% <73.43%> (ø)
...nents/tree-select/src/composables/useDataSource.ts 78.00% <78.00%> (ø)
...nents/tree-select/src/composables/useGetNodeKey.ts 80.00% <80.00%> (ø)
...ckages/components/tree-select/src/trigger/Item.tsx 80.00% <80.00%> (ø)
...kages/components/tree-select/src/trigger/Input.tsx 92.85% <92.85%> (ø)
...ges/components/tree-select/src/trigger/Trigger.tsx 94.59% <94.59%> (ø)
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e446fc...29ae7a2. Read the comment docs.

}

export interface CarouselBindings {
next: () => void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

少了个 goto

packages/components/carousel/style/index.less Outdated Show resolved Hide resolved
@@ -0,0 +1,11 @@
.vertical-center () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.vertical-center () {
.carousel-vertical-center () {

transform: translateY(-50%);
}

.horizontal-center () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.horizontal-center () {
.carousel-horizontal-center () {

Comment on lines 110 to 119
const dot =
slots.dot?.({ activeIndex: activeIndex.value }) ??
Array.from({ length: length.value }).map((_, index: number) => {
const isActive = index + 1 === activeIndex.value
const itemClass = {
[`${prefixCls}-dot-item`]: true,
[`${prefixCls}-dot-item--active`]: isActive,
}
return <div class={itemClass} onClick={() => onClick(index)} onMouseenter={() => onMouseenter(index)}></div>
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const dot =
slots.dot?.({ activeIndex: activeIndex.value }) ??
Array.from({ length: length.value }).map((_, index: number) => {
const isActive = index + 1 === activeIndex.value
const itemClass = {
[`${prefixCls}-dot-item`]: true,
[`${prefixCls}-dot-item--active`]: isActive,
}
return <div class={itemClass} onClick={() => onClick(index)} onMouseenter={() => onMouseenter(index)}></div>
})
const dots = Array.from({ length: length.value }).map((_, index: number) => {
const isActive = index + 1 === activeIndex.value
const itemClass = {
[`${prefixCls}-dot-item`]: true,
[`${prefixCls}-dot-item--active`]: isActive,
}
const children = slots.dot ? slots.dot({index, isActive}) : <button>{index}<button>
return <li class={itemClass} onClick={() => onClick(index)} onMouseenter={() => onMouseenter(index)}>{children}</li>
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个插槽不应该是真对整个区域吧,而就是 dot 的内容? 否则 还得自己加 item 的 class, 比较麻烦。

</div>
</>
)}
{dotPlacement.value !== 'none' && <div class={dotClass.value}>{dot}</div>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{dotPlacement.value !== 'none' && <div class={dotClass.value}>{dot}</div>}
{dotPlacement.value !== 'none' && <ul class={dotClass.value}>{dots}</ul>}

其实我更建议把这个代码拆成一个子组件。

category: components
type: 数据展示
title: Carousel
subtitle: 走马灯(轮播图)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subtitle: 走马灯(轮播图
subtitle: 轮播图

Copy link
Member

@danranVm danranVm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@danranVm danranVm merged commit 4737191 into IDuxFE:main Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[comp:Carousel] feature Carousel component
2 participants