[Question] adding filter to styleManager
Question
Hi, I am trying to add a filter property to Styles. The problem that I am having is that the property demands 2 arguments: 1. The type of filter 2. The strength. e.g filter: blur(10%). the problem I am having is that when added to the css file I am getting- filter: blur 10%. I understand that I should be using property.functionName to fix this, but cannot figure out how (there appear to be no examples of this in the existing libraries).
The code I have is:
sm.addProperty('Extra', {
name: 'Filter',
property: 'filter',
type: 'stack',
properties: [{
property: 'filter_type',
type: 'select',
defaults: 'none',
list: [{ value: 'none' }, { value: 'blur'} ,{ value: 'brightness'},{ value: 'contrast'} ,{ value: 'drop-shadow'} ,{ value: 'grayscale'} ,{ value: 'hue-rotate'} ,{ value: 'invert'} ,{ value: 'opacity'} ,{ value: 'saturate'} ,{ value: 'sepia'} ,{ value: 'url'}],
},{
property: 'filter_strength',
type: 'slider',
name: 'Strength',
units: ['%'],
defaults: 100,
step: 1,
max: 100,
min:0,
}],
functionName: () => {
}
});
Thank you
Answers (3)
Hi @shlomoko to make the filter work properly via stack type you have to add a custom style manager type, because, as you already noticed, you have to deal with dynamic stuff (eg. functionName). Unfortunately, we didn't document that part yet and the only example we have is grapesjs-style-gradient. Extending the stack property might be even a bit harder (probably will require also some enhancement on the current API), so I'll try to provide an example of this case.
Hi @shlomoko I've created a plugin with the filter type input https://github.com/artf/grapesjs-style-filter You can use it with the latest release https://github.com/artf/grapesjs/releases/tag/v0.14.40
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1614
[Bug]: adding css variables as style manager property
trying to add css variable to style manager causing error: Uncaught TypeError: Cannot read property 'toUpperCase' of undefined fiddle Am i...
Issue #1781
add a font-size type prop
I'm trying to create a font-size type of property that I would like to add to the dimensions sector. Doing this: Getting the value and all,...
Issue #1030
[Question] Firing events with custom components
I'm trying to build a plugin for Grapesjs with some custom components, and I'm having trouble with triggering events and interacting with t...
Issue #1179
[Question] Cannot load styles saved as !important
Hi! I'm trying to make all the user-set styles have the "!important" flag, in order to prevent some other previous existent classes to over...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.