
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
mml-react
Advanced tools
// YARN
yarn add mml-react
// NPM
npm install mml-react --save
import { MML } from 'mml-react';
<MML source="<mml>Text</mml>" />;
Making basic changes to the components is quite easy. You can use this option to add support for more custom tags.
Here's an example of how to overwrite the button tag's React component:
const converters = {
button: (tag, children) => {
return <MyCustomButton {...tag.node.attributes} text={tag.getText()} key={tag.key} />;
},
};
<MML converters={converters} source={source} />;
MML React components could be divided in four categories:
Very basic pieces of UI typically beyond a matter of styling
Always host other components, can be themable
Basic components that can be composed and themed
Text: a block of textButton: a simple buttonImage: a simple responsive imageInput: an input fieldMD: renders markdownIcon: simply displays an icon from material design iconsLoading: signals a loading temporary state with a circular spinnerError: display an error messageSuccess: display a success messageMore complex components composed of other components, certainly themable
AddToCalendar: wrapped in a CardScheduler: wrapped in a CardButtonList: a list of ButtonCarousel: a series of CarouselItem typically containing Image, Text and ButtonNumber: input spinner composed of two Button and a counterMML react ships with some good looking default styles but it can be completely customised to suit your visual identity.
MML ships with a default theme plus four variations. These differentiate from one another only in terms of colours providing different look and feels that suits common scenarios like Social messaging, Customer support, etc. Each theme is either available in the compiled and autoprefixed dist/styles/{name}.css file and in the src/styles/{name}.scss source file. You should always include only one of this files, either css or scss, as they all includes the basic styling your MML components need.
If your projects include a sass compilation step you might tweak the theme variables and roll out your branded style. A theme is made of the following SCSS map:
$mml-theme: (
primary-accent: #006cff,
app-canvas: #fff,
text-high-emphasis: #0e1621,
text-mid-emphasis: #8a898e,
text-low-emphasis: #b2b1b5,
text-self: #fff,
text-pressed: #fff,
card-bg: #f2f2f2,
card-alt-bg: #fff,
card-self-bg: #41affc,
stroke: #e5e5e6,
stroke-low-emphasis: #f2f2f2,
shadow: 0px 2px 5px rgba(0, 0, 0, 0.15),
);
If you are running
sasswithin your project you might customize most aspects of mml styling other than the them through scss variables. Refer to the source to see what is available.
By setting $mml-use-css-vars: true you can make each of these variables available as CSS variable that you can tweak dynamically client side, they are all prefixed with --mml:
:root {
--mml-primary-accent: #006cff;
--mml-app-canvas: #fff;
}
The theme related data is also made available to javascript through icss :export so that you can import them and reuse them to coherently style other parts of your chat outside of MML attachments (these are used in the MML docz app for instance).
import { locals as mmlTheme } from 'mml-react/dist/styles/index.css';
// or
import { locals as mmlTheme } from 'mml-react/src/styles/index.scss';
// variables for js are transformed into camelCase, e.g.:
primaryAccent: '#006cff',
appCanvas: '#fff',
// ...etc.
Some components need to slightly change according to their position in the chat. To achieve this MML scope its CSS alterations in a configurable selector through the SCSS variables $mml-selector-wrapper-align-right and $mml-selector-wrapper-align-left whose default values are respectively .mml-align-right and .mml-align-left class selectors. These selectors need to be placed on the container element that wraps your MML attachment. Internally to this library these SCSS tweaks are implemented through the SCSS mixins mml-align-right and mml-align-left, e.g.:
@include mml-component('text') {
@include mml-align-left() {
text-align: left;
}
@include mml-align-right() {
text-align: right;
}
}
MML attachments always have two wrapping elements with the following two classes:
.mml-container
.mml-wrap
The class .mml-container is responsible for some very basic styling that other components inherit, like border-box and font-family.
The class .mml-wrap instead takes care of contextual styling, like border-radius and margins, that are most likely dependent on the differentiation between me and other messages seen above.
Inside mml-wrap you could have as immediate children either the components as they are or the components automatically wrapped in a <div class="mml-card">...</div> when <mml type="card"> is used (see the MML docs). Note that the mml-card class (and its Card React component) is also used internally in various components like Scheduler and AddToCalendar.
yarn docs to run hot reload docs, best way to work on the componentsyarn build to build and type checkyarn lint to run lintingyarn format to prettify thingsyarn test to run testsnpm version patch|minor|major to make a releaseThe tree has:
mml_name)Let's say you want to create a new tag called color_picker.
Here's how you would go about implementing it.
In src/components directory create a file called ColorPicker.tsx and do something along these lines:
export const ColorPicker: FC<ColorPickerProps> = ({ name, value = '' }) => {
const [state, setState] = useState(value);
return (
<input
className="mml-input"
name={name}
value={state}
placeholder={placeholder}
onChange={(event) => setState(event.target.value)}
/>
);
};
Add an entry to converters.tsx file
color_picker: (tag: MMLTag) => {
return <ColorPicker {...tag.attributes} key={tag.key} name={tag.attributes.name} value={tag.attributes.value} />;
};
Docs is the easiest way to test your component in isolation. Simply create a new file named ColorPicker.mdx similar to other mdx files in the component directory and document/test the component.
We welcome code changes that improve this library or fix a problem. Please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are pleased to merge your code into the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.
We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
Check out our current openings and apply via Stream's website.
FAQs
MML (Message Markup Language) for React.
The npm package mml-react receives a total of 87,367 weekly downloads. As such, mml-react popularity was classified as popular.
We found that mml-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.