-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor: Component based PHP rendering #673
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
Open
abhishekxix
wants to merge
16
commits into
theme-elementary-v2
Choose a base branch
from
refactor/component-based-php-rendering
base: theme-elementary-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dc092e3
Add Component based rendering with priority
abhishekxix fd4b542
Add output buffered get static method
abhishekxix c60aa58
Add convenience wrapper for get method
abhishekxix 4512e3a
Fix global variable prefix phpcs error
abhishekxix 223b9ab
Fix WP global phpcs errors
abhishekxix 961f624
Fix short ternary error
abhishekxix 18b7098
Address feedback
abhishekxix 8641cd9
Merge branch 'theme-elementary-v2' into refactor/component-based-php-…
Adi-ty 9b3ae81
feat: add enqueue assets filter and action that can be reused.
bhavz-10 a4feb94
feat: add assets enqeue by default for the components
bhavz-10 beb73b1
feat: optimize, add cache loader for storing the paths statically
bhavz-10 95e33c4
feat: add theme and plugin component functions for assets and php par…
bhavz-10 28da679
feat: add js, scss and configure webpack
bhavz-10 333b541
feat: add card css
bhavz-10 fb50d2c
Update component source path casing
bhavz-10 e3384fd
Lowercase component source files
bhavz-10 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,9 @@ | ||
| /** | ||
| * Button component script. | ||
| */ | ||
| document.addEventListener('DOMContentLoaded', () => { | ||
| const buttons = document.querySelectorAll('.elementary-button'); | ||
| if (buttons.length > 0) { | ||
| console.log(`Elementary Button component loaded. Found ${buttons.length} buttons.`); | ||
| } | ||
| }); |
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,43 @@ | ||
| <?php | ||
| /** | ||
| * Button component. | ||
| * | ||
| * A render-only component that outputs a button or link element. | ||
| * | ||
| * @package rtCamp\Theme\Elementary | ||
| * | ||
| * @param array $args { | ||
| * Component arguments. | ||
| * | ||
| * @type string $label Button label text. Required. | ||
| * @type string $url URL for link buttons. Optional. | ||
| * @type string $class Additional CSS classes. Optional. | ||
| * @type string $tag HTML tag: 'a' or 'button'. Optional. Defaults to 'a' when $url is set, 'button' otherwise. | ||
| * } | ||
| */ | ||
|
|
||
| $label = $args['label'] ?? ''; | ||
| $url = $args['url'] ?? ''; | ||
| $class = $args['class'] ?? ''; | ||
| $tag = $args['tag'] ?? ( ! empty( $url ) ? 'a' : 'button' ); | ||
|
|
||
| if ( empty( $label ) ) { | ||
| return; | ||
| } | ||
|
|
||
| $css_class = trim( 'elementary-button ' . $class ); | ||
|
|
||
| if ( 'a' === $tag && ! empty( $url ) ) { | ||
| printf( | ||
| '<a href="%s" class="%s">%s</a>', | ||
| esc_url( $url ), | ||
| esc_attr( $css_class ), | ||
| esc_html( $label ) | ||
| ); | ||
| } else { | ||
| printf( | ||
| '<button type="button" class="%s">%s</button>', | ||
| esc_attr( $css_class ), | ||
| esc_html( $label ) | ||
| ); | ||
| } |
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,23 @@ | ||
| .elementary-button { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| padding: 0.75rem 1.5rem; | ||
| font-size: 1rem; | ||
| font-weight: 500; | ||
| line-height: 1.5; | ||
| color: #fff; | ||
| background-color: #0073aa; | ||
| border: 1px solid transparent; | ||
| border-radius: 4px; | ||
| text-decoration: none; | ||
| cursor: pointer; | ||
| transition: background-color 0.2s ease-in-out; | ||
|
|
||
| &:hover, | ||
| &:focus { | ||
| background-color: #005177; | ||
| text-decoration: none; | ||
| color: #fff; | ||
| } | ||
| } |
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,9 @@ | ||
| /** | ||
| * Card component script. | ||
| */ | ||
| document.addEventListener('DOMContentLoaded', () => { | ||
| const cards = document.querySelectorAll('.elementary-card'); | ||
| if (cards.length > 0) { | ||
| console.log(`Elementary Card component loaded. Found ${cards.length} cards.`); | ||
| } | ||
| }); |
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,63 @@ | ||
| <?php | ||
| /** | ||
| * Card component. | ||
| * | ||
| * A render-only component that outputs a card with optional image, title, | ||
| * description, and action button. Demonstrates component composability | ||
| * by rendering the Button component internally. | ||
| * | ||
| * @package rtCamp\Theme\Elementary | ||
| * | ||
| * @param array $args { | ||
| * Component arguments. | ||
| * | ||
| * @type string $title Card title. Required. | ||
| * @type string $description Card description text. Optional. | ||
| * @type string $image_url Card image URL. Optional. | ||
| * @type string $url Card link URL. Optional. | ||
| * } | ||
| */ | ||
|
|
||
| use rtCamp\Theme\Elementary\Framework\ComponentLoader; | ||
|
|
||
| $title = $args['title'] ?? ''; | ||
| $description = $args['description'] ?? ''; | ||
| $image_url = $args['image_url'] ?? ''; | ||
| $url = $args['url'] ?? ''; | ||
|
|
||
| if ( empty( $title ) ) { | ||
| return; | ||
| } | ||
|
|
||
| ?> | ||
| <div class="elementary-card"> | ||
| <?php if ( ! empty( $image_url ) ) : ?> | ||
| <div class="elementary-card__image"> | ||
| <img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $title ); ?>" /> | ||
| </div> | ||
| <?php endif; ?> | ||
|
|
||
| <div class="elementary-card__content"> | ||
| <h3 class="elementary-card__title"><?php echo esc_html( $title ); ?></h3> | ||
|
|
||
| <?php if ( ! empty( $description ) ) : ?> | ||
| <p class="elementary-card__description"><?php echo esc_html( $description ); ?></p> | ||
| <?php endif; ?> | ||
|
|
||
| <?php if ( ! empty( $url ) ) : ?> | ||
| <div class="elementary-card__action"> | ||
| <?php | ||
| ComponentLoader::render( | ||
| 'Button', | ||
| [ | ||
| 'label' => $title, | ||
| 'url' => $url, | ||
| 'class' => 'elementary-card__button', | ||
| ] | ||
| ); | ||
| ?> | ||
| </div> | ||
| <?php endif; ?> | ||
| </div> | ||
| </div> | ||
| <?php |
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,53 @@ | ||
| .elementary-card { | ||
| display: flex; | ||
| flex-direction: column; | ||
| background-color: #fff; | ||
| border: 1px solid #e2e8f0; | ||
| border-radius: 8px; | ||
| overflow: hidden; | ||
| box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); | ||
| transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; | ||
|
|
||
| &:hover { | ||
| transform: translateY(-4px); | ||
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); | ||
| } | ||
|
|
||
| &__image { | ||
| width: 100%; | ||
| height: 200px; | ||
| overflow: hidden; | ||
|
|
||
| img { | ||
| width: 100%; | ||
| height: 100%; | ||
| object-fit: cover; | ||
| } | ||
| } | ||
|
|
||
| &__content { | ||
| padding: 1.5rem; | ||
| display: flex; | ||
| flex-direction: column; | ||
| flex-grow: 1; | ||
| } | ||
|
|
||
| &__title { | ||
| font-size: 1.25rem; | ||
| font-weight: 600; | ||
| margin: 0 0 0.75rem; | ||
| color: #1a202c; | ||
| } | ||
|
|
||
| &__description { | ||
| font-size: 1rem; | ||
| color: #4a5568; | ||
| margin: 0 0 1.5rem; | ||
| line-height: 1.5; | ||
| flex-grow: 1; | ||
| } | ||
|
|
||
| &__action { | ||
| margin-top: auto; | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.