fhdaisy.xtras

Convenience functions that combine components with their needed parts
p = mk_previewer()

Chat bubbles

p(Chat(
    ChatBubble('Hi, what is 2+2?'),
    cls='-start')
)

source

ChatTurn

def ChatTurn(
    msg, # Text to display
    cls:str='', # Class of the `Chat`
    bubblecls:str='', # Class of the `ChatBubble`
    **kw
):

A ChatBubble in a Chat, representing one turn in a chat

p(
    ChatTurn('Hi, what is 2+2?', cls='-start'),
    ChatTurn('The answer is 4', cls='-end', bubblecls='-primary'),
)

source

ChatPair

def ChatPair(
    q, # Question text
    a, # Answer text
):

A question and answer pair as chat bubbles

c = Div(
    ChatPair('Hi, what is 2+2?', 'The answer is 4'),
    ChatPair('And what about 5*6?', 'That equals 30'),
    Div(cls='mt-4 flex gap-2')(
        Input(placeholder='Type your question...', cls='flex-1'),
        Btn('Send')
    )
)
p(c)

Actions

FAB


source

mk_fab

def mk_fab(
    txt, main, items, maincls:str='-success', btncls:str='-lg -circle', cls:str='', **kw
):

Call self as a function.

c = mk_fab('➕', 'M', ['A', 'B', 'C'], cls='-flower')
p(c, height=200)

Swap


source

mk_swap

def mk_swap(
    on, off, cls:str='', **kw
):

Call self as a function.

c = mk_swap('ON', 'OFF')
print(c)
<label class="swap  "><input type="checkbox"><div class="swap-on  ">ON</div><div class="swap-off  ">OFF</div></label>
p(c)
c = mk_swap('😀', '😪', cls='-rotate text-9xl')
p(c)

Data display

Accordian


source

mk_accordion_item

def mk_accordion_item(
    title, content, name:str='accordion', checked:bool=False, cls:str='', titlecls:str='', contentcls:str='', **kw
):

Call self as a function.

accitems = [
    ('How do I create an account?', 'Click the "Sign Up" button in the top right corner.'),
    ('I forgot my password', 'Click on "Forgot Password" on the login page.'),
    ('How do I update my profile?', 'Go to "My Account" settings and select "Edit Profile".')
]
ais = [
    mk_accordion_item(*o, name='acc1', checked=i==0, cls='-arrow border border-base-300', titlecls='font-semibold')
    for i,o in enumerate(accitems)
]
p( Join(*ais, cls='-vertical min-w-md') )

source

mk_accordion

def mk_accordion(
    *items, name:NoneType=None, cls:str='', itemcls:str='', titlecls:str='', contentcls:str='', itemkw:NoneType=None,
    **kw
):

Call self as a function.

c = mk_accordion(*accitems,
        titlecls='font-semibold', contentcls='text-sm',
        itemcls='-arrow border border-base-300',
        cls='-vertical min-w-md')
p(c)