Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wos 185 title with subtitle #188

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public class TitleComponent {
private String text;

@Inject
@Getter
@Default(values = "title")
private String type;
private String subtitle;

@Inject
@Getter
Expand All @@ -50,6 +48,11 @@ public class TitleComponent {
@Default(booleanValues = false)
private boolean isSpaced;

@Inject
@Getter
@Default(booleanValues = false)
private boolean addSubtitle;

@Inject
@Getter
@Default(values = StringUtils.EMPTY)
Expand All @@ -59,16 +62,33 @@ public class TitleComponent {
@Getter
private String[] titleClasses;

@Inject
@Getter
private String[] subtitleClasses;

@PostConstruct
private void init() {
List<String> classes = new ArrayList<>();
classes.add(type);
List<String> titleClassList = new ArrayList<>();
List<String> subtitleClassList = new ArrayList<>();
titleClassList.add("title");
subtitleClassList.add("subtitle");

if (StringUtils.isNotBlank(size)) {
classes.add(size);
titleClassList.add(size);
int sizeNumber = Integer.parseInt(size.split("-")[1]);
if (sizeNumber > 4) {
addSubtitle = false;
}
subtitleClassList.add("is-" + (sizeNumber + 2));
}
if (isSpaced) {
classes.add("is-spaced");
titleClassList.add("is-spaced");
}
titleClasses = classes.toArray(new String[]{});
titleClasses = titleClassList.toArray(new String[]{});
subtitleClasses = subtitleClassList.toArray(new String[]{});
}

public String getSubtitle() {
return addSubtitle ? subtitle : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@
"generalTab": {
"sling:resourceType": "wcm/dialogs/components/tab",
"label": "General",
"type": {
"sling:resourceType": "wcm/dialogs/components/radio",
"name": "type",
"label": "Type",
"required": true,
"title": {
"sling:resourceType": "wcm/dialogs/components/radio/option",
"label": "Title",
"value": "title",
"selected": true
},
"subtitle": {
"sling:resourceType": "wcm/dialogs/components/radio/option",
"label": "Subtitle",
"value": "subtitle"
}
},
"text": {
"sling:resourceType": "wcm/dialogs/components/textfield",
"name": "text",
Expand All @@ -38,14 +21,37 @@
"name": "element"
}
},
"isSpaced": {
"sling:resourceType": "wcm/dialogs/components/checkbox",
"name": "isSpaced",
"label": "Normal spacing between title and subtitle",
"subtitleOptionsContainer": {
"sling:resourceType": "wcm/dialogs/components/container",
"addSubtitle": {
"sling:resourceType": "wcm/dialogs/components/toggle",
"name": "addSubtitle",
"label": "Add a subtitle"
},
"subtitleContainer": {
"sling:resourceType": "wcm/dialogs/components/container",
"subtitle": {
"sling:resourceType": "wcm/dialogs/components/textfield",
"name": "subtitle",
"label": "Subtitle text",
"description": "A subtitle can be defined if the size of the title is 4 or bigger"
},
"isSpaced": {
"sling:resourceType": "wcm/dialogs/components/checkbox",
"name": "isSpaced",
"label": "Additional space between the title and subtitle"
},
"ws:display": {
"condition": {
"sourceName": "addSubtitle",
"values": "true"
}
}
},
"ws:display": {
"condition": {
"sourceName": "type",
"values": "title"
"sourceName": "size",
"values": ["is-1", "is-2", "is-3", "is-4"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"jcr:primaryType": "nt:unstructured",
"size": "is-2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
<h1 data-sly-element="${model.element}" class="${model.titleClasses @ join=' '}">
${model.text}
</h1>
<sly data-sly-test="${model.addSubtitle}">
<h1 data-sly-element="${model.element}" class="${model.subtitleClasses @ join=' '}">
${model.subtitle}
</h1>
</sly>
</sly>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void defaultTitleComponentModelTest() {

assertThat(model).isNotNull();
assertThat(model.getText()).isEqualTo("Title");
assertThat(model.getType()).isEqualTo("title");
assertThat(model.getElement()).isEqualTo("h2");
assertThat(model.getTitleClasses()).containsExactlyInAnyOrder("title");
assertThat(model.getSize()).isEmpty();
Expand All @@ -60,9 +59,9 @@ void titleComponentModelTest() {

assertThat(model).isNotNull();
assertThat(model.getText()).isEqualTo("Nice subtitle");
assertThat(model.getType()).isEqualTo("subtitle");
assertThat(model.getElement()).isEqualTo("p");
assertThat(model.getTitleClasses()).containsExactlyInAnyOrder("subtitle", "is-2", "is-spaced");
assertThat(model.getTitleClasses()).containsExactlyInAnyOrder("title", "is-2", "is-spaced");
assertThat(model.getSubtitleClasses()).containsExactlyInAnyOrder("subtitle", "is-4");
assertThat(model.getSize()).isEqualTo("is-2");
assertThat(model.isSpaced()).isTrue();
}
Expand Down
3 changes: 2 additions & 1 deletion application/backend/src/test/resources/title.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "bulma/components/title",
"text": "Nice subtitle",
"type": "subtitle",
"subtitle": "Nice subtitle",
"addSubtitle": true,
"element": "p",
"size": "is-2",
"isSpaced": true
Expand Down