-
Notifications
You must be signed in to change notification settings - Fork 26
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
Showing
15 changed files
with
171 additions
and
67 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import './style.styl' | ||
import '@/tweeq/style.styl' | ||
|
||
import {createApp} from 'vue' | ||
|
||
|
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,2 @@ | ||
import RoundButton from './RoundButton.vue' | ||
export default RoundButton |
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,8 @@ | ||
font-numeric() | ||
font-family var(--tq-font-numeric) | ||
font-variant-numeric tabular-nums | ||
|
||
pane() | ||
border 1px solid var(--tq-color-pane-border) | ||
background var(--tq-color-pane) | ||
backdrop-filter blur(4px) |
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 @@ | ||
export {useTweeq} from './useTweeq' |
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,97 @@ | ||
import { | ||
applyTheme, | ||
argbFromHex, | ||
hexFromArgb, | ||
themeFromSourceColor, | ||
} from '@material/material-color-utilities' | ||
import {kebab} from 'case' | ||
import {inject, InjectionKey, provide, Ref} from 'vue' | ||
|
||
export interface Theme { | ||
// Colors | ||
colorPrimary: string | ||
colorOnPrimary: string | ||
colorPrimaryContainer: string | ||
colorOnPrimaryContainer: string | ||
colorBg: string | ||
colorText: string | ||
colorPane: string | ||
colorPaneBorder: string | ||
|
||
// Font | ||
fontCode: string | ||
fontHeading: string | ||
fontUi: string | ||
fontNumeric: string | ||
|
||
// UI Metrics | ||
paneBorderRadius: string | ||
inputHeight: string | ||
} | ||
|
||
const ThemeKey: InjectionKey<Theme> = Symbol('tqTheme') | ||
|
||
export function provideTheme(accentColor: Ref<string>) { | ||
// Get the theme from a hex color | ||
const materialTheme = themeFromSourceColor(argbFromHex(accentColor.value)) | ||
|
||
const dark = false | ||
|
||
const scheme = dark ? materialTheme.schemes.dark : materialTheme.schemes.light | ||
|
||
const theme: Theme = { | ||
colorPrimary: toColor(scheme.primary), | ||
colorPrimaryContainer: toColor(scheme.primaryContainer), | ||
colorOnPrimaryContainer: toColor(scheme.onPrimaryContainer), | ||
colorOnPrimary: toColor(scheme.onPrimary), | ||
colorText: toColor(scheme.onBackground), | ||
colorBg: toColor(scheme.background), | ||
colorPane: toColor(scheme.background, 0.95), | ||
colorPaneBorder: toColor(scheme.onBackground, 0.12), | ||
|
||
fontCode: "'Fira Code', monospace", | ||
fontHeading: 'Inter, sans-serif', | ||
fontUi: 'Inter, system-ui, sans-serif', | ||
fontNumeric: 'Inter, system-ui, sans-serif', | ||
|
||
paneBorderRadius: '20px', | ||
inputHeight: '16px', | ||
} | ||
|
||
// Promote all | ||
for (const [key, value] of Object.entries(theme)) { | ||
const varName = '--tq-' + kebab(key) | ||
document.body.style.setProperty(varName, value) | ||
} | ||
|
||
provide(ThemeKey, theme) | ||
|
||
// Apply the theme to the body by updating custom properties for material tokens | ||
applyTheme(materialTheme, {target: document.body, dark}) | ||
|
||
return theme | ||
} | ||
|
||
// function | ||
|
||
function toColor(color: number, opacity?: number) { | ||
let alpha = '' | ||
|
||
if (opacity !== undefined) { | ||
alpha = Math.round(opacity * 255) | ||
.toString(16) | ||
.padStart(2, '0') | ||
} | ||
|
||
return `${hexFromArgb(color)}${alpha}` | ||
} | ||
|
||
export function useTheme() { | ||
const theme = inject(ThemeKey) | ||
|
||
if (!theme) { | ||
throw new Error('theme is not provided') | ||
} | ||
|
||
return theme | ||
} |
Oops, something went wrong.