Skip to content

Commit

Permalink
feat: Add missing variants to UIKit button (#29654)
Browse files Browse the repository at this point in the history
Co-authored-by: Tiago Evangelista Pinto <17487063+tiagoevanp@users.noreply.github.com>
  • Loading branch information
csuadev and tiagoevanp authored Jul 12, 2023
1 parent bd231a0 commit 1246a21
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/cuddly-ties-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/fuselage-ui-kit": minor
"@rocket.chat/uikit-playground": minor
---

feat: Add missing variants to UIKit button
37 changes: 20 additions & 17 deletions packages/fuselage-ui-kit/src/elements/ButtonElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,50 @@ const ButtonElement = ({
surfaceRenderer,
}: ButtonElementProps): ReactElement => {
const [{ loading }, action] = useUiKitState(block, context);
const { style, url, text, value, secondary } = block;

if (block.url) {
if (url) {
return (
<Button
is='a'
target='_blank'
href={block.url}
disabled={loading}
primary={block.style === 'primary'}
danger={block.style === 'danger'}
minWidth='4ch'
small
minWidth='4ch'
disabled={loading}
href={url}
primary={style === 'primary'}
danger={style === 'danger'}
success={style === 'success'}
warning={style === 'warning'}
secondary={secondary}
onClick={action}
>
{loading ? (
<Throbber />
) : (
surfaceRenderer.renderTextObject(
block.text,
0,
UiKit.BlockContext.NONE
)
surfaceRenderer.renderTextObject(text, 0, UiKit.BlockContext.NONE)
)}
</Button>
);
}

return (
<Button
disabled={loading}
primary={block.style === 'primary'}
danger={block.style === 'danger'}
minWidth='4ch'
small
value={block.value}
minWidth='4ch'
disabled={loading}
primary={style === 'primary'}
danger={style === 'danger'}
success={style === 'success'}
warning={style === 'warning'}
secondary={secondary}
value={value}
onClick={action}
>
{loading ? (
<Throbber />
) : (
surfaceRenderer.renderTextObject(block.text, 0, UiKit.BlockContext.NONE)
surfaceRenderer.renderTextObject(text, 0, UiKit.BlockContext.NONE)
)}
</Button>
);
Expand Down
35 changes: 35 additions & 0 deletions packages/uikit-playground/src/Payload/BlocksTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import type { Item } from '../Components/DropDown/types';
import {
actionWithButtonDefault,
actionWithButtonPrimary,
actionWithButtonSecondary,
actionWithButtonDanger,
actionWithButtonAsLink,
actionWithButtonWarning,
actionWithButtonSuccess,
actionWithButtonSecondaryWithVariant,
actionWithMenu,
// actionWithImage,
// actionWithSingleLineInput,
Expand Down Expand Up @@ -42,6 +46,9 @@ import {
sectionWithButtonDefault,
sectionWithButtonPrimary,
sectionWithButtonDanger,
sectionWithButtonWarning,
sectionWithButtonSuccess,
sectionWithButtonSecondaryWithVariant,
sectionWithButtonAsLink,
sectionWithImage,
sectionWithMenu,
Expand All @@ -63,10 +70,26 @@ const BlocksTree: Item = [
label: 'primary',
payload: actionWithButtonPrimary,
},
{
label: 'secondary',
payload: actionWithButtonSecondary,
},
{
label: 'danger',
payload: actionWithButtonDanger,
},
{
label: 'warning',
payload: actionWithButtonWarning,
},
{
label: 'success',
payload: actionWithButtonSuccess,
},
{
label: 'secondary with variant',
payload: actionWithButtonSecondaryWithVariant,
},
{
label: 'as Link',
payload: actionWithButtonAsLink,
Expand Down Expand Up @@ -136,6 +159,18 @@ const BlocksTree: Item = [
label: 'danger',
payload: sectionWithButtonDanger,
},
{
label: 'warning',
payload: sectionWithButtonWarning,
},
{
label: 'success',
payload: sectionWithButtonSuccess,
},
{
label: 'secondary with variant',
payload: sectionWithButtonSecondaryWithVariant,
},
{
label: 'as Link',
payload: sectionWithButtonAsLink,
Expand Down
81 changes: 81 additions & 0 deletions packages/uikit-playground/src/Payload/action/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ export const actionWithButtonPrimary: readonly LayoutBlock[] = [
},
];

export const actionWithButtonSecondary: readonly LayoutBlock[] = [
{
type: 'actions',
elements: [
{
type: 'button',
appId: 'app-id',
blockId: 'block-id',
actionId: 'action-id',
text: {
type: 'plain_text',
text: 'Click Me',
emoji: true,
},
secondary: true,
},
],
},
];

export const actionWithButtonDanger: readonly LayoutBlock[] = [
{
type: 'actions',
Expand All @@ -59,6 +79,67 @@ export const actionWithButtonDanger: readonly LayoutBlock[] = [
},
];

export const actionWithButtonSuccess: readonly LayoutBlock[] = [
{
type: 'actions',
elements: [
{
type: 'button',
appId: 'app-id',
blockId: 'block-id',
actionId: 'action-id',
text: {
type: 'plain_text',
text: 'Click Me',
emoji: true,
},
style: 'success',
},
],
},
];

export const actionWithButtonWarning: readonly LayoutBlock[] = [
{
type: 'actions',
elements: [
{
type: 'button',
appId: 'app-id',
blockId: 'block-id',
actionId: 'action-id',
text: {
type: 'plain_text',
text: 'Click Me',
emoji: true,
},
style: 'warning',
},
],
},
];

export const actionWithButtonSecondaryWithVariant: readonly LayoutBlock[] = [
{
type: 'actions',
elements: [
{
type: 'button',
appId: 'app-id',
blockId: 'block-id',
actionId: 'action-id',
text: {
type: 'plain_text',
text: 'Click Me',
emoji: true,
},
style: 'danger',
secondary: true,
},
],
},
];

export const actionWithButtonAsLink: readonly LayoutBlock[] = [
{
type: 'actions',
Expand Down
67 changes: 67 additions & 0 deletions packages/uikit-playground/src/Payload/section/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,73 @@ export const sectionWithButtonDanger: readonly LayoutBlock[] = [
},
];

export const sectionWithButtonSuccess: readonly LayoutBlock[] = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'This is a section block with a button.',
},
accessory: {
type: 'button',
appId: 'app-id',
blockId: 'block-id',
actionId: 'action-id',
text: {
type: 'plain_text',
text: 'Click Me',
emoji: true,
},
style: 'success',
},
},
];

export const sectionWithButtonWarning: readonly LayoutBlock[] = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'This is a section block with a button.',
},
accessory: {
type: 'button',
appId: 'app-id',
blockId: 'block-id',
actionId: 'action-id',
text: {
type: 'plain_text',
text: 'Click Me',
emoji: true,
},
style: 'warning',
},
},
];

export const sectionWithButtonSecondaryWithVariant: readonly LayoutBlock[] = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'This is a section block with a button.',
},
accessory: {
type: 'button',
appId: 'app-id',
blockId: 'block-id',
actionId: 'action-id',
text: {
type: 'plain_text',
text: 'Click Me',
emoji: true,
},
style: 'danger',
secondary: true,
},
},
];

export const sectionWithButtonAsLink: readonly LayoutBlock[] = [
{
type: 'section',
Expand Down

0 comments on commit 1246a21

Please sign in to comment.