Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix #77: added Panel component #148

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

Merged
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
2 changes: 2 additions & 0 deletions src/main/java/org/patternfly/component/ComponentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public enum ComponentType {

Pagination("pgn", null),

Panel("pnl", "PF5/Panel"),

Popover("pvr", "PF5/Popover"),

Radio("rd", "PF5/Radio"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/patternfly/component/SubComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected <C extends BaseComponent<E1, B1>, E1 extends HTMLElement, B1 extends T

protected <C extends BaseComponent<E1, B1>, E1 extends HTMLElement, B1 extends TypedBuilder<E1, B1>> C lookupComponent(
boolean lenient) {
return ComponentStore.lookup(componentType, element, false);
return ComponentStore.lookup(componentType, element, lenient);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed this one during random code reading - hope the fix as part of this commit is fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

}

protected <S extends SubComponent<E2, B2>, E2 extends HTMLElement, B2 extends TypedBuilder<E2, B2>> S lookupSubComponent(
Expand Down
132 changes: 132 additions & 0 deletions src/main/java/org/patternfly/component/panel/Panel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright 2023 Red Hat
*
* 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
*
* https://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 org.patternfly.component.panel;

import org.patternfly.component.BaseComponentFlat;
import org.patternfly.component.ComponentType;

import elemental2.dom.HTMLDivElement;
import org.patternfly.core.Logger;

import static org.jboss.elemento.Elements.div;
import static org.jboss.elemento.Elements.hr;
import static org.patternfly.component.panel.PanelMain.panelMain;
import static org.patternfly.component.panel.PanelFooter.panelFooter;
import static org.patternfly.component.panel.PanelHeader.panelHeader;
import static org.patternfly.core.Aria.labelledBy;
import static org.patternfly.style.Classes.*;

/**
* The panel component is a container that supports flexible content layouts. It can be used to house other components
* such as fields, forms, videos, buttons, and more. The panel should not be confused with the drawer component,
* which allows you to surface information via a collapsable container.
*
* @see <a href= "https://www.patternfly.org/components/panel">https://www.patternfly.org/components/panel</a>
*/
public class Panel extends BaseComponentFlat<HTMLDivElement, Panel> {

// ------------------------------------------------------ factory

public static Panel panel() {
return new Panel();
}

public Panel raised() {
return css(modifier(raised));
}

public Panel bordered() {
return css(modifier(bordered));
}

public Panel scrollable() {
return css(modifier(scrollable));
}

// ------------------------------------------------------ instance
private PanelHeader header;
private PanelMain main;
private PanelFooter footer;

protected Panel() {
super(ComponentType.Panel, div().css(component(panel)).element());
}

// ------------------------------------------------------ add

public Panel addHeader(String header) {
return add(panelHeader().textContent(header));
}

public Panel addHeader(PanelHeader header) {
return add(header);
}

public Panel add(PanelHeader header) {
if (this.header != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should throw an exception here. I prefer not adding a second header and log an error/warning. Something like Logger.unsupported(ComponentType, Element, String). Same for body and footer.

Logger.unsupported(ComponentType.Panel, this.header.element(), "header already added");
}
this.header = header;
aria(labelledBy, header.headerId);
return this;
}

public Panel addDivider() {
element().appendChild(hr().css(divider).element());
return this;
}

public Panel addMain(String main) {
return add(panelMain().textContent(main));
}

public Panel addMain(PanelMain main) {
return add(main);
}

public Panel add(PanelMain main) {
if (this.main != null) {
Logger.unsupported(ComponentType.Panel, this.main.element(), "main already added");
}
this.main = main;
element().appendChild(main.element());
return this;
}

public Panel addFooter(String footer) {
return add(panelFooter().textContent(footer));
}

public Panel addFooter(PanelFooter footer) {
return add(footer);
}

public Panel add(PanelFooter footer) {
if (this.footer != null) {
Logger.unsupported(ComponentType.Panel, this.footer.element(), "footer already added");
}
this.footer = footer;
element().appendChild(footer.element());
return this;
}

// ------------------------------------------------------ builder

@Override
public Panel that() {
return this;
}
}
45 changes: 45 additions & 0 deletions src/main/java/org/patternfly/component/panel/PanelFooter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023 Red Hat
*
* 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
*
* https://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 org.patternfly.component.panel;

import elemental2.dom.HTMLDivElement;

import static org.jboss.elemento.Elements.div;
import static org.patternfly.style.Classes.*;

public class PanelFooter extends PanelSubComponent<HTMLDivElement, PanelFooter> {

// ------------------------------------------------------ factory

public static PanelFooter panelFooter() {
return new PanelFooter();
}

// ------------------------------------------------------ instance

static final String SUB_COMPONENT_NAME = "pf";

PanelFooter() {
super(SUB_COMPONENT_NAME, div().css(component(panel, footer)).element());
}

// ------------------------------------------------------ builder

@Override
public PanelFooter that() {
return this;
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/patternfly/component/panel/PanelHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2023 Red Hat
*
* 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
*
* https://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 org.patternfly.component.panel;

import org.jboss.elemento.Id;
import org.patternfly.component.ComponentType;

import elemental2.dom.HTMLDivElement;

import static org.jboss.elemento.Elements.div;
import static org.patternfly.style.Classes.*;

public class PanelHeader extends PanelSubComponent<HTMLDivElement, PanelHeader> {

// ------------------------------------------------------ factory

public static PanelHeader panelHeader() {
return new PanelHeader();
}

// ------------------------------------------------------ instance

static final String SUB_COMPONENT_NAME = "ph";

final String headerId;

PanelHeader() {
super(SUB_COMPONENT_NAME, div().css(component(panel, header)).element());
headerId = Id.unique(ComponentType.Panel.id, header);
element().id = headerId;
}

// ------------------------------------------------------ builder

@Override
public PanelHeader that() {
return this;
}
}
58 changes: 58 additions & 0 deletions src/main/java/org/patternfly/component/panel/PanelMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2023 Red Hat
*
* 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
*
* https://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 org.patternfly.component.panel;

import org.patternfly.core.ElementDelegate;

import elemental2.dom.HTMLDivElement;
import elemental2.dom.HTMLElement;

import static org.jboss.elemento.Elements.*;
import static org.patternfly.style.Classes.*;
import static org.patternfly.style.Classes.main;

public class PanelMain extends PanelSubComponent<HTMLElement, PanelMain>
implements ElementDelegate<HTMLElement, PanelMain> {

// ------------------------------------------------------ factory

public static PanelMain panelMain() {
return new PanelMain();
}

// ------------------------------------------------------ instance

static final String SUB_COMPONENT_NAME = "pm";
final HTMLDivElement bodyElement;

PanelMain() {
super(SUB_COMPONENT_NAME, div().css(component(panel, main)).element());
element().appendChild(bodyElement = div().css(component(panel, main, body))
.element());
}

@Override
public HTMLElement delegate() {
return bodyElement;
}

// ------------------------------------------------------ builder

@Override
public PanelMain that() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2023 Red Hat
*
* 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
*
* https://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 org.patternfly.component.panel;

import org.jboss.elemento.TypedBuilder;
import org.patternfly.component.ComponentType;
import org.patternfly.component.SubComponent;

import elemental2.dom.HTMLElement;

abstract class PanelSubComponent<E extends HTMLElement, B extends TypedBuilder<E, B>> extends SubComponent<E, B> {

PanelSubComponent(String name, E element) {
super(ComponentType.Panel, name, element);
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/patternfly/style/Classes.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public interface Classes {
String page = "page";
String pageInsets = "page-insets";
String pagination = "pagination";
String panel = "panel";
String path = "path";
String picture = "picture";
String plain = "plain";
Expand All @@ -195,6 +196,7 @@ public interface Classes {
String progress = "progress";
String progressbar = "progressbar";
String radio = "radio";
String raised = "raised";
String read = "read";
String readOnly = "read-only";
String readonly = "readonly";
Expand Down