Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design): add
Textarea
component (#1778)
- Loading branch information
Showing
13 changed files
with
243 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/design/src/components/textarea/Textarea.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* 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 type { Meta } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { Textarea } from './Textarea'; | ||
|
||
const meta: Meta<typeof Textarea> = { | ||
title: 'Components / Textarea', | ||
component: Textarea, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
export const TextareaBasic = { | ||
render() { | ||
return ( | ||
<> | ||
<Textarea autoSize={{ minRows: 4 }} /> | ||
</> | ||
); | ||
}, | ||
}; | ||
|
||
export const TextareaDisabled = { | ||
render() { | ||
return <Textarea disabled />; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* 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 clsx from 'clsx'; | ||
import type { TextAreaProps } from 'rc-textarea'; | ||
import RcTextarea from 'rc-textarea'; | ||
import React from 'react'; | ||
|
||
import styles from './index.module.less'; | ||
|
||
export interface ITextareaProps extends Pick<TextAreaProps, 'onFocus' | 'onBlur'> { | ||
/** | ||
* Whether the input is autoFocus | ||
* @default false | ||
*/ | ||
autoFocus?: boolean; | ||
|
||
/** | ||
* The input class name | ||
*/ | ||
className?: string; | ||
|
||
/** | ||
* The input affix wrapper style | ||
*/ | ||
style?: React.CSSProperties; | ||
|
||
/** | ||
* The input affix wrapper style | ||
*/ | ||
autoSize?: boolean | { minRows?: number; maxRows?: number }; | ||
|
||
/** | ||
* The input placeholder | ||
*/ | ||
placeholder?: string; | ||
|
||
/** | ||
* The input content value | ||
*/ | ||
value?: string; | ||
|
||
/** | ||
* Whether the input is disabled | ||
* @default false | ||
*/ | ||
disabled?: boolean; | ||
|
||
/** | ||
* Callback when user press a key | ||
* @param e | ||
*/ | ||
onKeyDown?: React.KeyboardEventHandler; | ||
|
||
/** | ||
* Callback when user input | ||
* @param value | ||
*/ | ||
onChange?: (value: string) => void; | ||
|
||
} | ||
|
||
export function Textarea(props: ITextareaProps) { | ||
const { | ||
autoFocus = false, | ||
autoSize = false, | ||
className, | ||
placeholder, | ||
value, | ||
disabled = false, | ||
onKeyDown, | ||
onChange, | ||
...rest | ||
} = props; | ||
|
||
function handleChange(e: React.ChangeEvent<HTMLTextAreaElement>) { | ||
const { value } = e.target; | ||
onChange?.(value); | ||
} | ||
|
||
const _className = clsx(className, { | ||
}, className); | ||
|
||
return ( | ||
<RcTextarea | ||
prefixCls={styles.textarea} | ||
classNames={{ affixWrapper: _className }} | ||
autoFocus={autoFocus} | ||
autoSize={autoSize} | ||
placeholder={placeholder} | ||
value={value} | ||
disabled={disabled} | ||
onKeyDown={onKeyDown} | ||
onChange={handleChange} | ||
{...rest} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@textarea-prefix-cls: textarea; | ||
|
||
.@{textarea-prefix-cls} { | ||
position: relative; | ||
|
||
width: 280px; | ||
|
||
padding: var(--padding-sm); | ||
|
||
box-sizing: border-box; | ||
|
||
border: 1px solid rgb(var(--border-color)); | ||
border-radius: var(--border-radius-base); | ||
|
||
overflow: hidden; | ||
|
||
transition: all 0.15s; | ||
|
||
&:hover, | ||
&:focus { | ||
border-color: rgb(var(--primary-color)); | ||
outline: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* 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 { type ITextareaProps, Textarea } from './Textarea'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.