Skip to content

Commit

Permalink
feat(ui-kit): added accessory to CalloutBlock (#33528)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Oct 18, 2024
1 parent 81998f3 commit 687f1ef
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-spiders-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

---

Adds `accessory` properties to `CalloutBlock`
6 changes: 5 additions & 1 deletion apps/uikit-playground/src/Payload/actionBlock/BlocksTree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Item } from '../../Components/DropDown/types';
import { callout } from '../callout';
import { callout, calloutWithAction } from '../callout';
import {
actionWithButtonDefault,
actionWithButtonPrimary,
Expand Down Expand Up @@ -324,6 +324,10 @@ const BlocksTree: Item = [
label: 'Plain',
payload: callout,
},
{
label: 'With Action',
payload: calloutWithAction,
},
],
},
{
Expand Down
24 changes: 24 additions & 0 deletions apps/uikit-playground/src/Payload/callout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,27 @@ export const callout: readonly LayoutBlock[] = [
},
},
];

export const calloutWithAction: readonly LayoutBlock[] = [
{
type: 'callout',
title: {
type: 'plain_text',
text: 'Callout Title',
},
text: {
type: 'plain_text',
text: 'Callout Text',
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'Callout Action',
},
actionId: 'callout-action',
blockId: 'callout-action',
appId: 'A',
},
},
];
13 changes: 12 additions & 1 deletion packages/fuselage-ui-kit/src/blocks/CalloutBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ const CalloutBlock = ({
surfaceRenderer,
}: CalloutBlockProps): ReactElement => {
return (
<Callout type={block.variant} title={block.title?.text}>
<Callout
type={block.variant}
title={block.title?.text}
actions={
(block.accessory &&
surfaceRenderer.renderSectionAccessoryBlockElement(
block.accessory,
0
)) ||
undefined
}
>
{surfaceRenderer.renderTextObject(block.text, 0, UiKit.BlockContext.NONE)}
</Callout>
);
Expand Down
4 changes: 4 additions & 0 deletions packages/fuselage-ui-kit/src/stories/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ export const InputWithLinearScale = createStory(payloads.inputWithLinearScale, {
});

export const Conditional = createStory(payloads.conditional);

export const Callout = createStory(payloads.callout);

export const CalloutWithAction = createStory(payloads.calloutWithAction);
41 changes: 41 additions & 0 deletions packages/fuselage-ui-kit/src/stories/payloads/callout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type * as UiKit from '@rocket.chat/ui-kit';

export const callout: readonly UiKit.LayoutBlock[] = [
{
type: 'callout',
title: {
type: 'plain_text',
text: 'Callout',
},
text: {
type: 'plain_text',
text: 'This is a callout',
},
variant: 'info',
},
] as const;

export const calloutWithAction: readonly UiKit.LayoutBlock[] = [
{
type: 'callout',
title: {
type: 'plain_text',
text: 'Callout',
},
text: {
type: 'plain_text',
text: 'This is a callout',
},
variant: 'info',
accessory: {
appId: 'dummy-app-id',
blockId: 'dummy-block-id',
actionId: 'dummy-action-id',
type: 'button',
text: {
type: 'plain_text',
text: 'Action',
},
},
},
];
1 change: 1 addition & 0 deletions packages/fuselage-ui-kit/src/stories/payloads/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './actions';
export * from './conditional';
export * from './callout';
export * from './context';
export * from './divider';
export * from './image';
Expand Down
3 changes: 3 additions & 0 deletions packages/ui-kit/src/blocks/layout/CalloutBlock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { LayoutBlockish } from '../LayoutBlockish';
import type { TextObject } from '../TextObject';
import type { ButtonElement } from '../elements/ButtonElement';
import type { OverflowElement } from '../elements/OverflowElement';

export type CalloutBlock = LayoutBlockish<{
type: 'callout';
title?: TextObject;
text: TextObject;
variant?: 'info' | 'danger' | 'warning' | 'success';
accessory?: ButtonElement | OverflowElement;
}>;

0 comments on commit 687f1ef

Please sign in to comment.