Skip to content

Commit

Permalink
update(RotateControls, ZoomControls): Add icon size prop (#381)
Browse files Browse the repository at this point in the history
* update(RotateControls, ZoomControls): Add icon size prop

* Change prop name from size to iconSize

Co-authored-by: Alan Chen <alan.chen@airbnb.com>
  • Loading branch information
al-chen and Alan Chen authored Jul 1, 2020
1 parent 49e7c66 commit 79d0866
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
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

0 comments on commit 79d0866

Please sign in to comment.