Skip to content

Commit

Permalink
feat: Tree 新增 Tree 树形组件
Browse files Browse the repository at this point in the history
feat: Checkbox 组件新增 disabled 属性
  • Loading branch information
yinLiangDream committed Jan 8, 2020
1 parent 8f4d00c commit f636128
Show file tree
Hide file tree
Showing 20 changed files with 1,497 additions and 289 deletions.
1 change: 0 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 79 additions & 48 deletions .idea/workspace.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions @types/checkbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export type TCheckboxGroup = {
* 复选框的 value 设置,该参数为选中时的参数
*/
value?: string;
/**
* 禁用
*/
disabled?: boolean;
}[];

export type TOnChange = (value: string[]) => void;
Expand All @@ -41,6 +45,10 @@ export interface IProps extends BaseComponent {
* 可选类型 `normal`, `form`
*/
type?: "normal" | "form";
/**
* tree 使用
*/
more?: boolean;
/**
* 复选框形状设置
*
Expand Down
1 change: 1 addition & 0 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export { default as ClCurtain } from "./curtain";
export { default as ClNoticeBar } from "./noticeBar";
export { default as ClCalendar } from "./calendar";
export { default as ClTextarea } from "./textarea";
export { default as ClTree } from "./tree";

export { default as ClUtils } from "./utils";
46 changes: 46 additions & 0 deletions @types/tree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ComponentClass } from "react";

import {
bgColorType,
bgColorMoreType,
lightBgColorType,
iconType,
BaseComponent
} from "./baseType";

type data = {
name?: string;
checked?: boolean;
disabled?: boolean;
children?: children;
open?: boolean;
}[];

type children = data[];

export interface IProps extends BaseComponent {
/**
* tree 所需数据
*/
data?: data;
/**
* 是否显示 check 框
*/
showCheck?: boolean;
/**
* 选中颜色
*/
color?: bgColorType;
/**
* 选中状态发生改变时触发
*/
onCheckedChange?: ([]) => void;
/**
* 展开或者收缩时发生改变
*/
onOpenChange?: ({ }) => void;
}

declare const Tree: ComponentClass<IProps>;

export default Tree;
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"author": "liangyin",
"license": "MIT",
"dependencies": {
"@tarojs/async-await": "1.3.29",
"@tarojs/async-await": "2.0.0-beta.13",
"area-data": "^5.0.6",
"dayjs": "^1.8.17"
},
Expand All @@ -53,19 +53,20 @@
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/preset-env": "^7.1.0",
"@tarojs/cli": "1.3.29",
"@tarojs/components": "1.3.29",
"@tarojs/plugin-babel": "1.3.29",
"@tarojs/plugin-csso": "1.3.29",
"@tarojs/plugin-sass": "1.3.29",
"@tarojs/plugin-uglifyjs": "1.3.29",
"@tarojs/router": "1.3.29",
"@tarojs/taro": "1.3.29",
"@tarojs/taro-alipay": "1.3.29",
"@tarojs/taro-h5": "1.3.29",
"@tarojs/taro-swan": "1.3.29",
"@tarojs/taro-weapp": "1.3.29",
"@tarojs/webpack-runner": "1.3.29",
"@tarojs/cli": "2.0.0-beta.13",
"@tarojs/components": "2.0.0-beta.13",
"@tarojs/mini-runner": "^2.0.0-beta.13",
"@tarojs/plugin-babel": "2.0.0-beta.13",
"@tarojs/plugin-csso": "2.0.0-beta.13",
"@tarojs/plugin-sass": "2.0.0-beta.13",
"@tarojs/plugin-uglifyjs": "2.0.0-beta.13",
"@tarojs/router": "2.0.0-beta.13",
"@tarojs/taro": "2.0.0-beta.13",
"@tarojs/taro-alipay": "2.0.0-beta.13",
"@tarojs/taro-h5": "2.0.0-beta.13",
"@tarojs/taro-swan": "2.0.0-beta.13",
"@tarojs/taro-weapp": "2.0.0-beta.13",
"@tarojs/webpack-runner": "2.0.0-beta.13",
"@types/react": "^16.8.20",
"@types/sinon": "^5.0.7",
"@types/webpack-env": "^1.13.9",
Expand All @@ -87,12 +88,12 @@
"cross-env": "^5.2.0",
"eslint": "^6.1.0",
"eslint-config-prettier": "^6.4.0",
"eslint-config-taro": "1.3.29",
"eslint-config-taro": "2.0.0-beta.13",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.13.0",
"eslint-plugin-react-hooks": "^2.0.1",
"eslint-plugin-taro": "1.3.29",
"eslint-plugin-taro": "2.0.0-beta.13",
"highlight": "^0.2.4",
"highlight.js": "^9.15.10",
"husky": "^2.4.1",
Expand Down
98 changes: 50 additions & 48 deletions src/components/checkbox/h5/index.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
import { View, Text } from '@tarojs/components';
import Taro, { pxTransform, useMemo, useState } from '@tarojs/taro'
import { IProps } from '../../../../@types/checkbox';
import { View, Text } from "@tarojs/components";
import Taro, { pxTransform, useMemo, useState } from "@tarojs/taro";
import { IProps } from "../../../../@types/checkbox";

export default function ClCheckboxH5 (props: IProps) {
const [list, setList] = useState(props.checkboxGroup || [])
export default function ClCheckboxH5(props: IProps) {
const [list, setList] = useState(props.checkboxGroup || []);
useMemo(() => {
setList(props.checkboxGroup || [])
}, [props.checkboxGroup])
setList(props.checkboxGroup || []);
}, [props.checkboxGroup]);
const change = () => {
const arr = list
.filter(item => item.checked)
.map(item => item.value || '');
props.onChange && props.onChange(arr)
}
const arr = list.filter(item => item.checked).map(item => item.value || "");
props.onChange && props.onChange(arr);
};

const colorClassName = props.color || 'green'
const type = props.type === 'form' ? 'form' : ''
const shapeClassName = props.shape === 'round' ? 'round' : ''
const directionClassName =
props.direction === 'horizontal' ? 'flex' : ''
const title = props.title
const colorClassName = props.color || "green";
const type = props.type === "form" ? "form" : "";
const shapeClassName = props.shape === "round" ? "round" : "";
const directionClassName = props.direction === "horizontal" ? "flex" : "";
const title = props.title;
const checkboxComponent = list.map(item => (
<View className='padding-xs' key={item.value}>
<Text
className='padding-right-sm'
style={{
lineHeight: `${pxTransform(46)}`,
display: 'inline-block',
verticalAlign: 'text-bottom'
}}
>
{item.key}
</Text>
<View className="padding-xs" key={item.value}>
{item.key ? (
<Text
className="padding-right-sm"
style={{
lineHeight: `${pxTransform(46)}`,
display: "inline-block",
verticalAlign: "text-bottom"
}}
>
{item.key}
</Text>
) : (
""
)}
<View
className={`h5-checkbox-input ${shapeClassName} ${item.checked ? 'checked' : ''}`}
className={`h5-checkbox-input ${shapeClassName} ${
item.checked ? "checked" : ""
} ${item.disabled ? "disabled" : ""}`}
onClick={() => {
console.log(item.value)
const checkItem = list && list.find(has => has.value === item.value)
if (checkItem) checkItem.checked = !item.checked
setList(list)
change()
const checkItem = list && list.find(has => has.value === item.value);
if (checkItem) checkItem.checked = !item.checked;
setList(list);
change();
}}
/>
</View>
))
));
const formComponent = (
<View className='cu-form-group'>
<View className='title'>{title}</View>
<View className="cu-form-group">
<View className="title">{title}</View>
<View className={directionClassName}>{checkboxComponent}</View>
</View>
)
);
return (
<View className={`h5-checkbox ${colorClassName}`}>
{type === 'form' ? formComponent : checkboxComponent}
{type === "form" ? formComponent : checkboxComponent}
</View>
)
);
}

ClCheckboxH5.options = {
addGlobalClass: true
}
};
ClCheckboxH5.defaultProps = {
color: 'green',
type: 'normal',
shape: 'normal',
direction: 'vertical',
color: "green",
type: "normal",
shape: "normal",
direction: "vertical",
checkboxGroup: [],
title: ''
} as IProps
title: ""
} as IProps;
7 changes: 5 additions & 2 deletions src/components/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ export default function ClCheckbox(props: IProps) {
const title = props.title;
const checkboxComponent = list.map(item => (
<View className="padding-xs" key={item.value}>
<Text className="padding-right-sm">{item.key}</Text>
{item.key ? <Text className="padding-right-sm">{item.key}</Text> : ""}
<Checkbox
className={`${colorClassName} ${shapeClassName}`}
className={`${colorClassName} ${shapeClassName} ${
props.more ? "more" : ""
}`}
value={item.value || ""}
checked={item.checked}
disabled={item.disabled}
/>
</View>
));
Expand Down
18 changes: 15 additions & 3 deletions src/components/radio/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Radio, RadioGroup, Text, View } from "@tarojs/components";
import Taro from "@tarojs/taro";
import Taro, { useEffect, useState } from "@tarojs/taro";
import H5Radio from "./h5";
import ListRadio from "./components/ListRadio";
import { IProps } from "../../../@types/radio";
Expand All @@ -13,15 +13,27 @@ export default function ClRadio(props: IProps) {
const directionClassName = props.direction === "horizontal" ? "flex" : "";
const list = props.radioGroup || [];

const [checkedValue, setCheckedValue] = useState(props.checkedValue);

useEffect(() => {
setCheckedValue(checkedValue);
}, [props.checkedValue]);

const changeRadio = e => {
props.onChange && props.onChange(e.detail.value);
};
const radioComponent = list.map(item => (
<View className="padding-xs" key={"radio-" + item.value}>
<View
className="padding-xs"
key={"radio-" + item.value}
onClick={() => {
setCheckedValue(item.value);
}}
>
<Text className="padding-right-sm">{item.key}</Text>
<Radio
className={`${colorClassName()} ${shapeClassName()}`}
checked={item.value === props.checkedValue}
checked={item.value === checkedValue}
value={item.value || ""}
/>
</View>
Expand Down
Empty file added src/components/tree/index.scss
Empty file.
Loading

0 comments on commit f636128

Please sign in to comment.