Customizing the UI
DATA VIZ provides a way to extend the UI by adding custom components. This guide will show you how to add a custom component to the UI.
You can also use functions from wp-react-lib to extend the UI.
Adding A new Component​
-
In the
front/app/embeddablefolder, create a new file/folder with the name of the component you want to create. -
Create a new component in the
front/app/embeddablefolder.
import React from 'react';
const MyComponent = () => {
return <div>My Component</div>;
};
export default MyComponent;
- Register the component in the
front/app/embeddable/index.tsfile.
It is recommended to use the lazy function to import the component. This is because the component will be loaded only when it is needed and also perform code splitting. This is also beneficial for performance.
const ExampleComponentLazy = lazy(() => import('./MyExampleComponent'));
const embeddables = {
// existing embeddables...
MyComponent: ExampleComponentLazy,
}
customizer.registerCustomEmbeddables(embeddables)
- Run the project and see the changes.
- The custom component needs to have a corresponding wordpress blocks for it to be rendered by Wordpress.
Adding A New Reducer​
-
In the
front/app/reducersfolder, create a new file with the name of the reducer you want to create. -
Create a new reducer in the
front/app/reducersfolder.
import { createSlice } from '@reduxjs/toolkit';
const myReducer = createSlice({
name: 'myReducer',
initialState: {
},
reducers: {
myAction: (state, action) => {
state.value = action.payload;
},
},
});
export const { myAction } = myReducer.actions;
export default myReducer.reducer;
- Register the reducer in the
front/app/reducers/index.tsfile.
import myReducer from './my-reducer';
const reducers = {
// existing reducers...
myReducer,
}
customizer.registerCustomReducers(reducers)
- Run the project and see the changes.
Customizing the Header Or Footer​
-
We provide a way to customize the header and footer of the application.
-
To customize the header or footer, you need to create a new component in the
front/app/components/layoutfolder. -
Create a new component in the
front/app/components/layoutfolder.
import React from 'react';
const MyHeader = () => {
return <div>My Header</div>;
};
- Import the component in any of the routes that have the following component:
ResponsiveContainerPreviewContainerPreviewPageContainerSlugContainerSlugPostContainer
import MyHeader from '~/components/layout/MyHeader';
const RouteComponent = () => {
return (
<ResponsiveContainer header={<MyHeader />}>
// your route content...
</ResponsiveContainer>
)
}