-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NTP Next] Add updated NTP with background support
- Loading branch information
1 parent
819e3c6
commit 8ec8d10
Showing
63 changed files
with
3,260 additions
and
12 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
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
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,25 @@ | ||
# Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import("//brave/components/common/typescript.gni") | ||
import("//mojo/public/tools/bindings/mojom.gni") | ||
|
||
assert(!is_android) | ||
|
||
transpile_web_ui("resources") { | ||
entry_points = [ [ | ||
"new_tab", | ||
rebase_path("new_tab_page.tsx"), | ||
] ] | ||
resource_name = "brave_new_tab" | ||
output_module = true | ||
deps = [ "//brave/browser/ui/webui/brave_new_tab:mojom_js" ] | ||
} | ||
|
||
pack_web_resources("generated_resources") { | ||
resource_name = "brave_new_tab" | ||
output_dir = "$root_gen_dir/brave/browser/resources/brave_new_tab" | ||
deps = [ ":resources" ] | ||
} |
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,94 @@ | ||
/* Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import { color, font } from '@brave/leo/tokens/css/variables' | ||
import { scoped, global } from '../lib/scoped_css' | ||
|
||
export const style = scoped.css` | ||
.settings { | ||
--leo-icon-size: 20px; | ||
position: absolute; | ||
inset-block-start: 4px; | ||
inset-inline-end: 4px; | ||
block-size: 20px; | ||
inline-size: 20px; | ||
opacity: 0.5; | ||
color: #fff; | ||
filter: drop-shadow(0px 1px 4px rgba(0, 0, 0, 0.60)); | ||
&:hover { | ||
opacity: 0.7; | ||
cursor: pointer; | ||
} | ||
} | ||
main { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
min-height: 100vh; | ||
padding-top: 40px; | ||
} | ||
.topsites-container { | ||
min-height: 32px; | ||
} | ||
.searchbox-container { | ||
flex: 1 1 auto; | ||
margin: 16px 0; | ||
} | ||
.background-caption-container { | ||
margin: 8px 0; | ||
} | ||
.widget-container { | ||
min-height: 8px; | ||
} | ||
` | ||
|
||
global.css` | ||
@scope (${style.selector}) { | ||
& { | ||
font: ${font.default.regular}; | ||
color: ${color.text.primary}; | ||
} | ||
button { | ||
margin: 0; | ||
padding: 0; | ||
background: 0; | ||
border: none; | ||
text-align: unset; | ||
width: unset; | ||
font: inherit; | ||
cursor: pointer; | ||
&:disabled { | ||
cursor: default; | ||
} | ||
} | ||
h2 { | ||
font: ${font.heading.h2}; | ||
margin: 0; | ||
} | ||
h3 { | ||
font: ${font.heading.h3}; | ||
margin: 0; | ||
} | ||
h4 { | ||
font: ${font.heading.h4}; | ||
margin: 0; | ||
} | ||
} | ||
` |
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,43 @@ | ||
/* Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as React from 'react' | ||
import Icon from '@brave/leo/react/icon' | ||
|
||
import { Background } from './background' | ||
import { BackgroundCaption } from './background_caption' | ||
import { SettingsModal, SettingsView } from './settings/settings_modal' | ||
|
||
import { style } from './app.style' | ||
|
||
export function App() { | ||
const [settingsView, setSettingsView] = | ||
React.useState<SettingsView | null>(null) | ||
|
||
return ( | ||
<div {...style}> | ||
<button | ||
className='settings' | ||
onClick={() => setSettingsView('background')} | ||
> | ||
<Icon name='settings' /> | ||
</button> | ||
<main> | ||
<div className='topsites-container' /> | ||
<div className='searchbox-container' /> | ||
<div className='background-caption-container'> | ||
<BackgroundCaption /> | ||
</div> | ||
<div className='widget-container' /> | ||
</main> | ||
<Background /> | ||
<SettingsModal | ||
isOpen={Boolean(settingsView)} | ||
initialView={settingsView} | ||
onClose={() => setSettingsView(null)} | ||
/> | ||
</div> | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
browser/resources/brave_new_tab/components/background.style.ts
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,47 @@ | ||
/* Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import { scoped } from '../lib/scoped_css' | ||
|
||
export const style = scoped.css` | ||
& { | ||
pointer-events: none; | ||
position: fixed; | ||
inset: 0; | ||
z-index: -1; | ||
display: flex; | ||
animation-name: fade-in; | ||
animation-timing-function: ease-in-out; | ||
animation-duration: 350ms; | ||
animation-delay: 0s; | ||
animation-fill-mode: both; | ||
> div { | ||
flex: 1 1 auto; | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
background-position: center center; | ||
} | ||
} | ||
.image-background { | ||
background: | ||
linear-gradient( | ||
rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0) 35%, rgba(0, 0, 0, 0) 80%, | ||
rgba(0, 0, 0, 0.6) 100%), | ||
var(--ntp-background); | ||
} | ||
.color-background { | ||
background: var(--ntp-background); | ||
} | ||
@keyframes fade-in { | ||
from { opacity: 0; } | ||
to { opacity: 1; } | ||
} | ||
` |
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,68 @@ | ||
/* Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as React from 'react' | ||
|
||
import { useNewTabState } from './new_tab_context' | ||
import { loadImage } from '../lib/image_loader' | ||
|
||
import { style } from './background.style' | ||
|
||
function setBackgroundVariable(value: string) { | ||
if (value) { | ||
document.body.style.setProperty('--ntp-background', value) | ||
} else { | ||
document.body.style.removeProperty('--ntp-background') | ||
} | ||
} | ||
|
||
function ImageBackground(props: { url: string }) { | ||
// In order to avoid a "flash-of-unloaded-image", load the image in the | ||
// background and only update the background CSS variable when the image has | ||
// finished loading. | ||
React.useEffect(() => { | ||
loadImage(props.url).then((loaded) => { | ||
if (loaded) { | ||
setBackgroundVariable(`url(${CSS.escape(props.url)})`) | ||
} | ||
}) | ||
}, [props.url]) | ||
|
||
return <div className='image-background' /> | ||
} | ||
|
||
function ColorBackground(props: { colorValue: string }) { | ||
React.useEffect(() => { | ||
setBackgroundVariable(props.colorValue) | ||
}, [props.colorValue]) | ||
|
||
return <div className='color-background' /> | ||
} | ||
|
||
export function Background() { | ||
const currentBackground = useNewTabState((state) => state.currentBackground) | ||
|
||
function renderBackground() { | ||
if (!currentBackground) { | ||
return <ColorBackground colorValue='transparent' /> | ||
} | ||
|
||
switch (currentBackground.type) { | ||
case 'brave': | ||
case 'custom': | ||
case 'sponsored': | ||
return <ImageBackground url={currentBackground.imageUrl} /> | ||
case 'solid': | ||
case 'gradient': | ||
return <ColorBackground colorValue={currentBackground.cssValue} /> | ||
} | ||
} | ||
|
||
return ( | ||
<div {...style}> | ||
{renderBackground()} | ||
</div> | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
browser/resources/brave_new_tab/components/background_caption.style.ts
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,47 @@ | ||
/* Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import { color, font } from '@brave/leo/tokens/css/variables' | ||
import { scoped } from '../lib/scoped_css' | ||
|
||
export const style = scoped.css` | ||
a { | ||
text-decoration: none; | ||
color: inherit; | ||
} | ||
.photo-credits { | ||
color: ${color.white}; | ||
font: ${font.xSmall.regular}; | ||
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.10); | ||
opacity: .5; | ||
} | ||
.sponsored-logo { | ||
--leo-icon-size: 20px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: end; | ||
color: ${color.white}; | ||
leo-icon { | ||
opacity: 0; | ||
transition: opacity 200ms; | ||
} | ||
img { | ||
margin: 2px 20px 0 20px; | ||
width: 170px; | ||
height: auto; | ||
} | ||
&:hover { | ||
leo-icon { | ||
opacity: .7; | ||
} | ||
} | ||
} | ||
` |
Oops, something went wrong.