-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KYAN-306 Add Accordion Component (#512)
* KYAN-306 Add Accordion Component * KYAN-306 Add Accordion Component * KYAN-306 Add Accordion Component Refactor * KYAN-306 Add Accordion Component Added tests * KYAN-306 Add Accordion Component Refactor tests
- Loading branch information
1 parent
ced6367
commit ceb771f
Showing
17 changed files
with
526 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...mmon/backend/src/main/java/pl/ds/kyanite/common/components/models/AccordionComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2025 Dynamic Solutions | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pl.ds.kyanite.common.components.models; | ||
|
||
import static org.apache.sling.models.annotations.DefaultInjectionStrategy.OPTIONAL; | ||
import static pl.ds.kyanite.common.components.utils.SlingUtils.SLING_RESOURCE_TYPE; | ||
|
||
import java.util.List; | ||
import java.util.stream.StreamSupport; | ||
import lombok.Getter; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.ChildResource; | ||
import org.apache.sling.models.annotations.injectorspecific.SlingObject; | ||
|
||
@Model(adaptables = Resource.class, defaultInjectionStrategy = OPTIONAL) | ||
public class AccordionComponent { | ||
|
||
public static final String ACCORDION_ITEM_RESOURCE_TYPE | ||
= "kyanite/common/components/accordion/accordionitem"; | ||
|
||
@SlingObject | ||
private Resource resource; | ||
|
||
@ChildResource | ||
@Getter | ||
private List<AccordionItemComponent> elements; | ||
|
||
public List<Resource> getChildrenComponents() { | ||
return StreamSupport | ||
.stream(resource.getChildren() | ||
.spliterator(), false) | ||
.filter(it -> | ||
ACCORDION_ITEM_RESOURCE_TYPE.equals(it.getValueMap() | ||
.get(SLING_RESOURCE_TYPE))) | ||
.toList(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
.../backend/src/main/java/pl/ds/kyanite/common/components/models/AccordionItemComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2025 Dynamic Solutions | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pl.ds.kyanite.common.components.models; | ||
|
||
import static org.apache.sling.models.annotations.DefaultInjectionStrategy.OPTIONAL; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.annotation.PostConstruct; | ||
import lombok.Getter; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.models.annotations.Default; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
|
||
@Model(adaptables = Resource.class, defaultInjectionStrategy = OPTIONAL) | ||
public class AccordionItemComponent { | ||
|
||
@Getter | ||
@ValueMapValue | ||
@Default(values = "Accordion item title") | ||
private String title; | ||
|
||
@ValueMapValue | ||
@Getter | ||
private String size; | ||
|
||
@Getter | ||
private List<String> classList = new ArrayList<>(); | ||
|
||
@PostConstruct | ||
private void init() { | ||
if (StringUtils.isNotBlank(size)) { | ||
classList.add(size); | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
.../common/backend/src/main/resources/libs/kyanite/common/components/accordion/.content.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"isContainer": true, | ||
"group": "Kyanite Components", | ||
"allowedComponents": [ | ||
"/apps/kyanite/common/components/accordion/accordionitem", | ||
"/libs/kyanite/common/components/accordion/accordionitem" | ||
], | ||
"sling:resourceType": "ws:Component", | ||
"title": "Accordion" | ||
} |
33 changes: 33 additions & 0 deletions
33
...common/backend/src/main/resources/libs/kyanite/common/components/accordion/accordion.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!--/* | ||
Copyright (C) 2025 Dynamic Solutions | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/--> | ||
<sly data-sly-use.model="pl.ds.kyanite.common.components.models.AccordionComponent"> | ||
<sly data-sly-set.cssClasses="accordion"></sly> | ||
<div class="${cssClasses}"> | ||
<div data-sly-test="${resource.hasChildren}"> | ||
<ul> | ||
<sly data-sly-list.cell="${model.childrenComponents}"> | ||
<sly data-sly-resource="${cell}"></sly> | ||
</sly> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<sly data-sly-test="${!resource.hasChildren}"> | ||
<sly data-sly-use.lib="/libs/wcm/foundation/components/commons/templates.html" | ||
data-sly-call="${lib.placeholder @ classes=cssClasses}"> | ||
</sly> | ||
</sly> | ||
</sly> |
14 changes: 14 additions & 0 deletions
14
...d/src/main/resources/libs/kyanite/common/components/accordion/accordionitem/.content.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"group": "Kyanite sub-elements", | ||
"isContainer": true, | ||
"sling:resourceType": "ws:Component", | ||
"allowedComponents": [ | ||
"Kyanite Columns", | ||
"Kyanite Components", | ||
"Kyanite Elements", | ||
"Kyanite Layouts", | ||
"Kyanite In-Text Sections", | ||
"Kyanite Accordion" | ||
], | ||
"title": "Accordion Item" | ||
} |
36 changes: 36 additions & 0 deletions
36
.../main/resources/libs/kyanite/common/components/accordion/accordionitem/accordionitem.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!--/* | ||
Copyright (C) 2025 Dynamic Solutions | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/--> | ||
<sly data-sly-use.model="pl.ds.kyanite.common.components.models.AccordionItemComponent"> | ||
<sly data-sly-test="${resource.hasChildren}"> | ||
<li class="accordion-item ${wcmmode.isEdit ? 'opened' : ''}"> | ||
<button aria-expanded="false" class="accordion-item__title title ${model.classList @ join=' '}"> | ||
${model.title} | ||
<i class="mdi mdi-chevron-down mdi-36px"></i> | ||
</button> | ||
<div role="region" class="accordion-item__content"> | ||
<sly data-sly-list="${resource.children}"> | ||
<sly data-sly-resource="${item}"></sly> | ||
</sly> | ||
</div> | ||
</li> | ||
</sly> | ||
<sly data-sly-test="${!resource.hasChildren}"> | ||
<sly | ||
data-sly-use.lib="/libs/wcm/foundation/components/commons/templates.html" | ||
data-sly-call="${lib.placeholder @ classes=classes}"> | ||
</sly> | ||
</sly> | ||
</sly> |
19 changes: 19 additions & 0 deletions
19
...ain/resources/libs/kyanite/common/components/accordion/accordionitem/dialog/.content.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"sling:resourceType": "wcm/dialogs/dialog", | ||
"tabs": { | ||
"sling:resourceType": "wcm/dialogs/components/tabs", | ||
"generalTab": { | ||
"sling:resourceType": "wcm/dialogs/components/tab", | ||
"label": "General", | ||
"title": { | ||
"sling:resourceType": "wcm/dialogs/components/textfield", | ||
"name": "title", | ||
"label": "Title" | ||
}, | ||
"size": { | ||
"sling:resourceType": "wcm/dialogs/components/include", | ||
"path": "/libs/kyanite/common/components/common/issize" | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...n/resources/libs/kyanite/common/components/accordion/accordionitem/template/.content.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jcr:primaryType": "nt:unstructured", | ||
"sling:resourceType": "kyanite/common/components/accordion/accordionitem", | ||
"size": "is-4" | ||
} |
42 changes: 42 additions & 0 deletions
42
...ackend/src/main/resources/libs/kyanite/common/components/accordion/template/.content.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"jcr:primaryType": "nt:unstructured", | ||
"cell_1": { | ||
"title": "Title", | ||
"size": "is-4", | ||
"jcr:primaryType": "nt:unstructured", | ||
"sling:resourceType": "kyanite/common/components/accordion/accordionitem", | ||
"content": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"size": "is-normal", | ||
"text": "\u003Cp\u003ELorem ipsum dolor sit amet, consectetur adipiscing elit.\u003C/p\u003E", | ||
"sling:resourceType": "kyanite/common/components/content", | ||
"textWeight": "has-text-weight-normal" | ||
} | ||
}, | ||
"cell_2": { | ||
"title": "Title", | ||
"size": "is-4", | ||
"jcr:primaryType": "nt:unstructured", | ||
"sling:resourceType": "kyanite/common/components/accordion/accordionitem", | ||
"content": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"size": "is-normal", | ||
"text": "\u003Cp\u003ELorem ipsum dolor sit amet, consectetur adipiscing elit.\u003C/p\u003E", | ||
"sling:resourceType": "kyanite/common/components/content", | ||
"textWeight": "has-text-weight-normal" | ||
} | ||
}, | ||
"cell_3": { | ||
"title": "Title", | ||
"size": "is-4", | ||
"jcr:primaryType": "nt:unstructured", | ||
"sling:resourceType": "kyanite/common/components/accordion/accordionitem", | ||
"content": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"size": "is-normal", | ||
"text": "\u003Cp\u003ELorem ipsum dolor sit amet, consectetur adipiscing elit.\u003C/p\u003E", | ||
"sling:resourceType": "kyanite/common/components/content", | ||
"textWeight": "has-text-weight-normal" | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
.../backend/src/test/java/pl/ds/kyanite/common/components/models/AccordionComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2025 Dynamic Solutions | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pl.ds.kyanite.common.components.models; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.testing.mock.sling.ResourceResolverType; | ||
import org.apache.sling.testing.mock.sling.junit5.SlingContext; | ||
import org.apache.sling.testing.mock.sling.junit5.SlingContextExtension; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@ExtendWith(SlingContextExtension.class) | ||
public class AccordionComponentTest { | ||
|
||
private static final String PATH = "/content/accordion"; | ||
public static final String IS_5 = "is-5"; | ||
|
||
private final SlingContext context = new SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK); | ||
|
||
@BeforeEach | ||
public void init() { | ||
context.addModelsForClasses(AccordionComponent.class); | ||
context.addModelsForClasses(AccordionItemComponent.class); | ||
context.addModelsForClasses(ContentComponent.class); | ||
context.load().json(requireNonNull( | ||
Thread.currentThread().getContextClassLoader().getResourceAsStream("accordion.json")), PATH); | ||
} | ||
|
||
@Test | ||
void defaultAccordionComponentModelTest() { | ||
AccordionComponent model = context.resourceResolver().getResource(PATH + "/default") | ||
.adaptTo(AccordionComponent.class); | ||
assertThat(model).isNotNull(); | ||
List<Resource> childrenComponents = model.getChildrenComponents(); | ||
assertThat(childrenComponents).hasSize(2); | ||
AccordionItemComponent accordionItemComponent = childrenComponents.get(1).adaptTo(AccordionItemComponent.class); | ||
assertThat(accordionItemComponent).isNotNull(); | ||
assertThat(accordionItemComponent.getClassList()).containsExactly(IS_5); | ||
assertThat(accordionItemComponent.getSize()).isEqualTo(IS_5); | ||
assertThat(accordionItemComponent.getTitle()).isEqualTo("Title2"); | ||
Resource content = childrenComponents.get(0).getChild("content"); | ||
ContentComponent contentComponent = content.adaptTo(ContentComponent.class); | ||
assertThat(contentComponent.getText()).isEqualTo("<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
applications/common/backend/src/test/resources/accordion.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"default": { | ||
"sling:resourceType": "kyanite/common/components/accordion", | ||
"jcr:primaryType": "nt:unstructured", | ||
"cell_1": { | ||
"sling:resourceType": "kyanite/common/components/accordion/accordionitem", | ||
"jcr:primaryType": "nt:unstructured", | ||
"size": "is-4", | ||
"title": "Title", | ||
"content": { | ||
"sling:resourceType": "kyanite/common/components/content", | ||
"jcr:primaryType": "nt:unstructured", | ||
"size": "is-normal", | ||
"text": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>", | ||
"textWeight": "has-text-weight-normal" | ||
} | ||
}, | ||
"cell_2": { | ||
"sling:resourceType": "kyanite/common/components/accordion/accordionitem", | ||
"jcr:primaryType": "nt:unstructured", | ||
"size": "is-5", | ||
"title": "Title2", | ||
"content": { | ||
"sling:resourceType": "kyanite/common/components/content", | ||
"jcr:primaryType": "nt:unstructured", | ||
"size": "is-normal", | ||
"text": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit2.</p>", | ||
"textWeight": "has-text-weight-normal" | ||
} | ||
}, | ||
"text": { | ||
"title": "Title2" | ||
} | ||
} | ||
} |
Oops, something went wrong.