@knowark/componarkjs 1.11.2 → 1.12.1

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.
@@ -15,16 +15,17 @@ export class Droparea extends Component {
15
15
  }
16
16
 
17
17
  render () {
18
+ this._grabSlots()
18
19
  this.content = /* html */ `
19
20
  <form class="${tag}__form">
20
- <div class="${tag}__header">
21
+ <div data-content class="${tag}__header">
21
22
  <div class="${tag}__open">${this.title || 'Upload'}</div>
22
- <input id="fileElement"class="${tag}__input" type="file"
23
- data-input multiple />
24
23
  </div>
25
24
  <ark-droparea-preview></ark-droparea-preview>
26
25
  </form>
27
26
  `
27
+ this.querySelector('[data-content]').appendChild(
28
+ this._buildFileInput(this.fileInput))
28
29
  this.dragDropEvents = ['dragenter', 'dragover', 'dragleave', 'drop']
29
30
  this.dragEvents = this.dragDropEvents.slice(0, 2)
30
31
  this.dropEvents = this.dragDropEvents.slice(2)
@@ -149,6 +150,20 @@ export class Droparea extends Component {
149
150
  return true
150
151
  }
151
152
 
153
+ _grabSlots() {
154
+ const [fileInput] = [this.slots.general].flat()
155
+ this.fileInput = this.fileInput ?? fileInput
156
+
157
+ }
158
+
159
+ _buildFileInput (element) {
160
+ const input = element ?? document.createElement('input')
161
+ const attributes = [['id', 'fileElement'], ['class', `${tag}__input`],
162
+ ['type', 'file'], ['data-input', ''], ['multiple', '']]
163
+ attributes.forEach(([key, value]) => input.setAttribute(key, value))
164
+ return input
165
+ }
166
+
152
167
  get dropZone () {
153
168
  return this.select('.ark-droparea__form')
154
169
  }
@@ -317,4 +317,37 @@ describe('Droparea', () => {
317
317
  dropZone.dispatchEvent(dropEvent)
318
318
  expect(droparea.maxSizeValidate).toBeCalled
319
319
  })
320
+
321
+
322
+ it('allows to be passed a custom input element', () => {
323
+ container.innerHTML = /* html */ `
324
+ <ark-droparea single>
325
+ <input data-custom-input style="font-weight:bold" type="file">
326
+ </ark-droparea>
327
+ `
328
+
329
+ const droparea = container.querySelector('ark-droparea')
330
+ const input = droparea.querySelector('[data-custom-input]')
331
+ expect(input).toBeTruthy()
332
+ expect(input.style.fontWeight).toEqual('bold')
333
+ const dropZone = droparea.querySelector('.ark-droparea__form')
334
+ const myFile = new File(['image'], 'Snoopy.png', {
335
+ type: 'image/png'
336
+ })
337
+ const myFile2 = new File(['image'], 'Scooby.png', {
338
+ type: 'image/png'
339
+ })
340
+
341
+ const dropEvent = createBubbledEvent('drop', {
342
+ clientX: 0,
343
+ clientY: 1,
344
+ dataTransfer: {
345
+ files: [myFile, myFile2]
346
+ }
347
+ })
348
+
349
+ dropZone.dispatchEvent(dropEvent)
350
+ expect(droparea.fileList.length).toBe(1)
351
+ expect(droparea.fileList[1]).toBeFalsy()
352
+ })
320
353
  })
@@ -7,7 +7,7 @@ export class Paginator extends Component {
7
7
  this.binding = 'paginator-listen'
8
8
  this.collectionSize = (
9
9
  context.collectionSize || this.collectionSize || '120')
10
- this.pageSize = context.pageSize || this.pageSize || '24'
10
+ this.pageSize = context.pageSize || this.pageSize || '60'
11
11
  this.currentPage = context.currentPage || this.currentPage || '1'
12
12
  this.displayedPages = (
13
13
  context.displayedPages || this.displayedPages || '12')
@@ -23,14 +23,13 @@ export class Paginator extends Component {
23
23
 
24
24
  render () {
25
25
  this._grabSlots()
26
- this.content = /* html */ `
26
+ this.content = /* html */`
27
27
  <div class="ark-paginator__body">
28
28
  <div data-start class="ark-paginator__buttons">
29
29
  </div>
30
30
 
31
31
  <div data-middle paginator-listen on-click="_move"
32
- class="ark-paginator__pages">
33
- </div>
32
+ class="ark-paginator__pages"></div>
34
33
 
35
34
  <div data-end class="ark-paginator__buttons">
36
35
  </div>
@@ -121,7 +120,7 @@ export class Paginator extends Component {
121
120
  }
122
121
 
123
122
  _grabSlots() {
124
- const [pageButton] = [this.slots.general].flat()
123
+ const [pageButton] = [this.slots.page].flat()
125
124
  this.pageButton = this.pageButton ?? pageButton
126
125
  const [firstButton] = [this.slots.first].flat()
127
126
  this.firstButton = this.firstButton ?? firstButton
@@ -135,7 +134,7 @@ export class Paginator extends Component {
135
134
 
136
135
  _buildButton (element, handler, content, attributes = []) {
137
136
  const button = element ?? document.createElement('button')
138
- button.textContent = button.textContent || content
137
+ button.innerHTML = button.innerHTML || content
139
138
  if (handler) {
140
139
  button.setAttribute('paginator-listen', '')
141
140
  button.setAttribute('on-click', handler)
@@ -1,4 +1,4 @@
1
- import { Paginator } from './paginator.js'
1
+ import './paginator.js'
2
2
 
3
3
  describe('Paginator', () => {
4
4
  let container = null
@@ -129,9 +129,11 @@ describe('Paginator', () => {
129
129
  it('can be provided with custom styleable elements', () => {
130
130
  container.innerHTML = /* html */ `
131
131
  <ark-paginator page-size="12" displayed-pages="5">
132
- <button data-first slot="first"></button>
133
- <button data-previous slot="previous"></button>
134
- <button data-page-general></button>
132
+ <button data-first slot="first">
133
+ <span style="pointer-events: none">FIRST</span>
134
+ </button>
135
+ <button data-previous slot="previous">BACK</button>
136
+ <button data-page-general slot="page"></button>
135
137
  <button data-next slot="next"></button>
136
138
  <button data-last slot="last"></button>
137
139
  </ark-paginator>
@@ -139,8 +141,10 @@ describe('Paginator', () => {
139
141
 
140
142
  const paginator = container.querySelector('ark-paginator')
141
143
 
142
- expect(paginator.querySelector('[data-first]')).toBeTruthy()
143
- expect(paginator.querySelector('[data-previous]')).toBeTruthy()
144
+ expect(paginator.querySelector('[data-first]').innerHTML.trim()).toEqual(
145
+ '<span style="pointer-events: none">FIRST</span>')
146
+ expect(paginator.querySelector('[data-previous]').innerHTML.trim()).toEqual(
147
+ 'BACK')
144
148
  expect(paginator.querySelector('[data-page-general]')).toBeTruthy()
145
149
  expect(paginator.querySelector('[data-next]')).toBeTruthy()
146
150
  expect(paginator.querySelector('[data-last]')).toBeTruthy()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowark/componarkjs",
3
- "version": "1.11.2",
3
+ "version": "1.12.1",
4
4
  "author": "Knowark",
5
5
  "description": "Knowark's Web Components Library",
6
6
  "license": "ISC",
@@ -1,32 +0,0 @@
1
- PAGINATOR
2
- ---------
3
-
4
- The ``ark-paginator`` component allows the user to select a specific page from a range of pages.
5
-
6
-
7
- Examples
8
- --------
9
-
10
- **This component needs to initialize with** ``collectionSize`` **and** ``pageSize`` **properties to display the button and pages needed**
11
-
12
- ``` javascript
13
- const paginator = this.select('ark-paginator')
14
- paginator.init({ collectionSize: 4, pageSize: 1 }).render()
15
- ```
16
-
17
- **The** ``ark-paginator`` **component receive an** ``on-page-change`` **event that points to the data that's going to be displayed**
18
-
19
- ``` html
20
- <ark-paginator listen on-page-change="updateList"></ark-paginator>
21
- ```
22
-
23
- Properties
24
- ----------
25
-
26
- | Component | Name | Type | Default | Description |
27
- | :---------------: | :------------: | :----: | :-----: | :---------------------------------------------: |
28
- | ``ark-paginator`` | pageSize | number | null | Number of pages displayed in one page |
29
- | ``ark-paginator`` | collectionSize | number | null | Defines a range of pages in a number of buttons |
30
- | ``ark-paginator`` | currentPage | number | null | Selects an specific page |
31
-
32
-
@@ -1,110 +0,0 @@
1
- import { Component } from '../../../base/component/index.js'
2
- import styles from '../styles/index.js'
3
-
4
- const tag = 'ark-paginator'
5
- export class Paginator extends Component {
6
- init (context = {}) {
7
- this.binding = 'paginator-listen'
8
- this.collectionSize = (
9
- context.collectionSize || this.collectionSize || '120')
10
- this.pageSize = context.pageSize || this.pageSize || '24'
11
- this.currentPage = context.currentPage || this.currentPage || '1'
12
- this.displayedPages = (
13
- context.displayedPages || this.displayedPages || '12')
14
-
15
- this.global = context.global || window
16
-
17
- return super.init()
18
- }
19
-
20
- reflectedProperties () {
21
- return ['collectionSize', 'pageSize', 'displayedPages', 'currentPage']
22
- }
23
-
24
- render () {
25
- this.content = /* html */ `
26
- <div class="ark-paginator__body">
27
- <div class="ark-paginator__buttons">
28
- <button paginator-listen on-click="_first">&#60;&#60;</button>
29
- <button paginator-listen on-click="_prev">&#60;</button>
30
- </div>
31
-
32
- <div paginator-listen on-click="_move" class="ark-paginator__pages">
33
- ${this.currentPages.map((page) => (
34
- `<button ${page == this.currentPage ? 'active' : ''}
35
- data-page="${page}">${page}</button>`)).join('')}
36
- </div>
37
-
38
- <div class="ark-paginator__buttons">
39
- <button paginator-listen on-click="_next">&#62;</button>
40
- <button paginator-listen on-click="_last">&#62;&#62;</button>
41
- </div>
42
- </div>
43
- `
44
-
45
- return super.render()
46
- }
47
-
48
- get totalPages () {
49
- return Math.ceil(this.collectionSize / this.pageSize)
50
- }
51
-
52
- get currentPages () {
53
- const displayedPages = Math.min(
54
- parseInt(this.displayedPages), this.totalPages)
55
- const currentPage = parseInt(this.currentPage)
56
- let startPage = Math.max(currentPage - Math.trunc(displayedPages / 2), 1)
57
- startPage = Math.min(1 + this.totalPages - displayedPages, startPage)
58
-
59
- return Array.from({ length: displayedPages }, (_, i) => i + startPage)
60
- }
61
-
62
- _notifyChange () {
63
- const page = parseInt(this.currentPage)
64
- const limit = parseInt(this.pageSize)
65
- const offset = (page - 1) * limit
66
- this.emit('page-changed', { page, limit, offset })
67
- }
68
-
69
- /** @param {number} currentPage */
70
- _setCurrentPage (currentPage) {
71
- if (currentPage > 0 && currentPage <= this.totalPages) {
72
- this.currentPage = currentPage
73
- this.render()
74
- this._notifyChange()
75
- }
76
- }
77
-
78
- /** @param {Event} event */
79
- _first (event) {
80
- event.stopPropagation()
81
- this._setCurrentPage(1)
82
- }
83
-
84
- /** @param {Event} event */
85
- _prev (event) {
86
- event.stopPropagation()
87
- this._setCurrentPage(parseInt(this.currentPage) - 1)
88
- }
89
-
90
- /** @param {Event} event */
91
- _move (event) {
92
- event.stopPropagation()
93
- const page = parseInt(event.target.dataset.page)
94
- this._setCurrentPage(page)
95
- }
96
-
97
- /** @param {Event} event */
98
- _next (event) {
99
- event.stopPropagation()
100
- this._setCurrentPage(parseInt(this.currentPage) + 1)
101
- }
102
-
103
- /** @param {Event} event */
104
- _last (event) {
105
- event.stopPropagation()
106
- this._setCurrentPage(this.totalPages)
107
- }
108
- }
109
-
110
- Component.define(tag, Paginator, styles)
@@ -1,128 +0,0 @@
1
- import { Paginator } from './paginator.js'
2
-
3
- describe('Paginator', () => {
4
- let container = null
5
-
6
- beforeEach(() => {
7
- container = document.createElement('div')
8
- document.body.appendChild(container)
9
- })
10
-
11
- afterEach(() => {
12
- container.remove()
13
- container = null
14
- })
15
-
16
- it('can be instantiated', () => {
17
- container.innerHTML = /* html */ `
18
- <ark-paginator></ark-paginator>
19
- `
20
- const paginator = container.querySelector('ark-paginator')
21
-
22
- expect(paginator).toBe(paginator.init())
23
- })
24
-
25
- it('can be instantiated with parameters', () => {
26
- container.innerHTML = /* html */ `
27
- <ark-paginator page-size="12" displayed-pages="5"></ark-paginator>
28
- `
29
- const paginator = container.querySelector('ark-paginator')
30
- paginator.init({ collectionSize: 120, currentPage: 4 })
31
-
32
- expect(paginator.pageSize).toBe('12')
33
- expect(paginator.collectionSize).toBe('120')
34
- expect(paginator.currentPage).toBe('4')
35
- expect(paginator.displayedPages).toBe('5')
36
- expect(paginator.totalPages).toBe(10)
37
-
38
- paginator.init({ collectionSize: 120, pageSize: 10 })
39
- expect(paginator.totalPages).toBe(12)
40
- })
41
-
42
- it('computes the current shown pages', () => {
43
- container.innerHTML = /* html */ `
44
- <ark-paginator collection-size="120" page-size="12"
45
- displayed-pages="5" current-page="1"></ark-paginator>
46
- `
47
- const paginator = container.querySelector('ark-paginator')
48
-
49
- expect(paginator.currentPages).toEqual([1, 2, 3, 4, 5])
50
- expect(paginator.totalPages).toEqual(10)
51
-
52
- paginator.init({ currentPage: 3 })
53
- expect(paginator.currentPages).toEqual([1, 2, 3, 4, 5])
54
-
55
- paginator.init({ currentPage: 4 })
56
- expect(paginator.currentPages).toEqual([2, 3, 4, 5, 6])
57
-
58
- paginator.init({ currentPage: 5 })
59
- expect(paginator.currentPages).toEqual([3, 4, 5, 6, 7])
60
-
61
- paginator.init({ currentPage: 7 })
62
- expect(paginator.currentPages).toEqual([5, 6, 7, 8, 9])
63
-
64
- paginator.init({ currentPage: 8 })
65
- expect(paginator.currentPages).toEqual([6, 7, 8, 9, 10])
66
-
67
- paginator.init({ currentPage: 9 })
68
- expect(paginator.currentPages).toEqual([6, 7, 8, 9, 10])
69
-
70
- paginator.init({ currentPage: 10 })
71
- expect(paginator.currentPages).toEqual([6, 7, 8, 9, 10])
72
-
73
- paginator.init({ displayedPages: 6, currentPage: 5 })
74
- expect(paginator.currentPages).toEqual([2, 3, 4, 5, 6, 7])
75
-
76
- paginator.init({ displayedPages: 6, currentPage: 7 })
77
- expect(paginator.currentPages).toEqual([4, 5, 6, 7, 8, 9])
78
-
79
- paginator.init({ displayedPages: 6, currentPage: 9 })
80
- expect(paginator.currentPages).toEqual([5, 6, 7, 8, 9, 10])
81
- })
82
-
83
- it('enables and notifies page changes', () => {
84
- container.innerHTML = /* html */ `
85
- <ark-paginator collection-size="100" page-size="10"
86
- displayed-pages="5" current-page="1"></ark-paginator>
87
- `
88
- const paginator = container.querySelector('ark-paginator')
89
-
90
- let pageChangedEvent = null
91
- paginator.addEventListener(
92
- 'page-changed', (event) => pageChangedEvent = event)
93
-
94
- paginator._setCurrentPage(4)
95
-
96
- expect(paginator.currentPage).toEqual('4')
97
- expect(pageChangedEvent).toBeTruthy()
98
- })
99
-
100
- it('moves to the different pages', () => {
101
- container.innerHTML = /* html */ `
102
- <ark-paginator collection-size="100" page-size="10"
103
- displayed-pages="5" current-page="1"></ark-paginator>
104
- `
105
- const paginator = container.querySelector('ark-paginator')
106
-
107
- paginator.select('[data-page="4"]').click()
108
- expect(paginator.currentPage).toEqual('4')
109
-
110
- paginator.select('[data-page="6"]').click()
111
- expect(paginator.currentPage).toEqual('6')
112
-
113
- paginator.select('[on-click="_prev"]').click()
114
- expect(paginator.currentPage).toEqual('5')
115
-
116
- paginator.select('[on-click="_next"]').click()
117
- expect(paginator.currentPage).toEqual('6')
118
-
119
- paginator.select('[on-click="_first"]').click()
120
- expect(paginator.currentPage).toEqual('1')
121
-
122
- paginator.select('[on-click="_last"]').click()
123
- expect(paginator.currentPage).toEqual('10')
124
-
125
- paginator.select('[on-click="_next"]').click()
126
- expect(paginator.currentPage).toEqual('10')
127
- })
128
- })
@@ -1 +0,0 @@
1
- export { Paginator } from './components/paginator.js'
@@ -1,196 +0,0 @@
1
- const css = String.raw; export default css`
2
- .ark-paginator {
3
- background: var(--canvas, white);
4
- color: var(--ink, black);
5
- }
6
-
7
- /*-------------- THEME-------------- */
8
-
9
- .ark-paginator[background=primary] {
10
- background: var(--primary);
11
- color: white;
12
- }
13
-
14
- .ark-paginator.ark-paginator[color=primary] {
15
- color: var(--primary);
16
- }
17
-
18
- .ark-paginator[background=secondary] {
19
- background: var(--secondary);
20
- color: white;
21
- }
22
-
23
- .ark-paginator.ark-paginator[color=secondary] {
24
- color: var(--secondary);
25
- }
26
-
27
- .ark-paginator[background=success] {
28
- background: var(--success);
29
- color: white;
30
- }
31
-
32
- .ark-paginator.ark-paginator[color=success] {
33
- color: var(--success);
34
- }
35
-
36
- .ark-paginator[background=danger] {
37
- background: var(--danger);
38
- color: white;
39
- }
40
-
41
- .ark-paginator.ark-paginator[color=danger] {
42
- color: var(--danger);
43
- }
44
-
45
- .ark-paginator[background=warning] {
46
- background: var(--warning);
47
- color: white;
48
- }
49
-
50
- .ark-paginator.ark-paginator[color=warning] {
51
- color: var(--warning);
52
- }
53
-
54
- .ark-paginator[background=info] {
55
- background: var(--info);
56
- color: white;
57
- }
58
-
59
- .ark-paginator.ark-paginator[color=info] {
60
- color: var(--info);
61
- }
62
-
63
- .ark-paginator[background=dark] {
64
- background: var(--dark);
65
- color: white;
66
- }
67
-
68
- .ark-paginator.ark-paginator[color=dark] {
69
- color: var(--dark);
70
- }
71
-
72
- .ark-paginator[background=muted] {
73
- background: var(--muted);
74
- color: white;
75
- }
76
-
77
- .ark-paginator.ark-paginator[color=muted] {
78
- color: var(--muted);
79
- }
80
-
81
- .ark-paginator[background=light] {
82
- background: var(--light);
83
- color: white;
84
- }
85
-
86
- .ark-paginator.ark-paginator[color=light] {
87
- color: var(--light);
88
- }
89
-
90
- /*-------------------------------------------*/
91
-
92
- .ark-paginator__body {
93
- width: 100%;
94
- display: grid;
95
- grid-auto-flow: column;
96
- justify-content: center;
97
- align-items: center;
98
- }
99
-
100
- .ark-paginator__footer {
101
- display: grid;
102
- grid-auto-flow: column;
103
- justify-content: center;
104
- }
105
-
106
- .ark-paginator__footer small[data-info] {
107
- color: var(--primary);
108
- }
109
-
110
- .ark-paginator__buttons {
111
- margin: 10px;
112
- }
113
-
114
- .ark-paginator__buttons button {
115
- width: 1.8rem;
116
- height: 1.8rem;
117
- border: 0;
118
- margin: 0.1rem;
119
- background: inherit;
120
- }
121
-
122
- .ark-paginator__buttons button:focus {
123
- outline: none;
124
- }
125
-
126
- .ark-paginator__buttons button:active {
127
- border: 1px solid black;
128
- }
129
-
130
- .ark-paginator__buttons button[on-click=_prev],
131
- .ark-paginator__buttons button[on-click=_next] {
132
- border: 2px solid rgba(128, 128, 128, 0.411);
133
- background: white;
134
- }
135
-
136
- .ark-paginator__buttons button[on-click=_first],
137
- .ark-paginator__buttons button[on-click=_last] {
138
- border: 2px solid rgba(128, 128, 128, 0.411);
139
- background: white;
140
- }
141
-
142
- .ark-paginator__pages {
143
- display: grid;
144
- grid-auto-flow: column;
145
- }
146
-
147
- .ark-paginator__pages button {
148
- min-width: 1.8rem;
149
- width: 1.8rem;
150
- min-height: 1.8rem;
151
- height: 1.8rem;
152
- border: 1px solid var(--primary);
153
- margin: 0.1rem;
154
- text-align: center;
155
- }
156
-
157
- .ark-paginator__pages button:focus {
158
- outline: none;
159
- }
160
-
161
- .ark-paginator__pages button[active] {
162
- background: var(--primary, blue);
163
- color: white;
164
- }
165
-
166
- .ark-paginator__buttons button {
167
- border-radius: 4px;
168
- transition: transform 0.1s ease-in-out;
169
- }
170
-
171
- .ark-paginator__buttons button:hover {
172
- transform: scale(1.05);
173
- }
174
-
175
- .ark-paginator__pages {
176
- display: grid;
177
- }
178
-
179
- .ark-paginator__pages button {
180
- border-radius: 4px;
181
- transition: transform 0.1s ease-in-out;
182
- }
183
-
184
- .ark-paginator__pages button:focus {
185
- outline: none;
186
- }
187
-
188
- .ark-paginator__pages button[active] {
189
- background: var(--primary, blue);
190
- color: white;
191
- }
192
-
193
- .ark-paginator__pages button:hover {
194
- transform: scale(1.05);
195
- }
196
- `
@@ -1,2 +0,0 @@
1
- import styles from './ark.css.js'
2
- export default styles