Skip to content
Snippets Groups Projects
Unverified Commit 1246a216 authored by csuadev's avatar csuadev Committed by GitHub
Browse files

feat: Add missing variants to UIKit button (#29654)

parent bd231a06
No related branches found
No related tags found
No related merge requests found
---
"@rocket.chat/fuselage-ui-kit": minor
"@rocket.chat/uikit-playground": minor
---
feat: Add missing variants to UIKit button
......@@ -13,28 +13,28 @@ 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>
);
......@@ -42,18 +42,21 @@ const ButtonElement = ({
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>
);
......
......@@ -2,8 +2,12 @@ import type { Item } from '../Components/DropDown/types';
import {
actionWithButtonDefault,
actionWithButtonPrimary,
actionWithButtonSecondary,
actionWithButtonDanger,
actionWithButtonAsLink,
actionWithButtonWarning,
actionWithButtonSuccess,
actionWithButtonSecondaryWithVariant,
actionWithMenu,
// actionWithImage,
// actionWithSingleLineInput,
......@@ -42,6 +46,9 @@ import {
sectionWithButtonDefault,
sectionWithButtonPrimary,
sectionWithButtonDanger,
sectionWithButtonWarning,
sectionWithButtonSuccess,
sectionWithButtonSecondaryWithVariant,
sectionWithButtonAsLink,
sectionWithImage,
sectionWithMenu,
......@@ -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,
......@@ -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,
......
......@@ -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',
......@@ -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',
......
......@@ -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',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment