forked from react-component/image
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrevNext.tsx
More file actions
50 lines (46 loc) · 1.12 KB
/
PrevNext.tsx
File metadata and controls
50 lines (46 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { clsx } from 'clsx';
import * as React from 'react';
import type { OperationIcons } from '.';
export interface PrevNextProps {
prefixCls: string;
onActive: (offset: number) => void;
current: number;
count: number;
icons: OperationIcons;
}
export default function PrevNext(props: PrevNextProps) {
const {
prefixCls,
onActive,
current,
count,
icons: { left, right, prev, next },
} = props;
const switchCls = `${prefixCls}-switch`;
return (
<>
<button
type="button"
className={clsx(switchCls, `${switchCls}-prev`, {
[`${switchCls}-disabled`]: current === 0,
})}
onClick={() => onActive(-1)}
disabled={current === 0}
aria-label="Previous image"
>
{prev ?? left}
</button>
<button
type="button"
className={clsx(switchCls, `${switchCls}-next`, {
[`${switchCls}-disabled`]: current === count - 1,
})}
onClick={() => onActive(1)}
disabled={current === count - 1}
aria-label="Next image"
>
{next ?? right}
</button>
</>
);
}