Skip to content

Commit

Permalink
feat(controls): Create new rotate control + add to image viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
cweeii committed Nov 6, 2020
1 parent e8ec68a commit 3c3634f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/lib/viewers/controls/rotate/RotateControl.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import '../styles';

.bp-RotateControl {
@include bp-ControlButton;
}
15 changes: 15 additions & 0 deletions src/lib/viewers/controls/rotate/RotateControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import IconRotate24 from '../icons/IconRotate24';
import './RotateControl.scss';

export type Props = {
onRotateLeft: () => void;
};

export default function RotateControl({ onRotateLeft }: Props): JSX.Element {
return (
<button className="bp-RotateControl" onClick={onRotateLeft} title={__('rotate_left')} type="button">
<IconRotate24 />
</button>
);
}
28 changes: 28 additions & 0 deletions src/lib/viewers/controls/rotate/__tests__/RotateControl-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import IconRotate24 from '../../icons/IconRotate24';
import RotateControl from '../RotateControl';

describe('RotateControl', () => {
const getWrapper = (props = {}): ShallowWrapper => shallow(<RotateControl onRotateLeft={jest.fn()} {...props} />);

describe('event handlers', () => {
test('should invoke onRotateLeft prop on click', () => {
const onRotateLeft = jest.fn();
const wrapper = getWrapper({ onRotateLeft });

wrapper.simulate('click');

expect(onRotateLeft).toHaveBeenCalled();
});
});

describe('render', () => {
test('should return a valid wrapper', () => {
const wrapper = getWrapper();

expect(wrapper.hasClass('bp-RotateControl')).toBe(true);
expect(wrapper.exists(IconRotate24)).toBe(true);
});
});
});
2 changes: 2 additions & 0 deletions src/lib/viewers/controls/rotate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './RotateControl';
export { default } from './RotateControl';
13 changes: 10 additions & 3 deletions src/lib/viewers/image/ImageControls.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import React from 'react';
import ControlsBar from '../controls/controls-bar';
import FullscreenToggle, { Props as FullscreenToggleProps } from '../controls/fullscreen';
import RotateControl, { Props as RotateControlProps } from '../controls/rotate';
import ZoomControls, { Props as ZoomControlsProps } from '../controls/zoom';

export type Props = FullscreenToggleProps & ZoomControlsProps;
export type Props = FullscreenToggleProps & RotateControlProps & ZoomControlsProps;

export default function ImageControls({ onFullscreenToggle, onZoomIn, onZoomOut, scale }: Props): JSX.Element {
export default function ImageControls({
onFullscreenToggle,
onRotateLeft,
onZoomIn,
onZoomOut,
scale,
}: Props): JSX.Element {
return (
<ControlsBar>
<ZoomControls onZoomIn={onZoomIn} onZoomOut={onZoomOut} scale={scale} />
{/* TODO: RotateControl */}
<RotateControl onRotateLeft={onRotateLeft} />
<FullscreenToggle onFullscreenToggle={onFullscreenToggle} />
{/* TODO: AnnotationControls (separate group) */}
</ControlsBar>
Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/image/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class ImageViewer extends ImageBaseViewer {
this.controls.render(
<ImageControls
onFullscreenToggle={this.toggleFullscreen}
onRotateLeft={this.rotateLeft}
onZoomIn={this.zoomIn}
onZoomOut={this.zoomOut}
scale={this.scale}
Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ describe('lib/viewers/image/ImageViewer', () => {
expect(image.controls.render).toBeCalledWith(
<ImageControls
onFullscreenToggle={image.toggleFullscreen}
onRotateLeft={image.rotateLeft}
onZoomIn={image.zoomIn}
onZoomOut={image.zoomOut}
scale={1}
Expand Down

0 comments on commit 3c3634f

Please sign in to comment.