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

Theme tweak #4402

Merged
merged 6 commits into from
Sep 20, 2023
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
3 changes: 3 additions & 0 deletions frontend/app/src/components/MenuIcon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
menuStore.hideMenu();
} else {
const rect = menu.getBoundingClientRect();
console.log("ContextMenu: ", contextMenu);
megrogan marked this conversation as resolved.
Show resolved Hide resolved
menuStore.showMenu(contextMenu);

await tick();

console.log("Pos: ", rect, centered, position, align, gutter);
menuStore.position(rect, centered, position, align, gutter);
}
}
Expand All @@ -35,6 +37,7 @@
}

function closeMenu() {
console.log("is this happening for some reason");
menuStore.hideMenu();
}
</script>
Expand Down
106 changes: 106 additions & 0 deletions frontend/app/src/components/home/profile/ThemeButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<script lang="ts">
import { _ } from "svelte-i18n";
import ChevronDown from "svelte-material-icons/ChevronDown.svelte";
import Legend from "../../Legend.svelte";
import MenuIcon from "../../MenuIcon.svelte";
import Menu from "../../Menu.svelte";
import MenuItem from "../../MenuItem.svelte";
import { iconSize } from "../../../stores/iconSize";
import { AvatarSize, OpenChat } from "openchat-client";
import Avatar from "../../Avatar.svelte";
import type { Theme } from "../../../theme/types";
import { createEventDispatcher, getContext } from "svelte";
import type { Alignment } from "../../../utils/alignment";

const dispatch = createEventDispatcher();
const client = getContext<OpenChat>("client");

export let theme: Theme;
export let otherThemes: Theme[];
export let label: string;
export let align: Alignment;

$: userStore = client.userStore;

function onSelect(name: string) {
dispatch("select", name);
}
</script>

<div class="theme-wrapper">
<Legend {label} />
<MenuIcon gutter={0} position="bottom" {align}>
<div
tabindex="0"
role="button"
slot="icon"
class="theme"
style={`background: ${theme.bg}; border-color: ${theme.accent}`}>
<div style={`color: ${theme.txt}`} class="theme-txt">
{theme.label}
</div>

<div class="icon">
<ChevronDown viewBox={"0 -3 24 24"} size={$iconSize} color={`${theme.accent}`} />
</div>
</div>
<span slot="menu">
<Menu>
{#each otherThemes as theme}
<MenuItem on:click={() => onSelect(theme.name)}>
<div class="theme-item" slot="text">
<div class="label">{theme.label}</div>
{#if theme.author !== undefined && $userStore[theme.author] !== undefined}
<div class="avatar">
<Avatar
url={client.userAvatarUrl($userStore[theme.author])}
userId={theme.author}
size={AvatarSize.Tiny} />
</div>
{/if}
</div>
</MenuItem>
{/each}
</Menu>
</span>
</MenuIcon>
</div>

<style lang="scss">
.theme-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: $sp3;
width: 100%;
}

.theme-txt {
@include ellipsis();
}

.icon {
flex: 0 0 24px;
}

.theme-wrapper {
flex: 1;
}

.theme {
text-align: center;
padding: 36px 22px;
height: 65px;
color: #fff;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
gap: $sp2;
border-bottom: $sp2 solid var(--accent);

@include mobile() {
padding: 12px;
}
}
</style>
137 changes: 23 additions & 114 deletions frontend/app/src/components/home/profile/ThemeSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,17 @@
themes,
themeType,
} from "../../../theme/themes";
import ChevronDown from "svelte-material-icons/ChevronDown.svelte";
import Legend from "../../Legend.svelte";
import { getContext, onMount } from "svelte";
import { onMount } from "svelte";
import type { Theme } from "../../../theme/types";
import MenuIcon from "../../MenuIcon.svelte";
import Menu from "../../Menu.svelte";
import MenuItem from "../../MenuItem.svelte";
import { iconSize } from "../../../stores/iconSize";
import ButtonGroup from "../../ButtonGroup.svelte";
import Button from "../../Button.svelte";
import { AvatarSize, type OpenChat } from "openchat-client";
import Avatar from "../../Avatar.svelte";

const client = getContext<OpenChat>("client");

$: userStore = client.userStore;
import ThemeButton from "./ThemeButton.svelte";

type PartitionedThemes = {
light: Theme[];
dark: Theme[];
};

let lightMenu: MenuIcon;
let darkMenu: MenuIcon;

let partitionedThemes: PartitionedThemes = {
light: [],
dark: [],
Expand All @@ -49,6 +35,14 @@
return p;
}, partitionedThemes);
});

function selectLightTheme(ev: CustomEvent<string>) {
preferredLightThemeName.set(ev.detail);
}

function selectDarkTheme(ev: CustomEvent<string>) {
preferredDarkThemeName.set(ev.detail);
}
</script>

<div class="theme-buttons">
Expand All @@ -63,93 +57,24 @@
</div>

<div class="theme-selection">
<div class="theme-wrapper">
<Legend label={$_("theme.preferredLightTheme")} />
<div
tabindex="0"
role="button"
class="theme"
on:click={() => lightMenu.showMenu()}
style={`background: ${$preferredLightTheme.bg}; border-color: ${$preferredLightTheme.accent}`}>
<span style={`color: ${$preferredLightTheme.txt}`} class="theme-txt">
{$preferredLightTheme.label}
</span>

<MenuIcon bind:this={lightMenu} position="bottom" align="end">
<span class="icon" slot="icon">
<ChevronDown
viewBox={"0 -3 24 24"}
size={$iconSize}
color={`${$preferredLightTheme.accent}`} />
</span>
<span slot="menu">
<Menu>
{#each partitionedThemes.light as theme}
<MenuItem on:click={() => preferredLightThemeName.set(theme.name)}>
<div slot="text">
{theme.label}
</div>
</MenuItem>
{/each}
</Menu>
</span>
</MenuIcon>
</div>
</div>
<div class="theme-wrapper">
<Legend label={$_("theme.preferredDarkTheme")} />
<div
tabindex="0"
role="button"
class="theme"
on:click={() => darkMenu.showMenu()}
style={`background: ${$preferredDarkTheme.bg}; border-color: ${$preferredDarkTheme.accent}`}>
<span style={`color: ${$preferredDarkTheme.txt}`} class="theme-txt">
{$preferredDarkTheme.label}
</span>

<MenuIcon bind:this={darkMenu} position="bottom" align="end">
<span class="icon" slot="icon">
<ChevronDown
viewBox={"0 -3 24 24"}
size={$iconSize}
color={`${$preferredDarkTheme.accent}`} />
</span>
<span slot="menu">
<Menu>
{#each partitionedThemes.dark as theme}
<MenuItem on:click={() => preferredDarkThemeName.set(theme.name)}>
<div class="theme-item" slot="text">
<div class="label">{theme.label}</div>
{#if theme.author !== undefined && $userStore[theme.author] !== undefined}
<div class="avatar">
<Avatar
url={client.userAvatarUrl($userStore[theme.author])}
userId={theme.author}
size={AvatarSize.Tiny} />
</div>
{/if}
</div>
</MenuItem>
{/each}
</Menu>
</span>
</MenuIcon>
</div>
</div>
<ThemeButton
align={"start"}
on:select={selectLightTheme}
label={$_("theme.preferredLightTheme")}
theme={$preferredLightTheme}
otherThemes={partitionedThemes.light} />
<ThemeButton
align={"end"}
on:select={selectDarkTheme}
label={$_("theme.preferredDarkTheme")}
theme={$preferredDarkTheme}
otherThemes={partitionedThemes.dark} />
</div>

<style lang="scss">
:global(.theme-buttons button) {
min-width: 0 !important;
}

.theme-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: $sp3;
width: 100%;
padding: unset !important;
}

.theme-buttons {
Expand All @@ -161,21 +86,5 @@
align-items: center;
gap: $sp3;
margin-bottom: $sp4;
.theme-wrapper {
flex: 1;
}

.theme {
text-align: center;
padding: 22px;
height: 65px;
color: #fff;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
gap: $sp2;
border-bottom: $sp2 solid var(--accent);
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import DisplayNameInput from "../../DisplayNameInput.svelte";
import CommunityProfile from "./CommunityProfile.svelte";
import ThemeSelector from "./ThemeSelector.svelte";
import { menuCloser } from "../../../actions/closeMenu";

const client = getContext<OpenChat>("client");
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -241,7 +242,7 @@
</div>

{#if view === "global"}
<form class="user-form" on:submit|preventDefault={saveUser}>
<form use:menuCloser class="user-form" on:submit|preventDefault={saveUser}>
<div class="user">
<CollapsibleCard
on:toggle={userInfoOpen.toggle}
Expand Down
Loading
Loading