Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: including disabled prop #3

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@ Textarea component auto resizable. It grows when text is bigger
npm install react-native-textarea-resizable
```

or

```sh
yarn add react-native-textarea-resizable
```

## Usage

```js
import { multiply } from 'react-native-textarea-resizable';
import TextAreaResizable from 'react-native-textarea-resizable'

// ...

const result = await multiply(3, 7);
<TextAreaResizable />
```

### Props

| Name | Description | Type | Default | Required? |
| -------- | ----------- | ------- | ------- | --------- |
| minRows | | number | 1 | false |
| maxRows | | number | 6 | false |
| disabled | | boolean | false | false |

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-textarea-resizable",
"version": "1.0.0",
"version": "1.0.1",
"description": "Textarea component auto resizable. It grows when text is bigger",
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
Expand Down
10 changes: 8 additions & 2 deletions src/components/TextAreaResizable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'

Check failure on line 1 in src/components/TextAreaResizable/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Run autofix to sort these imports!
import { Platform, TextInput, type NativeSyntheticEvent, type TextInputContentSizeChangeEventData, type TextInputProps } from 'react-native'

const TEXTAREA_LINE_HEIGHT = 18
Expand All @@ -6,10 +6,11 @@
export interface TextAreaResizableProps extends TextInputProps {
minRows?: number
maxRows?: number
disabled?: boolean
}

export const TextAreaResizable = (props: TextAreaResizableProps) => {
const { minRows = 1, maxRows = 6 } = props
const { minRows = 1, maxRows = 6, disabled = false } = props

const [value, setValue] = useState('')
const [rows, setRows] = useState(2)
Expand Down Expand Up @@ -64,12 +65,15 @@
setMinHeight(rows * TEXTAREA_LINE_HEIGHT)
}, [rows])

const disabledCursor = disabled ? { cursor: 'not-allowed' } : {}

return (
<TextInput
style={{
...(props.style as Object),
padding: 4,
minHeight
minHeight,
...disabledCursor
}}
multiline={true}
numberOfLines={Platform.OS === 'web' ? Math.floor(rows) : Math.ceil(rows)}
Expand All @@ -78,6 +82,8 @@
textAlignVertical="top"
onChange={handleChange}
onContentSizeChange={handleContentSizeChange}
editable={props.editable ?? !disabled}
placeholderTextColor={props?.placeholderTextColor ?? 'lightgray'}
{...props}
/>
)
Expand Down
Loading