Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

refactor(*): replace style props with CSS classNames - #320 #387

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

98lenvi
Copy link
Contributor

@98lenvi 98lenvi commented Apr 17, 2020

Signed-off-by: Lenvin Gonsalves lenvin@oykuapp.com

Issue #320

The goal is to remove all style props in favor of CSS class names.
One pro I can think of is the user will have more flexibility on the appearance of the component,

Changes

  • The following will be done for each component

    • Removing the reliance on user passed props for styling in the styled-components.
    • Not passing these styling props down.
    • Removing them from propTypes as well.
    • Creating a new file customStyles.js which will have the classNames of the components.
    • The above file will export a styled-component div which will wrap around the main component.
  • Will be done for the following components

  • ErrorLogger

  • ContractEditor (already done during slate migration to 0.57)

  • Navigation

  • TemplateLibrary

Flags

  • I have done it for the ErrorLogger component, Once the maintainers feel the approach is right, I will perform the above for the other components as well.
  • Documentation must be updated.
  • Storybook must be updated.
  • Tests must be updated. Currently, snapshots are causing tests to fail.

Related Issues

  • Issue #320

@98lenvi
Copy link
Contributor Author

98lenvi commented Apr 18, 2020

@arteevraina. Tagging you here so you can get notified when this PR gets merged.

Copy link
Member

@jolanglinais jolanglinais left a comment

Choose a reason for hiding this comment

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

Left some comments and questions.

};

const shortMessageProps = {
onClick: handleClickSpecError,
shortMessage: errorProps.ERROR_SHORT_MESSAGE,
};

const fullMessageProps = {
Copy link
Member

Choose a reason for hiding this comment

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

fullMessageProps isn't needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback

};

return (
<SC.ErrorComponent {...componentProps}>
<SC.ErrorComponent className={'errorComponent'}>
Copy link
Member

Choose a reason for hiding this comment

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

Do all these need to be className="..." instead of className={'...'}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they need to be className="...". I'll change them!

Comment on lines 1 to 24
import styled from 'styled-components';

export const CustomStylesWrapper = styled.div`
.errorHeader{
};
.errorDisplay{
};
.errorBarArrow{
};
.errorComponent{
};
.errorFile{
};
.errorArrowDivExpanded{
};
.errorArrowDivCollapsed{
};
.errorType{
};
.errorShortMessage{
};
.errorFullMessage{
};
`
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain more why these custom style wrappers help / what they do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I first added them they meant sense to me as it is one of the best way for me to added custom CSS style to elements. But now it doesn't seem required at all since the user will be adding his/her own wrapper around the component or style document. Sorry for the inconvenience, I'll be removing it!

z-index: ${props => props.zIndexInput || 'auto'};
background-color: #1E2D53;
box-shadow: 0 -2px 20px 0 rgba(20,31,60,0.65);
z-index: auto;
Copy link
Member

Choose a reason for hiding this comment

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

auto is the default value for z-index, so these can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback

width: ${props => props.navWidth || 'inherit'};
background-color: ${props => props.backgroundColor || 'inherit'};
position: static;
top: auto;
Copy link
Member

Choose a reason for hiding this comment

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

auto is the default value for top, so this can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback

Copy link
Member

@DianaLease DianaLease left a comment

Choose a reason for hiding this comment

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

Can we also give the highest parent of each component a common class name? maybe ciceroUI? That way we can easily target specific elements within the ciceroUI parent.

I'd also like an explanation of the CustomStylesWrapper that you've added for each component. Thanks!

@98lenvi
Copy link
Contributor Author

98lenvi commented Apr 24, 2020

Can we also give the highest parent of each component a common class name? maybe ciceroUI? That way we can easily target specific elements within the ciceroUI parent.

I'd also like an explanation of the CustomStylesWrapper that you've added for each component. Thanks!

@DianaLease
Yes I'll work on adding a common className. Thank you for the feedback

When I first added them they meant sense to me as it is one of the best way for me to added custom CSS style to elements. But now it doesn't seem required at all since the user will be adding his/her own wrapper around the component or style document. Sorry for the inconvenience, I'll be removing it!

@98lenvi 98lenvi force-pushed the 98lenvi/i320/style_props_to_classname branch from 69ad521 to 2c9fd4e Compare April 24, 2020 18:38

return (
<TemplatesWrapper>
<TemplatesWrapper className='ciceroUI'>
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this class name be more specific?

Copy link
Contributor Author

@98lenvi 98lenvi Apr 25, 2020

Choose a reason for hiding this comment

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

Keeping @DianaLease comment in mind, do I need to add specific class names?

Copy link
Member

Choose a reason for hiding this comment

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

I think @DianaLease is correct, so this could be left.

@DianaLease
Copy link
Member

@irmerk I think it makes sense to have a common className at the top level for all cicero-ui components. Like how semantic-ui adds ui as a class name to their parent components. That way when we apply styles we can limit those styles to elements within the .ciceroUI hierarchy.

Copy link
Member

@jolanglinais jolanglinais left a comment

Choose a reason for hiding this comment

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

Made some different suggestions to keep the className more consistent.

{props.addTemp
&& <NewClauseComponent addTempInput={props.addTemp} />}
</Functionality>
<TemplateCards tempsHeight={libraryProps.TEMPLATES_HEIGHT} >
<TemplateCards className='templateCardsDiv' >
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could be 'templateLibraryCardsWrapper'

src/TemplateLibrary/index.js Outdated Show resolved Hide resolved

return (
<TemplatesWrapper>
<TemplatesWrapper className='ciceroUI'>
Copy link
Member

Choose a reason for hiding this comment

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

I think @DianaLease is correct, so this could be left.

src/TemplateLibrary/Components/TemplateCard.js Outdated Show resolved Hide resolved
src/TemplateLibrary/Components/TemplateCard.js Outdated Show resolved Hide resolved
src/ErrorLogger/Error.js Outdated Show resolved Hide resolved
src/ErrorLogger/Error.js Outdated Show resolved Hide resolved
src/ErrorLogger/Error.js Outdated Show resolved Hide resolved
src/Navigation/ComponentSwitch.js Outdated Show resolved Hide resolved
NAVIGATION
</SC.Navigation>
<SC.Files {...fileProps}>
<SC.Files {...fileProps} className={props.navState === 'FILES'?'navTitleActive':'navTitleInactive'}>
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could be 'navigationFilesActive' and 'navigationFilesInactive'

@jolanglinais
Copy link
Member

Following up on this @98lenvi, need any assistance?

@98lenvi
Copy link
Contributor Author

98lenvi commented May 4, 2020

@irmerk, actually my laptop's hard drive died a week ago. I'm waiting for the new drive to arrive (most probably tonight or tomorrow morning). I'll do the changes tomorrow morning!
Thanks for asking!

98lenvi added 8 commits May 5, 2020 15:48
… - i320

Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
…- i320

Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
…ames - i320

Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
Signed-off-by: Lenvin Gonsalves <lenvin@oykuapp.com>
@98lenvi 98lenvi force-pushed the 98lenvi/i320/style_props_to_classname branch from 42a5597 to 3b7c7ea Compare May 5, 2020 10:33
@98lenvi 98lenvi requested a review from jolanglinais May 5, 2020 10:34
Copy link
Member

@jolanglinais jolanglinais left a comment

Choose a reason for hiding this comment

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

A few more remaining changes.

{props.addTemp
&& <NewClauseComponent addTempInput={props.addTemp} />}
</Functionality>
{filtered && filtered.length ? <TemplateCards tempsHeight={libraryProps.TEMPLATES_HEIGHT} >
{filtered && filtered.length ? <TemplateCards className={'templateCardsDiv'} >
{_.sortBy(filtered, ['name']).map(t => (
<TemplateCard
key={t.uri}
addToCont={props.addToCont}
template={t}
handleViewTemplate={props.handleViewTemplate}
className="templateCard"
Copy link
Member

Choose a reason for hiding this comment

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

I believe this className="templateCard" can be removed, it's redundant on the className='templateLibraryCard' in src/TemplateLibrary/Components/TemplateCard.js

<SC.ArrowDiv {...errorArrowProps} />
<SC.ErrorFile {...fileProps} onClick={() => errorNav(error)} >
<SC.ArrowDiv {...errorArrowProps} className={specErrorVisible?'errorLoggerErrorArrowExpanded':'errorLoggerErrorArrowCollapsed'}/>
<SC.ErrorFile onClick={() => errorNav(error)} className='errorLoggerError'>
Copy link
Member

Choose a reason for hiding this comment

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

'errorLoggerErrorFile'

NAVIGATION
</SC.Navigation>
<SC.Files {...fileProps}>
<SC.Files {...fileProps} className={props.navState === 'FILES'?'navigationTitleActive':'navigationTitleInactive'}>
Copy link
Member

Choose a reason for hiding this comment

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

'navigationFilesActive' and 'navigationFilesInactive'

@jolanglinais
Copy link
Member

Also note the proposed changes in #411

@jolanglinais
Copy link
Member

We're migrating this repository into web-components the next couple of days, so I'll be closing this soon and you should reopen there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Medium Type: Enhancement ✨ Improvement to process or efficiency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants