Skip to content

Commit

Permalink
feat: Swiper 组件增加指示器的默认背景色配置 (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyatong authored Dec 23, 2022
1 parent a46b48f commit d33c6a3
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 39 deletions.
2 changes: 2 additions & 0 deletions src/packages/swiper/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const SwiperDemo = () => {
const swiperRef = React.useRef<any>(null)
const [height, setHeight] = useState<any>(150)
const [paginationColor, setPaginationColor] = useState<string>('#426543')
const [paginationBgColor, setPaginationBgColor] = useState<string>('#426ddd')
const [initPage1, setInitPage1] = useState<any>(0)
const [initPage2, setInitPage2] = useState<any>(0)
const [initPage3, setInitPage3] = useState<any>(0)
Expand Down Expand Up @@ -91,6 +92,7 @@ const SwiperDemo = () => {
<Swiper
height={height}
paginationColor={paginationColor}
paginationBgColor={paginationBgColor}
autoPlay="2000"
initPage={initPage1}
onChange={onChange}
Expand Down
2 changes: 2 additions & 0 deletions src/packages/swiper/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const SwiperDemo = () => {
const swiperRef = React.useRef<any>(null)
const [height, setHeight] = useState<any>(150)
const [paginationColor, setPaginationColor] = useState<string>('#426543')
const [paginationBgColor, setPaginationBgColor] = useState<string>('#426ddd')
const [initPage1, setInitPage1] = useState<any>(0)
const [initPage2, setInitPage2] = useState<any>(0)
const [initPage3, setInitPage3] = useState<any>(0)
Expand Down Expand Up @@ -93,6 +94,7 @@ const SwiperDemo = () => {
<Swiper
height={height}
paginationColor={paginationColor}
paginationBgColor={paginationBgColor}
autoPlay="2000"
initPage={initPage1}
onChange={onChange}
Expand Down
4 changes: 3 additions & 1 deletion src/packages/swiper/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { Swiper,SwiperItem } from '@nutui/nutui-react';
import { Swiper,SwiperItem } from '@nutui/nutui-react-taro';
```


### Basic Usage

`autoPlay` Duration of automatic rotation
`initPage` Initial index value
`paginationVisible` Show paging indicator
`paginationColor` Indicator color customization
`paginationBgColor` Indicator backgroundColor customization
`onChange` When the card changes

:::demo
Expand All @@ -38,6 +38,7 @@ const App = () => {
<Swiper
height={height}
paginationColor="#426543"
paginationBgColor='#426ddd'
autoPlay="3000"
initPage={initPage1}
paginationVisible
Expand Down Expand Up @@ -474,6 +475,7 @@ export default App;
| direction | Rotation direction, optional value:`horizontal`,`vertical` | String | 'horizontal' |
| paginationVisible | Whether the pagination indicator is displayed | Boolean | false |
| paginationColor | Pagination indicator selected color | String | '#fff' |
| paginationBgColor`v1.4.1` | Pagination indicator backgroundcolor | String | '#ddd' |
| loop | Whether to rotate | Boolean | true |
| duration | Animation duration(Unit ms | Number \| String | 500 |
| autoPlay | Automatic rotation duration, 0 means no automatic | Number \| String | 0 |
Expand Down
8 changes: 4 additions & 4 deletions src/packages/swiper/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import { Swiper,SwiperItem } from '@nutui/nutui-react';
import { Swiper,SwiperItem } from '@nutui/nutui-react-taro';
```

## 代码演示

### 基础用法

`autoPlay` 自动轮播的时长
`initPage` 初始索引值
`paginationVisible` 是否显示分页指示器
`paginationColor` 指示器颜色自定义
`paginationBgColor` 指示器背景颜色自定义
`onChange` 当卡片发生变化

:::demo
Expand All @@ -39,6 +38,7 @@ const App = () => {
<Swiper
height={height}
paginationColor="#426543"
paginationBgColor='#426ddd'
autoPlay="3000"
initPage={initPage1}
paginationVisible
Expand Down Expand Up @@ -475,6 +475,7 @@ export default App;
| direction | 轮播方向,可选值`horizontal`,`vertical` | String | 'horizontal' |
| paginationVisible | 分页指示器是否展示 | Boolean | false |
| paginationColor | 分页指示器选中的颜色 | String | '#fff' |
| paginationBgColor`v1.4.1` | 分页指示器的背景色 | String | '#ddd' |
| loop | 是否循环轮播 | Boolean | true |
| duration | 动画时长(单位是ms) | Number \| String | 500 |
| autoPlay | 自动轮播时长,0表示不会自动轮播 | Number \| String | 0 |
Expand All @@ -483,7 +484,7 @@ export default App;
| pageContent | 自定义指示器 | String \| React.ReactNode | - |
| isPreventDefault | 滑动过程中是否禁用默认事件 | Boolean | true |
| isStopPropagation | 滑动过程中是否禁止冒泡 | Boolean | true |
| isCenter`v1.3.0` | 是否居中展示,必须传对应的`width``height` | Boolean | false |
| isCenter`v1.3.0` | 是否居中展示,必须传对应的`width``height` | Boolean | false |



Expand All @@ -494,7 +495,6 @@ export default App;
| onChange | 卡片切换后的回调 | 当前索引值index |



### API

| 事件名 | 说明 | 参数 |
Expand Down
42 changes: 23 additions & 19 deletions src/packages/swiper/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import { Swiper,SwiperItem } from '@nutui/nutui-react';
import { Swiper,SwiperItem } from '@nutui/nutui-react-taro';
```

## 代码演示

### 基础用法

`autoPlay` 自动轮播的时长
`initPage` 初始索引值
`paginationVisible` 是否显示分页指示器
`paginationColor` 指示器颜色自定义
`paginationBgColor` 指示器背景颜色自定义
`onChange` 当卡片发生变化

:::demo
Expand All @@ -35,9 +34,11 @@ const App = () => {
// do something
}
return (
<div className="demo-box" style={{ height: 150 }}>
<Swiper
height={height}
paginationColor="#426543"
paginationBgColor='#426ddd'
autoPlay="3000"
initPage={initPage1}
paginationVisible
Expand All @@ -56,6 +57,7 @@ const App = () => {
<img src="https://storage.360buyimg.com/jdc-article/fristfabu.jpg" alt="" />
</SwiperItem>
</Swiper>
</div>
)
}
export default App;
Expand Down Expand Up @@ -84,21 +86,23 @@ const App = () => {
}, 3000)
}, [])
return (
<Swiper
height={height}
paginationColor="#426543"
autoPlay="3000"
initPage={initPage1}
paginationVisible
>
{list.map((item) => {
return (
<SwiperItem key={item}>
<img src={item} alt="" />
</SwiperItem>
)
})}
</Swiper>
<div className="demo-box" style={{ height: 150 }}>
<Swiper
height={height}
paginationColor="#426543"
autoPlay="3000"
initPage={initPage1}
paginationVisible
>
{list.map((item) => {
return (
<SwiperItem key={item}>
<img src={item} alt="" />
</SwiperItem>
)
})}
</Swiper>
</div>
)
}
export default App;
Expand Down Expand Up @@ -463,6 +467,7 @@ export default App;
| direction | 轮播方向,可选值`horizontal`,`vertical` | String | 'horizontal' |
| paginationVisible | 分页指示器是否展示 | Boolean | false |
| paginationColor | 分页指示器选中的颜色 | String | '#fff' |
| paginationBgColor`v1.4.1` | 分页指示器的背景色 | String | '#ddd' |
| loop | 是否循环轮播 | Boolean | true |
| duration | 动画时长(单位是ms) | Number \| String | 500 |
| autoPlay | 自动轮播时长,0表示不会自动轮播 | Number \| String | 0 |
Expand All @@ -471,7 +476,7 @@ export default App;
| pageContent | 自定义指示器 | String \| React.ReactNode | - |
| isPreventDefault | 滑动过程中是否禁用默认事件 | Boolean | true |
| isStopPropagation | 滑动过程中是否禁止冒泡 | Boolean | true |
| isCenter | 是否居中展示,必须传对应的`width``height` | Boolean | false |
| isCenter`v1.3.0` | 是否居中展示,必须传对应的`width``height` | Boolean | false |



Expand All @@ -482,7 +487,6 @@ export default App;
| onChange | 卡片切换后的回调 | 当前索引值index |



### API

| 事件名 | 说明 | 参数 |
Expand Down
3 changes: 0 additions & 3 deletions src/packages/swiper/swiper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
}
}
}
&__pagination-item {
background-color: $swiper-pagination-item-background-color;
}
&__pagination-vertical {
top: 50%;
left: 12px;
Expand Down
13 changes: 8 additions & 5 deletions src/packages/swiper/swiper.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SwiperProps {
autoPlay: number | string
direction: 'horizontal' | 'vertical'
paginationColor: string
paginationBgColor: string
paginationVisible: boolean
loop: boolean
touchable: boolean
Expand All @@ -42,6 +43,7 @@ const defaultProps = {
autoPlay: 0,
direction: 'horizontal',
paginationColor: '#fff',
paginationBgColor: '#ddd',
paginationVisible: false,
loop: true,
touchable: true,
Expand Down Expand Up @@ -415,7 +417,7 @@ export const Swiper = React.forwardRef<

query.select(`#${(element as any).id}`) &&
query.select(`#${(element as any).id}`).boundingClientRect()
query.exec(function (res: any) {
query.exec((res: any) => {
resolve(res[0])
})
})
Expand Down Expand Up @@ -494,7 +496,7 @@ export const Swiper = React.forwardRef<
}))
return (
<DataContext.Provider value={parent}>
<view
<div
className={`${classes} ${className}`}
ref={container}
{...rest}
Expand Down Expand Up @@ -533,10 +535,11 @@ export const Swiper = React.forwardRef<
? {
backgroundColor: propSwiper.paginationColor,
}
: undefined
: {
backgroundColor: propSwiper.paginationBgColor,
}
}
className={classNames({
[`${b('pagination-item')}`]: true,
active: (active + childCount) % childCount === index,
})}
key={index}
Expand All @@ -547,7 +550,7 @@ export const Swiper = React.forwardRef<
) : (
<div>{pageContent}</div>
)}
</view>
</div>
</DataContext.Provider>
)
})
Expand Down
15 changes: 8 additions & 7 deletions src/packages/swiper/swiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SwiperProps {
autoPlay: number | string
direction: 'horizontal' | 'vertical'
paginationColor: string
paginationBgColor: string
paginationVisible: boolean
loop: boolean
touchable: boolean
Expand All @@ -42,6 +43,7 @@ const defaultProps = {
autoPlay: 0,
direction: 'horizontal',
paginationColor: '#fff',
paginationBgColor: '#ddd',
paginationVisible: false,
loop: true,
touchable: true,
Expand Down Expand Up @@ -327,7 +329,6 @@ export const Swiper = React.forwardRef<
})
const getStyle = (moveOffset = offset) => {
const target = innerRef.current

let _offset = 0
if (!isCenter) {
_offset = moveOffset
Expand All @@ -340,10 +341,6 @@ export const Swiper = React.forwardRef<
moveOffset +
(active === childCount - 1 && !props.loop ? -val / 2 : val / 2)
}

target.style.transform = `translate3D${
!isVertical ? `(${_offset}px,0,0)` : `(0,${_offset}px,0)`
}`
target.style.transitionDuration = `${
_swiper.current.moving ? 0 : props.duration
}ms`
Expand All @@ -353,6 +350,9 @@ export const Swiper = React.forwardRef<
target.style[isVertical ? 'width' : 'height'] = `${
isVertical ? width : height
}px`
target.style.transform = `translate3D${
!isVertical ? `(${_offset}px,0,0)` : `(0,${_offset}px,0)`
}`
}

const onTouchStart = (e: TouchEvent) => {
Expand Down Expand Up @@ -518,10 +518,11 @@ export const Swiper = React.forwardRef<
? {
backgroundColor: propSwiper.paginationColor,
}
: undefined
: {
backgroundColor: propSwiper.paginationBgColor,
}
}
className={classNames({
[`${b('pagination-item')}`]: true,
active: (active + childCount) % childCount === index,
})}
key={index}
Expand Down

0 comments on commit d33c6a3

Please sign in to comment.