-
Notifications
You must be signed in to change notification settings - Fork 4
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
hpehl
merged 6 commits into
patternfly-java:main
from
halkosajtarevic:features/add-panel-compoent
Jan 9, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb3084c
Fix #77: added Panel component
halkosajtarevic 54e231f
Merge branch 'main' into features/add-panel-compoent
hpehl af541c3
Merge branch 'main' into features/add-panel-compoent
hpehl e859f6a
Merge branch 'patternfly-java:main' into features/add-panel-compoent
halkosajtarevic 6900755
Fix #77: addressed comments
halkosajtarevic 739566a
Merge branch 'main' into features/add-panel-compoent
hpehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
132 changes: 132 additions & 0 deletions
132
src/main/java/org/patternfly/component/panel/Panel.java
This file contains hidden or 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,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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.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
45
src/main/java/org/patternfly/component/panel/PanelFooter.java
This file contains hidden or 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,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
52
src/main/java/org/patternfly/component/panel/PanelHeader.java
This file contains hidden or 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,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
58
src/main/java/org/patternfly/component/panel/PanelMain.java
This file contains hidden or 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,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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/patternfly/component/panel/PanelSubComponent.java
This file contains hidden or 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,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); | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!