Last active
September 22, 2020 16:27
-
-
Save JeffreyWay/d3e0e5692b72c3d15d50061407028e39 to your computer and use it in GitHub Desktop.
Alpine Tab example - https://laracasts.com/series/alpine-essentials/episodes/3
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Alpine Examples</title> | |
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script> | |
<style> | |
.active { color: blue; } | |
.tab-wrap { border: 1px dotted grey; padding: 1rem; margin-top: 1rem; } | |
</style> | |
</head> | |
<body> | |
<div x-data="{ currentTab: 'first' }"> | |
<button @click="currentTab = 'first'" :class="{ 'active' : currentTab === 'first'}">First</button> | |
<button @click="currentTab = 'second'" :class="{ 'active' : currentTab === 'second'}">Second</button> | |
<button @click="currentTab = 'third'" :class="{ 'active' : currentTab === 'third'}">Third</button> | |
<div class="tab-wrap"> | |
<div x-show="currentTab === 'first'"> | |
<p>First tab.</p> | |
</div> | |
<div x-show="currentTab === 'second'"> | |
<p>Second tab.</p> | |
</div> | |
<div x-show="currentTab === 'third'"> | |
<p>Third tab.</p> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment