-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2d0864
commit 002c708
Showing
2 changed files
with
78 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template x-component:hui="switch-group"> | ||
<slot></slot> | ||
</template> | ||
|
||
<template x-component:hui="switch" tabindex="0" x-modelable="checked" x-data="{ | ||
checked: false, | ||
get disabled() {return $prop('disabled')} | ||
}" @click="$api.toggle()"> | ||
<slot></slot> | ||
<template x-if="checked"> | ||
<input type="hidden" :name="$prop('name')" :value="$prop('value') || 'on'"> | ||
</template> | ||
<script> | ||
return { | ||
toggle() { | ||
this.checked = !this.checked | ||
} | ||
} | ||
</script> | ||
</template> | ||
|
||
<template x-component:hui="switch-label"> | ||
<slot></slot> | ||
</template> | ||
|
||
<template x-component:hui="switch-description"> | ||
<slot></slot> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<head> | ||
<!-- | ||
<script src="https://unpkg.com/@vimesh/style" defer></script> | ||
<script src="https://unpkg.com/@vimesh/ui"></script> | ||
<script src="https://unpkg.com/alpinejs" defer></script> | ||
--> | ||
|
||
<script src="../node_modules/@vimesh/style/dist/vs.dev.js" defer></script> | ||
<script src="../node_modules/@vimesh/ui/dist/vui.dev.js"></script> | ||
<script src="../node_modules/alpinejs/dist/cdn.js" defer></script> | ||
|
||
<script> | ||
$vui.config.importMap = { | ||
"*": '../components/${component}.html' | ||
} | ||
</script> | ||
<style> | ||
[x-cloak] { | ||
display: none !important; | ||
} | ||
</style> | ||
|
||
<script> | ||
let data = { | ||
state: true, | ||
onSubmit() { | ||
console.log(this.state) | ||
} | ||
} | ||
</script> | ||
</head> | ||
|
||
<body x-cloak x-import="hui/switch" class="p-2" x-data="data"> | ||
<div class="flex h-full w-screen items-start justify-center bg-gray-50 p-12"> | ||
<form action="https://jsonplaceholder.typicode.com/todos/1"> | ||
<hui-switch-group class="flex items-center space-x-4"> | ||
<hui-switch-label>Enable notifications</hui-switch-label> | ||
|
||
<hui-switch name="email" x-model="state" :class="['relative inline-flex flex-shrink-0 h-6 transition-colors duration-200 ease-in-out border-2 border-transparent rounded-full cursor-pointer w-11 focus:outline-none focus:shadow-outline', | ||
checked ? 'bg-indigo-600' : 'bg-gray-200']"> | ||
<span | ||
class="inline-block h-5 w-5 transform rounded-full bg-white transition duration-200 ease-in-out" | ||
:class="[checked ? 'translate-x-5' : 'translate-x-0']"></span> | ||
</hui-switch> | ||
</hui-switch-group> | ||
<input type="submit" value="Submit" @click="onSubmit()" | ||
class="inline-block rounded-lg mt-2 bg-green-600 px-4 py-1.5 text-white shadow ring-1 ring-green-600 hover:bg-green-700 hover:ring-green-700"> | ||
</form> | ||
</div> | ||
</body> |