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

update(RotateControls, ZoomControls): Add icon size prop #381

Merged
merged 2 commits into from
Jul 1, 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
8 changes: 5 additions & 3 deletions packages/core/src/components/ImageViewer/RotateControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export type RotateControlsProps = {
rotation?: number;
/** Callback when rotation changes */
onRotation: (rotation: number) => void;
/** Size of the icons. */
iconSize?: number | string;
};

/** Rotate controls that can be used with an image viewer component */
export default function RotateControls(props: RotateControlsProps) {
const { onRotation, rotation = 0 } = props;
const { onRotation, rotation = 0, iconSize = '2em' } = props;

const handleRotateLeft = useCallback(() => onRotation(rotation - 90 < 0 ? 270 : rotation - 90), [
onRotation,
Expand All @@ -33,14 +35,14 @@ export default function RotateControls(props: RotateControlsProps) {
'lunar.image.rotateCounterClockwise',
'Rotate counter clockwise',
)}
size="2em"
size={iconSize}
/>
</IconButton>

<IconButton onClick={handleRotateRight}>
<IconRotateRight
accessibilityLabel={T.phrase('lunar.image.rotateClockwise', 'Rotate clockwise')}
size="2em"
size={iconSize}
/>
</IconButton>
</ButtonGroup>
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/components/ImageViewer/ZoomControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export type ZoomControlsProps = {
scale?: number;
/** Callback when scale / zoom changes */
onScale: (scale: number) => void;
/** Size of the icons. */
iconSize?: number | string;
/** Custom style sheet. */
styleSheet?: StyleSheet;
};
Expand All @@ -50,7 +52,7 @@ export type ZoomControlsProps = {
export default function ZoomControls({ styleSheet, ...props }: ZoomControlsProps) {
const [styles, cx] = useStyles(styleSheet ?? styleSheetZoomControls);
const [visible, setVisible] = useState(false);
const { onScale, scale = 1 } = props;
const { onScale, scale = 1, iconSize = '2em' } = props;

const zoomOptions = ZOOM_OPTIONS.map((zoom: { label: string; scale: number }) => ({
...zoom,
Expand All @@ -71,15 +73,18 @@ export default function ZoomControls({ styleSheet, ...props }: ZoomControlsProps
<div className={cx(styles.controls)}>
<ButtonGroup>
<IconButton disabled={scale === 1} onClick={handleZoomOut}>
<IconRemove accessibilityLabel={T.phrase('lunar.image.zoomOut', 'Zoom out')} size="2em" />
<IconRemove
accessibilityLabel={T.phrase('lunar.image.zoomOut', 'Zoom out')}
size={iconSize}
/>
</IconButton>

<Button borderless onClick={toggleZoomMenu}>
{scale * 100}%
</Button>

<IconButton onClick={handleZoomIn}>
<IconAdd accessibilityLabel={T.phrase('lunar.image.zoomIn', 'Zoom in')} size="2em" />
<IconAdd accessibilityLabel={T.phrase('lunar.image.zoomIn', 'Zoom in')} size={iconSize} />
</IconButton>
</ButtonGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('<RotateControls />', () => {
const rotateSpy = jest.fn();
const props = {
onRotation: rotateSpy,
iconSize: '1em',
};
let wrapper: Enzyme.ShallowWrapper<RotateControlsProps>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('<ZoomControls />', () => {
const props = {
onScale: setScaleSpy,
scale: 1,
iconSize: '1em',
};

describe('zoom buttons', () => {
Expand Down