Issue #3250Opened January 28, 2021by fmay2 reactions

Question : Layer labels

Question

@artf I am loving working with GJS. I have one last thing I'd love your help on.

It would be incredibly helpful to be able to customise the labels in the layer manager. I've searched high and low but not found anything.

The default way it just shows Text and Box is not very helpful when wanting to navigate efficiently.

<img width="204" alt="Screen Shot 2021-01-28 at 07 27 16" src="https://user-images.githubusercontent.com/2796719/106104795-d5544800-613a-11eb-97c4-762e5977e872.png">

I would really like to be able to customise these myself. In my case, I'd like to show the tagname and the id.

Many thanks

Answers (3)

artfFebruary 3, 20211 reactions

You can extend the model of your component/s and overwrite the getName function

fmayFebruary 4, 20211 reactions

In case this is useful for anyone, I found an easy/alternative way of doing this when a component is created.

editor.on('component:create', function(component) {

  // filter the tag types you're interested in
  if( component.attributes.tagName === 'div' ) {

    // Get some information you want to use as the replacement text
    // In my case, the component element's id attribute, which is stored in component.ccid
    const idParts = component.ccid.split('-')
    if( idParts.length > 0 && idParts[0] === 'cbt') {
      // This is specific to my case, but 'component.attributes.name' is the field that appears in the layer manager
      component.attributes.name = ''
      for( let i=1; i < idParts.length; i++ ) {
        component.attributes.name += idParts[i].charAt(0).toUpperCase() + idParts[i].slice(1) + ' '
      }
    }
    else {
      component.attributes.name = 'Div'
    }
  }
})
flaucNovember 9, 20240 reactions

This is how I did it:

  grapesInstance.on('component:create', (component) => {
    component.getName = () => component.attributes['custom-name'] || `${component.attributes.tagName}#${component.ccid}`;
  });

The benefit is that if the components id or tag change later it will still be updated in the layer manager and you can also rename individual components.

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.