Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

status-bar.tsx 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. <Section>{active.join(" | ")}</Section>
  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. function useRenderCount() {
  43. const rTime = useRef(Date.now())
  44. const rCounter = useRef(0)
  45. rCounter.current++
  46. const now = Date.now()
  47. let time = now - rTime.current
  48. if (time > 100) {
  49. time = 0
  50. }
  51. rTime.current = now
  52. return { count: rCounter.current, time }
  53. }