Skip to content

Commit e1d0ea5

Browse files
authored
Update readme.md
1 parent 5e6dfca commit e1d0ea5

1 file changed

Lines changed: 111 additions & 11 deletions

File tree

readme.md

Lines changed: 111 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,118 @@
1-
# Slack Blocks to JSX
1+
# Slack Blocks to JSX Documentation
22

3-
Playground - https://slack-block-to-jsx-playground.vercel.app/
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.
45

5-
### How to use
6+
**🚨 Quickly test out the libray on online playground**: https://slack-block-to-jsx-playground.vercel.app/
67

7-
1. Install the Library
8-
2. Import the CSS file in your entry point file `import "slack-blocks-to-jsx/dist/style.css"`
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:
1110

12-
`import type { Block } from "slack-blocks-to-jsx"`
11+
```bash
12+
npm install slack-blocks-to-jsx
13+
```
1314

14-
`const blocks: Block[] = [...your slack blocks]`
15+
Or using yarn:
1516

16-
`<Message time={new Date()} name="Your Company" logo="https://commons.wikimedia.org/wiki/File:Google_%22G%22_logo.svg" blocks={blocks} />`
17+
```bash
18+
yarn add slack-blocks-to-jsx
19+
```
1720

18-
Note: This library is under development, if you need any functionality and it is not working/available yet in the library please raise an issue [here](https://github.com/themashcodee/slack-blocks-to-jsx/issues). I will try to fix it asap :).
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+
[![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/themashcodee)

0 commit comments

Comments
 (0)