Skip to content

Commit

Permalink
fix: expression-setter add showOptionsDropDown
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Mar 26, 2024
1 parent 16b0c18 commit 83d4930
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions packages/designer/src/setters/expression-setter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useCallback } from 'react';
import { Box, Text, css } from 'coral-system';
import { Modal } from 'antd';
import { Dropdown, Modal } from 'antd';
import {
isValidExpressionCode,
isWrappedByExpressionContainer,
Expand All @@ -13,8 +13,8 @@ import {
getValue,
IVariableTreeNode,
} from '@music163/tango-helpers';
import { CloseCircleFilled, ExpandAltOutlined } from '@ant-design/icons';
import { Panel, InputCode, Action } from '@music163/tango-ui';
import { CloseCircleFilled, ExpandAltOutlined, InfoOutlined, KeyOutlined } from '@ant-design/icons';
import { Panel, InputCode, Action, CodeOutlined } from '@music163/tango-ui';
import { FormItemComponentProps } from '@music163/tango-setting-form';
import { useWorkspace, useWorkspaceData } from '@music163/tango-context';
import { VariableTree } from '../components';
Expand Down Expand Up @@ -60,6 +60,8 @@ export function getWrappedExpressionCode(code: string) {
}

const suffixStyle = css`
display: flex;
align-items: center;
.anticon-close-circle {
color: rgba(0, 0, 0, 0.25);
&:hover {
Expand All @@ -73,6 +75,7 @@ export interface ExpressionSetterProps extends FormItemComponentProps<string> {
modalTip?: string;
autoCompleteOptions?: string[];
allowClear?: boolean;
showOptionsDropDown?: boolean;
}

export function ExpressionSetter(props: ExpressionSetterProps) {
Expand All @@ -86,6 +89,7 @@ export function ExpressionSetter(props: ExpressionSetterProps) {
status,
allowClear = true,
newStoreTemplate,
showOptionsDropDown = true,
} = props;
const [visible, { on, off }] = useBoolean();
const [inputValue, setInputValue] = useState(() => {
Expand Down Expand Up @@ -118,6 +122,7 @@ export function ExpressionSetter(props: ExpressionSetterProps) {

return (
<Box className="ExpressionSetter">
{/* 同时支持下拉框展示 */}
<InputCode
placeholder={placeholder}
suffix={
Expand All @@ -130,6 +135,26 @@ export function ExpressionSetter(props: ExpressionSetterProps) {
}}
/>
)}
{showOptionsDropDown && autoCompleteOptions?.length && (
<Dropdown
menu={{
items: autoCompleteOptions.map((option) => ({
key: option,
label: (
<Text
onClick={() => {
change(option);
}}
>
{option}
</Text>
),
})),
}}
>
<Action tooltip="使用预设代码片段" icon={<InfoOutlined />} size="small" />
</Dropdown>
)}
<Action
tooltip="打开表达式变量选择面板"
icon={<ExpandAltOutlined />}
Expand Down

0 comments on commit 83d4930

Please sign in to comment.