GSMEthesis commited on
Commit
93286bb
·
verified ·
1 Parent(s): 73a7f64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -48
app.py CHANGED
@@ -808,58 +808,71 @@ def enhanced_likert_scale(question_data):
808
  if selected_value is not None:
809
  st.session_state[key] = selected_value
810
 
811
- onclick_js = "parent.document.querySelectorAll('div[data-testid=\"stRadio\"] input[type=\"radio\"]')[{i}].click()"
812
- # نمایش دکمه‌های سفارشی
813
- st.markdown(
814
- """
 
 
 
 
 
 
 
 
815
  <style>
816
- div[data-testid="stRadio"] > div[role="radiogroup"] {
817
- display: none !important;
818
- }
819
- .custom-likert-container {
820
- display: flex;
821
- justify-content: space-between;
822
- max-width: 475px;
823
- margin: 0 auto;
824
- direction: rtl;
825
- }
826
- .likert-option {
827
- width: 28px;
828
- height: 28px;
829
- border-radius: 50%;
830
- background: white;
831
- border: 2px solid #6a0dad;
832
- display: flex;
833
- align-items: center;
834
- justify-content: center;
835
- cursor: pointer;
836
- margin: 0 5px;
837
- position: relative;
838
- }
839
- .likert-option.selected {
840
- background: #6a0dad;
841
- }
842
- .likert-number {
843
- color: #6a0dad;
844
- font-weight: bold;
845
- font-size: 14px;
846
- }
847
- .likert-option.selected .likert-number {
848
- color: white;
849
- }
 
 
 
850
  </style>
851
- """ +
852
- ''.join([
853
- f'<div class="likert-option {"selected" if st.session_state.get(key) == i+1 else ""}" onclick="{onclick_js.format(i=i)}">'
854
- f'<span class="likert-number">{i+1}</span>'
855
- '</div>'
856
- for i in range(scale)
857
- ]) +
858
- "</div>",
859
- unsafe_allow_html=True
 
 
860
  )
861
 
862
- # نمایش پاسخ انتخاب شده
863
  status = f"پاسخ شما: {st.session_state[key]}" if st.session_state.get(key) else "پاسخ شما: هنوز انتخاب نشده"
864
  st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl; margin-top:10px;'>{status}</p>",
865
  unsafe_allow_html=True)
 
808
  if selected_value is not None:
809
  st.session_state[key] = selected_value
810
 
811
+ # ایجاد دکمه‌های سفارشی با JavaScript اختصاصی
812
+ components.html(
813
+ f"""
814
+ <script>
815
+ function selectOption(value) {{
816
+ const radioInput = parent.document.querySelector('input[type="radio"][value="' + value + '"]');
817
+ if (radioInput) {{
818
+ radioInput.click();
819
+ }}
820
+ }}
821
+ </script>
822
+
823
  <style>
824
+ .likert-container {{
825
+ display: flex;
826
+ justify-content: space-between;
827
+ width: 100%;
828
+ max-width: 475px;
829
+ margin: 0 auto;
830
+ direction: rtl;
831
+ }}
832
+ .likert-option {{
833
+ width: 32px;
834
+ height: 32px;
835
+ border-radius: 50%;
836
+ background: white;
837
+ border: 2px solid #6a0dad;
838
+ display: flex;
839
+ align-items: center;
840
+ justify-content: center;
841
+ cursor: pointer;
842
+ margin: 0 2px;
843
+ transition: all 0.2s;
844
+ }}
845
+ .likert-option:hover {{
846
+ transform: scale(1.1);
847
+ box-shadow: 0 0 8px rgba(106, 13, 173, 0.3);
848
+ }}
849
+ .likert-option.selected {{
850
+ background: #6a0dad;
851
+ }}
852
+ .likert-number {{
853
+ color: #6a0dad;
854
+ font-weight: bold;
855
+ font-size: 14px;
856
+ user-select: none;
857
+ }}
858
+ .likert-option.selected .likert-number {{
859
+ color: white;
860
+ }}
861
  </style>
862
+
863
+ <div class="likert-container">
864
+ {"".join([
865
+ f'<div class="likert-option {"selected" if st.session_state.get(key) == i+1 else ""}" onclick="selectOption({i+1})">'
866
+ f'<span class="likert-number">{i+1}</span>'
867
+ '</div>'
868
+ for i in range(scale)
869
+ ])}
870
+ </div>
871
+ """,
872
+ height=50
873
  )
874
 
875
+ # نمایش وضعیت انتخاب
876
  status = f"پاسخ شما: {st.session_state[key]}" if st.session_state.get(key) else "پاسخ شما: هنوز انتخاب نشده"
877
  st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl; margin-top:10px;'>{status}</p>",
878
  unsafe_allow_html=True)