-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PBNTR-285] Star Rating kit: interactive form variant (Rails) (#3523)
[PBNTR-285 ](https://runway.powerhrg.com/backlog_items/PBNTR-285) This PR adds a new interactive variant for the star rating kit. ![Screenshot 2024-07-11 at 4 13 27 PM](https://github.com/user-attachments/assets/3a708fa9-a697-454b-ab7e-22e5b7d8f30b) ![Screenshot 2024-07-11 at 4 13 46 PM](https://github.com/user-attachments/assets/0799b777-859e-46aa-a8c2-08315ef1cb16) **How to test?** Steps to confirm the desired behavior: 1. Go to the star rating kit 2. click to see the interactive functionally #### Checklist: - [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [x] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code.
- Loading branch information
1 parent
5e47c64
commit a07c7f8
Showing
10 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
playbook/app/pb_kits/playbook/pb_star_rating/docs/_star_rating_interactive.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= pb_rails("star_rating", props: { padding_bottom: "xs", variant: "interactive" }) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import PbEnhancedElement from "../pb_enhanced_element"; | ||
|
||
const STAR_RATING_SELECTOR = "[data-pb-star-rating]"; | ||
const STAR_RATING_INPUT_ID = "star-rating-input"; | ||
|
||
export default class PbStarRating extends PbEnhancedElement { | ||
static get selector() { | ||
return STAR_RATING_SELECTOR; | ||
} | ||
|
||
connect() { | ||
this.element.addEventListener("click", (event) => { | ||
const clickedStarId = event.currentTarget.id; | ||
this.updateStarColors(clickedStarId); | ||
this.updateHiddenInputValue(clickedStarId); | ||
}); | ||
} | ||
|
||
updateStarColors(clickedStarId) { | ||
const allStars = document.querySelectorAll(STAR_RATING_SELECTOR); | ||
|
||
allStars.forEach(star => { | ||
const starId = star.id; | ||
const icon = star.querySelector(".interactive-star-icon"); | ||
|
||
if (icon) { | ||
if (starId <= clickedStarId) { | ||
if (star.classList.contains("yellow_star")) { | ||
icon.classList.add("yellow-star-selected"); | ||
} else if (star.classList.contains("primary_star")) { | ||
icon.classList.add("primary-star-selected"); | ||
} else if (star.classList.contains("suble_star_light")) { | ||
icon.classList.add("suble-star-selected"); | ||
} else { | ||
icon.classList.add("yellow-star-selected"); | ||
} | ||
} else { | ||
icon.classList.remove("yellow-star-selected", "primary-star-selected", "suble-star-selected"); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
updateHiddenInputValue(value) { | ||
const hiddenInput = document.getElementById(STAR_RATING_INPUT_ID); | ||
if (hiddenInput) { | ||
hiddenInput.value = value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Playbook | ||
module Forms | ||
class Builder | ||
def star_rating_field(name, props: {}) | ||
props[:name] = name | ||
props[:margin_bottom] = "sm" | ||
props[:label] = @template.label(@object_name, name) if props[:label] == true | ||
@template.pb_rails("star_rating", props: props) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters