-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
1,497 additions
and
289 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.