mirror of
https://github.com/letieu/terminal.css.git
synced 2026-03-15 02:04:30 -07:00
theme
This commit is contained in:
@@ -28,7 +28,12 @@
|
||||
<div class="has-text-muted text-sm font-bold">dev@localhost:~/</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<label for="theme-selector" class="has-text-muted text-xs">Theme:</label>
|
||||
<select id="theme-selector" class="select" style="width: auto;">
|
||||
<select
|
||||
id="theme-selector"
|
||||
class="select"
|
||||
style="width: auto;"
|
||||
onchange="document.getElementById('theme-switcher').setAttribute('href', 'themes/' + this.value + '.css');"
|
||||
>
|
||||
<option value="default">Default</option>
|
||||
<option value="dracula">Dracula</option>
|
||||
<option value="light">Light</option>
|
||||
|
||||
74
index.js
74
index.js
@@ -10,16 +10,16 @@
|
||||
*/
|
||||
function toggleFaq(element) {
|
||||
const faqItem = element.parentElement;
|
||||
const wasActive = faqItem.classList.contains('is-active');
|
||||
|
||||
const wasActive = faqItem.classList.contains("is-active");
|
||||
|
||||
// Close all FAQ items
|
||||
document.querySelectorAll('.faq-item').forEach(item => {
|
||||
item.classList.remove('is-active');
|
||||
document.querySelectorAll(".faq-item").forEach((item) => {
|
||||
item.classList.remove("is-active");
|
||||
});
|
||||
|
||||
|
||||
// Open clicked item if it wasn't active
|
||||
if (!wasActive) {
|
||||
faqItem.classList.add('is-active');
|
||||
faqItem.classList.add("is-active");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,35 +31,35 @@ function toggleFaq(element) {
|
||||
* @param {number} duration - Duration in milliseconds (default: 5000)
|
||||
*/
|
||||
function showToast(type, title, message, duration = 5000) {
|
||||
const container = document.getElementById('toastContainer');
|
||||
|
||||
const container = document.getElementById("toastContainer");
|
||||
|
||||
// Create toast element
|
||||
const toast = document.createElement('div');
|
||||
const toast = document.createElement("div");
|
||||
toast.className = `toast is-${type}`;
|
||||
|
||||
|
||||
// Icon mapping
|
||||
const icons = {
|
||||
primary: '▸',
|
||||
success: '✓',
|
||||
danger: '✕',
|
||||
warning: '⚠',
|
||||
info: 'ℹ'
|
||||
primary: "▸",
|
||||
success: "✓",
|
||||
danger: "✕",
|
||||
warning: "⚠",
|
||||
info: "ℹ",
|
||||
};
|
||||
|
||||
|
||||
toast.innerHTML = `
|
||||
<div class="toast-icon">${icons[type] || '▸'}</div>
|
||||
<div class="toast-icon">${icons[type] || "▸"}</div>
|
||||
<div class="toast-content">
|
||||
<div class="toast-title">${title}</div>
|
||||
<div class="toast-message">${message}</div>
|
||||
</div>
|
||||
<button class="toast-close" onclick="dismissToast(this)">×</button>
|
||||
`;
|
||||
|
||||
|
||||
container.appendChild(toast);
|
||||
|
||||
|
||||
// Auto dismiss after duration
|
||||
setTimeout(() => {
|
||||
dismissToast(toast.querySelector('.toast-close'));
|
||||
dismissToast(toast.querySelector(".toast-close"));
|
||||
}, duration);
|
||||
}
|
||||
|
||||
@@ -68,41 +68,13 @@ function showToast(type, title, message, duration = 5000) {
|
||||
* @param {HTMLElement} closeButton - The close button element that was clicked
|
||||
*/
|
||||
function dismissToast(closeButton) {
|
||||
const toast = closeButton.closest('.toast');
|
||||
const toast = closeButton.closest(".toast");
|
||||
if (toast) {
|
||||
toast.classList.add('is-dismissing');
|
||||
|
||||
toast.classList.add("is-dismissing");
|
||||
|
||||
// Remove from DOM after animation
|
||||
setTimeout(() => {
|
||||
toast.remove();
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
|
||||
function initializeThemeSwitcher() {
|
||||
const themeSelector = document.getElementById("theme-selector");
|
||||
const themeSwitcher = document.getElementById("theme-switcher");
|
||||
|
||||
if (!themeSwitcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
function applyTheme(theme) {
|
||||
themeSwitcher.setAttribute("href", `themes/${theme}.css`);
|
||||
localStorage.setItem("theme", theme);
|
||||
if (themeSelector) {
|
||||
themeSelector.value = theme;
|
||||
}
|
||||
}
|
||||
|
||||
if (themeSelector) {
|
||||
themeSelector.addEventListener("change", () => {
|
||||
applyTheme(themeSelector.value);
|
||||
});
|
||||
}
|
||||
|
||||
const savedTheme = localStorage.getItem("theme") || "default";
|
||||
applyTheme(savedTheme);
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", initializeThemeSwitcher);
|
||||
@@ -29,8 +29,15 @@
|
||||
dev@localhost:~/tcss/installation
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<label for="theme-selector" class="has-text-muted text-xs">Theme:</label>
|
||||
<select id="theme-selector" class="select" style="width: auto;">
|
||||
<label for="theme-selector" class="has-text-muted text-xs"
|
||||
>Theme:</label
|
||||
>
|
||||
<select
|
||||
id="theme-selector"
|
||||
class="select"
|
||||
style="width: auto"
|
||||
onchange="document.getElementById('theme-switcher').setAttribute('href', 'themes/' + this.value + '.css');"
|
||||
>
|
||||
<option value="default">Default</option>
|
||||
<option value="dracula">Dracula</option>
|
||||
<option value="light">Light</option>
|
||||
@@ -88,14 +95,21 @@
|
||||
/></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"> </span>
|
||||
<div class="terminal-log-line mt-4">
|
||||
<span class="terminal-log-message has-text-muted"
|
||||
><!-- [Optional: Theme] --></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message has-text-muted"
|
||||
><!-- Before closing </body> tag --></span
|
||||
<span class="terminal-log-message"
|
||||
><link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/gh/letieu/terminal.css@v0.0.3/themes/gruvbox-dark.css"
|
||||
/></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"> </span>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message has-text-muted"
|
||||
><!-- [Optional: Only for toast, FAQ component]
|
||||
@@ -407,97 +421,6 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- SECTION 4: THEMEING -->
|
||||
<section class="section">
|
||||
<div class="flex items-center gap-2 mb-6">
|
||||
<span class="has-text-primary text-xl font-bold">04.</span>
|
||||
<h2 class="text-xl font-bold">Theming</h2>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<p class="has-text-muted">
|
||||
terminal.css includes a theming system that allows you to easily switch between different color schemes. The selected theme is persisted across pages using the browser's <code>localStorage</code>.
|
||||
</p>
|
||||
|
||||
<h4 class="has-text-muted text-sm mb-3">How to use themes:</h4>
|
||||
<ol class="content">
|
||||
<li class="mb-2">
|
||||
Include the main <code>index.css</code> stylesheet and then a theme stylesheet in your <code><head></code> section. The theme stylesheet must have the ID <code>theme-switcher</code>.
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<div class="terminal-log">
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message has-text-muted"
|
||||
><!-- In your <head> section --></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
><link rel="stylesheet" href="./index.css" /></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
><link rel="stylesheet" href="themes/default.css" id="theme-switcher" /></span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="has-text-muted text-sm mt-4">
|
||||
To enable theme switching and persistence, include the <code>index.js</code> script at the end of your <code><body></code> tag. This script contains the necessary logic to manage themes.
|
||||
</p>
|
||||
|
||||
<div class="terminal-log">
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message has-text-muted"
|
||||
><!-- Before closing </body> tag --></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
><script src="./index.js"></script></span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="has-text-muted text-sm mt-4">
|
||||
You can then add a theme selector dropdown to your HTML, like this:
|
||||
</p>
|
||||
|
||||
<div class="terminal-log">
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
><select id="theme-selector" class="select"></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
> <option value="default">Default</option></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
> <option value="dracula">Dracula</option></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
> <option value="light">Light</option></span
|
||||
>
|
||||
</div>
|
||||
<div class="terminal-log-line">
|
||||
<span class="terminal-log-message"
|
||||
></select></span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<p class="has-text-muted text-sm mt-4">
|
||||
The <code>value</code> attribute of each option should match the filename of the theme (e.g., <code>default</code> for <code>themes/default.css</code>).
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- FOOTER -->
|
||||
<div class="pt-12 mt-12 border-t border-gray-800">
|
||||
<div class="flex justify-between items-center">
|
||||
|
||||
@@ -63,8 +63,15 @@
|
||||
<div class="flex gap-3 justify-center items-center">
|
||||
<a href="./index.html" class="button is-primary">Get Started</a>
|
||||
<div class="flex items-center gap-2">
|
||||
<label for="theme-selector" class="has-text-muted text-xs">Theme:</label>
|
||||
<select id="theme-selector" class="select" style="width: auto;">
|
||||
<label for="theme-selector" class="has-text-muted text-xs"
|
||||
>Theme:</label
|
||||
>
|
||||
<select
|
||||
id="theme-selector"
|
||||
class="select"
|
||||
style="width: auto"
|
||||
onchange="document.getElementById('theme-switcher').setAttribute('href', 'themes/' + this.value + '.css');"
|
||||
>
|
||||
<option value="default">Default</option>
|
||||
<option value="dracula">Dracula</option>
|
||||
<option value="light">Light</option>
|
||||
|
||||
Reference in New Issue
Block a user