You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

status-bar.tsx 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { useStateDesigner } from "@state-designer/react"
  2. import state from "state"
  3. import styled from "styles"
  4. import { useRef } from "react"
  5. export default function StatusBar() {
  6. const local = useStateDesigner(state)
  7. const { count, time } = useRenderCount()
  8. const active = local.active.slice(1).map((s) => s.split("root.")[1])
  9. const log = local.log[0]
  10. return (
  11. <StatusBarContainer>
  12. <States>{active.join(" | ")}</States>
  13. <Section>| {log}</Section>
  14. <Section title="Renders | Time">
  15. {count} | {time.toString().padStart(3, "0")}
  16. </Section>
  17. </StatusBarContainer>
  18. )
  19. }
  20. const StatusBarContainer = styled("div", {
  21. position: "absolute",
  22. bottom: 0,
  23. left: 0,
  24. width: "100%",
  25. height: 40,
  26. userSelect: "none",
  27. borderTop: "1px solid black",
  28. gridArea: "status",
  29. display: "grid",
  30. gridTemplateColumns: "auto 1fr auto",
  31. alignItems: "center",
  32. backgroundColor: "white",
  33. gap: 8,
  34. fontSize: "$1",
  35. padding: "0 16px",
  36. zIndex: 200,
  37. })
  38. const Section = styled("div", {
  39. whiteSpace: "nowrap",
  40. overflow: "hidden",
  41. })
  42. const States = styled("div", {})
  43. function useRenderCount() {
  44. const rTime = useRef(Date.now())
  45. const rCounter = useRef(0)
  46. rCounter.current++
  47. const now = Date.now()
  48. let time = now - rTime.current
  49. if (time > 100) {
  50. time = 0
  51. }
  52. rTime.current = now
  53. return { count: rCounter.current, time }
  54. }