-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |