Skip to content

Commit

Permalink
add button schema
Browse files Browse the repository at this point in the history
  • Loading branch information
milewskibogumil committed Oct 15, 2024
1 parent 88f8ff8 commit 918294f
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions apps/sanity/schema/ui/cta.tsx → apps/sanity/schema/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Tooltip, Box, Text, } from '@sanity/ui';
import { isValidUrl } from "../../utils/is-valid-url";
import { InternalLinkableTypes } from "../../structure/internal-linkable-types";

const name = 'cta';
const title = 'Call to action';
const icon = () => '🗣️';
const name = 'button';
const title = 'Button';
const icon = () => '🔘';

export default defineType({
name,
Expand All @@ -24,34 +24,44 @@ export default defineType({
name: 'theme',
type: 'string',
title: 'Theme',
description: 'Theme is used to style the button. Choose "Primary" for the main call to action, or "Secondary" for less important actions.',
description: (
<>
<em>Primary</em> (main button) or <em>Secondary</em> (less important)
</>
),
options: {
list: ['primary', 'secondary'],
layout: 'radio',
direction: 'horizontal',
},
initialValue: 'primary',
validation: Rule => Rule.required(),
fieldset: 'style',
}),
defineField({
name: 'type',
name: 'linkType',
type: 'string',
title: 'Type',
description: 'Choose "External" for links to websites outside your domain, or "Internal" for links to pages within your site.',
description: (
<>
<em>External</em> (other websites) or <em>Internal</em> (within your site)
</>
),
options: {
list: ['external', 'internal'],
layout: 'radio',
direction: 'horizontal',
},
initialValue: 'external',
validation: Rule => Rule.required(),
fieldset: 'style',
}),
defineField({
name: 'external',
type: 'string',
title: 'URL',
description: 'Specify the full URL. Ensure it starts with "https://" and is a valid URL.',
hidden: ({ parent }) => parent?.type !== 'external',
hidden: ({ parent }) => parent?.linkType !== 'external',
validation: (Rule) => [
Rule.custom((value, { parent }) => {
const type = (parent as { type?: string })?.type;
Expand All @@ -76,7 +86,7 @@ export default defineType({
disableNew: true,
filter: 'defined(slug.current)',
},
hidden: ({ parent }) => parent?.type !== 'internal',
hidden: ({ parent }) => parent?.linkType !== 'internal',
validation: (rule) => [
rule.custom((value, { parent }) => {
const type = (parent as { type?: string })?.type;
Expand All @@ -85,6 +95,21 @@ export default defineType({
}),
],
}),
defineField({
name: 'img',
type: 'image',
title: 'Image (optional)',
description: 'If you want to display small image instead of arrow, you can add it here.',
}),
],
fieldsets: [
{
name: 'style',
title: 'Style',
options: {
columns: 2,
}
},
],
preview: {
select: {
Expand Down

0 comments on commit 918294f

Please sign in to comment.