Skip to content

Commit b761835

Browse files
Merge PR #4 from dev-branch
feat: Replace Indigo with Primary-color. Also: add darkmode support a…
2 parents 78e5939 + c8260a1 commit b761835

File tree

9 files changed

+204
-146
lines changed

9 files changed

+204
-146
lines changed

assets/script.js

Lines changed: 87 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,93 @@
1-
document.addEventListener('DOMContentLoaded', async () => {
2-
const navContainer = document.getElementById('nav-container');
3-
const previewContainer = document.getElementById('preview-container');
4-
const codeContainer = document.getElementById('code-container');
5-
const titleEl = document.getElementById('component-title');
6-
const idEl = document.getElementById('component-id');
7-
const codeWrapper = document.getElementById('code-block-wrapper');
8-
9-
try {
10-
const response = await fetch('data/components.json');
11-
const components = await response.json();
12-
renderNavigation(components);
13-
} catch (error) {
14-
console.error('Failed to load library:', error);
15-
}
1+
function formatHTML(html) {
2+
if (!html) return '';
3+
4+
let formatted = html.replace(/>\s+</g, '><').trim();
5+
6+
formatted = formatted
7+
.replace(/(<(?!\/)(?!span|strong|b|i|em|small)[^>]+>)/g, '\n$1')
8+
.replace(/(<\/(?!span|strong|b|i|em|small)[^>]+>)/g, '\n$1')
9+
.replace(/\n\n/g, '\n');
1610

17-
function renderNavigation(components) {
18-
const categories = {};
19-
20-
components.forEach((c) => {
21-
if (!categories[c.category]) categories[c.category] = [];
22-
categories[c.category].push(c);
23-
});
24-
25-
Object.keys(categories).forEach((cat) => {
26-
const group = document.createElement('div');
27-
group.className = 'mb-6';
28-
29-
const title = document.createElement('h3');
30-
title.className =
31-
'text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-2';
32-
title.textContent = cat;
33-
group.appendChild(title);
34-
35-
categories[cat].forEach((item) => {
36-
const btn = document.createElement('button');
37-
btn.className =
38-
'w-full text-left px-3 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-100 hover:text-gray-900 transition-colors mb-1';
39-
btn.textContent = item.name;
40-
btn.onclick = () => loadComponent(item);
41-
group.appendChild(btn);
42-
});
43-
44-
navContainer.appendChild(group);
45-
});
46-
}
11+
const lines = formatted.split('\n');
12+
let indentLevel = 0;
13+
const tab = ' ';
14+
let result = '';
15+
16+
lines.forEach((line) => {
17+
line = line.trim();
18+
if (!line) return;
4719

48-
async function loadComponent(item) {
49-
try {
50-
const response = await fetch(item.path);
51-
const html = await response.text();
52-
53-
previewContainer.innerHTML = html;
54-
codeContainer.textContent = html;
55-
titleEl.textContent = item.name;
56-
idEl.textContent = item.id;
57-
codeWrapper.classList.remove('hidden');
58-
} catch (e) {
59-
previewContainer.innerHTML = '<span class="text-red-500">Error loading component</span>';
20+
const isClosing = line.match(/^<\//);
21+
const isSelfClosing = line.match(/\/>$/) || line.match(/^<(img|input|br|hr|meta|link)/);
22+
23+
if (isClosing && indentLevel > 0) {
24+
indentLevel--;
6025
}
61-
}
62-
});
26+
27+
result += tab.repeat(indentLevel) + line + '\n';
28+
29+
if (!isClosing && !isSelfClosing) {
30+
indentLevel++;
31+
}
32+
});
33+
34+
return result.trim();
35+
}
6336

6437
window.copyCode = () => {
6538
const code = document.getElementById('code-container').textContent;
66-
navigator.clipboard.writeText(code);
67-
alert('Copied to clipboard!');
68-
};
39+
navigator.clipboard.writeText(code).then(() => {
40+
alert('Snippet copied to clipboard');
41+
});
42+
};
43+
44+
function initTheme() {
45+
const savedTheme = localStorage.getItem('theme') || 'system';
46+
setTheme(savedTheme, false);
47+
}
48+
49+
window.setTheme = (mode, save = true) => {
50+
if (save) localStorage.setItem('theme', mode);
51+
52+
const isDark =
53+
mode === 'dark' ||
54+
(mode === 'system' &&
55+
window.matchMedia('(prefers-color-scheme: dark)').matches);
56+
57+
if (isDark) {
58+
document.documentElement.classList.add('dark');
59+
} else {
60+
document.documentElement.classList.remove('dark');
61+
}
62+
63+
updateThemeUI(mode);
64+
};
65+
66+
function updateThemeUI(mode) {
67+
const slider = document.getElementById('theme-slider');
68+
if (!slider) return;
69+
70+
const positions = {
71+
'system': '0px',
72+
'light': '28px',
73+
'dark': '56px'
74+
};
75+
76+
slider.style.transform = `translateX(${positions[mode]})`;
77+
}
78+
79+
document.addEventListener('DOMContentLoaded', () => {
80+
initTheme();
81+
82+
const codeContainer = document.getElementById('code-container');
83+
84+
if (window.COMPONENT_DATA && codeContainer) {
85+
codeContainer.textContent = formatHTML(window.COMPONENT_DATA);
86+
}
87+
});
88+
89+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
90+
if (localStorage.getItem('theme') === 'system') {
91+
setTheme('system', false);
92+
}
93+
});

components/auth/alternative-login-form.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="min-h-screen bg-gray-50 dark:bg-gray-950 flex flex-col justify-center py-12 sm:px-6 lg:px-8">
22
<div class="sm:mx-auto sm:w-full sm:max-w-md">
33
<div class="flex justify-center">
4-
<div class="h-12 w-12 rounded-xl bg-indigo-600 flex items-center justify-center shadow-lg shadow-indigo-500/20">
4+
<div class="h-12 w-12 rounded-xl bg-primary-600 flex items-center justify-center shadow-lg shadow-primary-500/20">
55
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-7 text-white">
66
<path stroke-linecap="round" stroke-linejoin="round" d="M16.5 10.5V6.75a4.5 4.5 0 1 0-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 0 0 2.25-2.25v-6.75a2.25 2.25 0 0 0-2.25-2.25H6.75a2.25 2.25 0 0 0-2.25 2.25v6.75a2.25 2.25 0 0 0 2.25 2.25Z" />
77
</svg>
@@ -10,7 +10,7 @@
1010
<h2 class="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900 dark:text-white">Welcome back</h2>
1111
<p class="mt-2 text-center text-sm text-gray-600 dark:text-gray-400">
1212
Don't have an account?
13-
<a href="#" class="font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400">Create one here</a>
13+
<a href="#" class="font-medium text-primary-600 hover:text-primary-500 dark:text-primary-400">Create one here</a>
1414
</p>
1515
</div>
1616

@@ -20,17 +20,17 @@ <h2 class="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900 dark
2020
<div>
2121
<label for="email" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Email address</label>
2222
<div class="mt-1">
23-
<input id="email" name="email" type="email" autocomplete="email" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm transition-all" placeholder="name@company.com">
23+
<input id="email" name="email" type="email" autocomplete="email" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 sm:text-sm transition-all" placeholder="name@company.com">
2424
</div>
2525
</div>
2626

2727
<div>
2828
<div class="flex items-center justify-between">
2929
<label for="password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Password</label>
30-
<a href="#" class="text-xs font-semibold text-indigo-600 dark:text-indigo-400 hover:text-indigo-500">Forgot password?</a>
30+
<a href="#" class="text-xs font-semibold text-primary-600 dark:text-primary-400 hover:text-primary-500">Forgot password?</a>
3131
</div>
3232
<div class="mt-1 relative group">
33-
<input id="password" name="password" type="password" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm transition-all" placeholder="••••••••">
33+
<input id="password" name="password" type="password" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 sm:text-sm transition-all" placeholder="••••••••">
3434
<button type="button" class="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors">
3535
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5">
3636
<path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" />
@@ -41,14 +41,14 @@ <h2 class="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900 dark
4141
</div>
4242

4343
<div class="flex items-center">
44-
<input id="remember-me" name="remember-me" type="checkbox" class="h-4 w-4 rounded border-gray-300 dark:border-gray-700 text-indigo-600 focus:ring-indigo-500 bg-white dark:bg-gray-800">
44+
<input id="remember-me" name="remember-me" type="checkbox" class="h-4 w-4 rounded border-gray-300 dark:border-gray-700 text-primary-600 focus:ring-primary-500 bg-white dark:bg-gray-800">
4545
<label for="remember-me" class="ml-2 block text-xs text-gray-700 dark:text-gray-400">
4646
Stay signed in for 30 days
4747
</label>
4848
</div>
4949

5050
<div>
51-
<button type="submit" class="group flex w-full justify-center items-center gap-2 rounded-lg bg-indigo-600 px-4 py-2.5 text-sm font-semibold text-white shadow-lg shadow-indigo-500/20 hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 transition-all active:scale-[0.98]">
51+
<button type="submit" class="group flex w-full justify-center items-center gap-2 rounded-lg bg-primary-600 px-4 py-2.5 text-sm font-semibold text-white shadow-lg shadow-primary-500/20 hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 transition-all active:scale-[0.98]">
5252
Sign in
5353
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-4 opacity-70 group-hover:translate-x-0.5 transition-transform">
5454
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3" />

components/auth/alternative-registration-form.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="sm:mx-auto sm:w-full sm:max-w-md">
33
<!-- Icon / Logo -->
44
<div class="flex justify-center">
5-
<div class="h-12 w-12 rounded-xl bg-indigo-600 flex items-center justify-center shadow-lg shadow-indigo-500/20">
5+
<div class="h-12 w-12 rounded-xl bg-primary-600 flex items-center justify-center shadow-lg shadow-primary-500/20">
66
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-7 text-white">
77
<path stroke-linecap="round" stroke-linejoin="round" d="M18 7.5v3m0 0v3m0-3h3m-3 0h-3m-2.25-4.125a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0ZM3 19.235v-.11a6.375 6.375 0 0 1 12.75 0v.109A12.318 12.318 0 0 1 9.374 21c-2.331 0-4.512-.645-6.374-1.766Z" />
88
</svg>
@@ -11,7 +11,7 @@
1111
<h2 class="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900 dark:text-white">Create an account</h2>
1212
<p class="mt-2 text-center text-sm text-gray-600 dark:text-gray-400">
1313
Already have one?
14-
<a href="#" class="font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400">Sign in here</a>
14+
<a href="#" class="font-medium text-primary-600 hover:text-primary-500 dark:text-primary-400">Sign in here</a>
1515
</p>
1616
</div>
1717

@@ -22,23 +22,23 @@ <h2 class="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900 dark
2222
<div>
2323
<label for="name" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Full Name</label>
2424
<div class="mt-1">
25-
<input id="name" name="name" type="text" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm transition-all" placeholder="Fabian Ternis">
25+
<input id="name" name="name" type="text" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 sm:text-sm transition-all" placeholder="Fabian Ternis">
2626
</div>
2727
</div>
2828

2929
<!-- Email Field -->
3030
<div>
3131
<label for="email" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Email address</label>
3232
<div class="mt-1">
33-
<input id="email" name="email" type="email" autocomplete="email" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm transition-all" placeholder="fabian@mtex.dev">
33+
<input id="email" name="email" type="email" autocomplete="email" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 sm:text-sm transition-all" placeholder="fabian@mtex.dev">
3434
</div>
3535
</div>
3636

3737
<!-- Password Field -->
3838
<div>
3939
<label for="password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Password</label>
4040
<div class="mt-1 relative group">
41-
<input id="password" name="password" type="password" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm transition-all" placeholder="••••••••">
41+
<input id="password" name="password" type="password" required class="block w-full appearance-none rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-white placeholder-gray-400 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 sm:text-sm transition-all" placeholder="••••••••">
4242
<!-- Icon Toggle (Visual Only in pure HTML) -->
4343
<button type="button" class="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors">
4444
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5">
@@ -51,15 +51,15 @@ <h2 class="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900 dark
5151

5252
<!-- Terms -->
5353
<div class="flex items-center">
54-
<input id="terms" name="terms" type="checkbox" class="h-4 w-4 rounded border-gray-300 dark:border-gray-700 text-indigo-600 focus:ring-indigo-500 bg-white dark:bg-gray-800">
54+
<input id="terms" name="terms" type="checkbox" class="h-4 w-4 rounded border-gray-300 dark:border-gray-700 text-primary-600 focus:ring-primary-500 bg-white dark:bg-gray-800">
5555
<label for="terms" class="ml-2 block text-xs text-gray-700 dark:text-gray-400">
56-
I agree to the <a href="#" class="text-indigo-600 dark:text-indigo-400 hover:underline">Terms</a> and <a href="#" class="text-indigo-600 dark:text-indigo-400 hover:underline">Privacy Policy</a>
56+
I agree to the <a href="#" class="text-primary-600 dark:text-primary-400 hover:underline">Terms</a> and <a href="#" class="text-primary-600 dark:text-primary-400 hover:underline">Privacy Policy</a>
5757
</label>
5858
</div>
5959

6060
<!-- Submit Button -->
6161
<div>
62-
<button type="submit" class="group flex w-full justify-center items-center gap-2 rounded-lg bg-indigo-600 px-4 py-2.5 text-sm font-semibold text-white shadow-lg shadow-indigo-500/20 hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 transition-all active:scale-[0.98]">
62+
<button type="submit" class="group flex w-full justify-center items-center gap-2 rounded-lg bg-primary-600 px-4 py-2.5 text-sm font-semibold text-white shadow-lg shadow-primary-500/20 hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 transition-all active:scale-[0.98]">
6363
Create Account
6464
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-4 opacity-70 group-hover:translate-x-0.5 transition-transform">
6565
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3" />

0 commit comments

Comments
 (0)