feat: add image zoom options (#984)
This commit is contained in:
@@ -98,7 +98,7 @@ export const ConfirmPassword: FunctionComponent<Props> = observer(
|
|||||||
<IconButton
|
<IconButton
|
||||||
icon="arrow-left"
|
icon="arrow-left"
|
||||||
title="Go back"
|
title="Go back"
|
||||||
className="flex mr-2 color-neutral"
|
className="flex mr-2 color-neutral p-0"
|
||||||
onClick={handleGoBack}
|
onClick={handleGoBack}
|
||||||
focusable={true}
|
focusable={true}
|
||||||
disabled={isRegistering}
|
disabled={isRegistering}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export const CreateAccount: FunctionComponent<Props> = observer(
|
|||||||
<IconButton
|
<IconButton
|
||||||
icon="arrow-left"
|
icon="arrow-left"
|
||||||
title="Go back"
|
title="Go back"
|
||||||
className="flex mr-2 color-neutral"
|
className="flex mr-2 color-neutral p-0"
|
||||||
onClick={handleClose}
|
onClick={handleClose}
|
||||||
focusable={true}
|
focusable={true}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export const SignInPane: FunctionComponent<Props> = observer(
|
|||||||
<IconButton
|
<IconButton
|
||||||
icon="arrow-left"
|
icon="arrow-left"
|
||||||
title="Go back"
|
title="Go back"
|
||||||
className="flex mr-2 color-neutral"
|
className="flex mr-2 color-neutral p-0"
|
||||||
onClick={() => setMenuPane(AccountMenuPane.GeneralMenu)}
|
onClick={() => setMenuPane(AccountMenuPane.GeneralMenu)}
|
||||||
focusable={true}
|
focusable={true}
|
||||||
disabled={isSigningIn}
|
disabled={isSigningIn}
|
||||||
|
|||||||
@@ -46,9 +46,10 @@ export const IconButton: FunctionComponent<Props> = ({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
title={title}
|
title={title}
|
||||||
className={`no-border cursor-pointer bg-transparent flex flex-row items-center hover:brightness-130 p-0 ${focusableClass} ${className}`}
|
className={`no-border cursor-pointer bg-transparent flex flex-row items-center ${focusableClass} ${className}`}
|
||||||
onClick={click}
|
onClick={click}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
aria-label={title}
|
||||||
>
|
>
|
||||||
<Icon type={icon} className={iconClassName} />
|
<Icon type={icon} className={iconClassName} />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Button } from '@/Components/Button/Button'
|
|||||||
import { Icon } from '@/Components/Icon'
|
import { Icon } from '@/Components/Icon'
|
||||||
import { FilePreviewInfoPanel } from './FilePreviewInfoPanel'
|
import { FilePreviewInfoPanel } from './FilePreviewInfoPanel'
|
||||||
import { isFileTypePreviewable } from './isFilePreviewable'
|
import { isFileTypePreviewable } from './isFilePreviewable'
|
||||||
|
import { PreviewComponent } from './PreviewComponent'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -17,22 +18,6 @@ type Props = {
|
|||||||
onDismiss: () => void
|
onDismiss: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPreviewComponentForFile = (file: SNFile, objectUrl: string) => {
|
|
||||||
if (file.mimeType.startsWith('image/')) {
|
|
||||||
return <img src={objectUrl} />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.mimeType.startsWith('video/')) {
|
|
||||||
return <video className="w-full h-full" src={objectUrl} controls />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.mimeType.startsWith('audio/')) {
|
|
||||||
return <audio src={objectUrl} controls />
|
|
||||||
}
|
|
||||||
|
|
||||||
return <object className="w-full h-full" data={objectUrl} />
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FilePreviewModal: FunctionComponent<Props> = ({ application, file, onDismiss }) => {
|
export const FilePreviewModal: FunctionComponent<Props> = ({ application, file, onDismiss }) => {
|
||||||
const [objectUrl, setObjectUrl] = useState<string>()
|
const [objectUrl, setObjectUrl] = useState<string>()
|
||||||
const [isFilePreviewable, setIsFilePreviewable] = useState(false)
|
const [isFilePreviewable, setIsFilePreviewable] = useState(false)
|
||||||
@@ -132,9 +117,9 @@ export const FilePreviewModal: FunctionComponent<Props> = ({ application, file,
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-grow min-h-0 overflow-auto">
|
<div className="flex flex-grow min-h-0 overflow-auto">
|
||||||
<div className="flex flex-grow items-center justify-center">
|
<div className="flex flex-grow items-center justify-center relative">
|
||||||
{objectUrl ? (
|
{objectUrl ? (
|
||||||
getPreviewComponentForFile(file, objectUrl)
|
<PreviewComponent file={file} objectUrl={objectUrl} />
|
||||||
) : isLoadingFile ? (
|
) : isLoadingFile ? (
|
||||||
<div className="sk-spinner w-5 h-5 spinner-info"></div>
|
<div className="sk-spinner w-5 h-5 spinner-info"></div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
64
app/assets/javascripts/Components/Files/ImagePreview.tsx
Normal file
64
app/assets/javascripts/Components/Files/ImagePreview.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { IconType } from '@standardnotes/snjs'
|
||||||
|
import { FunctionComponent } from 'preact'
|
||||||
|
import { useEffect, useRef, useState } from 'preact/hooks'
|
||||||
|
import { IconButton } from '../Button/IconButton'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
objectUrl: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ImagePreview: FunctionComponent<Props> = ({ objectUrl }) => {
|
||||||
|
const initialImgHeightRef = useRef<number>()
|
||||||
|
|
||||||
|
const [imageZoomPercent, setImageZoomPercent] = useState(100)
|
||||||
|
const [imageHeight, setImageHeight] = useState(initialImgHeightRef.current)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialImgHeightRef.current) {
|
||||||
|
setImageHeight(imageZoomPercent * (initialImgHeightRef.current / 100))
|
||||||
|
}
|
||||||
|
}, [imageZoomPercent])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center w-full h-full overflow-auto">
|
||||||
|
<img
|
||||||
|
src={objectUrl}
|
||||||
|
height={imageHeight}
|
||||||
|
ref={(imgElement) => {
|
||||||
|
if (!initialImgHeightRef.current) {
|
||||||
|
initialImgHeightRef.current = imgElement?.height
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="flex items-center absolute bottom-6 py-1 px-3 bg-default border-1 border-solid border-main rounded">
|
||||||
|
<span className="mr-1.5">Zoom:</span>
|
||||||
|
<IconButton
|
||||||
|
className="hover:bg-contrast p-1 rounded"
|
||||||
|
icon="add"
|
||||||
|
title="Zoom In"
|
||||||
|
focusable={true}
|
||||||
|
onClick={() => {
|
||||||
|
setImageZoomPercent((percent) => percent + 10)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="mx-2">{imageZoomPercent}%</span>
|
||||||
|
<IconButton
|
||||||
|
className="hover:bg-contrast p-1 rounded"
|
||||||
|
icon={'subtract' as IconType}
|
||||||
|
title="Zoom Out"
|
||||||
|
focusable={true}
|
||||||
|
onClick={() => {
|
||||||
|
setImageZoomPercent((percent) => {
|
||||||
|
const newPercent = percent - 10
|
||||||
|
if (newPercent >= 10) {
|
||||||
|
return newPercent
|
||||||
|
} else {
|
||||||
|
return percent
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
24
app/assets/javascripts/Components/Files/PreviewComponent.tsx
Normal file
24
app/assets/javascripts/Components/Files/PreviewComponent.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { SNFile } from '@standardnotes/snjs'
|
||||||
|
import { FunctionComponent } from 'preact'
|
||||||
|
import { ImagePreview } from './ImagePreview'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
file: SNFile
|
||||||
|
objectUrl: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PreviewComponent: FunctionComponent<Props> = ({ file, objectUrl }) => {
|
||||||
|
if (file.mimeType.startsWith('image/')) {
|
||||||
|
return <ImagePreview objectUrl={objectUrl} />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.mimeType.startsWith('video/')) {
|
||||||
|
return <video className="w-full h-full" src={objectUrl} controls />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.mimeType.startsWith('audio/')) {
|
||||||
|
return <audio src={objectUrl} controls />
|
||||||
|
}
|
||||||
|
|
||||||
|
return <object className="w-full h-full" data={objectUrl} />
|
||||||
|
}
|
||||||
@@ -88,6 +88,7 @@ import {
|
|||||||
UserSwitch,
|
UserSwitch,
|
||||||
WarningIcon,
|
WarningIcon,
|
||||||
WindowIcon,
|
WindowIcon,
|
||||||
|
SubtractIcon,
|
||||||
} from '@standardnotes/stylekit'
|
} from '@standardnotes/stylekit'
|
||||||
|
|
||||||
export const ICONS = {
|
export const ICONS = {
|
||||||
@@ -177,6 +178,7 @@ export const ICONS = {
|
|||||||
user: UserIcon,
|
user: UserIcon,
|
||||||
warning: WarningIcon,
|
warning: WarningIcon,
|
||||||
window: WindowIcon,
|
window: WindowIcon,
|
||||||
|
subtract: SubtractIcon,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -194,7 +196,7 @@ export const Icon: FunctionalComponent<Props> = ({ type, className = '', ariaLab
|
|||||||
<IconComponent
|
<IconComponent
|
||||||
className={`sn-icon ${className}`}
|
className={`sn-icon ${className}`}
|
||||||
role="img"
|
role="img"
|
||||||
{...(ariaLabel ? { 'aria-label': ariaLabel } : {})}
|
{...(ariaLabel ? { 'aria-label': ariaLabel } : { 'aria-hidden': true })}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const Toggle: FunctionComponent<{
|
|||||||
setIsToggled: StateUpdater<boolean>
|
setIsToggled: StateUpdater<boolean>
|
||||||
}> = ({ isToggled, setIsToggled }) => (
|
}> = ({ isToggled, setIsToggled }) => (
|
||||||
<IconButton
|
<IconButton
|
||||||
className="w-5 h-5 justify-center sk-circle hover:bg-grey-4 color-neutral"
|
className="w-5 h-5 p-0 justify-center sk-circle hover:bg-grey-4 color-neutral"
|
||||||
icon={isToggled ? 'eye-off' : 'eye'}
|
icon={isToggled ? 'eye-off' : 'eye'}
|
||||||
iconClassName="sn-icon--small"
|
iconClassName="sn-icon--small"
|
||||||
title="Show/hide password"
|
title="Show/hide password"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const CopyButton: FunctionComponent<{ copyValue: string }> = ({ copyValue
|
|||||||
focusable={false}
|
focusable={false}
|
||||||
title="Copy to clipboard"
|
title="Copy to clipboard"
|
||||||
icon={isCopied ? 'check' : 'copy'}
|
icon={isCopied ? 'check' : 'copy'}
|
||||||
className={isCopied ? 'success' : undefined}
|
className={`${isCopied ? 'success' : undefined} p-0`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator?.clipboard?.writeText(secretKey).catch(console.error)
|
navigator?.clipboard?.writeText(secretKey).catch(console.error)
|
||||||
setCopied(() => true)
|
setCopied(() => true)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const SaveSecretKey: FunctionComponent<{
|
|||||||
focusable={false}
|
focusable={false}
|
||||||
title="Download"
|
title="Download"
|
||||||
icon="download"
|
icon="download"
|
||||||
|
className="p-0"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
downloadSecretKey(act.secretKey)
|
downloadSecretKey(act.secretKey)
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const TagsSectionAddButton: FunctionComponent<Props> = observer(({ tags }
|
|||||||
focusable={true}
|
focusable={true}
|
||||||
icon="add"
|
icon="add"
|
||||||
title="Create a new tag"
|
title="Create a new tag"
|
||||||
className="color-neutral"
|
className="color-neutral p-0"
|
||||||
onClick={() => tags.createNewTemplate()}
|
onClick={() => tags.createNewTemplate()}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -266,6 +266,11 @@
|
|||||||
margin-right: 3rem;
|
margin-right: 3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mx-2 {
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.mx-4 {
|
.mx-4 {
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
margin-right: 1rem;
|
margin-right: 1rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user