Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/sites/demos/apis/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ export default {
pcDemo: 'close-loop',
mfDemo: ''
},
{
name: 'disabled',
type: 'boolean',
defaultValue: 'false',
desc: {
'zh-CN': '控制轮播箭头禁用状态,设置为 true 则禁用',
'en-US': 'Control the disabled state of the carousel arrow, set to true to disable'
},
meta: {
stable: '3.19.0'
},
mode: ['pc'],
pcDemo: 'close-loop',
mfDemo: ''
},
{
name: 'show-title',
type: 'boolean',
Expand Down
109 changes: 102 additions & 7 deletions examples/sites/demos/pc/app/carousel/card-show-composition-api.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<template>
<tiny-carousel height="300px" arrow="always" indicator-position="outside">
<tiny-carousel arrow="never" height="300px" indicator-position="none" ref="carouselRef" :initial-index="index - 1">
<div class="btn-layout">
<div>
<tiny-button type="text" @click="prev" :disabled="disabledLeft" :icon="TinyIconChevronLeft"> </tiny-button>
</div>
<div>
<tiny-button type="text" @click="next" :disabled="disabledRight" :icon="TinyIconChevronRight"></tiny-button>
</div>
</div>
<tiny-carousel-item class="carousel-item-demo" v-for="(item, pos) in state.cardData" :key="item">
<template #default>
<div v-for="num in state.cardData.length" :key="num">
<div class="card-layout" v-for="num in state.cardData.length" :key="num">
<div v-if="num === pos + 1" :class="['card-dsp']">
<tiny-card
v-for="(child, childIndex) in item.children"
Expand All @@ -23,10 +31,23 @@
</template>

<script setup>
import { ref, reactive } from 'vue'
import { Carousel as TinyCarousel, CarouselItem as TinyCarouselItem, Card as TinyCard } from '@opentiny/vue'
import { ref, reactive, onMounted } from 'vue'
import {
Carousel as TinyCarousel,
CarouselItem as TinyCarouselItem,
Card as TinyCard,
Button as TinyButton
} from '@opentiny/vue'
import { IconChevronRight, IconChevronLeft } from '@opentiny/vue-icon'

const TinyIconChevronRight = IconChevronRight()
const TinyIconChevronLeft = IconChevronLeft()

let curIndex = ref(0)
const index = ref(1)
let disabledLeft = ref(false)
let disabledRight = ref(false)
const carouselRef = ref()
const dsj = ref(`${import.meta.env.VITE_APP_BUILD_BASE_URL}static/images/dsj.png`)
const userHead = ref(`${import.meta.env.VITE_APP_BUILD_BASE_URL}static/images/user-head.png`)
const state = reactive({
Expand Down Expand Up @@ -78,25 +99,99 @@ const state = reactive({
cardType: 'logo',
cardSrc: `${userHead.value}`,
content: '1-3-content'
},
{
cardTitle: '2-4',
cardType: 'logo',
cardSrc: `${userHead.value}`,
content: '2-4-content'
}
]
}
]
})

onMounted(() => {
disableStatus()
})

const next = () => {
index.value = Math.min(index.value + 1, 8)
carouselRef.value.next()
disableStatus()
}

const prev = () => {
index.value = Math.max(index.value - 1, 0)
carouselRef.value.prev()
disableStatus()
}

const disableStatus = () => {
disabledRight.value = false
disabledLeft.value = false
if (index.value === 1) {
disabledLeft.value = true
disabledRight.value = false
}
if (index.value === state.cardData.length) {
disabledRight.value = true
disabledLeft.value = false
}
}
</script>

<style scoped>
<style lang="less" scoped>
.carousel-item-demo {
display: flex;
justify-content: center;
}
.card-dsp {
display: flex;
justify-content: flex-start;
padding: 0 4px 0 12px;
align-items: center;
height: 100%;
}
.mb {
margin-bottom: 20px;
}
.card-demo {
width: 25%;
height: 300px;
margin-right: 8px;
height: 200px;
&:last-child {
margin-right: 0;
}
&:hover {
border-color: #1476ff;
}
}
.btn-layout {
position: relative;
display: flex;
justify-content: space-between;
top: 45%;
z-index: 10;
padding: 0 76px;
}
/deep/ .tiny-button.tiny-button--text.tiny-button.is-only-icon {
font-size: 16px;
border: none;
.tiny-svg {
fill: #808080;
}
&.is-disabled {
.tiny-svg {
fill: #c2c2c2;
}
}
&:hover {
background-color: transparent;
}
&:not(.is-disabled) {
.tiny-svg:hover {
fill: #191919;
}
}
}
</style>
10 changes: 3 additions & 7 deletions examples/sites/demos/pc/app/carousel/card-show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ test('轮播卡片', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('carousel#card-show')
const preview = page.locator('#card-show')
await preview
.locator('div')
.filter({ hasText: /^1-11-1-content$/ })
.first()
.click()
await preview.getByRole('button').nth(1).click()
const btnRight = preview.getByRole('button').nth(1)
await btnRight.click()
await preview
.locator('div')
.filter({ hasText: /^2-11-1-content$/ })
.first()
.click()
expect(btnRight).toHaveCSS('fill', 'rgb(194, 194, 194)')
})
101 changes: 94 additions & 7 deletions examples/sites/demos/pc/app/carousel/card-show.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<template>
<tiny-carousel height="300px" arrow="always" indicator-position="outside">
<tiny-carousel arrow="never" height="300px" indicator-position="none" ref="carouselRef" :initial-index="index - 1">
<div class="btn-layout">
<div>
<tiny-button type="text" @click="prev" :disabled="disabledLeft" :icon="TinyIconChevronLeft"> </tiny-button>
</div>
<div>
<tiny-button type="text" @click="next" :disabled="disabledRight" :icon="TinyIconChevronRight"></tiny-button>
</div>
</div>
<tiny-carousel-item class="carousel-item-demo" v-for="(item, pos) in cardData" :key="item">
<template #default>
<div v-for="num in cardData.length" :key="num">
<div class="card-layout" v-for="num in cardData.length" :key="num">
<div v-if="num === pos + 1" :class="['card-dsp']">
<tiny-card
v-for="(child, childIndex) in item.children"
Expand All @@ -23,17 +31,24 @@
</template>

<script>
import { Carousel, CarouselItem, Card } from '@opentiny/vue'
import { Carousel, CarouselItem, Card, Button } from '@opentiny/vue'
import { IconChevronRight, IconChevronLeft } from '@opentiny/vue-icon'

export default {
components: {
TinyCarousel: Carousel,
TinyCarouselItem: CarouselItem,
TinyCard: Card
TinyCard: Card,
TinyButton: Button
},
data() {
return {
TinyIconChevronRight: IconChevronRight(),
TinyIconChevronLeft: IconChevronLeft(),
curIndex: 0,
index: 1,
disabledLeft: false,
disabledRight: false,
cardData: [
{
children: [
Expand Down Expand Up @@ -82,27 +97,99 @@ export default {
cardType: 'logo',
cardSrc: `/static/images/user-head.png`,
content: '1-3-content'
},
{
cardTitle: '2-4',
cardType: 'logo',
cardSrc: `/static/images/user-head.png`,
content: '2-4-content'
}
]
}
]
}
},
mounted() {
this.disableStatus()
},
methods: {
next() {
this.index = Math.min(this.index + 1, 8)
this.$refs.carouselRef.next()
this.disableStatus()
},
prev() {
this.index = Math.max(this.index - 1, 0)
this.$refs.carouselRef.prev()
this.disableStatus()
},
disableStatus() {
this.disabledRight = false
this.disabledLeft = false
if (this.index === 1) {
this.disabledLeft = true
this.disabledRight = false
}
if (this.index === this.cardData.length) {
this.disabledRight = true
this.disabledLeft = false
}
}
}
}
</script>

<style scoped>
<style lang="less" scoped>
.carousel-item-demo {
display: flex;
justify-content: center;
}
.card-dsp {
display: flex;
justify-content: flex-start;
padding: 0 4px 0 12px;
align-items: center;
height: 100%;
}
.mb {
margin-bottom: 20px;
}
.card-demo {
width: 25%;
height: 300px;
margin-right: 8px;
height: 200px;
&:last-child {
margin-right: 0;
}
&:hover {
border-color: #1476ff;
}
}
.btn-layout {
position: relative;
display: flex;
justify-content: space-between;
top: 45%;
z-index: 10;
padding: 0 76px;
}
/deep/ .tiny-button.tiny-button--text.tiny-button.is-only-icon {
font-size: 16px;
border: none;
.tiny-svg {
fill: #808080;
}
&.is-disabled {
.tiny-svg {
fill: #c2c2c2;
}
}
&:hover {
background-color: transparent;
}
&:not(.is-disabled) {
.tiny-svg:hover {
fill: #191919;
}
}
}
</style>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<tiny-carousel height="150px" :loop="false" arrow="always">
<tiny-carousel height="150px" loop :disabled="true" arrow="always">
<tiny-carousel-item class="carousel-item-demo" v-for="item in 3" :key="item">
<h3>{{ item }}</h3>
</tiny-carousel-item>
Expand Down
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/app/carousel/close-loop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('关闭循环轮播', async ({ page }) => {
const arrow = carousel.locator('.tiny-carousel__arrow')

// 左侧切换按钮应该不可见
await expect(arrow.first()).not.toBeVisible()
await expect(arrow.first()).toBeVisible()
// 点击下一张按钮
await arrow.nth(1).click()
// 当前应该显示第二张幻灯片
Expand All @@ -18,7 +18,7 @@ test('关闭循环轮播', async ({ page }) => {
// 当前应该显示第三张幻灯片
await expect(carouselItems.nth(2)).toHaveCSS('transform', 'matrix(1, 0, 0, 1, 0, 0)')
// 右侧切换按钮应该不可见
await expect(arrow.nth(1)).not.toBeVisible()
await expect(arrow.nth(1)).toBeVisible()
// 点击上一张按钮
await arrow.first().click()
// 当前应该显示第一张幻灯片
Expand Down
2 changes: 1 addition & 1 deletion examples/sites/demos/pc/app/carousel/close-loop.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<tiny-carousel height="150px" :loop="false" arrow="always">
<tiny-carousel height="150px" loop :disabled="true" arrow="always">
<tiny-carousel-item class="carousel-item-demo" v-for="item in 3" :key="item">
<h3>{{ item }}</h3>
</tiny-carousel-item>
Expand Down
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/app/carousel/webdoc/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export default {
},
desc: {
'zh-CN':
'<p>通过配置 <code>loop</code> 属性为<code>false</code>后,若走马灯幻灯片已切换到最后一项,则将不能再从第一项开始循环切换。即切换到最后一项时,右侧切换箭头不再显示,切换到第一项时,左侧切换箭头不再显示。</p>\n',
'<p>通过配置 <code>loop</code> 属性为<code>true</code>,<code>disabled</code> 属性为<code>true</code>后,若走马灯幻灯片已切换到最后一项,则将不能再从第一项开始循环切换。即切换到最后一项时,右侧切换箭头不再显示,切换到第一项时,左侧切换箭头不再显示。</p>\n',
'en-US':
'<p>After the <code>loop</code> attribute is set to <code>false</code>, if the slide is switched to the last item, the slide cannot be switched cyclically from the first item. That is, when switching to the last item, the right toggle arrow is no longer displayed, and when switching to the first item, the left toggle arrow is no longer displayed. </p>\n'
'<p>After the <code>loop</code> attribute is set to <code>true</code> and the <code>disabled</code> attribute is set to <code>true</code> if the slide is switched to the last item, the slide cannot be switched cyclically from the first item. That is, when switching to the last item, the right toggle arrow is no longer displayed, and when switching to the first item, the left toggle arrow is no longer displayed. </p>\n'
},
codeFiles: ['close-loop.vue']
},
Expand Down
Loading