Configuration
The react-better-html library allows you to configure various aspects of its components through the <BetterHtmlProvider> wrapper component. This includes customizing the theme, icons, assets and more.
BetterHtmlProvider
The <BetterHtmlProvider> component should wrap your application's root component to apply the configuration.
import { createRoot } from "react-dom/client";
import { BetterHtmlProvider } from "react-better-html";
import App from "./App";
const root = document.getElementById("root");
createRoot(root).render(
<BetterHtmlProvider>
<App />
</BetterHtmlProvider>
);
This is enough for the components to work with the default configuration that the library comes with. They can be overridden by passing config prop to the <BetterHtmlProvider> tag.
If no value is provided for the config prop, then all components in the library will use the default configuration that comes with the library. Check out the default configuration
App configuration
There are some configuration properties for the whole app that can be set from the app object
<BetterHtmlProvider
config={{
...
app: {
contentMaxWidth: 1200
},
...
}}
>
<App />
</BetterHtmlProvider>
| Key | Value Type | Default Value | Description |
|---|---|---|---|
| contentMaxWidth | number | 1200 | Sets the max content width of the <PageContent /> component |
Theme configuration
It accepts object of type Theme and can customize the styles and colors. Colors support theme management.
<BetterHtmlProvider
config={{
...
theme: {
colors: {
light: {
backgroundBase: "#f0f0f0"
},
}
styles: {
gap: 20
}
},
...
}}
>
<App />
</BetterHtmlProvider>
All properties are optional - the default configuration values will be used otherwise.
We recommend using the default values initially and change them only if needed by your special use-cases.
Icons configuration
It accepts object of type IconConfig and can customize the already predefined ones. You can also define your own icons and use them by name in the Icon component.
<BetterHtmlProvider
config={{
...
icons: {
XMark: { // `XMark` is the name of the icon
width: 384,
height: 512,
paths: [
{
d: "M342.6 150.6c12.5-12.5 ...",
type: "fill"
}
]
},
...
},
...
}}
>
<App />
</BetterHtmlProvider>
Assets configuration
It accepts object of type AssetConfig and can override the already predefined ones. You can also define your own images/assets and use them by name in the Image component.
import logoAsset from "../assets/logo.svg";
<BetterHtmlProvider
config={{
...
assets: {
logo: logoAsset, // `logo` is the name of the asset
...
},
...
}}
>
<App />
</BetterHtmlProvider>
Loaders configuration
It accepts object of type LoaderConfig and can override the already predefined ones. You can also define your own loaders and use them by name in the app.
<BetterHtmlProvider
config={{
...
loaders: {
testLoader: false, // `testLoader` is the name of the loader
...
},
...
}}
>
<App />
</BetterHtmlProvider>
You can access the value of the loaders using the useLoader hook. To change the values dynamically you can use the useLoaderControls hook.
Components configuration
It accepts a list of components that can be configured. Per every component you can override the default styles and the tag used for the component itself.
An example can be seen below where the button component is having the default style overridden and the tag used for the component is changed.
<BetterHtmlProvider
config={{
...
components: {
button: {
style: {
default: {
backgroundColor: "#16d7ed",
color: "#ffffff",
},
},
tagReplacement: {
buttonComponent: "button",
},
},
...
},
...
}}
>
<App />
</BetterHtmlProvider>
Currently only the button component is supported. But we plan to add more components in the future.
Default Configuration
Here are the default values used in the global configuration of the components.
App
The default values for the app constants in the library are:
contentMaxWidth- 1100px
Theme
The default colors used in the library are (More on the Theme type page):
- textPrimary - #111111
- textSecondary - #777777
- textLink - #0894ff
- label - #111111
- primary - #6d466b
- secondary - #412234
- accent - #16d7ed
- success - #28a745
- info - #0fa0da
- warn - #ffc107
- error - #dc3545
- base - #f8f8f8
- backgroundBase - #f8f8f8
- backgroundSecondary - #e8e8e8
- backgroundContent - #ffffff
- border - #ced4da
The default styles used in the library are:
space- 16pxgap- 8pxborderRadius- 10pxfontFamily- Arial, sans-seriftransition- ease 0.2s
Those styles are tested in different projects and UI layouts and fit 85% of the use-cases, so you are not likely to change them.
Icons
The default icons used in the library are (More on the Icons type page):
XMark- the symbolXuploadCloud- a cloud with an arrow pointing uptrash- a trashchevronDown- an arrow pointing downchevronLeft- an arrow pointing leftchevronRight- an arrow pointing rightdoubleChevronLeft- an double arrow pointing leftdoubleChevronRight- an double arrow pointing righteye- an open eyeeyeDashed- a closed/dashed eyemagnifyingGlass- a magnifying glasscheck- a tick/check symbol✔infoI- an informationisymbolwarningTriangle- a triangle with exclamation mark insidefilter- a funnel/filter symbol
Assets
The default assets used in the library are (More on the Assets type page):
logo- The logo of the project (you can override it with your own logo)
Loaders
There are no default loaders predetermined in the library.