-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web-twig): Introduce
HelperText
component
- Loading branch information
1 parent
f8e5ee4
commit d2ab6d1
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/web-twig/src/Resources/components/Field/HelperText.twig
This file contains 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,25 @@ | ||
{# API #} | ||
{%- set props = props | default([]) -%} | ||
{%- set _className = props.className -%} | ||
{%- set _elementType = props.elementType | default('div') -%} | ||
{%- set _helperText = props.helperText | default(null) -%} | ||
{%- set _id = props.id | default(null) -%} | ||
{%- set _unsafeHelperText = props.UNSAFE_helperText | default(null) -%} | ||
|
||
{# Attributes #} | ||
{%- set _idAttr = _id ? 'id="' ~ _id | escape('html_attr') ~ '"' : null -%} | ||
|
||
{# Deprecations #} | ||
{% if not _id %} | ||
{% deprecated 'HelperText: The "id" property will be required starting from the next major version.' %} | ||
{% endif %} | ||
|
||
{% if _helperText or _unsafeHelperText %} | ||
<{{ _elementType }} class="{{ _className }}" {{ _idAttr | raw }}> | ||
{% if _helperText and not _unsafeHelperText %} | ||
{{ _helperText }} | ||
{% elseif _unsafeHelperText %} | ||
{{ _unsafeHelperText | raw }} | ||
{% endif %} | ||
</{{ _elementType }}> | ||
{% endif %} |
1 change: 1 addition & 0 deletions
1
packages/web-twig/src/Resources/twig-components/helperText.twig
This file contains 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 @@ | ||
{% extends '@spirit/Field/HelperText.twig' %} |
14 changes: 14 additions & 0 deletions
14
...ig/tests/__snapshots__/ComponentsSnapshotTest__test with data set helperText.twig__1.html
This file contains 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,14 @@ | ||
<!DOCTYPE html> | ||
<!-- DO NOT render without children --><!-- Render with plain helper text --><html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title> | ||
</title> | ||
</head> | ||
<body> | ||
<div class="myClass" id="validationText"> | ||
Helper text | ||
</div> | ||
<!-- Render with all props --> | ||
<span class="myClass" id="helperTextAllProps"><span>Unsafe helper text</span></span> | ||
</body> | ||
</html> |
18 changes: 18 additions & 0 deletions
18
packages/web-twig/tests/components-fixtures/helperText.twig
This file contains 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,18 @@ | ||
<!-- DO NOT render without children --> | ||
<HelperText /> | ||
|
||
<!-- Render with plain helper text --> | ||
<HelperText | ||
className="myClass" | ||
helperText="Helper text" | ||
id="validationText" | ||
/> | ||
|
||
<!-- Render with all props --> | ||
<HelperText | ||
className="myClass" | ||
elementType="span" | ||
helperText="Helper text" | ||
id="helperTextAllProps" | ||
UNSAFE_helperText="<span>Unsafe helper text</span>" | ||
/> |