1.0.1 • Published 3 years ago

sanity-blocks-vue-component v1.0.1

Weekly downloads
1,804
License
MIT
Repository
github
Last release
3 years ago

Install

Notice: This version is a complete rewrite for Vue 3. For Vue 2, see versions <1.0.0.

$ 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.

PropRequiredDescriptionType
blocksYesBlock content retrieved from Sanity.Array
serializersNoAny 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.

PropertyDescription
typesObject of serializers for block types.
marksObject of serializers for marks.
stylesObject of serializers for styles.
listSerializer for list containers.
listItemSerializer for list items.
hardBreakSerializer 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

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.3

3 years ago

1.0.0-beta.4

3 years ago

1.0.0-beta.5

3 years ago

1.0.0-beta.1

3 years ago

0.1.0

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago