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

Introduce emotion and styled-system #164

Merged
merged 75 commits into from
Aug 3, 2018
Merged

Conversation

shawnbot
Copy link
Contributor

@shawnbot shawnbot commented Jul 30, 2018

This is an attempt to bootstraps primer-react with emotion and styled-system and puts them to work for the Block and Box components. Tests and linting will likely fail spectacularly, but the diff is the main attraction here.

Some notes:

  • A bunch of different packages were required to make this work: not just emotion and styled-system, emotion-theming for the ThemeProvider, system-components to create components entirely from system props, and react-emotion (which system-components uses, but it's not clear to me what the diff is with emotion).
  • I added a borders array to the theme to support border={1} and the directional border props.
  • I added a shadows object to the theme to support the boxShadow prop.
  • I updated Box.defaultProps to match the requisite system props values.

@shawnbot shawnbot requested a review from a team July 30, 2018 21:17
src/Block.js Outdated
'minWidth',
'width',
'zIndex'
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhhh so yeah, there's zero implementation in this component anymore. It's purely system props! 😱

Copy link

Choose a reason for hiding this comment

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

Music to my eyes 😻

}
}
return keys
}, [])
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 function is silly, and we'll want to put this somewhere that other components can use it. But for now, this is how we generate the list of all themed values for our color props (bg, borderColor, and color): white, black, gray.0, blue.5, et al.

examples/_app.js Outdated
<Block p={3}>{render()}</Block>
</div>
<ThemeProvider theme={theme}>
<div className="text-dark-gray">
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 should probably just be <Block color='bodytext'> (or <Block color='gray.9'>).

@@ -4,7 +4,21 @@ import {LiveEditor} from '@compositor/kit'
import theme from '../../src/theme'
import {Block, Text, Heading} from '../../src'

const colors = Object.keys(theme.colors.bg)
const Mono = props => <Block fontFamily="mono" {...props} />
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 repeated a lot in the examples, so I made a little component out of it.

src/Text.js Outdated
'fontFamily',
'fontWeight',
'lineHeight',
'space'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again: zero implementation in here!

Copy link
Member

Choose a reason for hiding this comment

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

This should have fontSize too.

@shawnbot shawnbot mentioned this pull request Jul 30, 2018
8 tasks
@broccolini
Copy link
Member

broccolini commented Jul 30, 2018

A bunch of different packages were required to make this work: not just emotion and styled-system, emotion-theming for the ThemeProvider, system-components to create components entirely from system props, and react-emotion (which system-components uses, but it's not clear to me what the diff is with emotion).

We don't need system-components! It's optional, and probably better to start with understanding the mechanics of how emotion and styled-system work, this is from the styled-system docs:

system-components is an optional, alternative way to use styled-system. It replaces the styled function from styled-components and emotion, with an API that makes defining components that use styled-system even simpler.

@broccolini
Copy link
Member

For the benefit of sharing, seems like using styled and theming will give us pretty much the same api as styled-components.

@shawnbot
Copy link
Contributor Author

We don't need system-components! It's optional, and probably better to start with understanding the mechanics of how emotion and styled-system work, this is from the styled-system docs:

Understood. However, what I like a lot about it is that it reduces (if not eliminates) boilerplate code for components that use only system props. I haven't tried implementing anything but Block or Text yet, though, so maybe we'll see what that looks like next?

@shawnbot shawnbot mentioned this pull request Jul 31, 2018
9 tasks
src/Block.js Outdated
'fontFamily',
'fontSize',
'fontWeight',
'lineHeight',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nix fontFamily through lineHeight here; they're not needed in Block.

@shawnbot
Copy link
Contributor Author

Just to follow up on the system-components thing: I'm going to look into what it looks like to use styled-system with emotion, both with and without tagged template literals. I'll update this PR so we can compare the approaches in our session tomorrow.

Copy link
Member

@broccolini broccolini left a comment

Choose a reason for hiding this comment

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

Left a few comments, overall this is looking good :)

src/Block.js Outdated
'boxShadow',
'color',
'display',
'fontFamily',
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove the typography styles from here? I don't think they should be part of the Block component.

@@ -5,7 +5,8 @@ const Box = props => <Block {...props} />

Box.defaultProps = {
Copy link
Member

Choose a reason for hiding this comment

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

Since Block with system props does all this, can we deprecate this component and call "Block" => "Box" again? If that's easier to do in a follow up that's 🆒 .

Copy link

Choose a reason for hiding this comment

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

R.I.P. Block 😹

src/Text.js Outdated
'fontFamily',
'fontWeight',
'lineHeight',
'space'
Copy link
Member

Choose a reason for hiding this comment

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

This should have fontSize too.

src/theme.js Outdated
@@ -1,53 +1,24 @@
const black = '#1b1f23'
Copy link
Member

Choose a reason for hiding this comment

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

I guess this repeats primer-primitives, makes sense to live here but we should figure out what to do with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it'd be nice to get a lot of this stuff into primer-primitives and make any theme tweaks that we need for primer-react here, rather than recreating the entire thing.

src/theme.js Outdated
}

const {blue, gray, green, purple, red, yellow} = colors
const {blue, green, orange, purple, red, yellow} = colors

colors.border = {
Copy link
Member

Choose a reason for hiding this comment

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

Let borders have all the colors rather than limiting them to our previous css variations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the colors.border object is a holdover. See how it's been factored out in #157.

src/theme.js Outdated
])
},
lineHeights: {
normal: 1.5
Copy link
Member

Choose a reason for hiding this comment

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

We should have 1 and 1.25 here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. condensed and ultra-condensed, right?

Copy link
Member

Choose a reason for hiding this comment

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

@shawnbot yup! I was considering that people may want to pass in a numeric value, but I'd prefer to encourage using these pre-defined line-heights since they work with our typography scale. I think for custom non-system things like that they should use the css prop (when we add it).

expect(rendersClass(<Flash m={4} />, 'm-4')).toEqual(true)
// TODO: understand why these aren't working

xit('respects margin utility prop', () => {
Copy link

Choose a reason for hiding this comment

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

What does the 'x' here do? Is it just silencing this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, "marks it as pending".

@shawnbot
Copy link
Contributor Author

shawnbot commented Aug 3, 2018

We're going to change the base of this to a forthcoming v1 PR. 🌮 🎉

@shawnbot shawnbot changed the base branch from master to release-1.0.0-beta August 3, 2018 16:47
@shawnbot shawnbot changed the title [WIP] Introduce emotion and styled-system Introduce emotion and styled-system Aug 3, 2018
@emplums emplums mentioned this pull request Aug 3, 2018
12 tasks
@emplums emplums merged commit bf93b39 into release-1.0.0-beta Aug 3, 2018
@jonrohan jonrohan deleted the emotional-system branch August 3, 2018 18:05
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.

4 participants