@eturnity/eturnity_reusable_components 1.0.13 → 1.0.17

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.
@@ -0,0 +1,328 @@
1
+ <!-- This is just an example how to use mainTable with collective positioning -->
2
+ <!-- <template>
3
+ <draggable-table>
4
+ <thead>
5
+ <tr>
6
+ <div />
7
+ <th v-for="item in headerItems" :key="item.value">
8
+ {{ item.value }}
9
+ </th>
10
+ <th />
11
+ <div />
12
+ </tr>
13
+ </thead>
14
+ <draggable-container
15
+ :items="tableList"
16
+ handle=".drag-container"
17
+ :options="{ disabled: false }"
18
+ >
19
+ <parent-container v-for="el in tableList" :key="el.sales">
20
+ <tr :class="{ 'no-border': isOpen({ id: el.id }), disabled: true }">
21
+ <div class="drag-container">
22
+ <div class="drag-icon" />
23
+ </div>
24
+ <td>
25
+ <div :class="{ 'collective-container': el.children }">
26
+ <input-text :value="el.description" />
27
+ <div
28
+ v-if="el.children"
29
+ @click="
30
+ toggleShowChildren({ id: el.id, length: el.children.length })
31
+ "
32
+ :class="{
33
+ 'collective-box': true,
34
+ open: isChildrenOpen({ id: el.id }),
35
+ }"
36
+ >
37
+ {{ el.children.length }}
38
+ </div>
39
+ </div>
40
+ </td>
41
+ <td>
42
+ <div v-if="el.children" />
43
+ <input-text v-else :value="el.cost_price" />
44
+ </td>
45
+ <td>
46
+ <div v-if="el.children" />
47
+ <input-text v-else :value="el.margin" />
48
+ </td>
49
+ <td>
50
+ <div v-if="el.children" />
51
+ <input-text v-else :value="el.installation" />
52
+ </td>
53
+ <td>
54
+ <input-text :value="el.sales" />
55
+ </td>
56
+ <div class="arrow-container" @click="toggleOpen({ id: el.id })">
57
+ <div v-if="isOpen({ id: el.id })" class="arrow-up" />
58
+ <div v-if="!isOpen({ id: el.id })" class="arrow-down" />
59
+ </div>
60
+ <div class="icons-container">
61
+ <three-dots :options="listOptions" />
62
+ <delete-icon color="gray" />
63
+ </div>
64
+ </tr>
65
+ <tr v-if="isOpen({ id: el.id })" class="container-row">
66
+ <div />
67
+ <td class="no-border" colspan="6" v-if="isOpen({ id: el.id })">
68
+ <div class="open-container">
69
+ <container-wrapper>
70
+ <div>hi you</div>
71
+ <div>Test test</div>
72
+ </container-wrapper>
73
+ </div>
74
+ </td>
75
+ </tr>
76
+ <children-wrapper
77
+ v-if="
78
+ el.children && el.children.length && isChildrenOpen({ id: el.id })
79
+ "
80
+ >
81
+ <draggable-container :items="el.children" handle=".drag-container">
82
+ <template v-for="item in el.children">
83
+ <tr
84
+ :key="item.sales"
85
+ :class="{
86
+ 'no-border': isOpen({ id: item.id }),
87
+ disabled: true,
88
+ }"
89
+ >
90
+ <div class="drag-container">
91
+ <div class="drag-icon" />
92
+ </div>
93
+ <td>
94
+ <div class="collective-container">
95
+ <span class="subposition-icon" />
96
+ <input-text :value="item.description" />
97
+ </div>
98
+ </td>
99
+ <td>
100
+ <input-text :value="item.cost_price" />
101
+ </td>
102
+ <td>
103
+ <input-text :value="item.margin" />
104
+ </td>
105
+ <td>
106
+ <input-text :value="item.installation" />
107
+ </td>
108
+ <td><input-text :value="item.sales" /></td>
109
+ <div
110
+ class="arrow-container"
111
+ @click="toggleOpen({ id: item.id })"
112
+ >
113
+ <div v-if="isOpen({ id: item.id })" class="arrow-up" />
114
+ <div v-if="!isOpen({ id: item.id })" class="arrow-down" />
115
+ </div>
116
+ <div class="icons-container">
117
+ <three-dots :options="listOptions" />
118
+ <delete-icon color="gray" />
119
+ </div>
120
+ </tr>
121
+ <tr
122
+ v-if="isOpen({ id: item.id })"
123
+ class="container-row"
124
+ :key="item.sales"
125
+ >
126
+ <div />
127
+ <td
128
+ class="no-border"
129
+ colspan="6"
130
+ v-if="isOpen({ id: item.id })"
131
+ >
132
+ <div class="open-container">
133
+ <container-wrapper>
134
+ <div>hi you</div>
135
+ <div>Test test</div>
136
+ </container-wrapper>
137
+ </div>
138
+ </td>
139
+ </tr>
140
+ </template>
141
+ </draggable-container>
142
+ </children-wrapper>
143
+ </parent-container>
144
+ </draggable-container>
145
+ <tr class="footer">
146
+ <div />
147
+ <td class="text bold">
148
+ Total PV system code
149
+ </td>
150
+ <td />
151
+ <td />
152
+ <td />
153
+ <td class="text bold">
154
+ 17.000 CHF
155
+ </td>
156
+ <td />
157
+ <div />
158
+ </tr>
159
+ </draggable-table>
160
+ </template>
161
+
162
+ <script>
163
+ import draggable from "vuedraggable"
164
+ import styled from "vue-styled-components"
165
+ import DraggableTable from "@/components/reusable-components/tables/DraggableTable"
166
+ import InputText from "@eturnity/eturnity_reusable_components/src/components/inputs/inputText"
167
+ import DeleteIcon from "@/components/reusable-components/DeleteIcon"
168
+ import ThreeDots from "@/components/reusable-components/ThreeDots"
169
+
170
+ const DraggableContainer = styled(draggable)`
171
+ display: contents;
172
+ `
173
+
174
+ const ParentContainer = styled.tbody`
175
+ /* display: contents; */
176
+ `
177
+
178
+ const ChildrenWrapper = styled.div`
179
+ display: contents;
180
+ `
181
+
182
+ const ContainerWrapper = styled.div`
183
+ display: grid;
184
+ padding: 12px;
185
+ grid-template-columns: 1fr 1fr;
186
+ `
187
+
188
+ export default {
189
+ name: "nested-table",
190
+ components: {
191
+ DraggableContainer,
192
+ ParentContainer,
193
+ DraggableTable,
194
+ InputText,
195
+ ChildrenWrapper,
196
+ DeleteIcon,
197
+ ThreeDots,
198
+ ContainerWrapper,
199
+ },
200
+ data() {
201
+ return {
202
+ tableList: [
203
+ {
204
+ description: "My Description 1",
205
+ cost_price: null,
206
+ margin: null,
207
+ installation: null,
208
+ sales: 1000,
209
+ id: 1,
210
+ children: [
211
+ {
212
+ description: "My Description 2",
213
+ cost_price: 20,
214
+ margin: 200,
215
+ installation: 2000,
216
+ sales: 20,
217
+ id: 2,
218
+ children: [],
219
+ },
220
+ {
221
+ description: "My Description 7",
222
+ cost_price: 70,
223
+ margin: 700,
224
+ installation: 7000,
225
+ sales: 70,
226
+ id: 3,
227
+ children: [],
228
+ },
229
+ ],
230
+ },
231
+ {
232
+ description: "My Description 3",
233
+ cost_price: 30,
234
+ margin: 300,
235
+ installation: 3000,
236
+ sales: 30,
237
+ id: 4,
238
+ },
239
+ {
240
+ description: "My Description 5",
241
+ cost_price: 50,
242
+ margin: 500,
243
+ installation: 5000,
244
+ sales: 50,
245
+ id: 5,
246
+ children: [
247
+ {
248
+ description: "My Description 6",
249
+ cost_price: 60,
250
+ margin: 600,
251
+ installation: 6000,
252
+ sales: 60,
253
+ id: 6,
254
+ children: [],
255
+ },
256
+ ],
257
+ },
258
+ ],
259
+ openItem: null,
260
+ showChildren: [],
261
+ listOptions: [
262
+ {
263
+ name: "Option 1",
264
+ value: "option_1",
265
+ },
266
+ {
267
+ name: "Option 2",
268
+ value: "option_2",
269
+ },
270
+ {
271
+ name: "Option 3",
272
+ value: "option_3",
273
+ },
274
+ {
275
+ name: "Option 4",
276
+ value: "option_4",
277
+ },
278
+ ],
279
+ }
280
+ },
281
+ computed: {
282
+ headerItems() {
283
+ const items = [
284
+ {
285
+ value: "Description",
286
+ },
287
+ {
288
+ value: "Cost price",
289
+ },
290
+ {
291
+ value: "Calculation surcharge",
292
+ },
293
+ {
294
+ value: "Installation costs",
295
+ },
296
+ {
297
+ value: "Sales price",
298
+ },
299
+ ]
300
+
301
+ return items
302
+ },
303
+ },
304
+ methods: {
305
+ toggleOpen({ id }) {
306
+ this.openItem = this.openItem === id ? null : id
307
+ },
308
+ isOpen({ id }) {
309
+ return this.openItem === id
310
+ },
311
+ toggleShowChildren({ id, length }) {
312
+ if (!length) {
313
+ return
314
+ }
315
+ if (this.isChildrenOpen({ id })) {
316
+ // if the item is already in the Array
317
+ this.showChildren = this.showChildren.filter((item) => item !== id)
318
+ } else {
319
+ this.showChildren.push(id)
320
+ }
321
+ },
322
+ isChildrenOpen({ id }) {
323
+ return this.showChildren.length ? this.showChildren.includes(id) : false
324
+ },
325
+ },
326
+ }
327
+ </script>
328
+ -->
@@ -0,0 +1,264 @@
1
+ <template>
2
+ <table-scroll>
3
+ <table-wrapper :fullWidth="fullWidth">
4
+ <spinner-wrapper v-if="isLoading">
5
+ <spinner />
6
+ </spinner-wrapper>
7
+ <table-container v-else>
8
+ <slot />
9
+ </table-container>
10
+ </table-wrapper>
11
+ </table-scroll>
12
+ </template>
13
+
14
+ <script>
15
+ // ToDo: add this to storybook
16
+ // import MainTable from "@eturnity/eturnity_reusable_components/src/components/tables/mainTable"
17
+ import styled from "vue-styled-components"
18
+ import Spinner from "../../spinner"
19
+
20
+ const TableScroll = styled.div`
21
+ position: relative;
22
+ max-width: 100%;
23
+ `
24
+
25
+ const wrapperAttrs = { fullWidth: Boolean }
26
+ const TableWrapper = styled("div", wrapperAttrs)`
27
+ width: ${(props) => (props.fullWidth ? "100%" : "fit-content")};
28
+ max-width: 100%;
29
+ overflow: auto;
30
+
31
+ ::-webkit-scrollbar {
32
+ width: 10px; //width of the whole scrollbar area
33
+ }
34
+
35
+ track ::-webkit-scrollbar-track {
36
+ background: #fff;
37
+ }
38
+
39
+ ::-webkit-scrollbar-thumb {
40
+ border-bottom: 2px solid #b2b9c4; // width of the actual scrollbar
41
+ }
42
+ `
43
+
44
+ const SpinnerWrapper = styled.div`
45
+ height: 150px;
46
+ display: grid;
47
+ align-items: center;
48
+ justify-items: center;
49
+ `
50
+
51
+ const TableContainer = styled.table`
52
+ width: 100%;
53
+ border-collapse: collapse;
54
+ border: none;
55
+ font-size: 13px;
56
+
57
+ thead {
58
+ font-weight: bold;
59
+
60
+ tr {
61
+ border-bottom: none !important;
62
+ }
63
+ }
64
+
65
+ th {
66
+ padding: 12px 20px;
67
+ background-color: ${(props) => props.theme.colors.blue1};
68
+ }
69
+
70
+ td {
71
+ padding: 7px 10px;
72
+ border-bottom: 1px solid ${(props) => props.theme.colors.grey4};
73
+
74
+ &.no-border {
75
+ border-bottom: none;
76
+ }
77
+
78
+ .collective-container {
79
+ display: grid;
80
+ grid-template-columns: auto 1fr;
81
+ align-items: center;
82
+ grid-gap: 10px;
83
+ cursor: pointer;
84
+ }
85
+
86
+ .collective-box {
87
+ width: 22px;
88
+ height: 22px;
89
+ border-radius: 4px;
90
+ color: #fff;
91
+ background-color: ${(props) => props.theme.colors.grey3};
92
+ font-size: 13px;
93
+ font-weight: normal;
94
+ display: grid;
95
+ align-items: center;
96
+ justify-items: center;
97
+
98
+ &.open {
99
+ background-color: ${(props) => props.theme.colors.green};
100
+ }
101
+ }
102
+ }
103
+
104
+ td,
105
+ th {
106
+ white-space: nowrap;
107
+ text-align: left;
108
+
109
+ &.align {
110
+ &-left {
111
+ text-align: left;
112
+ }
113
+
114
+ &-center {
115
+ text-align: center;
116
+ }
117
+
118
+ &-right {
119
+ text-align: right;
120
+ }
121
+ }
122
+ }
123
+
124
+ tr {
125
+ &.disabled {
126
+ cursor: not-allowed;
127
+ }
128
+
129
+ &.footer {
130
+ td {
131
+ background-color: ${(props) => props.theme.colors.grey5};
132
+ border-top: 1px solid ${(props) => props.theme.colors.grey4};
133
+ }
134
+ }
135
+
136
+ .text {
137
+ padding: 12px 0 12px 18px;
138
+ color: ${(props) => props.theme.colors.black};
139
+ }
140
+
141
+ .bold {
142
+ font-weight: bold;
143
+ }
144
+
145
+ .icons-container {
146
+ width: 100%;
147
+ display: inline-flex;
148
+ flex-wrap: nowrap;
149
+ background-color: #fff;
150
+ vertical-align: middle;
151
+ }
152
+
153
+ .arrow-container {
154
+ display: table-cell;
155
+ vertical-align: middle;
156
+ text-align: center;
157
+ text-align: -webkit-center;
158
+ cursor: pointer;
159
+ border-bottom: 1px solid ${(props) => props.theme.colors.grey4};
160
+ }
161
+
162
+ &.container-row td {
163
+ padding: 0;
164
+ }
165
+
166
+ &.no-border {
167
+ td,
168
+ .arrow-container {
169
+ border-bottom: none;
170
+ }
171
+ }
172
+
173
+ &:hover {
174
+ input {
175
+ background-color: ${(props) => props.theme.colors.grey5};
176
+ }
177
+
178
+ .drag-icon {
179
+ visibility: visible;
180
+ }
181
+ }
182
+
183
+ .drag-container {
184
+ display: table-cell;
185
+ width: auto;
186
+ vertical-align: middle;
187
+ }
188
+
189
+ .drag-icon {
190
+ visibility: hidden;
191
+ width: 10px;
192
+ height: 16px;
193
+ cursor: grab;
194
+ background-position: center;
195
+ background-image: ${() =>
196
+ `url(${require("@/assets/images/drag_icon.svg")})`};
197
+
198
+ &:active {
199
+ cursor: grabbing;
200
+ }
201
+ }
202
+
203
+ .subposition-icon {
204
+ width: 14px;
205
+ height: 11px;
206
+ background: no-repeat;
207
+ margin-left: 10px;
208
+ background-image: ${() =>
209
+ `url(${require("@/assets/images/subposition_icon.svg")})`};
210
+ }
211
+
212
+ .arrow-down {
213
+ width: 14px;
214
+ height: 11px;
215
+ background: no-repeat;
216
+ background-position: center;
217
+ background-image: ${() =>
218
+ `url(${require("@/assets/images/arrow_down.svg")})`};
219
+ }
220
+
221
+ .arrow-up {
222
+ width: 14px;
223
+ height: 11px;
224
+ background: no-repeat;
225
+ background-position: center;
226
+ background-image: ${() =>
227
+ `url(${require("@/assets/images/arrow_up_red.svg")})`};
228
+ }
229
+ }
230
+
231
+ input {
232
+ border: none;
233
+ font-size: 13px;
234
+ padding: 5px 10px;
235
+ }
236
+
237
+ .open-container {
238
+ border: 1px solid ${(props) => props.theme.colors.grey4};
239
+ border-radius: 4px;
240
+ margin-bottom: 10px;
241
+ }
242
+ `
243
+
244
+ export default {
245
+ name: "main-table",
246
+ components: {
247
+ TableScroll,
248
+ TableWrapper,
249
+ SpinnerWrapper,
250
+ Spinner,
251
+ TableContainer,
252
+ },
253
+ props: {
254
+ fullWidth: {
255
+ required: false,
256
+ default: true,
257
+ },
258
+ isLoading: {
259
+ required: false,
260
+ default: false,
261
+ },
262
+ },
263
+ }
264
+ </script>