1- import { h } from 'preact' ;
1+ import { Fragment , h } from 'preact' ;
22import styles from './BackgroundReceiver.module.css' ;
3+ import { values } from '../customizer/values.js' ;
34import { useContext } from 'preact/hooks' ;
45import { CustomizerContext } from '../customizer/CustomizerProvider.js' ;
6+ import { detectThemeFromHex } from '../customizer/utils.js' ;
57
68/**
79 * @import { BackgroundVariant, BrowserTheme } from "../../types/new-tab"
@@ -18,12 +20,22 @@ export function inferSchemeFrom(background, browserTheme, system) {
1820 switch ( background . kind ) {
1921 case 'default' :
2022 return { bg : browser , browser } ;
21- case 'gradient' :
23+ case 'color' : {
24+ const color = values . colors [ background . value ] ;
25+ return { bg : color . colorScheme , browser } ;
26+ }
27+
28+ case 'gradient' : {
29+ const gradient = values . gradients [ background . value ] ;
30+ return { bg : gradient . colorScheme , browser } ;
31+ }
32+
2233 case 'userImage' :
34+ return { bg : background . value . colorScheme , browser } ;
35+
2336 case 'hex' :
24- console . log ( 'not supported yet!' ) ;
37+ return { bg : detectThemeFromHex ( background . value ) , browser } ;
2538 }
26- return { bg : browser , browser } ;
2739}
2840
2941/**
@@ -50,13 +62,79 @@ export function BackgroundConsumer({ browser }) {
5062 case 'default' : {
5163 return < div className = { styles . root } data-testid = "BackgroundConsumer" data-background-kind = "default" data-theme = { browser } /> ;
5264 }
53- case 'hex' :
54- case 'color' :
55- case 'gradient' :
56- case 'userImage' :
65+ case 'hex' : {
66+ return (
67+ < div
68+ class = { styles . root }
69+ data-animate = "true"
70+ data-testid = "BackgroundConsumer"
71+ style = { {
72+ backgroundColor : background . value ,
73+ } }
74+ > </ div >
75+ ) ;
76+ }
77+ case 'color' : {
78+ const color = values . colors [ background . value ] ;
79+ return (
80+ < div
81+ class = { styles . root }
82+ data-animate = "true"
83+ data-background-color = { color . hex }
84+ data-testid = "BackgroundConsumer"
85+ style = { {
86+ backgroundColor : color . hex ,
87+ } }
88+ > </ div >
89+ ) ;
90+ }
91+ case 'gradient' : {
92+ const gradient = values . gradients [ background . value ] ;
93+ return (
94+ < Fragment key = "gradient" >
95+ < div
96+ class = { styles . root }
97+ data-animate = "false"
98+ data-testid = "BackgroundConsumer"
99+ style = { {
100+ backgroundColor : gradient . fallback ,
101+ backgroundImage : `url(${ gradient . path } )` ,
102+ backgroundSize : 'cover' ,
103+ backgroundRepeat : 'no-repeat' ,
104+ } }
105+ />
106+ < div
107+ class = { styles . root }
108+ data-animate = "false"
109+ style = { {
110+ backgroundImage : `url(gradients/grain.png)` ,
111+ backgroundRepeat : 'repeat' ,
112+ opacity : 0.5 ,
113+ mixBlendMode : 'soft-light' ,
114+ } }
115+ > </ div >
116+ </ Fragment >
117+ ) ;
118+ }
119+ case 'userImage' : {
120+ const img = background . value ;
121+ return (
122+ < div
123+ class = { styles . root }
124+ data-animate = "true"
125+ data-testid = "BackgroundConsumer"
126+ style = { {
127+ backgroundImage : `url(${ img . src } )` ,
128+ backgroundSize : 'cover' ,
129+ backgroundRepeat : 'no-repeat' ,
130+ backgroundPosition : 'center center' ,
131+ } }
132+ > </ div >
133+ ) ;
134+ }
57135 default : {
58- console . warn ( 'not supported yet !' ) ;
59- return < div className = { styles . root } data-testid = "BackgroundConsumer" data-background-kind = "default" data-theme = { browser } / >;
136+ console . warn ( 'Unreachable !' ) ;
137+ return < div className = { styles . root } > </ div > ;
60138 }
61139 }
62140}
0 commit comments