Display colors for editors to choose from with this custom input component.
Starting from 2.0.0 the whole color object is returned and the type
has been changed from colors
to colorlist
.
sanity install color-list
- In your schema:
...,
{
title: "Color List",
description: "Pick a color",
name: "colors",
type: "colorlist", // required
options: {
list: [
{ title: "Red", value: "#f16d70" },
{ title: "Teal", value: "#88c6db" },
{ title: "Purple", value: "#aca0cc" },
{ title: "Green", value: "#bdcdcb" },
{ title: "White", value: "white" }
]
}
},
...
Done. The component returns the selected list object. If the value key was an object it will return an rgb string instead.
This plugin offers some ways of customization via the options object. If you don't use an off-white theme in your studio the defaults should work well out of the box.
{string} [background="white"] // If you are using a theme with a non-white bg use this to inform the plugin of this non-white background color so that contrasts can be calculated properly
{object} [borderradius]
{string} [borderradius.outer="100%"] // Borderradius for the active decorator
{string} [borderradius.inner="100%"] // Borderradius for the main item
{number} [contrastcutoff=20] // 0-255. When the contrast between the background and the color falls below this level decorate the item with a lighter/darker value for better contrast
{number} [darken=10] // How much darker than the actual color the decoration color will be
{number} [lighten=10] // How much lighter than the actual color the decoration color will be
{bool} [tooltip] // Set to true to show a tooltip with the colors title on hover/focus
{object} list
{string} list.title // Used to display a tooltip if activated
{string || object} list.value // can be an object with keys for r, g and b or a valid color string. 0x formatted hex strings are not supported at the moment.
Issues are actively monitored and PRs are welcome. When developing this plugin the easiest setup is:
- Fork this repo.
- Install the sanity cli and create a sanity project:
npm install -g @sanity/cli && sanity init
. Follow the prompts, starting out with the blog template is a good way to go. cd
into your project directory, runnpm install && npm start
- your sanity studio should be running on http://localhost:3333.cd
into theplugins
director of your project.- Fork this repo and clone your fork into the
plugins
directory inside your projectgit clone [email protected]:your-fork/sanity-plugin-color-list.git
. - Open
sanity.json
, go to theplugins
array and addcolor-list
. - Re-start the sanity studio server with
npm start
. - Edit
schemas/post.js
and add follow the plugin documentation to add acolorlist
type field. - Your studio should reload, and now when you edit the plugin code it should reload the studio, when you're done create a branch, put in a PR and a maintainer will review it. Thank you!