@aarongustafson/pull-to-refresh 1.1.1 → 1.1.2
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.
- package/README.md +97 -61
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ npm install @aarongustafson/pull-to-refresh
|
|
|
43
43
|
### Usage
|
|
44
44
|
|
|
45
45
|
**Option 1: Manual registration**
|
|
46
|
+
|
|
46
47
|
```javascript
|
|
47
48
|
import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
|
|
48
49
|
|
|
@@ -50,6 +51,7 @@ customElements.define('pull-to-refresh', PullToRefreshElement);
|
|
|
50
51
|
```
|
|
51
52
|
|
|
52
53
|
**Option 2: Auto-define (browser environments only)**
|
|
54
|
+
|
|
53
55
|
```javascript
|
|
54
56
|
import '@aarongustafson/pull-to-refresh/define.js';
|
|
55
57
|
// Registers <pull-to-refresh> when customElements is available
|
|
@@ -66,7 +68,10 @@ definePullToRefresh();
|
|
|
66
68
|
You can also include the guarded script from HTML:
|
|
67
69
|
|
|
68
70
|
```html
|
|
69
|
-
<script
|
|
71
|
+
<script
|
|
72
|
+
src="./node_modules/@aarongustafson/pull-to-refresh/define.js"
|
|
73
|
+
type="module"
|
|
74
|
+
></script>
|
|
70
75
|
```
|
|
71
76
|
|
|
72
77
|
### Basic Example
|
|
@@ -87,8 +92,8 @@ You can also include the guarded script from HTML:
|
|
|
87
92
|
ptr.addEventListener('ptr:refresh', (e) => {
|
|
88
93
|
// Perform your refresh logic (fetch data, etc.)
|
|
89
94
|
fetch('/api/data')
|
|
90
|
-
.then(response => response.json())
|
|
91
|
-
.then(data => {
|
|
95
|
+
.then((response) => response.json())
|
|
96
|
+
.then((data) => {
|
|
92
97
|
// Update your content
|
|
93
98
|
updateContent(data);
|
|
94
99
|
// Signal completion
|
|
@@ -102,15 +107,15 @@ You can also include the guarded script from HTML:
|
|
|
102
107
|
|
|
103
108
|
### Attributes
|
|
104
109
|
|
|
105
|
-
| Attribute
|
|
106
|
-
|
|
107
|
-
| `threshold`
|
|
108
|
-
| `indicator-text`
|
|
109
|
-
| `release-text`
|
|
110
|
-
| `refreshing-text`
|
|
111
|
-
| `lang`
|
|
112
|
-
| `disabled`
|
|
113
|
-
| `disable-selection` | boolean | `false`
|
|
110
|
+
| Attribute | Type | Default | Description |
|
|
111
|
+
| ------------------- | ------- | ------------- | ------------------------------------------- |
|
|
112
|
+
| `threshold` | number | `80` | Distance in pixels to trigger refresh |
|
|
113
|
+
| `indicator-text` | string | localized | Text shown when pulling down |
|
|
114
|
+
| `release-text` | string | localized | Text shown when ready to release |
|
|
115
|
+
| `refreshing-text` | string | localized | Text shown while refreshing |
|
|
116
|
+
| `lang` | string | auto-detected | Language code for localization |
|
|
117
|
+
| `disabled` | boolean | `false` | Disables pull-to-refresh functionality |
|
|
118
|
+
| `disable-selection` | boolean | `false` | Prevents text selection during pull gesture |
|
|
114
119
|
|
|
115
120
|
**Note:** The text attributes use automatic localization based on the `lang` attribute or auto-detection. See [Localization](#-localization-i18n) below.
|
|
116
121
|
|
|
@@ -127,13 +132,13 @@ ptr.disabled = true;
|
|
|
127
132
|
|
|
128
133
|
### Events
|
|
129
134
|
|
|
130
|
-
| Event
|
|
131
|
-
|
|
132
|
-
| `ptr:pull-start`
|
|
133
|
-
| `ptr:pull-move`
|
|
134
|
-
| `ptr:pull-end`
|
|
135
|
-
| `ptr:refresh`
|
|
136
|
-
| `ptr:refresh-complete` | `{}`
|
|
135
|
+
| Event | Detail | Description |
|
|
136
|
+
| ---------------------- | ------------------------ | ------------------------------- |
|
|
137
|
+
| `ptr:pull-start` | `{}` | Fired when pull gesture starts |
|
|
138
|
+
| `ptr:pull-move` | `{ distance: number }` | Fired during pull gesture |
|
|
139
|
+
| `ptr:pull-end` | `{}` | Fired when pull gesture ends |
|
|
140
|
+
| `ptr:refresh` | `{ complete: Function }` | Fired when refresh is triggered |
|
|
141
|
+
| `ptr:refresh-complete` | `{}` | Fired when refresh completes |
|
|
137
142
|
|
|
138
143
|
**Important**: Call `event.detail.complete()` in your `ptr:refresh` handler to signal completion:
|
|
139
144
|
|
|
@@ -149,25 +154,25 @@ If you don't call `complete()`, the component will auto-complete after 2 seconds
|
|
|
149
154
|
|
|
150
155
|
### Slots
|
|
151
156
|
|
|
152
|
-
| Slot
|
|
153
|
-
|
|
154
|
-
| (default)
|
|
157
|
+
| Slot | Description |
|
|
158
|
+
| ----------- | --------------------------------- |
|
|
159
|
+
| (default) | Your scrollable content |
|
|
155
160
|
| `indicator` | Optional custom indicator element |
|
|
156
161
|
|
|
157
162
|
### CSS Custom Properties
|
|
158
163
|
|
|
159
|
-
| Property
|
|
160
|
-
|
|
161
|
-
| `--ptr-indicator-height`
|
|
162
|
-
| `--ptr-indicator-bg`
|
|
163
|
-
| `--ptr-indicator-color`
|
|
164
|
-
| `--ptr-indicator-font-size` | `0.875rem`
|
|
165
|
-
| `--ptr-transition-duration` | `0.2s`
|
|
164
|
+
| Property | Default | Description |
|
|
165
|
+
| --------------------------- | ------------ | --------------------------------- |
|
|
166
|
+
| `--ptr-indicator-height` | `3.125rem` | Height of the indicator area |
|
|
167
|
+
| `--ptr-indicator-bg` | `ButtonFace` | Background color of indicator |
|
|
168
|
+
| `--ptr-indicator-color` | `ButtonText` | Text color of indicator |
|
|
169
|
+
| `--ptr-indicator-font-size` | `0.875rem` | Font size of indicator text |
|
|
170
|
+
| `--ptr-transition-duration` | `0.2s` | Duration of indicator transitions |
|
|
166
171
|
|
|
167
172
|
### Methods
|
|
168
173
|
|
|
169
|
-
| Method
|
|
170
|
-
|
|
174
|
+
| Method | Description |
|
|
175
|
+
| ------------------- | -------------------------------------------------------------------------------- |
|
|
171
176
|
| `completeRefresh()` | Manually complete the refresh (alternative to calling `event.detail.complete()`) |
|
|
172
177
|
|
|
173
178
|
## Examples
|
|
@@ -202,6 +207,7 @@ The component automatically detects the language and displays localized text:
|
|
|
202
207
|
```
|
|
203
208
|
|
|
204
209
|
The component supports 16 languages with automatic fallback to English. Language is detected from:
|
|
210
|
+
|
|
205
211
|
1. The element's `lang` attribute
|
|
206
212
|
2. The nearest ancestor's `lang` attribute
|
|
207
213
|
3. The document's `lang` attribute
|
|
@@ -216,8 +222,8 @@ PullToRefreshElement.registerTranslations({
|
|
|
216
222
|
'pt-BR': {
|
|
217
223
|
indicator: '↓ Puxe para atualizar',
|
|
218
224
|
release: '↻ Solte para atualizar',
|
|
219
|
-
refreshing: '⏳ Atualizando...'
|
|
220
|
-
}
|
|
225
|
+
refreshing: '⏳ Atualizando...',
|
|
226
|
+
},
|
|
221
227
|
});
|
|
222
228
|
```
|
|
223
229
|
|
|
@@ -226,8 +232,8 @@ PullToRefreshElement.registerTranslations({
|
|
|
226
232
|
```html
|
|
227
233
|
<style>
|
|
228
234
|
pull-to-refresh {
|
|
229
|
-
--ptr-indicator-bg: #
|
|
230
|
-
--ptr-indicator-color: #
|
|
235
|
+
--ptr-indicator-bg: #102030;
|
|
236
|
+
--ptr-indicator-color: #ffffff;
|
|
231
237
|
--ptr-indicator-font-size: 1rem;
|
|
232
238
|
--ptr-indicator-height: 3.75rem;
|
|
233
239
|
}
|
|
@@ -238,13 +244,41 @@ PullToRefreshElement.registerTranslations({
|
|
|
238
244
|
</pull-to-refresh>
|
|
239
245
|
```
|
|
240
246
|
|
|
247
|
+
The indicator defaults to `ButtonText` on `ButtonFace`. Set
|
|
248
|
+
`--ptr-indicator-bg` and `--ptr-indicator-color` together; changing one can
|
|
249
|
+
make the other unreadable. Custom properties override these defaults and
|
|
250
|
+
inherit from the host. A custom slotted indicator supplies its own markup
|
|
251
|
+
and styles. Test your complete pair, including nested text, in each supported
|
|
252
|
+
scheme and user palette. Automatic forced-color adjustment remains enabled.
|
|
253
|
+
The indicator uses different authored or localized messages for pulling,
|
|
254
|
+
release, and loading, rather than color alone.
|
|
255
|
+
|
|
256
|
+
The demos use `CanvasText` on `Canvas` for reading surfaces and status
|
|
257
|
+
messages, `ButtonText` on `ButtonFace` for code and buttons, and
|
|
258
|
+
`MarkText` on `Mark` for marked examples. They preserve native keyboard focus.
|
|
259
|
+
Each standalone demo includes a native Refresh form: enhancement runs the
|
|
260
|
+
existing refresh handler; without JavaScript or a successful module load,
|
|
261
|
+
the form reloads the document. The component does not generate a keyboard
|
|
262
|
+
button. Supply one for tasks that must not depend on a pull gesture.
|
|
263
|
+
Keep existing data visible during loading or failure, provide a readable
|
|
264
|
+
error and retry action, and call `event.detail.complete()` when your handler
|
|
265
|
+
finishes. Completion reports the end of the interaction, not success.
|
|
266
|
+
|
|
267
|
+
Recorded-palette substitution and browser emulation are regression checks,
|
|
268
|
+
not proof of native high-contrast repainting or assistive-technology support.
|
|
269
|
+
The recorded study’s 19 distinct palettes pass the tested demo pairs; bundled
|
|
270
|
+
Ubuntu WebKit has a known dark `ButtonText`/`ButtonFace` contrast limitation
|
|
271
|
+
outside that dataset. The browser suite tracks it as a narrowly scoped expected
|
|
272
|
+
failure instead of replacing every platform’s native pair.
|
|
273
|
+
|
|
241
274
|
### Custom Messages
|
|
242
275
|
|
|
243
276
|
```html
|
|
244
277
|
<pull-to-refresh
|
|
245
278
|
indicator-text="⬇ Swipe down"
|
|
246
279
|
release-text="🔄 Let go!"
|
|
247
|
-
refreshing-text="⏳ Loading..."
|
|
280
|
+
refreshing-text="⏳ Loading..."
|
|
281
|
+
>
|
|
248
282
|
<div>Content here</div>
|
|
249
283
|
</pull-to-refresh>
|
|
250
284
|
```
|
|
@@ -292,24 +326,24 @@ ptr.addEventListener('ptr:pull-move', (e) => {
|
|
|
292
326
|
|
|
293
327
|
The component includes built-in translations for **16 languages**:
|
|
294
328
|
|
|
295
|
-
| Language
|
|
296
|
-
|
|
297
|
-
| English
|
|
298
|
-
| Chinese (Mandarin) | `zh` | ↓ 下拉刷新
|
|
299
|
-
| Hindi
|
|
300
|
-
| Spanish
|
|
301
|
-
| French
|
|
302
|
-
| Arabic
|
|
303
|
-
| Bengali
|
|
304
|
-
| Portuguese
|
|
305
|
-
| Russian
|
|
306
|
-
| Japanese
|
|
307
|
-
| German
|
|
308
|
-
| Punjabi
|
|
309
|
-
| Javanese
|
|
310
|
-
| Korean
|
|
311
|
-
| Vietnamese
|
|
312
|
-
| Italian
|
|
329
|
+
| Language | Code | Indicator Text |
|
|
330
|
+
| ------------------ | ---- | ---------------------------- |
|
|
331
|
+
| English | `en` | ↓ Pull to refresh |
|
|
332
|
+
| Chinese (Mandarin) | `zh` | ↓ 下拉刷新 |
|
|
333
|
+
| Hindi | `hi` | ↓ रीफ्रेश करने के लिए खींचें |
|
|
334
|
+
| Spanish | `es` | ↓ Desliza para actualizar |
|
|
335
|
+
| French | `fr` | ↓ Tirez pour actualiser |
|
|
336
|
+
| Arabic | `ar` | ↓ اسحب للتحديث |
|
|
337
|
+
| Bengali | `bn` | ↓ রিফ্রেশ করতে টানুন |
|
|
338
|
+
| Portuguese | `pt` | ↓ Puxe para atualizar |
|
|
339
|
+
| Russian | `ru` | ↓ Потяните для обновления |
|
|
340
|
+
| Japanese | `ja` | ↓ 引っ張って更新 |
|
|
341
|
+
| German | `de` | ↓ Zum Aktualisieren ziehen |
|
|
342
|
+
| Punjabi | `pa` | ↓ ਤਾਜ਼ਾ ਕਰਨ ਲਈ ਖਿੱਚੋ |
|
|
343
|
+
| Javanese | `jv` | ↓ Tarik kanggo nyegerake |
|
|
344
|
+
| Korean | `ko` | ↓ 당겨서 새로고침 |
|
|
345
|
+
| Vietnamese | `vi` | ↓ Kéo để làm mới |
|
|
346
|
+
| Italian | `it` | ↓ Trascina per aggiornare |
|
|
313
347
|
|
|
314
348
|
### Language Detection
|
|
315
349
|
|
|
@@ -331,20 +365,20 @@ import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
|
|
|
331
365
|
|
|
332
366
|
// Add a new language
|
|
333
367
|
PullToRefreshElement.registerTranslations({
|
|
334
|
-
|
|
368
|
+
nl: {
|
|
335
369
|
indicator: '↓ Trek om te vernieuwen',
|
|
336
370
|
release: '↻ Loslaten om te vernieuwen',
|
|
337
|
-
refreshing: '⏳ Vernieuwen...'
|
|
338
|
-
}
|
|
371
|
+
refreshing: '⏳ Vernieuwen...',
|
|
372
|
+
},
|
|
339
373
|
});
|
|
340
374
|
|
|
341
375
|
// Override existing translations
|
|
342
376
|
PullToRefreshElement.registerTranslations({
|
|
343
|
-
|
|
377
|
+
en: {
|
|
344
378
|
indicator: '⬇ Pull down',
|
|
345
379
|
release: '🔄 Let go',
|
|
346
|
-
refreshing: '⏳ Loading...'
|
|
347
|
-
}
|
|
380
|
+
refreshing: '⏳ Loading...',
|
|
381
|
+
},
|
|
348
382
|
});
|
|
349
383
|
```
|
|
350
384
|
|
|
@@ -356,7 +390,8 @@ You can always override translations for individual instances:
|
|
|
356
390
|
<pull-to-refresh
|
|
357
391
|
lang="es"
|
|
358
392
|
indicator-text="Custom Spanish text"
|
|
359
|
-
release-text="Custom release text"
|
|
393
|
+
release-text="Custom release text"
|
|
394
|
+
>
|
|
360
395
|
<!-- Content -->
|
|
361
396
|
</pull-to-refresh>
|
|
362
397
|
```
|
|
@@ -382,6 +417,7 @@ npm run format # Format code
|
|
|
382
417
|
## Browser Support
|
|
383
418
|
|
|
384
419
|
Works in all modern browsers supporting:
|
|
420
|
+
|
|
385
421
|
- Custom Elements v1
|
|
386
422
|
- Shadow DOM v1
|
|
387
423
|
- ES Modules
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarongustafson/pull-to-refresh",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Web component that enables pull-to-refresh functionality.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html",
|
|
@@ -56,16 +56,18 @@
|
|
|
56
56
|
"test:ui": "vitest --ui",
|
|
57
57
|
"test:run": "vitest run",
|
|
58
58
|
"test:coverage": "vitest run --coverage",
|
|
59
|
+
"test:browser": "playwright test",
|
|
59
60
|
"lint": "npm run lint:eslint && npm run lint:prettier",
|
|
60
61
|
"format": "npm run format:eslint && npm run format:prettier",
|
|
61
62
|
"lint:eslint": "eslint .",
|
|
62
63
|
"format:eslint": "eslint . --fix",
|
|
63
|
-
"lint:prettier": "prettier \"**/*.js\" --check --ignore-path .gitignore",
|
|
64
|
-
"format:prettier": "prettier \"**/*.js\" --write --ignore-path .gitignore",
|
|
64
|
+
"lint:prettier": "prettier \"**/*.{js,ts,html,css,md,json}\" --check --ignore-path .gitignore",
|
|
65
|
+
"format:prettier": "prettier \"**/*.{js,ts,html,css,md,json}\" --write --ignore-path .gitignore",
|
|
65
66
|
"version": "node scripts/update-demo-versions.js && git add demo/esm.html",
|
|
66
67
|
"postversion": "git push --follow-tags"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
70
|
+
"@playwright/test": "^1.64.0",
|
|
69
71
|
"@open-wc/eslint-config": "^13.1.0",
|
|
70
72
|
"@testing-library/dom": "^10.4.2",
|
|
71
73
|
"@testing-library/user-event": "^14.6.7",
|