mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-17 19:19:47 +00:00
Add toggle
This commit is contained in:
23
src/client/lazy-app/Compress/Options/Toggle/index.tsx
Normal file
23
src/client/lazy-app/Compress/Options/Toggle/index.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { h, Component } from 'preact';
|
||||||
|
import * as style from './style.css';
|
||||||
|
import 'add-css:./style.css';
|
||||||
|
import { UncheckedIcon, CheckedIcon } from '../../../icons';
|
||||||
|
|
||||||
|
interface Props extends preact.JSX.HTMLAttributes {}
|
||||||
|
interface State {}
|
||||||
|
|
||||||
|
export default class Toggle extends Component<Props, State> {
|
||||||
|
render(props: Props) {
|
||||||
|
return (
|
||||||
|
<div class={style.checkbox}>
|
||||||
|
{/* @ts-ignore - TS bug https://github.com/microsoft/TypeScript/issues/16019 */}
|
||||||
|
<input class={style.realCheckbox} type="checkbox" {...props} />
|
||||||
|
<div class={style.track}>
|
||||||
|
<div class={style.thumbTrack}>
|
||||||
|
<div class={style.thumb}></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/client/lazy-app/Compress/Options/Toggle/style.css
Normal file
55
src/client/lazy-app/Compress/Options/Toggle/style.css
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
.checkbox {
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.track {
|
||||||
|
--thumb-size: 14px;
|
||||||
|
background: var(--black);
|
||||||
|
border-radius: 1000px;
|
||||||
|
width: 24px;
|
||||||
|
padding: 3px calc(var(--thumb-size) / 2 + 3px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumb {
|
||||||
|
position: relative;
|
||||||
|
width: var(--thumb-size);
|
||||||
|
height: var(--thumb-size);
|
||||||
|
background: var(--less-light-gray);
|
||||||
|
border-radius: 100%;
|
||||||
|
transform: translateX(calc(var(--thumb-size) / -2));
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: var(--main-theme-color);
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 200ms ease;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumb-track {
|
||||||
|
transition: transform 200ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.real-checkbox {
|
||||||
|
top: 0;
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
&:checked + .track {
|
||||||
|
.thumb-track {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumb::before {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
} from '../../feature-meta';
|
} from '../../feature-meta';
|
||||||
import Expander from './Expander';
|
import Expander from './Expander';
|
||||||
import Checkbox from './Checkbox';
|
import Checkbox from './Checkbox';
|
||||||
|
import Toggle from './Toggle';
|
||||||
import Select from './Select';
|
import Select from './Select';
|
||||||
import { Options as QuantOptionsComponent } from 'features/processors/quantize/client';
|
import { Options as QuantOptionsComponent } from 'features/processors/quantize/client';
|
||||||
import { Options as ResizeOptionsComponent } from 'features/processors/resize/client';
|
import { Options as ResizeOptionsComponent } from 'features/processors/resize/client';
|
||||||
@@ -127,7 +128,7 @@ export default class Options extends Component<Props, State> {
|
|||||||
<h3 class={style.optionsTitle}>Edit</h3>
|
<h3 class={style.optionsTitle}>Edit</h3>
|
||||||
<label class={style.sectionEnabler}>
|
<label class={style.sectionEnabler}>
|
||||||
Resize
|
Resize
|
||||||
<Checkbox
|
<Toggle
|
||||||
name="resize.enable"
|
name="resize.enable"
|
||||||
checked={!!processorState.resize.enabled}
|
checked={!!processorState.resize.enabled}
|
||||||
onChange={this.onProcessorEnabledChange}
|
onChange={this.onProcessorEnabledChange}
|
||||||
@@ -147,7 +148,7 @@ export default class Options extends Component<Props, State> {
|
|||||||
|
|
||||||
<label class={style.sectionEnabler}>
|
<label class={style.sectionEnabler}>
|
||||||
Reduce palette
|
Reduce palette
|
||||||
<Checkbox
|
<Toggle
|
||||||
name="quantize.enable"
|
name="quantize.enable"
|
||||||
checked={!!processorState.quantize.enabled}
|
checked={!!processorState.quantize.enabled}
|
||||||
onChange={this.onProcessorEnabledChange}
|
onChange={this.onProcessorEnabledChange}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ html {
|
|||||||
--dim-blue: #0a7bcc;
|
--dim-blue: #0a7bcc;
|
||||||
--deep-blue: #09f;
|
--deep-blue: #09f;
|
||||||
--light-blue: #76c8ff;
|
--light-blue: #76c8ff;
|
||||||
|
--less-light-gray: #bcbcbc;
|
||||||
--light-gray: #eaeaea;
|
--light-gray: #eaeaea;
|
||||||
--medium-light-gray: #d1d1d1;
|
--medium-light-gray: #d1d1d1;
|
||||||
--dark-gray: #333;
|
--dark-gray: #333;
|
||||||
|
|||||||
Reference in New Issue
Block a user