Skip to content

Commit

Permalink
Merge pull request #31 from nicolaswalcker/adaptative-course-shadow
Browse files Browse the repository at this point in the history
feat: change top shadow based course card image
  • Loading branch information
BernardoSM authored Nov 13, 2023
2 parents fb8af5f + 87585a7 commit 4de33f5
Show file tree
Hide file tree
Showing 6 changed files with 531 additions and 5 deletions.
17 changes: 15 additions & 2 deletions apps/app/components/molecules/TopBar.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<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>
Expand All @@ -11,10 +18,16 @@ const defaultAsideStore = useDefaultAsideStore();
>
<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 4de33f5

Please sign in to comment.