PageSwitcher.razor 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 
  2. <div class="page-switcher-container">
  3. @for (int i = 0; i < Pages.Length; i++)
  4. {
  5. var pageIndex = i;
  6. <button class="page-button @(CurrentPage == pageIndex ? "active" : "")"
  7. @onclick="() => OnPageChanged(pageIndex)">
  8. @Pages[pageIndex]
  9. </button>
  10. }
  11. </div>
  12. @code
  13. {
  14. [Parameter]
  15. public string[] Pages { get; set; } = { "1", "2", "3" };
  16. [Parameter]
  17. public int CurrentPage { get; set; } = 0;
  18. [Parameter]
  19. public EventCallback<int> PageChanged { get; set; }
  20. private async Task OnPageChanged(int pageIndex)
  21. {
  22. if (pageIndex != CurrentPage)
  23. {
  24. CurrentPage = pageIndex;
  25. await PageChanged.InvokeAsync(pageIndex);
  26. }
  27. }
  28. }
  29. <style>
  30. .page-switcher-container {
  31. display: flex;
  32. gap: 20px;
  33. align-items: center;
  34. justify-content: right;
  35. }
  36. .page-button {
  37. /* padding: 12px 24px; */
  38. border: none;
  39. border-radius: 8px;
  40. font-weight: 400;
  41. font-size: 12px;
  42. width: 60px;
  43. height: 40px;
  44. cursor: pointer;
  45. transition: all 0.3s ease;
  46. background-color: #f1f5f9;
  47. color: #64748b;
  48. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  49. }
  50. .page-button:hover {
  51. background-color: #e2e8f0;
  52. transform: translateY(-2px);
  53. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  54. }
  55. .page-button.active {
  56. background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  57. color: white;
  58. box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  59. }
  60. .page-button:focus {
  61. outline: none;
  62. box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
  63. }
  64. .page-button:active {
  65. transform: translateY(0);
  66. }
  67. </style>