style.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from pathlib import Path
  2. from typing import List
  3. from nicegui import ui
  4. def link_target(name: str, offset: str = '0') -> ui.link_target:
  5. target = ui.link_target(name).style(f'position: absolute; top: {offset}; left: 0')
  6. target.parent_slot.parent.classes('relative')
  7. return target
  8. def section_heading(subtitle: str, title: str) -> None:
  9. ui.label(subtitle).classes('md:text-lg font-bold')
  10. ui.markdown(title).classes('text-3xl md:text-5xl font-medium mt-[-12px]')
  11. def heading(title: str) -> ui.label:
  12. return ui.markdown(title).classes('text-2xl md:text-3xl xl:text-4xl font-medium text-white')
  13. def title(content: str) -> ui.markdown:
  14. return ui.markdown(content).classes('text-4xl sm:text-5xl md:text-6xl font-medium')
  15. def subtitle(content: str) -> ui.markdown:
  16. return ui.markdown(content).classes('text-xl sm:text-2xl md:text-3xl leading-7')
  17. def example_link(title: str, description: str) -> None:
  18. name = title.lower().replace(' ', '_')
  19. directory = Path(__file__).parent.parent / 'examples' / name
  20. content = [p for p in directory.glob('*') if p.name != '__pycache__' and not p.name.startswith('.')]
  21. filename = 'main.py' if len(content) == 1 else ''
  22. with ui.link(target=f'https://github.com/zauberzeug/nicegui/tree/main/examples/{name}/{filename}') \
  23. .classes('bg-[#5898d420] p-4 self-stretch rounded flex flex-col gap-2') \
  24. .style('box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1)'):
  25. ui.label(title).classes(replace='text-black font-bold')
  26. ui.markdown(description).classes(replace='text-black bold-links arrow-links')
  27. def features(icon: str, title: str, items: List[str]) -> None:
  28. with ui.column().classes('gap-1'):
  29. ui.icon(icon).classes('max-sm:hidden text-3xl md:text-5xl mb-3 text-primary opacity-80')
  30. ui.label(title).classes('font-bold mb-3')
  31. for item in items:
  32. ui.markdown(f'- {item}').classes('bold-links arrow-links')
  33. def side_menu() -> ui.left_drawer:
  34. return ui.left_drawer() \
  35. .classes('column no-wrap gap-1 bg-[#eee] mt-[-20px] px-8 py-20') \
  36. .style('height: calc(100% + 20px) !important')