forked from external-repos/squoosh
Add CLI button
This commit is contained in:
@@ -18,6 +18,8 @@ import Select from './Select';
|
||||
import { Options as QuantOptionsComponent } from 'features/processors/quantize/client';
|
||||
import { Options as ResizeOptionsComponent } from 'features/processors/resize/client';
|
||||
|
||||
import { generateCliInvocation } from '../../util/cli-invocation-generator';
|
||||
|
||||
interface Props {
|
||||
mobileView: boolean;
|
||||
source?: SourceImage;
|
||||
@@ -97,6 +99,23 @@ export default class Options extends Component<Props, State> {
|
||||
);
|
||||
};
|
||||
|
||||
private onCreateCLIInvocation = () => {
|
||||
if (!this.props.encoderState) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const cliInvocation = generateCliInvocation(
|
||||
this.props.encoderState,
|
||||
this.props.processorState,
|
||||
);
|
||||
navigator.clipboard.writeText(cliInvocation);
|
||||
} catch (e) {
|
||||
// Show toast
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
render(
|
||||
{ source, encoderState, processorState, onEncoderOptionsChange }: Props,
|
||||
{ supportedEncoderMap }: State,
|
||||
@@ -110,7 +129,9 @@ export default class Options extends Component<Props, State> {
|
||||
<Expander>
|
||||
{!encoderState ? null : (
|
||||
<div>
|
||||
<h3 class={style.optionsTitle}>Edit</h3>
|
||||
<h3 class={style.optionsTitle}>
|
||||
<button onClick={this.onCreateCLIInvocation}>CLI</button>Edit
|
||||
</h3>
|
||||
<label class={style.sectionEnabler}>
|
||||
<Checkbox
|
||||
name="resize.enable"
|
||||
|
||||
Reference in New Issue
Block a user