javascript - 如何使用弹出框描述显示数字而不是点

标签 javascript reactjs antd

我正在 antd 中显示数据步骤(点样式)并将鼠标悬停在点上,我使用 React 在 Popover 中显示数据。代码工作正常。当我添加更多步骤时,它看起来很笨拙。这是工作代码,请给我关于如何显示数字代替点的建议。将鼠标悬停在数字上(代替点),然后我们在 Popover 中显示数据。

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      steps: [
        { name: "START", dateTime: "Aug 05, 2019 12:30 PM" },
        {
          name: "RTC complex (PICKUP)",
          dateTime: "12:40 PM - 12:50 PM min(s)"
        },
        {
          name: "Kailasagiri Rope Way (DROP)",
          dateTime: "02:04 PM - 02:50 PM   46min(s)"
        },
        { name: "END", dateTime: "Aug 04, 2019 5:30 PM" }
      ]
    };
  }
  render() {
    const customDot = (dot, props) => {
      const { description, title, index } = props;

      if (description) {
        return (
          <Popover
            content={
              <div style={{ width: "140px", textAlign: "center" }}>
                <p> {title} </p>
                <p> {description} </p>
              </div>
            }
          >
            {dot}
          </Popover>
        );
      }
      return dot;
    };

    return (
      <div className="App">
        <Row gutter={16}>
          <Col xs={24}>
            <Steps
              progressDot={(dot, properties) => customDot(dot, properties)}
              current={0}
            >
              {this.state.steps.map((step, index) => (
                <Steps.Step
                  key={index}
                  title={step.name}
                  description={step.dateTime}
                />
              ))}
            </Steps>
          </Col>
        </Row>
      </div>
    );
  }
}

这是我的工作代码沙箱示例的链接 https://codesandbox.io/s/react-steps-f3b0t

最佳答案

调整Popoverplacement属性时,需要使用Steps.Stepicon属性。

那是因为您尝试使用 Popover 进行“自定义”步骤。

class App extends Component {
  state = {
    steps: [...]
  };

  render() {
    return (
      <>
        <Steps style={{ margin: 40 }}>
          {this.state.steps.map((step, index) => (
            <Steps.Step
              key={index}
              title={step.name}
              description={step.dateTime}
              icon={
                <Popover
                  // Choose your placement depending on steps location
                  placement="bottom"
                  content={
                    <div>
                      {step.name}
                      <br />
                      {step.dateTime}
                    </div>
                  }
                >
                  // Change icon to numbers
                  <Button shape="circle" type={index ? 'default' : 'primary'}>
                    {index + 1}
                  </Button>
                </Popover>
              }
            />
          ))}
        </Steps>
      </>
    );
  }
}

Edit Q-57393663-StepsHoverNumbered

关于javascript - 如何使用弹出框描述显示数字而不是点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57393663/

相关文章:

javascript - 为什么 Error 的堆栈属性不包含在 Object.keys 中?

javascript - 在 sapui5 中从主视图拖放到详细 View

javascript - React ANTD DatePicker HTMLCollection 在提取元素/值时不显示实时值

javascript - 在antd 4中将初始值设置为动态形式

forms - (Vue) Ant Design 使用 v-decorator 以 Ant 的形式显示客户端和服务器端验证

javascript - CSS 模糊和溢出 :hidden

javascript - 从 REST 调用中返回 Promise

reactjs - 在 'Switch' 中找不到 react 错误 'Switch'(导入为 'react-router-dom')

reactjs - 如何在 react 中将数组从子组件传递到父组件我知道如何从父组件传递

javascript - 将 ref 与 React.createElement 一起使用