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(ImageViewer): Add dropdownAbove prop #398

Merged
merged 2 commits into from
Aug 26, 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
12 changes: 10 additions & 2 deletions packages/core/src/components/ImageViewer/ZoomControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ export type ZoomControlsProps = {
iconSize?: number | string;
/** Custom style sheet. */
styleSheet?: StyleSheet;
/** Place dropdown menu above */
dropdownAbove?: boolean;
};

/** Zoom controls that can be used with an image viewer component */
export default function ZoomControls({ styleSheet, ...props }: ZoomControlsProps) {
const [styles, cx] = useStyles(styleSheet ?? styleSheetZoomControls);
const [visible, setVisible] = useState(false);
const { onScale, scale = 1, iconSize = '2em' } = props;
const { onScale, scale = 1, iconSize = '2em', dropdownAbove } = props;

const zoomOptions = ZOOM_OPTIONS.map((zoom: { label: string; scale: number }) => ({
...zoom,
Expand Down Expand Up @@ -89,7 +91,13 @@ export default function ZoomControls({ styleSheet, ...props }: ZoomControlsProps
</ButtonGroup>

{visible && (
<Dropdown visible={visible} left="0" zIndex={5} onClickOutside={toggleZoomMenu}>
<Dropdown
visible={visible}
bottom={dropdownAbove ? '100%' : undefined}
left="0"
zIndex={5}
onClickOutside={toggleZoomMenu}
>
<Menu accessibilityLabel={T.phrase('lunar.image.zoomMenu', 'Zoom dropdown menu')}>
{zoomOptions.map((zoom) => (
<Item key={zoom.scale} onClick={zoom.handleOnClick}>
Expand Down
31 changes: 29 additions & 2 deletions packages/core/src/components/ImageViewer/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@ import Row from '../Row';
type ImageViewerDemoProps = {
width?: string;
height?: string;
controlsBottom?: boolean;
};

function ImageViewerDemo({ width, height }: ImageViewerDemoProps) {
function ImageViewerDemo({ width, height, controlsBottom }: ImageViewerDemoProps) {
const [scale, setScale] = useState(1);
const [rotation, setRotation] = useState(0);

return (
return controlsBottom ? (
<>
<ImageViewer
alt="Testing"
scale={scale}
src={space}
rotation={rotation}
height={height}
width={width}
/>
<Row
before={
<RotateControls rotation={rotation} onRotation={(value: number) => setRotation(value)} />
}
>
<ZoomControls dropdownAbove scale={scale} onScale={(value: number) => setScale(value)} />
</Row>
</>
) : (
<>
<Row
before={
Expand Down Expand Up @@ -63,3 +82,11 @@ export function withSetWidthAndHeightPortrait() {
withSetWidthAndHeightPortrait.story = {
name: 'With set width and height, portrait.',
};

export function withControlsBottom() {
return <ImageViewerDemo controlsBottom />;
}

withControlsBottom.story = {
name: 'With dropdownAbove set.',
};