Skip to content

Commit

Permalink
Feature/rchaplin/lwb 264/specific attributes all components (#265)
Browse files Browse the repository at this point in the history
* LWB-264 Adding specific attributes to Demarcation components <del> and <ins>

* LWB-264 General code cleanup

* LWB-264 Adding specific attributes to Embeded components

* LWB-264 updating embeded components tests

* LWB-264 Adding specific attributes to the SvgMathMl components

* LWB-264 Adding specific attributes to the Scripting components

* LWB-264 Adding specific attributes to the Table components

* LWB-264 Adding specific attributes to most Form components

* LWB-264 Adding all of the Input types as individual components

* LWB-264 Major overhaul for attribute trait structuring

* LWB-264 Adjust MaxlengthMinLength to use integers as the 2 property types.

* LWB-264 Fixing the FormRelatedAttributes Trait logic

* LWB-264 Fixing doc blocks for ListAttribute Trait

* LWB-264 Fixing doc blocks for AutocompleteAttribute Trait

* LWB-264 Adjusting Iframe component to use the DimensionalAttributes trait

* LWB-264 adding in src attribute assignment for Iframe component

* LWB-264 Adjusting type logic for the Button Component

* LWB-264 Fixing docblocks for Text, Tel, and Url components

* LWB-264 Adding DimensionalAttributes Trait usage for the MEter Component

* LWB-264 Adding DimensionalAttributes Trait usage for the Canvas Component
  • Loading branch information
t73biz authored Jul 18, 2024
1 parent 5215e47 commit 9779745
Show file tree
Hide file tree
Showing 366 changed files with 5,339 additions and 12,080 deletions.
2 changes: 1 addition & 1 deletion resources/views/demarcation/del.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<del {!! $globalAttributes !!}>
<del {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</del>
2 changes: 1 addition & 1 deletion resources/views/demarcation/ins.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<ins {!! $globalAttributes !!}>
<ins {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</ins>
2 changes: 1 addition & 1 deletion resources/views/embedded_content/embed.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<embed {!! $globalAttributes !!}>
<embed {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</embed>
2 changes: 1 addition & 1 deletion resources/views/embedded_content/iframe.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<iframe {!! $globalAttributes !!}>
<iframe {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</iframe>
2 changes: 1 addition & 1 deletion resources/views/embedded_content/portal.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<portal {!! $globalAttributes !!}>
<portal {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</portal>
4 changes: 1 addition & 3 deletions resources/views/embedded_content/source.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<source {!! $globalAttributes !!}>
{{ $slot }}
</source>
<source {!! $globalAttributes !!} {!! $specificAttributes !!}>
2 changes: 1 addition & 1 deletion resources/views/forms/button.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button {!! $globalAttributes !!}>
<button {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</button>
2 changes: 1 addition & 1 deletion resources/views/forms/fieldset.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<fieldset {!! $globalAttributes !!}>
<fieldset {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</fieldset>
2 changes: 1 addition & 1 deletion resources/views/forms/form.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<form {!! $globalAttributes !!}>
<form {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</form>
2 changes: 1 addition & 1 deletion resources/views/forms/input.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<input {!! $globalAttributes !!}>
<input {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</input>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/button.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="button" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="checkbox" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/color.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="color" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/date.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="date" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/datetimelocal.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="datetimelocal" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/email.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="email" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/file.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="file" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/hidden.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="hidden" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/image.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="image" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/month.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="month" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/number.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="number" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/password.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="password" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/radio.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="radio" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/range.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="range" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/reset.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="reset" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/search.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="search" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/submit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="submit" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/tel.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="tel" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/text.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="text" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/time.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="time" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/url.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="url" {!! $globalAttributes !!} {!! $specificAttributes !!}>
1 change: 1 addition & 0 deletions resources/views/forms/inputs/week.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="week" {!! $globalAttributes !!} {!! $specificAttributes !!}>
2 changes: 1 addition & 1 deletion resources/views/forms/label.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<label {!! $globalAttributes !!}>
<label {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</label>
2 changes: 1 addition & 1 deletion resources/views/forms/meter.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<meter {!! $globalAttributes !!}>
<meter {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</meter>
2 changes: 1 addition & 1 deletion resources/views/forms/optgroup.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<optgroup {!! $globalAttributes !!}>
<optgroup {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</optgroup>
2 changes: 1 addition & 1 deletion resources/views/forms/option.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<option {!! $globalAttributes !!}>
<option {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</option>
2 changes: 1 addition & 1 deletion resources/views/forms/output.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<output {!! $globalAttributes !!}>
<output {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</output>
2 changes: 1 addition & 1 deletion resources/views/forms/progress.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<progress {!! $globalAttributes !!}>
<progress {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</progress>
2 changes: 1 addition & 1 deletion resources/views/forms/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<select {!! $globalAttributes !!}>
<select {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</select>
2 changes: 1 addition & 1 deletion resources/views/scripting/canvas.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<canvas {!! $globalAttributes !!}>
<canvas {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</canvas>
2 changes: 1 addition & 1 deletion resources/views/scripting/script.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<script {!! $globalAttributes !!}>
<script {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</script>
2 changes: 1 addition & 1 deletion resources/views/svg_math_ml/math.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<math {!! $globalAttributes !!}>
<math {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</math>
2 changes: 1 addition & 1 deletion resources/views/svg_math_ml/svg.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<svg {!! $globalAttributes !!}>
<svg {!! $specificAttributes !!}>
{{ $slot }}
</svg>
2 changes: 1 addition & 1 deletion resources/views/table_content/col.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<col {!! $globalAttributes !!}>
<col {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</col>
2 changes: 1 addition & 1 deletion resources/views/table_content/colgroup.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<colgroup {!! $globalAttributes !!}>
<colgroup {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</colgroup>
2 changes: 1 addition & 1 deletion resources/views/table_content/td.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<td {!! $globalAttributes !!}>
<td {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</td>
2 changes: 1 addition & 1 deletion resources/views/table_content/th.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<th {!! $globalAttributes !!}>
<th {!! $globalAttributes !!} {!! $specificAttributes !!}>
{{ $slot }}
</th>
26 changes: 26 additions & 0 deletions src/Components/AttributeTraits/AltAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace T73biz\LwBits\Components\AttributeTraits;

use Livewire\Features\SupportAttributes\AttributeCollection;

trait AltAttribute
{
/**
* A text description of the resource. This is a required attribute for accessibility and is used by screen readers.
*/
public string $alt = '';

/**
* Set the alt attribute
*
* @throws \T73biz\LwBits\Exceptions\InvalidAttributeException
*/
public function setAltAttribute(AttributeCollection &$specificAttributes): void
{
if (empty($this->alt)) {
throw new \T73biz\LwBits\Exceptions\InvalidAttributeException('The alt attribute is required for accessibility and must be set.');
}
$specificAttributes->add(['alt' => $this->alt]);
}
}
119 changes: 119 additions & 0 deletions src/Components/AttributeTraits/AutocompleteAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

namespace T73biz\LwBits\Components\AttributeTraits;

use Livewire\Features\SupportAttributes\AttributeCollection;
use T73biz\LwBits\Exceptions\InvalidAttributeException;

trait AutocompleteAttribute
{
/**
* The HTML autocomplete attribute lets web developers specify what if any permission the user agent has to provide
* automated assistance in filling out form field values, as well as guidance to the browser as to the type of
* information expected in the field.
*
* It is available on <input> elements that take a text or numeric value as input, <textarea> elements, <select>
* elements, and <form> elements.
*/
public string $autocomplete = '';

/**
* Set the autocomplete attribute.
*
* @throws \T73biz\LwBits\Exceptions\InvalidAttributeException
*/
public function setAutocompleteAttribute(AttributeCollection &$specificAttributes): void
{
/**
* Possible Values:
* - off: The browser is not allowed to automatically complete the input. Note: It can't prevent a password
* manager from asking the user if they want to save username and password information.
* - on: The browser is allowed to automatically complete the input with no guidance as to the type of data
* expected.
* - <token-list>: An ordered set of space-separated tokens consisting of autofill detail tokens.
*
* If the autocomplete attribute is <token-list>, each token is the string "section-", case-insensitive,
* followed by the rest of the token. All form controls with the same token belong to the named group.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values
*/
$allowedValues = [
'name',
'honorific-prefix',
'given-name',
'additional-name',
'family-name',
'honorific-suffix',
'nickname',
'email',
'username',
'new-password',
'current-password',
'one-time-code',
'organization-title',
'organization',
'street-address',
'shipping',
'billing',
'address-line1',
'address-line2',
'address-line3',
'address-level4',
'address-level3',
'address-level2',
'address-level1',
'country',
'country-name',
'postal-code',
'cc-name',
'cc-given-name',
'cc-additional-name',
'cc-family-name',
'cc-number',
'cc-exp',
'cc-exp-month',
'cc-exp-year',
'cc-csc',
'cc-type',
'transaction-currency',
'transaction-amount',
'language',
'bday',
'bday-day',
'bday-month',
'bday-year',
'sex',
'tel',
'tel-country-code',
'tel-national',
'tel-area-code',
'tel-local',
'tel-extension',
'impp',
'url',
'photo',
'webauthn',
];
if (! empty($this->autocomplete)) {
if (in_array($this->autocomplete, ['on', 'off'])) {
$specificAttributes->add(['autocomplete' => $this->autocomplete]);

return;
} else {
$valueParts = explode(' ', $this->autocomplete);

foreach ($valueParts as $key => $valuePart) {
if (str_starts_with($valuePart, 'section-') && $key !== 0) {
throw new InvalidAttributeException(
'The autocomplete attribute value is invalid. The section token must be the first token.'
);
} elseif (! in_array($valuePart, $allowedValues) && ! str_starts_with($valuePart, 'section-')) {
throw new InvalidAttributeException('The autocomplete attribute value is invalid.');
}
}
}

$specificAttributes->add(['autocomplete' => $this->autocomplete]);
}
}
}
35 changes: 35 additions & 0 deletions src/Components/AttributeTraits/CheckedAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace T73biz\LwBits\Components\AttributeTraits;

use Livewire\Features\SupportAttributes\AttributeCollection;

trait CheckedAttribute
{
/**
* Valid for both radio and checkbox types, checked is a Boolean attribute. If present on a radio type, it indicates
* that the radio button is the currently selected one in the group of same-named radio buttons. If present on a
* checkbox type, it indicates that the checkbox is checked by default (when the page loads). It does not indicate
* whether this checkbox is currently checked: if the checkbox's state is changed, this content attribute does not
* reflect the change. (Only the HTMLInputElement's checked IDL attribute is updated.)
*
* Note:
* Unlike other input controls, a checkboxes and radio buttons value are only included in the submitted data
* if they are currently checked. If they are, the name and the value(s) of the checked controls are submitted.
*
* For example, if a checkbox whose name is fruit has a value of cherry, and the checkbox is checked, the form data
* submitted will include fruit=cherry. If the checkbox isn't active, it isn't listed in the form data at all. The
* default value for checkboxes and radio buttons is on.
*/
public bool $checked = false;

/**
* Set the checked attribute.
*/
public function setCheckedAttribute(AttributeCollection $specificAttributes): void
{
if ($this->checked) {
$specificAttributes->add(['checked']);
}
}
}
31 changes: 31 additions & 0 deletions src/Components/AttributeTraits/DimensionalAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace T73biz\LwBits\Components\AttributeTraits;

use Livewire\Features\SupportAttributes\AttributeCollection;

trait DimensionalAttributes
{
/**
* The displayed height of the resource, in CSS pixels. This must be an absolute value; percentages are not allowed.
*/
public int $height = 0;

/**
* The displayed width of the resource, in CSS pixels. This must be an absolute value; percentages are not allowed.
*/
public int $width = 0;

/**
* Set the dimensional attributes
*/
public function setDimensionalAttributes(AttributeCollection &$specificAttributes): void
{
if ($this->height > 0) {
$specificAttributes->add(['height' => $this->height]);
}
if ($this->width > 0) {
$specificAttributes->add(['width' => $this->width]);
}
}
}
Loading

0 comments on commit 9779745

Please sign in to comment.