contextLine.tsx 857 B

12345678910111213141516171819202122232425262728293031323334
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import classNames from 'classnames';
  4. interface Props {
  5. isActive: boolean;
  6. line: [number, string];
  7. children?: React.ReactNode;
  8. className?: string;
  9. }
  10. const ContextLine = function ({line, isActive, children, className}: Props) {
  11. let lineWs = '';
  12. let lineCode = '';
  13. if (typeof line[1] === 'string') {
  14. [, lineWs, lineCode] = line[1].match(/^(\s*)(.*?)$/m)!;
  15. }
  16. const Component = !children ? Fragment : Context;
  17. return (
  18. <li className={classNames(className, 'expandable', {active: isActive})} key={line[0]}>
  19. <Component>
  20. <span className="ws">{lineWs}</span>
  21. <span className="contextline">{lineCode}</span>
  22. </Component>
  23. {children}
  24. </li>
  25. );
  26. };
  27. export default ContextLine;
  28. const Context = styled('div')`
  29. display: inline;
  30. `;