Skip to content

Commit

Permalink
custom hook used
Browse files Browse the repository at this point in the history
  • Loading branch information
MenamAfzal authored and raheeliftikhar5 committed Jul 1, 2024
1 parent fee527e commit 3d616ae
Show file tree
Hide file tree
Showing 53 changed files with 122 additions and 881 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";


const InputStyle = styled(Input) <{ $style: InputLikeStyleType }>`
Expand Down Expand Up @@ -107,21 +108,7 @@ const getValidate = (value: any): "" | "warning" | "error" | undefined => {

let AutoCompleteCompBase = (function () {
return new UICompBuilder(childrenMap, (props, dispatch) => {
const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'labelStyle', 'inputFieldStyle', 'animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
useMergeCompStyles(props as Record<string, any>, dispatch);

const {
items,
Expand Down
17 changes: 2 additions & 15 deletions client/packages/lowcoder/src/comps/comps/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { CompNameContext, EditorContext } from "../editorState";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const AvatarWrapper = styled(Avatar) <AvatarProps & { $cursorPointer?: boolean, $style: AvatarStyleType }>`
background: ${(props) => props.$style.background};
Expand Down Expand Up @@ -201,22 +202,8 @@ const AvatarView = (props: RecordConstructorToView<typeof childrenMap>) => {

let AvatarBasicComp = (function () {
return new UICompBuilder(childrenMap, (props , dispatch) => {
useMergeCompStyles(props as Record<string, any>, dispatch);

const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'labelStyle', 'inputFieldStyle', 'animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
return(<AvatarView {...props} />)})
.setPropertyViewFn((children) => (
<>
Expand Down
18 changes: 3 additions & 15 deletions client/packages/lowcoder/src/comps/comps/avatarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { JSONObject } from "util/jsonTypes";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const MacaroneList = [
'#fde68a',
Expand Down Expand Up @@ -146,21 +147,8 @@ const AvatarGroupView = (props: RecordConstructorToView<typeof childrenMap> & {

let AvatarGroupBasicComp = (function () {
return new UICompBuilder(childrenMap, (props, dispatch) =>{
const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'avatar'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
useMergeCompStyles(props as Record<string, any>, dispatch);

return( <AvatarGroupView {...props} dispatch={dispatch} />
)})
.setPropertyViewFn((children) => (
Expand Down
17 changes: 2 additions & 15 deletions client/packages/lowcoder/src/comps/comps/buttonComp/buttonComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { styleControl } from "@lowcoder-ee/comps/controls/styleControl";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const FormLabel = styled(CommonBlueLabel)`
font-size: 13px;
Expand Down Expand Up @@ -138,21 +139,7 @@ const ButtonTmpComp = (function () {
viewRef: RefControl<HTMLElement>,
};
return new UICompBuilder(childrenMap, (props , dispatch) => {
const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
useMergeCompStyles(props as Record<string, any>, dispatch);

return(
<ButtonCompWrapper disabled={props.disabled}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { styleControl } from "@lowcoder-ee/comps/controls/styleControl";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const StyledDropdownButton = styled(DropdownButton)`
width: 100%;
Expand Down Expand Up @@ -91,21 +92,7 @@ const DropdownTmpComp = (function () {
style: styleControl(DropdownStyle, 'style'),
};
return new UICompBuilder(childrenMap, (props, dispatch) => {
const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
useMergeCompStyles(props as Record<string, any>, dispatch);

const hasIcon =
props.options.findIndex((option) => (option.prefixIcon as ReactElement)?.props.value) > -1;
Expand Down
17 changes: 2 additions & 15 deletions client/packages/lowcoder/src/comps/comps/buttonComp/linkComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import React, { useContext, useEffect } from "react";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const Link = styled(Button)<{
$style: LinkStyleType;
Expand Down Expand Up @@ -95,22 +96,8 @@ const LinkTmpComp = (function () {
viewRef: RefControl<HTMLElement>,
};
return new UICompBuilder(childrenMap, (props, dispatch) => {
const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
useMergeCompStyles(props as Record<string, any>, dispatch);

const styleProps: Record<string, any> = {};
['style', 'animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);

// chrome86 bug: button children should not contain only empty span
const hasChildren = hasIcon(props.prefixIcon) || !!props.text || hasIcon(props.suffixIcon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { EditorContext } from "comps/editorState";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const Error = styled.div`
color: #f5222d;
Expand Down Expand Up @@ -76,24 +77,8 @@ const ScannerTmpComp = (function () {
style: styleControl(DropdownStyle, 'style'),
viewRef: RefControl<HTMLElement>,
};
return new UICompBuilder(childrenMap, (props ,dispatch) => {

const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);

return new UICompBuilder(childrenMap, (props, dispatch) => {
useMergeCompStyles(props as Record<string, any>, dispatch);

const [showModal, setShowModal] = useState(false);
const [errMessage, setErrMessage] = useState("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { EditorContext } from "comps/editorState";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const IconWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -72,21 +73,7 @@ const ToggleTmpComp = (function () {
const text = props.showText
? (props.value.value ? props.trueText : props.falseText) || undefined
: undefined;
const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
useMergeCompStyles(props as Record<string, any>, dispatch);

return (
<ButtonCompWrapperStyled
Expand Down
21 changes: 3 additions & 18 deletions client/packages/lowcoder/src/comps/comps/carouselComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AnimationStyle, AnimationStyleType, CarouselStyle } from "comps/control

import { useContext } from "react";
import { EditorContext } from "comps/editorState";
import { ThemeContext } from "@lowcoder-ee/index.sdk";
import { ThemeContext, useMergeCompStyles } from "@lowcoder-ee/index.sdk";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";

Expand Down Expand Up @@ -51,23 +51,8 @@ let CarouselBasicComp = (function () {
animationStyle: styleControl(AnimationStyle , 'animationStyle'),
...formDataChildren,
};
return new UICompBuilder(childrenMap, (props , dispatch) => {

const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style','animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
return new UICompBuilder(childrenMap, (props, dispatch) => {
useMergeCompStyles(props as Record<string, any>, dispatch);

const containerRef = useRef<HTMLDivElement>(null);
const [height, setHeight] = useState(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { DisabledContext } from "comps/generators/uiCompBuilder";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";

const ContainWrapper = styled.div<{
$style: ContainerStyleType & {
Expand Down Expand Up @@ -181,23 +182,8 @@ const ColumnLayout = (props: ColumnLayoutProps) => {

export const ResponsiveLayoutBaseComp = (function () {
return new UICompBuilder(childrenMap, (props, dispatch) => {
useMergeCompStyles(props as Record<string, any>, dispatch);

const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'columnStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);

return (
<ColumnLayout {...props} dispatch={dispatch} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { default as CloseOutlined } from "@ant-design/icons/CloseOutlined";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";


dayjs.extend(relativeTime);
Expand Down Expand Up @@ -377,22 +378,7 @@ const CommentCompBase = (

let CommentBasicComp = (function () {
return new UICompBuilder(childrenMap, (props, dispatch) =>{

const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
useMergeCompStyles(props as Record<string, any>, dispatch);

return (
<CommentCompBase {...props} dispatch={dispatch} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { styleControl } from "comps/controls/styleControl";
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
import { useMergeCompStyles } from "@lowcoder-ee/index.sdk";
const { Meta } = Card;

const Wrapper = styled.div<{
Expand Down Expand Up @@ -196,22 +197,7 @@ export const ContainerBaseComp = (function () {
};

return new ContainerCompBuilder(childrenMap, (props, dispatch) => {

const theme = useContext(ThemeContext);
const compType = useContext(CompTypeContext);
const compTheme = theme?.theme?.components?.[compType];
const styleProps: Record<string, any> = {};
['style', 'headerStyle', 'bodyStyle', 'animationStyle'].forEach((key: string) => {
styleProps[key] = (props as any)[key];
});

useEffect(() => {
setInitialCompStyles({
dispatch,
compTheme,
styleProps,
});
}, []);
useMergeCompStyles(props as Record<string, any>, dispatch);

props.container.showHeader = false;
// 注入容器参数
Expand Down
Loading

0 comments on commit 3d616ae

Please sign in to comment.