Skip to content

Commit 26b949c

Browse files
committed
Added possibility to upload file in textarea (WIP)
1 parent 9713a45 commit 26b949c

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

LinkDotNet.Blog.Web/Pages/Admin/CreateNew.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
</div>
2424
<div class="form-group">
2525
<label for="content">Content</label>
26-
<InputTextArea class="form-control" id="content" @bind-Value="_model.Content" rows="10"/>
26+
<InputTextAreaDragAndDropFile class="form-control" id="content" @bind-Value="_model.Content" rows="10" />
27+
<small id="content" class="form-text text-muted">Drag and drop images to upload and insert picture.</small>
2728
</div>
2829
<div class="form-group">
2930
<label for="preview">Preview-Url</label>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<style>
2+
.can-drop {
3+
border: 2px dashed green;
4+
}
5+
</style>
6+
<div>
7+
<InputTextArea
8+
@attributes="AdditionalAttributes"
9+
class="@_cssClass"
10+
@bind-Value="@BindingValue"
11+
ondragover="event.stopPropagation(); event.preventDefault();"
12+
ondragstart="event.stopPropagation(); event.preventDefault();"
13+
ondragexit="event.stopPropagation(); event.preventDefault();"
14+
ondragend="event.stopPropagation(); event.preventDefault();"
15+
@ondrop="HandleDrop"
16+
@ondragenter="HandleDragEnter"
17+
@ondragleave="HandleDragLeave"/>
18+
</div>
19+
20+
@code {
21+
private string _dropClass = string.Empty;
22+
private string _otherClasses = string.Empty;
23+
private string _cssClass => _dropClass + " " + _otherClasses;
24+
25+
private string _value;
26+
27+
[Parameter]
28+
public string BindingValue
29+
{
30+
get => _value;
31+
set
32+
{
33+
if (_value == value ) return;
34+
_value = value;
35+
BindingValueChanged.InvokeAsync(value);
36+
}
37+
}
38+
39+
[Parameter]
40+
public EventCallback<string> BindingValueChanged { get; set; }
41+
42+
[Parameter(CaptureUnmatchedValues = true)]
43+
public IReadOnlyDictionary<string, object> AdditionalAttributes { get; set; }
44+
45+
protected override void OnParametersSet()
46+
{
47+
if (AdditionalAttributes != null && AdditionalAttributes.ContainsKey("class"))
48+
{
49+
_otherClasses = AdditionalAttributes["class"].ToString();
50+
}
51+
}
52+
53+
private void HandleDrop(DragEventArgs args)
54+
{
55+
_dropClass = string.Empty;
56+
//// This will only work with .NET 6
57+
// var files = args.DataTransfer.Files;
58+
}
59+
60+
private void HandleDragEnter()
61+
{
62+
_dropClass = "can-drop";
63+
}
64+
65+
private void HandleDragLeave()
66+
{
67+
_dropClass = string.Empty;
68+
}
69+
}

0 commit comments

Comments
 (0)