FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

PredefinedIcon.predefinedIcon(String iconName) · patternfly-java/patternfly-java@01c4bf8 · GitHub

Commit 01c4bf8

Browse files
committed
PredefinedIcon.predefinedIcon(String iconName)
1 parent 7334a71 commit 01c4bf8

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Add `PredefinedIcon.predefinedIcon(String iconName)`
12+
913
## [0.4.2] - 2025-12-17
1014

1115
### Added

‎icons/src/main/java/org/patternfly/icon/PredefinedIcon.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ public final class PredefinedIcon implements
4949
SVGElementDataMethods<SVGElement, PredefinedIcon>,
5050
SVGElementStyleMethods<SVGElement, PredefinedIcon> {
5151

52+
// ------------------------------------------------------ factory
53+
54+
/**
55+
* Constructs a predefined SVG icon based on the provided icon name. The method supports multiple icon groups, such as
56+
* "fab", "far", "fas", and "patternfly". If the name contains a group prefix (e.g., "fab.iconName"), the method will use
57+
* that group; otherwise, it defaults to the "fas" group.
58+
* <p>
59+
* Normally you should use the static methods from {@link IconSets} to get predefined icons. Only use this method if you
60+
* need to get an icon based on the icon name provided as string.
61+
*
62+
* @param name the name of the icon, optionally prefixed with the group name (e.g., "fab.iconName"). If no group is
63+
* specified, "fas" is used by default.
64+
* @return a {@code PredefinedIcon} instance representing the specified icon.
65+
* @throws IllegalArgumentException if the group or icon name is unknown.
66+
*/
67+
public static PredefinedIcon predefinedIcon(String name) {
68+
String group = "fas";
69+
String iconName = name;
70+
if (name.contains(".")) {
71+
group = name.substring(0, name.indexOf('.'));
72+
iconName = name.substring(name.indexOf('.') + 1);
73+
}
74+
IconSpec iconSpec = switch (group) {
75+
case "fab" -> IconSpecs.fab.valueOf(iconName).iconSpec;
76+
case "far" -> IconSpecs.far.valueOf(iconName).iconSpec;
77+
case "fas" -> IconSpecs.fas.valueOf(iconName).iconSpec;
78+
case "patternfly" -> IconSpecs.patternfly.valueOf(iconName).iconSpec;
79+
default -> throw new IllegalArgumentException("Unknown icon group/name: '" + name + "'");
80+
};
81+
return new PredefinedIcon(iconSpec);
82+
}
83+
84+
// ------------------------------------------------------ instance
85+
5286
public final IconSpec iconSpec;
5387
private final SVGElement element;
5488

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL