nwl-components 1.5.2 → 1.6.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 +59 -0
- package/dist/nwl-components.es.js +1742 -1722
- package/dist/nwl-components.umd.js +6 -6
- package/dist/sort/nwl-components-sort.es.js +75 -0
- package/dist/sort/nwl-components-sort.umd.js +1 -0
- package/dist/sort/style.css +44 -0
- package/dist/style.css +1 -1
- package/package.json +12 -3
- package/sort/package.json +6 -0
- package/sort/style.css +44 -0
package/README.md
CHANGED
|
@@ -90,6 +90,65 @@ browser keeps it inside the table. `useSortable` also returns `sortBy(column)`,
|
|
|
90
90
|
`sortColumn` and `sortAscending`; a third argument `{ column, ascending }` sets an initial
|
|
91
91
|
sort. Story: `Common/Table` (`npm run storybook`). Since 1.5.0.
|
|
92
92
|
|
|
93
|
+
Table cells wrap at spaces only, so a long word such as an owner's user name is never
|
|
94
|
+
broken. A cell that may break inside a word, so that the table is never wider than its
|
|
95
|
+
panel (for example a long project name with no spaces), opts in with the class
|
|
96
|
+
`nwl-break-anywhere` (`overflow-wrap: anywhere`). It works on cells written in the
|
|
97
|
+
`Table` slot. Since 1.5.3.
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<tr v-for="project in sortedProjects">
|
|
101
|
+
<td class="nwl-break-anywhere">{{ project.name }}</td>
|
|
102
|
+
<td>{{ project.owner }}</td>
|
|
103
|
+
</tr>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Tables without Vue
|
|
107
|
+
|
|
108
|
+
Pages that build their tables with template strings and the DOM sort them the same way
|
|
109
|
+
with `nwl-components/sort`, which has no Vue (about 3 kB). Importing these names from
|
|
110
|
+
`nwl-components` itself also works, but bundles Vue and the whole library.
|
|
111
|
+
`useSortable` and `SortableTh` use the same code, so the order and the header markup
|
|
112
|
+
never differ.
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import { nextSort, sortRows, sortableHeader } from 'nwl-components/sort';
|
|
116
|
+
|
|
117
|
+
const columns = { Name: { key: 'project' }, Files: { key: 'numFiles', type: 'number' } };
|
|
118
|
+
let state = { column: null, ascending: true };
|
|
119
|
+
const headers = {};
|
|
120
|
+
const render = () => {
|
|
121
|
+
const rows = state.column ? sortRows(projects, columns[state.column], state.ascending) : projects;
|
|
122
|
+
tbody.innerHTML = rows.map((p) => `<tr><td>${p.project}</td><td>${p.numFiles}</td></tr>`).join('');
|
|
123
|
+
for (const [name, header] of Object.entries(headers)) {
|
|
124
|
+
header.setDirection(name !== state.column ? 'none' : state.ascending ? 'ascending' : 'descending');
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
for (const th of table.querySelectorAll('th')) {
|
|
128
|
+
const name = th.textContent;
|
|
129
|
+
headers[name] = sortableHeader(th, { onSort: () => { state = nextSort(state, name); render(); } });
|
|
130
|
+
}
|
|
131
|
+
render();
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- `sortRows(rows, { key, type }, ascending = true)`: a new, sorted array (stable; missing
|
|
135
|
+
values last in both directions; `localeCompare` for strings). `sortValue(row, column)`
|
|
136
|
+
is the value it compares.
|
|
137
|
+
- `sortableHeader(th, { direction, onSort })` turns a `<th>` into SortableTh's markup
|
|
138
|
+
(`class="nwl-sortable"`, `aria-sort`, a `<button type="button">` with the th's content
|
|
139
|
+
and the icon; Enter and Space work as on any button) and returns
|
|
140
|
+
`{ th, button, setDirection(direction) }`.
|
|
141
|
+
- `nextSort(state, column)`: the sort after a click, as in `useSortable`.
|
|
142
|
+
- For template strings: `renderSortIcon(direction)` (the SVG) and `ariaSort(direction)`.
|
|
143
|
+
|
|
144
|
+
The headers' look is in `nwl-components/sort/style.css`, which has only the
|
|
145
|
+
`th.nwl-sortable` and `.nwl-sort-*` rules (1 kB). Load that file, not `dist/style.css`, on a
|
|
146
|
+
page not built with nwl-components: `dist/style.css` has global rules (`*` sets the font
|
|
147
|
+
size and colour of every element). With a bundler, `import 'nwl-components/sort/style.css'`
|
|
148
|
+
(webpack 4 included); otherwise link `node_modules/nwl-components/dist/sort/style.css`.
|
|
149
|
+
`dist/style.css` keeps the same rules for `SortableTh`. Story: `Common/PlainSort`.
|
|
150
|
+
Since 1.6.0.
|
|
151
|
+
|
|
93
152
|
## Single File Components
|
|
94
153
|
|
|
95
154
|
This project makes use of Vue SFCs: _Single File Components_, that have the `.vue` extension.
|