反应。拥有所有扩展组件包括基类的className

时间:2017-08-28 08:56:03

标签: javascript css reactjs

说,我有类MySpecialPanel,它扩展了类Panel。 我想要一个css className" panel"默认情况下附加到MySpecialPanel根的className prop,而不必在每个扩展类中显式写入它。 如何将其作为基类功能的一部分?

1 个答案:

答案 0 :(得分:0)

为什么要使用继承?组合模式远比你描述的更好。

将MySpecialPanel类包含在Panel类中,并将渲染更改为以下内容:

/* I used PHP becase i need more functions, this only a example how
 * to creat and call a modal after click on a link.
*/
function create_modal($modal_ID = 'myModal')
{
    return "<div class='modal fade' id='$modal_ID' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
                <div class='modal-dialog'>
                  <div class='modal-content'>
                    <div class='modal-header'>
                      <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>
                      <h4 class='modal-title' id='myModalLabel'>Nhãn</h4>
                    </div>
                    <div class='modal-body'>
                      Nội dung
                    </div>
                    <div class='modal-footer'>
                      <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
                      <button type='button' class='btn btn-primary'>Save changes</button>
                    </div>
                  </div>
                </div>
              </div>";
}
echo create_modal();
?>