85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Slack\Blockkit\Blocks\Elements;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Slack\Blockkit\Element;
|
|
use Slack\Exceptions\SlackSyntaxException;
|
|
|
|
final class MultiExternalSelect extends Element
|
|
{
|
|
public const LIMITS = [
|
|
'action_id' => 255,
|
|
'placeholder' => 150,
|
|
];
|
|
|
|
public const MAX_OPTIONS = 100;
|
|
|
|
// @todo option_group? (double check it is applicable to this item)
|
|
|
|
/**
|
|
* @param string $placeholder
|
|
* @param string $action_id
|
|
* @throws SlackSyntaxException
|
|
*/
|
|
public function __construct(string $placeholder,string $action_id)
|
|
{
|
|
parent::__construct();
|
|
|
|
// Defaults
|
|
$this->type = 'multi_external_select';
|
|
|
|
$this->placeholder = Text::item($this->validate('placeholder',$placeholder),'plain_text');
|
|
$this->action_id = $this->validate('action_id',$action_id);
|
|
}
|
|
|
|
public static function item(string $placeholder,string $action_id): self
|
|
{
|
|
return new self($placeholder,$action_id);
|
|
}
|
|
|
|
/* OPTIONAL ITEMS */
|
|
|
|
public function confirm(Confirm $confirm): self
|
|
{
|
|
$this->confirm = $confirm;
|
|
|
|
return $this;
|
|
}
|
|
|
|
// @note only 1 element in a view can have this set to true
|
|
public function focus_on_load(bool $bool): self
|
|
{
|
|
$this->focus_on_load = $bool;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function initial_options(Collection $array=NULL): self
|
|
{
|
|
$this->initial_options = $array->map(function($item) { return ['text'=>['type'=>'plain_text','text'=>$item->name],'value'=>(string)$item->value]; });
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function min_query_length(int $int): self
|
|
{
|
|
if ($int < 1)
|
|
throw new SlackSyntaxException('Minimum 1 options must be configured');
|
|
|
|
$this->min_query_length = $int;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function max_selected_items(int $int): self
|
|
{
|
|
if ($int < 1)
|
|
throw new SlackSyntaxException('Minimum 1 options must be configured');
|
|
|
|
$this->max_selected_items = $int;
|
|
|
|
return $this;
|
|
}
|
|
} |