Fix the design of the Variable chip (#9871)
- Use a React component for variable tags in tiptap - Fix the design of the variable chip - Always display a button to delete the chip 
This commit is contained in:
committed by
GitHub
parent
ac8c0c72cc
commit
1e9dce3fd5
@ -0,0 +1,25 @@
|
||||
import { VariableChip } from '@/object-record/record-field/form-types/components/VariableChip';
|
||||
import styled from '@emotion/styled';
|
||||
import { NodeViewProps, NodeViewWrapper } from '@tiptap/react';
|
||||
|
||||
const StyledWrapper = styled.span`
|
||||
display: inline-block;
|
||||
padding-inline: ${({ theme }) => theme.spacing(0.5)};
|
||||
`;
|
||||
|
||||
type WorkflowTextEditorVariableChipProps = NodeViewProps;
|
||||
|
||||
export const WorkflowTextEditorVariableChip = ({
|
||||
deleteNode,
|
||||
node,
|
||||
}: WorkflowTextEditorVariableChipProps) => {
|
||||
const attrs = node.attrs as {
|
||||
variable: string;
|
||||
};
|
||||
|
||||
return (
|
||||
<NodeViewWrapper as={StyledWrapper} style={{ whiteSpace: 'nowrap' }}>
|
||||
<VariableChip rawVariableName={attrs.variable} onRemove={deleteNode} />
|
||||
</NodeViewWrapper>
|
||||
);
|
||||
};
|
||||
@ -1,6 +1,7 @@
|
||||
import { WorkflowTextEditorVariableChip } from '@/workflow/workflow-variables/components/WorkflowTextEditorVariableChip';
|
||||
import { extractVariableLabel } from '@/workflow/workflow-variables/utils/extractVariableLabel';
|
||||
import { Node } from '@tiptap/core';
|
||||
import { mergeAttributes } from '@tiptap/react';
|
||||
import { mergeAttributes, ReactNodeViewRenderer } from '@tiptap/react';
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands<ReturnType> {
|
||||
@ -41,6 +42,10 @@ export const VariableTag = Node.create({
|
||||
];
|
||||
},
|
||||
|
||||
addNodeView: () => {
|
||||
return ReactNodeViewRenderer(WorkflowTextEditorVariableChip);
|
||||
},
|
||||
|
||||
renderText: ({ node }) => {
|
||||
return node.attrs.variable;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user