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

Feature: Added Random Mesh Gradient Background & LinkedIn Banner Ratio #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"eslint": "^8.51.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.34.0",
"meshgrad": "^0.0.15",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.10.1",
"sass": "^1.69.4",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

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

50 changes: 50 additions & 0 deletions src/lib/components/RegenerateGradientButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<script lang="ts">
import { generateMeshGradient } from 'meshgrad';

/**
* Represents 2 properties.
* 1. background-color : hsl(XXX, XXX%, XX%)
* 2. background-image : radial-gradient(...)
* Both are converted to string format (combined)
*/
export let value: string | null;
</script>

<button
aria-label="Refresh"
on:click={async () => {
value = generateMeshGradient(6);
}}
>
<span class="block i-tabler-refresh" aria-hidden />
</button>

<style lang="scss">
button {
@include border-gradient;
--p-border-radius: 0.5rem;
--p-border-gradient-before: linear-gradient(
to bottom,
hsl(var(--color-white-hsl) / 0.12) 0%,
hsl(var(--color-white-hsl) / 0) 100%
);

background: hsl(var(--color-white-hsl) / 0.08);

--p-size: 2.5rem;
width: var(--p-size);
height: var(--p-size);
display: grid;
place-items: center;

transition: 150ms ease;

&:hover {
background: hsl(var(--color-white-hsl) / 0.12);
}

&:active {
background: hsl(var(--color-white-hsl) / 0.1);
}
}
</style>
18 changes: 16 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { melt, type SelectOption } from '@melt-ui/svelte';
import { tick } from 'svelte';
import { fly } from 'svelte/transition';
import RegenerateGradientButton from '$lib/components/RegenerateGradientButton.svelte';

// Options
const langOptions: SelectOption<LanguagePreset>[] = [
Expand Down Expand Up @@ -59,6 +60,10 @@
{
label: 'Stories (IG, LinkedIn)',
value: '1080/1920'
},
{
label: 'LinkedIn Banner',
value: '1584/396'
}
];
let ratio = ratios[0].value;
Expand All @@ -68,11 +73,13 @@

const bgOptions: SelectOption<string>[] = [
{ label: 'BG Dark 1', value: 'bg-1.png' },
{ label: 'Custom', value: 'custom' }
{ label: 'Custom', value: 'custom' },
{ label: 'Random Mesh Gradient', value: 'random_mesh_gradient' },
];

let bg = bgOptions[0].value;
let customBg: string | null = null;
let randomGradientValue: string | null = null;

// Debug Info
$: trueRatio = (() => {
Expand Down Expand Up @@ -129,7 +136,13 @@
</div>
{/if}

<Popover>
{#if bg === 'random_mesh_gradient'}
<div class="self-end" transition:fly={{ duration: 150, y: 4 }}>
<RegenerateGradientButton bind:value={randomGradientValue} />
</div>
{/if}

<Popover>
<button
slot="trigger"
let:trigger
Expand Down Expand Up @@ -197,6 +210,7 @@
style:--p-ratio={ratio}
style:--p-resize={capturing ? 'none' : 'both'}
style:--p-bg="url({bg === 'custom' ? customBg : `/images/${bg}`})"
style={bg === 'random_mesh_gradient' ? randomGradientValue : null}
>
<div class="code-window" style:--p-scale={scale}>
<div class="flex gap-8 mis-8">
Expand Down