npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kitconcept/volto-slider-block

v6.3.1

Published

Slider block for Plone 6 (Volto)

Downloads

3,057

Readme

Volto Slider Block

NPM Build Status Build Status Build Status

kitconcept GmbH

The Volto Slider Block allows editors to add sliders to a Volto page. You can see it in action under www.dlr.de and www.fz-juelich.de.

Screenshot

Screencast

https://user-images.githubusercontent.com/486927/170819371-6284d8e7-e5df-4893-9dab-cd06b1054505.mov

Volto Compatibility

These are the recommended versions:

| Version | Volto version | | ------- | ------------- | | >=5.0.0 | >=17.0.0-alpha.27 | | >=3.0.0 | >=16.0.0-rc.2 | | <=2.1.0 | <=16.0.0-a50 |

Installation

Create a new Volto project (you can skip this step if you already have one):

npm install -g yo @plone/generator-volto
yo @plone/volto my-volto-project --addon @kitconcept/volto-slider-block
cd my-volto-project

Add @kitconcept-volto/slider-blockto your package.json:

"addons": [
    "@kitconcept/volto-slider-block"
],

"dependencies": {
    "@kitconcept/volto-slider-block": "*"
}

Download and install the new add-on by running:

yarn install

Start Volto with:

yarn start

Go to http://localhost:3000, login, create a new page. The slider block will show up in the Volto blocks chooser.

Configuration options

enableAutoPlay

This enables the autoplay controls in the block's settings.

config.blocks.blocksConfig.slider.enableAutoPlay = true;

Upgrade Guide

volto-slider-block 6.0.0

The underlying library used by this block has been changed. Now it uses Embla Caroussel. Embla Caroussel has a similar API and has all the features that react-slick had. Embla is more modern and supported, uses hooks to configure itself and it's extensible using plugins. It solves all the problems that react-slick had, specially in the simplification of the containers and wrappers, and the way it handles the CSS transformations and the width of the elements.

If you've made any CSS customization, the classNames changed, so you'll need to update the CSS following this table.

| Old className | New className | | --------------- | ---------------- | | slick-slider | slider-wrapper | | slick-list | slider-viewport | | slick-track | slider-container | | slick-slide | slider-slide | | slick-arrow | slider-button | | slick-prev | slider-button-prev | | slick-next | slider-slide-next | | slick-next | slider-slide-next | | slick-dots | slider-dots | | slick-dot | slider-dot |

Customization

You can use a Volto schemaEnhancer to modify the existing block schema. The block also can be extended using Volto's block variations.

import { defineMessages } from 'react-intl';
import { pull } from 'lodash';

import SliderDefaultBody from './components/Blocks/Slider/DefaultBody'; // My custom view component for slides

const messages = defineMessages({
  color: {
    id: 'Color',
    defaultMessage: 'Color',
  },
  slideBackgroundColor: {
    id: 'Slide Background Color',
    defaultMessage: 'Slide Background Color',
  },
  flagColor: {
    id: 'Flag color',
    defaultMessage: 'Flag color',
  },
});

const BG_COLORS = [
  { name: 'transparent', label: 'Transparent' },
  { name: 'grey', label: 'Grey' },
];

// The schemaEnhancer
const sliderBlockSchemaEnhancer = ({ formData, schema, intl }) => {
  schema.properties.slides.schema.fieldsets[0].fields.push(
    'slideBackgroundColor',
  );
  schema.properties.slides.schema.properties.slideBackgroundColor = {
    widget: 'color_picker',
    title: intl.formatMessage(messages.slideBackgroundColor),
    colors: BG_COLORS,
    default: 'transparent',
  };
  pull(schema.properties.slides.schema.fieldsets[0].fields, 'description'); // You can remove fields as well
  return schema; // You should return the schema back
};

const applyConfig = (config) => {

  config.blocks.blocksConfig.slider = {
    schemaEnhancer: sliderBlockSchemaEnhancer,
    variations: [
      {
        id: 'default',
        isDefault: true,
        title: 'Default',
        view: SliderDefaultBody,
      },
    ],
  }

Extra Customization

More fields can be added to either the block itself or to each slide. You can use the configuration settings to do so:

config.blocks.blocksConfig.slider.extensions = {
  blockSchema: {
    fieldsets: [
      {
        id: 'default',
        title: 'Default',
        fields: ['new_field'],
      },
    ],
    properties: {
      new_field: {
        title: 'New Slider Field',
      },
    },
  },
  slideSchema: {
    fieldsets: [
      {
        id: 'default',
        title: 'Default',
        fields: ['new_field'],
      },
    ],
    properties: {
      new_field: {
        title: 'New Slide Field',
      },
    },
  },
};

The block and slide schemas will be merged with the existing ones.

Data adapter

The Teaser has a data adapter function that allows you to both tap into the changes in the settings and issue changes in other settings fields. This is valuable in the Teaser block because it saves an internal cache of the target element. If you select the target, these values are updated. When you update the target, by default these values remain, but you can issue another behavior.

The data adapter function is defined in the block's setting dataAdapter. You can override it and add your own function, if required. The following is the default adapter. You should stick to this signature in your custom adapters.

import { difference } from '@plone/volto/helpers';
import { replaceItemOfArray } from '@plone/volto/helpers';

export const SliderBlockDataAdapter = ({
  block,
  data,
  id,
  onChangeBlock,
  value,
}) => {
  let dataSaved = {
    ...data,
    [id]: value,
  };

  if (id === 'slides') {
    const diff = difference(value, data[id]);
    const index = diff.findIndex((val) => val);
    if (diff[index]?.href?.[0]) {
      dataSaved = {
        ...dataSaved,
        slides: replaceItemOfArray(value, index, {
          ...value[index],
          title: diff[index].href[0].Title,
          description: diff[index].href[0].Description,
          head_title: diff[index].href[0].head_title,
        }),
      };
    }
  }

  onChangeBlock(block, dataSaved);
};

Credits

The development of this plugin has been kindly sponsored by Forschungszentrum Jülich and the German Aerospace Center (DLR).

License

The project is licensed under the MIT license.