Skip to content

Commit 078c64e

Browse files
metc1999Carson-Shaar
authored andcommitted
fix: switch component
1 parent bc22862 commit 078c64e

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

zero_true/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
from zt_backend.models.components.html import HTML, pygwalker
2020
from zt_backend.models.state.state import state
2121
from zt_backend.models.state.state import global_state
22-
from zt_backend.models.components.chat_ui import chat_ui
22+
from zt_backend.models.components.chat_ui import chat_ui
23+
from zt_backend.models.components.switch import Switch
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import List, Optional,Union
2+
from pydantic import Field, field_validator, validator
3+
from zt_backend.models.components.zt_component import ZTComponent
4+
from zt_backend.models.components.validations import validate_color
5+
from zt_backend.models.state.user_state import UserContext
6+
7+
class Switch(ZTComponent):
8+
"""A slider component that allows a user to select a range of values"""
9+
component: str = Field("v-switch", description="Vue component name")
10+
value: str = Field ('', description="The input text value")
11+
hint: Optional[str] = Field('', description="Hint text for switch")
12+
disabled: Optional[bool] = Field(None, description="If true, the input is disabled")
13+
color: str = Field('primary', pre=True, description="Color of the switch. Can be custom or standard Material color")
14+
label: Optional[str] = Field(None,description= 'A label for your switch')
15+
multiple: Optional[bool] = Field(None, description="Determines if multiple selections are allowed")
16+
width: Union[int,str] = Field('100%', description="Width of the switch")
17+
triggerEvent: str = Field('update:modelValue',description="Trigger event for when to trigger a run")
18+
readonly: Optional[bool] = Field(None, description="Determines if the Switch is read-only")
19+
20+
@field_validator('color')
21+
def validate_color(cls, color):
22+
return validate_color(color)
23+
24+
@validator('value', always=True) #TODO: debug and replace with field validator
25+
def get_value_from_global_state(cls, value, values):
26+
id = values['id'] # Get the id if it exists in the field values
27+
execution_state = UserContext.get_state()
28+
try:
29+
if execution_state and id and id in execution_state.component_values: # Check if id exists in global_state
30+
return execution_state.component_values[id] # Return the value associated with id in global_state
31+
except Exception as e:
32+
e
33+
return value # If id doesn't exist in global_state, return the original value
34+

zt_backend/models/generate_schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .components.timer import Timer
2121
from .components.iframe import iFrame
2222
from .components.html import HTML
23+
from .components.switch import Switch
2324
import json
2425

2526
def generate_json(model, name):
@@ -62,4 +63,6 @@ def generate_schema():
6263
generate_json(Text,'text')
6364
generate_json(Timer,'timer')
6465
generate_json(iFrame,'iframe')
65-
generate_json(HTML,'html')
66+
generate_json(HTML,'html')
67+
generate_json(Switch,'switch')
68+

0 commit comments

Comments
 (0)