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

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