Issue #3123Opened November 9, 2020by fq-selbach1 reactions

FEAT: Add 'inline-flex' to display selector in Style Manager

Question

What are you trying to add to GrapesJS?

Display style inline-flex.

Description:

Currently the display selector of the Style Manager has only flex as option but same as block and inline-block it is useful to have inline-flex. When I try to add it manually with this (hack?):

editor.StyleManager.getProperty("general", "display").attributes.list.push({value: "inline-flex"});

I get a result but there are many conditional operators triggered by flex that won't trigger on inline-flex like for example the Style Manager "Flex" section will not appear.

Is there an alternative at the latest version?

[ ] Yes (descripe the alternative) [x] No

Is this related to an issue?

[ ] Yes (Give a link to the issue) [x] No

Answers (3)

lexoyoAugust 18, 20251 reactions

For anyone looking for a solution, I didn't manage to do this by modifying the StyleManager options So here is what I did

    const sector = editor.StyleManager.getSector('flex')
    sector.on('change:visible', () => applyVisibility())
    editor.on('component:selected', comp => applyVisibility(comp))
    function applyVisibility(comp: Component = editor.getSelected()) {
      requestAnimationFrame(() => {
        const computedDisplay = comp?.view?.el && getComputedStyle(comp.view.el)['display'] as string || ''
        const isFlex = computedDisplay === 'flex' || computedDisplay === 'inline-flex'
        const parent = comp.parent()
        const parentComputedDisplay = parent?.view?.el && getComputedStyle(parent.view.el)['display'] as string || ''
        const parentIsFlex = parentComputedDisplay === 'flex' || parentComputedDisplay === 'inline-flex'
        if (parentIsFlex || isFlex) {
          sector.set('visible', true)
        }
        if (parentIsFlex && isFlex) {
          sector.getProperties()
            .forEach(p => p.set('visible', true))
        } else if (isFlex) {
          sector.getProperties()
            .forEach(p => p.set('visible', FLEX_PROPS.includes(p.getId())))
        } else if (parentIsFlex) {
          sector.getProperties()
            .forEach(p => p.set('visible', FLEX_ITEM_PROPS.includes(p.getId())))
        }
      })
    }
artfNovember 16, 20200 reactions

Sorry @fq-selbach but this is something that could be handled via plugins, there is no need to have this logic in the core library

fq-selbachNovember 16, 20200 reactions

@artf ok, but can you tell me please how I can control the "Flex" category of the Style Manager because the logic of showing/hiding it seems to be hard-coded :-/ I can add 'inline-flex' to the "Display" selector with a plugin ... but it will never show the "Flex" category when its selected. Alternatively can you show me how to make the "Flex" category show always instead of being controlled by "Display=flex"?

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.