Understanding FastHTML xtend
```python
from fasthtml.common import *
```
```python
Card
```
What interesting things can we find out about the Card function?
```python
help(Card)
```
```python
dir(Card)
```
```python
import inspect
print(inspect.getsource(Card))
```
@delegates(xt_hx, keep=True) means it can accept and pass along any arguments that the xt_hx function accepts.
It's defined in https://github.com/fastai/fastcore/blob/005ffd986df737cfc46c7cb1eadec5d214d08da7/fastcore/meta.py#L109
Not sure what xt_hx is, probably a function that does something with the XML tree and HTMX attributes.
I'll run 02_xtend.ipynb to try and learn more.
```python
from functools import partial
from fasthtml.components import ft_hx
my_a = partial(ft_hx, "A")
my_a
```
```python
my_a()
```
```python
my_a('Hi')
```
```python
my_a("Hi", cls='linky')
```
```python
my_b = partial(ft_hx, "B")
my_b("Hello")
```
```python
C = partial(ft_hx, "C")
C("Hee hee")
```
```python
Uma = partial(ft_hx, "Uma")
Uma("Hi mommy", cls='cute', mood='happy', id="UmaTheKid")
```
```python
Mommy = partial(ft_hx, "Mommy")
Mommy("Hi Uma", cls='mom', hx_trigger="mouseenter", hx_get="/inbox")
```
```python
Daddy = partial(ft_hx, "Daddy")
Daddy("Hi fam", cls="dad", hx_target="#UmaTheKid")
```
```python
from fastcore.meta import delegates
```
```python
@delegates(ft_hx, keep=True)
def Mom(*c, title, description, **kwargs) -> FT:
print(f"Type of c: {type(c)}")
if title: c = H1(title, 1) + list(c)
if description: c += P(description)
return Mommy(*c, **kwargs)
```
```python
Mom("Hi Uma", title="Mother", description="Director of Motherhood", cls="ma", hx_trigger="mouseenter", hx_get="/inbox")
```
```python
type(H1("Hi"))
```
```python
@delegates(ft_hx, keep=True)
def Card(*c, header=None, footer=None, **kwargs) -> FT:
"A PicoCSS Card, implemented as an Article with optional Header and Footer"
if header:
c = (Header(header),) + c
if footer:
c += (Footer(footer),)
return Article(*c, **kwargs)
```
```python
Card("Hi Uma", header="Mother", footer="Director of Motherhood", cls="ma", hx_trigger="mouseenter", hx_get="/inbox")
```