File tree Expand file tree Collapse file tree 2 files changed +65
-3
lines changed Expand file tree Collapse file tree 2 files changed +65
-3
lines changed Original file line number Diff line number Diff line change 4
4
MaterialDynamicColors ,
5
5
hexFromArgb ,
6
6
} from " @material/material-color-utilities" ;
7
+ import { createEventDispatcher } from " svelte" ;
7
8
export let fg: string ;
8
9
export let bg: string ;
9
10
export let scheme: DynamicScheme ;
11
+ export let grabbing: boolean ;
12
+
10
13
type Color =
11
14
| " primary"
12
15
| " onPrimary"
45
48
| " surfaceContainerHigh"
46
49
| " surfaceContainerHighest"
47
50
| " surfaceTint" ;
51
+
52
+ let state = 0 ;
53
+ const dispatch = createEventDispatcher ();
48
54
$ : bgColor = hexFromArgb (MaterialDynamicColors [bg as Color ].getArgb (scheme ));
49
55
$ : fgColor = hexFromArgb (MaterialDynamicColors [fg as Color ].getArgb (scheme ));
56
+ $ : if (! grabbing ) state = 0 ;
50
57
</script >
51
58
52
- <div style ="background-color: {bgColor }; color: {fgColor };" >
59
+ <div
60
+ class =" card"
61
+ style ="background-color: {bgColor }; color: {fgColor };"
62
+ role ={grabbing ? " button" : undefined }
63
+ on:click ={(e ) => {
64
+ if (state ) {
65
+ if (state == 2 ) {
66
+ navigator .clipboard .writeText (bgColor );
67
+ } else {
68
+ navigator .clipboard .writeText (fgColor );
69
+ }
70
+ dispatch (" grabbed" );
71
+ }
72
+ }}
73
+ on:mousemove ={(e ) => {
74
+ if (grabbing ) {
75
+ const rect = e .currentTarget .getBoundingClientRect ();
76
+ const y = Math .min (Math .max (e .clientY - rect .top , 0 ), rect .height ) / rect .height ;
77
+ state = y < 0.3 ? 1 : 2 ;
78
+ }
79
+ }}
80
+ on:mouseleave ={() => {
81
+ state = 0 ;
82
+ }}
83
+ >
53
84
<p class ="m3-font-headline-small" >{bg }</p >
54
85
<p class ="m3-font-body-large" >{fg } text</p >
86
+ {#if state }
87
+ <div class ="overlay" style:background-color ={state == 2 ? bgColor : fgColor } />
88
+ {/if }
55
89
</div >
56
90
57
91
<style >
58
- div {
92
+ .card {
59
93
padding : 1rem ;
60
94
white-space : pre-wrap ;
95
+ position : relative ;
96
+ }
97
+ .card [role = " button" ] {
98
+ cursor : pointer ;
99
+ }
100
+ .overlay {
101
+ position : absolute ;
102
+ inset : 0 ;
103
+ pointer-events : none ;
61
104
}
62
105
p {
63
106
margin : 0 ;
Original file line number Diff line number Diff line change 4
4
import iconCopy from " @ktibow/iconset-material-symbols/content-copy-outline" ;
5
5
import iconLight from " @ktibow/iconset-material-symbols/light-mode-outline" ;
6
6
import iconDark from " @ktibow/iconset-material-symbols/dark-mode-outline" ;
7
+ import iconGrab from " @ktibow/iconset-material-symbols/unarchive-outline" ;
7
8
import { onMount } from " svelte" ;
8
9
9
10
import StyleFromScheme from " $lib/misc/StyleFromScheme.svelte" ;
14
15
export let schemeLight: DynamicScheme ;
15
16
export let schemeDark: DynamicScheme ;
16
17
let showDark = false ;
18
+ let grabbing = false ;
17
19
18
20
const copyUsage = () =>
19
21
navigator .clipboard .writeText (
35
37
<h2 class =" m3-font-title-large" >Your scheme 🎉</h2 >
36
38
<div class =" color-container" >
37
39
{#each pairs as [bgName, fgName]}
38
- <ColorCard scheme ={showDark ? schemeDark : schemeLight } fg ={fgName } bg ={bgName } />
40
+ <ColorCard
41
+ scheme ={showDark ? schemeDark : schemeLight }
42
+ fg ={fgName }
43
+ bg ={bgName }
44
+ {grabbing }
45
+ on:grabbed ={() => (grabbing = false )}
46
+ />
39
47
{/each }
40
48
</div >
41
49
<div class =" buttons" >
47
55
<Icon icon ={showDark ? iconLight : iconDark } />
48
56
{showDark ? " Light" : " Dark" }
49
57
</Button >
58
+ {#if grabbing }
59
+ <Button type ="tonal" iconType ="left" on:click ={() => (grabbing = false )}>
60
+ <Icon icon ={iconGrab } />
61
+ Stop grab
62
+ </Button >
63
+ {:else }
64
+ <Button type ="tonal" iconType ="left" on:click ={() => (grabbing = true )}>
65
+ <Icon icon ={iconGrab } />
66
+ Grab
67
+ </Button >
68
+ {/if }
50
69
</div >
51
70
</div >
52
71
You can’t perform that action at this time.
0 commit comments