Need app-wide CSS constants in GWT

前端 未结 3 1554
情话喂你
情话喂你 2021-02-04 15:53

I\'d like to define some colours as constants in a GWT CssResource, and use those constants throughout my application; but I don\'t know how to do that.

I\'ll tell you w

相关标签:
3条回答
  • 2021-02-04 16:27

    You should be able to use

    <ui:style>
      @IMPORT url("../../../global.css");
      .mainPanel {
        background:{resources.css.JUNGLEGREEN};
        ...
      }
    </ui:style>
    
    0 讨论(0)
  • 2021-02-04 16:31

    This is how we do it:

    • we place all our constant attributes in a constant.css file
    @def black #241b15;   /* text color */
    @def orange #ff4f00;   /* links */
    • in each ui.xml file you can reference to those constants the following way:
    <ui:style src="../../resources/css/constants.css">
        .myStyle {
            color: orange;
        }
    </ui:style>

    Hope that helps.

    EDIT:

    To avoid the relative path in the <ui:style> element you could do the following:

    • define your constants again in a css file (say constants.css)
    @def junglegreen #1f3d0a;
    • create a ClientBundle and CssResource to retrieve the defined constants
    public interface MyResources extends ClientBundle {
    
        public static final MyResources INSTANCE = GWT.create(MyResources.class);
    
        public interface Constants extends CssResource {
    
            String junglegreen();
        }
    
        Constants constants();
    }

    -use the @eval annotation to access the constant

    <ui:style>
        @eval green com.gwt.client.widget.test.MyResources.INSTANCE.constants().junglegreen();
    
        .someClass {
            color: green;
        }
    </ui:style>

    The only way I know of how to deal with constants without referencing the css file itself.

    0 讨论(0)
  • 2021-02-04 16:37

    I know this answer might be kind of late but may help someone. I was having the same problem and was able to solve it by adding the following:

    Resources.css().ensureInjected()

    I added it in my factory but tried it in a couple of places and no matter where I put it, it worked.

    0 讨论(0)
提交回复
热议问题