Skip to content

Commit 449b58d

Browse files
authored
overflow menu element (#74)
* overflow menu element * review feedback
1 parent f91b35d commit 449b58d

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-chat-renderer",
3-
"version": "0.6.11",
3+
"version": "0.6.12",
44
"license": "MIT",
55
"scripts": {
66
"postversion": "npm publish",

src/__tests__/__snapshots__/renderer.test.tsx.snap

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,39 @@ Object {
845845
}
846846
`;
847847

848+
exports[`slack jsx renders an overflow menu 1`] = `
849+
Object {
850+
"accessory": Object {
851+
"action_id": "action1",
852+
"options": Array [
853+
Object {
854+
"text": Object {
855+
"emoji": false,
856+
"text": "option 1",
857+
"type": "plain_text",
858+
},
859+
"value": "value1",
860+
},
861+
Object {
862+
"text": Object {
863+
"emoji": false,
864+
"text": "option 2",
865+
"type": "plain_text",
866+
},
867+
"value": "value2",
868+
},
869+
],
870+
"type": "overflow",
871+
},
872+
"text": Object {
873+
"text": "This is a section block with an overflow menu.",
874+
"type": "mrkdwn",
875+
"verbatim": false,
876+
},
877+
"type": "section",
878+
}
879+
`;
880+
848881
exports[`slack jsx renders contextblock children 1`] = `
849882
Object {
850883
"elements": Array [

src/__tests__/renderer.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
InputBlock,
3434
TimePickerElement,
3535
MultiExternalSelectElement,
36+
OverflowMenuElement,
3637
} from '../components';
3738

3839
const fakePromise = async () => Promise.resolve();
@@ -763,4 +764,31 @@ describe('slack jsx', () => {
763764
);
764765
expect(await render(message)).toMatchSnapshot();
765766
});
767+
768+
it('renders an overflow menu', async () => {
769+
const message = (
770+
<SectionBlock
771+
accessory={
772+
<OverflowMenuElement
773+
actionId="action1"
774+
options={[
775+
{
776+
text: <PlainText>option 1</PlainText>,
777+
value: 'value1',
778+
},
779+
{
780+
text: <PlainText>option 2</PlainText>,
781+
value: 'value2',
782+
},
783+
]}
784+
/>
785+
}
786+
>
787+
<MarkdownText>
788+
This is a section block with an overflow menu.
789+
</MarkdownText>
790+
</SectionBlock>
791+
);
792+
expect(await render(message)).toMatchSnapshot();
793+
});
766794
});

src/components/OverflowMenuElement.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { StaticSelect, Overflow } from '@slack/types';
2+
import { FC } from '..';
3+
import { buildInputOptions, InputOption } from './shared/inputOption';
4+
5+
export interface OverflowMenuElementProps {
6+
actionId: string;
7+
options: InputOption[];
8+
}
9+
10+
export const OverflowMenuElement: FC<OverflowMenuElementProps, Overflow> = ({
11+
actionId,
12+
options,
13+
}) => ({
14+
type: 'overflow',
15+
action_id: actionId,
16+
...(options && { options: buildInputOptions(options) }),
17+
});

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export * from './MultiSelectElement';
2020
export * from './ExternalSelect';
2121
export * from './Checkbox';
2222
export * from './RadioButtons';
23+
export * from './OverflowMenuElement';
2324
export { InputOption } from './shared/inputOption';
2425

2526
export * from './PlainText';

0 commit comments

Comments
 (0)