-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #478 from illa-family/develop
Develop
- Loading branch information
Showing
34 changed files
with
1,171 additions
and
10 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
41 changes: 41 additions & 0 deletions
41
apps/builder/src/page/App/components/PanelSetters/MenuSetter/MenuOptionSetter/body.tsx
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,41 @@ | ||
import { FC, useContext } from "react" | ||
import { Reorder } from "framer-motion" | ||
import { MenuListSetterContext } from "./context/menuListContext" | ||
import { EmptyBody } from "./empty" | ||
import { removeNativeStyle } from "@/page/App/components/PanelSetters/TableSetter/ColumnSetter/style" | ||
import { MenuItem } from "@/page/App/components/PanelSetters/MenuSetter/MenuOptionSetter/menuItem" | ||
|
||
export const ListBody: FC = () => { | ||
const { columnItems, handleUpdateDsl, attrPath } = useContext( | ||
MenuListSetterContext, | ||
) | ||
|
||
if (!columnItems || !Array.isArray(columnItems) || columnItems.length === 0) | ||
return <EmptyBody /> | ||
|
||
return ( | ||
<Reorder.Group | ||
axis="y" | ||
initial={false} | ||
values={columnItems} | ||
onReorder={(value) => { | ||
handleUpdateDsl(attrPath, value) | ||
}} | ||
css={removeNativeStyle} | ||
> | ||
{columnItems.map((item, index) => { | ||
const { title, id, disabled, icon, subMenu } = item | ||
return ( | ||
<Reorder.Item | ||
initial={false} | ||
css={removeNativeStyle} | ||
key={item.id} | ||
value={item} | ||
> | ||
<MenuItem {...item} index={index} /> | ||
</Reorder.Item> | ||
) | ||
})} | ||
</Reorder.Group> | ||
) | ||
} |
81 changes: 81 additions & 0 deletions
81
.../page/App/components/PanelSetters/MenuSetter/MenuOptionSetter/context/menuListContext.tsx
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,81 @@ | ||
import { createContext, FC, ReactNode, useCallback } from "react" | ||
import { PanelFieldConfig } from "@/page/App/components/InspectPanel/interface" | ||
import { generateNewSubMenuItem } from "../utils/generateNewMenu" | ||
import { MenuList } from "@/widgetLibrary/MenuWidget/interface" | ||
|
||
interface ProviderProps { | ||
columnItems: MenuList[] | ||
childrenSetter: PanelFieldConfig[] | ||
widgetDisplayName: string | ||
attrPath: string | ||
handleUpdateDsl: (attrPath: string, value: any) => void | ||
children: ReactNode | ||
} | ||
|
||
interface Inject extends Omit<ProviderProps, "children"> { | ||
handleDeleteMenuItem: (index: number) => void | ||
handleAddSubMenuItem: (index: number) => void | ||
handleDeleteSubMenuItem: (index: number, subIndex: number) => void | ||
} | ||
|
||
export const MenuListSetterContext = createContext<Inject>({} as Inject) | ||
|
||
export const MenusSetterProvider: FC<ProviderProps> = (props) => { | ||
const { columnItems, attrPath, handleUpdateDsl } = props | ||
|
||
const handleDeleteMenuItem = useCallback( | ||
(index: number) => { | ||
const updatedArray = columnItems.filter( | ||
(optionItem: Record<string, any>, i: number) => { | ||
return i !== index | ||
}, | ||
) | ||
handleUpdateDsl(attrPath, updatedArray) | ||
}, | ||
[columnItems, handleUpdateDsl, attrPath], | ||
) | ||
|
||
const handleDeleteSubMenuItem = useCallback( | ||
(index: number, subIndex: number) => { | ||
const updatedArray = JSON.parse(JSON.stringify(columnItems)) | ||
updatedArray[index].subMenu = updatedArray[index].subMenu?.filter( | ||
(optionItem: Record<string, any>, i: number) => { | ||
return i !== subIndex | ||
}, | ||
) | ||
handleUpdateDsl(attrPath, updatedArray) | ||
}, | ||
[columnItems, handleUpdateDsl, attrPath], | ||
) | ||
|
||
const handleAddSubMenuItem = useCallback( | ||
(index: number) => { | ||
const updatedArray = JSON.parse(JSON.stringify(columnItems)) | ||
const num = (updatedArray[index]?.subMenu?.length ?? 0) + 1 | ||
const newItem = generateNewSubMenuItem(num) | ||
if (updatedArray[index].subMenu) { | ||
updatedArray[index].subMenu.push(newItem) | ||
} else { | ||
updatedArray[index]["subMenu"] = [newItem] | ||
} | ||
|
||
handleUpdateDsl(attrPath, updatedArray) | ||
}, | ||
[columnItems, handleUpdateDsl, attrPath], | ||
) | ||
|
||
const value = { | ||
...props, | ||
handleDeleteMenuItem, | ||
handleAddSubMenuItem, | ||
handleDeleteSubMenuItem, | ||
} | ||
|
||
return ( | ||
<MenuListSetterContext.Provider value={value}> | ||
{props.children} | ||
</MenuListSetterContext.Provider> | ||
) | ||
} | ||
|
||
MenusSetterProvider.displayName = "ColumnsSetterProvider" |
97 changes: 97 additions & 0 deletions
97
...der/src/page/App/components/PanelSetters/MenuSetter/MenuOptionSetter/dragIconAndLabel.tsx
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,97 @@ | ||
import { FC, useCallback, useContext, useState } from "react" | ||
import { useTranslation } from "react-i18next" | ||
import { DragPointIcon, AddIcon } from "@illa-design/icon" | ||
import { Trigger } from "@illa-design/trigger" | ||
import { | ||
addIconStyle, | ||
deleteButtonStyle, | ||
dragItemStyle, | ||
iconAreaStyle, | ||
labelNameAndIconStyle, | ||
labelNameWrapperStyle, | ||
modalStyle, | ||
movableIconWrapperStyle, | ||
} from "./style" | ||
import { DragIconAndLabelProps } from "./interface" | ||
import { BaseModal } from "@/page/App/components/PanelSetters/PublicComponent/Modal" | ||
import { MenuListSetterContext } from "./context/menuListContext" | ||
import { Button } from "@illa-design/button" | ||
|
||
export const DragIconAndLabel: FC<DragIconAndLabelProps> = (props) => { | ||
const { index, title } = props | ||
const [modalVisible, setModalVisible] = useState(false) | ||
const { | ||
widgetDisplayName, | ||
attrPath, | ||
childrenSetter, | ||
handleAddSubMenuItem, | ||
handleDeleteMenuItem, | ||
} = useContext(MenuListSetterContext) | ||
|
||
const { t } = useTranslation() | ||
|
||
const handleCloseModal = useCallback(() => { | ||
setModalVisible(false) | ||
}, []) | ||
|
||
return ( | ||
<Trigger | ||
withoutPadding | ||
colorScheme="white" | ||
popupVisible={modalVisible} | ||
content={ | ||
<BaseModal | ||
_css={modalStyle} | ||
title={title ?? ""} | ||
handleCloseModal={handleCloseModal} | ||
attrPath={`${attrPath}.${index}`} | ||
widgetDisplayName={widgetDisplayName} | ||
childrenSetter={childrenSetter} | ||
extraElement={ | ||
<Button | ||
css={deleteButtonStyle} | ||
colorScheme="red" | ||
variant="light" | ||
onClick={() => { | ||
handleDeleteMenuItem(index) | ||
}} | ||
> | ||
{t("editor.inspect.setter_content.menu_setter.delete")} | ||
</Button> | ||
} | ||
/> | ||
} | ||
trigger="click" | ||
showArrow={false} | ||
position="left" | ||
clickOutsideToClose | ||
onVisibleChange={(visible) => { | ||
setModalVisible(visible) | ||
}} | ||
> | ||
<div css={dragItemStyle}> | ||
<div css={labelNameAndIconStyle}> | ||
<span css={movableIconWrapperStyle} className="movableIconWrapper"> | ||
<DragPointIcon /> | ||
</span> | ||
<span css={labelNameWrapperStyle}> | ||
{title || | ||
t("editor.inspect.setter_content.option_list.list_no_label")} | ||
</span> | ||
</div> | ||
<div | ||
css={iconAreaStyle} | ||
onClick={(event) => { | ||
handleAddSubMenuItem(index) | ||
event.stopPropagation() | ||
}} | ||
> | ||
<AddIcon _css={addIconStyle} /> | ||
<span>{t("editor.inspect.setter_content.menu_setter.sub")}</span> | ||
</div> | ||
</div> | ||
</Trigger> | ||
) | ||
} | ||
|
||
DragIconAndLabel.displayName = "DragIconAndLabel" |
8 changes: 8 additions & 0 deletions
8
apps/builder/src/page/App/components/PanelSetters/MenuSetter/MenuOptionSetter/empty.tsx
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,8 @@ | ||
import { FC } from "react" | ||
import { emptyEmptyBodyStyle } from "./style" | ||
|
||
export const EmptyBody: FC = () => { | ||
return <div css={emptyEmptyBodyStyle}>No columns</div> | ||
} | ||
|
||
EmptyBody.displayName = "ColumnsEmptyBody" |
17 changes: 17 additions & 0 deletions
17
apps/builder/src/page/App/components/PanelSetters/MenuSetter/MenuOptionSetter/header.tsx
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,17 @@ | ||
import { FC } from "react" | ||
import { optionListHeaderStyle } from "./style" | ||
import { HeaderProps } from "./interface" | ||
import { useTranslation } from "react-i18next" | ||
|
||
export const OptionListHeader: FC<HeaderProps> = (props) => { | ||
const { labelName } = props | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<div css={optionListHeaderStyle}> | ||
<div>{labelName}</div> | ||
</div> | ||
) | ||
} | ||
|
||
OptionListHeader.displayName = "OptionListHeader" |
Oops, something went wrong.