Adding labels to collapsed view

This commit is contained in:
Jake Archibald
2018-10-27 12:23:15 +01:00
parent 068dfe1b19
commit 52f61dfccc
5 changed files with 26 additions and 6 deletions

View File

@@ -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;
} }
@@ -66,7 +67,8 @@ export default class MultiPanel extends HTMLElement {
// dont handle modifier shortcuts used by assistive technology. // dont handle modifier shortcuts used by assistive technology.
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':

View File

@@ -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 (

View File

@@ -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;
} }

View File

@@ -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}

View File

@@ -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 {