slack-blocks-to-jsx 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
- package/readme.md +111 -11
package/dist/index.js
CHANGED
|
@@ -1178,19 +1178,19 @@ var Message = (props) => {
|
|
|
1178
1178
|
style,
|
|
1179
1179
|
showBlockKitDebug = false,
|
|
1180
1180
|
unstyled = false,
|
|
1181
|
-
data
|
|
1182
|
-
hooks
|
|
1181
|
+
data,
|
|
1182
|
+
hooks,
|
|
1183
1183
|
withoutWrapper = false
|
|
1184
1184
|
} = props;
|
|
1185
1185
|
const { setChannels, setUsers, setHooks } = useGlobalData();
|
|
1186
1186
|
(0, import_react6.useEffect)(() => {
|
|
1187
|
-
if (data.users)
|
|
1187
|
+
if (data == null ? void 0 : data.users)
|
|
1188
1188
|
setUsers(data.users);
|
|
1189
|
-
if (data.channels)
|
|
1189
|
+
if (data == null ? void 0 : data.channels)
|
|
1190
1190
|
setChannels(data.channels);
|
|
1191
1191
|
if (hooks)
|
|
1192
1192
|
setHooks(hooks);
|
|
1193
|
-
}, [data]);
|
|
1193
|
+
}, [data, hooks]);
|
|
1194
1194
|
if (withoutWrapper) {
|
|
1195
1195
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
1196
1196
|
"div",
|
package/dist/index.mjs
CHANGED
|
@@ -1145,19 +1145,19 @@ var Message = (props) => {
|
|
|
1145
1145
|
style,
|
|
1146
1146
|
showBlockKitDebug = false,
|
|
1147
1147
|
unstyled = false,
|
|
1148
|
-
data
|
|
1149
|
-
hooks
|
|
1148
|
+
data,
|
|
1149
|
+
hooks,
|
|
1150
1150
|
withoutWrapper = false
|
|
1151
1151
|
} = props;
|
|
1152
1152
|
const { setChannels, setUsers, setHooks } = useGlobalData();
|
|
1153
1153
|
useEffect5(() => {
|
|
1154
|
-
if (data.users)
|
|
1154
|
+
if (data == null ? void 0 : data.users)
|
|
1155
1155
|
setUsers(data.users);
|
|
1156
|
-
if (data.channels)
|
|
1156
|
+
if (data == null ? void 0 : data.channels)
|
|
1157
1157
|
setChannels(data.channels);
|
|
1158
1158
|
if (hooks)
|
|
1159
1159
|
setHooks(hooks);
|
|
1160
|
-
}, [data]);
|
|
1160
|
+
}, [data, hooks]);
|
|
1161
1161
|
if (withoutWrapper) {
|
|
1162
1162
|
return /* @__PURE__ */ jsx24(
|
|
1163
1163
|
"div",
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,18 +1,118 @@
|
|
|
1
|
-
# Slack Blocks to JSX
|
|
1
|
+
# Slack Blocks to JSX Documentation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Overview
|
|
4
|
+
The `slack-blocks-to-jsx` package allows you to render Slack blocks in React with styles that closely mimic how they are displayed in Slack. This library converts Slack's block kit components into JSX components, maintaining the visual fidelity and interactive elements.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
**🚨 Quickly test out the libray on online playground**: https://slack-block-to-jsx-playground.vercel.app/
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Import the component and use it `import { Message } from "slack-blocks-to-jsx"`
|
|
10
|
-
4. (optional) import the Block type to define the blocks for better type safety :)
|
|
8
|
+
## Installation
|
|
9
|
+
To use this package in your project, install it via npm:
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
```bash
|
|
12
|
+
npm install slack-blocks-to-jsx
|
|
13
|
+
```
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
Or using yarn:
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
```bash
|
|
18
|
+
yarn add slack-blocks-to-jsx
|
|
19
|
+
```
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Importing Styles
|
|
24
|
+
Import the necessary CSS file in your entry point to ensure the styles are applied:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import "slack-blocks-to-jsx/dist/style.css";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Using Components
|
|
31
|
+
Import the `Message` component from the package and use it to render your Slack blocks:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import { Message } from "slack-blocks-to-jsx";
|
|
35
|
+
|
|
36
|
+
const blocks = [...]; // your Slack blocks data
|
|
37
|
+
|
|
38
|
+
<Message time={new Date()} name="Your Company" logo="logo_url" blocks={blocks} />
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Types
|
|
42
|
+
For better type safety, you can import the `Block` type:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import type { Block } from "slack-blocks-to-jsx";
|
|
46
|
+
|
|
47
|
+
const blocks: Block[] = [...]; // your Slack blocks data
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Components
|
|
51
|
+
|
|
52
|
+
### `Message`
|
|
53
|
+
This is the main component that renders the entire Slack message. It supports various props to customize the appearance and behavior:
|
|
54
|
+
|
|
55
|
+
- `blocks`: Array of Slack block objects.
|
|
56
|
+
- `logo`: URL of the logo to display.
|
|
57
|
+
- `name`: Name of the sender.
|
|
58
|
+
- `time?`: Timestamp for the message.
|
|
59
|
+
- `className?`, `style?`: Standard React styling props.
|
|
60
|
+
- `unstyled?`: If true, disables all included styles. Default to false.
|
|
61
|
+
- `withoutWrapper?`: If true, renders only the Slack blocks without any wrapper. Default to false.
|
|
62
|
+
- `hooks?`: custom handlers for user, channel, broadcast, usergroup, emoji etc.
|
|
63
|
+
- `data?`: optionally pass an array or users, channels and user groups to automatically be replaced with the user, channel and user group mentions.
|
|
64
|
+
- `showBlockKitDebug?`: Show a link to open the message in the Slack Block Kit Builder, for debugging purposes. Defaults to false.
|
|
65
|
+
|
|
66
|
+
### Block Components
|
|
67
|
+
Each Slack block type has a corresponding component:
|
|
68
|
+
|
|
69
|
+
- `Section` (✅ supported)
|
|
70
|
+
- `Divider` (✅ supported)
|
|
71
|
+
- `Image` (✅ supported)
|
|
72
|
+
- `Context` (✅ supported)
|
|
73
|
+
- `Actions` (🟨 partially supported)
|
|
74
|
+
- `File` (❌ not supported yet)
|
|
75
|
+
- `Header` (❌ not supported yet)
|
|
76
|
+
- `Input` (🟨 partially supported)
|
|
77
|
+
- `RichText` (✅ supported)
|
|
78
|
+
- `Video` (❌ not supported yet)
|
|
79
|
+
|
|
80
|
+
If you want a support of a particular block or element which is not supported yet so please raise a github issue or mail me at codeemash@gmail.com. I will try to push it asap.
|
|
81
|
+
|
|
82
|
+
## Customization
|
|
83
|
+
You can handle custom rendering and interactions using the `hooks` prop in the `Message` component. This allows you to define custom behavior for user mentions, channels, and other interactive elements. You can also override default styling. Here are the classes structure to understand to override any block styling.
|
|
84
|
+
|
|
85
|
+
`.slack_blocks_to_jsx`: Main Wrapper
|
|
86
|
+
`.slack_blocks_to_jsx--header`: Header (name and time)
|
|
87
|
+
`.slack_blocks_to_jsx--blocks`: blocks array mapping wrapper
|
|
88
|
+
`.slack_blocks_to_jsx--block_wrapper`: wrapper around every block
|
|
89
|
+
`.slack_blocks_to_jsx__divider`: Divider Block
|
|
90
|
+
`.slack_blocks_to_jsx__section`: Section Block
|
|
91
|
+
`.slack_blocks_to_jsx__image`: Image Block
|
|
92
|
+
`.slack_blocks_to_jsx__context`: Context Block
|
|
93
|
+
`.slack_blocks_to_jsx__actions`: Actions Block
|
|
94
|
+
`.slack_blocks_to_jsx__input`: Input Block
|
|
95
|
+
`.slack_blocks_to_jsx__rich_text`: Rich Text Block
|
|
96
|
+
`.slack_blocks_to_jsx__rich_text_list_element`: Rich Text Block List Element
|
|
97
|
+
`.slack_blocks_to_jsx__rich_text_preformatted_element`: Rich Text Block Preformatted Element
|
|
98
|
+
`.slack_blocks_to_jsx__rich_text_quote_element`: Rich Text Block Element Quote Element
|
|
99
|
+
`.slack_blocks_to_jsx__rich_text_section_element`: Rich Text Block Section Element
|
|
100
|
+
|
|
101
|
+
...as so on (all the other classes will be similar too, for example `.slack_blocks_to_jsx__rich_text_section_element_user` for Rich Text Block Section Element User)
|
|
102
|
+
|
|
103
|
+
If you want any other customization so please raise a github issue or mail me at codeemash@gmail.com. I will try to push it asap if it aligns with the library development vision.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Development and Contribution
|
|
107
|
+
The project is open-source, and contributions are welcome. If you encounter any issues or want to suggest improvements, please file an issue on the GitHub repository:
|
|
108
|
+
|
|
109
|
+
[GitHub Repository Issues](https://github.com/themashcodee/slack-blocks-to-jsx/issues)
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
The project is licensed under the MIT license, allowing free use, modification, and distribution.
|
|
113
|
+
|
|
114
|
+
## Support
|
|
115
|
+
|
|
116
|
+
If you like my work, you can buy me a coffee! 😊
|
|
117
|
+
|
|
118
|
+
[](https://www.buymeacoffee.com/themashcodee)
|