Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Fix FiveStarComponent #218

Open
4 tasks
nileshtrivedi opened this issue Oct 31, 2020 · 0 comments
Open
4 tasks

Fix FiveStarComponent #218

nileshtrivedi opened this issue Oct 31, 2020 · 0 comments
Labels

Comments

@nileshtrivedi
Copy link
Contributor

I have implemented the first version of AJAX-powered FiveStarComponent.
image

Code is in: app/components/five_star_component.html.erb and a demo can be seen at /components.

<%= form_with(model: @review) do |form| %>
<div 
  x-data="{ val: <%= @review.overall_score.to_json %>, orig: <%= @review.overall_score.to_json %> }"
  class="flex ml-8 cursor-pointer text-orange-600" 
  @click="orig = val; $nextTick(() => { Rails.fire($el.parentElement,'submit') });"
>
  <input type="number" name="review[overall_score]" :value="orig" class="hidden"/>
  <span class="text-gray-400" @mouseenter="val = null" @mouseleave="val = orig"></span>

  <template x-for="item in [1,2,3,4,5]">
    <span x-text="val >= item ? '★' : '☆'" @mouseenter="val = item" @mouseleave="val = orig"></span>
  </template>

</div>
<input type="hidden" name="review[item_id]" value="<%= @review.item_id %>" />
<% end %>

Listing down all remaining tasks for this here:

  • Testing for all cases
  • Test on browsers like IE11 (where AlpineJS requires polyfill)
  • Test on touchscreen devices which may not support mouseenter or mouseleave events
  • Fix styling
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant