All Projects → rdunk → sanity-blocks-vue-component

rdunk / sanity-blocks-vue-component

Licence: MIT license
Vue component for rendering block content from Sanity

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to sanity-blocks-vue-component

sneyder.dev
📌 My personal website.
Stars: ✭ 26 (-61.19%)
Mutual labels:  sanity
React-Commenting-System
Commenting System built with NextJS and Sanity
Stars: ✭ 28 (-58.21%)
Mutual labels:  sanity
how-to-css
howtocss.dev
Stars: ✭ 48 (-28.36%)
Mutual labels:  sanity
sanity-plugin-media
Asset management plugin for Sanity
Stars: ✭ 106 (+58.21%)
Mutual labels:  sanity
exo
EXO, the empathy-first framework for an accessible world.
Stars: ✭ 75 (+11.94%)
Mutual labels:  sanity
sanity-mobile-preview
An NPM package written in React used to preview mobile devices. Especially helpful when used in combination with a CMS like sanity.
Stars: ✭ 19 (-71.64%)
Mutual labels:  sanity
nuxt-sanity
Easily integrate Sanity in your Nuxt.js project.
Stars: ✭ 14 (-79.1%)
Mutual labels:  sanity
sanity-linq
Strongly-typed .Net Client for Sanity
Stars: ✭ 36 (-46.27%)
Mutual labels:  sanity
sanity-codegen
Generate TypeScript types from your Sanity.io schemas
Stars: ✭ 181 (+170.15%)
Mutual labels:  sanity
sanity-portfolio-studio
A Sanity.io instance that powers a Gatsby portfolio site. Watch it get built live:
Stars: ✭ 14 (-79.1%)
Mutual labels:  sanity
startup-starter-kit
The Structured Content Startup Starter Kit
Stars: ✭ 42 (-37.31%)
Mutual labels:  sanity
sanity-gatsby-portfolio
A Gatsby portfolio site powered by Sanity.io. Watch it get built live:
Stars: ✭ 16 (-76.12%)
Mutual labels:  sanity
svelte-portable-text
Svelte component for rendering block content
Stars: ✭ 30 (-55.22%)
Mutual labels:  sanity

Sanity Blocks Vue Component

NPM version NPM downloads GitHub Release Date Vue version License

A Vue component for rendering block content from Sanity.



Install

Notice: This version is a complete rewrite for Vue 3. For Vue 2 and Nuxt 2, follow the instructions in the legacy branch.

$ npm i sanity-blocks-vue-component # or yarn add sanity-blocks-vue-component

Usage

Import directly into your component or view:

<template>
  <SanityBlocks :blocks="blocks" :serializers="serializers" />
</template>

<script>
import { SanityBlocks } from 'sanity-blocks-vue-component';
import CustomComponent from 'CustomComponent.vue';

export default {
  components: { SanityBlocks },
  setup() {
    const blocks = [...]; // Sanity block text
    const serializers = {
      types: {
        custom: CustomComponent,
      },
    };
    return { blocks, serializers };
  }
}
</script>

Or install globally:

import { createApp } from 'vue';
import { SanityBlocks } from 'sanity-blocks-vue-component';
import App from './App.vue';

const app = createApp(App);
app.component('sanity-blocks', SanityBlocks);
app.mount('#app');

Props

The following props can be passed to the component.

Prop Required Description Type
blocks Yes Block content retrieved from Sanity. Array
serializers No Any custom serializers you want to use. See below. Object

Serializers

Serializers are the functions used for rendering block content. They can be defined as a string or a Vue Component. This package comes with default serializers for rendering basic block content, you can pass a serializer prop to override or extend the defaults.

Property Description
types Object of serializers for block types.
marks Object of serializers for marks.
styles Object of serializers for styles.
list Serializer for list containers.
listItem Serializer for list items.
hardBreak Serializer for hard breaks.

Component Serializers

The most common use case is defining serializers for custom block types and marks, using the types and marks serializer properties. For example, if you have a block of type custom, you can add a property to the serializers.types object with the key custom and a value of the Vue component that should serialize blocks of that type.

When using a custom Vue component as a serializer, all properties of the block or mark object (excluding _key and _type) will be passed as props.

To access the data, you should define the correpsonding props in your component.

For mark serializers, you can also use slots to access the mark text or content.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].