Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(controls): Create new rotate control + add to image viewer #1286

Merged
merged 1 commit into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
);
}
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