styled-components / comparison

Comparing different ways to style components
MIT License
183 stars 23 forks source link

Add aphrodite example #19

Closed mxstbr closed 7 years ago

mxstbr commented 7 years ago

Closes #4

jossmac commented 7 years ago

This is more about component composition and extensibility rather than an Aphrodite specific implementation. Let me know if this is helpful or not. I'll use the Content component as an example:

import React, { PropTypes } from 'react';
import { css, StyleSheet } from 'aphrodite';

const styles = StyleSheet.create({
  ...
});

export default function Content ({
  aphroditeStyles,
  component: Tag,
  media,
  text,
  ...props,
}) {
  props.className = css(
    styles.content,
    ...aphroditeStyles
  );
  return (
    <Tag {...props}>
      <p className={css(styles.text)} dangerouslySetInnerHTML={{ __html: text }} />
      <a className={css(styles.media)} href={media.expanded_url}>
        <img className={css(styles.image)} src={media.media_url_https} alt="" />
      </a>
    </Tag>
  );
};

Content.propTypes = {
  aphroditeStyles: PropTypes.arrayOf(PropTypes.shape({
    _definition: PropTypes.object,
    _name: PropTypes.string,
  })),
  component: PropTypes.oneOfType([
    PropTypes.func,
    PropTypes.string,
  ]),
  media: PropTypes.shape({
    expanded_url: PropTypes.string,
    media_url_https: PropTypes.string,
  }),
  text: PropTypes.string,
};
Content.defaultProps = {
  aphroditeStyles: [],
  component: 'div',
};