Skip to content

Commit

Permalink
fixup! Refactor(web-twig): Use new HelperText component in all form…
Browse files Browse the repository at this point in the history
… fields
  • Loading branch information
adamkudrna committed Aug 15, 2023
1 parent 0df0fbd commit 581ae34
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 55 deletions.
47 changes: 2 additions & 45 deletions packages/web-twig/src/Resources/components/Field/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
# ValidationText
# Form Field Subcomponents

The validationText subcomponent displays validation texts for Field components like TextField, TextArea, Checkbox, FileUploader, etc.

Basic example usage:

```twig
<ValidationText
className="Component__validationText"
validationState="danger"
validationText="Danger validation text"
/>
```

Advanced example:

```twig
<ValidationText
className="Component__validationText"
elementType="span"
validationState="danger"
UNSAFE_validationText="Danger <strong>validation</strong> text"
/>
```

Without lexer:

```twig
{% embed "@spirit/validationText.twig" with { props: {
className: 'Component__validationText',
validationState: 'danger',
validationText: 'Danger validation text'
}} %}{% endembed %}
```

## API

| Prop name | Type | Default | Required | Description |
| ----------------------- | -------------------- | ------- | -------- | ----------------------------------------------------------------------------- |
| `className` | `string` | - | yes | ClassName of the ValidationText |
| `elementType` | `string` | `div` | no | HTML tag to render, except if text is an array, then the root element is `ul` |
| `validationState` | `string` | `null` | no | Validation State is used to determine if the component should be rendered |
| `validationText` | `string`, `string[]` | - | yes\* | Validation text |
| `UNSAFE_validationText` | `string`, `string[]` | - | yes\* | Validation text with HTML tags |

\*: ValidationText is required. You can use the `validationText` for simple text or `UNSAFE_validationText` for HTML content.
⚠️ All components in this directory are private and should not be used outside of Spirit components.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE html>
<!-- DO NOT render without children --><!-- Render with plain helper text --><html xmlns="http://www.w3.org/1999/xhtml">
<!-- DO NOT render when there is nothing to display --><!-- Render with plain helper text --><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
</title>
</head>
<body>
<div class="myClass" id="validationText">
<div class="myClass">
Helper text
</div>
<!-- Render with all props -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE html>
<!-- DO NOT render without children --><!-- DO NOT render when validationState is not set --><!-- Render with plain validation text --><html xmlns="http://www.w3.org/1999/xhtml">
<!-- DO NOT render when there is nothing to display --><!-- DO NOT render when validationState is not set --><!-- Render with plain validation text --><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
</title>
</head>
<body>
<div class="myClass" id="validationText">
<div class="myClass">
Validation text
</div>
<!-- Render with all props -->
Expand Down
5 changes: 2 additions & 3 deletions packages/web-twig/tests/components-fixtures/helperText.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<!-- DO NOT render without children -->
<HelperText />
<!-- DO NOT render when there is nothing to display -->
<HelperText className="myClass" />

<!-- Render with plain helper text -->
<HelperText
className="myClass"
helperText="Helper text"
id="validationText"
/>

<!-- Render with all props -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!-- DO NOT render without children -->
<ValidationText />
<!-- DO NOT render when there is nothing to display -->
<ValidationText className="myClass" />

<!-- DO NOT render when validationState is not set -->
<ValidationText
className="myClass"
validationText="Validation text"
/>

<!-- Render with plain validation text -->
<ValidationText
className="myClass"
id="validationText"
validationState="success"
validationText="Validation text"
/>
Expand Down

0 comments on commit 581ae34

Please sign in to comment.