Skip to content

Commit eb1f712

Browse files
Initial release. (#1)
1 parent 956399b commit eb1f712

File tree

100 files changed

+13251
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+13251
-60
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Change Log
22

3-
## 0.1.0 Under development
3+
## 0.1.0 March 24, 2024
4+
5+
- Enh #1: Initial release (@terabytesoftw)

README.md

+58-18
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,93 @@
11
<p align="center">
2-
<a href="https://github.com/yii-tools/template" target="_blank">
2+
<a href="https://github.com/ui-awesome/html-core-component" target="_blank">
33
<img src="https://avatars.githubusercontent.com/u/121752654?s=200&v=4" height="100px">
44
</a>
5-
<h1 align="center">Template.</h1>
5+
<h1 align="center">UI Awesome HTML Core Component for PHP.</h1>
66
<br>
77
</p>
88

99
<p align="center">
10-
<a href="https://github.com/yii-tools/template/actions/workflows/build.yml" target="_blank">
11-
<img src="https://github.com/yii-tools/template/actions/workflows/build.yml/badge.svg" alt="PHPUnit">
10+
<a href="https://github.com/ui-awesome/html-core-component/actions/workflows/build.yml" target="_blank">
11+
<img src="https://github.com/ui-awesome/html-core-component/actions/workflows/build.yml/badge.svg" alt="PHPUnit">
1212
</a>
13-
<a href="https://codecov.io/gh/yii-tools/template" target="_blank">
14-
<img src="https://codecov.io/gh/yii-tools/template/branch/main/graph/badge.svg?token=MF0XUGVLYC" alt="Codecov">
13+
<a href="https://codecov.io/gh/ui-awesome/html-core-component" target="_blank">
14+
<img src="https://codecov.io/gh/ui-awesome/html-core-component/branch/main/graph/badge.svg?token=MF0XUGVLYC" alt="Codecov">
1515
</a>
16-
<a href="https://dashboard.stryker-mutator.io/reports/github.com/yii-tools/template/main" target="_blank">
17-
<img src="https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyii2-extensions%2Fasset-bootstrap5%2Fmain" alt="Infection">
16+
<a href="https://dashboard.stryker-mutator.io/reports/github.com/ui-awesome/html-core-component/main" target="_blank">
17+
<img src="https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fui-awesome%2Fhtml-core-component%2Fmain" alt="Infection">
1818
</a>
19-
<a href="https://github.com/yii-tools/template/actions/workflows/static.yml" target="_blank">
20-
<img src="https://github.com/yii-tools/template/actions/workflows/static.yml/badge.svg" alt="Psalm">
19+
<a href="https://github.com/ui-awesome/html-core-component/actions/workflows/static.yml" target="_blank">
20+
<img src="https://github.com/ui-awesome/html-core-component/actions/workflows/static.yml/badge.svg" alt="Psalm">
2121
</a>
22-
<a href="https://shepherd.dev/github/yii-tools/template" target="_blank">
23-
<img src="https://shepherd.dev/github/yii-tools/template/coverage.svg" alt="Psalm Coverage">
22+
<a href="https://shepherd.dev/github/ui-awesome/html-core-component" target="_blank">
23+
<img src="https://shepherd.dev/github/ui-awesome/html-core-component/coverage.svg" alt="Psalm Coverage">
2424
</a>
25-
<a href="https://github.styleci.io/repos/494495136?branch=main" target="_blank">
26-
<img src="https://github.styleci.io/repos/494495136/shield?branch=main" alt="Style ci">
27-
</a>
25+
<a href="https://github.styleci.io/repos/776381948?branch=main">
26+
<img src="https://github.styleci.io/repos/776381948/shield?branch=main" alt="Style ci">
27+
</a>
2828
</p>
2929

30+
These abstract classes serve as foundational building blocks for creating diverse UI components in HTML applications.
31+
32+
They provide a structured approach to developing reusable components with customizable configurations and default
33+
settings.
34+
35+
By extending these classes, you can quickly implement and customize various UI elements, such as breadcrumbs,
36+
dropdowns, navigation bars, and toggles, to enhance your application's user interface.
37+
38+
- AbstractBreadcrumb: Extend this class to implement breadcrumb navigation components. It simplifies the management of
39+
breadcrumb items and offers customizable configurations for rendering breadcrumb elements.
40+
41+
- AbstractDropdown: Extend this class to effortlessly implement dropdown components. It simplifies the management of
42+
menu items and offers customizable configurations for rendering dropdown elements.
43+
44+
- AbstractNavBar: Use this class as a basis for crafting navigation bar components. It provides flexibility in rendering
45+
brand elements, menus, and additional content, with customizable attributes and default configurations.
46+
47+
- AbstractToggle: Extend this class to create toggle components with ease. It supports various types (e.g., button, link)
48+
and offers functionality for rendering toggle elements using customizable templates, attributes, and content.
49+
50+
- Item: This class represents individual items within a menu or breadcrumb. It allows for easy management of item attributes
51+
and content.
52+
53+
- Menu: This class represents a collection of menu items. It facilitates the organization and rendering of menu items within
54+
dropdowns, navigation bars, or other menu-based components.
55+
56+
Simply extend these abstract classes and apply their default configurations to swiftly integrate and customize UI components
57+
tailored to your application's requirements.
58+
3059
## Installation
3160

3261
The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
3362

3463
Either run
3564

3665
```shell
37-
composer require --prefer-dist package
66+
composer require --prefer-dist ui-awesome/html-core-component:^0.1
3867
```
3968

4069
or add
4170

4271
```json
43-
"package": "version"
72+
"ui-awesome/html-core-component": "^0.1"
4473
```
4574

4675
to the require-dev section of your `composer.json` file.
4776

4877
## Usage
4978

50-
[Check the documentation docs](docs/README.md) to learn about usage.
79+
To use the classes in your project, you need to extend them in your custom components.
80+
81+
For example, to create a custom breadcrumb component, you can extend the `AbstractBreadcrumb` class:
82+
83+
```php
84+
use UIAwesome\Html\Core\Component\AbstractBreadcrumb;
85+
86+
class CustomBreadcrumb extends AbstractBreadcrumb
87+
{
88+
// Custom implementation
89+
}
90+
```
5191

5292
## Testing
5393

composer.json

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
{
2-
"name": "yii-tools/template",
2+
"name": "ui-awesome/html-core-component",
33
"type": "library",
4-
"description": "template",
4+
"description": "UI Awesome HTML Core Component for PHP.",
55
"keywords": [
6-
"template"
6+
"ui-awesome",
7+
"html",
8+
"core-component",
9+
"php"
710
],
811
"license": "mit",
9-
"minimum-stability": "dev",
10-
"prefer-stable": true,
1112
"require": {
12-
"php": "^8.1"
13+
"php": "^8.1",
14+
"php-forge/awesome-widget": "^0.1",
15+
"ui-awesome/html-attribute": "^0.1",
16+
"ui-awesome/html-concern": "^0.1",
17+
"ui-awesome/html-helper": "^0.1",
18+
"ui-awesome/html-interop": "^0.1",
19+
"ui-awesome/html-svg": "^0.1"
1320
},
1421
"require-dev": {
1522
"maglnet/composer-require-checker": "^4.7",
23+
"php-forge/support": "^0.1",
1624
"phpunit/phpunit": "^10.5",
1725
"roave/infection-static-analysis-plugin": "^1.34",
1826
"symplify/easy-coding-standard": "^12.1",
19-
"vimeo/psalm": "^5.19"
27+
"vimeo/psalm": "^5.20"
2028
},
2129
"autoload": {
2230
"psr-4": {
23-
"Template\\": "src"
31+
"UIAwesome\\Html\\Core\\Component\\": "src"
2432
}
2533
},
2634
"autoload-dev": {
2735
"psr-4": {
28-
"Template\\Tests\\": "tests"
36+
"UIAwesome\\Html\\Core\\Component\\Tests\\": "tests"
2937
}
3038
},
3139
"extra": {

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
stopOnFailure="false"
1212
>
1313
<testsuites>
14-
<testsuite name="Template">
14+
<testsuite name="html-core-component">
1515
<directory>tests</directory>
1616
</testsuite>
1717
</testsuites>

src/AbstractAlert.php

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace UIAwesome\Html\Core\Component;
6+
7+
use PHPForge\Widget\Element;
8+
use UIAwesome\Html\{
9+
Attribute\Aria\HasRole,
10+
Attribute\HasClass,
11+
Attribute\HasId,
12+
Attribute\HasStyle,
13+
Concern\HasAttributes,
14+
Concern\HasContainerCollection,
15+
Concern\HasContent,
16+
Concern\HasPrefixCollection,
17+
Concern\HasSuffixCollection,
18+
Concern\HasTemplate,
19+
Core\Component\Concern\HasToggle,
20+
Helper\HTMLBuilder,
21+
Helper\Template,
22+
Helper\Utils,
23+
Interop\RenderInterface
24+
};
25+
26+
use function is_string;
27+
28+
/**
29+
* This class serves as a base for implementing various types of alert components.
30+
*/
31+
abstract class AbstractAlert extends Element implements RenderInterface
32+
{
33+
use HasAttributes;
34+
use HasClass;
35+
use HasContainerCollection;
36+
use HasContent;
37+
use HasId;
38+
use HasPrefixCollection;
39+
use HasRole;
40+
use HasStyle;
41+
use HasSuffixCollection;
42+
use HasTemplate;
43+
use HasToggle;
44+
45+
protected array $attributes = [];
46+
47+
/**
48+
* Loads the default definitions for the alert component.
49+
*
50+
* @return array The default definitions.
51+
*/
52+
protected function loadDefaultDefinitions(): array
53+
{
54+
return [
55+
'id()' => [Utils::generateId('alert-')],
56+
'role()' => ['alert'],
57+
'template()' => ['{prefix}\n{content}\n{suffix}\n{toggle}'],
58+
];
59+
}
60+
61+
/**
62+
* Renders the alert component.
63+
*
64+
* This method generates the HTML representation of the alert component with the specified content and attributes.
65+
*
66+
* @return string The rendered alert component.
67+
*/
68+
protected function run(): string
69+
{
70+
if ($this->content === '') {
71+
return '';
72+
}
73+
74+
$content = Template::render(
75+
$this->template,
76+
[
77+
'{prefix}' => $this->renderTag($this->prefixAttributes, $this->prefix, $this->prefixTag),
78+
'{content}' => $this->renderTag($this->containerAttributes, $this->content, $this->containerTag),
79+
'{suffix}' => $this->renderTag($this->suffixAttributes, $this->suffix, $this->suffixTag),
80+
'{toggle}' => $this->renderToggle(),
81+
],
82+
);
83+
84+
return HTMLBuilder::createTag('div', $content, $this->attributes);
85+
}
86+
87+
/**
88+
* Renders a HTML tag with the provided attributes and content.
89+
*
90+
* @param array $attributes The attributes for the tag.
91+
* @param string $content The content of the tag.
92+
* @param false|string $tag The tag name. If false, the content will be returned as is.
93+
*
94+
* @return string The rendered HTML tag.
95+
*/
96+
private function renderTag(array $attributes, string $content, false|string $tag): string
97+
{
98+
if ($content === '' || $tag === false) {
99+
return $content;
100+
}
101+
102+
return HTMLBuilder::createTag($tag, $content, $attributes);
103+
}
104+
105+
/**
106+
* Renders the toggle component.
107+
*
108+
* @return string The rendered toggle component.
109+
*/
110+
private function renderToggle(): string
111+
{
112+
if (is_string($this->toggle)) {
113+
return $this->toggle;
114+
}
115+
116+
$id = $this->getId() ?? '';
117+
118+
return $this->toggle->dataValue($id)->render();
119+
}
120+
}

0 commit comments

Comments
 (0)