Skip to content

Commit cd59cf7

Browse files
committed
wire up copy css buttons
1 parent a0abcbd commit cd59cf7

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

src/components/Gradient.svelte

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,22 @@ import GradientImportDialog from './GradientImportDialog.svelte'
400400
document.querySelector('.preview-panel .panel-actions button').focus()
401401
}
402402
403+
import { copyToClipboard } from '../utils/clipboard.ts'
404+
import { layers as layersStore, active_layer_index as activeLayerIndex, defaultLayer, selectLayer as selectLayerFn } from '../store/layers.ts'
405+
403406
function globalAction(event) {
404407
switch (event.target.value) {
405408
case 'Start new':
406-
$gradient_type = 'linear'
407-
$gradient_space = 'oklab'
408-
$gradient_stops = [
409-
{kind: 'stop', color: '#000', auto: '0', position1: '0', position2: '0'},
410-
{kind: 'hint', auto: '50', percentage: '50'},
411-
{kind: 'stop', color: '#fff', auto: '100', position1: '100', position2: '100'},
412-
]
413-
$linear_named_angle = 'to right'
409+
// Reset to a single default linear layer and sync stores
410+
layersStore.set([defaultLayer()])
411+
activeLayerIndex.set(0)
412+
selectLayerFn(0)
413+
break
414+
case 'Copy modern CSS':
415+
copyToClipboard(user_layers_joined || user_gradient)
416+
break
417+
case 'Copy classic CSS':
418+
copyToClipboard(classic_layers_joined || classic_gradient)
414419
break
415420
case 'Import gradient':
416421
openImport()
@@ -477,7 +482,7 @@ let user_gradient = $derived(gensyntax[$gradient_type](
477482
<header class="brand">
478483
<div class="gradient-logo" style="background:{preview_hd ? (user_layers_joined || user_gradient) : (classic_layers_joined || classic_gradient)}"></div>
479484
<h1 class="brand-name">
480-
HD G<b>rad</b>ients
485+
HDR G<b>rad</b>ients
481486
</h1>
482487
</header>
483488
<ColorPicker />
@@ -500,7 +505,7 @@ let user_gradient = $derived(gensyntax[$gradient_type](
500505
<div class="preview">
501506
{#if $gradient_interpolation !== 'longer'}
502507
<label class="hd-switch">
503-
<Hint title="HDR" copy="This switch toggles between the SDR and HDR CSS gradients.<br><br>When off it shows the gradient with hex colors, which has always been in the sRGB colorspace.<br><br>When on, the gradient shown is using a newer color space and also using newer wide gamut colors.<br><br>This button helps you preview the classic gradient vs the HD gradient you're building in this tool." />
508+
<Hint title="HDR" copy="This switch toggles between the SDR and HDR CSS gradients.<br><br>When off it shows the gradient with hex colors, which has always been in the sRGB colorspace.<br><br>When on, the gradient shown is using a newer color space and also using newer wide gamut colors.<br><br>This button helps you preview the classic gradient vs the HDR gradient you're building in this tool." />
504509
<span class="sr-only">HD on or off?</span>
505510
{#if preview_hd == true}
506511
<svg aria-hidden="true" width="32" height="32" viewBox="0 0 20 20"><path fill="currentColor" d="M4.75 4A2.75 2.75 0 0 0 2 6.75v6.5A2.75 2.75 0 0 0 4.75 16h10.5A2.75 2.75 0 0 0 18 13.25v-6.5A2.75 2.75 0 0 0 15.25 4H4.75ZM4.5 7.5A.5.5 0 0 1 5 8v1.5h2V8a.5.5 0 0 1 1 0v4a.5.5 0 0 1-1 0v-1.5H5V12a.5.5 0 0 1-1 0V8a.5.5 0 0 1 .5-.5ZM9 8a.5.5 0 0 1 .5-.5h.25A2.25 2.25 0 0 1 12 9.75v.5a2.25 2.25 0 0 1-2.25 2.25H9.5A.5.5 0 0 1 9 12V8Zm1 3.475c.57-.116 1-.62 1-1.225v-.5c0-.605-.43-1.11-1-1.225v2.95ZM13 8a.5.5 0 0 1 .5-.5h1a1.5 1.5 0 0 1 .868 2.724l.6 1.6a.5.5 0 0 1-.936.352l-.629-1.676H14V12a.5.5 0 0 1-1 0V8Zm1 1.5h.5a.5.5 0 0 0 0-1H14v1Z"/></svg>
@@ -550,15 +555,15 @@ let user_gradient = $derived(gensyntax[$gradient_type](
550555
<div class="menu-bar">
551556
<button class="global-actions">
552557
<select tabindex="-1" onchange={globalAction}>
553-
<option disabled selected>Actions</option>
558+
<option disabled selected>Global Actions</option>
554559
<hr>
555560
<option>Start new</option>
556561
<option>Import gradient</option>
557-
<option disabled>Copy modern CSS</option>
558-
<option disabled>Copy classic CSS</option>
559-
<option disabled>Reset all stops to auto</option>
562+
<option>Copy modern CSS</option>
563+
<option>Copy classic CSS</option>
564+
<!-- <option disabled>Reset all stops to auto</option> -->
560565
<hr>
561-
<option disabled>Toggle light & dark</option>
566+
<!-- <option disabled>Toggle light & dark</option> -->
562567
<option>Tips & tricks</option>
563568
<option>Help & feedback</option>
564569
</select>

0 commit comments

Comments
 (0)