star.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from nicegui import ui
  2. from nicegui.element import Element
  3. from website import svg
  4. STYLE = '''
  5. <style>
  6. @keyframes star-tumble {
  7. 0% { transform: translateX(2em) rotate(144deg); }
  8. 100% { transform: translateX(0) rotate(0); }
  9. }
  10. @keyframes star-pulse {
  11. 0% { scale: 1.0; }
  12. 60% { scale: 1.0; }
  13. 70% { scale: 1.2; }
  14. 80% { scale: 1.0; }
  15. 90% { scale: 1.2; }
  16. 100% { scale: 1.0; }
  17. }
  18. .star {
  19. height: 1.75em;
  20. fill: white;
  21. animation: 1s ease-in-out 6s both star-tumble,
  22. 3s ease-in-out 3s infinite star-pulse;
  23. }
  24. .star:hover {
  25. fill: rgb(250 204 21);
  26. }
  27. @keyframes star-grow {
  28. 0% { width: 0 }
  29. 100% { width: 2em }
  30. }
  31. .star-container {
  32. animation: 1s ease-in-out 6s both star-grow;
  33. }
  34. </style>
  35. '''
  36. STAR = '''
  37. <svg viewBox="0 0 16 16">
  38. <path d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path>
  39. </svg>
  40. '''
  41. def add_star() -> None:
  42. ui.add_head_html(STYLE)
  43. with ui.link(target='https://github.com/zauberzeug/nicegui/').classes('star-container'):
  44. with Element('svg').props('viewBox="0 0 24 24"').classes('star'):
  45. Element('path').props('d="M23.555,8.729a1.505,1.505,0,0,0-1.406-.98H16.062a.5.5,0,0,1-.472-.334L13.405,1.222a1.5,1.5,0,0,0-2.81,0l-.005.016L8.41,7.415a.5.5,0,0,1-.471.334H1.85A1.5,1.5,0,0,0,.887,10.4l5.184,4.3a.5.5,0,0,1,.155.543L4.048,21.774a1.5,1.5,0,0,0,2.31,1.684l5.346-3.92a.5.5,0,0,1,.591,0l5.344,3.919a1.5,1.5,0,0,0,2.312-1.683l-2.178-6.535a.5.5,0,0,1,.155-.543l5.194-4.306A1.5,1.5,0,0,0,23.555,8.729Z"')
  46. with ui.tooltip('').classes('bg-[#486991] w-96 p-4'):
  47. with ui.row().classes('items-center no-wrap'):
  48. svg.face().classes('w-14 stroke-white stroke-[1pt]')
  49. with ui.column().classes('p-2 gap-2'):
  50. ui.label('Star us on GitHub!').classes('text-[180%]')
  51. ui.label('And tell others about NiceGUI.').classes('text-[140%]')