import {defineType, defineField} from 'sanity'
export default defineType({
type: 'object',
title: 'Swatch',
name: 'swatch',
fields: [
defineField({
title: 'Name',
name: 'name',
type: 'string',
validation: (Rule) => Rule.required(),
}),
defineField({
title: 'Handleized name',
name: 'handle',
type: 'slug',
options: {
source: 'name',
disableArrayWarning: true,
},
description: "",
validation: (Rule) => Rule.required(),
}),
defineField({
title: 'Color',
name: 'color',
type: 'color',
validation: (Rule) => Rule.required(),
}),
],
preview: {
select: {
title: 'name',
subtitle: 'color.hex',
media: 'color',
},
prepare({title, subtitle, media}) {
return {
title,
subtitle,
media: <div style={{backgroundColor: media.hex, width: '100%', height: '100%'}} />,
}
},
},
})