|
12 | 12 | --ion-safe-area-top: 20px; |
13 | 13 | --ion-safe-area-bottom: 22px; |
14 | 14 | } |
| 15 | + |
| 16 | + ion-content { |
| 17 | + user-select: none; |
| 18 | + } |
| 19 | + |
| 20 | + ion-item { |
| 21 | + --padding-start: 8px; |
| 22 | + } |
| 23 | + |
15 | 24 | .unread { |
16 | 25 | width: 10px; |
17 | 26 | height: 10px; |
18 | 27 | border-radius: 10px; |
19 | 28 | background-color: #3684ff; |
20 | | - position: absolute; |
21 | | - left: 0; |
22 | | - margin-top: 0.4em; |
| 29 | + margin-top: 15px; |
| 30 | + margin-right: 8px; |
| 31 | + align-self: start; |
23 | 32 | } |
24 | | - |
| 33 | + |
25 | 34 | ion-item h2 { |
26 | 35 | font-weight: 500 !important; |
27 | 36 | } |
28 | | - |
| 37 | + |
29 | 38 | ion-item h3 { |
30 | 39 | color: #777; |
31 | 40 | } |
|
41 | 50 | </ion-toolbar> |
42 | 51 | </ion-header> |
43 | 52 |
|
44 | | - <ion-content padding> |
| 53 | + <ion-content> |
45 | 54 | <ion-refresher slot="fixed" id="refresher"> |
46 | 55 | <ion-refresher-content></ion-refresher-content> |
47 | 56 | </ion-refresher> |
48 | | - |
| 57 | + |
49 | 58 | <ion-list></ion-list> |
50 | 59 | </ion-content> |
51 | 60 | </ion-app> |
52 | | - |
| 61 | + |
53 | 62 | <script> |
54 | 63 | const refresher = document.getElementById('refresher'); |
55 | 64 | const names = [ |
|
67 | 76 | 'Rachel Rabbit', |
68 | 77 | 'Ted Turtle' |
69 | 78 | ]; |
70 | | - |
| 79 | + |
71 | 80 | refresher.addEventListener('ionRefresh', () => { |
72 | 81 | setTimeout(() => { |
73 | 82 | prependMessages(5, true); |
74 | 83 | refresher.complete(); |
75 | 84 | }, 2000); |
76 | | - }) |
77 | | - |
| 85 | + }) |
| 86 | + |
78 | 87 | const list = document.querySelector('ion-list'); |
79 | 88 | appendMessages(5); |
80 | | - |
| 89 | + |
81 | 90 | function chooseRandomName() { |
82 | 91 | return names[Math.floor(Math.random() * names.length)]; |
83 | 92 | } |
84 | | - |
| 93 | + |
85 | 94 | function appendMessages(numMessages = 1, unread) { |
86 | 95 | for (let i = 0; i < numMessages; i++) { |
87 | 96 | list.appendChild(createMessage(unread)); |
88 | 97 | } |
89 | 98 | } |
90 | | - |
| 99 | + |
91 | 100 | function prependMessages(numMessages = 1, unread) { |
92 | 101 | for (let i = 0; i < numMessages; i++) { |
93 | 102 | list.insertBefore(createMessage(unread), list.firstChild); |
|
97 | 106 | function createMessage(unread = false) { |
98 | 107 | let item = document.createElement('ion-item'); |
99 | 108 | item.innerHTML = ` |
100 | | - <ion-label text-wrap> |
101 | | - <div class="${(unread) ? 'unread' : 'read'}"></div> |
| 109 | + <div slot="start" class="${(unread) ? 'unread' : 'read'}"></div> |
| 110 | + <ion-label class="ion-text-wrap"> |
102 | 111 | <h2>${chooseRandomName()}</h2> |
103 | 112 | <h3>Lorem ipsum dolor sit amet, consectetur adipiscing elit</h3> |
104 | 113 | </ion-label> |
105 | 114 | `; |
106 | | - |
| 115 | + |
107 | 116 | return item; |
108 | 117 | } |
109 | 118 | </script> |
|
0 commit comments