step.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import styled from '@emotion/styled';
  2. import {IconChevron} from 'app/icons';
  3. import space from 'app/styles/space';
  4. type Props = {
  5. children: React.ReactNode;
  6. label: string;
  7. activeStep: number;
  8. isActive: boolean;
  9. height?: number;
  10. };
  11. function Step({children, label, activeStep, isActive, height}: Props) {
  12. return (
  13. <Wrapper activeStep={activeStep} isActive={isActive} height={height}>
  14. <Connector>
  15. <IconChevron direction="right" size="sm" isCircled />
  16. </Connector>
  17. <Content>
  18. {label}
  19. {children && <div>{children}</div>}
  20. </Content>
  21. </Wrapper>
  22. );
  23. }
  24. export default Step;
  25. const Connector = styled('div')`
  26. padding: ${space(0.5)} ${space(1.5)} 0 ${space(1.5)};
  27. `;
  28. const getHeightStyle = (isActive: boolean, height?: number) => {
  29. if (!height) {
  30. return '';
  31. }
  32. if (isActive) {
  33. return `
  34. height: ${height}px;
  35. `;
  36. }
  37. return `
  38. height: 26px;
  39. :not(:last-child) {
  40. height: 42px;
  41. }
  42. `;
  43. };
  44. const Wrapper = styled('div')<{activeStep: number; isActive: boolean; height?: number}>`
  45. display: grid;
  46. grid-template-columns: max-content 1fr;
  47. position: relative;
  48. color: ${p => p.theme.gray200};
  49. margin-left: -${space(1.5)};
  50. :not(:last-child) {
  51. padding-bottom: ${space(2)};
  52. ${Connector} {
  53. :before {
  54. content: ' ';
  55. border-right: 1px ${p => p.theme.gray300} dashed;
  56. position: absolute;
  57. top: 28px;
  58. left: ${space(3)};
  59. height: calc(100% - 28px);
  60. }
  61. }
  62. :nth-child(-n + ${p => p.activeStep + 1}) {
  63. ${Connector} {
  64. :before {
  65. border-color: ${p => p.theme.gray500};
  66. }
  67. }
  68. }
  69. }
  70. :nth-child(-n + ${p => p.activeStep + 1}) {
  71. color: ${p => p.theme.gray500};
  72. }
  73. transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  74. ${p => getHeightStyle(p.isActive, p.height)}
  75. `;
  76. const Content = styled('div')`
  77. display: grid;
  78. grid-gap: ${space(1.5)};
  79. `;