Skip to content

Commit cc02fa9

Browse files
committed
Finalize MaterialSymbol Component
1 parent f732166 commit cc02fa9

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

gwt-material/src/main/java/gwt/material/design/client/base/HasSymbols.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gwt.material.design.client.base;
22

3+
import gwt.material.design.client.constants.Color;
34
import gwt.material.design.client.constants.SymbolType;
45

56
public interface HasSymbols {
@@ -8,6 +9,10 @@ public interface HasSymbols {
89

910
void setSymbol(String symbol);
1011

12+
void setColor(Color color);
13+
14+
void setSymbolSize(String size);
15+
1116
void setFilled(boolean filled);
1217

1318
void setWeight(int weight);

gwt-material/src/main/java/gwt/material/design/client/constants/SymbolType.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44

55
public enum SymbolType implements CssType {
66

7-
OUTLINED("material-symbols-outlined"),
8-
ROUNDED("material-symbols-rounded"),
9-
SHARP("material-symbols-sharp");
7+
OUTLINED("material-symbols-outlined", "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"),
8+
ROUNDED("material-symbols-rounded", "https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"),
9+
SHARP("material-symbols-sharp", "https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL,[email protected],100..700,0..1,-50..200");
1010

1111
protected String name;
12+
protected String cssLink;
1213

13-
SymbolType(String name) {
14+
SymbolType(String name, String cssLink) {
1415
this.name = name;
16+
this.cssLink = cssLink;
1517
}
1618

1719
@Override
1820
public String getCssName() {
1921
return name;
2022
}
2123

24+
public String getCssLink() {
25+
return cssLink;
26+
}
27+
2228
public static SymbolType fromStyleName(final String styleName) {
2329
return EnumHelper.fromStyleName(styleName, SymbolType.class, OUTLINED);
2430
}

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialSymbol.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@
44
import com.google.gwt.dom.client.LinkElement;
55
import gwt.material.design.client.base.HasSymbols;
66
import gwt.material.design.client.base.MaterialWidget;
7+
import gwt.material.design.client.base.mixin.ColorsMixin;
78
import gwt.material.design.client.base.mixin.CssNameMixin;
9+
import gwt.material.design.client.constants.Color;
810
import gwt.material.design.client.constants.SymbolType;
911
import gwt.material.design.client.ui.html.Span;
1012

1113
public class MaterialSymbol extends MaterialWidget implements HasSymbols {
1214

13-
static {
14-
LinkElement linkElement = Document.get().createLinkElement();
15-
linkElement.setRel("stylesheet");
16-
linkElement.setHref("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200");
17-
body().append(linkElement);
18-
}
19-
2015
protected Span span = new Span();
16+
protected static LinkElement linkElement = Document.get().createLinkElement();
2117
protected CssNameMixin<Span, SymbolType> symbolTypeMixin;
18+
protected ColorsMixin<MaterialSymbol> symbolColorsMixin;
2219
protected boolean filled;
2320
protected int weight = 400;
2421
protected int grade = 0;
2522
protected int opticalSize = 48;
2623

24+
static {
25+
linkElement.setRel("stylesheet");
26+
body().append(linkElement);
27+
}
28+
2729
public MaterialSymbol() {
2830
super(Document.get().createElement("div"));
2931
setType(SymbolType.OUTLINED);
@@ -42,9 +44,20 @@ public void setSymbol(String symbol) {
4244
span.getElement().setInnerText(symbol);
4345
}
4446

47+
@Override
48+
public void setColor(Color color) {
49+
getSymbolColorsMixin().setTextColor(color);
50+
}
51+
52+
@Override
53+
public void setSymbolSize(String size) {
54+
span.getElement().getStyle().setProperty("fontSize", size);
55+
}
56+
4557
@Override
4658
public void setType(SymbolType type) {
4759
getSymbolTypeMixin().setCssName(type);
60+
linkElement.setHref(type.getCssLink());
4861
}
4962

5063
@Override
@@ -68,7 +81,14 @@ public void setOpticalSize(int size) {
6881
}
6982

7083
protected void load() {
71-
getElement().setAttribute("style", "font-variation-settings: 'FILL' 1, 'wght' 700, 'GRAD' 0, 'opsz' 48;");
84+
span.getElement().getStyle().setProperty("fontVariationSettings", "'FILL' " + (filled ? 1 : 0) + ", 'wght' " + weight + ", 'GRAD' " + grade + ", 'opsz' " + opticalSize);
85+
}
86+
87+
public ColorsMixin<MaterialSymbol> getSymbolColorsMixin() {
88+
if (symbolColorsMixin == null) {
89+
symbolColorsMixin = new ColorsMixin<>(this);
90+
}
91+
return symbolColorsMixin;
7292
}
7393

7494
public CssNameMixin<Span, SymbolType> getSymbolTypeMixin() {

0 commit comments

Comments
 (0)