feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const CACHE_KEY = 'workflow_prefer_interactive_type';
|
||||
export const SHOW_KEY = 'show_workflow_interactive_type_guide';
|
||||
|
||||
export const IS_MAC_OS = /(Macintosh|MacIntel|MacPPC|Mac68K|iPad)/.test(
|
||||
navigator.userAgent,
|
||||
);
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export function MouseIcon() {
|
||||
return (
|
||||
<svg
|
||||
width="34"
|
||||
height="52"
|
||||
viewBox="0 0 34 52"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M30.9998 16.6666V35.3333C30.9998 37.5748 30.9948 38.4695 30.9 39.1895C30.2108 44.4247 26.0912 48.5443 20.856 49.2335C20.1361 49.3283 19.2413 49.3333 16.9998 49.3333C14.7584 49.3333 13.8636 49.3283 13.1437 49.2335C7.90847 48.5443 3.78888 44.4247 3.09965 39.1895C3.00487 38.4695 2.99984 37.5748 2.99984 35.3333V16.6666C2.99984 14.4252 3.00487 13.5304 3.09965 12.8105C3.78888 7.57528 7.90847 3.45569 13.1437 2.76646C13.7232 2.69017 14.4159 2.67202 15.8332 2.66785V9.86573C14.4738 10.3462 13.4998 11.6426 13.4998 13.1666V17.8332C13.4998 19.3571 14.4738 20.6536 15.8332 21.1341V23.6666C15.8332 24.3109 16.3555 24.8333 16.9998 24.8333C17.6442 24.8333 18.1665 24.3109 18.1665 23.6666V21.1341C19.5259 20.6536 20.4998 19.3572 20.4998 17.8332V13.1666C20.4998 11.6426 19.5259 10.3462 18.1665 9.86571V2.66785C19.5837 2.67202 20.2765 2.69017 20.856 2.76646C26.0912 3.45569 30.2108 7.57528 30.9 12.8105C30.9948 13.5304 30.9998 14.4252 30.9998 16.6666ZM0.666504 16.6666C0.666504 14.4993 0.666504 13.4157 0.786276 12.5059C1.61335 6.22368 6.55687 1.28016 12.8391 0.453085C13.7489 0.333313 14.8325 0.333313 16.9998 0.333313C19.1671 0.333313 20.2508 0.333313 21.1605 0.453085C27.4428 1.28016 32.3863 6.22368 33.2134 12.5059C33.3332 13.4157 33.3332 14.4994 33.3332 16.6666V35.3333C33.3332 37.5006 33.3332 38.5843 33.2134 39.494C32.3863 45.7763 27.4428 50.7198 21.1605 51.5469C20.2508 51.6666 19.1671 51.6666 16.9998 51.6666C14.8325 51.6666 13.7489 51.6666 12.8391 51.5469C6.55687 50.7198 1.61335 45.7763 0.786276 39.494C0.666504 38.5843 0.666504 37.5006 0.666504 35.3333V16.6666ZM15.8332 13.1666C15.8332 13.0011 15.8676 12.8437 15.9297 12.7011C15.9886 12.566 16.0722 12.4443 16.1749 12.3416C16.386 12.1305 16.6777 11.9999 16.9998 11.9999C17.6435 11.9999 18.1654 12.5212 18.1665 13.1646L18.1665 13.1666V17.8332L18.1665 17.8353C18.1665 17.8364 18.1665 17.8376 18.1665 17.8387C18.1661 17.9132 18.1588 17.986 18.1452 18.0565C18.0853 18.3656 17.9033 18.6312 17.6515 18.8011C17.4655 18.9266 17.2412 18.9999 16.9998 18.9999C16.3555 18.9999 15.8332 18.4776 15.8332 17.8332V13.1666Z"
|
||||
fill="currentColor"
|
||||
fill-opacity="0.8"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export function PadIcon() {
|
||||
return (
|
||||
<svg
|
||||
width="48"
|
||||
height="38"
|
||||
viewBox="0 0 48 38"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<rect
|
||||
x="1.83317"
|
||||
y="1.49998"
|
||||
width="44.3333"
|
||||
height="35"
|
||||
rx="3.5"
|
||||
stroke="currentColor"
|
||||
stroke-opacity="0.8"
|
||||
stroke-width="2.33333"
|
||||
/>
|
||||
<path
|
||||
d="M14.6665 30.6667H33.3332"
|
||||
stroke="currentColor"
|
||||
stroke-opacity="0.8"
|
||||
stroke-width="2.33333"
|
||||
stroke-linecap="round"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {
|
||||
MousePadSelector,
|
||||
type MousePadSelectorProps,
|
||||
InteractiveType,
|
||||
} from './mouse-pad-selector';
|
||||
|
||||
export {
|
||||
GuidingPopover,
|
||||
type GuidingPopoverProps,
|
||||
} from './with-guiding-popover';
|
||||
|
||||
export { getPreferInteractiveType, setPreferInteractiveType } from './utils';
|
||||
@@ -0,0 +1,112 @@
|
||||
/* stylelint-disable no-descending-specificity */
|
||||
/* stylelint-disable selector-class-pattern */
|
||||
.ui-mouse-pad-selector {
|
||||
position: relative;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
box-sizing: border-box;
|
||||
width: 68px;
|
||||
height: 32px;
|
||||
padding: 8px 12px;
|
||||
|
||||
border: 1px solid rgba(29, 28, 35, 8%);
|
||||
border-radius: 8px;
|
||||
|
||||
&-icon {
|
||||
height: 20px;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
&-arrow {
|
||||
height: 16px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
&-popover {
|
||||
padding: 16px;
|
||||
|
||||
&-options {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.mouse-pad-option {
|
||||
box-sizing: border-box;
|
||||
width: 220px;
|
||||
padding-bottom: 20px;
|
||||
|
||||
text-align: center;
|
||||
|
||||
background: var(--coz-mg-card, #FFF);
|
||||
border: 1px solid var(--coz-stroke-plus, rgba(6, 7, 9, 15%));
|
||||
border-radius: var(--default, 8px);
|
||||
|
||||
&-icon {
|
||||
padding-top: 26px;
|
||||
}
|
||||
|
||||
&-title {
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
&-subTitle {
|
||||
padding: 4px 12px 0;
|
||||
}
|
||||
|
||||
&-icon-selected {
|
||||
color: rgb(19 0 221);
|
||||
}
|
||||
|
||||
&-title-selected {
|
||||
color: var(--coz-fg-hglt, #4E40E5);
|
||||
}
|
||||
|
||||
&-subTitle-selected {
|
||||
color: var(--coz-fg-hglt, #4E40E5);
|
||||
}
|
||||
|
||||
&-selected {
|
||||
cursor: pointer;
|
||||
background-color: var(--coz-mg-hglt, rgba(186, 192, 255, 20%));
|
||||
border: 1px solid var(--coz-stroke-hglt, #4E40E5);
|
||||
border-radius: var(--default, 8px);
|
||||
}
|
||||
|
||||
&:hover:not(&-selected) {
|
||||
cursor: pointer;
|
||||
|
||||
background-color: var(--coz-mg-card-hovered, #FFF);
|
||||
border: 1px solid var(--coz-stroke-plus, rgba(6, 7, 9, 15%));
|
||||
border-radius: var(--default, 8px);
|
||||
box-shadow: 0 8px 24px 0 rgba(0, 0, 0, 16%), 0 16px 48px 0 rgba(0, 0, 0, 8%);
|
||||
}
|
||||
|
||||
&:active:not(&-selected) {
|
||||
background-color: rgba(46, 46, 56, 12%);
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
padding-top: 13px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
background-color: rgba(46, 46, 56, 8%);
|
||||
border-color: rgba(77, 83, 232, 100%);
|
||||
}
|
||||
|
||||
&:active,
|
||||
&:focus {
|
||||
background-color: rgba(46, 46, 56, 12%);
|
||||
border-color: rgba(77, 83, 232, 100%);
|
||||
}
|
||||
|
||||
&-active {
|
||||
border-color: rgba(77, 83, 232, 100%);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { type CSSProperties, useState } from 'react';
|
||||
|
||||
import cls from 'classnames';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import {
|
||||
IconCozArrowDown,
|
||||
IconCozMouse,
|
||||
IconCozTablet,
|
||||
} from '@coze-arch/coze-design/icons';
|
||||
import { Popover, Typography } from '@coze-arch/bot-semi';
|
||||
|
||||
import { PadIcon } from './icons/pad';
|
||||
import { MouseIcon } from './icons/mouse';
|
||||
|
||||
import styles from './mouse-pad-selector.module.less';
|
||||
|
||||
const { Title, Paragraph } = Typography;
|
||||
|
||||
export enum InteractiveType {
|
||||
Mouse = 'MOUSE',
|
||||
Pad = 'PAD',
|
||||
}
|
||||
|
||||
export interface MousePadSelectorProps {
|
||||
value: InteractiveType;
|
||||
onChange: (value: InteractiveType) => void;
|
||||
onPopupVisibleChange?: (visible: boolean) => void;
|
||||
containerStyle?: CSSProperties;
|
||||
iconStyle?: CSSProperties;
|
||||
arrowStyle?: CSSProperties;
|
||||
}
|
||||
|
||||
const IteractiveItem: React.FC<{
|
||||
title: string;
|
||||
subTitle: string;
|
||||
icon: React.ReactNode;
|
||||
value: InteractiveType;
|
||||
selected: boolean;
|
||||
onChange: (value: InteractiveType) => void;
|
||||
}> = ({ title, subTitle, icon, onChange, value, selected }) => (
|
||||
<div
|
||||
className={cls({
|
||||
[styles['mouse-pad-option']]: true,
|
||||
[styles['mouse-pad-option-selected']]: selected,
|
||||
})}
|
||||
onClick={() => onChange(value)}
|
||||
>
|
||||
<div
|
||||
className={cls({
|
||||
[styles['mouse-pad-option-icon']]: true,
|
||||
[styles['mouse-pad-option-icon-selected']]: selected,
|
||||
})}
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
<Title
|
||||
heading={6}
|
||||
className={cls({
|
||||
[styles['mouse-pad-option-title']]: true,
|
||||
[styles['mouse-pad-option-title-selected']]: selected,
|
||||
})}
|
||||
>
|
||||
{title}
|
||||
</Title>
|
||||
<Paragraph
|
||||
type="tertiary"
|
||||
className={cls({
|
||||
[styles['mouse-pad-option-subTitle']]: true,
|
||||
[styles['mouse-pad-option-subTitle-selected']]: selected,
|
||||
})}
|
||||
>
|
||||
{subTitle}
|
||||
</Paragraph>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const MousePadSelector: React.FC<
|
||||
MousePadSelectorProps & React.RefAttributes<HTMLDivElement>
|
||||
> = React.forwardRef(
|
||||
(
|
||||
{
|
||||
value,
|
||||
onChange,
|
||||
onPopupVisibleChange,
|
||||
containerStyle,
|
||||
iconStyle,
|
||||
arrowStyle,
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const isMouse = value === InteractiveType.Mouse;
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
return (
|
||||
<Popover
|
||||
trigger="custom"
|
||||
position="topLeft"
|
||||
closeOnEsc
|
||||
visible={visible}
|
||||
onVisibleChange={v => {
|
||||
onPopupVisibleChange?.(v);
|
||||
}}
|
||||
onClickOutSide={() => {
|
||||
setVisible(false);
|
||||
}}
|
||||
spacing={20}
|
||||
content={
|
||||
<div className={styles['ui-mouse-pad-selector-popover']}>
|
||||
<Typography.Title heading={4}>
|
||||
{I18n.t('workflow_interactive_mode')}
|
||||
</Typography.Title>
|
||||
<div className={styles['ui-mouse-pad-selector-popover-options']}>
|
||||
<IteractiveItem
|
||||
title={I18n.t('workflow_mouse_friendly')}
|
||||
subTitle={I18n.t('workflow_mouse_friendly_desc')}
|
||||
data-testid="workflow.detail.toolbar.interactive.mouse"
|
||||
value={InteractiveType.Mouse}
|
||||
selected={value === InteractiveType.Mouse}
|
||||
icon={<MouseIcon />}
|
||||
onChange={onChange}
|
||||
/>
|
||||
|
||||
<IteractiveItem
|
||||
title={I18n.t('workflow_pad_friendly')}
|
||||
subTitle={I18n.t('workflow_pad_friendly_desc')}
|
||||
data-testid="workflow.detail.toolbar.interactive.pad"
|
||||
value={InteractiveType.Pad}
|
||||
selected={value === InteractiveType.Pad}
|
||||
icon={<PadIcon />}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div
|
||||
className={cls({
|
||||
[styles['ui-mouse-pad-selector']]: true,
|
||||
[styles['ui-mouse-pad-selector-active']]: visible,
|
||||
})}
|
||||
ref={ref}
|
||||
onClick={() => {
|
||||
setVisible(!visible);
|
||||
}}
|
||||
style={containerStyle}
|
||||
>
|
||||
<div
|
||||
className={styles['ui-mouse-pad-selector-icon']}
|
||||
style={iconStyle}
|
||||
>
|
||||
{isMouse ? <IconCozMouse /> : <IconCozTablet />}
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={styles['ui-mouse-pad-selector-arrow']}
|
||||
style={arrowStyle}
|
||||
>
|
||||
<IconCozArrowDown />
|
||||
</div>
|
||||
</div>
|
||||
</Popover>
|
||||
);
|
||||
},
|
||||
);
|
||||
17
frontend/packages/components/mouse-pad-selector/src/typings.d.ts
vendored
Normal file
17
frontend/packages/components/mouse-pad-selector/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
45
frontend/packages/components/mouse-pad-selector/src/utils.ts
Normal file
45
frontend/packages/components/mouse-pad-selector/src/utils.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { InteractiveType } from './mouse-pad-selector';
|
||||
import { CACHE_KEY, SHOW_KEY, IS_MAC_OS } from './constants';
|
||||
|
||||
export const getPreferInteractiveType = () => {
|
||||
const data = localStorage.getItem(CACHE_KEY) as string;
|
||||
if (
|
||||
data &&
|
||||
[InteractiveType.Mouse, InteractiveType.Pad].includes(
|
||||
data as InteractiveType,
|
||||
)
|
||||
) {
|
||||
return data;
|
||||
}
|
||||
return IS_MAC_OS ? InteractiveType.Pad : InteractiveType.Mouse;
|
||||
};
|
||||
|
||||
/** 记录选择的交互模式 */
|
||||
export const setPreferInteractiveType = (type: InteractiveType) => {
|
||||
localStorage.setItem(CACHE_KEY, type);
|
||||
};
|
||||
|
||||
export const hideGuidingPopover = () => {
|
||||
localStorage.setItem(SHOW_KEY, 'true');
|
||||
};
|
||||
|
||||
export const needShowGuidingPopover = () => {
|
||||
const data = localStorage.getItem(SHOW_KEY) as string;
|
||||
return data !== 'true';
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
.guiding-content {
|
||||
width: 277px;
|
||||
padding: 16px;
|
||||
box-sizing: border-box;
|
||||
|
||||
&-title {
|
||||
font-weight: 600
|
||||
}
|
||||
|
||||
&-desc {
|
||||
font-size: 12px;
|
||||
color: rgba(29, 28, 35, 0.6);
|
||||
}
|
||||
|
||||
&-button {
|
||||
width: 100%;
|
||||
height: 32px;
|
||||
border-radius: 8px;
|
||||
background-color: rgba(77, 83, 232, 1);
|
||||
}
|
||||
|
||||
&-mouse-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 16px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
&-icon {
|
||||
width: 32px;
|
||||
margin-right: 4px;
|
||||
transform: scale(0.577) translate(-5px, 0);
|
||||
color: rgba(77, 83, 232, 1);
|
||||
text-align: center;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
&-pad-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
|
||||
&-icon {
|
||||
width: 32px;
|
||||
margin-right: 4px;
|
||||
transform: scale(0.577) translate(-13px, 0);
|
||||
color: rgba(62, 194, 84, 1);
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { Button, Popover, Typography } from '@coze-arch/bot-semi';
|
||||
|
||||
import { PadIcon } from '../src/icons/pad';
|
||||
import { MouseIcon } from '../src/icons/mouse';
|
||||
import { needShowGuidingPopover, hideGuidingPopover } from './utils';
|
||||
|
||||
import styles from './with-guiding-popover.module.less';
|
||||
|
||||
export interface GuidingPopoverProps {
|
||||
buttonText: string;
|
||||
mainTitle: string;
|
||||
mouseOptionTitle: string;
|
||||
mouseOptionDesc: string;
|
||||
padOptionTitle: string;
|
||||
padOptionDesc: string;
|
||||
onGotIt: () => void;
|
||||
}
|
||||
|
||||
const GuidingContent = (props: GuidingPopoverProps) => (
|
||||
<div className={styles['guiding-content']}>
|
||||
<div className={styles['guiding-content-title']}>
|
||||
<Typography.Text>{props.mainTitle}</Typography.Text>
|
||||
</div>
|
||||
|
||||
<div className={styles['guiding-content-mouse-option']}>
|
||||
<div className={styles['guiding-content-mouse-option-icon']}>
|
||||
<MouseIcon />
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text className={styles['guiding-content-title']}>
|
||||
{props.mouseOptionTitle}
|
||||
</Typography.Text>
|
||||
<Typography.Paragraph className={styles['guiding-content-desc']}>
|
||||
{props.mouseOptionDesc}
|
||||
</Typography.Paragraph>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles['guiding-content-pad-option']}>
|
||||
<div className={styles['guiding-content-pad-option-icon']}>
|
||||
<PadIcon />
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text className={styles['guiding-content-title']}>
|
||||
{props.padOptionTitle}
|
||||
</Typography.Text>
|
||||
<Typography.Paragraph className={styles['guiding-content-desc']}>
|
||||
{props.padOptionDesc}
|
||||
</Typography.Paragraph>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
type="primary"
|
||||
theme="solid"
|
||||
className={styles['guiding-content-button']}
|
||||
onClick={props?.onGotIt}
|
||||
>
|
||||
{props.buttonText}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const GuidingPopover = (
|
||||
props: React.PropsWithChildren<Partial<GuidingPopoverProps>>,
|
||||
) => {
|
||||
const {
|
||||
children,
|
||||
mainTitle = I18n.t('workflow_interactive_mode_popover_title'),
|
||||
buttonText = I18n.t('guidance_got_it'),
|
||||
mouseOptionTitle = I18n.t('workflow_interactive_mode_mouse_friendly'),
|
||||
mouseOptionDesc = I18n.t('workflow_interactive_mode_mouse_friendly_desc'),
|
||||
padOptionTitle = I18n.t('workflow_interactive_mode_pad_friendly'),
|
||||
padOptionDesc = I18n.t('workflow_interactive_mode_pad_friendly_desc'),
|
||||
} = props;
|
||||
|
||||
const [visible, setVisible] = useState(() => needShowGuidingPopover());
|
||||
const onButtonClick = () => setVisible(false);
|
||||
|
||||
// gotIt 方法先不暴露到上层了,后续需要使用再暴露出来
|
||||
const handleGotIt = () => {
|
||||
hideGuidingPopover();
|
||||
setVisible(false);
|
||||
};
|
||||
|
||||
const textProps = {
|
||||
mainTitle,
|
||||
mouseOptionTitle,
|
||||
mouseOptionDesc,
|
||||
padOptionTitle,
|
||||
padOptionDesc,
|
||||
buttonText,
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover
|
||||
content={<GuidingContent {...textProps} onGotIt={handleGotIt} />}
|
||||
trigger="custom"
|
||||
position="top"
|
||||
style={{ padding: 0 }}
|
||||
visible={visible}
|
||||
showArrow
|
||||
onClickOutSide={onButtonClick}
|
||||
>
|
||||
{children}
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user