|
| 1 | +import { ColumnTypeCompBuilder } from "comps/comps/tableComp/column/columnTypeCompBuilder"; |
| 2 | +import { StringControl } from "comps/controls/codeControl"; |
| 3 | +import { MultiCompBuilder, stateComp, withDefault } from "comps/generators"; |
| 4 | +import { trans } from "i18n"; |
| 5 | +import styled from "styled-components"; |
| 6 | +import { LightActiveTextColor, PrimaryColor } from "constants/style"; |
| 7 | +import { styleControl } from "comps/controls/styleControl"; |
| 8 | +import { avatarGroupStyle, AvatarGroupStyleType } from "comps/controls/styleControlConstants"; |
| 9 | +import { AlignCenter, AlignLeft, AlignRight } from "lowcoder-design"; |
| 10 | +import { NumberControl } from "comps/controls/codeControl"; |
| 11 | +import { Avatar, Tooltip } from "antd"; |
| 12 | +import { clickEvent, eventHandlerControl, refreshEvent } from "comps/controls/eventHandlerControl"; |
| 13 | +import { ReactElement } from "react"; |
| 14 | +import { IconControl } from "comps/controls/iconControl"; |
| 15 | +import { ColorControl } from "comps/controls/colorControl"; |
| 16 | +import { optionsControl } from "comps/controls/optionsControl"; |
| 17 | +import { BoolControl } from "comps/controls/boolControl"; |
| 18 | +import { dropdownControl } from "comps/controls/dropdownControl"; |
| 19 | +import { JSONObject } from "util/jsonTypes"; |
| 20 | +import { Dispatch } from 'redux'; |
| 21 | +import { changeChildAction } from "lowcoder-core"; |
| 22 | + |
| 23 | +const MenuLinkWrapper = styled.div` |
| 24 | + > a { |
| 25 | + color: ${PrimaryColor} !important; |
| 26 | +
|
| 27 | + &:hover { |
| 28 | + color: ${LightActiveTextColor} !important; |
| 29 | + } |
| 30 | + } |
| 31 | +`; |
| 32 | + |
| 33 | +const MacaroneList = [ |
| 34 | + '#fde68a', |
| 35 | + '#eecff3', |
| 36 | + '#a7f3d0', |
| 37 | + '#bfdbfe', |
| 38 | + '#bfdbfe', |
| 39 | + '#c7d2fe', |
| 40 | + '#fecaca', |
| 41 | + '#fcd6bb', |
| 42 | +] |
| 43 | + |
| 44 | +const Container = styled.div<{ $style: AvatarGroupStyleType | undefined, alignment: string }>` |
| 45 | + height: 100%; |
| 46 | + width: 100%; |
| 47 | + display: flex; |
| 48 | + align-items: center; |
| 49 | + justify-content: ${props => props.alignment}; |
| 50 | + cursor: pointer; |
| 51 | +`; |
| 52 | + |
| 53 | +const DropdownOption = new MultiCompBuilder( |
| 54 | + { |
| 55 | + src: StringControl, |
| 56 | + AvatarIcon: IconControl, |
| 57 | + label: StringControl, |
| 58 | + color: ColorControl, |
| 59 | + backgroundColor: ColorControl, |
| 60 | + Tooltip: StringControl, |
| 61 | + }, |
| 62 | + (props) => props |
| 63 | +) |
| 64 | +.setPropertyViewFn((children) => { |
| 65 | + return ( |
| 66 | + <> |
| 67 | + {children.src.propertyView({ label: trans("avatarComp.src"), placeholder: "", tooltip: trans("avatarComp.avatarCompTooltip") })} |
| 68 | + {children.label.propertyView({label: trans("avatarComp.title"), tooltip: trans("avatarComp.avatarCompTooltip"), |
| 69 | + })} |
| 70 | + {children.AvatarIcon.propertyView({ |
| 71 | + label: trans("avatarComp.icon"), |
| 72 | + IconType: "All", |
| 73 | + tooltip: trans("avatarComp.avatarCompTooltip"), |
| 74 | + })} |
| 75 | + {children.color.propertyView({ label: trans("style.fill") })} |
| 76 | + {children.backgroundColor.propertyView({ label: trans("style.background") })} |
| 77 | + {children.Tooltip.propertyView({ label: trans("badge.tooltip") })} |
| 78 | + </> |
| 79 | + ); |
| 80 | +}) |
| 81 | +.build(); |
| 82 | + |
| 83 | +const EventOptions = [clickEvent, refreshEvent] as const; |
| 84 | + |
| 85 | +export const alignOptions = [ |
| 86 | + { label: <AlignLeft />, value: "flex-start" }, |
| 87 | + { label: <AlignCenter />, value: "center" }, |
| 88 | + { label: <AlignRight />, value: "flex-end" }, |
| 89 | +] as const; |
| 90 | + |
| 91 | +// props.dispatch(changeChildAction("currentAvatar", item as JSONObject, false)); |
| 92 | + |
| 93 | +export const ColumnAvatarsComp = (function () { |
| 94 | + const childrenMap = { |
| 95 | + style: styleControl(avatarGroupStyle), |
| 96 | + maxCount: withDefault(NumberControl, 3), |
| 97 | + avatarSize: withDefault(NumberControl, 40), |
| 98 | + alignment: dropdownControl(alignOptions, "center"), |
| 99 | + autoColor: BoolControl.DEFAULT_TRUE, |
| 100 | + onEvent: eventHandlerControl(EventOptions), |
| 101 | + currentAvatar: stateComp<JSONObject>({}), |
| 102 | + avatars: optionsControl(DropdownOption, { |
| 103 | + initOptions: [ |
| 104 | + { src: "https://api.dicebear.com/7.x/miniavs/svg?seed=1", label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) }, |
| 105 | + { AvatarIcon: "/icon:antd/startwotone" }, |
| 106 | + { label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) }, |
| 107 | + { label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) }, |
| 108 | + ], |
| 109 | + }) |
| 110 | + }; |
| 111 | + return new ColumnTypeCompBuilder( |
| 112 | + childrenMap, |
| 113 | + (props) => { |
| 114 | + return ( |
| 115 | + <Container |
| 116 | + $style={props.style} |
| 117 | + alignment={props.alignment} |
| 118 | + > |
| 119 | + { |
| 120 | + <Avatar.Group maxCount={props.maxCount} size={props.avatarSize}> |
| 121 | + { |
| 122 | + props.avatars.map((item, index) => { |
| 123 | + return ( |
| 124 | + <Tooltip title={item.Tooltip}> |
| 125 | + <Avatar |
| 126 | + src={item.src ?? undefined} |
| 127 | + icon={(item.AvatarIcon as ReactElement)?.props.value === '' || item.label.trim() !== '' ? undefined : item.AvatarIcon} |
| 128 | + style={{ |
| 129 | + color: item.color ? item.color : (props.style.fill !== '#FFFFFF' ? props.style.fill : '#FFFFFF'), |
| 130 | + backgroundColor: item.backgroundColor ? item.backgroundColor : (props.autoColor ? MacaroneList[index % MacaroneList.length] : props.style.background), |
| 131 | + }} |
| 132 | + size={props.avatarSize} |
| 133 | + onClick={() => { |
| 134 | + props.onEvent("click") |
| 135 | + // dispatch(changeChildAction("currentAvatar", item as JSONObject, false)); |
| 136 | + }} |
| 137 | + > |
| 138 | + {item.label} |
| 139 | + </Avatar> |
| 140 | + </Tooltip> |
| 141 | + ) |
| 142 | + }) |
| 143 | + } |
| 144 | + </Avatar.Group> |
| 145 | + } |
| 146 | + </Container> |
| 147 | + ) |
| 148 | + }, |
| 149 | + () => "" |
| 150 | + ) |
| 151 | + .setPropertyViewFn((children) => ( |
| 152 | + <> |
| 153 | + {children.avatars.propertyView({})} |
| 154 | + {children.maxCount.propertyView({ |
| 155 | + label: trans("avatarGroup.maxCount") |
| 156 | + })} |
| 157 | + {children.avatarSize.propertyView({ |
| 158 | + label: trans("avatarGroup.avatarSize") |
| 159 | + })} |
| 160 | + {children.autoColor.propertyView({ |
| 161 | + label: trans("avatarGroup.autoColor") |
| 162 | + })} |
| 163 | + {children.alignment.propertyView({ |
| 164 | + label: trans("avatarGroup.alignment"), |
| 165 | + radioButton: true, |
| 166 | + })} |
| 167 | + {children.avatars.propertyView({ |
| 168 | + newOptionLabel: trans("table.option"), |
| 169 | + title: trans("table.optionList"), |
| 170 | + })} |
| 171 | + </> |
| 172 | + )) |
| 173 | + .build(); |
| 174 | +})(); |
0 commit comments