Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit ed7c670

Browse files
committed
add signature , datepicker wip
Signed-off-by: Dieter Coopman <dieter@deltasolutions.be>
1 parent cbb5953 commit ed7c670

File tree

8 files changed

+95
-2
lines changed

8 files changed

+95
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ composer require lloadout/components
1717
- [Blade Ui Kit](https://github.com/blade-ui-kit)
1818
- [Apex charts](https://apexcharts.com/)
1919
- [Select 2](https://select2.org/)
20+
- [Signature pad](https://github.com/szimek/signature_pad)
2021

2122
## Extra LLoadout components
2223

@@ -75,4 +76,10 @@ For the stacked barchart you can use the same tag as for the simple barchart , i
7576
#### Linechart
7677
<x-load-linechart title="Provide a title" key="delayed-{{ now() }}" :data="[10,20,70]" :labels="['a']"></x-load-linechart>
7778

79+
### Signature
80+
81+
This signature component will create a textfield in your html , in that textfield a base64 encoded png stream will be stored.
82+
83+
<x-load-signature name="my-signature" width="400" height="400" background="white" color="black" />
84+
7885

resources/assets/js/signature.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function signPad() {
2+
return {
3+
signature: '',
4+
jpeg: '',
5+
draw(width = 500, height = 400, background = 'white', color = 'black') {
6+
var canvas = document.createElement('canvas');
7+
canvas.width = width;
8+
canvas.height = height;
9+
canvas.style.zIndex = 8;
10+
canvas.style.background = background;
11+
canvas.style.position = "absolute";
12+
canvas.style.border = "1px solid #C0C0C0";
13+
canvas.position = "relative";
14+
15+
this.signature = new SignaturePad(canvas);
16+
this.signature.minWidth = 2;
17+
this.signature.maxWidth = 2;
18+
this.signature.penColor = color;
19+
this.signature.onEnd = () => this.save();
20+
21+
this.$el.appendChild(canvas);
22+
},
23+
save() {
24+
this.jpeg = this.signature.toDataURL("image/png");
25+
},
26+
clear() {
27+
this.signature.clear();
28+
}
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<input {{ $attributes->merge(['class' => 'daterangepicker'])}} type="text" />
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<livewire:signature :name="$name" :width="$width" :height="$height" :background="$background" :color="$color">
2+
</livewire:signature>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div x-data="signPad()" x-init="draw(@this.width,@this.height,@this.background,@this.color)"
2+
style="position: relative;height: {{ $height + 30}}px; width:{{ $width }}px">
3+
<button x-on:click="clear()" style="display:block;position: relative; top:37px; left:7px; z-index: 100;background: #ff6961; padding:4px;border-radius:4px">
4+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" style="height: 20px; color:white">
5+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
6+
</svg>
7+
</button>
8+
<input type="hidden" name="{{ $name }}" x-bind:value="jpeg" />
9+
</div>

src/Http/Livewire/Signature.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace LLoadoutComponents\Http\Livewire;
4+
5+
use Livewire\Component;
6+
7+
class Signature extends Component
8+
{
9+
public $width;
10+
public $height;
11+
public $background;
12+
public $name;
13+
public $color;
14+
15+
public function mount($width, $height, $background, $name, $color)
16+
{
17+
$this->width = $width;
18+
$this->height = $height;
19+
$this->background = $background;
20+
$this->name = $name;
21+
$this->color = $color;
22+
}
23+
24+
public function render()
25+
{
26+
return view('load::livewire.signature.signature');
27+
}
28+
}

src/LLoadoutComponents.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,28 @@ public static function outputScripts(): string
1111
{
1212

1313
$scripts = [
14-
"charts" => [
14+
"charts" => [
1515
'<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>',
1616
'<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>',
1717
'<script>function drawBarChart(e,t,a,n,r){if(a);else;var i,o={title:{text:n,align:"left",margin:10,offsetX:0,offsetY:0,floating:!1,style:{fontSize:"14px",fontWeight:"bold",fontFamily:void 0,color:"#263238"}},chart:{type:"bar",toolbar:{export:{csv:{filename:n+".csv",columnDelimiter:";",headerCategory:"category",headerValue:"value",dateFormatter:e=>new Date(e).toDateString()},svg:{filename:n+".svg"},png:{filename:n+".png"}}}},series:t,xaxis:{categories:e,labels:{show:!0,rotate:-45}},dataLabels:{enabled:!1},plotOptions:{bar:{horizontal:a,dataLabels:{position:"top"}}},grid:{show:!0,xaxis:{lines:{show:!0}},yaxis:{lines:{show:!0}}}},l=document.getElementById("bar-chart-"+r);l.innerHTML="",(i=document.createElement("div")).id="chart-"+r,l.appendChild(i),(i=new ApexCharts(document.getElementById("chart-"+r),o)).render()}function drawPieChart(e,t,a,n){var r,i={title:{text:a,align:"left",margin:10,offsetX:0,offsetY:0,floating:!1,style:{fontSize:"14px",fontWeight:"bold",fontFamily:void 0,color:"#263238"}},series:t,chart:{type:"pie"},labels:e,responsive:[{breakpoint:480,options:{chart:{width:200},legend:{position:"bottom"}}}]},o=document.getElementById("pie-chart-"+n);o.innerHTML="",(r=document.createElement("div")).id="chart-"+n,o.appendChild(r),(r=new ApexCharts(document.getElementById("chart-"+n),i)).render()}function drawLineChart(e,t,a,n){var r,i={series:[{data:t}],chart:{height:350,type:"line",zoom:{enabled:!1}},dataLabels:{enabled:!1},stroke:{curve:"straight"},title:{text:"Product Trends by Month",align:"left"},grid:{row:{colors:["#f3f3f3","transparent"],opacity:.5}},xaxis:{categories:e}},o=document.getElementById("line-chart-"+n);o.innerHTML="",(r=document.createElement("div")).id="chart-"+n,o.appendChild(r),(r=new ApexCharts(document.getElementById("chart-"+n),i)).render()}</script>'
1818
],
19-
"select" => [
19+
"select" => [
2020
'<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />',
2121
'<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>',
2222
'<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>',
2323
'<script>$(".searchable").select2();</script>'
24+
],
25+
"daterange" => [
26+
'<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>',
27+
'<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>',
28+
'<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>',
29+
'<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />',
30+
'<script>$(".daterangepicker").daterangepicker();</script>'
31+
],
32+
"signature" => [
33+
'<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>',
34+
'<script src="https://cdn.jsdelivr.net/npm/signature_pad@2.3.2/dist/signature_pad.min.js"></script>',
35+
'<script>function signPad(){return{signature:"",jpeg:"",draw(t=500,e=400,i="white",s="black"){var a=document.createElement("canvas");a.width=t,a.height=e,a.style.zIndex=8,a.style.background=i,a.style.position="absolute",a.style.border="1px solid #C0C0C0",a.position="relative",this.signature=new SignaturePad(a),this.signature.minWidth=2,this.signature.maxWidth=2,this.signature.penColor=s,this.signature.onEnd=(()=>this.save()),this.$el.appendChild(a)},save(){this.jpeg=this.signature.toDataURL("image/png")},clear(){this.signature.clear()}}}</script>'
2436
]
2537
];
2638

src/LLoadoutComponentsServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use LLoadoutComponents\Http\Livewire\BarChart;
88
use LLoadoutComponents\Http\Livewire\LineChart;
99
use LLoadoutComponents\Http\Livewire\PieChart;
10+
use LLoadoutComponents\Http\Livewire\Signature;
1011

1112

1213
class LLoadoutComponentsServiceProvider extends ServiceProvider
@@ -33,6 +34,8 @@ protected function bootBladeComponents()
3334
Blade::component('load::blade.charts.piechart', "load-piechart");
3435
Blade::component('load::blade.charts.linechart', "load-linechart");
3536
Blade::component('load::blade.forms.select', "load-select");
37+
Blade::component('load::blade.forms.daterange', "load-daterange");
38+
Blade::component('load::blade.signature.signature', "load-signature");
3639
});
3740
}
3841

@@ -41,6 +44,7 @@ protected function bootLivewireComponents()
4144
Livewire::component('barchart', BarChart::class);
4245
Livewire::component('piechart', PieChart::class);
4346
Livewire::component('linechart', LineChart::class);
47+
Livewire::component('signature', Signature::class);
4448
}
4549

4650
private function bootDirectives(): void

0 commit comments

Comments
 (0)