Skip to content

Commit 48b3c30

Browse files
alazzaragithub-actions[bot][ Cassondra ]castastropheheyMP
authored
fix: pfe-readtime word count calculation (#1537)
* cleaned up code and tied it all together * fix word-count calculation functionality * Updating readtime calculation to be based on the average readtime of supported countries * update demo page styles as well as add language code functionality * remove some css * demo page updates * Pair programming * WIP updates for multiple calls to functions from observers. * fix JS * fix for -forChangedHandler * update pfe-readtim_test * Update JS to not show pfe-readtime if the calculated readtime is <1 minute and update demo page to show this example in action. * Update elements/pfe-readtime/demo/pfe-readtime.story.js Co-authored-by: [ Cassondra ] <[email protected]> * Update elements/pfe-readtime/README.md Co-authored-by: [ Cassondra ] <[email protected]> * some code review feedback items * update vue and react test.html files * code review updates * update readme * add var for font size * WIP: AT updates * clean up test.html * fix: added setup element references to readtime element * fixes for lang fuctionality * cleanup of lang code functionality * WIP: fix hidding readtime if there is no value * Adding in getters & attributes * update changelogs * Update baselines * add test for templateString * update templateString test name * Update tests * Revert clipboard update * Update storybook * Fix template error * Update readme * remove 1 test * replace wordcunt logic with a more accurate regex * fix js and minor updates to demos * Update elements/pfe-readtime/src/pfe-readtime.js Co-authored-by: [ Cassondra ] <[email protected]> * Update elements/pfe-readtime/src/pfe-readtime.js Co-authored-by: [ Cassondra ] <[email protected]> * branch feedback and updates to demo page Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: [ Cassondra ] <[email protected]> Co-authored-by: [ Cassondra ] <[email protected]> Co-authored-by: heyMP <[email protected]>
1 parent 5892153 commit 48b3c30

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

CHANGELOG-1.x.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.5.1 (2021-04-15)
2+
3+
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: adjust word-count calculation on pfe-readtime
4+
15
# 1.5.0 (2021-04-14)
26

37
- [a1e4b67](https://github.com/patternfly/patternfly-elements/commit/a1e4b67ac012f5987e6cddf2cc7b532a135fa989) feat: Add CSS variable support for typography & background colors on tabs

elements/pfe-readtime/demo/demo.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ h3.custom-band-summary {
1717
[data-padding="30"] {
1818
padding: 30px;
1919
}
20-
.cards {
21-
display: grid;
22-
grid-auto-flow: column;
23-
grid-gap: 15px;
24-
}
2520
.card {
2621
border: 1px solid #ddd;
2722
border-radius: 3px;

elements/pfe-readtime/demo/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="es">
2+
<html lang="en">
33

44
<head>
55
<meta charset="utf-8">
@@ -83,7 +83,7 @@ <h3><code>lang</code> attribute</h3>
8383
<section class="readtime-section" word-count="1600" id="readtime1">
8484
<pfe-band color="lightest">
8585
<header slot="pfe-band--header">
86-
<h2>This is pfe-readtime with a given word-count.</h2>
86+
<h2>This is pfe-readtime with a given word-count of 1600.</h2>
8787
<h3 class="custom-band-summary">This component gets the readtime from the 'word-count' data attribute's given
8888
value. </h3>
8989
</header>
@@ -251,7 +251,7 @@ <h4>This is another header</h4>
251251
<!-- Example 3 -->
252252
<div class="container" data-padding="30">
253253

254-
<pfe-readtime for="readtime3" lang="en">-minute readtime</pfe-readtime>
254+
<pfe-readtime for="readtime3">-minute readtime</pfe-readtime>
255255

256256
<section class="readtime-section" word-count="0" id="readtime3">
257257
<pfe-band color="lightest">
@@ -272,7 +272,7 @@ <h4>This is a header</h4>
272272
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa
273273
qui officia deserunt mollit anim id est laborum.</p>
274274

275-
<div class="cards">
275+
<div class="pfe-l-grid pfe-m-gutters pfe-m-all-4-col">
276276
<div class="card" data-padding="30">
277277
<h5>Card 1</h5>
278278
<ul>

elements/pfe-readtime/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
],
5454
"license": "MIT",
5555
"dependencies": {
56-
"@patternfly/pfelement": "^1.5.0",
57-
"gh-pages": "^2.2.0"
56+
"@patternfly/pfelement": "^1.5.0"
5857
}
5958
}

elements/pfe-readtime/src/pfe-readtime.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function getEstimatedWPM(language) {
2323
return 228;
2424
}
2525
}
26+
2627
class PfeReadtime extends PFElement {
2728
static get tag() {
2829
return "pfe-readtime";
@@ -51,14 +52,6 @@ class PfeReadtime extends PFElement {
5152

5253
static get properties() {
5354
return {
54-
_lang: {
55-
title: "Language of content",
56-
type: String,
57-
attr: "lang",
58-
enum: ["en", "ko", "zh", "fr", "ja", "de", "it", "pt-br", "es"],
59-
default: () => document.documentElement.lang || "en",
60-
observer: "_langChangedHandler"
61-
},
6255
wpm: {
6356
title: "Words per minute",
6457
type: Number,
@@ -80,6 +73,14 @@ class PfeReadtime extends PFElement {
8073
default: el => el.textContent.trim() || "%t-minute readtime",
8174
observer: `render`
8275
},
76+
_lang: {
77+
title: "Language of content",
78+
type: String,
79+
attr: "lang",
80+
enum: ["en", "ko", "zh", "fr", "ja", "de", "it", "pt-br", "es"],
81+
default: () => document.documentElement.lang || "en",
82+
observer: `_langChangedHandler`
83+
},
8384
for: {
8485
title: "Element containing content",
8586
//This is the unique selector of the target
@@ -138,7 +139,7 @@ class PfeReadtime extends PFElement {
138139
this.wordCount = Number(wcAttr);
139140
}
140141
} else if (target.textContent.trim()) {
141-
this.wordCount = target.textContent.trim().split(" ").length;
142+
this.wordCount = target.textContent.split(/\b\w+\b/).length;
142143
}
143144

144145
// If a new target element is identified, re-render

0 commit comments

Comments
 (0)