README
<vc-messages>
This Web Component follows the open-wc recommendation and is meant to be used with the Vonage Client SDK In-App Messaging.
A goal is to simplify the code needed to create a chat room quickly. Please see the Creating a chat app tutorial to see an implementation using Vanilla JavaScript.
This Web Component can be used to replace a part of the Chat app UI.
Installation
npm i @vonage/vc-messages
Usage
<script type="module">
import '@vonage/vc-messages/vc-messages.js';
</script>
<vc-messages></vc-messages>
The vc-messages
Web Component can handle all its responsibilities in a Conversation.
First, get a reference to the element:
const vcMessages = document.querySelector("vc-messages");
Then, pass the Conversation object to the Web Component:
vcMessages.conversation = conversation;
Note: To see where
conversation
came from, see step 10 in the tutorial.
Styling
The vc-messages
component uses CSS part to apply custom styles.
Here are two diagram that labels the parts of the component as well as the default style:
To style the overall message, the part is "message". To style the application user's message, the part to target is "message mine".
Each message is made up of the text (part is "message-text"), and their name (part is "username"). To specifically style the application user's message text, target "message-text mine" and for their name, the target would be "username mine".
Example:
vc-messages {
background-color: red;
height: 300px;
}
vc-messages::part(message) {
background-color: green;
border-radius: 20px 20px 20px 0;
}
vc-messages::part(message mine) {
text-align: left;
background-color: royalblue;
border-radius: 20px 20px 0 20px;
border: 0;
}
vc-messages::part(message-text) {
background-color: yellow;
border-radius: 20px 20px 20px 0;
}
vc-messages::part(message-text mine) {
background-color: purple;
color: white;
font-style: italic;
border-radius: 20px 20px 0 20px;
}
vc-messages::part(username) {
color: white;
}
vc-messages::part(username mine) {
text-align: right;
font-style: italic;
color: black;
}
Linting with ESLint, Prettier, and Types
To scan the project for linting errors, run
npm run lint
You can lint with ESLint and Prettier individually as well
npm run lint:eslint
npm run lint:prettier
To automatically fix many linting errors, run
npm run format
You can format using ESLint and Prettier individually as well
npm run format:eslint
npm run format:prettier
Testing with Web Test Runner
To run the suite of Web Test Runner tests, run
npm run test
To run the tests in watch mode (for <abbr title="test driven development">TDD</abbr>, for example), run
npm run test:watch
Demoing with Storybook
To run a local instance of Storybook for your component, run
npm run storybook
To build a production version of Storybook, run
npm run storybook:build
Tooling configs
For most of the tools, the configuration is in the package.json
to reduce the amount of files in your project.
If you customize the configuration a lot, you can consider moving them to individual files.
web-dev-server
Local Demo with npm start
To run a local development server that serves the basic demo located in demo/index.html