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: implement highlightedtext component #1864

Merged
merged 8 commits into from
Oct 5, 2020

Conversation

amontalvof
Copy link
Collaborator

fix: #1847

Changes proposed in this PR:

@nexxtway/react-rainbow

@commit-lint
Copy link

commit-lint bot commented Sep 26, 2020

Features

  • implement highlightedtext component (78d54eb)
  • fixed props and test in the component highlightedtext (f82687b)
  • added isInline prop (92080df)
  • fixed proptypes and description (8757dff)

Contributors

@amontalvof, @TahimiLeonBravo, @LeandroTorresSicilia

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

src/components/HighlightedText/index.js Outdated Show resolved Hide resolved
src/components/HighlightedText/index.js Outdated Show resolved Hide resolved
src/components/HighlightedText/index.js Show resolved Hide resolved
import styled from 'styled-components';
import attachThemeAttrs from '../../../styles/helpers/attachThemeAttrs';

// eslint-disable-next-line import/prefer-default-export
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove the eslint exception

import attachThemeAttrs from '../../../styles/helpers/attachThemeAttrs';

// eslint-disable-next-line import/prefer-default-export
export const HighlightedContainer = attachThemeAttrs(styled.div)`
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we aren't adding some styles to the container, we would not create a styled for that

@TahimiLeonBravo
Copy link
Collaborator

@amontalvof also we need to export the new components on the ts global index file

src/components/HighlightedText/readme.md Outdated Show resolved Hide resolved
src/components/HighlightedText/readme.md Outdated Show resolved Hide resolved
src/components/HighlightedText/readme.md Outdated Show resolved Hide resolved
src/components/HighlightedText/readme.md Outdated Show resolved Hide resolved
src/components/HighlightedText/index.d.ts Outdated Show resolved Hide resolved
.html()
.includes('Honeycrisp'),
).toBe(true);
});

Choose a reason for hiding this comment

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

we should change these tests to make clearer the difference between a hit and normal text

Copy link
Contributor

Choose a reason for hiding this comment

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

this second test you can delete the first the third test all the code

##### This example shows the style that is applied by default to the component.
```js
import React, { useState } from 'react';
import { HighlightedText } from 'react-rainbow-components';
Copy link
Contributor

Choose a reason for hiding this comment

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

identation

Comment on lines 15 to 26
{
"value" : "Apples come in several ",
"type" : "text"
},
{
"value" : "varieties",
"type" : "hit"
},
{
"value" : ", including Fuji, Granny Smith, and Honeycrisp.",
"type" : "text"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

# HighlightedText base
##### This example shows the style that is applied by default to the component.
```js
import React, { useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

useState is not used in the example

##### This example shows the component when custom styles are applied to it.

```js
import React, { useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

same before

```js
import React, { useState } from 'react';
import styled from 'styled-components';
import { HighlightedText } from 'react-rainbow-components';
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

Comment on lines 49 to 60
{
"value" : "Apples come in several ",
"type" : "text"
},
{
"value" : "varieties",
"type" : "hit"
},
{
"value" : ", including Fuji, Granny Smith, and Honeycrisp.",
"type" : "text"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

Comment on lines 63 to 72
const TextContainer = styled.span`
color: gray;
font-size: 1rem;
`;

const HitContainer = styled.span`
background-color: #00a3dc;
color: #fff;
font-size: 1rem;
`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to use the theme colors for this example

.html()
.includes('Honeycrisp'),
).toBe(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

this second test you can delete the first the third test all the code

Comment on lines 24 to 41
expect(
container
.at(0)
.html()
.includes('Apples'),
).toBe(true);
expect(
container
.at(1)
.html()
.includes('varieties'),
).toBe(true);
expect(
container
.at(2)
.html()
.includes('Honeycrisp'),
).toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be cleaner like this

const component = mount(<HighlightedText parts={parts} />);
        const container = component.find('span');
        expect(container.length).toBe(3);
        parts.forEach(({ value }, index) => {
            expect(
                container
                    .at(index)
                    .html()
                    .includes(value),
            ).toBe(true);
        });

`;

// eslint-disable-next-line react/prop-types
const hitComponent = ({ children }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

capitalize the first letter HitComponent

@@ -0,0 +1,104 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

HighlightedText.spec.js change to highlightedText.spec.js

export interface HighlightedText extends BaseProps {
hitComponent?: ComponentType<{ children?: string }>;
textComponent?: ComponentType<{ children?: string }>;
part?: Part[];

Choose a reason for hiding this comment

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

it is parts:
parts?: Part[];

* HighlightedText is a component that highlights a part of a text.
*/

function HighlightedText(props) {

Choose a reason for hiding this comment

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

when using function declaration you can export directly here like:
export default function HighlightedText(props) {...

maxWidth:"700px",
textAlign:"center",
padding:"20px",
margin:"auto",

Choose a reason for hiding this comment

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

use single quotes and add a space after the : symbol like:
maxWidth: '700px',

export default HighlightedText;

HighlightedText.propTypes = {
/** The class of the component. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to be consistent, we should use the same description that we use in other components
A CSS class for the outer element, in addition to the component's base classes.

const finalTextContainer = textComponent || DefaultTextContainer;

return (
<p className={className} style={style}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to add a new prop isInline in order to change the p element by a span element, also we should add a useful description for this prop

Copy link
Collaborator

Choose a reason for hiding this comment

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

add a new example using the isInline prop

@codeclimate
Copy link

codeclimate bot commented Oct 5, 2020

Code Climate has analyzed commit 45634f4 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

View more on Code Climate.

@LeandroTorresSicilia LeandroTorresSicilia merged commit 9060d29 into master Oct 5, 2020
@LeandroTorresSicilia LeandroTorresSicilia deleted the implement-highlightedtext-component branch October 5, 2020 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: implement HighlightedText component
4 participants