|
| 1 | +package blocks; |
| 2 | + |
| 3 | +import static com.slack.api.model.block.composition.BlockCompositions.plainText; |
| 4 | + |
| 5 | +import com.slack.api.model.block.ActionsBlock; |
| 6 | +import com.slack.api.model.block.Blocks; |
| 7 | +import com.slack.api.model.block.composition.BlockCompositions; |
| 8 | +import com.slack.api.model.block.composition.OptionObject; |
| 9 | +import com.slack.api.model.block.element.BlockElements; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +/** |
| 13 | + * Holds multiple interactive elements. |
| 14 | + * {@link https://docs.slack.dev/reference/block-kit/blocks/actions-block/} |
| 15 | + */ |
| 16 | +public class Actions { |
| 17 | + /** |
| 18 | + * An actions block with a select menu and a button. |
| 19 | + */ |
| 20 | + public static ActionsBlock example01() { |
| 21 | + ActionsBlock block = Blocks.actions(a -> a.blockId("actions1") |
| 22 | + .elements(List.of( |
| 23 | + BlockElements.staticSelect(s -> s.actionId("select_2") |
| 24 | + .placeholder(BlockCompositions.plainText("Which witch is the witchiest witch?")) |
| 25 | + .options(List.of( |
| 26 | + OptionObject.builder() |
| 27 | + .text(plainText("Matilda")) |
| 28 | + .value("matilda") |
| 29 | + .build(), |
| 30 | + OptionObject.builder() |
| 31 | + .text(plainText("Glinda")) |
| 32 | + .value("glinda") |
| 33 | + .build(), |
| 34 | + OptionObject.builder() |
| 35 | + .text(plainText("Granny Weatherwax")) |
| 36 | + .value("grannyWeatherwax") |
| 37 | + .build(), |
| 38 | + OptionObject.builder() |
| 39 | + .text(plainText("Hermione")) |
| 40 | + .value("hermione") |
| 41 | + .build()))), |
| 42 | + BlockElements.button(b -> b.text(BlockCompositions.plainText("Cancel")) |
| 43 | + .value("cancel") |
| 44 | + .actionId("button_1"))))); |
| 45 | + return block; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * An actions block with a datepicker, an overflow, and a button. |
| 50 | + */ |
| 51 | + public static ActionsBlock example02() { |
| 52 | + ActionsBlock block = Blocks.actions(a -> a.blockId("actionblock789") |
| 53 | + .elements(List.of( |
| 54 | + BlockElements.datePicker(d -> d.actionId("datepicker123") |
| 55 | + .initialDate("1990-04-28") |
| 56 | + .placeholder(BlockCompositions.plainText("Select a date"))), |
| 57 | + BlockElements.overflowMenu(o -> o.actionId("overflow") |
| 58 | + .options(List.of( |
| 59 | + OptionObject.builder() |
| 60 | + .text(plainText("*this is plain_text text*")) |
| 61 | + .value("value-0") |
| 62 | + .build(), |
| 63 | + OptionObject.builder() |
| 64 | + .text(plainText("*this is plain_text text*")) |
| 65 | + .value("value-1") |
| 66 | + .build(), |
| 67 | + OptionObject.builder() |
| 68 | + .text(plainText("*this is plain_text text*")) |
| 69 | + .value("value-2") |
| 70 | + .build(), |
| 71 | + OptionObject.builder() |
| 72 | + .text(plainText("*this is plain_text text*")) |
| 73 | + .value("value-3") |
| 74 | + .build(), |
| 75 | + OptionObject.builder() |
| 76 | + .text(plainText("*this is plain_text text*")) |
| 77 | + .value("value-4") |
| 78 | + .build()))), |
| 79 | + BlockElements.button(b -> b.text(BlockCompositions.plainText("Click Me")) |
| 80 | + .value("click_me_123") |
| 81 | + .actionId("button"))))); |
| 82 | + return block; |
| 83 | + } |
| 84 | +} |
0 commit comments