-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddd78b8
commit ab8ee9e
Showing
45 changed files
with
2,660 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
special-pages/pages/new-tab/app/components/BackgroundProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { Fragment, h } from 'preact'; | ||
import styles from './BackgroundReceiver.module.css'; | ||
import { detectThemeFromHex, values } from '../customizer/values.js'; | ||
import { useContext } from 'preact/hooks'; | ||
import { CustomizerContext } from '../customizer/CustomizerProvider.js'; | ||
|
||
/** | ||
* @import { BackgroundVariant, BrowserTheme } from "../../types/new-tab" | ||
*/ | ||
|
||
/** | ||
* @param {BackgroundVariant} background | ||
* @param {BrowserTheme} browserTheme | ||
* @param {'light' | 'dark'} system | ||
* @return {{bg: 'light' | 'dark', browser: 'light' | 'dark'}} | ||
*/ | ||
export function inferSchemeFrom(background, browserTheme, system) { | ||
const browser = themeFromBrowser(browserTheme, system); | ||
switch (background.kind) { | ||
case 'default': | ||
return { bg: browser, browser }; | ||
case 'color': { | ||
const color = values.colors[background.value]; | ||
return { bg: color.colorScheme, browser }; | ||
} | ||
|
||
case 'gradient': { | ||
const gradient = values.gradients[background.value]; | ||
return { bg: gradient.colorScheme, browser }; | ||
} | ||
|
||
case 'userImage': | ||
return { bg: background.value.colorScheme, browser }; | ||
|
||
case 'hex': | ||
return { bg: detectThemeFromHex(background.value), browser }; | ||
} | ||
} | ||
|
||
/** | ||
* @param {BrowserTheme} browserTheme | ||
* @param {'light' | 'dark'} system | ||
* @return {'light' | 'dark'} | ||
*/ | ||
export function themeFromBrowser(browserTheme, system) { | ||
if (browserTheme === 'system') { | ||
return system; | ||
} | ||
return browserTheme; | ||
} | ||
|
||
/** | ||
* @param {object} props | ||
* @param {import("@preact/signals").Signal<'light' | 'dark'>} props.bg | ||
* @param {import("@preact/signals").Signal<'light' | 'dark'>} props.browser | ||
*/ | ||
export function BackgroundConsumer({ bg, browser }) { | ||
const { data } = useContext(CustomizerContext); | ||
const background = data.value.background; | ||
|
||
switch (background.kind) { | ||
case 'default': { | ||
return <div className={styles.root} data-testid="BackgroundConsumer" data-background-kind="default" data-theme={browser} />; | ||
} | ||
case 'hex': { | ||
return ( | ||
<div | ||
class={styles.root} | ||
data-animate="true" | ||
data-testid="BackgroundConsumer" | ||
style={{ | ||
backgroundColor: background.value, | ||
}} | ||
></div> | ||
); | ||
} | ||
case 'color': { | ||
const color = values.colors[background.value]; | ||
return ( | ||
<div | ||
class={styles.root} | ||
data-animate="true" | ||
data-background-color={color.hex} | ||
data-testid="BackgroundConsumer" | ||
style={{ | ||
backgroundColor: color.hex, | ||
}} | ||
></div> | ||
); | ||
} | ||
case 'gradient': { | ||
const gradient = values.gradients[background.value]; | ||
return ( | ||
<Fragment key="gradient"> | ||
<div | ||
class={styles.root} | ||
data-animate="false" | ||
data-testid="BackgroundConsumer" | ||
style={{ | ||
backgroundColor: gradient.fallback, | ||
backgroundImage: `url(${gradient.path})`, | ||
backgroundSize: 'cover', | ||
backgroundRepeat: 'no-repeat', | ||
}} | ||
/> | ||
<div | ||
class={styles.root} | ||
data-animate="false" | ||
style={{ | ||
backgroundImage: `url(gradients/grain.png)`, | ||
backgroundRepeat: 'repeat', | ||
opacity: 0.5, | ||
mixBlendMode: 'soft-light', | ||
}} | ||
></div> | ||
</Fragment> | ||
); | ||
} | ||
case 'userImage': { | ||
const img = background.value; | ||
return ( | ||
<div | ||
class={styles.root} | ||
data-animate="true" | ||
data-testid="BackgroundConsumer" | ||
style={{ | ||
backgroundImage: `url(${img.src})`, | ||
backgroundSize: 'cover', | ||
backgroundRepeat: 'no-repeat', | ||
backgroundPosition: 'center center', | ||
}} | ||
></div> | ||
); | ||
} | ||
default: { | ||
console.warn('Unreachable!'); | ||
return <div className={styles.root}></div>; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
special-pages/pages/new-tab/app/components/BackgroundReceiver.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.root { | ||
position: fixed; | ||
z-index: 0; | ||
inset: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
pointer-events: none; | ||
|
||
&[data-animate="true"] { | ||
transition: all .3s ease-in-out; | ||
} | ||
|
||
&[data-background-kind="default"][data-theme=dark] { | ||
background: var(--default-dark-bg); | ||
} | ||
&[data-background-kind="default"][data-theme=light] { | ||
background: var(--default-light-bg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.