Need app-wide CSS constants in GWT

前端 未结 3 1541
情话喂你
情话喂你 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: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:
    
        .myStyle {
            color: orange;
        }
    

    Hope that helps.

    EDIT:

    To avoid the relative path in the 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

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

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

提交回复
热议问题