Skip to content

Commit

Permalink
Add dummy code area in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
xinjie-zhang committed Dec 23, 2022
1 parent b1ed80b commit a563272
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 97 deletions.
File renamed without changes.
File renamed without changes
2 changes: 1 addition & 1 deletion examples/components/header.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template x-component:app="header">
<img src="logo.svg" class="w-8 inline-block"><span class="text-2xl text-white align-middle"> Vimesh Headless UI </span>
<img src="./assets/logo.svg" class="w-8 inline-block"><span class="ml-2 text-2xl text-white align-middle"> Vimesh Headless UI </span>
<script>
return {

Expand Down
87 changes: 87 additions & 0 deletions examples/dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<head>
<link rel="icon" type="image/x-icon" href="./assets/favicon.ico">

<script src="/node_modules/@vimesh/style/dist/vs.dev.js"></script>
<script src="/node_modules/@vimesh/ui/dist/vui.dev.js"></script>
<script src="/node_modules/alpinejs/dist/cdn.js" defer></script>
<script src="/node_modules/universal-router/universal-router.min.js"></script>


<script>
$vui.config.importMap = {
"*": '../components/${component}.html',
"app": './components/${path}${component}.html',
"page": './pages/${path}${component}.html'
}
let root = {
$route: {},
routes: [
{ name: 'Home', path: '/index', page: 'home' },
{ name: 'Switch Basic', path: '/switch/basic', page: 'switch/basic' },
{ name: 'Tabs Basic', path: '/tabs/basic', page: 'tabs/basic' },
{ name: 'Combobox Basic', path: '/combobox/basic', page: 'combobox/basic' },
{ name: 'Listbox Basic', path: '/listbox/basic', page: 'listbox/basic' },
{ name: 'Listbox Multi', path: '/listbox/multi', page: 'listbox/multi' },
{ name: 'Radio Group Basic', path: '/radio-group/basic', page: 'radio-group/basic' },
{ name: 'Something Wrong!', path: '(.*)', page: 'home', hidden: true }
]
}
</script>
<style>
[x-cloak] {
display: none !important;
}
</style>
</head>

<body x-cloak x-import="app:header,footer,side-menu"
class="h-full w-full font-sans text-gray-900 antialiased flex flex-col" x-data="root">
<app-header class="flex-none h-16 px-1 py-3 bg-gray-700 flex"></app-header>
<div class="flex-1 flex">
<app-side-menu class="w-64 flex-none"></app-side-menu>
<div class="flex flex-1 flex-col">
<app-router-view class="flex-1"></app-router-view>
<div class="flex-1">
this is code area
</div>
</div>
</div>
<app-footer class="flex-none"></app-footer>
<template x-component:app="router-view" x-shtml="$api && $api.pageContent || ''"
x-import:dynamic="$api && $api.pageToImport">
<script>
return {
router: null,
currentPage: null,
get pageContent() {
if (!this.currentPage) return ''
let component = `page-${this.currentPage.replace('/', '-')}`
return `<${component}></${component}>`
},
get pageToImport() {
if (!this.currentPage) return ''
return `page:${this.currentPage}`
},
onUrlChange() {
let match = window.location.href.match(/#(.*)$/)
let fragment = match ? match[1] : ''
this.router.resolve({ pathname: fragment }).then(page => this.currentPage = page)
},
onMounted() {
this.router = new UniversalRouter(this.routes, {
context: { self: this },
resolveRoute(context, params) {
context.self.$route = { params, path: context.pathname }
if (typeof context.route.action === 'function') {
return context.route.action(context, params)
}
return context.route.page
}
})
this.onUrlChange()
window.addEventListener('popstate', e => this.onUrlChange())
}
}
</script>
</template>
</body>
72 changes: 35 additions & 37 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
<head>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<link rel="icon" type="image/x-icon" href="./assets/favicon.ico">

<script src="https://unpkg.com/@vimesh/style"></script>
<script src="https://unpkg.com/@vimesh/ui"></script>
<script src="https://unpkg.com/alpinejs" defer></script>
<script src="https://unpkg.com/universal-router/universal-router.min.js"></script>

<!--
<script src="/node_modules/@vimesh/style/dist/vs.dev.js"></script>
<script src="/node_modules/@vimesh/ui/dist/vui.dev.js"></script>
<script src="/node_modules/alpinejs/dist/cdn.js" defer></script>
<script src="/node_modules/universal-router/universal-router.min.js"></script>
-->
<script src="https://unpkg.com/universal-router/universal-router.min.js"></script>

<script>
$vs.addMacroCss({
"*": 'border-gray-200'
})
$vui.config.importMap = {
"*": '../components/${component}.html',
"app": './components/${path}${component}.html',
Expand All @@ -25,14 +15,14 @@
let root = {
$route: {},
routes: [
{ name: 'Home', path: '/index', component: 'page-home' },
{ name: 'Switch Basic', path: '/switch/basic', component: 'page-switch-basic' },
{ name: 'Tabs Basic', path: '/tabs/basic', component: 'page-tabs-basic' },
{ name: 'Combobox Basic', path: '/combobox/basic', component: 'page-combobox-basic' },
{ name: 'Listbox Basic', path: '/listbox/basic', component: 'page-listbox-basic' },
{ name: 'Listbox Multi', path: '/listbox/multi', component: 'page-listbox-multi' },
{ name: 'Radio Group Basic', path: '/radio-group/basic', component: 'page-radio-group-basic@page:radio-group/basic' },
{ name: 'Something Wrong!', path: '(.*)', component: 'page-home', hidden: true }
{ name: 'Home', path: '/index', page: 'home' },
{ name: 'Switch Basic', path: '/switch/basic', page: 'switch/basic' },
{ name: 'Tabs Basic', path: '/tabs/basic', page: 'tabs/basic' },
{ name: 'Combobox Basic', path: '/combobox/basic', page: 'combobox/basic' },
{ name: 'Listbox Basic', path: '/listbox/basic', page: 'listbox/basic' },
{ name: 'Listbox Multi', path: '/listbox/multi', page: 'listbox/multi' },
{ name: 'Radio Group Basic', path: '/radio-group/basic', page: 'radio-group/basic' },
{ name: 'Something Wrong!', path: '(.*)', page: 'home', hidden: true }
]
}
</script>
Expand All @@ -43,30 +33,38 @@
</style>
</head>

<body x-cloak x-import="app:header,footer,side-menu" class="h-full w-full font-sans text-gray-900 antialiased flex flex-col"
x-data="root">
<body x-cloak x-import="app:header,footer,side-menu"
class="h-full w-full font-sans text-gray-900 antialiased flex flex-col" x-data="root">
<app-header class="flex-none h-16 px-1 py-3 bg-gray-700 flex"></app-header>
<main class="flex-1 flex">
<app-side-menu class=" w-64 flex-none"></app-side-menu>
<app-router-view class="flex-1"></app-router-view>
</main>
<div class="flex-1 flex">
<app-side-menu class="w-64 flex-none"></app-side-menu>
<div class="flex flex-1 flex-col">
<app-router-view class="flex-1"></app-router-view>
<div class="flex-1">
this is code area
</div>
</div>
</div>
<app-footer class="flex-none"></app-footer>
<template x-component:app="router-view">
<template x-component:app="router-view" x-shtml="$api && $api.pageContent || ''"
x-import:dynamic="$api && $api.pageToImport">
<script>
return {
router: null,
currentPage: null,
get pageContent() {
if (!this.currentPage) return ''
let component = `page-${this.currentPage.replace('/', '-')}`
return `<${component}></${component}>`
},
get pageToImport() {
if (!this.currentPage) return ''
return `page:${this.currentPage}`
},
onUrlChange() {
let match = window.location.href.match(/#(.*)$/)
let fragment = match ? match[1] : ''
this.router.resolve({ pathname: fragment }).then(component => {
if (component) {
let pos = component.indexOf('@')
let from = pos !== -1 ? component.substring(pos + 1) : component.replace('-', ':').replace('-', '/')
if (pos !== -1) component = component.substring(0, pos)
$vui.import(from)
$vui.setHtml(this.$el, `<${component}></${component}>`)
}
})
this.router.resolve({ pathname: fragment }).then(page => this.currentPage = page)
},
onMounted() {
this.router = new UniversalRouter(this.routes, {
Expand All @@ -76,7 +74,7 @@
if (typeof context.route.action === 'function') {
return context.route.action(context, params)
}
return context.route.component
return context.route.page
}
})
this.onUrlChange()
Expand Down
107 changes: 51 additions & 56 deletions examples/pages/combobox/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,72 +27,67 @@
}
</script>
<template x-component:page="combobox-basic" x-import="hui/combobox" x-data="setupComboboxBasicData()">
<div class="flex flex-col h-full overflow-hidden bg-gray-700 font-sans text-gray-900 antialiased">
<main class="flex-1 overflow-auto bg-gray-50">
<div class="flex justify-center bg-gray-50 p-12">
<div class="mx-auto w-full max-w-xs">
<div class="py-8 font-mono text-xs">
Selected person: <span x-text="activePerson && activePerson.name || 'Nobody yet'"></span>
</div>
<div class="space-y-1">
<hui-combobox x-model="activePerson">
<hui-combobox-label class="block text-sm font-medium leading-5 text-gray-700">
Assigned to
</hui-combobox-label>
<div class="h-full justify-center bg-gray-50 p-12">
<div class="mx-auto w-full max-w-xs">
<div class="py-8 font-mono text-xs">
Selected person: <span x-text="activePerson && activePerson.name || 'Nobody yet'"></span>
</div>
<div class="space-y-1">
<hui-combobox x-model="activePerson">
<hui-combobox-label class="block text-sm font-medium leading-5 text-gray-700">
Assigned to
</hui-combobox-label>

<div class="relative">
<span class="relative inline-flex flex-row overflow-hidden rounded-md border shadow-sm">
<hui-combobox-input @change="query=$event.target.value"
:display-value="() => (person) => person && person.name || ''"
class="border-none px-3 py-1 outline-none"></hui-combobox-input>
<hui-combobox-button
class="cursor-default border-l bg-gray-100 px-1 text-indigo-600 focus:outline-none">
<span class="pointer-events-none flex items-center px-2">
<svg class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="none"
stroke="currentColor">
<path d="M7 7l3-3 3 3m0 6l-3 3-3-3" strokeWidth="1.5"
strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
</hui-combobox-button>
<div class="relative">
<span class="relative inline-flex flex-row overflow-hidden rounded-md border border-gray-300 shadow-sm">
<hui-combobox-input @change="query=$event.target.value"
:display-value="() => (person) => person && person.name || ''"
class="border-none px-3 py-1 outline-none"></hui-combobox-input>
<hui-combobox-button
class="cursor-default border-l border-gray-300 bg-gray-100 px-1 text-indigo-600 focus:outline-none">
<span class="pointer-events-none flex items-center px-2">
<svg class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="none"
stroke="currentColor">
<path d="M7 7l3-3 3 3m0 6l-3 3-3-3" strokeWidth="1.5" strokeLinecap="round"
strokeLinejoin="round" />
</svg>
</span>
</hui-combobox-button>
</span>

<div class="absolute mt-1 w-full rounded-md bg-white shadow-lg">
<hui-combobox-options
class="shadow-xs max-h-60 overflow-auto rounded-md py-1 text-base leading-6 focus:outline-none sm:text-sm sm:leading-5">
<template x-for="person in filteredPeople" :key="person.id">
<hui-combobox-option :value="person">
<div :class="[
<div class="absolute mt-1 w-full rounded-md bg-white shadow-lg">
<hui-combobox-options
class="shadow-xs max-h-60 overflow-auto rounded-md py-1 text-base leading-6 focus:outline-none sm:text-sm sm:leading-5">
<template x-for="person in filteredPeople" :key="person.id">
<hui-combobox-option :value="person">
<div :class="[
'relative cursor-default select-none py-2 pl-3 pr-9 focus:outline-none',
active ? 'bg-indigo-600 text-white' : 'text-gray-900',
]">
<span
:class="['block truncate', selected ? 'font-semibold' : 'font-normal']"
x-text="person.name">
</span>
<template x-if="selected">
<span :class="[
<span
:class="['block truncate', selected ? 'font-semibold' : 'font-normal']"
x-text="person.name">
</span>
<template x-if="selected">
<span :class="[
'absolute inset-y-0 right-0 flex items-center pr-4',
active ? 'text-white' : 'text-indigo-600',
]">
<svg class="h-5 w-5" viewBox="0 0 20 20"
fill="currentColor">
<path fillRule="evenodd"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
clipRule="evenodd" />
</svg>
</span>
</template>
</div>
</hui-combobox-option>
</template>
</hui-combobox-options>
</div>
</div>
</hui-combobox>
<svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fillRule="evenodd"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
clipRule="evenodd" />
</svg>
</span>
</template>
</div>
</hui-combobox-option>
</template>
</hui-combobox-options>
</div>
</div>
</div>
</hui-combobox>
</div>
</main>
</div>
</div>
</template>
4 changes: 2 additions & 2 deletions examples/pages/listbox/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
}
}
</script>
<template x-component:page="listbox-basic" x-import="hui/listbox" class="p-2" x-data="setupListboxBasicData()">
<div class="flex h-full justify-center bg-gray-50 p-12">
<template x-component:page="listbox-basic" x-import="hui/listbox" x-data="setupListboxBasicData()">
<div class="h-full justify-center bg-gray-50 p-12">
<div class="mx-auto w-full max-w-xs">
<div class="space-y-1">
<hui-listbox x-model="active">
Expand Down
2 changes: 1 addition & 1 deletion examples/pages/listbox/multi.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
}
</script>
<template x-component:page="listbox-multi" x-import="hui/listbox" class="p-2" x-data="setupListboxMultiData()">
<template x-component:page="listbox-multi" x-import="hui/listbox" x-data="setupListboxMultiData()">
<div class="flex h-full justify-center space-x-4 bg-gray-50 p-12">
<div class="w-full max-w-4xl">
<div class="space-y-1">
Expand Down

0 comments on commit a563272

Please sign in to comment.