-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(textarea):New component: Textarea (#130)
* feat: 新增textarea组件,测试待完善 * feat: 新增textarea test * docs(textarea): updated docs of textarea * docs(textarea): add html source code * docs(textarea): update index.md of textarea * fix(textarea): fix broken unit test * chore: changeset --------- Co-authored-by: Jerry.Qin 秦利杰 <[email protected]> Co-authored-by: BugMaker.Huang <[email protected]>
- Loading branch information
1 parent
e6cd2e8
commit 6af84b1
Showing
18 changed files
with
962 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@banana-ui/react': minor | ||
'@banana-ui/banana': minor | ||
--- | ||
|
||
New Component: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* title: 基本使用 | ||
*/ | ||
|
||
import { Textarea } from '@banana-ui/react'; | ||
|
||
export default function BasicUsage() { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '16px', | ||
}} | ||
> | ||
<Textarea /> | ||
<Textarea placeholder="Custom placeholder" /> | ||
<Textarea placeholder="Disabled" disabled /> | ||
</div> | ||
); | ||
} |
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,62 @@ | ||
/** | ||
* title: 表单测试 | ||
* debug: true | ||
*/ | ||
|
||
import { Button, Textarea } from '@banana-ui/react'; | ||
import React from 'react'; | ||
|
||
export default function FormTest() { | ||
const [controlledInputValue, setControlledInputValue] = React.useState('controlled'); | ||
|
||
return ( | ||
<div> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
const formData = new FormData(e.target as HTMLFormElement); | ||
console.log('formData.entries()', formData.entries()); | ||
|
||
for (const [key, value] of formData.entries()) { | ||
console.log(`${key}: ${value as string}`); | ||
} | ||
}} | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '16px', | ||
}} | ||
> | ||
<Textarea name="username" rows={2} value="789" /> | ||
<Textarea name="password" rows={2} /> | ||
<Textarea name="test" value="123" rows={2} disabled /> | ||
<Textarea name="email" rows={2} required placeholder="required email" /> | ||
<Textarea | ||
controlled | ||
name="controlled" | ||
value={controlledInputValue} | ||
rows={2} | ||
placeholder="controlled input" | ||
onChange={(e: any) => { | ||
console.log('change'); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access | ||
setControlledInputValue(e.detail.value); | ||
}} | ||
/> | ||
|
||
<Button name="submit" value="haha" htmlType="submit"> | ||
submit | ||
</Button> | ||
<Button htmlType="reset">reset</Button> | ||
<button type="submit">native submit</button> | ||
<Button | ||
onClick={() => { | ||
setControlledInputValue('123'); | ||
}} | ||
> | ||
change the value of controlled input to '123' | ||
</Button> | ||
</form> | ||
</div> | ||
); | ||
} |
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,22 @@ | ||
/** | ||
* title: Rows | ||
* description: 使用 `rows` 属性更改显示的文本行数,默认为 4。 | ||
*/ | ||
|
||
import { Textarea } from '@banana-ui/react'; | ||
|
||
export default function Size() { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '16px', | ||
}} | ||
> | ||
<Textarea /> | ||
<Textarea rows={3} /> | ||
<Textarea rows={2} /> | ||
</div> | ||
); | ||
} |
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,22 @@ | ||
/** | ||
* title: 尺寸 | ||
* description: 通过设置`size`属性可以控制输入框的大小,可选值为`small`、`medium`和 `large`;高度分别为`24px`、`32px`和 `40px`。默认为`medium`。 | ||
*/ | ||
|
||
import { Textarea } from '@banana-ui/react'; | ||
|
||
export default function Size() { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '16px', | ||
}} | ||
> | ||
<Textarea size="large" rows={1} placeholder="Large size" /> | ||
<Textarea size="medium" rows={1} placeholder="Medium size" /> | ||
<Textarea size="small" rows={1} placeholder="Small size" /> | ||
</div> | ||
); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BTextarea } from '@banana-ui/banana'; | ||
import { createComponent } from '@lit-labs/react'; | ||
import * as React from 'react'; | ||
|
||
const events = { onChange: 'change' }; | ||
|
||
export const Textarea = createComponent({ | ||
tagName: 'b-textarea', | ||
react: React, | ||
elementClass: BTextarea, | ||
events, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { css, unsafeCSS } from 'lit'; | ||
import componentStyles from '../../styles/components.styles'; | ||
import { Variables as Var } from '../../styles/global-variables'; | ||
|
||
export default [ | ||
componentStyles, | ||
css` | ||
:host { | ||
display: block; | ||
width: 100%; | ||
} | ||
.textarea__wrapper { | ||
display: flex; | ||
align-items: center; | ||
position: relative; | ||
width: 100%; | ||
border: var(--banana-input-border-width, ${unsafeCSS(Var.InputBorderWidth)}) solid | ||
var(--banana-input-border-color, ${unsafeCSS(Var.InputBorderColor)}); | ||
font-family: var(--banana-input-font-family, ${unsafeCSS(Var.InputFontFamily)}); | ||
transition: all ${unsafeCSS(Var.TransitionFast)}; | ||
line-height: 1.5; | ||
color: fieldtext; | ||
background-color: var(--banana-input-background-color, ${unsafeCSS(Var.InputBackgroundColor)}); | ||
} | ||
.textarea__wrapper:hover:not(.textarea__wrapper--disabled) { | ||
border-color: var(--banana-input-border-hover-color, ${unsafeCSS(Var.InputBorderHoverColor)}); | ||
} | ||
.textarea__wrapper.textarea__wrapper--focusing:not(.textarea__wrapper--disabled) { | ||
border-color: var(--banana-input-border-focus-color, ${unsafeCSS(Var.ColorPrimary)}); | ||
box-shadow: var(--banana-input-box-shadow-focus, ${unsafeCSS(Var.InputBoxShadowFocus)}); | ||
} | ||
.textarea__wrapper--small { | ||
font-size: var(--banana-input-font-size-small, ${unsafeCSS(Var.InputFontSizeSmall)}); | ||
min-height: var(--banana-input-height-small, ${unsafeCSS(Var.InputHeightSmall)}); | ||
border-radius: var(--banana-input-border-radius-small, ${unsafeCSS(Var.InputBorderRadiusSmall)}); | ||
} | ||
.textarea__wrapper--small .textarea { | ||
padding: var(--banana-input-padding-small, ${unsafeCSS(Var.InputPaddingSmall)}); | ||
} | ||
.textarea__wrapper--medium { | ||
font-size: var(--banana-input-font-size-medium, ${unsafeCSS(Var.InputFontSizeMedium)}); | ||
min-height: var(--banana-input-height-medium, ${unsafeCSS(Var.InputHeightMedium)}); | ||
border-radius: var(--banana-input-border-radius-medium, ${unsafeCSS(Var.InputBorderRadiusMedium)}); | ||
} | ||
.textarea__wrapper--medium .textarea { | ||
padding: var(--banana-input-padding-medium, ${unsafeCSS(Var.InputPaddingMedium)}); | ||
} | ||
.textarea__wrapper--large { | ||
font-size: var(--banana-input-font-size-large, ${unsafeCSS(Var.InputFontSizeLarge)}); | ||
min-height: var(--banana-input-height-large, ${unsafeCSS(Var.InputHeightLarge)}); | ||
border-radius: var(--banana-input-border-radius-large, ${unsafeCSS(Var.InputBorderRadiusLarge)}); | ||
} | ||
.textarea__wrapper--large .textarea { | ||
padding: var(--banana-input-padding-large, ${unsafeCSS(Var.InputPaddingLarge)}); | ||
} | ||
.textarea__wrapper--disabled { | ||
color: var(--banana-input-disabled-color, ${unsafeCSS(Var.InputDisabledColor)}); | ||
background-color: var(--banana-input-disabled-background-color, ${unsafeCSS(Var.InputDisabledBackgroundColor)}); | ||
border-color: var(--banana-input-disabled-border-color, ${unsafeCSS(Var.InputDisabledBorderColor)}); | ||
cursor: not-allowed; | ||
} | ||
.textarea { | ||
flex: 1 1 auto; | ||
padding: 0; | ||
margin: 0; | ||
font-size: inherit; | ||
line-height: inherit; | ||
font-family: inherit; | ||
font-weight: inherit; | ||
border: none; | ||
outline: none; | ||
box-shadow: none; | ||
cursor: inherit; | ||
appearance: none; | ||
} | ||
.textarea::-webkit-search-decoration, | ||
.textarea::-webkit-search-cancel-button, | ||
.textarea::-webkit-search-results-button, | ||
.textarea::-webkit-search-results-decoration { | ||
-webkit-appearance: none; | ||
} | ||
.textarea::placeholder { | ||
user-select: none; | ||
-webkit-user-select: none; | ||
} | ||
.textarea:focus { | ||
outline: none; | ||
} | ||
.textarea:-webkit-autofill, | ||
.textarea:-webkit-autofill:hover, | ||
.textarea:-webkit-autofill:focus, | ||
.textarea:-webkit-autofill:active { | ||
color: inherit; | ||
background-color: transparent; | ||
/* Override the default styles of the autofill input. */ | ||
box-shadow: 0 0 0 var(--banana-input-height-large, ${unsafeCSS(Var.InputHeightLarge)}) | ||
var(--banana-input-background-color, ${unsafeCSS(Var.InputBackgroundColor)}) inset !important; | ||
} | ||
`, | ||
]; |
Oops, something went wrong.