Add Accessories/Overflow
This commit is contained in:
parent
181365f456
commit
4ea6152194
61
src/Blockkit/Blocks/Accessories/Overflow.php
Normal file
61
src/Blockkit/Blocks/Accessories/Overflow.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Slack\Blockkit\Blocks\Accessories;
|
||||||
|
|
||||||
|
use \Exception;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Slack\Blockkit\Blocks\Elements\Text;
|
||||||
|
use Slack\Blockkit\Element;
|
||||||
|
|
||||||
|
final class Overflow extends Element
|
||||||
|
{
|
||||||
|
protected const LIMITS = [
|
||||||
|
'action_id' => 255,
|
||||||
|
];
|
||||||
|
|
||||||
|
private const MIN_OPTIONS = 1;
|
||||||
|
private const MAX_OPTIONS = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Text $placeholder
|
||||||
|
* @param string $action_id
|
||||||
|
* @param Collection $options
|
||||||
|
* @throws Exception
|
||||||
|
* @todo We dont handle option_groups yet.
|
||||||
|
*/
|
||||||
|
public function __construct(string $action_id,Collection $options)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
$this->type = 'overflow';
|
||||||
|
|
||||||
|
$this->action_id = $this->validate('action_id',$action_id);
|
||||||
|
|
||||||
|
if (count($options) < self::MIN_OPTIONS)
|
||||||
|
throw new Exception(sprintf('Must have atleast %d options',self::MIN_OPTIONS));
|
||||||
|
|
||||||
|
if (count($options) > self::MAX_OPTIONS)
|
||||||
|
throw new Exception(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
||||||
|
|
||||||
|
$this->options = $options->transform(function($item) {
|
||||||
|
return ['text'=>Text::item(Arr::get($item,'name'),'plain_text'),'value'=>(string)Arr::get($item,'id')];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function item(string $action_id,Collection $options): self
|
||||||
|
{
|
||||||
|
return new self($action_id,$options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OPTIONAL ITEMS */
|
||||||
|
|
||||||
|
public function confirm(Confirm $confirm): self
|
||||||
|
{
|
||||||
|
$this->confirm = $confirm;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -92,6 +92,8 @@ final class Modal extends BlockKit
|
|||||||
throw new Exception(sprintf('Unknown action %s',$string));
|
throw new Exception(sprintf('Unknown action %s',$string));
|
||||||
|
|
||||||
$this->action = $string;
|
$this->action = $string;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clear_on_close(bool $bool): self
|
public function clear_on_close(bool $bool): self
|
||||||
|
Loading…
Reference in New Issue
Block a user