-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from josefaidt/next
- Loading branch information
Showing
12 changed files
with
136 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules | |
/lib | ||
|
||
.vercel | ||
coverage |
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,2 +1,3 @@ | ||
export { default as ThemeWrapper } from './ThemeWrapper.svelte' | ||
export { default as ThemeToggle } from './ThemeToggle.svelte' | ||
export { presets } from './presets.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,31 @@ | ||
import { createCSSVariableCollection } from '../support/css' | ||
|
||
/** | ||
* | ||
* @param {HTMLElement} node | ||
* @param {Object.<string, string|number>} theme | ||
* @returns | ||
*/ | ||
export async function theme(node, theme) { | ||
/** | ||
* | ||
* @param {string} name | ||
* @param {string} value | ||
* @returns {void} | ||
*/ | ||
function setProperty(name, value) { | ||
if (!node.style && node.document?.documentElement) { | ||
node.document.documentElement.style.setProperty(name, value) | ||
return | ||
} | ||
node.style.setProperty(name, value) | ||
return | ||
} | ||
|
||
const variables = createCSSVariableCollection(theme) | ||
for (let [name, value] of variables) { | ||
setProperty(name, value) | ||
} | ||
|
||
return {} | ||
} |
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,11 @@ | ||
export function render(Component, props = {}) { | ||
const host = document.createElement('div') | ||
host.setAttribute('id', 'host') | ||
document.body.appendChild(host) | ||
const instance = new Component({ target: host, props }) | ||
return instance | ||
} | ||
|
||
export function getByTestId(id) { | ||
return document.querySelector(`[data-testid="${id}"]`) | ||
} |
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,24 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import UseComponent from './use.test.svelte' | ||
import { render as _render, getByTestId } from './support.js' | ||
|
||
function render(props = {}) { | ||
return _render(UseComponent, props) | ||
} | ||
|
||
describe('Theme Action', () => { | ||
it('should render', () => { | ||
const instance = render() | ||
expect(instance).toBeTruthy() | ||
}) | ||
|
||
it('should create inline styles', () => { | ||
const myTheme = { | ||
text: 'red', | ||
} | ||
const instance = render({ myTheme }) | ||
const container = getByTestId('container') | ||
expect(container.style).toBeTruthy() | ||
expect(container.style.getPropertyValue('--text')).toBe('red') | ||
}) | ||
}) |
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,16 @@ | ||
<script> | ||
import { theme } from '../components/use' | ||
export let myTheme = { | ||
text: 'red', | ||
} | ||
</script> | ||
|
||
<div use:theme="{myTheme}" data-testid="container"> | ||
<p data-testid="paragraph">Hello, World!</p> | ||
</div> | ||
|
||
<style> | ||
p { | ||
color: var(--text); | ||
} | ||
</style> |
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,2 +1,3 @@ | ||
export { default as ThemeWrapper } from "./ThemeWrapper.svelte"; | ||
export { default as ThemeToggle } from "./ThemeToggle.svelte"; | ||
export { default as presets } from "./presets.js"; |
8f89ec1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: