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

Get theme working with web components #102

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@userfront/toolkit",
"version": "1.1.0-alpha.0",
"version": "1.1.0-alpha.1",
"description": "Bindings and components for authentication with Userfront with React, Vue, other frameworks, and plain JS + HTML",
"type": "module",
"directories": {
Expand Down
30 changes: 15 additions & 15 deletions package/src/forms/UniversalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ const componentForStep = (state) => {
};

const UniversalForm = ({
theme = {},
theme,
state,
isDemo = false,
demoState = "live",
Expand All @@ -590,48 +590,48 @@ const UniversalForm = ({
// Build the theme

// Define CSS variables
const themeColors = theme.colors || {};
const themeColors = theme?.colors;
const style = {
"--userfront-light-color": themeColors.light || "#ffffff",
"--userfront-dark-color": themeColors.dark || "#5e72e4",
"--userfront-accent-color": themeColors.accent || "#13a0ff",
"--userfront-light-color": themeColors?.light || "#ffffff",
"--userfront-dark-color": themeColors?.dark || "#5e72e4",
"--userfront-accent-color": themeColors?.accent || "#13a0ff",
};
if (themeColors.lightBackground) {
if (themeColors?.lightBackground) {
style["--userfront-light-background-color"] = themeColors.lightBackground;
}
if (themeColors.darkBackground) {
if (themeColors?.darkBackground) {
style["--userfront-dark-background-color"] = themeColors.darkBackground;
}
if (theme.fontFamily) {
if (theme?.fontFamily) {
style["--userfront-font-family"] = theme.fontFamily;
}

// Classes for color schemes
// For now, "light scheme only" is default, to match existing behavior.
// In a future iteration "auto scheme" should be made default
let colorSchemeClass = "userfront-light-scheme";
if (theme.colorScheme === "dark") {
if (theme?.colorScheme === "dark") {
colorSchemeClass = "userfront-dark-scheme";
}
if (theme.colorScheme === "auto") {
if (theme?.colorScheme === "auto") {
colorSchemeClass = "userfront-auto-scheme";
}

// CSS variables for sizing
if (theme.size === "compact") {
if (theme?.size === "compact") {
style["--userfront-em-size"] = "14px";
style["--userfront-spacing"] = "0.5em";
}
if (theme.size === "mini") {
if (theme?.size === "mini") {
style["--userfront-em-size"] = "12px";
style["--userfront-spacing"] = "0.5em";
style["--userfront-container-width"] = "250px";
}
if (theme.size === "spaced") {
if (theme?.size === "spaced") {
style["--userfront-em-size"] = "14px";
style["--userfront-spacing"] = "20px";
}
if (theme.size === "large") {
if (theme?.size === "large") {
style["--userfront-em-size"] = "20px";
style["--userfront-spacing"] = "18px";
}
Expand All @@ -644,7 +644,7 @@ const UniversalForm = ({
raisedButtons: "userfront-raised-buttons",
dottedOutlines: "userfront-dotted-outlines",
};
const extras = theme.extras || {};
const extras = theme?.extras || {};
let customizationClasses = "";
Object.entries(extras)
.filter(([key, val]) => Boolean(val))
Expand Down
4 changes: 4 additions & 0 deletions package/src/web-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (typeof window === "object" && window.customElements) {
props: {
tenantId: "string",
flow: "json",
theme: "json",
compact: "boolean",
redirect: "string",
redirectOnLoadIfLoggedIn: "boolean",
Expand All @@ -37,6 +38,7 @@ if (typeof window === "object" && window.customElements) {
props: {
tenantId: "string",
flow: "json",
theme: "json",
compact: "boolean",
redirect: "string",
redirectOnLoadIfLoggedIn: "boolean",
Expand All @@ -51,6 +53,7 @@ if (typeof window === "object" && window.customElements) {
props: {
tenantId: "string",
flow: "json",
theme: "json",
compact: "boolean",
redirect: "string",
redirectOnLoadIfLoggedIn: "boolean",
Expand All @@ -65,6 +68,7 @@ if (typeof window === "object" && window.customElements) {
props: {
disabled: "boolean",
redirect: "string",
theme: "json",
},
})
);
Expand Down
Loading