From 4ea61521945c343e851382c2d7c4e6a607377426 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 23 Feb 2022 08:14:00 +1100 Subject: [PATCH] Add Accessories/Overflow --- src/Blockkit/Blocks/Accessories/Overflow.php | 61 ++++++++++++++++++++ src/Blockkit/Modal.php | 2 + 2 files changed, 63 insertions(+) create mode 100644 src/Blockkit/Blocks/Accessories/Overflow.php 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