@knowark/componarkjs 1.11.1 → 1.12.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.
@@ -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
  })
@@ -22,26 +22,40 @@ export class Paginator extends Component {
22
22
  }
23
23
 
24
24
  render () {
25
+ this._grabSlots()
25
26
  this.content = /* html */ `
26
27
  <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>
28
+ <div data-start class="ark-paginator__buttons">
30
29
  </div>
31
30
 
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('')}
31
+ <div data-middle paginator-listen on-click="_move"
32
+ class="ark-paginator__pages">
36
33
  </div>
37
34
 
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>
35
+ <div data-end class="ark-paginator__buttons">
41
36
  </div>
42
37
  </div>
43
38
  `
44
39
 
40
+ this.querySelector('[data-start]').appendChild(
41
+ this._buildButton(this.firstButton, '_first', '<<'))
42
+ this.querySelector('[data-start]').appendChild(
43
+ this._buildButton(this.previousButton, '_prev', '<'))
44
+
45
+ for (const page of this.currentPages) {
46
+ const attributes = [['data-page', page]]
47
+ if ((Number(page) === Number(this.currentPage))) {
48
+ attributes.unshift(['active', ''])
49
+ }
50
+ this.querySelector('[data-middle]').appendChild(
51
+ this._buildButton(this.pageButton, null, page, attributes))
52
+ }
53
+
54
+ this.querySelector('[data-end]').appendChild(
55
+ this._buildButton(this.nextButton, '_next', '>'))
56
+ this.querySelector('[data-end]').appendChild(
57
+ this._buildButton(this.lastButton, '_last', '>>'))
58
+
45
59
  return super.render()
46
60
  }
47
61
 
@@ -105,6 +119,30 @@ export class Paginator extends Component {
105
119
  event.stopPropagation()
106
120
  this._setCurrentPage(this.totalPages)
107
121
  }
122
+
123
+ _grabSlots() {
124
+ const [pageButton] = [this.slots.general].flat()
125
+ this.pageButton = this.pageButton ?? pageButton
126
+ const [firstButton] = [this.slots.first].flat()
127
+ this.firstButton = this.firstButton ?? firstButton
128
+ const [previousButton] = [this.slots.previous].flat()
129
+ this.previousButton = this.previousButton ?? previousButton
130
+ const [nextButton] = [this.slots.next].flat()
131
+ this.nextButton = this.nextButton ?? nextButton
132
+ const [lastButton] = [this.slots.last].flat()
133
+ this.lastButton = this.lastButton ?? lastButton
134
+ }
135
+
136
+ _buildButton (element, handler, content, attributes = []) {
137
+ const button = element ?? document.createElement('button')
138
+ button.textContent = button.textContent || content
139
+ if (handler) {
140
+ button.setAttribute('paginator-listen', '')
141
+ button.setAttribute('on-click', handler)
142
+ }
143
+ attributes.forEach(([key, value]) => button.setAttribute(key, value))
144
+ return button
145
+ }
108
146
  }
109
147
 
110
148
  Component.define(tag, Paginator, styles)
@@ -125,4 +125,24 @@ describe('Paginator', () => {
125
125
  paginator.select('[on-click="_next"]').click()
126
126
  expect(paginator.currentPage).toEqual('10')
127
127
  })
128
+
129
+ it('can be provided with custom styleable elements', () => {
130
+ container.innerHTML = /* html */ `
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>
135
+ <button data-next slot="next"></button>
136
+ <button data-last slot="last"></button>
137
+ </ark-paginator>
138
+ `
139
+
140
+ const paginator = container.querySelector('ark-paginator')
141
+
142
+ expect(paginator.querySelector('[data-first]')).toBeTruthy()
143
+ expect(paginator.querySelector('[data-previous]')).toBeTruthy()
144
+ expect(paginator.querySelector('[data-page-general]')).toBeTruthy()
145
+ expect(paginator.querySelector('[data-next]')).toBeTruthy()
146
+ expect(paginator.querySelector('[data-last]')).toBeTruthy()
147
+ })
128
148
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowark/componarkjs",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "author": "Knowark",
5
5
  "description": "Knowark's Web Components Library",
6
6
  "license": "ISC",
@@ -8,7 +8,7 @@
8
8
  <script type="importmap">
9
9
  {
10
10
  "imports": {
11
- "@knowark/componarkjs": "https://unpkg.com/@knowark/componarkjs@1.7.3/lib/index.js"
11
+ "@knowark/componarkjs": "https://unpkg.com/@knowark/componarkjs@1.11.1/lib/index.js"
12
12
  }
13
13
  }
14
14
  </script>
@@ -11,17 +11,17 @@ module.exports = (env, argv) => {
11
11
  const commonConfig = {
12
12
  mode: argv.mode,
13
13
  entry: {
14
- showcase: './lib/showcase/design/index.js'
14
+ showcase: './showcase/index.js'
15
15
  },
16
16
  plugins: [
17
17
  new CleanWebpackPlugin(),
18
18
  new HtmlWebpackPlugin({
19
19
  chunks: ['showcase', 'runtime'],
20
20
  title: 'Componark',
21
- template: './lib/showcase/design/index.html'
21
+ template: './showcase/index.html'
22
22
  }),
23
23
  new CopyWebpackPlugin({
24
- patterns: ['lib/showcase/design/.htaccess']
24
+ patterns: ['./showcase/.htaccess']
25
25
  }),
26
26
  new DefinePlugin({
27
27
  PRODUCTION: !devMode,
@@ -51,9 +51,9 @@ module.exports = (env, argv) => {
51
51
  },
52
52
  resolve: {
53
53
  alias: {
54
- base: path.resolve(__dirname, './lib/base/'),
55
- components: path.resolve(__dirname, './lib/components/'),
56
- screens: path.resolve(__dirname, './lib/showcase/screens/')
54
+ base: path.resolve(__dirname, './base/'),
55
+ components: path.resolve(__dirname, './components/'),
56
+ screens: path.resolve(__dirname, './showcase/screens/')
57
57
  }
58
58
  }
59
59
  }
@@ -77,7 +77,7 @@ module.exports = (env, argv) => {
77
77
  name: 'root',
78
78
  mode: argv.mode,
79
79
  entry: {
80
- index: './lib/showcase/index.js'
80
+ index: './showcase/index.js'
81
81
  },
82
82
  plugins: [
83
83
  new CleanWebpackPlugin(),
@@ -88,12 +88,12 @@ module.exports = (env, argv) => {
88
88
  }),
89
89
  new CopyWebpackPlugin({
90
90
  patterns: [
91
- { from: 'lib/showcase/locales/', to: 'locales/' }
91
+ { from: './showcase/locales/', to: 'locales/' }
92
92
  ]
93
93
  }),
94
94
  new HtmlWebpackPlugin({
95
95
  title: 'Componark',
96
- template: './lib/showcase/index.html'
96
+ template: './showcase/index.html'
97
97
  })
98
98
  ]
99
99
  }