Skip to content

Commit

Permalink
docs: add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed Aug 27, 2024
1 parent b5adc1d commit 8bde833
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 9 deletions.
8 changes: 4 additions & 4 deletions docs/.vitepress/components/DocTopbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ watch(path, () => {
v-for="tab in sectionTabs.filter(i => i.label !== 'Examples')"
:key="tab.label"
:href="tab.link"
:class="{ '!border-b-primary !font-semibold !text-foreground': page.relativePath.includes(tab.label?.toLowerCase() ?? '') }"
class="py-2 mx-4 text-sm font-medium border-b border-b-transparent text-muted-foreground hover:border-b-muted hover:text-foreground h-full inline-flex items-center"
:class="{ '!border-b-primary !text-foreground': page.relativePath.includes(tab.label?.toLowerCase() ?? '') }"
class=" py-2 mx-4 text-sm font-semibold border-b border-b-transparent text-muted-foreground hover:border-b-muted hover:text-foreground h-full inline-flex items-center"
>
<Icon
v-if="tab.icon"
Expand All @@ -51,8 +51,8 @@ watch(path, () => {
v-for="tab in sectionTabs.filter(i => i.label === 'Examples')"
:key="tab.label"
:href="tab.link"
:class="{ '!border-b-primary !font-semibold !text-foreground': page.relativePath.includes(tab.label?.toLowerCase() ?? '') }"
class="py-2 mx-4 text-sm font-medium border-b border-b-transparent text-muted-foreground hover:border-b-muted hover:text-foreground h-full inline-flex items-center"
:class="{ '!border-b-primary !text-foreground': page.relativePath.includes(tab.label?.toLowerCase() ?? '') }"
class=" py-2 mx-4 text-sm font-semibold border-b border-b-transparent text-muted-foreground hover:border-b-muted hover:text-foreground h-full inline-flex items-center"
>
<Icon
v-if="tab.icon"
Expand Down
9 changes: 7 additions & 2 deletions docs/.vitepress/components/ExampleHome.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<script setup lang="ts">
import { computed } from 'vue'
import { computed, onBeforeMount } from 'vue'
// @ts-expect-error type issue with `createContentLoader`
import { data as examples } from '../functions/examples.data'
import type { ContentData } from 'vitepress'
import { type ContentData, useRouter } from 'vitepress'
const router = useRouter()
const data = computed(() => examples.filter((example: ContentData) => example.url !== '/examples/') as ContentData[])
onBeforeMount(() => {
router.go(data.value?.[0].url)
})
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { Icon } from '@iconify/vue'
</a>
<a
class="group flex h-12 items-center justify-center gap-2 font-semibold text-muted-foreground hover:text-foreground whitespace-nowrap rounded-xl px-4 hover:bg-card"
href="/docs/components/accordion"
href="/docs/components/checkbox"
>
Explore components
<Icon icon="lucide:arrow-right" />
Expand Down
14 changes: 12 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default defineConfig({
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Docs', link: '/docs/overview/getting-started' },
{ text: 'Examples', link: '/examples' },
{ text: 'Examples', link: '/examples/checkbox-group' },
{ text: 'Showcase', link: '/showcase' },
{
text: `v${version}`,
Expand Down Expand Up @@ -181,7 +181,7 @@ export default defineConfig({
{
text: 'Examples',
icon: 'lucide:square-dashed-mouse-pointer',
link: '/examples',
link: '/examples/checkbox-group',
items: [
{ text: 'Checkbox', items: [
{ text: 'Checkbox Group', link: '/examples/checkbox-group' },
Expand All @@ -193,9 +193,19 @@ export default defineConfig({
{ text: 'Dialog', items: [
{ text: 'Dialog Command Menu', link: '/examples/dialog-command-menu' },
] },
{ text: 'Listbox', items: [
{ text: 'Listbox Transfer', link: '/examples/listbox-transfer' },
] },
{ text: 'Slider', items: [
{ text: 'Slider with Number Field', link: '/examples/slider-number-field' },
{ text: 'Slider Tooltip', link: '/examples/slider-tooltip' },
] },
{ text: 'Tooltip', items: [
{ text: 'Tooltip Cursor', link: '/examples/tooltip-cursor' },
] },
{ text: 'Progress', items: [
{ text: 'Circular Progress', link: '/examples/progress-circular' },
] },
],
},
],
Expand Down
101 changes: 101 additions & 0 deletions docs/components/examples/ListboxTransfer/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<script setup lang="ts">
import { ref } from 'vue'
import { Icon } from '@iconify/vue'
import { ListboxContent, ListboxItem, ListboxRoot } from 'reka-ui'
const states = [
'California',
'Illinois',
'Maryland',
'Texas',
'Florida',
'Colorado',
'Connecticut ',
]
const list1 = ref<string[]>([...states])
const list2 = ref<string[]>([])
const selectedList1 = ref([])
const selectedList2 = ref([])
const searchValue1 = ref([])
const searchValue2 = ref([])
function transferAction(action: '1to2' | '2to1') {
const [fromList, toList, selectedList] = action === '1to2'
? [list1, list2, selectedList1]
: [list2, list1, selectedList2]
fromList.value = fromList.value.filter(item => !selectedList.value.includes(item))
toList.value.push(...selectedList.value)
selectedList.value = []
}
</script>

<template>
<div class="text-foreground flex items-center ">
<ListboxRoot
v-model="selectedList1"
class="bg-card rounded-lg border border-muted w-48"
multiple
>
<div class="px-3 py-2">
<h2 class="text-muted-foreground text-xs font-semibold">
List 1
</h2>
</div>

<ListboxContent class="h-44 overflow-auto p-1 border-t border-muted">
<ListboxItem
v-for="item in list1"
:key="item"
:value="item"
class="text-sm px-2 py-1 cursor-default data-[state=checked]:bg-green9 data-[state=checked]:text-white rounded select-none"
>
{{ item }}
</ListboxItem>
</ListboxContent>
</ListboxRoot>

<div class="flex mx-2 gap-2">
<button
class="w-8 h-8 text-lg border border-muted flex items-center justify-center rounded bg-card hover:bg-muted disabled:opacity-50"
:disabled="!selectedList2.length"
@click="transferAction('2to1')"
>
<Icon icon="lucide:chevron-left" />
</button>
<button
class="w-8 h-8 text-lg border border-muted flex items-center justify-center rounded bg-card hover:bg-muted disabled:opacity-50"
:disabled="!selectedList1.length"
@click="transferAction('1to2')"
>
<Icon icon="lucide:chevron-right" />
</button>
</div>

<ListboxRoot
v-model="selectedList2"
class="bg-card rounded-lg border border-muted w-48"
multiple
>
<div class="px-3 py-2">
<h2 class="text-muted-foreground text-xs font-semibold">
List 2
</h2>
</div>

<ListboxContent class="h-44 overflow-auto p-1 border-t border-muted">
<ListboxItem
v-for="item in list2"
:key="item"
:value="item"
class="text-sm px-2 py-1 cursor-default data-[state=checked]:bg-green9 data-[state=checked]:text-white rounded select-none"
>
{{ item }}
</ListboxItem>
</ListboxContent>
</ListboxRoot>
</div>
</template>
69 changes: 69 additions & 0 deletions docs/components/examples/ProgressCircular/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { ProgressIndicator, ProgressRoot } from 'reka-ui'
const RADIUS = 45
const circumference = 2 * Math.PI * RADIUS
const progress = ref(0)
const dashOffset = computed(() =>
(progress.value / 100) * circumference,
)
const trackPath = computed(() => {
const r = RADIUS
return `
M 50 50
m 0 -${r}
a ${r} ${r} 0 1 1 0 ${r * 2}
a ${r} ${r} 0 1 1 0 -${r * 2}
`
})
onMounted(() => {
setInterval(() => {
if (progress.value < 100) {
progress.value += 10
}
else {
progress.value = 0
}
}, 1000)
})
</script>

<template>
<div class="relative w-40 h-40">
<ProgressRoot
v-model="progress"
as-child
>
<svg
class="w-full h-full"
viewBox="0 0 100 100"
>
<!-- Background circle -->
<path
:d="trackPath"
class="fill-none stroke-muted stroke-[6px]"
/>
<!-- Progress circle -->
<ProgressIndicator as-child>
<path
:d="trackPath"
class="fill-none stroke-primary stroke-[6px] transition-[stroke-dasharray,opacity] duration-700 data-[value='0']:opacity-0"
:style="{
'stroke-linecap': 'round',
'stroke-dasharray': `${dashOffset}px, ${circumference}px`,
'stroke-dashoffset': '0px',
}"
/>
</ProgressIndicator>
</svg>
<div class="absolute inset-0 flex items-center justify-center">
<span class="text-lg font-bold text-foreground">{{ progress }}%</span>
</div>
</ProgressRoot>
</div>
</template>
42 changes: 42 additions & 0 deletions docs/components/examples/SliderNumberField/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup lang="ts">
import { ref } from 'vue'
import { NumberFieldInput, NumberFieldRoot, SliderRange, SliderRoot, SliderThumb, SliderTrack } from 'reka-ui'
const sliderValue = ref([20, 50])
</script>

<template>
<div class="w-[200px] flex flex-col">
<SliderRoot
v-model="sliderValue"
class="relative flex items-center select-none touch-none h-5"
:max="100"
:step="1"
>
<SliderTrack class="bg-blackA10 relative grow rounded-full h-[3px]">
<SliderRange class="absolute bg-white rounded-full h-full" />
</SliderTrack>
<SliderThumb
v-for="thumb in sliderValue.length"
:key="thumb"
class="block w-5 h-5 bg-white shadow-[0_2px_10px] shadow-blackA7 rounded-[10px] hover:bg-violet3 focus:outline-none focus:shadow-[0_0_0_5px] focus:shadow-blackA8"
aria-label="Volume"
/>
</SliderRoot>

<div class="mt-2 flex items-center justify-between">
<NumberFieldRoot
v-model="sliderValue[0]"
:max="sliderValue[1]"
>
<NumberFieldInput class="bg-card border border-muted rounded text-foreground text-xs py-1.5 font-semibold w-12 text-center" />
</NumberFieldRoot>
<NumberFieldRoot
v-model="sliderValue[1]"
:min="sliderValue[0]"
>
<NumberFieldInput class="bg-card border border-muted rounded text-foreground text-xs py-1.5 font-semibold w-12 text-center" />
</NumberFieldRoot>
</div>
</div>
</template>
39 changes: 39 additions & 0 deletions docs/components/examples/SliderTooltip/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script setup lang="ts">
import { ref } from 'vue'
import { SliderRange, SliderRoot, SliderThumb, SliderTrack, TooltipContent, TooltipPortal, TooltipProvider, TooltipRoot, TooltipTrigger } from 'reka-ui'
const sliderValue = ref([50])
</script>

<template>
<TooltipProvider :delay-duration="0">
<SliderRoot
v-model="sliderValue"
class="relative flex items-center select-none touch-none w-[200px] h-5"
:max="100"
:step="1"
>
<SliderTrack class="bg-blackA10 relative grow rounded-full h-[3px]">
<SliderRange class="absolute bg-white rounded-full h-full" />
</SliderTrack>

<TooltipRoot disable-closing-trigger>
<TooltipTrigger as-child>
<SliderThumb
class="block w-5 h-5 bg-white shadow-[0_2px_10px] shadow-blackA7 rounded-[10px] hover:bg-violet3 focus:outline-none focus:shadow-[0_0_0_5px] focus:shadow-blackA8"
aria-label="Volume"
/>
</TooltipTrigger>

<TooltipPortal>
<TooltipContent
class="bg-card px-2 py-1 rounded text-foreground text-xs font-semibold border border-muted"
:side-offset="6"
>
{{ sliderValue[0] }}
</TooltipContent>
</TooltipPortal>
</TooltipRoot>
</SliderRoot>
</TooltipProvider>
</template>
23 changes: 23 additions & 0 deletions docs/content/examples/listbox-transfer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Listbox Transfer
tags:
- Listbox
---

# Listbox Transfer

<Description>

Render a Transfer component with Listbox.

</Description>

<Tags />

<ComponentPreview type="example" name="ListboxTransfer" />

<ExampleSection>

### Listbox Transfer

</ExampleSection>
23 changes: 23 additions & 0 deletions docs/content/examples/progress-circular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Circular Progress
tags:
- Progress
---

# Circular Progress

<Description>

Rendering progress bar as a Circular Progress.

</Description>

<Tags />

<ComponentPreview type="example" name="ProgressCircular" />

<ExampleSection>

### Circular Progress

</ExampleSection>
Loading

0 comments on commit 8bde833

Please sign in to comment.