Skip to content

Commit

Permalink
chore: add emoji pancel
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpd committed May 30, 2023
1 parent 3458ca9 commit 7fdb404
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 16 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
"prepare": "husky install"
},
"dependencies": {
"@emoji-mart/data": "1.1.2",
"@emoji-mart/react": "1.1.1",
"@reduxjs/toolkit": "1.9.5",
"@vercel/analytics": "1.0.1",
"ahooks": "3.7.7",
"antd": "5.5.0",
"axios": "1.4.0",
"dayjs": "1.11.7",
"emoji-mart": "5.5.2",
"github-markdown-css": "5.2.0",
"i18next": "22.5.0",
"katex": "0.16.7",
Expand All @@ -52,6 +55,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "12.3.1",
"react-icons": "4.9.0",
"react-markdown": "8.0.7",
"react-redux": "8.0.5",
"react-syntax-highlighter": "15.5.0",
Expand Down
42 changes: 42 additions & 0 deletions src/components/EmojiPicker/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import { Button, Tooltip } from 'antd'
import EmojiPicker from './index'
import Image from 'next/image'

const ButtonEmojiPicker = (props: {
value?: ''
readOnly?: boolean
onChange?: (val: any) => void
onEmojiClick?: (emoji: any) => void
theme?: 'auto' | 'light' | 'dark'
style?: 'native' | 'apple' | 'google' | 'facebook'
}) => {
const [_value, setValue] = React.useState(props.value)
return (
<Tooltip
placement="bottom"
destroyTooltipOnHide={true}
trigger={'click'}
overlayStyle={{ maxWidth: 'auto' }}
color={'#00000000'}
open={props.readOnly ? false : undefined}
title={
<EmojiPicker
theme={props?.theme || 'auto'}
style={props?.style || 'apple'}
onEmojiClick={(emoji: any) => {
props?.onEmojiClick?.(emoji)
props?.onChange?.(emoji.imageUrl)
setValue(emoji.imageUrl)
}}
/>
}
>
<Button size={'middle'} type="dashed" style={{ height: '38px', overflow: 'hidden', padding: '0 auto' }}>
{_value && <Image src={_value} width={30} height={30} style={{ width: 30, height: 30, overflow: 'hidden' }} alt={''} />}
</Button>
</Tooltip>
)
}

export default ButtonEmojiPicker
24 changes: 24 additions & 0 deletions src/components/EmojiPicker/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import data from '@emoji-mart/data'
import Picker from '@emoji-mart/react'

export function getEmojiUrl(unified: string, style: string) {
return `https://cdn.staticfile.org/emoji-datasource-apple/14.0.0/img/${style}/64/${unified}.png`
}

const EmojiPicker = (props: { onEmojiClick: (emoji: any) => void; theme: 'auto' | 'light' | 'dark'; style: 'native' | 'apple' | 'google' | 'facebook' }) => {
return (
<Picker
theme={props.theme || 'auto'}
data={data}
onEmojiSelect={(emoji: any) => {
// 返回emoji图片链接
emoji.imageUrl = getEmojiUrl(emoji.unified, props.style || 'apple')
console.log('onEmojiSelect', emoji)
props.onEmojiClick(emoji)
}}
/>
)
}

export default EmojiPicker
2 changes: 1 addition & 1 deletion src/components/pages/plugin/Store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function OnlinePlugin() {
/>
</div>
<Drawer
title={t('c.plugin')}
title={(openItem as Plugin)?.name || t('c.plugin')}
onClose={() => setOpen(false)}
extra={
<Space>
Expand Down
30 changes: 18 additions & 12 deletions src/components/pages/prompt/Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useSiteContext } from '@/contexts/site'
import { Button, Form, Input, InputNumber, Popconfirm, Select, Space, theme as antdTheme, Typography, Divider, Tag, message } from 'antd'
import { DeleteOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
import { Button, Form, Input, InputNumber, Popconfirm, Select, Space, theme as antdTheme, Typography, Divider, Tag, message, Tooltip } from 'antd'
import AntIcon, { DeleteOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
import { usePromptContext } from '@/contexts'
import { Prompt } from '@/types/prompt'
import { useTranslation } from '@/locales'
import { uuidv4 } from '@/utils/uuid'
import { useEffect, useState } from 'react'
import { Model, ModelList, LanguageList } from '@/config/constant'
import { useRouter } from 'next/router'
import ButtonEmojiPicker from '@/components/EmojiPicker/Button'

function Edit(props: { action: string; page: boolean; prompt?: Prompt; edit: boolean }) {
// const router = useRouter()
Expand Down Expand Up @@ -122,6 +123,9 @@ function Edit(props: { action: string; page: boolean; prompt?: Prompt; edit: boo
<Radio value="text">文本</Radio>
</Radio.Group>
</Form.Item> */}
<Form.Item label="图标" name="image" required>
<ButtonEmojiPicker theme={theme} style={'apple'} readOnly={!edit} />
</Form.Item>
<Form.Item label="名称" name="name" required>
<Input readOnly={!edit} />
</Form.Item>
Expand Down Expand Up @@ -226,16 +230,18 @@ function Edit(props: { action: string; page: boolean; prompt?: Prompt; edit: boo
{/* <Form.Item label="是否公开" name="private" valuePropName="private">
<Switch />
</Form.Item> */}
<Form.Item wrapperCol={{ offset: 6, span: 16 }}>
<Space>
<Button type="primary" htmlType="submit">
保存
</Button>
<Button type="text" htmlType="button" onClick={onReset}>
重置
</Button>
</Space>
</Form.Item>
{edit && (
<Form.Item wrapperCol={{ offset: 6, span: 16 }}>
<Space>
<Button type="primary" htmlType="submit">
保存
</Button>
<Button type="text" htmlType="button" onClick={onReset}>
重置
</Button>
</Space>
</Form.Item>
)}
</Form>
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/prompt/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function IndexPage(props: { setContent: Function; style?: React.CSSProperties })
ellipsis={{ rows: 1 }}
style={{ marginBottom: '0.5em', fontSize: 12, textAlign: 'left', color: uuid == item.uuid ? token.colorPrimaryActive : token.colorText }}
>
{item.description || 'No description'}
{item.intro || 'No intro'}
</Typography.Paragraph>
}
/>
Expand Down Expand Up @@ -162,7 +162,7 @@ function IndexPage(props: { setContent: Function; style?: React.CSSProperties })
</Space>
</div>
<Drawer
title={t('c.prompt')}
title={(openItem as Prompt)?.name || t('c.prompt')}
extra={
<Space>
<Popconfirm
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/prompt/Store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function OnlinePrompt() {
/>
</div>
<Drawer
title={t('c.prompt')}
title={(openItem as Prompt)?.name || t('c.prompt')}
onClose={() => setOpen(false)}
extra={
<Space>
Expand Down

0 comments on commit 7fdb404

Please sign in to comment.