-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/chips input v2 #1490
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
Merged
Merged
Feat/chips input v2 #1490
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
0468453
index.js -> index.tsx
mendyEdri ed9235c
added chips-input presenter
mendyEdri dec823a
set disable color logic code
mendyEdri 56f253e
demo screen changes
mendyEdri 6a66baf
migrate to typescript, added new chip usage supporting code
mendyEdri 784001b
Merge branch 'master' into feat/chips-input-v2
mendyEdri eefbbc2
Fixed namings on tests
mendyEdri d4487db
typings
mendyEdri 3cc26e2
build ts
mendyEdri 3f7f91a
Merge branch 'master' into feat/chips-input-v2
mendyEdri 6dbb8fa
build ts
mendyEdri 1c8e43a
remove old typings
mendyEdri 17944ea
rename chipsProps to chips
mendyEdri a6c176e
export new typings
mendyEdri 3cf3ced
renaming
mendyEdri 93123d0
export from generatedTypes
mendyEdri 01ca150
fixed export path
mendyEdri a44e00e
added key for performance
mendyEdri fbffefa
Merge branch 'master' into feat/chips-input-v2
mendyEdri 9585e78
rename method
mendyEdri 650e717
missing import
mendyEdri 38c6608
Merge branch 'master' into feat/chips-input-v2
mendyEdri d8537cf
rename method name in demo screen
mendyEdri ce1915a
ChipsInputScreen.js -> ChipsInputScreen.tsx
mendyEdri 9fb87b1
migrate ChipsInputScreen to typescript
mendyEdri 61689ca
add missing export prop
mendyEdri e098955
change spread position to override the default labelStyle
mendyEdri 85aa6f2
Export chipsProps
mendyEdri 532f470
Kept old usage for later reference, export new prop that contains `va…
mendyEdri 71b9449
added deprecation note
mendyEdri 2bb2ffa
use ChipsInputChipProp to have `invalid` prop in this type
mendyEdri d04fb89
Extract inline style
mendyEdri bfb8309
change array decleration to transpile with typescript
mendyEdri a6f9242
PR Comments
mendyEdri 5d385b8
removed ref inline function
mendyEdri e0f0db0
move code inside other function
mendyEdri 3497126
make CI great again
mendyEdri d5b3bc6
Update src/components/chipsInput/index.tsx
Inbal-Tish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -11,7 +11,7 @@ import {TextField} from '../inputs'; | |
import View from '../view'; | ||
import TouchableOpacity from '../touchableOpacity'; | ||
import Text from '../text'; | ||
import Chip, {ChipProps as ExternalChipProp} from '../chip'; | ||
import Chip, {ChipProps} from '../chip'; | ||
import {getValidationBasedColor, getCounterTextColor, getCounterText, getChipDismissColor, isDisabled} from './Presenter'; | ||
import {TextFieldProps} from '../../../typings/components/Inputs'; | ||
|
||
|
@@ -20,7 +20,7 @@ import {TextFieldProps} from '../../../typings/components/Inputs'; | |
// TODO: add notes to Docs about the Android fix for onKeyPress | ||
|
||
type ChipType = string | boolean | any; | ||
export type ChipProps = ExternalChipProp & {invalid?: boolean} | ||
export type ChipsInputChipProps = ChipProps & {invalid?: boolean} | ||
|
||
export type ChipsInputProps = TypographyModifiers & TextFieldProps & { | ||
/** | ||
|
@@ -30,29 +30,29 @@ export type ChipsInputProps = TypographyModifiers & TextFieldProps & { | |
/** | ||
* list of tags. can be string boolean or custom object when implementing getLabel | ||
*/ | ||
chips?: Array<ChipProps>; | ||
chips?: Array<ChipsInputChipProps>; | ||
/** | ||
* Style your chips | ||
*/ | ||
defaultChipProps?: ChipProps; | ||
defaultChipProps?: ChipsInputChipProps; | ||
/** | ||
* callback for extracting the label out of the tag item | ||
*/ | ||
getLabel?: (tag: ChipType) => any; | ||
Inbal-Tish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* callback for custom rendering tag item | ||
* DEPRECATED: use chips instead. callback for custom rendering tag item | ||
*/ | ||
renderTag?: (tag: ChipType, index: number, shouldMarkTag: boolean, label: string) => React.ReactElement; | ||
/** | ||
* callback for onChangeTags event | ||
*/ | ||
onChangeTags?: () => void; | ||
/** | ||
* callback for creating new tag out of input value (good for composing tag object) | ||
* DEPRECATED: use chips instead. callback for creating new tag out of input value (good for composing tag object) | ||
*/ | ||
onCreateTag?: (value: any) => void; | ||
/** | ||
* callback for when pressing a tag in the following format (tagIndex, markedTagIndex) => {...} | ||
* DEPRECATED: use chips instead. callback for when pressing a tag in the following format (tagIndex, markedTagIndex) => {...} | ||
*/ | ||
onTagPress?: (index: number, toRemove?: number) => void; | ||
/** | ||
|
@@ -254,29 +254,34 @@ class ChipsInput extends Component<OwnProps, State> { | |
return isLastTagMarked; | ||
} | ||
|
||
removeTag = () => { | ||
const {value, chips, chipIndexToRemove} = this.state; | ||
const tagsCount = _.size(chips); | ||
const hasNoValue = _.isEmpty(value); | ||
const hasTags = tagsCount > 0; | ||
|
||
if (hasNoValue && hasTags && _.isUndefined(chipIndexToRemove)) { | ||
this.setState({ | ||
chipIndexToRemove: tagsCount - 1 | ||
}); | ||
} else if (!_.isUndefined(chipIndexToRemove)) { | ||
this.removeMarkedTag(); | ||
} | ||
} | ||
|
||
onKeyPress = (event: NativeSyntheticEvent<TextInputKeyPressEventData>) => { | ||
_.invoke(this.props, 'onKeyPress', event); | ||
|
||
const {disableTagRemoval} = this.props; | ||
Inbal-Tish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (disableTagRemoval) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this logic should move to removeTag method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any changes here... |
||
return; | ||
} | ||
|
||
const {value, chips, chipIndexToRemove} = this.state; | ||
const tagsCount = _.size(chips); | ||
|
||
const keyCode = _.get(event, 'nativeEvent.key'); | ||
const hasNoValue = _.isEmpty(value); | ||
const pressedBackspace = keyCode === Constants.backspaceKey; | ||
const hasTags = tagsCount > 0; | ||
|
||
if (pressedBackspace) { | ||
if (hasNoValue && hasTags && _.isUndefined(chipIndexToRemove)) { | ||
this.setState({ | ||
chipIndexToRemove: tagsCount - 1 | ||
}); | ||
} else if (!_.isUndefined(chipIndexToRemove)) { | ||
this.removeMarkedTag(); | ||
} | ||
this.removeTag(); | ||
} | ||
} | ||
|
||
|
@@ -300,15 +305,15 @@ class ChipsInput extends Component<OwnProps, State> { | |
this.setState({isFocused: false}); | ||
} | ||
|
||
renderLabel(tag: ChipType, shouldMarkTag: boolean) { | ||
renderLabel(tag: ChipType, shouldMarkTag: boolean) { | ||
const {typography} = this.props.modifiers; | ||
const label = this.getLabel(tag); | ||
|
||
return ( | ||
<View row centerV> | ||
{shouldMarkTag && ( | ||
<Image | ||
style={[styles.removeIcon, tag.invalid && styles.invalidTagRemoveIcon, styles.basicTagStyle]} | ||
style={[styles.removeIcon, tag.invalid && styles.basicTagStyle && styles.invalidTagRemoveIcon]} | ||
source={Assets.icons.x} | ||
/>) | ||
} | ||
|
@@ -362,7 +367,7 @@ class ChipsInput extends Component<OwnProps, State> { | |
const selected = chipIndexToRemove === index; | ||
const dismissColor = getChipDismissColor(chip, selected, defaultChipProps); | ||
return ( | ||
<View center flexS> | ||
<View center flexS marginT-2 marginB-2> | ||
<Chip | ||
key={index} | ||
containerStyle={[styles.tag, chip.invalid && styles.invalidTag]} | ||
|
@@ -466,7 +471,7 @@ class ChipsInput extends Component<OwnProps, State> { | |
onBlur={this.onBlur} | ||
hideUnderline | ||
selectionColor={isLastTagMarked ? 'transparent' : selectionColor} | ||
style={[inputStyle, {textAlignVertical: 'center'}]} | ||
style={[inputStyle, styles.alignTextCenter]} | ||
containerStyle={{flexGrow: 0}} | ||
collapsable={false} | ||
accessibilityHint={ | ||
|
@@ -583,7 +588,7 @@ const styles = StyleSheet.create({ | |
borderColor: Colors.red10 | ||
}, | ||
tagMarked: { | ||
backgroundColor: Colors.dark10 | ||
backgroundColor: Colors.grey10 | ||
}, | ||
dismissIconStyle: { | ||
width: 10, | ||
|
@@ -615,5 +620,8 @@ const styles = StyleSheet.create({ | |
alignSelf: 'flex-end', | ||
height: Typography.text80?.lineHeight, | ||
...Typography.text80 | ||
}, | ||
alignTextCenter: { | ||
textAlignVertical: 'center' | ||
} | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.