feat: feature support UI preview (#269)

This commit is contained in:
Joel 2023-05-31 14:10:59 +08:00 committed by GitHub
parent 5239b2c7ab
commit 554570dc22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 551 additions and 15 deletions

View File

@ -1,9 +1,13 @@
'use client' 'use client'
import React, { FC } from 'react' import type { FC } from 'react'
import React from 'react'
import cn from 'classnames'
import s from './style.module.css'
import Switch from '@/app/components/base/switch' import Switch from '@/app/components/base/switch'
export interface IFeatureItemProps { export type IFeatureItemProps = {
icon: React.ReactNode icon: React.ReactNode
previewImgClassName?: string
title: string title: string
description: string description: string
value: boolean value: boolean
@ -12,13 +16,14 @@ export interface IFeatureItemProps {
const FeatureItem: FC<IFeatureItemProps> = ({ const FeatureItem: FC<IFeatureItemProps> = ({
icon, icon,
previewImgClassName,
title, title,
description, description,
value, value,
onChange onChange,
}) => { }) => {
return ( return (
<div className='flex justify-between p-3 rounded-xl border border-transparent bg-gray-50 hover:border-gray-200 cursor-pointer'> <div className={cn(s.wrap, 'relative flex justify-between p-3 rounded-xl border border-transparent bg-gray-50 hover:border-gray-200 cursor-pointer')}>
<div className='flex space-x-3 mr-2'> <div className='flex space-x-3 mr-2'>
{/* icon */} {/* icon */}
<div <div
@ -36,6 +41,11 @@ const FeatureItem: FC<IFeatureItemProps> = ({
</div> </div>
<Switch onChange={onChange} defaultValue={value} /> <Switch onChange={onChange} defaultValue={value} />
{
previewImgClassName && (
<div className={cn(s.preview, s[previewImgClassName])}>
</div>)
}
</div> </div>
) )
} }

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 54 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 108 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 211 KiB

View File

@ -0,0 +1,25 @@
.preview {
display: none;
position: fixed;
transform: translate(410px, -54px);
width: 280px;
height: 360px;
background: center center no-repeat;
background-size: contain;
}
.wrap:hover .preview {
display: block;
}
.openingStatementPreview {
background-image: url(./preview-imgs/opening-statement.svg);
}
.suggestedQuestionsAfterAnswerPreview {
background-image: url(./preview-imgs/suggested-questions-after-answer.svg);
}
.moreLikeThisPreview {
background-image: url(./preview-imgs/more-like-this.svg);
}

View File

@ -1,19 +1,19 @@
'use client' 'use client'
import React, { FC } from 'react' import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import Modal from '@/app/components/base/modal'
import FeatureItem from './feature-item'
import FeatureGroup from '../feature-group' import FeatureGroup from '../feature-group'
import MoreLikeThisIcon from '../../../base/icons/more-like-this-icon' import MoreLikeThisIcon from '../../../base/icons/more-like-this-icon'
import FeatureItem from './feature-item'
import Modal from '@/app/components/base/modal'
import SuggestedQuestionsAfterAnswerIcon from '@/app/components/app/configuration/base/icons/suggested-questions-after-answer-icon' import SuggestedQuestionsAfterAnswerIcon from '@/app/components/app/configuration/base/icons/suggested-questions-after-answer-icon'
type IConfig = {
interface IConfig {
openingStatement: boolean openingStatement: boolean
moreLikeThis: boolean moreLikeThis: boolean
suggestedQuestionsAfterAnswer: boolean suggestedQuestionsAfterAnswer: boolean
} }
export interface IChooseFeatureProps { export type IChooseFeatureProps = {
isShow: boolean isShow: boolean
onClose: () => void onClose: () => void
config: IConfig config: IConfig
@ -32,7 +32,7 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
onClose, onClose,
isChatApp, isChatApp,
config, config,
onChange onChange,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
@ -43,6 +43,7 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
className='w-[400px]' className='w-[400px]'
title={t('appDebug.operation.addFeature')} title={t('appDebug.operation.addFeature')}
closable closable
overflowVisible
> >
<div className='pt-5 pb-10'> <div className='pt-5 pb-10'>
{/* Chat Feature */} {/* Chat Feature */}
@ -54,17 +55,19 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
<> <>
<FeatureItem <FeatureItem
icon={OpeningStatementIcon} icon={OpeningStatementIcon}
previewImgClassName='openingStatementPreview'
title={t('appDebug.feature.conversationOpener.title')} title={t('appDebug.feature.conversationOpener.title')}
description={t('appDebug.feature.conversationOpener.description')} description={t('appDebug.feature.conversationOpener.description')}
value={config.openingStatement} value={config.openingStatement}
onChange={(value) => onChange('openingStatement', value)} onChange={value => onChange('openingStatement', value)}
/> />
<FeatureItem <FeatureItem
icon={<SuggestedQuestionsAfterAnswerIcon />} icon={<SuggestedQuestionsAfterAnswerIcon />}
previewImgClassName='suggestedQuestionsAfterAnswerPreview'
title={t('appDebug.feature.suggestedQuestionsAfterAnswer.title')} title={t('appDebug.feature.suggestedQuestionsAfterAnswer.title')}
description={t('appDebug.feature.suggestedQuestionsAfterAnswer.description')} description={t('appDebug.feature.suggestedQuestionsAfterAnswer.description')}
value={config.suggestedQuestionsAfterAnswer} value={config.suggestedQuestionsAfterAnswer}
onChange={(value) => onChange('suggestedQuestionsAfterAnswer', value)} onChange={value => onChange('suggestedQuestionsAfterAnswer', value)}
/> />
</> </>
</FeatureGroup> </FeatureGroup>
@ -76,10 +79,11 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
<> <>
<FeatureItem <FeatureItem
icon={<MoreLikeThisIcon />} icon={<MoreLikeThisIcon />}
previewImgClassName='moreLikeThisPreview'
title={t('appDebug.feature.moreLikeThis.title')} title={t('appDebug.feature.moreLikeThis.title')}
description={t('appDebug.feature.moreLikeThis.description')} description={t('appDebug.feature.moreLikeThis.description')}
value={config.moreLikeThis} value={config.moreLikeThis}
onChange={(value) => onChange('moreLikeThis', value)} onChange={value => onChange('moreLikeThis', value)}
/> />
</> </>
</FeatureGroup> </FeatureGroup>

View File

@ -12,6 +12,7 @@ type IModal = {
description?: React.ReactNode description?: React.ReactNode
children: React.ReactNode children: React.ReactNode
closable?: boolean closable?: boolean
overflowVisible?: boolean
} }
export default function Modal({ export default function Modal({
@ -23,6 +24,7 @@ export default function Modal({
description, description,
children, children,
closable = false, closable = false,
overflowVisible = false,
}: IModal) { }: IModal) {
return ( return (
<Transition appear show={isShow} as={Fragment}> <Transition appear show={isShow} as={Fragment}>
@ -50,7 +52,7 @@ export default function Modal({
leaveFrom="opacity-100 scale-100" leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95" leaveTo="opacity-0 scale-95"
> >
<Dialog.Panel className={`w-full max-w-md transform overflow-hidden rounded-2xl bg-white p-6 text-left align-middle shadow-xl transition-all ${className}`}> <Dialog.Panel className={`w-full max-w-md transform ${overflowVisible ? 'overflow-visible' : 'overflow-hidden'} rounded-2xl bg-white p-6 text-left align-middle shadow-xl transition-all ${className}`}>
{title && <Dialog.Title {title && <Dialog.Title
as="h3" as="h3"
className="text-lg font-medium leading-6 text-gray-900" className="text-lg font-medium leading-6 text-gray-900"