-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
385 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
group: Data Display | ||
title: Slides | ||
--- | ||
|
||
## API | ||
|
||
### DTagProps | ||
|
||
Extend `React.HTMLAttributes<HTMLDivElement>`. | ||
|
||
<!-- prettier-ignore-start --> | ||
| Property | Description | Type | Default | | ||
| --- | --- | --- | --- | | ||
| dType | Set tag type | 'primary' \| 'fill' \| 'outline' | 'primary' | | ||
| dTheme | Set tag theme | 'primary' \| 'success' \| 'warning' \| 'danger' | - | | ||
| dColor | Custom tag color | string | - | | ||
| dSize | Set tag size | 'smaller' \| 'larger' | - | | ||
| dClosable | Whether the tag can be closed | boolean | false | | ||
| onClose | Callback when the close button is clicked | React.MouseEventHandler\<HTMLSpanElement\> | - | | ||
<!-- prettier-ignore-end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: 走马灯 | ||
--- | ||
|
||
## API | ||
|
||
### DTagProps | ||
|
||
继承 `React.HTMLAttributes<HTMLDivElement>`。 | ||
|
||
<!-- prettier-ignore-start --> | ||
| 参数 | 说明 | 类型 | 默认值 | | ||
| --- | --- | --- | --- | | ||
| dType | 设置标签形态 | 'primary' \| 'fill' \| 'outline' | 'primary' | | ||
| dTheme | 设置标签主题 | 'primary' \| 'success' \| 'warning' \| 'danger' | - | | ||
| dColor | 自定义标签颜色 | string | - | | ||
| dSize | 设置标签尺寸 | 'smaller' \| 'larger' | - | | ||
| dClosable | 标签是否可关闭 | boolean | false | | ||
| onClose | 点击关闭按钮的回调 | React.MouseEventHandler\<HTMLSpanElement\> | - | | ||
<!-- prettier-ignore-end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { SwiperSlideProps } from 'swiper/react'; | ||
|
||
import { useComponentConfig } from '../../hooks'; | ||
import { registerComponentMate } from '../../utils'; | ||
|
||
export type DSlideProps = SwiperSlideProps; | ||
|
||
const { COMPONENT_NAME } = registerComponentMate({ COMPONENT_NAME: 'DSlide' }); | ||
export function DSlide(props: DSlideProps): JSX.Element | null { | ||
useComponentConfig(COMPONENT_NAME, props); | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import type { SwiperProps, SwiperSlideProps } from 'swiper/react'; | ||
|
||
import { isUndefined } from 'lodash'; | ||
import React from 'react'; | ||
import { | ||
A11y, | ||
Autoplay, | ||
Controller, | ||
EffectCoverflow, | ||
EffectCube, | ||
EffectFade, | ||
EffectFlip, | ||
EffectCreative, | ||
EffectCards, | ||
HashNavigation, | ||
History, | ||
Keyboard, | ||
Lazy, | ||
Mousewheel, | ||
Navigation, | ||
Pagination, | ||
Parallax, | ||
Scrollbar, | ||
Thumbs, | ||
Virtual, | ||
Zoom, | ||
FreeMode, | ||
Grid, | ||
Manipulation, | ||
} from 'swiper'; | ||
import 'swiper/css/bundle'; | ||
import { Swiper, SwiperSlide } from 'swiper/react'; | ||
|
||
import { useComponentConfig, usePrefixConfig } from '../../hooks'; | ||
import { LeftOutlined, RightOutlined } from '../../icons'; | ||
import { getClassName, registerComponentMate } from '../../utils'; | ||
|
||
export type DSlidesProps = SwiperProps; | ||
|
||
const { COMPONENT_NAME } = registerComponentMate({ COMPONENT_NAME: 'DSlides' }); | ||
export function DSlides(props: DSlidesProps): JSX.Element | null { | ||
const { | ||
children, | ||
|
||
navigation: _navigation, | ||
pagination: _pagination, | ||
direction = 'horizontal', | ||
|
||
className, | ||
...restProps | ||
} = useComponentConfig(COMPONENT_NAME, props); | ||
|
||
//#region Context | ||
const dPrefix = usePrefixConfig(); | ||
//#endregion | ||
|
||
const navigation = (() => { | ||
const configs = { | ||
nextEl: '.swiper-button-next', | ||
prevEl: '.swiper-button-prev', | ||
}; | ||
if (_navigation === true || isUndefined(_navigation)) { | ||
return configs; | ||
} | ||
if (_navigation !== false) { | ||
return Object.assign(configs, _navigation); | ||
} | ||
return _navigation; | ||
})(); | ||
|
||
const pagination = (() => { | ||
const configs = { | ||
clickable: true, | ||
}; | ||
if (_pagination === true || isUndefined(_pagination)) { | ||
return configs; | ||
} | ||
if (_pagination !== false) { | ||
return Object.assign(configs, _pagination); | ||
} | ||
return _pagination; | ||
})(); | ||
|
||
return ( | ||
<Swiper | ||
{...restProps} | ||
className={getClassName(className, `${dPrefix}slides`, { | ||
[`${dPrefix}slides--vertical`]: direction === 'vertical', | ||
})} | ||
direction={direction} | ||
modules={[ | ||
A11y, | ||
Autoplay, | ||
Controller, | ||
EffectCoverflow, | ||
EffectCube, | ||
EffectFade, | ||
EffectFlip, | ||
EffectCreative, | ||
EffectCards, | ||
HashNavigation, | ||
History, | ||
Keyboard, | ||
Lazy, | ||
Mousewheel, | ||
Navigation, | ||
Pagination, | ||
Parallax, | ||
Scrollbar, | ||
Thumbs, | ||
Virtual, | ||
Zoom, | ||
FreeMode, | ||
Grid, | ||
Manipulation, | ||
]} | ||
navigation={navigation} | ||
pagination={pagination} | ||
> | ||
{React.Children.map(children, (child) => | ||
React.isValidElement(child) | ||
? React.createElement(SwiperSlide, { | ||
...(child.props as SwiperSlideProps), | ||
className: getClassName((child.props as SwiperSlideProps).className, `${dPrefix}slide`), | ||
}) | ||
: child | ||
)} | ||
<button className="swiper-button-prev"> | ||
<LeftOutlined /> | ||
</button> | ||
<button className="swiper-button-next"> | ||
<RightOutlined /> | ||
</button> | ||
</Swiper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: | ||
en-US: Basic | ||
zh-Hant: 基本 | ||
--- | ||
|
||
# en-US | ||
|
||
The simplest usage. | ||
|
||
# zh-Hant | ||
|
||
最简单的用法。 | ||
|
||
```tsx | ||
import { DSlides, DSlide } from '@react-devui/ui'; | ||
|
||
export default function Demo() { | ||
return ( | ||
<DSlides style={{ height: 200 }}> | ||
<DSlide> | ||
<div className="app-demo-slide">Slide 1</div> | ||
</DSlide> | ||
<DSlide> | ||
<div className="app-demo-slide">Slide 2</div> | ||
</DSlide> | ||
<DSlide> | ||
<div className="app-demo-slide">Slide 3</div> | ||
</DSlide> | ||
<DSlide> | ||
<div className="app-demo-slide">Slide 4</div> | ||
</DSlide> | ||
</DSlides> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: | ||
en-US: Reference Swiper | ||
zh-Hant: 参考 Swiper | ||
--- | ||
|
||
# en-US | ||
|
||
For more usage, refer to [Swiper](https://swiperjs.com/react). | ||
|
||
# zh-Hant | ||
|
||
更多用法参考 [Swiper](https://swiperjs.com/react)。 | ||
|
||
```tsx | ||
import { DSlides, DSlide } from '@react-devui/ui'; | ||
|
||
export default function Demo() { | ||
return ( | ||
<DSlides | ||
style={{ height: 200 }} | ||
direction={'vertical'} | ||
pagination={{ | ||
dynamicBullets: true, | ||
}} | ||
> | ||
{Array(8) | ||
.fill(0) | ||
.map((n, i) => ( | ||
<DSlide key={i}> | ||
<div className="app-demo-slide">Slide {i}</div> | ||
</DSlide> | ||
))} | ||
</DSlides> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './Slides'; | ||
export * from './Slide'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.