Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: form elements - form label documentation #571

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wmnds/components/form-elements/dropdown/_dropdown.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="wmnds-fe-dropdown">
{{
wmndsLabel({
label: 'Dropdown label',
contentText: 'Dropdown label',
for: id
}) | trim
}}
Expand Down
2 changes: 1 addition & 1 deletion src/wmnds/components/form-elements/input/_input.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="wmnds-fe-group{{groupErrorClass}}">
{{
wmndsLabel({
label: label,
contentText: label,
for: id
}) | trim | indent
}}
Expand Down
12 changes: 12 additions & 0 deletions src/wmnds/components/form-elements/label/_example.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% raw %}
{% from "wmnds/components/form-elements/label/_label.njk" import wmndsLabel %}

{{
wmndsLabel({
contentText: "Form label",
contentHTML: null,
classes: null,
for: "genericInput"
houbly marked this conversation as resolved.
Show resolved Hide resolved
})
}}
{% endraw %}
7 changes: 5 additions & 2 deletions src/wmnds/components/form-elements/label/_label.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{% macro wmndsLabel(params) %}
{# Set vars and defaults #}
{% set for = params.for if params.for else "genericInput" %}
{% set label = params.label if params.label else "Form label" %}
{% set contentText = params.contentText if params.contentText else "Form label" %}
{% set classes = " " + params.classes if params.classes %}
{% set contentHTML = params.contentHTML if params.contentHTML else contentText %}
{% set _label = contentHTML | safe if contentHTML else contentText %}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "classes"

<label class="wmnds-fe-label" for="{{for}}">{{ label }}</label>
<label class="wmnds-fe-label{{classes}}" for="{{for}}">{{ _label }}</label>

{% endmacro %}
24 changes: 24 additions & 0 deletions src/wmnds/components/form-elements/label/_properties.njk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"wmndsLabelProps": [
{
"name": "contentText",
"type": "string",
"description": "<strong>Required.</strong> Specifies the text that will be included in the label. If <code class='wmnds-website-inline-code'>contentHTML</code> is provided this is not required and will be ignored."
},
{
"name": "contentHTML",
"type": "string",
"description": "<strong>Required.</strong> Specifies the text that will be included in the label as HTML. If <code class='wmnds-website-inline-code'>contentText</code> is provided, this is not required."
},
{
"name": "for",
"type": "string",
"description": "<strong>Required.</strong> Specifies the id of the element this label should link to."
},
{
"name": "classes",
"type": "string",
"description": "Classes to add to the label tag."
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "classes" property.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
  "name": "classes",
  "type": "string",
  "description": "Classes to add to the label tag."
} 

]
}
2 changes: 1 addition & 1 deletion src/wmnds/components/form-elements/textarea/_textarea.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="wmnds-fe-group">
{{
wmndsLabel({
label: 'Textarea label',
contentText: 'Textarea label',
for: id
}) | trim
}}
Expand Down
2 changes: 1 addition & 1 deletion src/wmnds/patterns/autocomplete/_autocomplete.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{
wmndsLabel({
for: id,
label: 'Autocomplete label'
contentText: 'Autocomplete label'
}) | trim
}}

Expand Down
3 changes: 3 additions & 0 deletions src/www/data.njk.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
{
"name": "Form elements"
},
{
"name": "Form label"
},
{
"name": "Inset text"
},
Expand Down
11 changes: 10 additions & 1 deletion src/www/pages/components/form-elements/index.njk.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@

{% from "wmnds/components/form-elements/label/_label.njk" import wmndsLabel %}
{{
compExample([wmndsLabel()])
compExample([
wmndsLabel()
],
{
componentPath: "wmnds/components/form-elements/label/",
njk: true,
njkProps: wmndsLabelProps,
js: false,
iframe: false
})
}}
{# End label #}

Expand Down
42 changes: 42 additions & 0 deletions src/www/pages/components/form-label/index.njk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends "www/_layouts/layout-left-pane.njk" %}
{% set pageTitle = "Form label" %}
{% from "www/_partials/component-example/component-example.njk" import compExample %}

{% block content %}
{% markdown %}
{# Label #}

## About

### What does it do?

- Tells users what a field is for.

### When to use it?

- When you are requesting multiple pieces of information to answer the same question. For example, the day, month and year of a date.
- The label must appear directly above the field.

### When not to use it?

- Do not use this component to ask more questions within a question - instead, ask a new question.
- When you're giving extra information and hints to help the user answer a question.

{% endmarkdown %}

{% from "wmnds/components/form-elements/label/_label.njk" import wmndsLabel %}
{{
compExample([
wmndsLabel()
],
{
componentPath: "wmnds/components/form-elements/label/",
njk: true,
njkProps: wmndsLabelProps,
js: false,
iframe: false
})
}}
{# End label #}

{% endblock %}