src.py.jinja2 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Reflex custom component {{ component_class_name }}."""
  2. # For wrapping react guide, visit https://reflex.dev/docs/wrapping-react/overview/
  3. import reflex as rx
  4. # Some libraries you want to wrap may require dynamic imports.
  5. # This is because they they may not be compatible with Server-Side Rendering (SSR).
  6. # To handle this in Reflex, all you need to do is subclass `NoSSRComponent` instead.
  7. # For example:
  8. # from reflex.components.component import NoSSRComponent
  9. # class {{ component_class_name }}(NoSSRComponent):
  10. # pass
  11. class {{ component_class_name }}(rx.Component):
  12. """{{ component_class_name }} component."""
  13. # The React library to wrap.
  14. library = "Fill-Me"
  15. # The React component tag.
  16. tag = "Fill-Me"
  17. # If the tag is the default export from the module, you must set is_default = True.
  18. # This is normally used when components don't have curly braces around them when importing.
  19. # is_default = True
  20. # If you are wrapping another components with the same tag as a component in your project
  21. # you can use aliases to differentiate between them and avoid naming conflicts.
  22. # alias = "Other{{ component_class_name }}"
  23. # The props of the React component.
  24. # Note: when Reflex compiles the component to Javascript,
  25. # `snake_case` property names are automatically formatted as `camelCase`.
  26. # The prop names may be defined in `camelCase` as well.
  27. # some_prop: rx.Var[str] = "some default value"
  28. # some_other_prop: rx.Var[int] = 1
  29. # By default Reflex will install the library you have specified in the library property.
  30. # However, sometimes you may need to install other libraries to use a component.
  31. # In this case you can use the lib_dependencies property to specify other libraries to install.
  32. # lib_dependencies: list[str] = []
  33. # Event triggers declaration if any.
  34. # Below is equivalent to merging `{ "on_change": lambda e: [e] }`
  35. # onto the default event triggers of parent/base Component.
  36. # The function defined for the `on_change` trigger maps event for the javascript
  37. # trigger to what will be passed to the backend event handler function.
  38. # on_change: rx.EventHandler[lambda e: [e]]
  39. # To add custom code to your component
  40. # def _get_custom_code(self) -> str:
  41. # return "const customCode = 'customCode';"
  42. {{ module_name }} = {{ component_class_name }}.create