Skip to content

Commit

Permalink
added font sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
kemo-1 committed Aug 16, 2024
1 parent 10913b3 commit 25d4396
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 30 deletions.
1 change: 1 addition & 0 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ starlight({
Search: "./src/components/starlight/Search.astro",
Sidebar: "./src/components/starlight/Sidebar.astro",
LastUpdated: "./src/components/starlight/LastUpdated.astro",
SiteTitle: "./src/components/starlight/SiteTitle.astro",
PageFrame: "./src/components/starlight/PageFrame.astro"
},
title: "سَنَابِلُ الْفِرْدَوْسِ",
Expand Down
55 changes: 55 additions & 0 deletions src/components/starlight/SiteTitle.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
import { logos } from 'virtual:starlight/user-images';
import config from 'virtual:starlight/user-config';
import type { Props } from '@astrojs/starlight/props';
const { siteTitle, siteTitleHref } = Astro.props;
---

<a href={siteTitleHref} class="site-title sl-flex">
{
config.logo && logos.dark && (
<>
<img
class:list={{ 'light:sl-hidden': !('src' in config.logo) }}
alt={config.logo.alt}
src={logos.dark.src}
width={logos.dark.width}
height={logos.dark.height}
/>
{/* Show light alternate if a user configure both light and dark logos. */}
{!('src' in config.logo) && (
<img
class="dark:sl-hidden"
alt={config.logo.alt}
src={logos.light?.src}
width={logos.light?.width}
height={logos.light?.height}
/>
)}
</>
)
}
<span class:list={{ 'sr-only': config.logo?.replacesTitle }}>
{siteTitle}
</span>
</a>

<style>
.site-title {
align-items: center;
gap: var(--sl-nav-gap);
font-size: var(--sl-text-xl);
font-weight: 600;
color: var(--sl-color-text-accent);
text-decoration: none;
white-space: nowrap;
}
img {
height: calc(var(--sl-nav-height) - 2 * var(--sl-nav-pad-y));
width: auto;
max-width: 100%;
object-fit: contain;
object-position: 0 50%;
}
</style>
26 changes: 26 additions & 0 deletions src/components/starlight/ThemeProvider.astro
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ if ('serviceWorker' in navigator) {
const c_sl_color_gray_7 = localStorage.getItem('--c-sl-color-gray-7');
const c_sl_color_black = localStorage.getItem('--c-sl-color-black');

const sl_text_h1 = localStorage.getItem('--sl-text-h1');
const sl_text_h2 = localStorage.getItem('--sl-text-h2');
const sl_text_h3 = localStorage.getItem('--sl-text-h3');
const sl_text_h4 = localStorage.getItem('--sl-text-h4');
const sl_text_h5 = localStorage.getItem('--sl-text-h5');
const sl_text_main = localStorage.getItem('--sl-text-main');


if (c_sl_color_accent_low !== null) {
document.documentElement.style.setProperty('--c-sl-color-accent-low', c_sl_color_accent_low);
}
Expand Down Expand Up @@ -120,6 +128,24 @@ if (c_sl_color_black !== null) {
document.documentElement.style.setProperty('--c-sl-color-black', c_sl_color_black);
}

if (sl_text_h1 !== null) {
document.documentElement.style.setProperty('--sl-text-h1', sl_text_h1);
}
if (sl_text_h2 !== null) {
document.documentElement.style.setProperty('--sl-text-h2', sl_text_h2);
}
if (sl_text_h3 !== null) {
document.documentElement.style.setProperty('--sl-text-h3', sl_text_h3);
}
if (sl_text_h4 !== null) {
document.documentElement.style.setProperty('--sl-text-h4', sl_text_h4);
}
if (sl_text_h5 !== null) {
document.documentElement.style.setProperty('--sl-text-h5', sl_text_h5);
}
if (sl_text_main !== null) {
document.documentElement.style.setProperty('--sl-text-main', sl_text_main);
}

// ☝️ This script prevent the FART effect.
if (localStorage.getItem("theme") === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/theme-designer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {

<div>
<theme-designer>
<div class="sl-flex controls not-content">
<div >
<ColorEditor key="accent" legend={editor.accentColor} labels={editor} />
<ColorEditor key="gray" legend={editor.grayColor} labels={editor} />
</div>
Expand Down
175 changes: 175 additions & 0 deletions src/components/theme-designer/font-slider.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
---
---


<h1>
العنوان الرئيسي

<span id="h1"></span>
</h1>
<input type="range" id="font-size-h1" min="15" max="100" value="36" />

<h2>
العنوان 2
<span id="h2"></span>
</h2>
<input type="range" id="font-size-h2" min="15" max="100" value="36" />


<h3>
العنوان 3
<span id="h3"></span>
</h3>
<input type="range" id="font-size-h3" min="15" max="100" value="36" />


<h4>
العنوان 4
<span id="h4"></span>
</h4>
<input type="range" id="font-size-h4" min="15" max="100" value="36" />

<h5>
العنوان 5
<span id="h5"></span>
</h5>
<input type="range" id="font-size-h5" min="15" max="100" value="36" />

<p>
النص
<span id="main"></span>
</p>
<input type="range" id="font-size-main" min="15" max="60" value="36" />





<script is:inline>

const fontSizeH1 = document.getElementById("font-size-h1");
const fontSizeH2 = document.getElementById("font-size-h2");
const fontSizeH3 = document.getElementById("font-size-h3");
const fontSizeH4 = document.getElementById("font-size-h4");
const fontSizeH5 = document.getElementById("font-size-h5");
const fontSizemain = document.getElementById("font-size-main");

const H1 = document.getElementById("h1");
const H2 = document.getElementById("h2");
const H3 = document.getElementById("h3");
const H4 = document.getElementById("h4");
const H5 = document.getElementById("h5");
const main = document.getElementById("main");


if (localStorage.getItem('--sl-text-h1') !== null) {
H1.innerHTML = '('+ localStorage.getItem('--sl-text-h1').slice(0,2) + ')';
fontSizeH1.value = localStorage.getItem('--sl-text-h1').slice(0,2);
}

if (localStorage.getItem('--sl-text-h2') !== null) {
H2.innerHTML = '('+ localStorage.getItem('--sl-text-h2').slice(0,2) + ')';
fontSizeH2.value = localStorage.getItem('--sl-text-h2').slice(0,2);
}

if (localStorage.getItem('--sl-text-h3') !== null) {
H3.innerHTML = '('+ localStorage.getItem('--sl-text-h3').slice(0,2) + ')';
fontSizeH3.value = localStorage.getItem('--sl-text-h3').slice(0,2);
}
if (localStorage.getItem('--sl-text-h4') !== null) {
H4.innerHTML = '('+ localStorage.getItem('--sl-text-h4').slice(0,2) + ')';
fontSizeH4.value = localStorage.getItem('--sl-text-h4').slice(0,2);
}
if (localStorage.getItem('--sl-text-h5') !== null) {
H5.innerHTML = '('+ localStorage.getItem('--sl-text-h5').slice(0,2) + ')';
fontSizeH5.value = localStorage.getItem('--sl-text-h5').slice(0,2);
}





var r = document.querySelector(':root');

fontSizeH1.addEventListener("input", () => {
const fontSize = fontSizeH1.value;
r.style.setProperty(`--sl-text-h1`, fontSize + 'px');
H1.innerHTML = '('+ fontSizeH1.value + ')';
localStorage.setItem(`--sl-text-h1`, fontSize + 'px');
});
fontSizeH2.addEventListener("input", () => {
const fontSize = fontSizeH2.value;
r.style.setProperty(`--sl-text-h2`, fontSize + 'px');
H2.innerHTML = '('+ fontSizeH2.value + ')';
localStorage.setItem(`--sl-text-h2`, fontSize + 'px');
});
fontSizeH3.addEventListener("input", () => {
const fontSize = fontSizeH3.value;
r.style.setProperty(`--sl-text-h3`, fontSize + 'px');
H3.innerHTML = '('+ fontSizeH3.value + ')';
localStorage.setItem(`--sl-text-h3`, fontSize + 'px');
});
fontSizeH4.addEventListener("input", () => {
const fontSize = fontSizeH4.value;
r.style.setProperty(`--sl-text-h4`, fontSize + 'px');
H4.innerHTML = '('+ fontSizeH4.value + ')';
localStorage.setItem(`--sl-text-h4`, fontSize + 'px');
});
fontSizeH5.addEventListener("input", () => {
const fontSize = fontSizeH5.value;
r.style.setProperty(`--sl-text-h5`, fontSize + 'px');
H5.innerHTML = '('+ fontSizeH5.value + ')';
localStorage.setItem(`--sl-text-h5`, fontSize + 'px');
});
fontSizemain.addEventListener("input", () => {
const fontSize = fontSizemain.value;
r.style.setProperty(`--sl-text-main`, fontSize + 'px');
main.innerHTML = '('+ fontSizemain.value + ')';
localStorage.setItem(`--sl-text-main`, fontSize + 'px');
});


</script>

<style>

input[type=range] {
-webkit-appearance: none;
margin: 10px 0;
width: 100%;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 12.8px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
background: #007bff;
border-radius: 25px;
border: 0px solid #000101;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
border: 0px solid #000000;
height: 20px;
width: 39px;
border-radius: 7px;
background: #fff;
cursor: pointer;
box-shadow: 0px 0px 5px rgb(143, 143, 143);
-webkit-appearance: none;
margin-top: -3.6px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #007bff;
}

.display-text {
text-align: center;
padding-top: 2rem;
}
</style>
53 changes: 40 additions & 13 deletions src/components/theme-designer/value-slider.astro
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const value = store[storeKey].get()[type];
<span class="value">{value}</span>
</label>
</value-slider>
<br>

<script>
import { store } from './store';
Expand Down Expand Up @@ -46,17 +47,43 @@ const value = store[storeKey].get()[type];
</script>

<style>
label {
display: grid;
grid-template-columns: auto 1fr 2.5rem;
align-items: center;
gap: 0.75rem;
}
input {
min-width: 5rem;
}
.value {
font-size: var(--sl-text-sm);
color: var(--sl-color-gray-2);
}



input[type=range] {
-webkit-appearance: none;
margin: 10px 0;
width: 100%;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 12.8px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
background: #007bff;
border-radius: 25px;
border: 0px solid #000101;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
border: 0px solid #000000;
height: 20px;
width: 39px;
border-radius: 7px;
background: #fff;
cursor: pointer;
box-shadow: 0px 0px 5px rgb(143, 143, 143);
-webkit-appearance: none;
margin-top: -3.6px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #007bff;
}



</style>
5 changes: 5 additions & 0 deletions src/content/docs/theme.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import Preview from '../../components/theme-designer/preview.astro';

import ThemeDesigner from '../../components/theme-designer-copy.astro';

import FontSlider from '../../components/theme-designer/font-slider.astro';

<FontSlider>
</FontSlider>

<Preview>

## لَيْسَ الغَريبُ [laysa-al-gharib]
Expand Down
Loading

0 comments on commit 25d4396

Please sign in to comment.