sanity-linked-media-asset
Version:
Expose and override image-asset fields (title, alt, …) directly in Sanity Studio.
71 lines (67 loc) • 2.12 kB
text/typescript
import React from 'react';
import { StringInputProps, FieldDefinition } from 'sanity';
/**
* Shared input component for image fields that displays the value from the linked asset (if present)
* alongside the local field value, and allows copying or updating between them.
*
* - Shows both the local and asset values for a field (e.g., title, altText, etc.)
* - Allows editing the local value and (optionally) the asset value
* - Provides a button to copy the asset value to the local field
* - Shows a toast notification if updating the asset fails
*
* @param props - See {@link LinkedMediaAssetFieldProps}
* @public
*/
declare const LinkedMediaAssetField: React.FC<StringInputProps>;
/**
* Type alias for the field definitions returned by getLinkedMediaAssetFields.
* Matches the FieldDefinition type
*/
type LinkedMediaAssetFieldDefinition = FieldDefinition;
/**
* Options for getLinkedMediaAssetFields.
*
* @public
*/
interface LinkedMediaAssetFieldsOptions {
title?: {
enabled: boolean;
};
altText?: {
enabled: boolean;
};
description?: {
enabled: boolean;
};
creditLine?: {
enabled: boolean;
};
}
/**
* Returns an array of linked asset text fields for use inside an image field.
* Each field uses the LinkedMediaAssetField component for local/asset value sync.
*
* Usage:
* ```ts
* import {getLinkedMediaAssetFields} from './linkedMediaAssetFields'
* ...
* fields: [
* defineField({
* name: 'image',
* type: 'image',
* fields: [
* ...getLinkedMediaAssetFields({
* title: {enabled: true},
* altText: {enabled: true},
* description: {enabled: true},
* creditLine: {enabled: true},
* }),
* // any custom fields
* ],
* }),
* ]
* ```
* @public
*/
declare function getLinkedMediaAssetFields(options?: LinkedMediaAssetFieldsOptions): LinkedMediaAssetFieldDefinition[];
export { LinkedMediaAssetField, type LinkedMediaAssetFieldDefinition, type LinkedMediaAssetFieldsOptions, getLinkedMediaAssetFields };