Skip to content

Commit e7e758a

Browse files
committed
feat: support showTotal
1 parent e88b0a5 commit e7e758a

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class App extends React.Component<any, any> {
8080
| disableMouseZoom | boolean | false | whether disable mouse zoom | false |
8181
| downloadInNewWindow | boolean | false | whether to download in a new window | false |
8282
| className | string | - | customized CSS class | false |
83+
| showTotal | boolean | true | whether to display the total number and range | false |
8384

8485
### ImageDecorator
8586

src/ViewerCore.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export default (props: ViewerProps) => {
7070
downloadable = false,
7171
noImgDetails = false,
7272
noToolbar = false,
73+
showTotal = true,
7374
} = props;
7475

7576
const initialState: ViewerCoreState = {
@@ -688,6 +689,9 @@ export default (props: ViewerProps) => {
688689
downloadable={downloadable}
689690
noImgDetails={noImgDetails}
690691
toolbars={customToolbar(defaultToolbars)}
692+
activeIndex={state.activeIndex}
693+
count={images.length}
694+
showTotal={showTotal}
691695
/>
692696
)}
693697
{props.noNavbar || (

src/ViewerProps.ts

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ interface ViewerProps {
105105
downloadInNewWindow?: boolean;
106106

107107
className?: string;
108+
109+
// whether to display the total number and range
110+
showTotal?: boolean;
108111
}
109112

110113
export default ViewerProps;

src/ViewerToolbar.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export interface ViewerToolbarProps {
1616
downloadable: boolean;
1717
noImgDetails: boolean;
1818
toolbars: ToolbarConfig[];
19+
activeIndex: number;
20+
count: number;
21+
showTotal: boolean;
1922
}
2023

2124
export const defaultToolbars: ToolbarConfig[] = [
@@ -99,6 +102,8 @@ export default function ViewerToolbar(props: ViewerToolbarProps) {
99102
{props.noImgDetails || <span className={`${props.prefixCls}-img-details`}>
100103
{`(${props.width} x ${props.height})`}
101104
</span>}
105+
{props.showTotal
106+
&& <span className={`${props.prefixCls}-showTotal`}>{`${props.activeIndex + 1} of ${props.count}`}</span>}
102107
</p>
103108
) : null;
104109
let toolbars = props.toolbars;

src/__tests__/viewer.test.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -739,4 +739,15 @@ describe('Viewer', () => {
739739

740740
expect($$('.my-react-viewer')).toHaveLength(1);
741741
});
742+
743+
it('showTotal', () => {
744+
viewerHelper.new({
745+
className: 'my-react-viewer',
746+
});
747+
viewerHelper.open();
748+
749+
expect($$('.react-viewer-showTotal')[0].innerHTML).toBe('1 of 2');
750+
triggerKeyboard(document, 'keydown', 39);
751+
expect($$('.react-viewer-showTotal')[0].innerHTML).toBe('2 of 2');
752+
});
742753
});

src/style/index.less

+5-1
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,17 @@
112112
}
113113

114114
&-attribute {
115-
margin: 0;
115+
margin: 0 20px;
116116
margin-bottom: 6px;
117117
opacity: .8;
118118
color: #ccc;
119119
font-size: 15px;
120120
}
121121

122+
&-showTotal {
123+
float: right;
124+
}
125+
122126
@toolbarHeight: 28px;
123127

124128
&-toolbar {

0 commit comments

Comments
 (0)