Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

FEAT: Create TagsInput component #177

Merged
merged 1 commit into from
Jan 15, 2019
Merged

FEAT: Create TagsInput component #177

merged 1 commit into from
Jan 15, 2019

Conversation

FilipMessa
Copy link
Contributor

No description provided.

@FilipMessa FilipMessa force-pushed the placePicker/tags-input branch 10 times, most recently from 34cc212 to 18de489 Compare January 8, 2019 15:08
@netlify
Copy link

netlify bot commented Jan 9, 2019

Deploy preview for kiwicom-universal-components ready!

Built with commit 0bc5c1c

https://deploy-preview-177--kiwicom-universal-components.netlify.com

@FilipMessa FilipMessa force-pushed the placePicker/tags-input branch 3 times, most recently from 4ffe572 to 33c3f73 Compare January 9, 2019 16:25
@FilipMessa FilipMessa changed the title WIP: Create TagsInput component FEAT: Create TagsInput component Jan 9, 2019
@FilipMessa
Copy link
Contributor Author

Finally, the MR is ready, it was tricky find way how to handle it with one code because of differences between web input and native input.
Especially on the web input element, is no easy change width base on a count of characters.

I created the hidden element (sizer) and based on it I count the input width. It is kind of hacky but I can't find a better solution.

So pls check it properly I spent a lot of the time on it so maby I missed something. Thanks

src/TagsInput/components/Label.js Outdated Show resolved Hide resolved
src/TagsInput/components/IconButton.js Outdated Show resolved Hide resolved
src/TagsInput/TagsInput.js Outdated Show resolved Hide resolved
@FilipMessa
Copy link
Contributor Author

I realize that there is the issue in test
screen shot 2019-01-11 at 14 05 38

@FilipMessa
Copy link
Contributor Author

Issue with test fixed

@@ -1085,6 +1106,13 @@
5C04BEA7D09C4DC4B05BB661 /* Roboto-MediumItalic.ttf in Resources */,
90151CF9607749A28BB60FDD /* Roboto-Regular.ttf in Resources */,
F9A904A78F284EE6989903AF /* orbit-icons.ttf in Resources */,
D88FDFB084E3435482711AB1 /* orbit-icons.ttf in Resources */,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is related to your recent tests fix update? I'm just wondering why all fonts were added to xcode project for a second time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, could you try to remove this file from the commit and see if you can still run the storybook?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on it

src/Badge/Badge.js Outdated Show resolved Hide resolved
};

class TagInput extends React.Component<Props, State> {
inputRef: any; // @TODO find a way how to type this properly, the issue with mixing react and react-native
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are using react > v16.3, so that could be helpful: https://reactjs.org/docs/refs-and-the-dom.html#creating-refs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the first approach what I tried but, it didn't work.

if (containerWidth && width) {
return containerWidth - width;
}
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always been told that it was better to return null than undefined, as null meant value could not be set instead of being undefined.

Copy link
Contributor Author

@FilipMessa FilipMessa Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, just there is another side of the coin, https://youtu.be/rhV6hlL_wMc?t=1326 😄
But I will change it as you suggest.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reference, I think he's got some very valid points. If we feel strongly about this, then we should enforce it.

getWidth = (width: ?number) => {
const { containerWidth } = this.state;
if (containerWidth && width) {
return containerWidth - width;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you get a negative result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't happen I suppose, in the current use-case.
It can be zero but not negative.

}

return (
<View>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this wrapping necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, I need it for the web, if I don't use it break how overflow works

style={[styles.container, styles.row, { maxWidth }]}
showsHorizontalScrollIndicator={false}
contentContainerStyle={{
alignItems: 'center',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract the style?

Copy link
Contributor Author

@FilipMessa FilipMessa Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried before but I get back this flow error,
screen shot 2019-01-11 at 16 01 13

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we might need to address how our StyleSheet.create works, compared to RN's native one. Or use StyleSheet.create from RN implementation.
@tbergq What do you think about this issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I played with the flow for while but without success so I decided to use StyleSheet.create from RN implementation.

// $FlowFixMe property focus is missing in object type
Platform.OS === 'web' && this.inputRef.current.focus();

if (onClearPress) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can even do onClearPress?.().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I have been learned something new.

fontSize={fontSize}
disabled={disabled}
minWidth={MIN_WIDTH}
maxWidth={this.getWidth(MIN_WIDTH)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the naming could be improved here: why is maxWidth linked to MIN_WIDTH?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of in the getWidth method I subtract passing param, in this case, MIN_WIDTH from the width of the whole container.
And because TagsContainer minWidth is also MIN_WIDTH, maxWidth of the InputField must respect this.

I will try to improve it to something more readable.

|};

type State = {|
componentWidth: number | string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
componentWidth: number | string,
componentWidth: number | 'auto',

That's the only string that's allowed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot see it added now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

},
input: {
web: {
outline: 'none',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a problem for accessibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've improved website design. An inspiration I took from kiwi.com

Summary: Created TagsInput component. Added tests and Storybook's stories for the TagsInput.
@RobinCsl RobinCsl merged commit d5b46e2 into master Jan 15, 2019
@RobinCsl RobinCsl deleted the placePicker/tags-input branch January 15, 2019 12:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants