""" WARNING: this is a highly experimental/unsupported/private module for JSX/React components. Although JSXTag currently allows for HTML tags on attributes and children, that's an issue for HTML() and """ def create_tag( *args: TagNode, **kwargs: TagAttrValue, ) -> JSXTag: return JSXTag(name, *args, allowedProps=allowedProps, **kwargs) create_tag.__name__ = name return create_tag # -------------------------------------------------------- # jsx expressions # -------------------------------------------------------- class jsx(str): """ Mark a string as a JSX expression. Example ------- >>> Foo = JSXTag("Foo") >>> Foo(prop = "A string", jsxProp = jsx("() => console.log('here')")) """ def __new__(cls, *args: str) -> "jsx": return super().__new__( # pyright: ignore[reportGeneralTypeIssues] cls, "\n".join(args) ) # jsx() + jsx() should return jsx() def __add__(self, other: "str | jsx") -> str: res = str.__add__(self, other) return jsx(res) if isinstance(other, jsx) else res def _lib_dependency(pkg: str, script: ScriptItem) -> HTMLDependency: return HTMLDependency( name=pkg, version=versions[pkg], source={"package": "htmltools", "subdir": "lib/" + pkg}, script=script, )