mirror of https://github.com/xfarrow/phpxpress.git
dropdown
This commit is contained in:
parent
b76a67562e
commit
2040d745c9
|
@ -0,0 +1,18 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Dropdown example</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
include "../phpxpress/dropdown.php";
|
||||
|
||||
$dropdown = new Dropdown;
|
||||
|
||||
$dropdown->setTitle("Title");
|
||||
$dropdown->setDataSource(array("AA" => "#" , "BB" => "#"));
|
||||
$dropdown->setSize("large");
|
||||
$dropdown->draw();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,64 @@
|
|||
<script type="text/javascript" src="../bootstrap-5.1.3-dist/js/bootstrap.bundle.js"></script>
|
||||
<?php
|
||||
include "include.php";
|
||||
|
||||
class Dropdown{
|
||||
|
||||
private $title;
|
||||
private $datasource;
|
||||
private $color = 'secondary';
|
||||
private $size;
|
||||
|
||||
// Associative array name => link
|
||||
public function setDataSource(Array $datasource){
|
||||
$this->datasource = $datasource;
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function setColor($color){
|
||||
$this->color = Code::bootstrapColors($color);
|
||||
}
|
||||
|
||||
public function setSize($size){
|
||||
if($size == "default")
|
||||
$this->size = NULL;
|
||||
|
||||
else if($size == "large")
|
||||
$this->size = "btn-lg";
|
||||
|
||||
else if($size == "small")
|
||||
$this->size = "btn-sm";
|
||||
|
||||
else
|
||||
throw new InvalidArgumentException('Parameter size must be either default, large or small.');
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function draw(){
|
||||
|
||||
$btnClass = 'btn btn-' . $this->color . ' dropdown-toggle';
|
||||
if(isset($this->size)){
|
||||
$btnClass .= ' ' . $this->size;
|
||||
}
|
||||
|
||||
echo '<div class="dropdown">';
|
||||
|
||||
// Title
|
||||
echo '<button class="' . $btnClass .'" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">';
|
||||
echo $this->title;
|
||||
echo '</button>';
|
||||
|
||||
echo '<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">';
|
||||
|
||||
foreach($this->datasource as $name => $link){
|
||||
echo '<li><a class="dropdown-item" href="' . $link . '">' . $name . '</a></li>';
|
||||
}
|
||||
|
||||
echo '</ul></div>';
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue