Skip to content

Commit

Permalink
feat: create image and alt schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Oct 6, 2024
1 parent df05fd3 commit fc5f17d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/sanity-cms/schemas/fields/basic/alt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineField } from 'sanity';

export const altField = defineField({
title: 'Alternative Text',
description: (
<p>
Describe the image for screen readers and search engines. It is not meant to supplement the
image and should not repeat information that is already provided in the context around the
image.{' '}
<a
href="https://html.spec.whatwg.org/multipage/images.html#general-guidelines"
target="_blank"
rel="noopener noreferrer"
>
Learn More.
</a>
</p>
),
name: 'alt',
type: 'string',
validation: (Rule) => Rule.required(),
});
56 changes: 56 additions & 0 deletions packages/sanity-cms/schemas/fields/basic/image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { defineField } from 'sanity';
import type { SchemaFieldsType } from '../../types';
import { altField } from './alt';

const imageFields = [
defineField({
title: 'Priority Loading',
description: (
<p>
Load the image immediately when the page loads. This must only be used for images that are
immediately visible on screen when the page loads.{' '}
<strong>
Don't enable this inside a rich copy block. Rich copy blocks override this setting.
</strong>
</p>
),
name: 'priority',
type: 'boolean',
initialValue: false,
}),
defineField({
title: 'Rounded Corners',
description: (
<p>
Round the image corners.{' '}
<strong>If the image already has rounded corners, this must be enabled.</strong>
</p>
),
name: 'rounded',
type: 'boolean',
initialValue: true,
}),
];

const imageFieldsWithAlt = [...imageFields, altField];

export const imageFieldDefinition = {
name: 'image',
type: 'image' as const,
title: 'Image',
description: 'An image will full accessibility support',
options: {
hotspot: true,
},
fields: imageFieldsWithAlt,
};

export const imageField = defineField(imageFieldDefinition);

export const imageFieldWithOutAltText = defineField({
...imageFieldDefinition,
fields: imageFields,
});

export type ImageFieldsSchemaType = SchemaFieldsType<typeof imageFieldsWithAlt>;
export type ImageFieldsSchemaTypeWithoutAltText = SchemaFieldsType<typeof imageFields>;

0 comments on commit fc5f17d

Please sign in to comment.