Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
feat: add colors [NOTICKET]
Browse files Browse the repository at this point in the history
  • Loading branch information
boostvolt committed Aug 6, 2023
1 parent 6d7b805 commit c374bbe
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 20 deletions.
9 changes: 2 additions & 7 deletions .eslintrc.cjs → .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
const fs = require("fs")

module.exports = {
extends: [
"next",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:tailwindcss/recommended",
],
extends: ["next", "prettier", "plugin:@typescript-eslint/recommended", "plugin:tailwindcss/recommended"],
parserOptions: {
babelOptions: {
presets: [require.resolve("next/babel")],
Expand Down Expand Up @@ -73,4 +68,4 @@ function getDirectories(path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + "/" + file).isDirectory()
})
}
}
File renamed without changes.
80 changes: 67 additions & 13 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
import html2canvas from "html2canvas"
import { Cog, Info } from "lucide-react"
import Image from "next/image"
import { useEffect } from "react"
import { useForm } from "react-hook-form"
import * as z from "zod"
import AppleMusic from "@/components/icons/apple-music"
Expand Down Expand Up @@ -36,11 +37,10 @@ const formSchema = z.object({
subTitle: z.string(),
footer: z.string(),
gradient: z.string(),
color: z.string(),
})

export default function Home() {


const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: formSchema.parse({
Expand All @@ -50,10 +50,11 @@ export default function Home() {
subTitle: "",
footer: "",
gradient: "0",
color: "",
}),
})
const { dirtyFields } = form.formState
const isEdited = dirtyFields.bigTitle ?? dirtyFields.subTitle ?? dirtyFields.footer
const isEdited = dirtyFields.bigTitle ?? dirtyFields.subTitle ?? dirtyFields.footer

const handleDownload = () => {
const element = document.getElementById("coverElement")
Expand All @@ -67,6 +68,10 @@ export default function Home() {
}
}

useEffect(() => {
form.setValue("color", "")
}, [form.watch("gradient")])

return (
<main className="flex justify-center">
<style jsx global>{`
Expand Down Expand Up @@ -116,7 +121,9 @@ export default function Home() {
<div id="coverElement" style={{ width: 300, height: 300, position: "relative" }}>
{/* Background Image */}
<Image
src={`/assets/gradients/${form.watch("gradient")}.png`}
src={`/assets/${
form.watch("color") === "" ? `gradients/${form.watch("gradient")}` : `colors/${form.watch("color")}`
}.png`}
loading="eager"
alt={`Gradient ${form.watch("gradient")}`}
layout="fill"
Expand All @@ -131,11 +138,15 @@ export default function Home() {
)}
{/* Big Title */}
<div style={{ position: "absolute", top: 55, left: 25 }}>
<h1 className="text-[3em] font-semibold text-white">{isEdited ? form.watch("bigTitle") : "Big Title"}</h1>
<h1 className="text-[3em] font-semibold text-white">
{isEdited ? form.watch("bigTitle") : "Big Title"}
</h1>
</div>
{/* Sub Title */}
<div style={{ position: "absolute", top: 105, left: 25 }}>
<h2 className="text-[2.5em] font-thin text-white">{isEdited ? form.watch("subTitle") : "Sub Title"}</h2>
<h2 className="text-[2.5em] font-thin text-white">
{isEdited ? form.watch("subTitle") : "Sub Title"}
</h2>
</div>
{/* Footer */}
<div style={{ position: "absolute", bottom: 25, left: 25 }}>
Expand Down Expand Up @@ -167,7 +178,11 @@ export default function Home() {
render={({ field }) => (
<FormItem>
<FormControl>
<Switch checked={field.value} onCheckedChange={field.onChange} title="Toggle Apple Music Logo"/>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
title="Toggle Apple Music Logo"
/>
</FormControl>
</FormItem>
)}
Expand Down Expand Up @@ -242,7 +257,12 @@ export default function Home() {
className="rounded-full border-2 border-muted bg-popover p-0.5 hover:cursor-pointer hover:bg-accent hover:text-accent-foreground [&:has([data-state=checked])]:border-primary"
>
<Avatar className="h-full w-full">
<RadioGroupItem value={`${index}`} id={`${index}`} className="sr-only" title={`Gradient ${index}`}/>
<RadioGroupItem
value={`${index}`}
id={`${index}`}
className="sr-only"
title={`Gradient ${index}`}
/>
<Image
src={`/assets/gradients/${index}.png`}
alt={`Gradient ${index}`}
Expand All @@ -259,11 +279,45 @@ export default function Home() {
/>
</TabsContent>
<TabsContent value="color" className="mt-4">
<Alert>
<Info className="h-4 w-4" />
<AlertTitle>Coming soon</AlertTitle>
<AlertDescription>Color selection will be available soon.</AlertDescription>
</Alert>
<FormField
control={form.control}
name="color"
render={({ field }) => (
<FormItem>
<FormControl>
<RadioGroup
onValueChange={field.onChange}
defaultValue={field.value}
className="grid grid-cols-5 gap-4"
>
{[...Array(7)].map((_, index) => (
<Label
key={index}
htmlFor={`${index}`}
className="rounded-full border-2 border-muted bg-popover p-0.5 hover:cursor-pointer hover:bg-accent hover:text-accent-foreground [&:has([data-state=checked])]:border-primary"
>
<Avatar className="h-full w-full">
<RadioGroupItem
value={`${index}`}
id={`${index}`}
className="sr-only"
title={`Color ${index}`}
/>
<Image
src={`/assets/colors/${index}.png`}
alt={`Color ${index}`}
width={70}
height={70}
/>
</Avatar>
</Label>
))}
</RadioGroup>
</FormControl>
</FormItem>
)}
/>
{/* <Input id="image" type="color" /> */}
</TabsContent>
<TabsContent value="image" className="mt-4">
<Alert>
Expand Down
Binary file added public/assets/colors/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/colors/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/colors/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/colors/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/colors/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/colors/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/colors/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c374bbe

Please sign in to comment.