Skip to content

Commit

Permalink
✨ feat: add Input
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed May 26, 2023
1 parent b1b0c7f commit 3eec31a
Show file tree
Hide file tree
Showing 23 changed files with 225 additions and 108 deletions.
4 changes: 2 additions & 2 deletions src/ActionIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const ActionIcon = memo<ActionIconProps>(
borderRadius = 5;
break;
case 'small':
blockSize = 28;
blockSize = 24;
borderRadius = 5;
break;
case 'site':
Expand All @@ -99,7 +99,7 @@ const ActionIcon = memo<ActionIconProps>(
style={{ width: blockSize, height: blockSize, borderRadius, ...style }}
{...props}
>
<Icon size={size === 'site' ? 'small' : size} icon={icon} />
<Icon size={size === 'site' ? 'normal' : size} icon={icon} />
</div>
);

Expand Down
37 changes: 23 additions & 14 deletions src/EditableMessage/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { EditableMessage } from '@lobehub/ui';
import { Button, Divider } from 'antd';
import { EditableMessage, StroyBook, useControls, useCreateStore } from '@lobehub/ui';
import { button } from 'leva';
import { useState } from 'react';
import { Flexbox } from 'react-layout-kit';

export default () => {
const [openModal, setOpenModal] = useState(false);
const [editing, setEdit] = useState(false);
const store = useCreateStore();
useControls(
{
editing: button(() => {
setEdit(true);
}),
openModal: button(() => {
setOpenModal(true);
}),
},
{ store },
);
return (
<Flexbox width={400}>
<Button
onClick={() => {
setEdit(true);
}}
>
编辑
</Button>
<Divider />
<EditableMessage value={'editable text'} editing={editing} onEditingChange={setEdit} />
</Flexbox>
<StroyBook levaStore={store}>
<EditableMessage
value={'editable text'}
openModal={openModal}
editing={editing}
onEditingChange={setEdit}
/>
</StroyBook>
);
};
2 changes: 1 addition & 1 deletion src/EditableMessage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: EditableMessage

## Default

<code src="./demos/index.tsx" center></code>
<code src="./demos/index.tsx" nopadding></code>

## APIs

Expand Down
14 changes: 6 additions & 8 deletions src/EditableMessageList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import IconAction from '@/ActionIcon';
import { ChatMessage, messagesReducer } from '@/Chat';
import { ControlInput } from '@/components/ControlInput';
import { PlusOutlined } from '@ant-design/icons';
import { Button, Select } from 'antd';
import isEqual from 'fast-deep-equal';
import { TrashIcon } from 'lucide-react';
import { memo, useEffect, useReducer } from 'react';
import { Flexbox } from 'react-layout-kit';

import IconAction from '@/ActionIcon';
import { ChatMessage, messagesReducer } from '@/Chat';
import { ControlInput } from '@/components/ControlInput';

import { TrashIcon } from 'lucide-react';

export interface EditableMessageListProps {
dataSources: ChatMessage[];
onChange?: (chatMessages: ChatMessage[]) => void;
Expand Down Expand Up @@ -60,8 +58,8 @@ export const EditableMessageList = memo<EditableMessageListProps>(
/>
<IconAction
icon={TrashIcon}
title={'删除'}
size={'small'}
placement="right"
title="Delete"
onClick={() => {
dispatch({ type: 'deleteMessage', index });
}}
Expand Down
2 changes: 1 addition & 1 deletion src/EditableText/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const EditableText = memo<EditableTextProps>(({ value, onChange }: ControlInputP
title={'Edit'}
placement="right"
icon={Edit3}
size={{ fontSize: 14, blockSize: 24 }}
size="small"
onClick={() => {
setEdited(!edited);
}}
Expand Down
8 changes: 6 additions & 2 deletions src/Icon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SvgProps } from '@/types';
import { LucideIcon } from 'lucide-react';
import { FC, memo } from 'react';

Expand Down Expand Up @@ -29,12 +30,15 @@ const Icon: FC<IconProps> = ({ icon, size = 'normal', ...props }) => {
const SvgIcon = icon;
switch (size) {
case 'large':
case 'normal':
fontSize = 24;
strokeWidth = 2;
break;
case 'small':
case 'normal':
fontSize = 20;
strokeWidth = 2;
break;
case 'small':
fontSize = 14;
strokeWidth = 1.5;
break;
default:
Expand Down
20 changes: 20 additions & 0 deletions src/Input/demos/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { StroyBook, TextArea, TextAreaProps, useControls, useCreateStore } from '@lobehub/ui';

export default () => {
const store = useCreateStore();
const controls: TextAreaProps | any = useControls(
{
placeholder: 'Type keywords...',
type: {
value: 'ghost',
options: ['ghost', 'block'],
},
},
{ store },
);
return (
<StroyBook levaStore={store}>
<TextArea {...controls} />
</StroyBook>
);
};
20 changes: 20 additions & 0 deletions src/Input/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Input, InputProps, StroyBook, useControls, useCreateStore } from '@lobehub/ui';

export default () => {
const store = useCreateStore();
const controls: InputProps | any = useControls(
{
placeholder: 'Type keywords...',
type: {
value: 'ghost',
options: ['ghost', 'block'],
},
},
{ store },
);
return (
<StroyBook levaStore={store}>
<Input {...controls} />
</StroyBook>
);
};
20 changes: 20 additions & 0 deletions src/Input/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
nav: Components
group: Common
title: Input
description: A basic widget for getting the user input is a text field. Keyboard and mouse can be used for providing or changing data.
---

## Default

The rest of the props of Input are exactly the same as the original [input](https://ant.design/components/input).

<code src="./demos/index.tsx" nopadding></code>

## TextArea

<code src="./demos/TextArea.tsx" nopadding></code>

## APIs

<API></API>
23 changes: 23 additions & 0 deletions src/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Input as AntInput, InputProps as AntdInputProps } from 'antd';
import { TextAreaProps as AntdTextAreaProps } from 'antd/es/input/TextArea';
import { memo } from 'react';
import { useStyles } from './style';
export interface InputProps extends AntdInputProps {
ref?: any;
type?: 'ghost' | 'block';
}

export const Input = memo<InputProps>(({ className, type = 'ghost', ...props }) => {
const { styles, cx } = useStyles({ type });
return <AntInput className={cx(styles.input, className)} {...props} />;
});

export interface TextAreaProps extends AntdTextAreaProps {
ref?: any;
type?: 'ghost' | 'block';
}

export const TextArea = memo<TextAreaProps>(({ className, type = 'ghost', ...props }) => {
const { styles, cx } = useStyles({ type });
return <AntInput.TextArea className={cx(styles.textarea, className)} {...props} />;
});
44 changes: 44 additions & 0 deletions src/Input/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { createStyles } from 'antd-style';
import { rgba } from 'polished';

export const useStyles = createStyles(({ css, token }, { type }: { type: 'ghost' | 'block' }) => ({
input: css`
position: relative;
max-width: 100%;
height: 36px;
padding: 0 12px;
background-color: ${type === 'block' ? rgba(token.colorBgElevated, 0.6) : 'transparent'};
border: 1px solid ${type === 'block' ? 'transparent' : token.colorBorder};
transition: background-color 100ms ${token.motionEaseOut};
input {
background: transparent;
}
&:hover {
background-color: ${token.colorFillTertiary};
}
`,
textarea: css`
position: relative;
max-width: 100%;
padding: 8px 12px;
background-color: ${type === 'block' ? rgba(token.colorBgElevated, 0.6) : 'transparent'};
border: 1px solid ${type === 'block' ? 'transparent' : token.colorBorder};
transition: background-color 100ms ${token.motionEaseOut};
textarea {
background: transparent;
}
&:hover {
background-color: ${token.colorFillTertiary};
}
`,
}));
1 change: 1 addition & 0 deletions src/Logo/Logo3D.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ImgProps } from '@/types';
import { memo } from 'react';

const Logo3D = memo<ImgProps | any>(({ ...props }) => (
Expand Down
1 change: 1 addition & 0 deletions src/Logo/LogoFlat.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SvgProps } from '@/types';
import { memo } from 'react';

const LogoFlat = memo<SvgProps | any>(({ ...props }) => (
Expand Down
1 change: 1 addition & 0 deletions src/Logo/LogoHighContrast.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SvgProps } from '@/types';
import { memo } from 'react';

const LogoHighContrast = memo<SvgProps | any>(({ ...props }) => (
Expand Down
1 change: 1 addition & 0 deletions src/Logo/LogoText.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SvgProps } from '@/types';
import { memo } from 'react';

const LogoText = memo<SvgProps | any>(({ ...props }) => (
Expand Down
18 changes: 10 additions & 8 deletions src/MessageInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, ButtonProps, Input } from 'antd';
import { TextArea, type TextAreaProps } from '@/index';
import { Button, ButtonProps } from 'antd';
import { cx } from 'antd-style';
import { memo, useState } from 'react';
import { Flexbox } from 'react-layout-kit';
Expand Down Expand Up @@ -33,17 +34,18 @@ export interface MessageInputProps {
renderButtons?: (text: string) => ButtonProps[];
height?: number;
className?: string;
type?: TextAreaProps['type'];
}

const MessageInput = memo<MessageInputProps>(
({ onCancel, defaultValue, onConfirm, renderButtons, height, className }) => {
({ type, onCancel, defaultValue, onConfirm, renderButtons, height, className }) => {
const [tempSystemRole, setRole] = useState<string>(defaultValue || '');

return (
<Flexbox gap={8}>
<Input.TextArea
<TextArea
type={type}
value={tempSystemRole}
allowClear
placeholder={'例如:你是一名擅长翻译的翻译官,请将用户所输入的英文都翻译为中文。'}
style={{ height: height ?? 200 }}
onChange={(e) => {
Expand All @@ -59,16 +61,16 @@ const MessageInput = memo<MessageInputProps>(
) : (
<>
<Button
type={'primary'}
type="primary"
onClick={() => {
onConfirm?.(tempSystemRole);
}}
>
设定
Confirm
</Button>

<Button type={'text'} onClick={onCancel}>
取消
<Button type="text" onClick={onCancel}>
Cancel
</Button>
</>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/SearchBar/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ description: SearchBar that includes an input field with a search icon and clear

## Default

The rest of the props of Input are exactly the same as the original [input](https://ant.design/components/input).

<code src="./demos/index.tsx" nopadding></code>

## APIs
Expand Down
Loading

1 comment on commit 3eec31a

@vercel
Copy link

@vercel vercel bot commented on 3eec31a May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lobe-ui – ./

lobe-ui.vercel.app
lobe-ui-git-master-lobehub.vercel.app
lobe-ui-lobehub.vercel.app
ui.lobehub.com

Please sign in to comment.