-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add note prop into TextArea and withCounter hoc
- Loading branch information
Sergey Zveroboev
committed
Aug 14, 2023
1 parent
5067bca
commit 75037a5
Showing
8 changed files
with
124 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea | ||
.vscode | ||
.history | ||
.DS_Store | ||
*.log | ||
|
||
|
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
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,34 @@ | ||
import React from 'react'; | ||
|
||
import {Text} from '../../../Text'; | ||
import {getComponentName} from '../../../utils/getComponentName'; | ||
import {TextArea, TextAreaProps} from '../TextArea'; | ||
|
||
export interface WithCounterProps { | ||
counterMax: number; | ||
} | ||
|
||
export function withCounter( | ||
TextAreaComponents: React.ComponentType<TextAreaProps>, | ||
): React.ComponentType<Omit<TextAreaProps, 'note'> & WithCounterProps> { | ||
const componentName = getComponentName(TextAreaComponents); | ||
const displayName = `withCounter(${componentName})`; | ||
|
||
return class extends React.Component<Omit<TextAreaProps, 'note'> & WithCounterProps> { | ||
static displayName = displayName; | ||
|
||
render() { | ||
return <TextArea {...this.props} note={this.renderNote()} />; | ||
} | ||
|
||
private renderNote() { | ||
const {value, counterMax} = this.props; | ||
|
||
return ( | ||
<Text color="secondary"> | ||
{counterMax - (value?.length ?? 0)}/{counterMax} | ||
</Text> | ||
); | ||
} | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export {TextArea} from './TextArea'; | ||
export type {TextAreaProps, TextAreaPin, TextAreaSize, TextAreaView} from './TextArea'; | ||
|
||
export {withCounter} from './hoc/withCounter'; | ||
export type {WithCounterProps} from './hoc/withCounter'; |