Skip to content

Commit

Permalink
pull from main
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoSM committed Nov 14, 2023
2 parents 61cd6b0 + 4de33f5 commit 3510b42
Show file tree
Hide file tree
Showing 7 changed files with 471 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.language": "en,pt,pt-BR",
"cSpell.enabledLanguageIds": ["javascript", "typescript"],
"cSpell.words": ["nuxt", "menthor", "ofetch", "menthorlabs", "sakura", "pinia"],
"cSpell.words": ["nuxt", "menthor", "ofetch", "menthorlabs", "sakura", "pinia", "colorthief"],
}
18 changes: 16 additions & 2 deletions apps/app/components/molecules/TopBar.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
<script setup lang="ts">
import { Color } from "colorthief";
const router = useRouter();
const sessionStore = useSessionStore();
const userStore = useUserStore();
const defaultAsideStore = useDefaultAsideStore();
const shadowStore = useShadowStore();
const shadowGenerator = (color: Array<Color>): string => {
return `radial-gradient(50% 50% at 50% 50%, rgba(${color[0][0]}, ${color[0][1]}, ${color[0][2]}, 0.2) 0%, rgba(${color[0][0]}, ${color[0][1]}, ${color[0][2]}, 0) 100%)`;
};
</script>

<template>
<div
class="absolute left-0 top-0 flex h-[90px] w-full justify-center overflow-hidden pointer-events-none"
v-if="shadowStore.primaryColors && shadowStore.secondaryColors"
>
<div class="relative h-full w-full max-w-[1017px]">
<div
class="bg-[radial-gradient(50%_50%_at_50%_50%,_rgba(236,_72,_153,_0.2)_0%,_rgba(236,_72,_153,_0)_100%)] absolute bottom-0 left-0 h-[179px] w-[678px]"
class="absolute bottom-0 left-0 h-[179px] w-[678px]"
:style="{
background: shadowGenerator(shadowStore.primaryColors),
}"
></div>
<div
class="bg-[radial-gradient(50%_50%_at_50%_50%,_rgba(37,_99,_235,_0.2)_0%,_rgba(28,_100,_242,_0)_100%)] absolute bottom-0 right-0 h-[179px] w-[678px]"
class="absolute bottom-0 right-0 h-[179px] w-[678px]"
:style="{
background: shadowGenerator(shadowStore.secondaryColors),
}"
></div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@nuxt/content": "npm:@nuxt/content-edge@latest",
"@nuxtjs/fontaine": "^0.2.5",
"@types/node": "^20.4.6",
"colorthief": "^2.4.0",
"nuxt": "^3.7.3",
"nuxt-schema-org": "^2.1.3",
"typescript": "^5.1.6"
Expand Down
18 changes: 18 additions & 0 deletions apps/app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<script setup lang="ts">
import ColorThief, { Color } from "colorthief";
const userStore = useUserStore();
const shadowStore = useShadowStore();
const title = computed(() => {
return `Olá${
userStore.user?.firstName ? `, ${userStore.user.firstName}` : ""
}, o que vamos aprender hoje?`;
});
const checkEnter = (param: string) => {
const img = new Image();
img.src = param;
img.crossOrigin = "Anonymous";
img.onload = () => {
const colorThief = new ColorThief();
const colors: Color[] = colorThief.getPalette(img);
shadowStore.setColor(colors);
};
};
const checkLeave = () => {
shadowStore.setDefaultColors();
};
const description =
"Plataforma gratuita de ensino de programação web para pessoas que estão buscando o primeiro emprego na área ou que querem construir seu próprio negócio.";
useSeoMeta({
Expand Down Expand Up @@ -36,6 +52,8 @@ useSeoMeta({
<NuxtLink
v-for="item of navigation"
:key="item._path"
@mouseenter="checkEnter(item.image)"
@mouseleave="checkLeave()"
:nav-item="item"
:href="
item.children && item.children[0].children
Expand Down
35 changes: 35 additions & 0 deletions apps/app/stores/utils/shadow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { defineStore } from "pinia";
import { Color } from "colorthief";

const DEFAULT_COLORS: Array<Color> = [
[236, 72, 153],
[236, 72, 153],
[37, 99, 235],
[28, 100, 242],
];
export const useShadowStore = defineStore("shadow", {
state: (): { colors: Array<Color> | null } => ({
colors: DEFAULT_COLORS,
}),
getters: {
primaryColors(state): Color[] | undefined {
return state.colors?.slice(0, 2);
},
secondaryColors(state): Color[] | undefined {
return state.colors?.slice(2, 4);
},
},
actions: {
setColor(colors: Array<Color> | null) {
if (!colors) {
this.colors = null;
return;
}

this.colors = colors;
},
setDefaultColors() {
this.colors = DEFAULT_COLORS;
},
},
});
7 changes: 7 additions & 0 deletions apps/app/types/colorthief.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module "colorthief" {
type Color = [number, number, number];
export default class ColorThief {
getColor: (img: HTMLImageElement | null) => Color;
getPalette: (img: HTMLImageElement | null) => Color[];
}
}
Loading

0 comments on commit 3510b42

Please sign in to comment.