|
1 | 1 | --- |
2 | 2 | title: Testing - Dropdown Select |
3 | 3 | --- |
| 4 | +{% set contentClasses = 'dropdown-select-spec' %} |
4 | 5 | {% extends 'test.njk' %} |
5 | | -{% macro dropdown(id='', wasChanged=false, wasTouched=false, className='', isRequired=false, isDisabled=false, isFocused=false, isValid=true) %} |
6 | | - {% set isPristine = (className === '') and not (wasChanged or wasTouched) %} |
| 6 | +{% macro dropdown(id='', isDirty=false, className='', isRequired=false, isDisabled=false, isFocused=false, isValid=true) %} |
| 7 | + {% set isPristine = (className === '') and not isDirty %} |
7 | 8 |
|
8 | 9 | {% set idAttr -%}hxSelect- |
9 | | - {{- 'p' if not (wasChanged or wasTouched) -}} |
10 | | - {{- 'c' if wasChanged -}} |
11 | | - {{- 't' if wasTouched -}} |
| 10 | + {{- 'd' if isDirty else 'p' -}} |
12 | 11 | {{- 'R' if isRequired else 'O' -}} |
13 | 12 | {{- 'D' if isDisabled else 'E' -}} |
14 | 13 | {{- 'V' if isValid else 'I' -}} |
|
17 | 16 | {%- if id !== '' %}-{{id}}{% endif -%} |
18 | 17 | {%- endset %} |
19 | 18 |
|
20 | | - <label for="{{idAttr | trim}}"> |
21 | | - {% if isPristine %} |
22 | | - Pristine, |
23 | | - {% else %} |
24 | | - {% if className !== '' %}.{{ className }},{% endif %} |
25 | | - {% if wasChanged %}Changed,{% endif %} |
26 | | - {% if wasTouched %}Touched,{% endif %} |
27 | | - {% endif %} |
28 | | - {{ 'Required' if isRequired else 'Optional' }}, |
29 | | - {{ 'Disabled' if isDisabled else 'Enabled' }}, |
30 | | - {{ 'Valid' if isValid else 'Invalid' }} |
31 | | - ({{ 'focus' if isFocused else 'blur' }}) |
32 | | - </label> |
33 | | - |
34 | 19 | <hx-select-control |
35 | 20 | {% if className !== '' %}class="{{className}}" {% endif %} |
36 | | - {% if wasChanged %}hx-changed {% endif %} |
37 | | - {% if wasTouched %}hx-touched {% endif %} |
| 21 | + {% if isDirty %}hx-dirty {% endif %} |
38 | 22 | > |
39 | 23 | <select |
40 | 24 | id="{{idAttr | trim}}" |
|
60 | 44 | {% endif %} |
61 | 45 | </select> |
62 | 46 | <hx-select></hx-select> |
| 47 | + <label for="{{idAttr | trim}}"> |
| 48 | + {% if isPristine %} |
| 49 | + Pristine, |
| 50 | + {% else %} |
| 51 | + {% if className !== '' %}.{{ className }},{% endif %} |
| 52 | + {% if isDirty %}Dirty,{% endif %} |
| 53 | + {% endif %} |
| 54 | + {{ 'Required' if isRequired else 'Optional' }}, |
| 55 | + {{ 'Disabled' if isDisabled else 'Enabled' }}, |
| 56 | + {{ 'Valid' if isValid else 'Invalid' }} |
| 57 | + ({{ 'focus' if isFocused else 'blur' }}) |
| 58 | + </label> |
63 | 59 | </hx-select-control> |
64 | 60 | {% endmacro %} |
65 | | -{% macro stateTable(id, wasChanged=false, wasTouched=false, className="", isRequired=false) %} |
| 61 | +{% macro stateTable(id, isDirty=false, className="", isRequired=false) %} |
66 | 62 | <table> |
67 | 63 | <thead> |
68 | 64 | <tr> |
|
72 | 68 | </thead> |
73 | 69 | <tbody> |
74 | 70 | <tr><!-- select:enabled --> |
75 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired)}}</td> |
76 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired, isValid=false)}}</td> |
| 71 | + <td>{{dropdown(id, isDirty, className, isRequired)}}</td> |
| 72 | + <td>{{dropdown(id, isDirty, className, isRequired, isValid=false)}}</td> |
77 | 73 | </tr> |
78 | 74 | <tr><!-- select:enabled:focus --> |
79 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired, isFocused=true)}}</td> |
80 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired, isFocused=true, isValid=false)}}</td> |
| 75 | + <td>{{dropdown(id, isDirty, className, isRequired, isFocused=true)}}</td> |
| 76 | + <td>{{dropdown(id, isDirty, className, isRequired, isFocused=true, isValid=false)}}</td> |
81 | 77 | </tr> |
82 | 78 | <tr><!-- select:disabled --> |
83 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired, isDisabled=true)}}</td> |
84 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired, isDisabled=true, isValid=false)}}</td> |
| 79 | + <td>{{dropdown(id, isDirty, className, isRequired, isDisabled=true)}}</td> |
| 80 | + <td>{{dropdown(id, isDirty, className, isRequired, isDisabled=true, isValid=false)}}</td> |
85 | 81 | </tr> |
86 | 82 | <tr><!-- select:disabled:focus --> |
87 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired, isDisabled=true, isFocused=true)}}</td> |
88 | | - <td>{{dropdown(id, wasChanged, wasTouched, className, isRequired, isDisabled=true, isFocused=true, isValid=false)}}</td> |
| 83 | + <td>{{dropdown(id, isDirty, className, isRequired, isDisabled=true, isFocused=true)}}</td> |
| 84 | + <td>{{dropdown(id, isDirty, className, isRequired, isDisabled=true, isFocused=true, isValid=false)}}</td> |
89 | 85 | </tr> |
90 | 86 | </tbody> |
91 | 87 | </table> |
|
96 | 92 | </p> |
97 | 93 | {% endif %} |
98 | 94 | {% endmacro %} |
99 | | -{% macro stateTables(id, wasChanged=false, wasTouched=false, className="") %} |
| 95 | +{% macro stateTables(id, isDirty=false, className="") %} |
100 | 96 | <section id="{{id}}-optional-states"> |
101 | 97 | <header> |
102 | 98 | <h3>Optional</h3> |
103 | | - <code>select:optional</code> |
| 99 | + <code><select></code> |
104 | 100 | </header> |
105 | | - {{stateTable(id, wasChanged, wasTouched, className, isRequired=false)}} |
| 101 | + {{stateTable(id, isDirty, className, isRequired=false)}} |
106 | 102 | </section> |
107 | 103 |
|
108 | 104 | <section id="{{id}}-required-states"> |
109 | 105 | <header> |
110 | 106 | <h3>Required</h3> |
111 | | - <code>select:required</code> |
| 107 | + <code><select required></code> |
112 | 108 | </header> |
113 | | - {{stateTable(id, wasChanged, wasTouched, className, isRequired=true)}} |
| 109 | + {{stateTable(id, isDirty, className, isRequired=true)}} |
114 | 110 | </section> |
115 | 111 | {% endmacro %} |
116 | 112 |
|
117 | | -{% block content %} |
| 113 | +{% block page_header %} |
118 | 114 | <nav class="hxBreadcrumb"> |
119 | 115 | <a href="components/dropdown-select">Dropdown Select</a> |
120 | 116 | <hx-icon class="delimiter" type="angle-right"></hx-icon> |
121 | 117 | <a href="#">{{page.title}}</a> |
122 | 118 | </nav> |
| 119 | +{% endblock %} |
123 | 120 |
|
| 121 | +{% block content %} |
124 | 122 | <section> |
125 | 123 | <header> |
126 | | - <h2>Pristine</h2> |
| 124 | + <h2 id="test-pristine">Pristine</h2> |
127 | 125 | <code><hx-select-control></code> |
128 | 126 | </header> |
129 | 127 | {{stateTables('pristine')}} |
130 | 128 | </section> |
131 | 129 |
|
132 | 130 | <section> |
133 | 131 | <header> |
134 | | - <h2>Changed</h2> |
135 | | - <p><code><hx-select-control hx-changed></code></p> |
| 132 | + <h2 id="test-dirty">Dirty</h2> |
| 133 | + <code><hx-select-control hx-dirty></code> |
136 | 134 | </header> |
137 | | - {{stateTables('changed', wasChanged=true)}} |
| 135 | + {{stateTables('changed', isDirty=true)}} |
138 | 136 | </section> |
139 | 137 |
|
140 | 138 | <section> |
141 | 139 | <header> |
142 | | - <h2>Touched</h2> |
143 | | - <p><code><hx-select-control hx-touched></code></p> |
144 | | - </header> |
145 | | - {{stateTables('touched', wasTouched=true)}} |
146 | | - </section> |
147 | | - |
148 | | - <section> |
149 | | - <header> |
150 | | - <h2>Styled Invalid (control-level)</h2> |
151 | | - <p><code>hx-select-control.hxInvalid</code></p> |
| 140 | + <h2 id="test-visually-invalid">Visually Invalid</h2> |
| 141 | + <code><hx-select-control class="hxInvalid"></code> |
152 | 142 | </header> |
153 | 143 | {{stateTables('invalid', className="hxInvalid")}} |
154 | 144 | </section> |
155 | 145 |
|
156 | | - <section class="hxInvalid"> |
157 | | - <header> |
158 | | - <h2>Styled Invalid (ancestor-level)</h2> |
159 | | - <p><code>.hxInvalid hx-select-control</code></p> |
160 | | - </header> |
161 | | - {{stateTables('ancestor-invalid')}} |
162 | | - </section> |
163 | | - |
164 | 146 | <section> |
165 | 147 | <header> |
166 | | - <h2>Layout</h2> |
| 148 | + <h2 id="test-layout">Layout</h2> |
167 | 149 | <p class="hxSubdued hxSubBody"> |
168 | 150 | <hx-icon type="info-circle"></hx-icon> |
169 | 151 | Extra elements should not be visible. |
@@ -249,7 +231,9 @@ <h2>Layout</h2> |
249 | 231 | </section> |
250 | 232 |
|
251 | 233 | <section> |
252 | | - <h2>Miscellaneous</h2> |
| 234 | + <header> |
| 235 | + <h2 id="test-misc">Miscellaneous</h2> |
| 236 | + </header> |
253 | 237 |
|
254 | 238 | <div class="hxRow"> |
255 | 239 | <div class="hxCol hxSpan-4"> |
|
0 commit comments