In general we'd prefer to keep most of our HTML where in belongs in blade components and files. However, there are various cases where it can be nice to autogenerate the HTML needed for a component automagically. This package is intended for those exact circumstances.
Similar to our Forms package we have some simple directives for loading any needed assets for the components.
<!-- Html Styles --> <style > </style> <!-- Html Scripts --> <script type="module" > window.HtmlJS = () => { } window.HtmlJS(); </script> <!-- Html Styles --> <style > </style> <!-- Html Scripts --> <script type="module" > window.HtmlJS = () => { } window.HtmlJS(); </script> <script src="https://cdn.usefathom.com/script.js" data-site="" defer></script>
Just place that below any of your JavaScript file references and you can easily load the html assets when the content is being rendered on screen.
As for the Fathom directive, ensure that you have the following added to your services:
'fathom' => [ 'key' => env('FATHOM_KEY'), ],
Accordion ActionDropdown ActionDropdownGroup Admonition Alert Animation Announcement Avatar Badge Breadcrumbs Calendar Card Carousel Code Countdown Divider DropdownDivider DropdownItem DropdownItemButton Feed FeedItem HtmlComponent Image ImageCompare Lightbox ListGroup ListGroupItem Lottie Modal Nav NavButton NavDropdown NavLink Offcanvas Parallax Popover Progress Rating Spinner Table Tag Text Tilt Video WordSwitcher Animations/Hamster Animations/Pulse Animations/Spaceman Animations/Typewriter
This class base lets us create our own global components for any needs in our application. These are single-file components, containing JavaScript, Styles and HTML content.
Below is an example of an overlay component.
namespace App\View\Components\Global; use Grafite\Html\Tags\HtmlTagComponent; class PendingOverlay extends HtmlTagComponent { public static function template() { return HTML <div id="_componentPendingOverlay" class="overlay d-none bg-dark"> <div class="spinner-container"> <div class="spinner-border" role="status"> <span class="visually-hidden">Loading...</span> </div> </div> </div> HTML; } public static function styles() { return CSS .overlay { width: 100%; height: 100vh; position: absolute; top: 0; left: 0; z-index: 30000; opacity: .8; } .spinner-container { position: absolute; top: 49%; left: calc(50% - 15px); } CSS; } public static function js() { return JS window.pending = (button) => { if (button && button.form.checkValidity()) { button.form.submit(); button.disabled = true; document.getElementById('_componentPendingOverlay').classList.remove('d-none'); } if (! button) { document.getElementById('_componentPendingOverlay').classList.remove('d-none'); } return false; }; window.pendingHide = () => { document.getElementById('_componentPendingOverlay').classList.add('d-none'); }; JS; } }
To generate any component you must first call the make method statically. Alert::make(). Subsequently, you need to end all component chains with the render() method or the renderWhen method.
Between those methods you can call any of these global methods to set various values in the component.
id() => $id css() => $css url() => $url text() => $text onClick() => $onClick items() => $items attributes() => $attributes
Some components have unique properties which have unique methods to call each of them to set their values. Below is a list of any unique properties that can be set for the components.
Nearly all components have corresponding blade tags which can also be used. Many of which can be seen here
There are a few core component methods which we should discuss.
Renders the component as a string
Renders the component as a string when the callback is true.
Intiates the build of the html component.
Sends some CSS to the HtmlAssets which are minified and pushed to the blade directive styles.
Sends an array of CDN links to the HtmlAssets which are pushed to the blade directive scripts.
Sends JavaScript code to the HtmlAssets which are pushed to the blade directive scripts.