Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - New Font Usage (Inter) and Dynamic Font Handling #1597

Merged
merged 25 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Working as of now
  • Loading branch information
Adamj1232 committed Mar 17, 2023
commit 33126ced5912a8cc60ba6f5dc363879ceaffc65e
5 changes: 2 additions & 3 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,8 @@ The Onboard styles can customized via [CSS variables](https://developer.mozilla.
--onboard-action-required-btn-text-color

/* FONTS */
--onboard-font-family-normal: Sofia Pro;
--onboard-font-family-semibold: Sofia Pro Semibold;
--onboard-font-family-light: Sofia Pro Light;
--onboard-font-family-normal: Inter;
--onboard-font-family-light: Inter Light;

--onboard-font-size-1: 3rem;
--onboard-font-size-2: 2.25rem;
Expand Down
58 changes: 43 additions & 15 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { state } from './store/index.js'
import { reset$, wallets$ } from './streams.js'
import initI18N from './i18n/index.js'
import App from './views/Index.svelte'
import type { InitOptions, Notify } from './types.js'
import type { InitOptions, Notify, Theme } from './types.js'
import { APP_INITIAL_STATE, STORAGE_KEYS } from './constants.js'
import { configuration, updateConfiguration } from './configuration.js'
import updateBalances from './update-balances.js'
Expand Down Expand Up @@ -197,7 +197,7 @@ function init(options: InitOptions): OnboardAPI {
updateNotify(notifyUpdate)
}

const app = svelteInstance || mountApp()
const app = svelteInstance || mountApp(theme)

updateConfiguration({
appMetadata,
Expand Down Expand Up @@ -241,7 +241,20 @@ function init(options: InitOptions): OnboardAPI {
return API
}

function mountApp() {
const fontFamilyExternallyDefined = (theme: Theme): boolean => {
if (!theme) return false
if (typeof theme === 'object' && theme['--w3o-font-family']) return true
if (
Adamj1232 marked this conversation as resolved.
Show resolved Hide resolved
document.body &&
getComputedStyle(document.body).getPropertyValue(
'--onboard-font-family-normal'
)
)
return true
return false
}

function mountApp(theme: Theme) {
class Onboard extends HTMLElement {
constructor() {
super()
Expand All @@ -251,15 +264,28 @@ function mountApp() {
if (!customElements.get('onboard-v2')) {
customElements.define('onboard-v2', Onboard)
}

// Add Fonts to main page
const styleEl = document.createElement('style')

styleEl.innerHTML = `
${SofiaProRegular}
`

document.body.appendChild(styleEl)
console.log('theme check', theme)
if (!fontFamilyExternallyDefined(theme)) {
console.log('here')
// const myFont = new FontFace(
// 'Inter',
// 'url(https://fonts.gstatic.com/s/pacifico/v21/FwZY7-Qmy14u9lezJ-6H6MmBp0u-.woff2)'
// )
// myFont.load().then(() => {

// document.fonts.add(myFont);
// });

const link = document.createElement('link')
link.rel = 'preconnect'
link.href = 'https://rsms.me/'
const link2 = document.createElement('link')
link2.rel = 'stylesheet'
link2.href = 'https://rsms.me/inter/inter.css'
// Add Fonts to main page
document.head.appendChild(link)
document.head.appendChild(link2)
}

// add to DOM
const onboard = document.createElement('onboard-v2')
Expand All @@ -268,8 +294,10 @@ function mountApp() {
onboard.style.all = 'initial'

target.innerHTML = `
<style>
:host {

<style>

:host {
/* COLORS */
--white: white;
--black: black;
Expand Down Expand Up @@ -311,7 +339,7 @@ function mountApp() {
--warning-700: #664600;

/* FONTS */
--font-family-normal: Sofia Pro;
--font-family-normal: Inter;

--font-size-1: 3rem;
--font-size-2: 2.25rem;
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"webpack-dev-server": "4.7.4"
},
"dependencies": {
"@web3-onboard/core": "^2.15.5",
"@web3-onboard/core": "^2.16.0-alpha.1",
"@web3-onboard/coinbase": "^2.1.4",
"@web3-onboard/transaction-preview": "^2.0.4",
"@web3-onboard/dcent": "^2.2.3",
Expand Down
Loading