TwoColumnLayout

1.基本介绍

左右两侧布局

2.组件示例

1.普通样式

<TwoColumnLayout title="左侧内容:">
  <p>右侧内容</p>
</TwoColumnLayout>

在这里插入图片描述
2.居中样式

<TwoColumnLayout title="左侧内容:">
  <p>右侧内容</p>
</TwoColumnLayout>

在这里插入图片描述
3.左侧单独设置样式

<TwoColumnLayout leftStyle={{ fontWeight: 'bold', color: 'red' }} title="左侧内容:">
  <p>右侧内容</p>
</TwoColumnLayout>

在这里插入图片描述

3.属性

属性名属性类型默认值说明
childrenReactNodenull
titlestring 或 ReactNode“twoColumnLayout”可接受ReactNode
bodyHeightstring“100px”整体容器高度
centerbooleanfalse左侧和右侧同时垂直居中
leftStyleCSSProperties{}左侧展示样式

4.代码

1.ts

import React, { useEffect, ReactNode, useState, CSSProperties } from 'react';
import style from './index.less';

interface ITwoColumnLayoutProps {
  children?: ReactNode;
  title?: string | ReactNode;
  bodyHeight?: string;
  center?: boolean;
  leftStyle?: CSSProperties;
}

const TwoColumnLayout = (props: ITwoColumnLayoutProps) => {
  const { children, title, bodyHeight, center, leftStyle } = props;

  const [flexCenter, setFlexCenter] = useState('flex-start');

  useEffect(() => {
    if (center) {
      setFlexCenter('center');
    }
  }, []);

  return (
    <div style={{ height: bodyHeight, alignItems: flexCenter }} className={style.container}>
      <div style={leftStyle} className={style.left}>{title}</div>
      <div style={{ alignItems: flexCenter }} className={style.right}>{children}</div>
    </div>
  )
}

export default TwoColumnLayout;

TwoColumnLayout.defaultProps = {
  children: null,
  title: 'twoColumnLayout',
  bodyHeight: '100px',
  center: false,
  leftStyle: {},
};

2.less

.container {
  width: 100%;
  height: 100px;
  background-color: #f1f1f1;
  padding: 10px;
  display: flex;

  .left {
    width: 100px;
    text-align: center;
    overflow: hidden;
  }

  .right {
    display: flex;
    width: 100%;
    height: inherit;
    overflow: hidden;
  }
}
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值