mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 17:27:09 +00:00
Close Options flyout when clicking an item
This commit is contained in:
@@ -18,7 +18,7 @@ type Direction = 'left' | 'right' | 'up' | 'down';
|
|||||||
const has = (haystack: string | string[] | undefined, needle: string) =>
|
const has = (haystack: string | string[] | undefined, needle: string) =>
|
||||||
Array.isArray(haystack) ? haystack.includes(needle) : haystack === needle;
|
Array.isArray(haystack) ? haystack.includes(needle) : haystack === needle;
|
||||||
|
|
||||||
interface Props extends ComponentProps<'aside'> {
|
interface Props extends Omit<ComponentProps<'aside'>, 'ref'> {
|
||||||
showing?: boolean;
|
showing?: boolean;
|
||||||
direction?: Direction | Direction[];
|
direction?: Direction | Direction[];
|
||||||
anchor?: Anchor;
|
anchor?: Anchor;
|
||||||
@@ -53,16 +53,24 @@ export default class Flyout extends Component<Props, State> {
|
|||||||
this.setShowing(false);
|
this.setShowing(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hide = () => {
|
||||||
|
this.setShowing(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
show = () => {
|
||||||
|
this.setShowing(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
toggle = () => {
|
||||||
|
this.setShowing(!this.state.showing);
|
||||||
|
};
|
||||||
|
|
||||||
private setShowing = (showing?: boolean) => {
|
private setShowing = (showing?: boolean) => {
|
||||||
this.shown = Date.now();
|
this.shown = Date.now();
|
||||||
if (showing) this.setState({ showing: true, hasShown: true });
|
if (showing) this.setState({ showing: true, hasShown: true });
|
||||||
else this.setState({ showing: false });
|
else this.setState({ showing: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
private toggle = () => {
|
|
||||||
this.setShowing(!this.state.showing);
|
|
||||||
};
|
|
||||||
|
|
||||||
private reposition = () => {
|
private reposition = () => {
|
||||||
const menu = this.menu.current;
|
const menu = this.menu.current;
|
||||||
const wrap = this.wrap.current;
|
const wrap = this.wrap.current;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component, createRef } from 'preact';
|
||||||
|
|
||||||
import * as style from './style.css';
|
import * as style from './style.css';
|
||||||
import 'add-css:./style.css';
|
import 'add-css:./style.css';
|
||||||
@@ -65,6 +65,8 @@ export default class Options extends Component<Props, State> {
|
|||||||
supportedEncoderMap: undefined,
|
supportedEncoderMap: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu = createRef<Flyout>();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
supportedEncoderMapP.then((supportedEncoderMap) =>
|
supportedEncoderMapP.then((supportedEncoderMap) =>
|
||||||
@@ -111,10 +113,12 @@ export default class Options extends Component<Props, State> {
|
|||||||
|
|
||||||
private onCopyCliClick = () => {
|
private onCopyCliClick = () => {
|
||||||
this.props.onCopyCliClick(this.props.index);
|
this.props.onCopyCliClick(this.props.index);
|
||||||
|
if (this.menu.current) this.menu.current.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
private onCopyToOtherSideClick = () => {
|
private onCopyToOtherSideClick = () => {
|
||||||
this.props.onCopyToOtherSideClick(this.props.index);
|
this.props.onCopyToOtherSideClick(this.props.index);
|
||||||
|
if (this.menu.current) this.menu.current.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
render(
|
render(
|
||||||
@@ -139,6 +143,7 @@ export default class Options extends Component<Props, State> {
|
|||||||
<h3 class={style.optionsTitle}>
|
<h3 class={style.optionsTitle}>
|
||||||
Edit
|
Edit
|
||||||
<Flyout
|
<Flyout
|
||||||
|
ref={this.menu}
|
||||||
class={style.menu}
|
class={style.menu}
|
||||||
direction={['up', 'left']}
|
direction={['up', 'left']}
|
||||||
anchor="right"
|
anchor="right"
|
||||||
|
|||||||
Reference in New Issue
Block a user