-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit bca6084
Showing
13 changed files
with
623 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
{ | ||
"name": "focalstrategy/core", | ||
"description": "Core Library for Focal Strategy's components", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Shane Glee", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"myclabs/php-enum": "^1.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"FocalStrategy\\Core\\": "src" | ||
} | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace FocalStrategy\Core; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
class BaseBgType extends Enum | ||
{ | ||
const NONE = 'none'; | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace FocalStrategy\Core; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
class BaseBtnType extends Enum | ||
{ | ||
const NONE = 'btn-default'; | ||
} |
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,131 @@ | ||
<?php | ||
|
||
namespace FocalStrategy\Core\Buttons; | ||
|
||
use FocalStrategy\Core\ReceivesData; | ||
use FocalStrategy\Core\BaseBtnType; | ||
use FocalStrategy\Core\Renderable; | ||
use View; | ||
|
||
class Button implements Renderable, ReceivesData | ||
{ | ||
protected $text; | ||
protected $action_type; | ||
protected $url_template; | ||
protected $data_attributes = []; | ||
protected $attributes = [ | ||
'class' => 'btn ' | ||
]; | ||
|
||
public function __construct($text, $url, BaseBtnType $action_type) | ||
{ | ||
$this->text = $text; | ||
|
||
if ($url != null) { | ||
$this->attributes['href'] = $url; | ||
} | ||
|
||
$this->attributes['class'] .= $action_type; | ||
} | ||
|
||
public function addDataAttributes(array $data_attributes) : Button | ||
{ | ||
$this->data_attributes = $data_attributes; | ||
return $this; | ||
} | ||
|
||
public function mergeAttributes(array $attributes) : Button | ||
{ | ||
foreach ($attributes as $key => $a) { | ||
if (isset($this->attributes[$key])) { | ||
$this->attributes[$key] .= ' '.$a; | ||
} else { | ||
$this->attributes[$key] = $a; | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function getText() : string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function isButton() : bool | ||
{ | ||
return !isset($this->attributes['href']); | ||
} | ||
|
||
public function getRoute() : string | ||
{ | ||
return $this->attributes['href'] ?? ''; | ||
} | ||
|
||
public function attributes() : string | ||
{ | ||
$result = ''; | ||
foreach ($this->attributes as $key => $attr) { | ||
$result .= ' '.$key.'="'.$attr.'"'; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function getDataAttributes() : string | ||
{ | ||
$result = ''; | ||
foreach ($this->data_attributes as $key => $attr) { | ||
$result .= ' '.$key.'="'.$attr.'"'; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function setTarget($target) : Button | ||
{ | ||
$this->attributes['target'] = $target; | ||
|
||
return $this; | ||
} | ||
|
||
public function setUrlTemplate(string $template) : Button | ||
{ | ||
$this->url_template = $template; | ||
|
||
return $this; | ||
} | ||
|
||
public function addData(array $data) | ||
{ | ||
if ($this->url_template) { | ||
$url = $this->url_template; | ||
foreach ($data as $key => $value) { | ||
$url = str_replace('+'.$key.'+', $value, $url); | ||
$url = str_replace('%2B'.$key.'%2B', $value, $url); | ||
} | ||
$this->attributes['href'] = $url; | ||
} | ||
|
||
if ($this->text) { | ||
$text = $this->text; | ||
foreach ($data as $key => $value) { | ||
if (!is_array($value)) { | ||
$text = str_replace('+'.$key.'+', $value, $text); | ||
$text = str_replace('%2B'.$key.'%2B', $value, $text); | ||
} | ||
} | ||
$this->text = $text; | ||
} | ||
} | ||
|
||
public function hasAttribute($key) | ||
{ | ||
return isset($this->attributes[$key]); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('_components.button')->with('button', $this); | ||
} | ||
} |
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,73 @@ | ||
<?php | ||
|
||
namespace FocalStrategy\Core\Buttons; | ||
|
||
use FocalStrategy\Core\BaseBtnType; | ||
use View; | ||
|
||
class ButtonGroupDropdown implements Renderable | ||
{ | ||
protected $text; | ||
protected $action_type; | ||
protected $attributes = [ | ||
'class' => 'btn ' | ||
]; | ||
|
||
public function __construct($text, $url, BaseBtnType $action_type, $buttons) | ||
{ | ||
$this->text = $text; | ||
|
||
if ($url != null) { | ||
$this->attributes['href'] = $url; | ||
} | ||
|
||
$this->attributes['class'] .= $action_type; | ||
$this->buttons = $buttons; | ||
} | ||
|
||
public function mergeAttributes(array $attributes) | ||
{ | ||
foreach ($attributes as $key => $a) { | ||
if (isset($this->attributes[$key])) { | ||
$this->attributes[$key] .= ' '.$a; | ||
} else { | ||
$this->attributes[$key] = $a; | ||
} | ||
} | ||
} | ||
|
||
public function getText() | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function isButton() | ||
{ | ||
return !isset($this->attributes['href']); | ||
} | ||
|
||
public function getRoute() | ||
{ | ||
return $this->attributes['href'] ?? ''; | ||
} | ||
|
||
public function attributes() | ||
{ | ||
$result = ''; | ||
foreach ($this->attributes as $key => $attr) { | ||
$result .= ' '.$key.'="'.$attr.'"'; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function setTarget($target) | ||
{ | ||
$this->attributes['target'] = $target; | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('_components.button_group_dropdown')->with('button', $this); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace FocalStrategy\Core\Buttons; | ||
|
||
use FocalStrategy\Core\BaseBtnType; | ||
|
||
class ImageButton extends Button | ||
{ | ||
protected $img_url; | ||
|
||
public function __construct($img_url, $route) | ||
{ | ||
parent::__construct('', $route, BaseBtnType::NONE()); | ||
$this->img_url = $img_url; | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('_components.image_button')->with('button', $this); | ||
} | ||
|
||
public function getImage() | ||
{ | ||
return $this->img_url; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace FocalStrategy\Core\Buttons; | ||
|
||
use FocalStrategy\Core\BaseBtnType; | ||
|
||
class PostButton extends Button | ||
{ | ||
protected $data; | ||
|
||
public function __construct($text, $action, $data, BaseBtnType $btn_type) | ||
{ | ||
parent::__construct($text, $action, $btn_type); | ||
$this->data = $data; | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('_components.post_button')->with('button', $this); | ||
} | ||
|
||
public function data() | ||
{ | ||
return $this->data; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace FocalStrategy\Core; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class CoreServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
} | ||
|
||
/** | ||
* Bootstrap services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->loadViewsFrom(__DIR__.'/views', 'core'); | ||
$this->publishes([ | ||
__DIR__.'/views' => resource_path('views/vendor/core'), | ||
]); | ||
} | ||
} |
Oops, something went wrong.