-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
9 changed files
with
294 additions
and
94 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
/* | ||
@layer components { | ||
.btn-primary { | ||
@apply py-2 px-4 bg-blue-200; | ||
} | ||
} | ||
*/ |
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,19 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static targets = ["source"]; | ||
|
||
copy(event) { | ||
event.preventDefault(); | ||
navigator.clipboard.writeText(this.sourceTarget.value); | ||
|
||
this.sourceTarget.focus(); | ||
var triggerElement = this.triggerTarget; | ||
var initialHTML = triggerElement.innerHTML; | ||
triggerElement.innerHTML = "<span style='color:grey;'>Copied</span>"; | ||
setTimeout(() => { | ||
triggerElement.innerHTML = initialHTML; | ||
this.sourceTarget.blur(); | ||
}, 2000); | ||
} | ||
} |
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,15 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static targets = ["text", "uploadIcon", "fileIcon"]; | ||
|
||
display(event) { | ||
const file = event.target.files[0]; | ||
if (file) { | ||
const fileName = file.name; | ||
this.textTarget.innerHTML = `${fileName}`; | ||
this.uploadIconTarget.classList.toggle("hidden"); | ||
this.fileIconTarget.classList.toggle("hidden"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static classes = ["activeTab", "inactiveTab"]; | ||
static targets = ["tab", "panel", "select"]; | ||
static values = { | ||
index: 0, | ||
updateAnchor: Boolean, | ||
}; | ||
|
||
connect() { | ||
if (this.anchor) | ||
this.indexValue = this.tabTargets.findIndex( | ||
(tab) => tab.id === this.anchor, | ||
); | ||
this.showTab(); | ||
} | ||
|
||
// Changes to the clicked tab | ||
change(event) { | ||
if (event.currentTarget.tagName === "SELECT") { | ||
this.indexValue = event.currentTarget.selectedIndex; | ||
|
||
// If target specifies an index, use that | ||
} else if (event.currentTarget.dataset.index) { | ||
this.indexValue = event.currentTarget.dataset.index; | ||
|
||
// If target specifies an id, use that | ||
} else if (event.currentTarget.dataset.id) { | ||
this.indexValue = this.tabTargets.findIndex( | ||
(tab) => tab.id == event.currentTarget.dataset.id, | ||
); | ||
|
||
// Otherwise, use the index of the current target | ||
} else { | ||
this.indexValue = this.tabTargets.indexOf(event.currentTarget); | ||
} | ||
event.stopPropagation(); | ||
window.dispatchEvent(new CustomEvent("tsc:tab-change")); | ||
} | ||
|
||
nextTab() { | ||
this.indexValue = Math.min(this.indexValue + 1, this.tabsCount - 1); | ||
} | ||
|
||
previousTab() { | ||
this.indexValue = Math.max(this.indexValue - 1, 0); | ||
} | ||
|
||
firstTab() { | ||
this.indexValue = 0; | ||
} | ||
|
||
lastTab() { | ||
this.indexValue = this.tabsCount - 1; | ||
} | ||
|
||
indexValueChanged() { | ||
this.showTab(); | ||
|
||
// Update URL with the tab ID if it has one | ||
// This will be automatically selected on page load | ||
if (this.updateAnchorValue) { | ||
location.hash = this.tabTargets[this.indexValue].id; | ||
} | ||
} | ||
|
||
showTab() { | ||
this.panelTargets.forEach((panel, index) => { | ||
const tab = this.tabTargets[index]; | ||
|
||
if (index === this.indexValue) { | ||
panel.classList.remove("hidden"); | ||
if (this.hasInactiveTabClass) | ||
tab?.classList?.remove(...this.inactiveTabClasses); | ||
if (this.hasActiveTabClass) | ||
tab?.classList?.add(...this.activeTabClasses); | ||
} else { | ||
panel.classList.add("hidden"); | ||
if (this.hasActiveTabClass) | ||
tab?.classList?.remove(...this.activeTabClasses); | ||
if (this.hasInactiveTabClass) | ||
tab?.classList?.add(...this.inactiveTabClasses); | ||
} | ||
}); | ||
|
||
if (this.hasSelectTarget) { | ||
this.selectTarget.selectedIndex = this.indexValue; | ||
} | ||
} | ||
|
||
get tabsCount() { | ||
return this.tabTargets.length; | ||
} | ||
|
||
get anchor() { | ||
return document.URL.split("#").length > 1 | ||
? document.URL.split("#")[1] | ||
: null; | ||
} | ||
} |
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
Oops, something went wrong.