Skip to content

Commit

Permalink
Replace <img> with inline SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenzia committed Jun 22, 2023
1 parent 0de2545 commit 0b367aa
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
35 changes: 35 additions & 0 deletions content/patterns/feed/examples/css/feedDisplay.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,38 @@ body {
padding: 10px;
width: 100%;
}

.restaurant-rating svg g {
color: #ffde00;
}

.restaurant-rating svg .star {
stroke-width: 2px;
stroke: #f8951d;
fill-opacity: 0;
}

.restaurant-rating[data-rating-value="1"] svg .star-1 .star {
fill: currentcolor;
fill-opacity: 1;
}

.restaurant-rating[data-rating-value="2"] svg .star-2 .star {
fill: currentcolor;
fill-opacity: 1;
}

.restaurant-rating[data-rating-value="3"] svg .star-3 .star {
fill: currentcolor;
fill-opacity: 1;
}

.restaurant-rating[data-rating-value="4"] svg .star-4 .star {
fill: currentcolor;
fill-opacity: 1;
}

.restaurant-rating[data-rating-value="5"] svg .star-5 .star {
fill: currentcolor;
fill-opacity: 1;
}
31 changes: 24 additions & 7 deletions content/patterns/feed/examples/js/feedDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,31 @@ aria.FeedDisplay.prototype.renderItemData = function (itemData) {
itemContent +=
'<div class="restaurant-rating" id="' +
ratingID +
'">' +
'<img class="restaurant-star-img" ' +
'alt="' +
itemData.rating +
' stars" ' +
'src="imgs/rating-' +
'" data-rating-value="' +
itemData.rating +
'.png">' +
'">' +
'<svg role="none" xmlns="http://www.w3.org/2000/svg" viewBox="38 -5 100 48" width="90" height="25">' +
'<defs>' +
'<g id="star">' +
'<polygon points="2.0,13.4 11.7,20.5 8.0,31.1 17.7,24.8 27.4,31.9 23.7,20.5 33.4,13.4 21.4,13.4 17.7,2.0 14.0,13.4" />' +
'</g>' +
'</defs>' +
'<g aria-label="one star" class="star-1 star-2 star-3 star-4 star-5">' +
'<use class="star" xlink:href="#star" x="0" y="0" />' +
'</g>' +
'<g aria-label="two stars" class="star-2 star-3 star-4 star-5">' +
'<use class="star" xlink:href="#star" x="35" y="0" />' +
'</g>' +
'<g aria-label="three stars" class="star-3 star-4 star-5">' +
'<use class="star" xlink:href="#star" x="70" y="0" />' +
'</g>' +
'<g aria-label="four stars" class="star-4 star-5">' +
'<use class="star" xlink:href="#star" x="105" y="0" />' +
'</g>' +
'<g aria-label="five stars" class="star-5">' +
'<use class="star" xlink:href="#star" x="140" y="0" />' +
'</g>' +
'</svg>' +
'</div>';
describedbyIDs.push(ratingID);
}
Expand Down

0 comments on commit 0b367aa

Please sign in to comment.