diff --git a/src/Blockkit/Blocks/Accessories/Overflow.php b/src/Blockkit/Blocks/Accessories/Overflow.php new file mode 100644 index 0000000..577bde9 --- /dev/null +++ b/src/Blockkit/Blocks/Accessories/Overflow.php @@ -0,0 +1,61 @@ + 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; + } +} \ No newline at end of file diff --git a/src/Blockkit/Modal.php b/src/Blockkit/Modal.php index 8761304..d308201 100644 --- a/src/Blockkit/Modal.php +++ b/src/Blockkit/Modal.php @@ -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