style.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from typing import List
  2. from nicegui import ui
  3. def link_target(name: str, offset: str = '0') -> ui.link_target:
  4. target = ui.link_target(name).style(f'position: absolute; top: {offset}; left: 0')
  5. target.parent_slot.parent.classes('relative')
  6. return target
  7. def section_heading(subtitle: str, title: str) -> None:
  8. ui.label(subtitle).classes('md:text-lg font-bold')
  9. ui.markdown(title).classes('text-3xl md:text-5xl font-medium mt-[-12px]')
  10. def heading(title: str) -> ui.label:
  11. return ui.markdown(title).classes('text-2xl md:text-3xl xl:text-4xl font-medium text-white')
  12. def title(content: str) -> ui.markdown:
  13. return ui.markdown(content).classes('text-4xl sm:text-5xl md:text-6xl font-medium')
  14. def subtitle(content: str) -> ui.markdown:
  15. return ui.markdown(content).classes('text-xl sm:text-2xl md:text-3xl leading-7')
  16. def example_link(title: str, description: str) -> None:
  17. name = title.lower().replace(' ', '_')
  18. with ui.link(target=f'https://github.com/zauberzeug/nicegui/tree/main/examples/{name}/main.py') \
  19. .classes('bg-[#5898d420] p-4 self-stretch rounded flex flex-col gap-2') \
  20. .style('box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1)'):
  21. ui.label(title).classes(replace='text-black font-bold')
  22. ui.markdown(description).classes(replace='text-black bold-links arrow-links')
  23. def features(icon: str, title: str, items: List[str]) -> None:
  24. with ui.column().classes('gap-1'):
  25. ui.icon(icon).classes('max-sm:hidden text-3xl md:text-5xl mb-3 text-primary opacity-80')
  26. ui.label(title).classes('font-bold mb-3')
  27. for item in items:
  28. ui.markdown(f'- {item}').classes('bold-links arrow-links')