grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

QUESTION: Is there a way to use different variations of the same style property?

Open Joshmamroud opened this issue 6 years ago • 8 comments

Note: This is in the context of the Style Manager.

Is there a way to use different variations of the same style property?

For example when I use the text-align property on a non-text node component I'd like the label to read "Align Content" with the options of "left", "right" and "center". However, when the "text-align" property is displayed for a text node I'd like the label to read "Align Text" with the options of "left", "right", "center", and "justify".

I've searched the documentation and issues on GitHub and can't seem to find any answers.

Does anyone know how to achieve this?

Thanks in advance!

Joshmamroud avatar Sep 01 '20 20:09 Joshmamroud

I don't think that's possible using the API, also does text-align work for non-text components? You'll probably want to use the align-content property from flexbox

Ju99ernaut avatar Sep 05 '20 08:09 Ju99ernaut

You should try to use Component's stylable-require property to show the particular style property (marked with toRequire) and unstylable for the one you don't need.

editor.Components.addType('...', {
 model: {
  defaults: {
   'stylable-require': ['align-content'],
   unstylable: ['text-align'],
  }
 }
});

// in your StyleManager configuration
buildProps: [..., 'text-align', 'align-content'],
properties: [{
       // ...
        property: 'align-content',
        toRequire: true, // <-- So this property will be hidden if the component doesn't require it
}]

artf avatar Sep 08 '20 06:09 artf

@artf Thank you for your response.

In this case, I would still have an issue using the align-content property with flex columns and rows. For columns, I'd like the options to read: Top, Center, and Bottom and for rows I'd like the options to read: Left, Center, and Right.

My users aren't too familiar with CSS let alone flexbox and to use Start, Center and End won't be as good of a user experience as I'd like.

Do you have any other suggestions?

Thank you, Josh

Joshmamroud avatar Sep 08 '20 18:09 Joshmamroud

In Style Manager configuration, you use buildProps to build a built-in property object but you can also use properties key to extending those generated.

An example of what I do in the main demo page

buildProps: [..... 'margin', 'padding'],
properties: [
  // ...
  {
     property: 'margin', // this will merge the 'margin' property with the one genereated from "buildProps"
     properties:[ // Here I'm replacing the key which defines names for inner properties
        // So, instead of having the default "Margin Top" label I replace it with "Top"
        { name: 'Top', property: 'margin-top'},
        { name: 'Right', property: 'margin-right'},
        { name: 'Bottom', property: 'margin-bottom'},
        { name: 'Left', property: 'margin-left'}
      ],
 }
]

artf avatar Sep 08 '20 23:09 artf

@artf Thank you again for your response.

In my case I would need two sets of properties. One for flex rows and another for flex columns.

For example I'm looking to accomplish something like this:

buildProps: [..., 'align-column', 'align-row', 'padding'], // I know this is wrong
properties: [

  // these would be used for COLUMNs
  {
     id: 'align-column', // I know this doesn't do anything at the moment
     property: 'align-content',
     properties:[ 
        { name: 'Top', property: 'flex-start'},
        { name: 'Center', property: 'center'},
        { name: 'Bottom', property: 'flex-end'},
      ],
  },

  // These would be used for ROWs
  {
     id: 'align-row', // I know this doesn't do anything at the moment
     property: 'align-content',
     properties:[ 
        { name: 'Left', property: 'flex-start'},
        { name: 'Center', property: 'center'},
        { name: 'Right', property: 'flex-end'},
      ],
  }
]

As you can see here I'm trying to use the same align-content property in two different ways. One for flex rows and another for flex columns.

Would this be possible?

Thanks again! -Josh

Joshmamroud avatar Sep 08 '20 23:09 Joshmamroud

Well, actually the thing with id works and, your code should run as you expect

artf avatar Sep 12 '20 21:09 artf

@artf I've tried that, many times, and I can't get it to work. Can you please provide an example of how to use it? It would be greatly appreciated

Joshmamroud avatar Sep 17 '20 14:09 Joshmamroud

I have the same issue - if I use property id in 'stylable-require' - it doesn't work @Joshmamroud @artf have you any solution of this problem?

OrigoVl avatar Aug 22 '23 10:08 OrigoVl