mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 00:37:19 +00:00
Download button on the outside.
This commit is contained in:
@@ -156,6 +156,9 @@ async function processSvg(blob: Blob): Promise<HTMLImageElement> {
|
|||||||
|
|
||||||
// These are only used in the mobile view
|
// These are only used in the mobile view
|
||||||
const resultTitles = ['Top', 'Bottom'];
|
const resultTitles = ['Top', 'Bottom'];
|
||||||
|
// These are only used in the desktop view
|
||||||
|
const buttonPositions =
|
||||||
|
['download-left', 'download-right'] as ('download-left' | 'download-right')[];
|
||||||
|
|
||||||
export default class Compress extends Component<Props, State> {
|
export default class Compress extends Component<Props, State> {
|
||||||
widthQuery = window.matchMedia('(max-width: 599px)');
|
widthQuery = window.matchMedia('(max-width: 599px)');
|
||||||
@@ -424,6 +427,7 @@ export default class Compress extends Component<Props, State> {
|
|||||||
loading={loading || image.loading}
|
loading={loading || image.loading}
|
||||||
copyDirection={copyDirections[index]}
|
copyDirection={copyDirections[index]}
|
||||||
onCopyToOtherClick={this.onCopyToOtherClick.bind(this, index)}
|
onCopyToOtherClick={this.onCopyToOtherClick.bind(this, index)}
|
||||||
|
buttonPosition={mobileView ? 'stack-right' : buttonPositions[index]}
|
||||||
>
|
>
|
||||||
{!mobileView ? null : [
|
{!mobileView ? null : [
|
||||||
<ExpandIcon class={style.expandIcon} key="expand-icon"/>,
|
<ExpandIcon class={style.expandIcon} key="expand-icon"/>,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { DownloadIcon, CopyAcrossIcon, CopyAcrossIconProps } from '../../lib/ico
|
|||||||
import '../custom-els/LoadingSpinner';
|
import '../custom-els/LoadingSpinner';
|
||||||
import { SourceImage } from '../compress';
|
import { SourceImage } from '../compress';
|
||||||
import { Fileish, bind } from '../../lib/initial-util';
|
import { Fileish, bind } from '../../lib/initial-util';
|
||||||
|
import { button } from '../output/style.scss.d';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@@ -14,6 +15,7 @@ interface Props {
|
|||||||
downloadUrl?: string;
|
downloadUrl?: string;
|
||||||
children: ComponentChildren;
|
children: ComponentChildren;
|
||||||
copyDirection: CopyAcrossIconProps['copyDirection'];
|
copyDirection: CopyAcrossIconProps['copyDirection'];
|
||||||
|
buttonPosition: keyof typeof buttonPositionClass;
|
||||||
onCopyToOtherClick(): void;
|
onCopyToOtherClick(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,6 +23,12 @@ interface State {
|
|||||||
showLoadingState: boolean;
|
showLoadingState: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buttonPositionClass = {
|
||||||
|
'stack-right': style.stackRight,
|
||||||
|
'download-right': style.downloadRight,
|
||||||
|
'download-left': style.downloadLeft,
|
||||||
|
};
|
||||||
|
|
||||||
const loadingReactionDelay = 500;
|
const loadingReactionDelay = 500;
|
||||||
|
|
||||||
export default class Results extends Component<Props, State> {
|
export default class Results extends Component<Props, State> {
|
||||||
@@ -52,11 +60,12 @@ export default class Results extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render(
|
render(
|
||||||
{ source, imageFile, downloadUrl, children, copyDirection }: Props,
|
{ source, imageFile, downloadUrl, children, copyDirection, buttonPosition }: Props,
|
||||||
{ showLoadingState }: State,
|
{ showLoadingState }: State,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={style.results}>
|
<div class={`${style.results} ${buttonPositionClass[buttonPosition]}`}>
|
||||||
<div class={style.resultData}>
|
<div class={style.resultData}>
|
||||||
{(children as ComponentChild[])[0]
|
{(children as ComponentChild[])[0]
|
||||||
? <div class={style.resultTitle}>{children}</div>
|
? <div class={style.resultTitle}>{children}</div>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
.results {
|
.results {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr auto auto;
|
grid-template-columns: [text] 1fr [copy-button] auto [download-button] auto;
|
||||||
background: rgba(0, 0, 0, 0.9);
|
background: rgba(0, 0, 0, 0.9);
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
|
|
||||||
@@ -34,13 +34,29 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.result-data {
|
.result-data {
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: text;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 15px;
|
padding: 0 10px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.download-right {
|
||||||
|
grid-template-columns: [copy-button] auto [text] 1fr [download-button] auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.download-left {
|
||||||
|
grid-template-columns: [download-button] auto [text] 1fr [copy-button] auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stack-right {
|
||||||
|
& .result-data {
|
||||||
|
padding: 0 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.result-title {
|
.result-title {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -64,6 +80,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.download {
|
.download {
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: download-button;
|
||||||
background: #34B9EB;
|
background: #34B9EB;
|
||||||
--size: 38px;
|
--size: 38px;
|
||||||
width: var(--size);
|
width: var(--size);
|
||||||
@@ -104,6 +122,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.copy-to-other {
|
.copy-to-other {
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: copy-button;
|
||||||
composes: unbutton from '../../lib/util.scss';
|
composes: unbutton from '../../lib/util.scss';
|
||||||
composes: download;
|
composes: download;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user