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

Refactor common component attributes to be more consistent (I.E. marginTop, etc) #113

Open
gabrielbull opened this issue Jan 30, 2018 · 2 comments
Projects
Milestone

Comments

@gabrielbull
Copy link
Owner

gabrielbull commented Jan 30, 2018

Blocked by: #112

We should have one common way to add the props attributes like marginTop, horizontalAlignment, etc to the styling.

For example:

import createCss from './createCssForAllComponents';
import styled, { css } from 'react-emotion'

const viewStyle = css`
  color: rebeccapurple;
`

class View extends React.Component {
  propTypes = {
    hidden: PropTypes.boolean,
    marginTop: PropTypes.number
  }
  
  render() {
    const { otherProp, ...props } = this.props;
    
    return <div otherProp={otherProp} className={createCss(css, props)} />
  }
}
function createMarginCss(css, props) {
  for (let prop of in props) {
    if (props.hasOwnProperty(prop)) {
      switch (prop) {
        case 'marginTop': css.extend(...); break; // add margin-top: `${props[prop]}px` here
      }
    }
  }
}

function createHiddenCss(css, props) {
  if (props.hidden) {
    return css.extend(...); // add display: 'none' here
  }
}

export default createCss (css, props) {
   css = createMarginCss(css, props);
   css = createHiddenCss(css, props);
  return css;
}
@gabrielbull gabrielbull created this issue from a note in v0.4 (To Do) Jan 30, 2018
@gabrielbull gabrielbull added this to the Beta 0.4.0 milestone Jan 30, 2018
@alacroix
Copy link
Collaborator

alacroix commented Feb 1, 2018

@gabrielbull something like styled-system may fit our needs? Seems pretty cool to use with styled-components. (Never used it before though)

@gabrielbull
Copy link
Owner Author

Looks like something we might try indeed. Keeping the dependency count low is also very important so if it's something simple we might want to implement our own solution. If we do not use styled-system, we should inspire ourselves from styled-system so people coming to this library who have used it will find it familiar, and vice-versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
v0.4
To Do
Development

No branches or pull requests

2 participants