@focus-reactive/sanity-plugin-inline-svg-input

中文文档
1.3.1发布于 2026/05/06MITTypeScriptESM + CJS近 30 天下载 5465

Sanity plugin to upload and preview inline SVGs

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Preview
  4. Within arrays
  5. Custom preview component
  6. Development, testing and publishing
  7. Credits
  8. Our Expertise

Sanity Plugin Inline SVG Input npm version Sanity Exchange

Sanity Studio v3 plugin to upload and preview inline SVGs.

preview

Installation

npm install @focus-reactive/sanity-plugin-inline-svg-input
yarn add @focus-reactive/sanity-plugin-inline-svg-input
pnpm add @focus-reactive/sanity-plugin-inline-svg-input

Usage

  1. Add it as a plugin in sanity.config.ts (or .js):
import { defineConfig } from 'sanity'
import { inlineSvgInput } from '@focus-reactive/sanity-plugin-inline-svg-input'

export default defineConfig({
  // ...
  plugins: [inlineSvgInput()],
})
  1. Use the inlineSvg type in your schema types:
// ...
{
  fields: [
    // ...
    {
      name: 'svgIcon',
      title: 'SVG Icon',
      type: 'inlineSvg',
    },
  ]
}

That's it! Now you can use this field to upload SVG images and see the preview in your Sanity Studio.

Preview

The sections below describe how to preview your SVG within arrays, objects or your own custom preview component.

Within arrays

Sanity offers a convenient way to preview arrays out of the box, but it only allows the use of the image type in media. To provide same functionality for SVGs, we provide a ready-to-use preview component that mimics the default array preview.

preview

To preview your SVG in arrays, use the InlineSvgPreviewItem component.
It accepts the following props:

  • icon [string] - inline SVG
  • title [string] - the title of the item
  • subtitle [string] - the subtitle of the item

iconsList in the example below is an array of objects with icon, title and subtitle fields. To use them in preview the same way as the default array preview, only what you need is to replace default preview component with InlineSvgPreviewItem.

import { defineType } from 'sanity'
import { InlineSvgPreviewItem } from '@focus-reactive/sanity-plugin-inline-svg-input'

const IconsListItem = defineType({
  type: 'object',
  name: 'iconsListItem',
  fields: [
    {
      name: 'icon',
      type: 'inlineSvg',
    },
    {
      name: 'title',
      type: 'string',
    },
    {
      name: 'subtitle',
      type: 'string',
    },
  ],
  preview: {
    select: {
      icon: 'icon',
      title: 'title',
      subtitle: 'subtitle',
    },
  },
  components: {
    preview: ({ icon, title, subtitle }) => {
      return <InlineSvgPreviewItem icon={icon} title={title} subtitle={subtitle} />
    },
  },
})

const IconsList = defineType({
  name: 'iconsList',
  type: 'array',
  of: [{ type: IconsListItem.name }],
})

Custom preview component

If you need more customization or want to build your own preview component using SVG icons, you can use the InlineSvgPreviewComponent.

InlineSvgPreviewComponent is the smallest building block of the plugin the only purpose of which is to sanitize and render SVG.
It accepts the following props:

  • value [string] - inline SVG
import { InlineSvgPreviewComponent } from '@focus-reactive/sanity-plugin-inline-svg-input'

export const PreviewComponent = ({ value }) => {
  return (
    // ...
    <InlineSvgPreviewComponent value={value} />
    // ...
  )
}

To customize the preview component, you can either:

  • Pass className or style props
  • Extend default styles with styled-components
import { InlineSvgPreviewComponent } from '@focus-reactive/sanity-plugin-inline-svg-input'
import styled from 'styled-components'

const StyledInlineSvg = styled(InlineSvgPreviewComponent)`
  // ...
`

Development, testing and publishing

This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.

npm run build - creates a ready to publish plugin in /dist folder.

npm run link-watch - creates a symlink from the plugin repo to the local sanity repo and watches for changes. After running this command, you will see the instructions on how to add this plugin to your Sanity Studio in the terminal.

npm publish - there is pre-publish script that prepares the plugin for publishing, you don't need to build it manually. Please run npm publish --dry-run to make sure that everything is ok before publishing.

See Testing a plugin in Sanity Studio for additional information.

Credits

This project was created at FocusReactive - the Sanity Partner Agency. We specialize in helping clients beat the competition and accelerate business growth. With a deep expertise in headless CMS, NextJS, and eCommerce, we deliver cutting-edge solutions that prioritize your business goals.

Our Expertise

  • Content-Centric Websites: We have a deep experience building extendable, SEO optimized content and marketing websites with advanced CMS integrations and analytics.
  • Headless eCommerce: Our next-generation, content-rich, and performant online eCommerce websites come with end-to-end integrations to power your digital business.
  • Headless CMS Consulting: We offer multi-channel CMS development, modeling, customization, and support to help you manage your content seamlessly across various platforms.
  • Web Performance: Our experts can audit, transform the architecture, and optimize your website to meet the 100 SCORE Core Web Vitals for exceptional web performance.

If you're looking for expertise in headless CMS, NextJS, or eCommerce, get in touch with FocusReactive today. Visit our website at focusreactive.com to learn more about how we can help you accelerate your business growth.

FocusReactive

This project is licensed under the MIT License. © 2023 FocusReactive.

版本与发布记录

@focus-reactive/sanity-plugin-inline-svg-input 共发布 7 个版本,首次发布于 2023/11/29;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.3.1latest2026/05/066 个月前
1.3.02026/02/168 个月前
1.2.02025/07/241.3 年前
1.1.02024/06/252 年前
1.0.12023/12/132 年前
1.0.02023/11/292 年前

关于 @focus-reactive/sanity-plugin-inline-svg-input 的常见问题

@focus-reactive/sanity-plugin-inline-svg-input 是什么?

Sanity plugin to upload and preview inline SVGs

如何安装 @focus-reactive/sanity-plugin-inline-svg-input?

在项目目录运行 npm install @focus-reactive/sanity-plugin-inline-svg-input,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18 || ^19)、sanity(^3 || ^4 || ^5)、@sanity/ui(^1 || ^2)、styled-components(^5 || ^6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@focus-reactive/sanity-plugin-inline-svg-input 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@focus-reactive/sanity-plugin-inline-svg-input 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@focus-reactive/sanity-plugin-inline-svg-input 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@focus-reactive/sanity-plugin-inline-svg-input 可以商用吗?

@focus-reactive/sanity-plugin-inline-svg-input 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@focus-reactive/sanity-plugin-inline-svg-input 的下载量有多少?

根据 npm 官方下载统计,@focus-reactive/sanity-plugin-inline-svg-input 在 2026/10/15 – 2026/11/13 这 30 天内被下载 5,465 次,日均约 182 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@focus-reactive/sanity-plugin-inline-svg-input 还在维护吗?

最新版本 1.3.1 发布于 2026/05/06(6 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/11/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。