Skip to content

Commit d732ba1

Browse files
authored
Merge pull request #87 from raycharius/v2.5.0
✨ Release v2.5.0
2 parents 9dda415 + d18e885 commit d732ba1

File tree

19 files changed

+328
-9
lines changed

19 files changed

+328
-9
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ The `Utilities` object contains various utility functions for creating UI. Curre
345345

346346
`AttachmentCollection()` – Accepts multiple arguments or an array of attachments and returns them in an array, in their built state.
347347

348-
These two functions are useful when you wish to keep surface or view configuration separate from UI representation.
348+
`OptionCollection()` – Accepts multiple arguments or an array of options and returns them in an array, in their built state.
349+
350+
`OptionGroupCollection()` – Accepts multiple arguments or an array of option groups and returns them in an array, in their built state.
351+
352+
Both `BlockCollection()` and `AttachmentCollection()` are useful when you wish to keep surface or view configuration separate from UI representation.
349353

350354
An example using Slack's `WebClient` from their [SDK for Node.js](https://github.com/slackapi/node-slack-sdk):
351355

@@ -382,6 +386,16 @@ const unfurl = ({ channel, ts, url }) => client.chat.unfurl({
382386
.catch((error) => console.log(error));
383387
```
384388

389+
Both `OptionCollection()` and `OptionGroupCollection()` come in handy when returning an array of options or option groups for select menus with external data sources, as seen in [Slack's API docs](https://api.slack.com/reference/block-kit/block-elements#external_multi_select):
390+
391+
```javascript
392+
return { options: OptionCollection( /* Pass in options */ ) };
393+
394+
// Or:
395+
396+
return { options: OptionGroupCollection( /* Pass in option groups */ ) };
397+
```
398+
385399
### Working With Inline Conditionals
386400

387401
There are a few helper functions available to make it easy to work with inline conditionals within your UI source code.

docs/_sidebar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
* **Other**
7171
* [Block Collection](other/block-collection.md "Block Builder – Block Collection – Maintainable JavaScript Code for Slack Block Kit")
7272
* [Attachment Collection](other/attachment-collection.md "Block Builder – Attachment Collection – Maintainable JavaScript Code for Slack Block Kit")
73+
* [Option Collection](other/option-collection.md "Block Builder – Option Collection – Maintainable JavaScript Code for Slack Block Kit")
74+
* [Option Group Collection](other/option-group-collection.md "Block Builder – Option Group Collection – Maintainable JavaScript Code for Slack Block Kit")
7375
* [Conditionals](other/conditionals.md "Block Builder – Conditionals – Maintainable JavaScript Code for Slack Block Kit")
7476
* [Markdown](other/markdown.md "Block Builder – Markdown – Maintainable JavaScript Code for Slack Block Kit")
7577

docs/elements/button.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const myObj = Elements.Button(params?);
2323
2424
Each instance of the `ButtonBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer:
2525
26+
`accessibilityLabel` – *String*
27+
2628
`actionId` – *String*
2729
2830
`text` – *String*
@@ -49,6 +51,11 @@ ButtonBuilder.primary(boolean?);
4951
5052
For a button element, this changes the color to green. For confirmation dialogs, this sets the main button in the bottom right corner to green, which is meant to confirm the action. Defaults to `true`.
5153
```javascript
54+
ButtonBuilder.accessibilityLabel(string);
55+
```
56+
57+
A label for longer descriptive text about a button element. This label will be read out by screen readers instead of the button text object.
58+
```javascript
5259
ButtonBuilder.actionId(string);
5360
```
5461

docs/other/attachment-collection.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Attachment Collection
22

3-
?> **Note:** This document is a reference for creating a collection of blocks in **Block Builder**. For information on the business logic for the blocks in the context of the Slack Block Kit framework, visit [the official doc site](https://api.slack.com/block-kit) from Slack.
3+
?> **Note:** This document is a reference for creating a collection of attachments in **Block Builder**. For information on the business logic for the attachments in the context of the Slack Block Kit framework, visit [the official doc site](https://api.slack.com/block-kit) from Slack.
44

5-
### Creating a Attachment Collection
5+
### Creating an Attachment Collection
66

77
A block collection is an array of built block objects. The function that creates a collection, `AttachmentCollection`, is available as both a top-level import and as a member of its 'category', `Utilities`:
88

@@ -21,7 +21,7 @@ const myAttachments = Utilities.AttachmentCollection(attachments);
2121

2222
This function behaves in the same way as any other [methods that append](../setter-methods.md).
2323

24-
### When To Use a Attachment Collection
24+
### When To Use an Attachment Collection
2525

2626
In **Block Builder**, the `Message` object is more than a UI representation. It also allow you to configure the behavior of the message. However, you may prefer to keep UI representation and surface configuration separate in your application. When that's the case, using `AttachmentCollection` is the way to go.
2727

docs/other/option-collection.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Option Collection
2+
3+
?> **Note:** This document is a reference for creating a collection of options in **Block Builder**. For information on the business logic for the options in the context of the Slack Block Kit framework, visit [the official doc site](https://api.slack.com/block-kit) from Slack.
4+
5+
### Creating an Option Collection
6+
7+
An option collection is an array of built option objects. The function that creates a collection, `OptionCollection`, is available as both a top-level import and as a member of its 'category', `Utilities`:
8+
9+
```javascript
10+
import { OptionCollection } from 'slack-block-builder';
11+
12+
const myOptions = OptionCollection(options);
13+
14+
```
15+
16+
```javascript
17+
import { Utilities } from 'slack-block-builder';
18+
19+
const myOptions = Utilities.OptionCollection(options);
20+
```
21+
22+
This function behaves in the same way as any other [methods that append](../setter-methods.md).
23+
24+
### When To Use an Option Collection
25+
26+
The `OptionCollection` function is meant to be used to create a response to requests to your service made from select menus with external data sources, where you return an array of options:
27+
28+
```javascript
29+
return { options: OptionCollection( /* Pass in options */ ) };
30+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Option Group Collection
2+
3+
?> **Note:** This document is a reference for creating a collection of option groups in **Block Builder**. For information on the business logic for the option groups in the context of the Slack Block Kit framework, visit [the official doc site](https://api.slack.com/block-kit) from Slack.
4+
5+
### Creating an Option Group Collection
6+
7+
An option group collection is an array of built option group objects. The function that creates a collection, `OptionGroupCollection`, is available as both a top-level import and as a member of its 'category', `Utilities`:
8+
9+
```javascript
10+
import { OptionGroupCollection } from 'slack-block-builder';
11+
12+
const myOptionGroups = OptionGroupCollection(optionGroups);
13+
14+
```
15+
16+
```javascript
17+
import { Utilities } from 'slack-block-builder';
18+
19+
const myOptionGroups = Utilities.OptionGroupCollection(optionGroups);
20+
```
21+
22+
This function behaves in the same way as any other [methods that append](../setter-methods.md).
23+
24+
### When To Use an Option Group Collection
25+
26+
The `OptionGroupCollection` function is meant to be used to create a response to requests to your service made from select menus with external data sources, where you return an array of options or option groups:
27+
28+
```javascript
29+
return { options: OptionGroupCollection( /* Pass in option groups */ ) };
30+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "slack-block-builder",
3-
"version": "2.4.2",
3+
"version": "2.5.0",
44
"description": "Maintainable code for interactive Slack messages, modals, home tabs, and workflow steps. A must-have for the Slack Block Kit framework.",
55
"author": {
66
"name": "Ray East",

src/elements/button.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ElementType } from '../internal/constants';
33
import { SlackElementDto } from '../internal/dto';
44
import { applyMixins, getPlainTextObject, getBuilderResult } from '../internal/helpers';
55
import {
6+
AccessibilityLabel,
67
ActionId,
78
Confirm,
89
Danger,
@@ -17,13 +18,15 @@ import type { SlackDto } from '../internal/dto';
1718
import type { ConfirmationDialogBuilder } from '../bits';
1819

1920
export interface ButtonParams {
21+
accessibilityLabel?: string;
2022
actionId?: string;
2123
text?: string;
2224
url?: string;
2325
value?: string;
2426
}
2527

26-
export interface ButtonBuilder extends ActionId,
28+
export interface ButtonBuilder extends AccessibilityLabel,
29+
ActionId,
2730
Confirm<ConfirmationDialogBuilder>,
2831
Danger,
2932
End,
@@ -51,6 +54,7 @@ export class ButtonBuilder extends ElementBuilderBase {
5154
}
5255

5356
applyMixins(ButtonBuilder, [
57+
AccessibilityLabel,
5458
ActionId,
5559
Confirm,
5660
Danger,

src/elements/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export type {
6464

6565
/**
6666
* @param {Object} [params] Parameters passed to the constructor.
67+
* @param {string} [params.accessibilityLabel] Sets a longer descriptive text that will be read out by screen readers instead of the button text object.
6768
* @param {string} [params.actionId] Sets a string to be an identifier for the source of an action in interaction payloads.
6869
* @param {string} [params.text] Sets the display text for the button.
6970
* @param {string} [params.url] Sets the URL to redirect the user to when this button is clicked.

src/internal/constants/props.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ export enum Prop {
7676
IgnoreMarkdown = 'ignoreMarkdown',
7777
SubmitDisabled = 'submitDisabled',
7878
FocusOnLoad = 'focusOnLoad',
79+
AccessibilityLabel = 'accessibilityLabel',
7980
}

0 commit comments

Comments
 (0)