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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. size={{
  13. '@sm': 'small',
  14. }}
  15. >
  16. <Section>{active.join(' | ')}</Section>
  17. <Section>| {log}</Section>
  18. {/* <Section
  19. title="Renders | Time"
  20. >
  21. {count} | {time.toString().padStart(3, '0')}
  22. </Section> */}
  23. </StatusBarContainer>
  24. )
  25. }
  26. const StatusBarContainer = styled('div', {
  27. position: 'absolute',
  28. bottom: 0,
  29. left: 0,
  30. width: '100%',
  31. zIndex: 300,
  32. height: 40,
  33. userSelect: 'none',
  34. borderTop: '1px solid black',
  35. gridArea: 'status',
  36. display: 'grid',
  37. gridTemplateColumns: 'auto 1fr auto',
  38. alignItems: 'center',
  39. backgroundColor: 'white',
  40. gap: 8,
  41. fontSize: '$0',
  42. padding: '0 16px',
  43. variants: {
  44. size: {
  45. small: {
  46. fontSize: '$1',
  47. },
  48. },
  49. },
  50. })
  51. const Section = styled('div', {
  52. whiteSpace: 'nowrap',
  53. overflow: 'hidden',
  54. })
  55. function useRenderCount() {
  56. const rTime = useRef(Date.now())
  57. const rCounter = useRef(0)
  58. rCounter.current++
  59. const now = Date.now()
  60. let time = now - rTime.current
  61. if (time > 100) {
  62. time = 0
  63. }
  64. rTime.current = now
  65. return { count: rCounter.current, time }
  66. }