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

fix: make TS the default without JS #198

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions apps/svelte.dev/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
}
}

if (localStorage.getItem('svelte:prefers-ts') !== 'false') {
for (const node of document.querySelectorAll('.ts-toggle')) {
if (localStorage.getItem('svelte:prefers-ts') === 'false') {
for (const node of document.querySelectorAll('.js-toggle')) {
node.checked = true;
}
}
Expand Down
28 changes: 14 additions & 14 deletions packages/site-kit/src/lib/components/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
afterNavigate(update);

function update() {
const inputs = container.querySelectorAll('.ts-toggle') as NodeListOf<HTMLInputElement>;
const inputs = container.querySelectorAll('.js-toggle') as NodeListOf<HTMLInputElement>;

for (const input of inputs) {
input.checked = $prefers_ts;
input.checked = !$prefers_ts;
}
}

function toggle(e: Event) {
if ((e.target as HTMLElement).classList.contains('ts-toggle')) {
if ((e.target as HTMLElement).classList.contains('js-toggle')) {
const input = e.target as HTMLInputElement;
$prefers_ts = input.checked;
$prefers_ts = !input.checked;
fix_position(input, update);
}
}
Expand All @@ -32,7 +32,7 @@
.composedPath()
.find((node) => (node as HTMLElement).classList.contains('code-block')) as HTMLElement;

const ts = !!parent.querySelector('.ts-toggle:checked');
const ts = !parent.querySelector('.js-toggle:checked');
const code = parent.querySelector(`pre:${ts ? 'last' : 'first'}-of-type code`) as HTMLElement;

let result = '';
Expand Down Expand Up @@ -132,13 +132,13 @@
}
}

&:has(.ts-toggle:checked) {
.filename[data-ext='.js']::after {
content: '.ts';
&:has(.js-toggle:checked) {
.filename[data-ext='.ts']::after {
content: '.js';
}
}

.ts-toggle {
.js-toggle {
appearance: none;
display: flex;
align-items: center;
Expand All @@ -160,21 +160,21 @@

&::before {
content: 'JS';
opacity: 0.3;
}

&::after {
content: 'TS';
border-left: none;
opacity: 0.3;
}

&:checked {
&::before {
opacity: 0.3;
opacity: 1;
}

&::after {
opacity: 1;
opacity: 0.3;
}
}
}
Expand Down Expand Up @@ -236,11 +236,11 @@
}
}

&:has(.ts-toggle:checked) pre:first-of-type {
&:has(.js-toggle:not(:checked)) pre:first-of-type {
display: none;
}

&:has(.ts-toggle:not(:checked)) pre:last-of-type {
&:has(.js-toggle:checked) pre:last-of-type {
display: none;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/site-kit/src/lib/markdown/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export async function render_content_markdown(
}

if (converted) {
html += `<input class="ts-toggle" title="Toggle language" type="checkbox" aria-label="Toggle JS/TS">`;
html += `<input class="js-toggle" title="Toggle language" type="checkbox" aria-label="Toggle JS/TS">`;
}

if (options.copy) {
Expand Down
Loading