Skip to content

Commit

Permalink
feat(ui-kit): Add new UIKit components (#1074)
Browse files Browse the repository at this point in the history
- Callout
- Checkbox
- Radio Button
- Time Picker
- Toggle Switch
- Tab Navigation
  • Loading branch information
csuadev authored Jul 7, 2023
1 parent 00d08d1 commit 84fb125
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 10 deletions.
10 changes: 10 additions & 0 deletions packages/ui-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@

<!--install-->

Firstly, install the peer dependencies (prerequisites):

```sh
npm i @rocket.chat/icons

# or, if you are using yarn:

yarn add @rocket.chat/icons
```

Add `@rocket.chat/ui-kit` as a dependency:

```sh
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@babel/preset-env": "~7.21.4",
"@rocket.chat/eslint-config-alt": "workspace:~",
"@rocket.chat/prettier-config": "workspace:~",
"@rocket.chat/icons": "workspace:~",
"@types/jest": "~29.5.0",
"babel-loader": "~9.1.2",
"bump": "workspace:~",
Expand All @@ -59,5 +60,8 @@
"typescript": "~5.0.4",
"webpack": "~5.78.0",
"webpack-cli": "~5.0.1"
},
"peerDependencies": {
"@rocket.chat/icons": "*"
}
}
10 changes: 9 additions & 1 deletion packages/ui-kit/src/blocks/ActionableElement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ButtonElement } from './elements/ButtonElement';
import type { ChannelsSelectElement } from './elements/ChannelsSelectElement';
import type { CheckboxElement } from './elements/CheckboxElement';
import type { ConversationsSelectElement } from './elements/ConversationsSelectElement';
import type { DatePickerElement } from './elements/DatePickerElement';
import type { LinearScaleElement } from './elements/LinearScaleElement';
Expand All @@ -9,7 +10,10 @@ import type { MultiStaticSelectElement } from './elements/MultiStaticSelectEleme
import type { MultiUsersSelectElement } from './elements/MultiUsersSelectElement';
import type { OverflowElement } from './elements/OverflowElement';
import type { PlainTextInputElement } from './elements/PlainTextInputElement';
import type { RadioButtonElement } from './elements/RadioButtonElement';
import type { StaticSelectElement } from './elements/StaticSelectElement';
import type { TimePickerElement } from './elements/TimePickerElement';
import type { ToggleSwitchElement } from './elements/ToggleSwitchElement';
import type { UsersSelectElement } from './elements/UsersSelectElement';

export type ActionableElement =
Expand All @@ -25,4 +29,8 @@ export type ActionableElement =
| OverflowElement
| PlainTextInputElement
| StaticSelectElement
| UsersSelectElement;
| UsersSelectElement
| ToggleSwitchElement
| RadioButtonElement
| CheckboxElement
| TimePickerElement;
10 changes: 9 additions & 1 deletion packages/ui-kit/src/blocks/BlockElement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ButtonElement } from './elements/ButtonElement';
import type { ChannelsSelectElement } from './elements/ChannelsSelectElement';
import type { CheckboxElement } from './elements/CheckboxElement';
import type { ConversationsSelectElement } from './elements/ConversationsSelectElement';
import type { DatePickerElement } from './elements/DatePickerElement';
import type { ImageElement } from './elements/ImageElement';
Expand All @@ -10,7 +11,10 @@ import type { MultiStaticSelectElement } from './elements/MultiStaticSelectEleme
import type { MultiUsersSelectElement } from './elements/MultiUsersSelectElement';
import type { OverflowElement } from './elements/OverflowElement';
import type { PlainTextInputElement } from './elements/PlainTextInputElement';
import type { RadioButtonElement } from './elements/RadioButtonElement';
import type { StaticSelectElement } from './elements/StaticSelectElement';
import type { TimePickerElement } from './elements/TimePickerElement';
import type { ToggleSwitchElement } from './elements/ToggleSwitchElement';
import type { UsersSelectElement } from './elements/UsersSelectElement';

export type BlockElement =
Expand All @@ -27,4 +31,8 @@ export type BlockElement =
| OverflowElement
| PlainTextInputElement
| StaticSelectElement
| UsersSelectElement;
| UsersSelectElement
| ToggleSwitchElement
| RadioButtonElement
| CheckboxElement
| TimePickerElement;
4 changes: 4 additions & 0 deletions packages/ui-kit/src/blocks/BlockElementType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export enum BlockElementType {
MULTI_CHANNELS_SELECT = 'multi_channels_select',
MULTI_CONVERSATIONS_SELECT = 'multi_conversations_select',
MULTI_USERS_SELECT = 'multi_users_select',
TOGGLE_SWITCH = 'toggle_switch',
RADIO_BUTTON = 'radio_button',
CHECKBOX = 'checkbox',
TIME_PICKER = 'time_picker',
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-kit/src/blocks/LayoutBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ActionsBlock } from './layout/ActionsBlock';
import type { CalloutBlock } from './layout/CalloutBlock';
import type { ConditionalBlock } from './layout/ConditionalBlock';
import type { ContextBlock } from './layout/ContextBlock';
import type { DividerBlock } from './layout/DividerBlock';
Expand All @@ -20,4 +21,5 @@ export type LayoutBlock =
| SectionBlock
| VideoConferenceBlock
| PreviewBlock
| CalloutBlock
| TabNavigationBlock;
3 changes: 2 additions & 1 deletion packages/ui-kit/src/blocks/LayoutBlockType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export enum LayoutBlockType {
INPUT = 'input',
CONDITIONAL = 'conditional',
PREVIEW = 'preview',
TAB_NAVIGATION = 'tab_navigation',
VIDEO_CONF = 'video_conf',
CALLOUT = 'callout',
TAB_NAVIGATION = 'tab_navigation',
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
8 changes: 8 additions & 0 deletions packages/ui-kit/src/blocks/elements/CheckboxElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Actionable } from '../Actionable';
import type { Option } from '../Option';

export type CheckboxElement = Actionable<{
type: 'checkbox';
options: Option[];
initialOptions?: Option[];
}>;
8 changes: 8 additions & 0 deletions packages/ui-kit/src/blocks/elements/RadioButtonElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Actionable } from '../Actionable';
import type { Option } from '../Option';

export type RadioButtonElement = Actionable<{
type: 'radio_button';
options: Option[];
initialOption?: Option;
}>;
8 changes: 8 additions & 0 deletions packages/ui-kit/src/blocks/elements/TimePickerElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Actionable } from '../Actionable';
import type { TextObject } from '../TextObject';

export type TimePickerElement = Actionable<{
type: 'time_picker';
placeholder?: TextObject;
initialTime?: number;
}>;
8 changes: 8 additions & 0 deletions packages/ui-kit/src/blocks/elements/ToggleSwitchElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Actionable } from '../Actionable';
import type { Option } from '../Option';

export type ToggleSwitchElement = Actionable<{
type: 'toggle_switch';
options: Option[];
initialOptions?: Option[];
}>;
4 changes: 4 additions & 0 deletions packages/ui-kit/src/blocks/isActionsBlockElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export const isActionsBlockElement = (
case BlockElementType.MULTI_STATIC_SELECT:
case BlockElementType.OVERFLOW:
case BlockElementType.STATIC_SELECT:
case BlockElementType.TOGGLE_SWITCH:
case BlockElementType.CHECKBOX:
case BlockElementType.RADIO_BUTTON:
case BlockElementType.TIME_PICKER:
return true;

default:
Expand Down
8 changes: 8 additions & 0 deletions packages/ui-kit/src/blocks/layout/ActionsBlock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { LayoutBlockish } from '../LayoutBlockish';
import type { ButtonElement } from '../elements/ButtonElement';
import type { ChannelsSelectElement } from '../elements/ChannelsSelectElement';
import type { CheckboxElement } from '../elements/CheckboxElement';
import type { ConversationsSelectElement } from '../elements/ConversationsSelectElement';
import type { DatePickerElement } from '../elements/DatePickerElement';
import type { LinearScaleElement } from '../elements/LinearScaleElement';
Expand All @@ -9,7 +10,10 @@ import type { MultiConversationsSelectElement } from '../elements/MultiConversat
import type { MultiStaticSelectElement } from '../elements/MultiStaticSelectElement';
import type { MultiUsersSelectElement } from '../elements/MultiUsersSelectElement';
import type { OverflowElement } from '../elements/OverflowElement';
import type { RadioButtonElement } from '../elements/RadioButtonElement';
import type { StaticSelectElement } from '../elements/StaticSelectElement';
import type { TimePickerElement } from '../elements/TimePickerElement';
import type { ToggleSwitchElement } from '../elements/ToggleSwitchElement';
import type { UsersSelectElement } from '../elements/UsersSelectElement';

export type ActionsBlock = LayoutBlockish<{
Expand All @@ -27,5 +31,9 @@ export type ActionsBlock = LayoutBlockish<{
| OverflowElement
| StaticSelectElement
| UsersSelectElement
| ToggleSwitchElement
| CheckboxElement
| RadioButtonElement
| TimePickerElement
)[];
}>;
12 changes: 12 additions & 0 deletions packages/ui-kit/src/blocks/layout/CalloutBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Keys } from '@rocket.chat/icons';

import type { LayoutBlockish } from '../LayoutBlockish';
import type { TextObject } from '../TextObject';

export type CalloutBlock = LayoutBlockish<{
type: 'callout';
title?: TextObject;
icon?: Keys;
text: TextObject;
variant?: 'info' | 'danger' | 'warning' | 'success';
}>;
10 changes: 9 additions & 1 deletion packages/ui-kit/src/blocks/layout/InputBlock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LayoutBlockish } from '../LayoutBlockish';
import type { ChannelsSelectElement } from '../elements/ChannelsSelectElement';
import type { CheckboxElement } from '../elements/CheckboxElement';
import type { ConversationsSelectElement } from '../elements/ConversationsSelectElement';
import type { DatePickerElement } from '../elements/DatePickerElement';
import type { LinearScaleElement } from '../elements/LinearScaleElement';
Expand All @@ -8,7 +9,10 @@ import type { MultiConversationsSelectElement } from '../elements/MultiConversat
import type { MultiStaticSelectElement } from '../elements/MultiStaticSelectElement';
import type { MultiUsersSelectElement } from '../elements/MultiUsersSelectElement';
import type { PlainTextInputElement } from '../elements/PlainTextInputElement';
import type { RadioButtonElement } from '../elements/RadioButtonElement';
import type { StaticSelectElement } from '../elements/StaticSelectElement';
import type { TimePickerElement } from '../elements/TimePickerElement';
import type { ToggleSwitchElement } from '../elements/ToggleSwitchElement';
import type { UsersSelectElement } from '../elements/UsersSelectElement';
import type { PlainText } from '../text/PlainText';

Expand All @@ -26,7 +30,11 @@ export type InputBlock = LayoutBlockish<{
| MultiUsersSelectElement
| PlainTextInputElement
| StaticSelectElement
| UsersSelectElement;
| UsersSelectElement
| CheckboxElement
| RadioButtonElement
| TimePickerElement
| ToggleSwitchElement;
hint?: PlainText;
optional?: boolean;
}>;
5 changes: 5 additions & 0 deletions packages/ui-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export { OverflowElement } from './blocks/elements/OverflowElement';
export { PlainTextInputElement } from './blocks/elements/PlainTextInputElement';
export { StaticSelectElement } from './blocks/elements/StaticSelectElement';
export { UsersSelectElement } from './blocks/elements/UsersSelectElement';
export { ToggleSwitchElement } from './blocks/elements/ToggleSwitchElement';
export { CheckboxElement } from './blocks/elements/CheckboxElement';
export { RadioButtonElement } from './blocks/elements/RadioButtonElement';
export { TimePickerElement } from './blocks/elements/TimePickerElement';
export { BlockElement } from './blocks/BlockElement';

export { ActionsBlock } from './blocks/layout/ActionsBlock';
Expand All @@ -34,6 +38,7 @@ export { InputBlock } from './blocks/layout/InputBlock';
export { SectionBlock } from './blocks/layout/SectionBlock';
export { VideoConferenceBlock } from './blocks/layout/VideoConferenceBlock';
export { LayoutBlock } from './blocks/LayoutBlock';
export { CalloutBlock } from './blocks/layout/CalloutBlock';
export { TabNavigationBlock } from './blocks/layout/TabNavigationBlock';

export { InputElementDispatchAction } from './blocks/InputElementDispatchAction';
Expand Down
13 changes: 13 additions & 0 deletions packages/ui-kit/src/rendering/ActionOf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ActionableElement } from '../blocks/ActionableElement';
import type { Option } from '../blocks/Option';
import type { ButtonElement } from '../blocks/elements/ButtonElement';
import type { ChannelsSelectElement } from '../blocks/elements/ChannelsSelectElement';
import type { CheckboxElement } from '../blocks/elements/CheckboxElement';
import type { ConversationsSelectElement } from '../blocks/elements/ConversationsSelectElement';
import type { DatePickerElement } from '../blocks/elements/DatePickerElement';
import type { LinearScaleElement } from '../blocks/elements/LinearScaleElement';
Expand All @@ -10,7 +12,10 @@ import type { MultiStaticSelectElement } from '../blocks/elements/MultiStaticSel
import type { MultiUsersSelectElement } from '../blocks/elements/MultiUsersSelectElement';
import type { OverflowElement } from '../blocks/elements/OverflowElement';
import type { PlainTextInputElement } from '../blocks/elements/PlainTextInputElement';
import type { RadioButtonElement } from '../blocks/elements/RadioButtonElement';
import type { StaticSelectElement } from '../blocks/elements/StaticSelectElement';
import type { TimePickerElement } from '../blocks/elements/TimePickerElement';
import type { ToggleSwitchElement } from '../blocks/elements/ToggleSwitchElement';
import type { UsersSelectElement } from '../blocks/elements/UsersSelectElement';

export type ActionOf<TElement extends ActionableElement> =
Expand Down Expand Up @@ -40,4 +45,12 @@ export type ActionOf<TElement extends ActionableElement> =
? StaticSelectElement['initialValue']
: TElement extends UsersSelectElement
? unknown
: TElement extends ToggleSwitchElement
? Option['value'][]
: TElement extends RadioButtonElement
? Option['value'] | undefined
: TElement extends CheckboxElement
? Option['value'][] | undefined
: TElement extends TimePickerElement
? TimePickerElement['initialTime']
: never;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ActionsBlock } from '../../blocks/layout/ActionsBlock';
import type { CalloutBlock } from '../../blocks/layout/CalloutBlock';
import type { ContextBlock } from '../../blocks/layout/ContextBlock';
import type { DividerBlock } from '../../blocks/layout/DividerBlock';
import type { ImageBlock } from '../../blocks/layout/ImageBlock';
Expand All @@ -10,14 +11,15 @@ type AttachmentSurfaceLayoutBlock =
| ContextBlock
| DividerBlock
| ImageBlock
| SectionBlock;
| SectionBlock
| CalloutBlock;

export abstract class UiKitParserAttachment<T> extends SurfaceRenderer<
T,
AttachmentSurfaceLayoutBlock
> {
public constructor() {
super(['actions', 'context', 'divider', 'image', 'section']);
super(['actions', 'context', 'divider', 'image', 'section', 'callout']);
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/ui-kit/src/rendering/surfaces/UiKitParserBanner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ActionsBlock } from '../../blocks/layout/ActionsBlock';
import type { CalloutBlock } from '../../blocks/layout/CalloutBlock';
import type { ContextBlock } from '../../blocks/layout/ContextBlock';
import type { DividerBlock } from '../../blocks/layout/DividerBlock';
import type { ImageBlock } from '../../blocks/layout/ImageBlock';
Expand All @@ -12,7 +13,8 @@ type BannerSurfaceLayoutBlock =
| DividerBlock
| ImageBlock
| InputBlock
| SectionBlock;
| SectionBlock
| CalloutBlock;

export abstract class UiKitParserBanner<T> extends SurfaceRenderer<
T,
Expand Down
5 changes: 4 additions & 1 deletion packages/ui-kit/src/rendering/surfaces/UiKitParserMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ActionsBlock } from '../../blocks/layout/ActionsBlock';
import type { CalloutBlock } from '../../blocks/layout/CalloutBlock';
import type { ContextBlock } from '../../blocks/layout/ContextBlock';
import type { DividerBlock } from '../../blocks/layout/DividerBlock';
import type { ImageBlock } from '../../blocks/layout/ImageBlock';
Expand All @@ -14,7 +15,8 @@ type MessageSurfaceLayoutBlock =
| ImageBlock
| SectionBlock
| VideoConferenceBlock
| PreviewBlock;
| PreviewBlock
| CalloutBlock;

export abstract class UiKitParserMessage<OutputElement> extends SurfaceRenderer<
OutputElement,
Expand All @@ -29,6 +31,7 @@ export abstract class UiKitParserMessage<OutputElement> extends SurfaceRenderer<
'section',
'preview',
'video_conf',
'callout',
]);
}
}
Expand Down
14 changes: 12 additions & 2 deletions packages/ui-kit/src/rendering/surfaces/UiKitParserModal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ActionsBlock } from '../../blocks/layout/ActionsBlock';
import type { CalloutBlock } from '../../blocks/layout/CalloutBlock';
import type { ContextBlock } from '../../blocks/layout/ContextBlock';
import type { DividerBlock } from '../../blocks/layout/DividerBlock';
import type { ImageBlock } from '../../blocks/layout/ImageBlock';
Expand All @@ -12,14 +13,23 @@ type ModalSurfaceLayoutBlock =
| DividerBlock
| ImageBlock
| InputBlock
| SectionBlock;
| SectionBlock
| CalloutBlock;

export abstract class UiKitParserModal<OutputElement> extends SurfaceRenderer<
OutputElement,
ModalSurfaceLayoutBlock
> {
public constructor() {
super(['actions', 'context', 'divider', 'image', 'input', 'section']);
super([
'actions',
'context',
'divider',
'image',
'input',
'section',
'callout',
]);
}
}

Expand Down

0 comments on commit 84fb125

Please sign in to comment.