fhdaisy.core

Builder API used behind the scenes to create the basic components
from fastcore.test import *

The basics


source

mk_previewer


def mk_previewer(
    app:NoneType=None, cls:str='max-w-lg'
):
p = mk_previewer()
c = Button('Hey there', cls='btn')
p(c)
print(c)
<button class="btn">Hey there</button>

Creating simple components


source

hyphens2camel


def hyphens2camel(
    x
):

Tailwind utility classes can start with - (like -mt-5 or -right-5). We need to distinguish these from our shorthand where we prepend the class name to user provided values that start with - (e.g. Tooltip('-left') becomes tooltip-left)

for o in ('-mt-5', '-right-5'): test_eq(_is_neg_twu(o), True)
for o in ('-right', 'mt-5', 'right-5'): test_eq(_is_neg_twu(o), False)

source

mk_compfn


def mk_compfn(
    compcls, tag:NoneType=None, name:NoneType=None, xcls:str='', compkw:VAR_KEYWORD
):
mk_compfn('btn', 'Button')
c = Btn('Hey there', cls='-primary p-5 text-2xl rounded-full')
print(c)
<button class="btn btn-primary p-5 text-2xl rounded-full ">Hey there</button>
p(c)

Demonstrating that negative utility classes are handled correctly:

mk_compfn('tooltip', 'Div')
c = Tooltip('Main text is offset to the right', cls='-right-50 -primary -left', data_tip='Tooltip appears to the left')
print(c)
<div data-tip="Tooltip appears to the left" class="tooltip -right-50 tooltip-primary tooltip-left ">Main text is offset to the right</div>
p(c)