mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 18:19:47 +00:00
Adding labels to collapsed view
This commit is contained in:
@@ -7,7 +7,8 @@ interface CloseAllOptions {
|
|||||||
const openOneOnlyAttr = 'open-one-only';
|
const openOneOnlyAttr = 'open-one-only';
|
||||||
|
|
||||||
function getClosestHeading(el: Element) {
|
function getClosestHeading(el: Element) {
|
||||||
const closestEl = el.closest('multi-panel > *');
|
// Look for the child of multi-panel, but stop at interactive elements like links & buttons
|
||||||
|
const closestEl = el.closest('multi-panel > *, a, button');
|
||||||
if (closestEl && closestEl.classList.contains(style.panelHeading)) {
|
if (closestEl && closestEl.classList.contains(style.panelHeading)) {
|
||||||
return closestEl;
|
return closestEl;
|
||||||
}
|
}
|
||||||
@@ -67,6 +68,7 @@ export default class MultiPanel extends HTMLElement {
|
|||||||
if (event.altKey) return;
|
if (event.altKey) return;
|
||||||
|
|
||||||
let newHeading: HTMLElement | undefined;
|
let newHeading: HTMLElement | undefined;
|
||||||
|
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case 'ArrowLeft':
|
case 'ArrowLeft':
|
||||||
case 'ArrowUp':
|
case 'ArrowUp':
|
||||||
|
|||||||
@@ -153,6 +153,9 @@ async function processSvg(blob: Blob): Promise<HTMLImageElement> {
|
|||||||
return blobToImg(new Blob([newSource], { type: 'image/svg+xml' }));
|
return blobToImg(new Blob([newSource], { type: 'image/svg+xml' }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are only used in the mobile view
|
||||||
|
const resultTitles = ['Top', 'Bottom'];
|
||||||
|
|
||||||
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)');
|
||||||
|
|
||||||
@@ -411,13 +414,15 @@ export default class Compress extends Component<Props, State> {
|
|||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
const results = images.map(image => (
|
const results = images.map((image, i) => (
|
||||||
<Results
|
<Results
|
||||||
downloadUrl={image.downloadUrl}
|
downloadUrl={image.downloadUrl}
|
||||||
imageFile={image.file}
|
imageFile={image.file}
|
||||||
source={source}
|
source={source}
|
||||||
loading={loading || image.loading}
|
loading={loading || image.loading}
|
||||||
/>
|
>
|
||||||
|
{mobileView ? `${resultTitles[i]} (${encoderMap[image.encoderState.type].label})` : null}
|
||||||
|
</Results>
|
||||||
));
|
));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -27,8 +27,10 @@
|
|||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
width: calc(100% - 60px);
|
width: calc(100% - 60px);
|
||||||
|
max-height: calc(100% - 143px);
|
||||||
|
|
||||||
@media (min-width: 600px) {
|
@media (min-width: 600px) {
|
||||||
|
max-height: none;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component, ComponentChildren, ComponentChild } from 'preact';
|
||||||
|
|
||||||
import * as style from './style.scss';
|
import * as style from './style.scss';
|
||||||
import FileSize from './FileSize';
|
import FileSize from './FileSize';
|
||||||
@@ -12,6 +12,7 @@ interface Props {
|
|||||||
source?: SourceImage;
|
source?: SourceImage;
|
||||||
imageFile?: Fileish;
|
imageFile?: Fileish;
|
||||||
downloadUrl?: string;
|
downloadUrl?: string;
|
||||||
|
children: ComponentChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
@@ -42,10 +43,14 @@ export default class Results extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render({ source, imageFile, downloadUrl }: Props, { showLoadingState }: State) {
|
render({ source, imageFile, downloadUrl, children }: Props, { showLoadingState }: State) {
|
||||||
return (
|
return (
|
||||||
<div class={style.results}>
|
<div class={style.results}>
|
||||||
<div class={style.resultData}>
|
<div class={style.resultData}>
|
||||||
|
{(children as ComponentChild[])[0]
|
||||||
|
? <div class={style.resultTitle}>{children}</div>
|
||||||
|
: null
|
||||||
|
}
|
||||||
{!imageFile || showLoadingState ? 'Working…' :
|
{!imageFile || showLoadingState ? 'Working…' :
|
||||||
<FileSize
|
<FileSize
|
||||||
blob={imageFile}
|
blob={imageFile}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 15px;
|
padding: 0 15px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-title {
|
||||||
|
margin-right: 0.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.size-delta {
|
.size-delta {
|
||||||
|
|||||||
Reference in New Issue
Block a user