MCPcopy
hub / github.com/reflex-dev/reflex / Style

Class Style

packages/reflex-base/src/reflex_base/style.py:244–318  ·  view source on GitHub ↗

A style dictionary.

Source from the content-addressed store, hash-verified

242
243
244class Style(dict[str, Any]):
245 """A style dictionary."""
246
247 def __init__(self, style_dict: dict[str, Any] | None = None, **kwargs):
248 """Initialize the style.
249
250 Args:
251 style_dict: The style dictionary.
252 kwargs: Other key value pairs to apply to the dict update.
253 """
254 if style_dict:
255 style_dict.update(kwargs)
256 else:
257 style_dict = kwargs
258 if style_dict:
259 style_dict, self._var_data = convert(style_dict)
260 else:
261 self._var_data = EMPTY_VAR_DATA
262 super().__init__(style_dict)
263
264 def update(self, style_dict: dict | None, **kwargs):
265 """Update the style.
266
267 Args:
268 style_dict: The style dictionary.
269 kwargs: Other key value pairs to apply to the dict update.
270 """
271 if not isinstance(style_dict, Style):
272 converted_dict = type(self)(style_dict)
273 else:
274 converted_dict = style_dict
275 if kwargs:
276 if converted_dict is None:
277 converted_dict = type(self)(kwargs)
278 else:
279 converted_dict.update(kwargs)
280 # Combine our VarData with that of any Vars in the style_dict that was passed.
281 self._var_data = VarData.merge(self._var_data, converted_dict._var_data)
282 super().update(converted_dict)
283
284 def __setitem__(self, key: str, value: Any):
285 """Set an item in the style.
286
287 Args:
288 key: The key to set.
289 value: The value to set.
290 """
291 # Create a Var to collapse VarData encoded in f-string.
292 var = LiteralVar.create(value)
293 if var is not None:
294 # Carry the imports/hooks when setting a Var as a value.
295 self._var_data = VarData.merge(
296 getattr(self, "_var_data", None), var._get_all_var_data()
297 )
298 super().__setitem__(key, value)
299
300 def __or__(self, other: Style | dict) -> Style:
301 """Combine two styles.

Callers 15

add_styleMethod · 0.90
add_styleMethod · 0.90
add_styleMethod · 0.90
createMethod · 0.90
_post_initMethod · 0.90
_add_styleMethod · 0.90
_get_component_styleMethod · 0.90
_color_selectorMethod · 0.90
add_styleMethod · 0.90
add_styleMethod · 0.90
createMethod · 0.90
ShikiJsTransformerClass · 0.90

Calls

no outgoing calls

Tested by 9

test_default_appFunction · 0.72
test_add_styleFunction · 0.72
test_add_style_createFunction · 0.72
add_styleMethod · 0.72
add_styleMethod · 0.72
test_add_style_foreachFunction · 0.72