Skip to content

Commit

Permalink
Added copy code button for the example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oia20 committed Apr 27, 2024
1 parent 15b09cd commit 277bca9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
16 changes: 15 additions & 1 deletion CropSQL/Pages/Components/Terminal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,21 @@
<h2>Prompt</h2>

<p>@prompt[termNum - 1]</p>
<div class="flex-row">
<h3>Example:</h3>
<div class="exampleCode">
<button class="copy-button" @onclick="CopyToClipboard">
<span>Copy Code</span>
<!-- You can use an icon here if you prefer -->
<!-- Example: <i class="fas fa-copy"></i> -->
</button>
</div>
<div class="exampleCode" @onclick="CopyToClipboard">

@foreach (string lines in codeSample[termNum - 1])
{
<p class="code-line">@string.Join(" ", lines)</p>
}

</div>
</div>
</div>
Expand All @@ -95,6 +104,11 @@
{
isDropdownVisible = !isDropdownVisible;
}
private async Task CopyToClipboard()
{
var codeContent = string.Join("\n", codeSample[termNum - 1]);
await JSRuntime.InvokeVoidAsync("copyToClipboard", codeContent);
}
private void ButtonClicked() {
AddCommand(currentInput);
currentInput = ""; // Clear the input field
Expand Down
27 changes: 27 additions & 0 deletions CropSQL/Pages/Components/Terminal.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ h2 {

h3 {
text-align: left;
display: flex;
align-items: center;
}


Expand Down Expand Up @@ -218,4 +220,29 @@ h3 {

.code-line {
text-align: left;
}

.copy-button {
bottom: 5px; /* Adjust the positioning as needed */
right: 5px; /* Adjust the positioning as needed */
padding: 5px 10px;
background-color: rgba(49, 87, 54, 0.664);
border: 2px solid #e8a073; /* Solid border */
border-radius: 20px;
color: #f4d35d;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin: 14px;
}

.copy-button:hover {
color:#f4d35d;
background-color: #e8a073;
border-color: rgba(49, 87, 54, 0.664);
}

.flex-row {
display: flex;
flex-direction: row;
}
3 changes: 3 additions & 0 deletions CropSQL/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
inputRef.value = ""
return
}
window.copyToClipboard = function(text) {
navigator.clipboard.writeText(text);
}
</script>

</body>
Expand Down

0 comments on commit 277bca9

Please sign in to comment.