|
| 1 | +import reflex as rx |
| 2 | + |
| 3 | +loading_style = { |
| 4 | + "rect": { |
| 5 | + "opacity": "0", |
| 6 | + "animation": "fadeInStayOut 6s linear infinite", |
| 7 | + }, |
| 8 | + "@keyframes fadeInStayOut": { |
| 9 | + "0%": {"opacity": "0"}, |
| 10 | + "5%": {"opacity": "1"}, |
| 11 | + "50%": {"opacity": "1"}, |
| 12 | + "55%": {"opacity": "0"}, |
| 13 | + "100%": {"opacity": "0"}, |
| 14 | + }, |
| 15 | +} |
| 16 | + |
| 17 | +for i in range(1, 14): |
| 18 | + loading_style[f"rect:nth-child({i})"] = {"animation_delay": f"{(i - 1) * 0.2}s"} |
| 19 | + |
| 20 | + |
| 21 | +def svg_loading(): |
| 22 | + return rx.box( |
| 23 | + rx.html( |
| 24 | + """<svg width="88" height="88" viewBox="0 0 88 88" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 25 | + <rect x="32" y="41" width="6" height="6" fill="#6E56CF"/> |
| 26 | + <rect x="38" y="29" width="6" height="6" fill="#6E56CF"/> |
| 27 | + <rect x="50" y="47" width="6" height="6" fill="#6E56CF"/> |
| 28 | + <rect x="32" y="53" width="6" height="6" fill="#6E56CF"/> |
| 29 | + <rect x="44" y="41" width="6" height="6" fill="#6E56CF"/> |
| 30 | + <rect x="50" y="35" width="6" height="6" fill="#6E56CF"/> |
| 31 | + <rect x="50" y="53" width="6" height="6" fill="#6E56CF"/> |
| 32 | + <rect x="44" y="29" width="6" height="6" fill="#6E56CF"/> |
| 33 | + <rect x="32" y="29" width="6" height="6" fill="#6E56CF"/> |
| 34 | + <rect x="32" y="47" width="6" height="6" fill="#6E56CF"/> |
| 35 | + <rect x="50" y="29" width="6" height="6" fill="#6E56CF"/> |
| 36 | + <rect x="38" y="41" width="6" height="6" fill="#6E56CF"/> |
| 37 | + <rect x="32" y="35" width="6" height="6" fill="#6E56CF"/> |
| 38 | + </svg>""" |
| 39 | + ), |
| 40 | + style=loading_style, |
| 41 | + position="absolute", |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +spinner_style = { |
| 46 | + "g rect": { |
| 47 | + "transform-origin": "0 0", |
| 48 | + }, |
| 49 | + "g rect:nth-of-type(1)": { |
| 50 | + "animation": "growShrinkWidth 3s linear infinite", |
| 51 | + "width": "0", |
| 52 | + }, |
| 53 | + "g rect:nth-of-type(2)": { |
| 54 | + "animation": "growShrinkHeight 3s linear infinite 0.35s", |
| 55 | + "height": "0", |
| 56 | + }, |
| 57 | + "g rect:nth-of-type(3)": { |
| 58 | + "animation": "growShrinkWidthReverse 3s linear infinite 0.7s", |
| 59 | + "width": "0", |
| 60 | + }, |
| 61 | + "g rect:nth-of-type(4)": { |
| 62 | + "animation": "growShrinkHeightReverse 3s linear infinite 1.05s", |
| 63 | + "height": "0", |
| 64 | + }, |
| 65 | + "@keyframes growShrinkWidth": { |
| 66 | + "0%": {"width": "0", "transform": "translateX(0)"}, |
| 67 | + "12.5%": {"width": "40px", "transform": "translateX(0)"}, |
| 68 | + "37.5%": {"width": "40px", "transform": "translateX(0)"}, |
| 69 | + "50%": {"width": "40px", "transform": "translateX(0)"}, |
| 70 | + "62.5%": {"width": "0", "transform": "translateX(40px)"}, |
| 71 | + "100%": {"width": "0", "transform": "translateX(40px)"}, |
| 72 | + }, |
| 73 | + "@keyframes growShrinkHeight": { |
| 74 | + "0%": {"height": "0", "transform": "translateY(0)"}, |
| 75 | + "12.5%": {"height": "40px", "transform": "translateY(0)"}, |
| 76 | + "37.5%": {"height": "40px", "transform": "translateY(0)"}, |
| 77 | + "50%": {"height": "40px", "transform": "translateY(0)"}, |
| 78 | + "62.5%": {"height": "0", "transform": "translateY(40px)"}, |
| 79 | + "100%": {"height": "0", "transform": "translateY(40px)"}, |
| 80 | + }, |
| 81 | + "@keyframes growShrinkWidthReverse": { |
| 82 | + "0%": {"width": "0", "transform": "translateX(41px)"}, |
| 83 | + "12.5%": {"width": "41px", "transform": "translateX(0)"}, |
| 84 | + "37.5%": {"width": "41px", "transform": "translateX(0)"}, |
| 85 | + "50%": {"width": "41px", "transform": "translateX(0)"}, |
| 86 | + "62.5%": {"width": "0", "transform": "translateX(0)"}, |
| 87 | + "100%": {"width": "0", "transform": "translateX(0)"}, |
| 88 | + }, |
| 89 | + "@keyframes growShrinkHeightReverse": { |
| 90 | + "0%": {"height": "0", "transform": "translateY(40px)"}, |
| 91 | + "12.5%": {"height": "40px", "transform": "translateY(0)"}, |
| 92 | + "37.5%": {"height": "40px", "transform": "translateY(0)"}, |
| 93 | + "50%": {"height": "40px", "transform": "translateY(0)"}, |
| 94 | + "62.5%": {"height": "0", "transform": "translateY(0)"}, |
| 95 | + "100%": {"height": "0", "transform": "translateY(0)"}, |
| 96 | + }, |
| 97 | +} |
| 98 | + |
| 99 | + |
| 100 | +def spinner_svg(mask_name: str): |
| 101 | + return rx.box( |
| 102 | + rx.html( |
| 103 | + f"""<svg width="88" height="88" viewBox="0 0 88 88" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 104 | + <mask id="{mask_name}" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="20" y="20" width="48" height="48"> |
| 105 | + <rect x="21" y="21" width="46" height="46" rx="7" stroke="black" stroke-width="2"/> |
| 106 | + </mask> |
| 107 | + <g mask="url(#{mask_name})"> |
| 108 | + <rect x="20" y="20" width="0" height="8" fill="#6E56CF"/> |
| 109 | + <rect x="60" y="20" width="8" height="0" fill="#6E56CF"/> |
| 110 | + <rect x="27" y="60" width="0" height="8" fill="#6E56CF"/> |
| 111 | + <rect x="20" y="28" width="8" height="0" fill="#6E56CF"/> |
| 112 | + </g> |
| 113 | + </svg>""" |
| 114 | + ), |
| 115 | + style=spinner_style, |
| 116 | + ) |
| 117 | + |
| 118 | + |
| 119 | +def r_svg_loader(): |
| 120 | + return rx.fragment( |
| 121 | + spinner_svg(mask_name="mask"), |
| 122 | + svg_loading(), |
| 123 | + ) |
0 commit comments