-
Notifications
You must be signed in to change notification settings - Fork 17
/
demo.js
118 lines (105 loc) · 3.02 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { html, render } from 'lit';
import changelog from './CHANGELOG.md';
import readme from './README.md';
import './index';
import '../../10-atoms/button';
import '../../10-atoms/text';
export default {
title: 'Examples/File Upload/Pure HTML',
parameters: {
readme,
usage: { disable: true },
changelog,
controls: { disable: true },
},
};
export const GetFilesFromOnchange = () => {
const changeHandler = e => {
const files = e.detail;
if (files.length > 0) {
const listWrapper = html`
<div class="js-file-upload__list-wrapper">
<h3>The following files were selected:</h3>
<ol>
${files.map(file => {
return html` <li>${file.name}</li> `;
})}
</ol>
</div>
`;
render(listWrapper, document.getElementById('listWrapper'));
} else {
render('', document.getElementById('listWrapper'));
}
};
return html`
<div style="width:455px;">
<axa-file-upload
@change="${changeHandler}"
maxSizeOfSingleFileKB="500"
class="js-file-upload__file-upload"
>These files are going to be uploaded</axa-file-upload
>
</div>
<div id="listWrapper"></div>
`;
};
export const InAForm = () => {
const handleSubmit = e => {
e.preventDefault();
const imgUpload = document.querySelector('.js-file-upload__file-upload');
if (imgUpload.files.length > 0) {
const listWrapper = html`
<div class="js-file-upload__list-wrapper">
<h3>The following files were selected:</h3>
<ol>
${imgUpload.files.map(file => {
return html` <li>${file.name}</li> `;
})}
</ol>
</div>
`;
render(listWrapper, document.getElementById('listWrapper'));
}
};
return html`
<div style="width:455px;">
<axa-file-upload
maxSizeOfSingleFileKB="500"
class="js-file-upload__file-upload"
>These files are going to be uploaded
</axa-file-upload>
</div>
<form @click="${handleSubmit}" style="margin-top:40px;">
<axa-button type="submit">Submit</axa-button>
</form>
<div id="listWrapper"></div>
`;
};
export const Invalid = () => {
const handleSubmit = () => {
const textSelector = document.querySelector('axa-text');
if (document.querySelector('axa-file-upload').hasAttribute('invalid')) {
textSelector.innerHTML =
'could not submit because file-upload is invalid';
textSelector.style.color = '#c91432';
} else {
textSelector.innerHTML = 'submitted successfully';
textSelector.style.color = '#000000';
}
};
return html`
<div style="width: 455px">
<axa-file-upload
allowedFileTypes="image/jpg, image/jpeg, application/pdf, image/png"
>
The following files are being transferred:
</axa-file-upload>
</div>
<axa-button style="margin: 10px 0" @click="${handleSubmit}">
Submit
</axa-button>
<br />
<axa-text size="2"></axa-text>
`;
};