@weni/unnnic-system 2.0.12 → 2.0.14
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/dist/style.css +1 -1
- package/dist/unnnic.mjs +10106 -10051
- package/dist/unnnic.umd.js +26 -26
- package/package.json +1 -1
- package/src/assets/icons/weni-loading.svg +2 -0
- package/src/components/Pagination/Pagination.vue +11 -11
- package/src/components/SelectSmart/SelectSmart.vue +30 -54
- package/src/components/TableNext/TableBodyCell.vue +38 -0
- package/src/components/TableNext/TableNext.vue +269 -0
- package/src/components/TableNext/TablePagination.vue +95 -0
- package/src/components/TableNext/validation.js +52 -0
- package/src/components/index.js +3 -0
- package/src/stories/SelectSmart2.stories.js +59 -0
- package/src/stories/TableNext.stories.js +103 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<section class="table-pagination">
|
|
3
|
+
<p class="table-pagination__count">
|
|
4
|
+
{{ tablePagination }}
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<Pagination
|
|
8
|
+
:modelValue="modelValue"
|
|
9
|
+
@update:model-value="$emit('update:model-value', $event)"
|
|
10
|
+
:max="pages"
|
|
11
|
+
:show="5"
|
|
12
|
+
/>
|
|
13
|
+
</section>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script>
|
|
17
|
+
import Pagination from '../Pagination/Pagination.vue';
|
|
18
|
+
import UnnnicI18n from '../../mixins/i18n';
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
name: 'TablePagination',
|
|
22
|
+
|
|
23
|
+
mixins: [UnnnicI18n],
|
|
24
|
+
|
|
25
|
+
components: {
|
|
26
|
+
Pagination,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
props: {
|
|
30
|
+
modelValue: {
|
|
31
|
+
type: Number,
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
total: {
|
|
35
|
+
type: Number,
|
|
36
|
+
required: false,
|
|
37
|
+
},
|
|
38
|
+
interval: {
|
|
39
|
+
type: Number,
|
|
40
|
+
required: true,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
data() {
|
|
45
|
+
return {
|
|
46
|
+
defaultTranslations: {
|
|
47
|
+
pagination: {
|
|
48
|
+
'pt-br': '{from} - {to} de {total}',
|
|
49
|
+
en: '{from} - {to} of {total}',
|
|
50
|
+
es: '{from} - {to} de {total}',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
computed: {
|
|
57
|
+
tablePagination() {
|
|
58
|
+
const { modelValue, interval, total } = this;
|
|
59
|
+
|
|
60
|
+
return this.i18n('pagination', {
|
|
61
|
+
from: total === 0 ? 0 : (modelValue - 1) * interval + 1,
|
|
62
|
+
to: Math.min(modelValue * interval, total),
|
|
63
|
+
total,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
pages() {
|
|
68
|
+
return Math.ceil(this.total / this.interval);
|
|
69
|
+
},
|
|
70
|
+
showTotal() {
|
|
71
|
+
return typeof this.total === 'number';
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<style lang="scss" scoped>
|
|
78
|
+
@import '../../assets/scss/unnnic.scss';
|
|
79
|
+
|
|
80
|
+
.table-pagination {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
justify-content: space-between;
|
|
84
|
+
|
|
85
|
+
padding: $unnnic-spacing-sm $unnnic-spacing-nano;
|
|
86
|
+
|
|
87
|
+
height: min-content;
|
|
88
|
+
|
|
89
|
+
&__count {
|
|
90
|
+
color: $unnnic-color-neutral-dark;
|
|
91
|
+
font-size: $unnnic-font-size-body-gt;
|
|
92
|
+
font-family: $unnnic-font-family-secondary;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
</style>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const validateHeader = (cell) => {
|
|
2
|
+
const isContentString = typeof cell.content !== 'string';
|
|
3
|
+
if (isContentString) {
|
|
4
|
+
throw new Error('Each item in "headers" must have "content" as a string.');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const isSortableBoolean = 'isSortable' in cell && typeof cell.isSortable !== 'boolean';
|
|
8
|
+
if (isSortableBoolean) {
|
|
9
|
+
throw new Error('Each item in "headers" that contains “isSortable” must assign it as boolean');
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const validateHeaders = (headers) => {
|
|
14
|
+
if (!Array.isArray(headers)) {
|
|
15
|
+
throw new Error('Property headers needs to be an array.');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (headers.length === 0) {
|
|
19
|
+
throw new Error('Property headers must not to be an empty array.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
headers.forEach(validateHeader);
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const validateRow = (cell) => {
|
|
28
|
+
const isContentArray = !('content' in cell) || !Array.isArray(cell.content);
|
|
29
|
+
if (isContentArray) {
|
|
30
|
+
throw new Error('Each item in "rows" must have "content" as an array.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isLinkObject = 'link' in cell && typeof cell.link !== 'object' && typeof cell.link !== 'undefined';
|
|
34
|
+
if (isLinkObject) {
|
|
35
|
+
throw new Error('Each item in "rows" that contains “link” must assign it as object');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isLinkWithoutUrl = cell.link && !('url' in cell.link);
|
|
39
|
+
if (isLinkWithoutUrl) {
|
|
40
|
+
throw new Error('Each item in "rows" with "link" must contain "url".');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const validateRows = (rows) => {
|
|
45
|
+
if (!Array.isArray(rows)) {
|
|
46
|
+
throw new Error('Property rows needs to be an array.');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
rows.forEach(validateRow);
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
};
|
package/src/components/index.js
CHANGED
|
@@ -79,6 +79,7 @@ import EmojiPicker from './EmojiPicker/EmojiPicker.vue';
|
|
|
79
79
|
import ChartFunnel from './ChartFunnel/ChartFunnel.vue';
|
|
80
80
|
import Disclaimer from './Disclaimer/Disclaimer.vue';
|
|
81
81
|
import Drawer from './Drawer/Drawer.vue';
|
|
82
|
+
import TableNext from './TableNext/TableNext.vue';
|
|
82
83
|
|
|
83
84
|
export const components = {
|
|
84
85
|
unnnicFormElement: formElement,
|
|
@@ -163,6 +164,7 @@ export const components = {
|
|
|
163
164
|
unnnicChartFunnel: ChartFunnel,
|
|
164
165
|
unnnicDisclaimer: Disclaimer,
|
|
165
166
|
unnnicDrawer: Drawer,
|
|
167
|
+
unnnicTableNext: TableNext,
|
|
166
168
|
};
|
|
167
169
|
|
|
168
170
|
export const unnnicFontSize = fontSize;
|
|
@@ -248,3 +250,4 @@ export const unnnicEmojiPicker = EmojiPicker;
|
|
|
248
250
|
export const unnnicChartFunnel = ChartFunnel;
|
|
249
251
|
export const unnnicDisclaimer = Disclaimer;
|
|
250
252
|
export const unnnicDrawer = Drawer;
|
|
253
|
+
export const unnnicTableNext = TableNext;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import unnnicSelectSmart from '../components/SelectSmart/SelectSmart.vue';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: 'Form/SelectSmart2',
|
|
5
|
+
component: unnnicSelectSmart,
|
|
6
|
+
argTypes: {
|
|
7
|
+
'on-update:model-value': { action: '@update:model-value' },
|
|
8
|
+
size: { control: { type: 'select', options: ['md', 'sm'] } },
|
|
9
|
+
type: { control: { type: 'select', options: ['normal', 'error'] } },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const Template = (args, { argTypes }) => ({
|
|
14
|
+
props: Object.keys(argTypes),
|
|
15
|
+
|
|
16
|
+
components: {
|
|
17
|
+
unnnicSelectSmart,
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
data() {
|
|
21
|
+
return {
|
|
22
|
+
selected: [],
|
|
23
|
+
options: [
|
|
24
|
+
{
|
|
25
|
+
value: 't1',
|
|
26
|
+
label: 'teste 1'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
value: 't2',
|
|
30
|
+
label: 'teste 2'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
value: 't3',
|
|
34
|
+
label: 'teste 3'
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
template: `
|
|
41
|
+
<div>
|
|
42
|
+
<pre>v-model: {{ content }}</pre>
|
|
43
|
+
<unnnic-select-smart :options="options" v-model="selected" multiple :selectFirst="false" />
|
|
44
|
+
</div>
|
|
45
|
+
`,
|
|
46
|
+
|
|
47
|
+
methods: {},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const Default = Template.bind({});
|
|
51
|
+
|
|
52
|
+
Default.args = {
|
|
53
|
+
label: 'Label',
|
|
54
|
+
placeholder: 'Placeholder',
|
|
55
|
+
maxLength: 150,
|
|
56
|
+
disabled: false,
|
|
57
|
+
type: 'normal',
|
|
58
|
+
errors: [],
|
|
59
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import UnnnicTableNext from '../components/TableNext/TableNext.vue';
|
|
2
|
+
import UnnnicButton from '../components/Button/Button.vue';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'example/TableNext',
|
|
6
|
+
component: UnnnicTableNext,
|
|
7
|
+
argTypes: {},
|
|
8
|
+
render: (args) => ({
|
|
9
|
+
components: {
|
|
10
|
+
UnnnicTableNext,
|
|
11
|
+
},
|
|
12
|
+
setup() {
|
|
13
|
+
return { args };
|
|
14
|
+
},
|
|
15
|
+
data() {
|
|
16
|
+
return {
|
|
17
|
+
pagination: 1,
|
|
18
|
+
table: {
|
|
19
|
+
headers: [
|
|
20
|
+
{
|
|
21
|
+
content: 'ID',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
content: 'Name',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
content: 'Age',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
content: 'Country',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
content: 'Add with friend',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
rows: [],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
template: `
|
|
41
|
+
<UnnnicTableNext
|
|
42
|
+
v-bind="args"
|
|
43
|
+
:headers="table.headers"
|
|
44
|
+
:rows="args.rows || table.rows"
|
|
45
|
+
v-model:pagination="pagination"
|
|
46
|
+
:paginationTotal="125"
|
|
47
|
+
/>
|
|
48
|
+
`,
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
const addButton = {
|
|
52
|
+
component: UnnnicButton,
|
|
53
|
+
props: {
|
|
54
|
+
text: 'Add',
|
|
55
|
+
type: 'tertiary',
|
|
56
|
+
iconLeft: 'add',
|
|
57
|
+
size: 'small',
|
|
58
|
+
},
|
|
59
|
+
events: {
|
|
60
|
+
click: (event) => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
// eslint-disable-next-line no-alert
|
|
63
|
+
console.log('click');
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const Default = {
|
|
69
|
+
args: {
|
|
70
|
+
rows: [
|
|
71
|
+
{
|
|
72
|
+
content: ['1', 'Alice', '30', 'USA', addButton],
|
|
73
|
+
link: {
|
|
74
|
+
url: 'https://weni.ai/',
|
|
75
|
+
target: '_blank',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
content: ['2', 'Bob', '25', 'Canada', addButton],
|
|
80
|
+
link: {
|
|
81
|
+
url: 'https://weni.ai/',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
content: ['3', 'Charlie', '35', 'UK', addButton],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
content: ['4', 'Diana', '28', 'Australia', addButton],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
content: ['5', 'Ethan', '22', 'New Zealand', addButton],
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const WithoutResults = { args: {} };
|
|
98
|
+
|
|
99
|
+
export const Loading = {
|
|
100
|
+
args: {
|
|
101
|
+
isLoading: true,
|
|
102
|
+
},
|
|
103
|
+
};
|