@solexllc/usx-react 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.cjs +3173 -3238
- package/dist/index.js +3174 -3239
- package/package.json +4 -4
- package/src/components/checkbox/Checkbox.tsx +9 -4
- package/src/components/checkbox/checkbox.django.html +2 -2
- package/src/components/checkbox/config.json +9 -0
- package/src/components/data-table/DataTable.tsx +177 -0
- package/src/components/data-table/README.md +42 -0
- package/src/components/data-table/TableBody.tsx +123 -0
- package/src/components/{table → data-table}/TableCell.tsx +6 -3
- package/src/components/data-table/TableContext.tsx +49 -0
- package/src/components/{table → data-table}/TableFoot.tsx +8 -7
- package/src/components/data-table/TableGroup.tsx +62 -0
- package/src/components/data-table/TableHead.tsx +126 -0
- package/src/components/data-table/TableRow.tsx +24 -0
- package/src/components/data-table/cells.ts +49 -0
- package/src/components/data-table/columns.ts +15 -0
- package/src/components/data-table/config.json +375 -0
- package/src/components/data-table/data-table.django-snapshot.html +13560 -0
- package/src/components/data-table/data-table.django.html +13 -0
- package/src/components/data-table/data-table.html +34 -0
- package/src/components/data-table/data-table.react-snapshot.html +12033 -0
- package/src/components/{table → data-table}/table-body.django.html +12 -12
- package/src/components/{table → data-table}/table-foot.django.html +6 -6
- package/src/components/data-table/table-group.django.html +24 -0
- package/src/components/data-table/table-head.django.html +21 -0
- package/src/components/data-table/table-row.django.html +57 -0
- package/src/components/{table → data-table}/types.ts +48 -5
- package/src/components/pagination/Pagination.tsx +7 -1
- package/src/components/pagination/config.json +8 -0
- package/src/components/pagination/navigation/PaginationNavigation.tsx +10 -0
- package/src/components/pagination/step-options/PaginationStepOptions.tsx +3 -0
- package/src/components/radio-buttons/RadioButtons.tsx +37 -27
- package/src/components/radio-buttons/config.json +19 -1
- package/src/components/radio-buttons/radio-buttons.django-snapshot.html +28 -60
- package/src/components/radio-buttons/radio-buttons.django.html +16 -28
- package/src/components/table/Table.tsx +64 -334
- package/src/components/table/config.json +21 -339
- package/src/components/table/table.django-snapshot.html +712 -1482
- package/src/components/table/table.django.html +14 -59
- package/src/components/table/table.html +7 -2364
- package/src/components/table/table.react-snapshot.html +711 -2085
- package/src/index.js +1 -0
- package/src/components/table/TableBody.tsx +0 -256
- package/src/components/table/TableContext.tsx +0 -87
- package/src/components/table/TableGroup.tsx +0 -69
- package/src/components/table/TableHead.tsx +0 -139
- package/src/components/table/TableRow.tsx +0 -56
- package/src/components/table/hooks/useRowDetails.ts +0 -34
- package/src/components/table/hooks/useTableGroups.ts +0 -61
- package/src/components/table/hooks/useTableSelect.ts +0 -82
- package/src/components/table/hooks/useTableSort.ts +0 -60
- package/src/components/table/table-group.django.html +0 -40
- package/src/components/table/table-head.django.html +0 -85
- package/src/components/table/table-row.django.html +0 -98
- package/src/components/table/table_helper.py +0 -298
- /package/src/components/{table → data-table}/table-detail-row.django.html +0 -0
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
{# ── Grouped mode: render one <tbody> per group (no nested tables) ───────── #}
|
|
26
26
|
{% if groups %}
|
|
27
27
|
{% for group in groups %}
|
|
28
|
-
{% table_group tableId=tableId groupKey=group.key label=group.key rows=group.rows leaf_columns=leaf_columns total_cols=total_cols primaryKey=primaryKey select=select disabled=disabled selectionMode=selectionMode selectionPosition=selectionPosition onClickRow=onClickRow rowUrlField=rowUrlField rowDetails=rowDetails rowDetailTemplate=rowDetailTemplate rowDetailField=rowDetailField expandedRows=expandedRows responsive=responsive defaultExpanded=defaultExpanded %}{% endtable_group %}
|
|
28
|
+
{% table_group tableId=tableId groupKey=group.key label=group.key rows=group.rows groupCells=group.groupCells leaf_columns=leaf_columns total_cols=total_cols primaryKey=primaryKey select=select disabled=disabled selectionMode=selectionMode selectionPosition=selectionPosition selectionVerticalAlign=selectionVerticalAlign onClickRow=onClickRow rowUrlField=rowUrlField rowDetails=rowDetails rowDetailTemplate=rowDetailTemplate rowDetailField=rowDetailField expandedRows=expandedRows responsive=responsive defaultExpanded=defaultExpanded groupRowClassName=groupRowClassName %}{% endtable_group %}
|
|
29
29
|
{% endfor %}
|
|
30
30
|
|
|
31
31
|
{% if loading %}
|
|
32
|
-
<tbody class="usx-table__body usx-table__body--loading">
|
|
33
|
-
<tr class="usx-table__loading-row" aria-live="polite">
|
|
34
|
-
<td class="usx-table__loading-cell" colspan="{{ total_cols|default:1 }}">
|
|
35
|
-
|
|
32
|
+
<tbody class="usx-data-table__body usx-data-table__body--loading">
|
|
33
|
+
<tr class="usx-data-table__loading-row" aria-live="polite">
|
|
34
|
+
<td class="usx-data-table__loading-cell" colspan="{{ total_cols|default:1 }}">
|
|
35
|
+
Loading more rows…
|
|
36
36
|
</td>
|
|
37
37
|
</tr>
|
|
38
38
|
</tbody>
|
|
@@ -40,26 +40,26 @@
|
|
|
40
40
|
|
|
41
41
|
{# ── Flat / empty mode: single tbody ─────────────────────────────────────── #}
|
|
42
42
|
{% else %}
|
|
43
|
-
<tbody class="usx-table__body">
|
|
43
|
+
<tbody class="usx-data-table__body">
|
|
44
44
|
|
|
45
45
|
{% if not data %}
|
|
46
46
|
{% if placeholder %}
|
|
47
|
-
<tr class="usx-table__placeholder-row">
|
|
48
|
-
<td class="usx-table__placeholder-cell" colspan="{{ total_cols|default:1 }}">
|
|
47
|
+
<tr class="usx-data-table__placeholder-row">
|
|
48
|
+
<td class="usx-data-table__placeholder-cell" colspan="{{ total_cols|default:1 }}">
|
|
49
49
|
{{ placeholder }}
|
|
50
50
|
</td>
|
|
51
51
|
</tr>
|
|
52
52
|
{% endif %}
|
|
53
53
|
{% else %}
|
|
54
54
|
{% for row in data %}
|
|
55
|
-
{% table_row row=row rowIndex=forloop.counter0 leaf_columns=leaf_columns total_cols=total_cols primaryKey=primaryKey select=select disabled=disabled selectionMode=selectionMode selectionPosition=selectionPosition onClickRow=onClickRow rowUrlField=rowUrlField rowDetails=rowDetails rowDetailTemplate=rowDetailTemplate rowDetailField=rowDetailField expandedRows=expandedRows responsive=responsive %}{% endtable_row %}
|
|
55
|
+
{% table_row tableId=tableId row=row rowIndex=forloop.counter0 leaf_columns=leaf_columns total_cols=total_cols primaryKey=primaryKey select=select disabled=disabled selectionMode=selectionMode selectionPosition=selectionPosition selectionVerticalAlign=selectionVerticalAlign onClickRow=onClickRow rowUrlField=rowUrlField rowDetails=rowDetails rowDetailTemplate=rowDetailTemplate rowDetailField=rowDetailField expandedRows=expandedRows responsive=responsive %}{% endtable_row %}
|
|
56
56
|
{% endfor %}
|
|
57
57
|
{% endif %}
|
|
58
58
|
|
|
59
59
|
{% if loading %}
|
|
60
|
-
<tr class="usx-table__loading-row" aria-live="polite">
|
|
61
|
-
<td class="usx-table__loading-cell" colspan="{{ total_cols|default:1 }}">
|
|
62
|
-
|
|
60
|
+
<tr class="usx-data-table__loading-row" aria-live="polite">
|
|
61
|
+
<td class="usx-data-table__loading-cell" colspan="{{ total_cols|default:1 }}">
|
|
62
|
+
Loading more rows…
|
|
63
63
|
</td>
|
|
64
64
|
</tr>
|
|
65
65
|
{% endif %}
|
|
@@ -7,23 +7,23 @@
|
|
|
7
7
|
{# rowDetails truthy when row-detail column is present #}
|
|
8
8
|
{# ──────────────────────────────────────────────────────────────────────────────── #}
|
|
9
9
|
|
|
10
|
-
<tfoot class="usx-table__foot">
|
|
11
|
-
<tr class="usx-table__foot-row">
|
|
10
|
+
<tfoot class="usx-data-table__foot">
|
|
11
|
+
<tr class="usx-data-table__foot-row">
|
|
12
12
|
|
|
13
13
|
{# Empty cell for row-detail column #}
|
|
14
14
|
{% if rowDetails %}
|
|
15
|
-
<td class="usx-table__cell"></td>
|
|
15
|
+
<td class="usx-data-table__cell"></td>
|
|
16
16
|
{% endif %}
|
|
17
17
|
|
|
18
18
|
{# Empty cell for selection column #}
|
|
19
19
|
{% if selectionMode and selectionMode != "null" %}
|
|
20
|
-
<td class="usx-table__cell usx-table__cell--selection"></td>
|
|
20
|
+
<td class="usx-data-table__cell usx-data-table__cell--selection"></td>
|
|
21
21
|
{% endif %}
|
|
22
22
|
|
|
23
23
|
{# Footer values per leaf column #}
|
|
24
24
|
{% for col in leaf_columns %}
|
|
25
|
-
<td class="usx-table__cell{% if col.align %} usx-table__cell--align-{{ col.align }}{% endif %}">
|
|
26
|
-
{
|
|
25
|
+
<td class="usx-data-table__cell{% if col.align %} usx-data-table__cell--align-{{ col.align }}{% endif %}">
|
|
26
|
+
{{ footerValues|get_item:col.key }}
|
|
27
27
|
</td>
|
|
28
28
|
{% endfor %}
|
|
29
29
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{% load static components usx_components %}
|
|
2
|
+
{% with expanded=defaultExpanded|default_bool:True %}
|
|
3
|
+
<tbody class="usx-data-table__group usx-data-table__group--header">
|
|
4
|
+
<tr class="usx-data-table__group-row{% if groupRowClassName %} {{ groupRowClassName }}{% endif %}">
|
|
5
|
+
{% if groupCells %}
|
|
6
|
+
{% if rowDetails %}<td class="usx-data-table__group-cell"></td>{% endif %}
|
|
7
|
+
{% if selectionMode and selectionPosition != 'right' %}<td class="usx-data-table__group-cell"></td>{% endif %}
|
|
8
|
+
{% for cell in groupCells %}{% with column=cell.column options=cell.options %}
|
|
9
|
+
{% if forloop.first %}<th scope="row"{% else %}<td{% endif %} class="usx-data-table__group-cell{% if options.align %} usx-data-table__cell--align-{{ options.align }}{% elif column.align %} usx-data-table__cell--align-{{ column.align }}{% endif %}{% if options.verticalAlign %} usx-data-table__cell--valign-{{ options.verticalAlign }}{% elif column.verticalAlign %} usx-data-table__cell--valign-{{ column.verticalAlign }}{% endif %}{% if column.className %} {{ column.className }}{% endif %}"{% if options.colSpan %} colspan="{{ options.colSpan }}"{% elif column.colSpan %} colspan="{{ column.colSpan }}"{% endif %}{% if options.backgroundColor or column.backgroundColor or options.color or column.color %} style="{% if options.backgroundColor %}background-color: {{ options.backgroundColor }};{% elif column.backgroundColor %}background-color: {{ column.backgroundColor }};{% endif %}{% if options.color %}color: {{ options.color }};{% elif column.color %}color: {{ column.color }};{% endif %}"{% endif %}>
|
|
10
|
+
{% if forloop.first %}<button type="button" class="usx-data-table__group-toggle" aria-expanded="{{ expanded|yesno:'true,false' }}" aria-controls="{{ tableId }}-group-{{ groupKey }}-content">{{ cell.value }}</button>{% else %}{% if options.align == 'center' or not options.align and column.align == 'center' %}<div class="usx-data-table__cell-content">{% endif %}{{ cell.value }}{% if options.align == 'center' or not options.align and column.align == 'center' %}</div>{% endif %}{% endif %}
|
|
11
|
+
{% if forloop.first %}</th>{% else %}</td>{% endif %}
|
|
12
|
+
{% endwith %}{% endfor %}
|
|
13
|
+
{% if selectionMode and selectionPosition == 'right' %}<td class="usx-data-table__group-cell"></td>{% endif %}
|
|
14
|
+
{% else %}
|
|
15
|
+
<th scope="row" colspan="{{ total_cols|default:1 }}" class="usx-data-table__group-cell"><button type="button" class="usx-data-table__group-toggle" aria-expanded="{{ expanded|yesno:'true,false' }}" aria-controls="{{ tableId }}-group-{{ groupKey }}-content">{{ label }}</button></th>
|
|
16
|
+
{% endif %}
|
|
17
|
+
</tr>
|
|
18
|
+
</tbody>
|
|
19
|
+
<tbody class="usx-data-table__group usx-data-table__group--content" id="{{ tableId }}-group-{{ groupKey }}-content"{% if not expanded %} hidden{% endif %}>
|
|
20
|
+
{% for row in rows %}
|
|
21
|
+
{% table_row row=row rowIndex=forloop.counter0 leaf_columns=leaf_columns total_cols=total_cols primaryKey=primaryKey select=select disabled=disabled selectionMode=selectionMode selectionPosition=selectionPosition selectionVerticalAlign=selectionVerticalAlign onClickRow=onClickRow rowUrlField=rowUrlField rowDetails=rowDetails rowDetailTemplate=rowDetailTemplate rowDetailField=rowDetailField expandedRows=expandedRows responsive=responsive tableId=tableId %}{% endtable_row %}
|
|
22
|
+
{% endfor %}
|
|
23
|
+
</tbody>
|
|
24
|
+
{% endwith %}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{% load components %}
|
|
2
|
+
<thead class="usx-data-table__head">
|
|
3
|
+
{% if groupHeaders %}
|
|
4
|
+
<tr class="usx-data-table__head-row usx-data-table__head-row--groups">
|
|
5
|
+
{% if rowDetails %}<th scope="col" rowspan="{{ total_depth|add:1 }}" class="usx-data-table__cell usx-data-table__cell--detail-toggle">Details</th>{% endif %}
|
|
6
|
+
{% if selectionMode and selectionPosition != 'right' %}<th scope="col" rowspan="{{ total_depth|add:1 }}" class="usx-data-table__cell usx-data-table__cell--selection usx-data-table__cell--valign-{{ selectionVerticalAlign }}">{% if selectionMode == 'checkbox' %}{% checkbox id=tableId|add:'-select-all' label='' ariaLabel='Select all rows' small=True formGroup=False %}{% endcheckbox %}{% endif %}</th>{% endif %}
|
|
7
|
+
{% for column in groupHeaders %}<th scope="col" class="usx-data-table__cell{% if column.align %} usx-data-table__cell--align-{{ column.align }}{% endif %}{% if column.verticalAlign %} usx-data-table__cell--valign-{{ column.verticalAlign }}{% endif %}{% if column.className %} {{ column.className }}{% endif %}"{% if column.colSpan > 1 %} colspan="{{ column.colSpan }}"{% endif %}{% if column.backgroundColor or column.color %} style="{% if column.backgroundColor %}background-color: {{ column.backgroundColor }};{% endif %}{% if column.color %} color: {{ column.color }};{% endif %}"{% endif %}>{{ column.header }}</th>{% endfor %}
|
|
8
|
+
{% if selectionMode and selectionPosition == 'right' %}<th scope="col" rowspan="{{ total_depth|add:1 }}" class="usx-data-table__cell usx-data-table__cell--selection usx-data-table__cell--valign-{{ selectionVerticalAlign }}">{% if selectionMode == 'checkbox' %}{% checkbox id=tableId|add:'-select-all' label='' ariaLabel='Select all rows' small=True formGroup=False %}{% endcheckbox %}{% endif %}</th>{% endif %}
|
|
9
|
+
</tr>
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% for header_row in header_rows %}
|
|
12
|
+
<tr class="usx-data-table__head-row">
|
|
13
|
+
{% if forloop.first and not groupHeaders and rowDetails %}<th scope="col" class="usx-data-table__cell usx-data-table__cell--detail-toggle" aria-label="Row details"{% if total_depth > 1 %} rowspan="{{ total_depth }}"{% endif %}></th>{% endif %}
|
|
14
|
+
{% if forloop.first and not groupHeaders and selectionMode and selectionPosition != 'right' %}<th scope="col" class="usx-data-table__cell usx-data-table__cell--selection usx-data-table__cell--valign-{{ selectionVerticalAlign }}"{% if total_depth > 1 %} rowspan="{{ total_depth }}"{% endif %}>{% if selectionMode == 'checkbox' %}{% checkbox id=tableId|add:'-select-all' label='' ariaLabel='Select all rows' small=True formGroup=False %}{% endcheckbox %}{% endif %}</th>{% endif %}
|
|
15
|
+
{% for cell in header_row %}{% with column=cell.col %}
|
|
16
|
+
<th scope="col" class="usx-data-table__cell{% if column.headerAlign %} usx-data-table__cell--align-{{ column.headerAlign }}{% elif column.align %} usx-data-table__cell--align-{{ column.align }}{% endif %}{% if column.headerClassName %} {{ column.headerClassName }}{% endif %}"{% if cell.row_span > 1 %} rowspan="{{ cell.row_span }}"{% endif %}{% if cell.col_span > 1 %} colspan="{{ cell.col_span }}"{% endif %}{% if column.sortable and not column.columns %} data-usx-sortable="true"{% endif %} data-column-key="{{ column.key }}"{% if column.headerBackgroundColor or column.headerColor or column.width %} style="{% if column.headerBackgroundColor %}background-color: {{ column.headerBackgroundColor }};{% endif %}{% if column.headerColor %} color: {{ column.headerColor }};{% endif %}{% if column.width %} width: {{ column.width }};{% endif %}"{% endif %}>{{ column.header }}</th>
|
|
17
|
+
{% endwith %}{% endfor %}
|
|
18
|
+
{% if forloop.first and not groupHeaders and selectionMode and selectionPosition == 'right' %}<th scope="col" class="usx-data-table__cell usx-data-table__cell--selection usx-data-table__cell--valign-{{ selectionVerticalAlign }}"{% if total_depth > 1 %} rowspan="{{ total_depth }}"{% endif %}>{% if selectionMode == 'checkbox' %}{% checkbox id=tableId|add:'-select-all' label='' ariaLabel='Select all rows' small=True formGroup=False %}{% endcheckbox %}{% endif %}</th>{% endif %}
|
|
19
|
+
</tr>
|
|
20
|
+
{% endfor %}
|
|
21
|
+
</thead>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{% load static components usx_components %}
|
|
2
|
+
{% with pk=row|get_item:primaryKey %}
|
|
3
|
+
{% with pk_string=pk|stringformat:'s' %}
|
|
4
|
+
<tr class="usx-data-table__row{% if pk in select %} usx-data-table__row--selected{% endif %}{% if pk in disabled %} usx-data-table__row--disabled{% endif %}{% if onClickRow and not pk in disabled %} usx-data-table__row--clickable{% endif %}{% if row.rowProps.className %} {{ row.rowProps.className }}{% endif %}" data-row-key="{{ pk }}" data-search-value="{{ row.usxSearchText }}"{% if row.rowProps.backgroundColor or row.rowProps.color %} style="{% if row.rowProps.backgroundColor %}--usx-data-table-row-bg: {{ row.rowProps.backgroundColor }};{% endif %}{% if row.rowProps.color %} color: {{ row.rowProps.color }};{% endif %}"{% endif %}>
|
|
5
|
+
{% if rowDetails and rowDetails != 'null' %}
|
|
6
|
+
<td class="usx-data-table__cell usx-data-table__cell--detail-toggle">
|
|
7
|
+
{% with isExpanded=expandedRows|contains:pk %}
|
|
8
|
+
{% dict aria_expanded=isExpanded aria_controls=tableId|add:'-row-detail-'|add:pk_string aria_label=isExpanded|yesno:'Collapse row details,Expand row details' as detailAttributes %}
|
|
9
|
+
{% button variant='unstyled' className='usx-data-table__detail-toggle' extraAttributes=detailAttributes %}
|
|
10
|
+
{% icon name='expand_more' size=2 staticBaseUrl=staticBaseUrl %}{% endicon %}
|
|
11
|
+
{% endbutton %}
|
|
12
|
+
{% endwith %}
|
|
13
|
+
</td>
|
|
14
|
+
{% endif %}
|
|
15
|
+
|
|
16
|
+
{% if selectionMode and selectionMode != 'null' and selectionPosition != 'right' %}
|
|
17
|
+
<td class="usx-data-table__cell usx-data-table__cell--selection usx-data-table__cell--valign-{{ selectionVerticalAlign }}">
|
|
18
|
+
{% if selectionMode == 'radio' %}
|
|
19
|
+
{% dict id=tableId|add:'-select-'|add:pk_string value=pk_string label='' ariaLabel=row.usxSelectionLabel checked=select|contains:pk disabled=disabled|contains:pk as option %}
|
|
20
|
+
{% make_list option as options %}
|
|
21
|
+
{% radio_buttons name=tableId|add:'-selection' options=options fieldset=False small=True formGroup=False %}{% endradio_buttons %}
|
|
22
|
+
{% else %}
|
|
23
|
+
{% checkbox id=tableId|add:'-select-'|add:pk_string name=tableId|add:'-selection' value=pk_string label='' ariaLabel=row.usxSelectionLabel checked=select|contains:pk disabled=disabled|contains:pk small=True formGroup=False %}{% endcheckbox %}
|
|
24
|
+
{% endif %}
|
|
25
|
+
</td>
|
|
26
|
+
{% endif %}
|
|
27
|
+
|
|
28
|
+
{% for cell in row.usxCells %}{% with col=cell.column options=cell.options %}
|
|
29
|
+
{% if col.primary %}<th scope="{% if cell.row_span > 1 %}rowgroup{% else %}row{% endif %}"{% else %}<td{% endif %}
|
|
30
|
+
class="usx-data-table__cell{% if options.align %} usx-data-table__cell--align-{{ options.align }}{% elif col.align %} usx-data-table__cell--align-{{ col.align }}{% endif %}{% if options.verticalAlign %} usx-data-table__cell--valign-{{ options.verticalAlign }}{% elif col.verticalAlign %} usx-data-table__cell--valign-{{ col.verticalAlign }}{% endif %}{% if cell.class_name %} {{ cell.class_name }}{% endif %}"
|
|
31
|
+
data-column-key="{{ col.key }}"
|
|
32
|
+
{% if cell.sort_value != None %}data-sort-value="{{ cell.sort_value }}"{% endif %}
|
|
33
|
+
{% if cell.col_span > 1 %}colspan="{{ cell.col_span }}"{% endif %}
|
|
34
|
+
{% if cell.row_span > 1 %}rowspan="{{ cell.row_span }}"{% endif %}
|
|
35
|
+
{% if responsive == 'stack' or responsive == 'stack-header' %}{% if col.stackLabel or col.header %}data-label="{{ col.stackLabel|default:col.header }}"{% endif %}{% endif %}
|
|
36
|
+
{% if col.width or options.backgroundColor or col.backgroundColor or options.color or col.color %}style="{% if col.width %}width: {{ col.width }};{% endif %}{% if options.backgroundColor %}background-color: {{ options.backgroundColor }};{% elif col.backgroundColor %}background-color: {{ col.backgroundColor }};{% endif %}{% if options.color %}color: {{ options.color }};{% elif col.color %}color: {{ col.color }};{% endif %}"{% endif %}
|
|
37
|
+
>{% if options.align == 'center' or not options.align and col.align == 'center' %}<div class="usx-data-table__cell-content">{% endif %}{{ row|get_item:col.key|default_if_none:'--' }}{% if options.align == 'center' or not options.align and col.align == 'center' %}</div>{% endif %}{% if col.primary %}</th>{% else %}</td>{% endif %}
|
|
38
|
+
{% endwith %}{% endfor %}
|
|
39
|
+
|
|
40
|
+
{% if selectionMode and selectionMode != 'null' and selectionPosition == 'right' %}
|
|
41
|
+
<td class="usx-data-table__cell usx-data-table__cell--selection usx-data-table__cell--valign-{{ selectionVerticalAlign }}">
|
|
42
|
+
{% if selectionMode == 'radio' %}
|
|
43
|
+
{% dict id=tableId|add:'-select-'|add:pk_string value=pk_string label='' ariaLabel=row.usxSelectionLabel checked=select|contains:pk disabled=disabled|contains:pk as option %}
|
|
44
|
+
{% make_list option as options %}
|
|
45
|
+
{% radio_buttons name=tableId|add:'-selection' options=options fieldset=False small=True formGroup=False %}{% endradio_buttons %}
|
|
46
|
+
{% else %}
|
|
47
|
+
{% checkbox id=tableId|add:'-select-'|add:pk_string name=tableId|add:'-selection' value=pk_string label='' ariaLabel=row.usxSelectionLabel checked=select|contains:pk disabled=disabled|contains:pk small=True formGroup=False %}{% endcheckbox %}
|
|
48
|
+
{% endif %}
|
|
49
|
+
</td>
|
|
50
|
+
{% endif %}
|
|
51
|
+
</tr>
|
|
52
|
+
{% if rowDetails and rowDetails != 'null' %}
|
|
53
|
+
<tr id="{{ tableId }}-row-detail-{{ pk }}" class="usx-data-table__detail-row"{% if not pk in expandedRows %} hidden{% endif %}>
|
|
54
|
+
<td colspan="{{ total_cols|default:1 }}" class="usx-data-table__detail-cell">{% if rowDetailField %}{{ row|get_item:rowDetailField }}{% endif %}</td>
|
|
55
|
+
</tr>
|
|
56
|
+
{% endif %}
|
|
57
|
+
{% endwith %}{% endwith %}
|
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
-
export type TableRowData = Record<string, unknown>;
|
|
4
3
|
export type RowKey = string | number;
|
|
5
4
|
export type Align = 'left' | 'center' | 'right';
|
|
5
|
+
export type VerticalAlign = 'top' | 'middle' | 'bottom';
|
|
6
6
|
export type SortDirection = 'asc' | 'desc' | null;
|
|
7
7
|
export type SelectionMode = 'checkbox' | 'radio' | null;
|
|
8
8
|
export type Responsive = false | 'stack' | 'stack-header';
|
|
9
9
|
export type Aggregate = 'sum' | 'avg' | 'min' | 'max' | 'count';
|
|
10
10
|
|
|
11
|
+
export interface CellOptions {
|
|
12
|
+
colSpan?: number;
|
|
13
|
+
rowSpan?: number;
|
|
14
|
+
align?: Align;
|
|
15
|
+
verticalAlign?: VerticalAlign;
|
|
16
|
+
backgroundColor?: string;
|
|
17
|
+
color?: string;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RowOptions {
|
|
22
|
+
backgroundColor?: string;
|
|
23
|
+
color?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TableRowData extends Record<string, unknown> {
|
|
28
|
+
rowProps?: RowOptions;
|
|
29
|
+
cellProps?: Record<string, CellOptions>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface GroupColumn extends Omit<CellOptions, 'rowSpan'> {
|
|
33
|
+
key: string;
|
|
34
|
+
header: ReactNode;
|
|
35
|
+
/** The first group column displays the group key unless a value is supplied. */
|
|
36
|
+
render?: (group: TableGroupEntry) => ReactNode;
|
|
37
|
+
}
|
|
38
|
+
|
|
11
39
|
export interface SortState {
|
|
12
40
|
key: string | null;
|
|
13
41
|
direction: SortDirection;
|
|
@@ -21,16 +49,26 @@ export interface TableColumn {
|
|
|
21
49
|
render?: (row: TableRowData, rowIndex: number) => ReactNode;
|
|
22
50
|
footer?: ReactNode | ((data: TableRowData[]) => ReactNode);
|
|
23
51
|
align?: Align;
|
|
52
|
+
verticalAlign?: VerticalAlign;
|
|
24
53
|
headerAlign?: Align;
|
|
25
54
|
sortable?: boolean;
|
|
26
|
-
sortFn?: (a: TableRowData, b: TableRowData, direction: SortDirection) => number;
|
|
27
55
|
width?: string | number;
|
|
28
56
|
minWidth?: string;
|
|
29
57
|
/** Render body cells as row-header `<th scope="row">`. */
|
|
30
58
|
primary?: boolean;
|
|
31
59
|
hidden?: boolean;
|
|
60
|
+
/** Exclude this column from client-side search. */
|
|
61
|
+
filterable?: boolean;
|
|
62
|
+
/** Text used by client-side search when the displayed value is computed. */
|
|
63
|
+
searchValue?: (row: TableRowData) => unknown;
|
|
64
|
+
/** Comparable value serialized into each cell for the shared JS sorter. */
|
|
65
|
+
sortValue?: (row: TableRowData) => string | number;
|
|
32
66
|
className?: string;
|
|
33
67
|
headerClassName?: string;
|
|
68
|
+
backgroundColor?: string;
|
|
69
|
+
color?: string;
|
|
70
|
+
headerBackgroundColor?: string;
|
|
71
|
+
headerColor?: string;
|
|
34
72
|
aggregate?: Aggregate;
|
|
35
73
|
/** data-label for stacked/responsive layouts when `header` isn't a plain string. */
|
|
36
74
|
stackLabel?: string;
|
|
@@ -38,8 +76,15 @@ export interface TableColumn {
|
|
|
38
76
|
|
|
39
77
|
export interface GroupByConfig {
|
|
40
78
|
property: string;
|
|
79
|
+
/** Header band above the regular column headers. Defaults to columns for compatibility. */
|
|
80
|
+
headers?: GroupColumn[];
|
|
81
|
+
/** Cells displayed within each grouped row. */
|
|
82
|
+
columns?: GroupColumn[];
|
|
83
|
+
/** Classes applied to every grouped row, including bg-* and text-* utilities. */
|
|
84
|
+
rowClassName?: string;
|
|
85
|
+
/** Additional values for each group row, keyed by group key then column key. */
|
|
86
|
+
values?: Record<string, Record<string, unknown>>;
|
|
41
87
|
expand?: RowKey[];
|
|
42
|
-
onExpand?: (expanded: RowKey[]) => void;
|
|
43
88
|
defaultExpanded?: boolean;
|
|
44
89
|
}
|
|
45
90
|
export type GroupBy = string | GroupByConfig | null | undefined;
|
|
@@ -47,7 +92,6 @@ export type GroupBy = string | GroupByConfig | null | undefined;
|
|
|
47
92
|
export interface RowDetailsConfig {
|
|
48
93
|
render?: (row: TableRowData) => ReactNode;
|
|
49
94
|
expand?: RowKey[];
|
|
50
|
-
onExpand?: (expanded: RowKey[]) => void;
|
|
51
95
|
expandLabel?: string | ((row: TableRowData) => string);
|
|
52
96
|
}
|
|
53
97
|
export type RowDetails = ((row: TableRowData) => ReactNode) | RowDetailsConfig | null | undefined;
|
|
@@ -57,7 +101,6 @@ export interface PaginateConfig {
|
|
|
57
101
|
pageSizeOptions?: number[];
|
|
58
102
|
/** Total item count — enables server-side mode. */
|
|
59
103
|
totalCount?: number;
|
|
60
|
-
onPageChange?: (page: number, pageSize: number) => void;
|
|
61
104
|
showStepOptions?: boolean;
|
|
62
105
|
showSummary?: boolean;
|
|
63
106
|
}
|
|
@@ -25,6 +25,8 @@ export interface PaginationProps {
|
|
|
25
25
|
arrowsOnly?: boolean;
|
|
26
26
|
pageUrlPrefix?: string;
|
|
27
27
|
className?: string;
|
|
28
|
+
onPageChange?: (page: number) => void;
|
|
29
|
+
onPageSizeChange?: (size: number) => void;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export default function Pagination({
|
|
@@ -47,13 +49,15 @@ export default function Pagination({
|
|
|
47
49
|
arrowsOnly = false,
|
|
48
50
|
pageUrlPrefix,
|
|
49
51
|
className = '',
|
|
52
|
+
onPageChange,
|
|
53
|
+
onPageSizeChange,
|
|
50
54
|
}: PaginationProps) {
|
|
51
55
|
const currentPage = page ?? initialPage;
|
|
52
56
|
const pageSize = size ?? initialPageSize;
|
|
53
57
|
|
|
54
58
|
const totalPages =
|
|
55
59
|
totalItems !== undefined && !unbounded
|
|
56
|
-
? Math.ceil(totalItems / pageSize)
|
|
60
|
+
? Math.max(1, Math.ceil(totalItems / pageSize))
|
|
57
61
|
: undefined;
|
|
58
62
|
|
|
59
63
|
// showSummary defaults to true when totalItems is provided
|
|
@@ -73,6 +77,7 @@ export default function Pagination({
|
|
|
73
77
|
hideLinkText={hideLinkText}
|
|
74
78
|
arrowsOnly={arrowsOnly}
|
|
75
79
|
pageUrlPrefix={pageUrlPrefix}
|
|
80
|
+
onPageChange={onPageChange}
|
|
76
81
|
/>
|
|
77
82
|
);
|
|
78
83
|
const stepOptions = (
|
|
@@ -80,6 +85,7 @@ export default function Pagination({
|
|
|
80
85
|
pageSize={pageSize}
|
|
81
86
|
pageSizeOptions={pageSizeOptions}
|
|
82
87
|
id={stepOptionsId}
|
|
88
|
+
onPageSizeChange={onPageSizeChange}
|
|
83
89
|
/>
|
|
84
90
|
);
|
|
85
91
|
const summary = typeof totalItems === 'number' ? (
|
|
@@ -175,6 +175,14 @@
|
|
|
175
175
|
"default": "pagination-step-options",
|
|
176
176
|
"description": "HTML id for the step options select element"
|
|
177
177
|
},
|
|
178
|
+
"onPageChange": {
|
|
179
|
+
"type": "function",
|
|
180
|
+
"description": "React-only callback for client-side page navigation."
|
|
181
|
+
},
|
|
182
|
+
"onPageSizeChange": {
|
|
183
|
+
"type": "function",
|
|
184
|
+
"description": "React-only callback when the page size changes."
|
|
185
|
+
},
|
|
178
186
|
"className": {
|
|
179
187
|
"type": "string",
|
|
180
188
|
"default": "",
|
|
@@ -14,6 +14,7 @@ export interface PaginationNavigationProps {
|
|
|
14
14
|
arrowsOnly?: boolean;
|
|
15
15
|
pageUrlPrefix?: string;
|
|
16
16
|
className?: string;
|
|
17
|
+
onPageChange?: (page: number) => void;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export function getPageItems(currentPage: number, totalPages: number) {
|
|
@@ -76,6 +77,7 @@ export default function PaginationNavigation({
|
|
|
76
77
|
arrowsOnly = false,
|
|
77
78
|
pageUrlPrefix,
|
|
78
79
|
className = '',
|
|
80
|
+
onPageChange,
|
|
79
81
|
}: PaginationNavigationProps) {
|
|
80
82
|
const unbounded = totalPages === undefined || totalPages === null;
|
|
81
83
|
const items = unbounded
|
|
@@ -85,6 +87,11 @@ export default function PaginationNavigation({
|
|
|
85
87
|
const isFirstPage = currentPage === 1;
|
|
86
88
|
const isLastPage = !unbounded && currentPage === totalPages;
|
|
87
89
|
const hrefFor = (page: number) => pageUrlPrefix ? `${pageUrlPrefix}${page}` : '#';
|
|
90
|
+
const goTo = (event: React.MouseEvent<HTMLAnchorElement>, page: number) => {
|
|
91
|
+
if (!onPageChange) return;
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
if (page >= 1 && (unbounded || page <= totalPages!)) onPageChange(page);
|
|
94
|
+
};
|
|
88
95
|
|
|
89
96
|
const navClasses = ClassNames(
|
|
90
97
|
'usa-pagination',
|
|
@@ -112,6 +119,7 @@ export default function PaginationNavigation({
|
|
|
112
119
|
}
|
|
113
120
|
>
|
|
114
121
|
<a
|
|
122
|
+
onClick={(event) => goTo(event, currentPage - 1)}
|
|
115
123
|
href={isFirstPage ? '#' : hrefFor(currentPage - 1)}
|
|
116
124
|
data-usx-pagination-page={currentPage - 1}
|
|
117
125
|
className={
|
|
@@ -153,6 +161,7 @@ export default function PaginationNavigation({
|
|
|
153
161
|
return (
|
|
154
162
|
<li key={item.page} className="usa-pagination__item usa-pagination__page-no">
|
|
155
163
|
<a
|
|
164
|
+
onClick={(event) => goTo(event, item.page)}
|
|
156
165
|
href={hrefFor(item.page)}
|
|
157
166
|
data-usx-pagination-page={item.page}
|
|
158
167
|
className={
|
|
@@ -179,6 +188,7 @@ export default function PaginationNavigation({
|
|
|
179
188
|
}
|
|
180
189
|
>
|
|
181
190
|
<a
|
|
191
|
+
onClick={(event) => goTo(event, currentPage + 1)}
|
|
182
192
|
href={isLastPage ? '#' : hrefFor(currentPage + 1)}
|
|
183
193
|
data-usx-pagination-page={currentPage + 1}
|
|
184
194
|
className={
|
|
@@ -8,6 +8,7 @@ export interface PaginationStepOptionsProps {
|
|
|
8
8
|
label?: string;
|
|
9
9
|
id?: string;
|
|
10
10
|
className?: string;
|
|
11
|
+
onPageSizeChange?: (size: number) => void;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export default function PaginationStepOptions({
|
|
@@ -16,6 +17,7 @@ export default function PaginationStepOptions({
|
|
|
16
17
|
label = 'Items per page',
|
|
17
18
|
id = 'pagination-step-options',
|
|
18
19
|
className = '',
|
|
20
|
+
onPageSizeChange,
|
|
19
21
|
}: PaginationStepOptionsProps) {
|
|
20
22
|
const classes = ClassNames(
|
|
21
23
|
'usx-pagination__step-options',
|
|
@@ -31,6 +33,7 @@ export default function PaginationStepOptions({
|
|
|
31
33
|
defaultValue={String(pageSize)}
|
|
32
34
|
formGroup={false}
|
|
33
35
|
options={pageSizeOptions.map((size) => ({ value: String(size), label: String(size) }))}
|
|
36
|
+
onChange={(event) => onPageSizeChange?.(Number(event.target.value))}
|
|
34
37
|
/>
|
|
35
38
|
</div>
|
|
36
39
|
);
|
|
@@ -8,12 +8,13 @@ export interface RadioOption {
|
|
|
8
8
|
id?: string;
|
|
9
9
|
value: string;
|
|
10
10
|
label: React.ReactNode;
|
|
11
|
+
ariaLabel?: string;
|
|
11
12
|
description?: React.ReactNode;
|
|
12
13
|
checked?: boolean;
|
|
13
14
|
disabled?: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export interface RadioButtonsProps extends React.HTMLAttributes<HTMLFieldSetElement> {
|
|
17
|
+
export interface RadioButtonsProps extends Omit<React.HTMLAttributes<HTMLFieldSetElement>, 'onChange'> {
|
|
17
18
|
tile?: boolean;
|
|
18
19
|
small?: boolean;
|
|
19
20
|
legend?: string;
|
|
@@ -23,6 +24,10 @@ export interface RadioButtonsProps extends React.HTMLAttributes<HTMLFieldSetElem
|
|
|
23
24
|
name?: string;
|
|
24
25
|
options: RadioOption[];
|
|
25
26
|
defaultValue?: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
29
|
+
formGroup?: boolean;
|
|
30
|
+
fieldset?: boolean;
|
|
26
31
|
className?: string;
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -37,6 +42,10 @@ const RadioButtons: React.FC<RadioButtonsProps> = ({
|
|
|
37
42
|
id: groupId,
|
|
38
43
|
options = [],
|
|
39
44
|
defaultValue = undefined,
|
|
45
|
+
value,
|
|
46
|
+
onChange,
|
|
47
|
+
formGroup = true,
|
|
48
|
+
fieldset = true,
|
|
40
49
|
className = '',
|
|
41
50
|
...props
|
|
42
51
|
}) => {
|
|
@@ -44,8 +53,30 @@ const RadioButtons: React.FC<RadioButtonsProps> = ({
|
|
|
44
53
|
|
|
45
54
|
const inputClasses = classNames('usa-radio__input', { 'usa-radio__input--tile': tile });
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
const optionsMarkup = options.map((opt, idx) => {
|
|
57
|
+
const id = opt.id || `${groupId || name}-${idx}`;
|
|
58
|
+
return (
|
|
59
|
+
<div className={classes} key={id}>
|
|
60
|
+
<input
|
|
61
|
+
className={inputClasses}
|
|
62
|
+
id={id}
|
|
63
|
+
type="radio"
|
|
64
|
+
name={name}
|
|
65
|
+
value={opt.value}
|
|
66
|
+
aria-label={opt.ariaLabel}
|
|
67
|
+
{...(value !== undefined && onChange ? { checked: value === opt.value } : { defaultChecked: defaultValue === opt.value || !!opt.checked })}
|
|
68
|
+
onChange={onChange}
|
|
69
|
+
disabled={!!opt.disabled}
|
|
70
|
+
/>
|
|
71
|
+
<Label className="usa-radio__label" classOverride={true} htmlFor={id}>
|
|
72
|
+
{opt.label}
|
|
73
|
+
{opt.description ? <span className="usa-checkbox__label-description">{opt.description}</span> : null}
|
|
74
|
+
</Label>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const content = fieldset ? (
|
|
49
80
|
<Fieldset
|
|
50
81
|
id={groupId}
|
|
51
82
|
legend={legend}
|
|
@@ -54,31 +85,10 @@ const RadioButtons: React.FC<RadioButtonsProps> = ({
|
|
|
54
85
|
error={error}
|
|
55
86
|
{...props}
|
|
56
87
|
>
|
|
57
|
-
{
|
|
58
|
-
const id = opt.id || `${groupId || name}-${idx}`;
|
|
59
|
-
return (
|
|
60
|
-
<div className={classes} key={id}>
|
|
61
|
-
<input
|
|
62
|
-
className={inputClasses}
|
|
63
|
-
id={id}
|
|
64
|
-
type="radio"
|
|
65
|
-
name={name}
|
|
66
|
-
value={opt.value}
|
|
67
|
-
defaultChecked={defaultValue === opt.value || !!opt.checked}
|
|
68
|
-
disabled={!!opt.disabled}
|
|
69
|
-
/>
|
|
70
|
-
<Label className="usa-radio__label" classOverride={true} htmlFor={id}>
|
|
71
|
-
{opt.label}
|
|
72
|
-
{opt.description ? (
|
|
73
|
-
<span className="usa-checkbox__label-description">{opt.description}</span>
|
|
74
|
-
) : null}
|
|
75
|
-
</Label>
|
|
76
|
-
</div>
|
|
77
|
-
);
|
|
78
|
-
})}
|
|
88
|
+
{optionsMarkup}
|
|
79
89
|
</Fieldset>
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
) : optionsMarkup;
|
|
91
|
+
return formGroup ? <FormGroup error={!!error}>{content}</FormGroup> : content;
|
|
82
92
|
};
|
|
83
93
|
|
|
84
94
|
export default RadioButtons;
|
|
@@ -68,9 +68,27 @@
|
|
|
68
68
|
"type": "string",
|
|
69
69
|
"description": "Value of the option to be selected by default"
|
|
70
70
|
},
|
|
71
|
+
"value": {
|
|
72
|
+
"type": "string",
|
|
73
|
+
"description": "Controlled selected value in React."
|
|
74
|
+
},
|
|
75
|
+
"onChange": {
|
|
76
|
+
"type": "function",
|
|
77
|
+
"description": "React change handler for the selected radio input."
|
|
78
|
+
},
|
|
79
|
+
"fieldset": {
|
|
80
|
+
"type": "boolean",
|
|
81
|
+
"default": true,
|
|
82
|
+
"description": "Wrap options in a fieldset; false allows one option inside a table cell."
|
|
83
|
+
},
|
|
84
|
+
"formGroup": {
|
|
85
|
+
"type": "boolean",
|
|
86
|
+
"default": true,
|
|
87
|
+
"description": "Wrap the fieldset in a form group."
|
|
88
|
+
},
|
|
71
89
|
"options": {
|
|
72
90
|
"type": "array",
|
|
73
|
-
"description": "Array of option objects: {id, value, label, description, checked, disabled}"
|
|
91
|
+
"description": "Array of option objects: {id, value, label, ariaLabel, description, checked, disabled}"
|
|
74
92
|
},
|
|
75
93
|
"className": {
|
|
76
94
|
"type": "string",
|