-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playground): languages and themes switching (#3)
Co-authored-by: L33Z22L11 <[email protected]>
- Loading branch information
Showing
12 changed files
with
883 additions
and
564 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,63 @@ | ||
<script lang="ts" setup> | ||
import { type BundledLanguage, bundledLanguages, type BundledTheme, bundledThemes } from "shiki"; | ||
import pkg from "../../package.json"; | ||
const repository = new URL(pkg.repository, "https://github.com").href; | ||
const version = "v" + pkg.version; | ||
const langNames = Object.keys(bundledLanguages).sort((a, b) => a.localeCompare(b)); | ||
const themeNames = Object.keys(bundledThemes).sort((a, b) => a.localeCompare(b)); | ||
const lang = ref<BundledLanguage>("typescript"); | ||
const lightTheme = ref<BundledTheme>("catppuccin-latte"); | ||
const darkTheme = ref<BundledTheme>("one-dark-pro"); | ||
const themes = computed(() => ({ | ||
light: lightTheme.value, | ||
dark: darkTheme.value | ||
})); | ||
</script> | ||
|
||
<template> | ||
<div m="2"> | ||
<theme-switch /> | ||
<plain-shiki /> | ||
</div> | ||
<header | ||
flex="~ items-center justify-between" | ||
m="x-auto y-4" | ||
p="x-4" | ||
max-w="screen-lg" | ||
> | ||
<hgroup flex="~ gap-2 items-center"> | ||
<h1 font="bold" text="5">Plain Shiki Playground</h1> | ||
<span | ||
p="x-1 y-.5" | ||
b="rounded-1" | ||
bg="primary op-20" | ||
font="mono" | ||
text="3 primary" | ||
>{{ version }}</span> | ||
</hgroup> | ||
<nav flex="~ gap-2"> | ||
<plain-button as="a" icon="ph:github-logo" title="GitHub" :href="repository"/> | ||
<theme-button mode="light" icon="solar:sun-2-outline"/> | ||
<theme-button mode="system" icon="solar:monitor-outline"/> | ||
<theme-button mode="dark" icon="solar:moon-outline"/> | ||
</nav> | ||
</header> | ||
<main | ||
m="x-auto" | ||
p="x-4" | ||
max-w="screen-lg" | ||
> | ||
<div b="1 solid gray op-40 rounded-md"> | ||
<div | ||
flex="~ gap-2 items-center" | ||
p="x-4 y-1" | ||
b-b="~ solid gray op-40" | ||
> | ||
<plain-select :items="langNames" v-model="lang"/> | ||
<plain-select :items="themeNames" v-model="lightTheme"/> | ||
<plain-select :items="themeNames" v-model="darkTheme"/> | ||
</div> | ||
<plain-shiki :lang :themes/> | ||
</div> | ||
</main> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<script lang="ts" setup> | ||
const { as = "button" } = defineProps<{ | ||
as?: string; | ||
icon: string; | ||
}>(); | ||
const attrs = computed(() => (as === "a" ? { | ||
rel: "noopener noreferrer", | ||
target: "_blank" | ||
} : {})); | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="as" | ||
v-bind="attrs" | ||
grid="~ place-items-center" | ||
size="9" | ||
b="1 solid gray op-40 rounded-md" | ||
bg="transparent" | ||
hover:bg="gray op-20" | ||
un-text="4.5" | ||
cursor="pointer" | ||
> | ||
<iconify :name="icon"/> | ||
</component> | ||
</template> | ||
|
||
<style scoped> | ||
.is-checked { | ||
--uno: outline-primary outline outline-2 outline-offset--1; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<script lang="ts" setup> | ||
defineProps<{ | ||
items: string[]; | ||
}>(); | ||
const modelValue = defineModel<string>(); | ||
</script> | ||
|
||
<template> | ||
<select-root v-model="modelValue"> | ||
<select-trigger | ||
flex="inline items-center gap-1.5" | ||
h="8" | ||
w="45" | ||
outline="none" | ||
bg="inherit" | ||
font="mono" | ||
text="sm nowrap truncate" | ||
cursor="pointer" | ||
> | ||
<select-icon flex="~" text="3 gray"> | ||
<iconify name="fa6-solid:chevron-down"/> | ||
</select-icon> | ||
<select-value /> | ||
</select-trigger> | ||
<select-portal> | ||
<select-content | ||
class="select-content" | ||
p="y-2" | ||
b="~ solid gray op-40 rounded-md" | ||
backdrop="blur-6" | ||
font="mono" | ||
position="popper" | ||
> | ||
<select-scroll-up-button flex="~ justify-center" text="3 gray"> | ||
<iconify name="fa6-solid:chevron-up"/> | ||
</select-scroll-up-button> | ||
<select-viewport> | ||
<select-item | ||
v-for="item, i in items" | ||
:key="i" | ||
class="select-item" | ||
p="x-3.5" | ||
leading="6" | ||
text="sm" | ||
:value="item" | ||
> | ||
<select-item-text>{{ item }}</select-item-text> | ||
</select-item> | ||
</select-viewport> | ||
<select-scroll-down-button flex="~ justify-center" text="3 gray"> | ||
<iconify name="fa6-solid:chevron-down"/> | ||
</select-scroll-down-button> | ||
</select-content> | ||
</select-portal> | ||
</select-root> | ||
</template> | ||
|
||
<style> | ||
.select-content { | ||
min-width: var(--radix-select-trigger-width); | ||
max-height: var(--radix-select-content-available-height); | ||
} | ||
.select-item[data-highlighted] { | ||
--uno: outline-none text-primary bg-gray bg-op-30; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
<script lang="ts" setup> | ||
import type { BundledLanguage, BundledTheme } from "shiki"; | ||
import example from "~/assets/example.ts?raw"; | ||
const { lang, themes } = defineProps<{ | ||
lang: BundledLanguage; | ||
themes: Record<string, BundledTheme>; | ||
}>(); | ||
const editorEl = useTemplateRef("editor"); | ||
usePlainShiki(editorEl, { | ||
lang: "ts", | ||
themes: { | ||
light: "catppuccin-latte", | ||
dark: "one-dark-pro" | ||
} | ||
lang: () => lang, | ||
themes: () => themes | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div | ||
ref="editor" | ||
class="plain-shiki" | ||
p="x-3 y-2" | ||
b="1 solid gray op-40 rounded-md" | ||
overflow="x-auto" | ||
p="x-4 y-3" | ||
outline="none" | ||
font="mono" | ||
whitespace="break-spaces" | ||
lh="6" | ||
text="4" | ||
leading="6" | ||
text="nowrap" | ||
contenteditable | ||
v-html="example" | ||
></div> | ||
</template> | ||
|
||
<style> | ||
.plain-shiki { | ||
font-family: consolas, var(--font); | ||
} | ||
</style> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import { defineConfig, presetAttributify, presetUno } from "unocss"; | ||
import { defineConfig, presetAttributify, presetUno, transformerDirectives } from "unocss"; | ||
|
||
export default defineConfig({ | ||
presets: [ | ||
presetUno(), | ||
presetAttributify() | ||
], | ||
theme: { | ||
colors: { | ||
primary: "hsl(154deg 32% 46%)" | ||
} | ||
}, | ||
transformers: [ | ||
transformerDirectives() | ||
] | ||
}); |
Oops, something went wrong.