Add Accessories/Overflow

This commit is contained in:
Deon George 2022-02-23 08:14:00 +11:00
parent 181365f456
commit 4ea6152194
2 changed files with 63 additions and 0 deletions

View 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;
}
}

View File

@ -92,6 +92,8 @@ final class Modal extends BlockKit
throw new Exception(sprintf('Unknown action %s',$string));
$this->action = $string;
return $this;
}
public function clear_on_close(bool $bool): self