【问题标题】:How to hide TagNav in profile page in reactioncommerce如何在 reactcommerce 的个人资料页面中隐藏 TagNav
【发布时间】:2018-07-21 04:48:03
【问题描述】:

在 reactCommerce 中,我想根据某些条件在配置文件组件/页面的导航栏中隐藏 TagNav。我是 reactCommerce 的新手

【问题讨论】:

    标签: reactjs reactive-programming reaction-commerce


    【解决方案1】:

    您需要使用 Reaction Commerce 的组件 API 覆盖 TagNav

    由于您只想自定义组件的呈现方式,我建议使用 getRawComponent 来获取 Reaction 的默认 TagNav 组件而不使用其 HOC,然后扩展它并使用 replaceComponent 替换它。

    import React from "react";
    import { Components, getRawComponent, replaceComponent } from "@reactioncommerce/reaction-components";
    
    const TagNav = getRawComponent("TagNav");
    
    class CustomTagNav extends TagNav {
      /**
       * This implementation of render will override TagNav's default
       */
      render() {
        const { navbarOrientation, navbarPosition, navbarAnchor, navbarVisibility } = this.props;
        
        // Provided that you want to return a whole different component tree if your condition matches
        
        if (yourCondition) {
          return (
            {/* What you want to return if TagNav isn't shown */}
          );
        }
        
        return (
          <div className={`rui tagnav ${navbarOrientation} ${navbarPosition} ${navbarAnchor} ${navbarVisibility}`}>
            <div className="navbar-header">
              <Components.Button
                primary={true}
                icon="times"
                status="default"
                className="close-button"
                onClick={this.props.closeNavbar}
              />
              {this.props.children}
            </div>
            {this.renderShopSelect()}
            <div className="navbar-items">
              <Components.DragDropProvider>
                <Components.TagList
                  {...this.props}
                  isTagNav={true}
                  draggable={true}
                  enableNewTagForm={true}
                >
                  <div className="dropdown-container">
                    <Components.TagGroup
                      {...this.props}
                      editable={this.props.editable === true}
                      tagGroupProps={this.tagGroupProps(this.state.selectedTag || {})}
                      onMove={this.props.onMoveTag}
                      onTagInputBlur={this.handleTagSave}
                      onTagMouseOut={this.handleTagMouseOut}
                      onTagMouseOver={this.handleTagMouseOver}
                      onTagSave={this.handleTagSave}
                    />
                  </div>
                </Components.TagList>
              </Components.DragDropProvider>
              {this.props.canEdit && this.renderEditButton()}
            </div>
          </div>
        );
      }
    }
    
    replaceComponent("TagNav", CustomTagNav);

    【讨论】:

    • Anish,你的问题解决了吗?如果是这种情况,如果您能验证我的回答,我将不胜感激。
    • @anish 这是一个老问题,但如果我帮助您解决了问题,请验证我的回答。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 2015-10-08
    • 1970-01-01
    • 2015-06-02
    相关资源
    最近更新 更多