Wajahat698 commited on
Commit
1ff5033
·
verified ·
1 Parent(s): 71aa5e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -1976,22 +1976,32 @@ function refresh() {
1976
  }
1977
  """
1978
  custom_css = """
1979
- <style>
1980
- /* Target specific buttons using elem_id or data-testid */
1981
- button[data-testid="vw-owners-btn"]:focus,
1982
- button[data-testid="vw-prospects-btn"]:focus {
1983
- border-color: darkblue !important;
1984
- outline: none;
1985
- }
1986
- </style>
1987
  """
1988
 
1989
- def set_vw_owners():
1990
- pass # Do nothing, just to handle button click
1991
-
1992
- def set_vw_prospects():
1993
- pass # Do nothing, just to handle button click
 
 
 
 
 
 
1994
 
 
 
 
 
 
1995
  with gr.Blocks(js=js_func) as demo:
1996
  with gr.Column():
1997
  gr.Markdown(
@@ -2008,14 +2018,12 @@ with gr.Blocks(js=js_func) as demo:
2008
  with gr.Column():
2009
  with gr.Row():
2010
 
2011
- gr.HTML(custom_css) # Inject custom CSS
2012
  # Define buttons with specific elem_id for targeting
2013
- vw_customers_btn = gr.Button("VW Owners", elem_id="vw-owners-btn")
2014
- vw_prospects_btn = gr.Button("VW Prospects", elem_id="vw-prospects-btn")
2015
 
2016
- # Button click handlers, but no output displayed
2017
- vw_customers_btn.click(set_vw_owners)
2018
- vw_prospects_btn.click(set_vw_prospects)
2019
 
2020
  with gr.Row():
2021
  with gr.Column():
 
1976
  }
1977
  """
1978
  custom_css = """
1979
+ .highlighted {
1980
+ background-color: #4CAF50; /* Green color when clicked */
1981
+ color: white;
1982
+ }
1983
+ .gr-button {
1984
+ margin: 10px;
1985
+ }
 
1986
  """
1987
 
1988
+ # JavaScript to handle button clicks
1989
+ custom_js = """
1990
+ function highlightButton(event) {
1991
+ // Remove 'highlighted' class from all buttons
1992
+ var buttons = document.querySelectorAll('.gr-button');
1993
+ buttons.forEach(function(button) {
1994
+ button.classList.remove('highlighted');
1995
+ });
1996
+ // Add 'highlighted' class to the clicked button
1997
+ event.target.classList.add('highlighted');
1998
+ }
1999
 
2000
+ // Attach the highlightButton function to button clicks
2001
+ document.querySelectorAll('.gr-button').forEach(function(button) {
2002
+ button.addEventListener('click', highlightButton);
2003
+ });
2004
+ """
2005
  with gr.Blocks(js=js_func) as demo:
2006
  with gr.Column():
2007
  gr.Markdown(
 
2018
  with gr.Column():
2019
  with gr.Row():
2020
 
2021
+ gr.HTML(f"<style>{custom_css}</style><script>{custom_js}</script>")
2022
  # Define buttons with specific elem_id for targeting
2023
+ vw_customers_btn = gr.Button("VW Owners")
2024
+ vw_prospects_btn = gr.Button("VW Prospects")
2025
 
2026
+
 
 
2027
 
2028
  with gr.Row():
2029
  with gr.Column():