From 5b1c6968f3cc41140b4b0ed1d50989210a5efb35 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Mon, 30 Sep 2019 20:03:57 +0900 Subject: [PATCH 1/4] Add input-compatible props to selectable elements By passing label prop, they are wrapped in Input layout block. --- docs/jsx-components-for-block-kit.md | 92 +++++++++++++++++++--- src/block-kit/Input.tsx | 9 ++- src/block-kit/elements/Select.tsx | 109 +++++++++++++++++---------- test/index.tsx | 52 ++++++++++++- 4 files changed, 207 insertions(+), 55 deletions(-) diff --git a/docs/jsx-components-for-block-kit.md b/docs/jsx-components-for-block-kit.md index 86149d2f..4362f7e7 100644 --- a/docs/jsx-components-for-block-kit.md +++ b/docs/jsx-components-for-block-kit.md @@ -245,7 +245,7 @@ If you want to use `` as layout block, you have to place the one of avail ```jsx - + @@ -257,7 +257,7 @@ If you want to use `` as layout block, you have to place the one of avail - `label` (**required**): The label string for the element. - `id` / `blockId` (optional): A string of unique identifier of block. -- `hint` (optional): Specify a helpful text appears under the element. +- `title`/ `hint` (optional): Specify a helpful text appears under the element. `title` is alias to `hint` prop for keeping HTML compatibility. - `required` (optional): A boolean prop to specify whether any value must be filled when user confirms modal. `false` by default for HTML compatibility, and _notice that it is different from Slack's default._ #### Available elements as a child @@ -268,8 +268,6 @@ If you want to use `` as layout block, you have to place the one of avail - [``](#conversationsselect-select-menu-with-conversations-list) - [``](#channelsselect-select-menu-with-channel-list) -In jsx-slack, [`` component also can use as the block element for plain text input in modal.](#input-element) - ## Block elements Some blocks may include block elements. e.g. the interactive component to exchange info with Slack app. @@ -319,7 +317,9 @@ A menu element with static options passed by ``. It has [](https://api.slack.com/tools/block-kit-builder?blocks=%5B%7B%22type%22%3A%22actions%22%2C%22elements%22%3A%5B%7B%22type%22%3A%22static_select%22%2C%22placeholder%22%3A%7B%22type%22%3A%22plain_text%22%2C%22text%22%3A%22Rate%20it!%22%2C%22emoji%22%3Atrue%7D%2C%22action_id%22%3A%22rating%22%2C%22options%22%3A%5B%7B%22value%22%3A%225%22%2C%22text%22%3A%7B%22text%22%3A%225%20%3Astar%3A%3Astar%3A%3Astar%3A%3Astar%3A%3Astar%3A%22%2C%22type%22%3A%22plain_text%22%2C%22emoji%22%3Atrue%7D%7D%2C%7B%22value%22%3A%224%22%2C%22text%22%3A%7B%22text%22%3A%224%20%3Astar%3A%3Astar%3A%3Astar%3A%3Astar%3A%22%2C%22type%22%3A%22plain_text%22%2C%22emoji%22%3Atrue%7D%7D%2C%7B%22value%22%3A%223%22%2C%22text%22%3A%7B%22text%22%3A%223%20%3Astar%3A%3Astar%3A%3Astar%3A%22%2C%22type%22%3A%22plain_text%22%2C%22emoji%22%3Atrue%7D%7D%2C%7B%22value%22%3A%222%22%2C%22text%22%3A%7B%22text%22%3A%222%20%3Astar%3A%3Astar%3A%22%2C%22type%22%3A%22plain_text%22%2C%22emoji%22%3Atrue%7D%7D%2C%7B%22value%22%3A%221%22%2C%22text%22%3A%7B%22text%22%3A%221%20%3Astar%3A%22%2C%22type%22%3A%22plain_text%22%2C%22emoji%22%3Atrue%7D%7D%5D%7D%5D%7D%5D) -By defining `multiple` attribute, you also can provide [the selectable menu from multiple options][multi-select] with an appearance is similar to button or text input. The same goes for other menu-like components. +#### Multiple select + +By defining `multiple` attribute, you also can provide [the selectable menu from multiple options][multi-select] with an appearance is similar to button or text input. The same goes for other select-like components. [multi-select]: https://api.slack.com/reference/block-kit/block-elements#multi_select @@ -346,9 +346,46 @@ By defining `multiple` attribute, you also can provide [the selectable menu from > :warning: Slack does not allow to place the multi-select menu in `Actions` block. So jsx-slack throws error if you're trying to use `multiple` attribute in the children of ``. +#### Usage in `` container + +In `` container, select-like components may place as children of `` directly by wrapping in [`` layout block](#input-block) by passing `label` prop. Thereby it would allow natural templating like as HTML form style. + +```jsx + + + +``` + +The above JSX means exactly same as following: + + + +```jsx + + + + + +``` + + + #### Props -- `actionId` (optional): An identifier for the action. +- `name` / `actionId` (optional): An identifier for the action. - `placeholder` (optional): A plain text to be shown at first. - `value` (optional): A value of item to show initially. It must choose value from defined `