In this section, we will learn how to build a simple “Color Picker” app using the Contentstack App Framework. This app contains a Custom Field UI location, which provides a native color picker polyfill that Contentstack users can use as an input field.
This step-by-step guide explains how to create a Color Picker app and use it to select color as an input within an entry.
As a first step, you need to create a project directory where you can work in. You can use the Contentstack Apps CLI Plugin to clone the Marketplace App Boilerplate for creating your project.
csdx app:create



Your boilerplate will be cloned locally in the color-picker directory and the app is automatically registered in Developer Hub.
cd color-picker
npm install
npm run dev
This hosts your application on http://localhost:3000. We will connect to this through the Contentstack web app.
The boilerplate app has sample pages for all the supported UI locations in the source code. To test the app, Install the app in one of the stacks.
csdx app:install




You will see a custom field as shown above.
npm i reactcss react-color @contentstack/venus-components npm i --save-dev @types/react-color
export interface ColorPickerData {
showPicker: boolean;
pickerColor: {
r: string;
g: string;
b: string;
a: string;
};
} /* eslint-disable @typescript-eslint/no-explicit-any */
/* Import Node modules */
import React from "react";
import { useEffect, useState } from "react";
import { Color, SketchPicker } from "react-color";
import reactCSS from "reactcss";
import { InstructionText } from "@contentstack/venus-components";
import { isEmpty } from "lodash";
/* Import our modules */
import localeTexts from "../../common/locales/en-us/index";
import { ColorPickerData } from "../../common/types/types";
import { useCustomField } from "../../common/hooks/useCustomField";
/* Import our CSS */
import "./styles.css";
const CustomFieldUILocation = () => {
const { customField, setFieldData }: any = useCustomField();
const [stateColor, setColor] = useState<ColorPickerData>({
showPicker: false,
pickerColor: {
r: "108",
g: "92",
b: "231",
a: "100",
},
});
const styles = reactCSS({
default: {
color: {
width: "70px",
height: "30px",
borderRadius: "4px",
background: `rgba(${stateColor.pickerColor.r}, ${stateColor.pickerColor.g}, ${stateColor.pickerColor.b}, ${stateColor.pickerColor.a})`,
},
},
});
const togglePickerVisibility = () => {
setColor((prev) => ({
showPicker: !prev.showPicker,
pickerColor: prev.pickerColor,
}));
};
const closePicker = () => {
setColor((prev) => ({
showPicker: false,
pickerColor: prev.pickerColor,
}));
};
const pickerColorChanged = (color: any) => {
setColor((prev) => ({
showPicker: prev.showPicker,
pickerColor: color.rgb,
}));
setFieldData(color);
};
useEffect(() => {
if (!isEmpty(customField) && customField !== null) {
setColor({
showPicker: false,
pickerColor: customField.rgb,
});
}
}, [customField]);
return (
<div className="layout-container">
<InstructionText testId="color-picker-text">{localeTexts.CustomField.instruction}</InstructionText>
<div>
<div className="swatch" role="none" onClick={togglePickerVisibility} onKeyDown={togglePickerVisibility}>
<div style={styles.color} />
</div>
{stateColor.showPicker ? (
<div className="popover">
<div className="cover" role="presentation" onClick={closePicker} onKeyDown={closePicker}>
<SketchPicker color={stateColor.pickerColor as unknown as Color} onChange={pickerColorChanged} />
</div>
</div>
) : null}
</div>
</div>
);
};
export default CustomFieldUILocation;
.layout-container {
padding: 5px;
margin: -28px 0;
}
.layout-container .InstructionText {
text-align: left;
color: #647696;
display: block;
font-family: Inter;
font-size: 0.75rem;
line-height: 1.5;
}
.layout-container .swatch {
padding: 5px;
background: #fff;
border-radius: 1px;
box-shadow: 0 0 0 1px rgb(0 0 0 / 10%);
display: inline-block;
cursor: pointer;
}
CustomField: {
. . .
instruction: "Pick a Color",
},
npm start

Host the app on Launch:
Now that your app is ready, you can host it on Launch for your team to use. You can also choose to host the app on external services like Netlify, Vercel, etc.
Secure your application:
Using the signed support, you can learn how to secure calls to outgoing APIs from the Contentstack UI and backend using the Contentstack App Framework.
Submit for publishing on Marketplace:
Once your application is production-ready and you want to share the solution with Contentstack Marketplace, you can check the App Submission and Approval Guide.