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

Implement currying interface, resolve #18 #19

Merged
merged 2 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ Install peer dependencies `react` and `react-dom` in your project.
```js
import styled from 'styled-jss'

const Button = styled('button', {
const Button = styled('button')({
fontSize: 12,
color: (props) => props.theme.textColor
})

// You can also use curried interface this way.
Copy link
Member

Choose a reason for hiding this comment

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

its all curried ...

Copy link
Member

Choose a reason for hiding this comment

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

but yeah a separate example is still good.

const div = styled('div')

const Container = div({
padding: 20
})

// Composition.
const PrimaryButton = styled(Button, {
const PrimaryButton = styled(Button)({
color: 'red'
})
```
Expand Down Expand Up @@ -59,14 +66,14 @@ const styled = Styled({
}
})

const NormalButton = styled('button', {
const NormalButton = styled('button')({
composes: '$baseButton',
border: [1, 'solid', 'grey'],
color: 'black'
})

// Composition - same way.
const PrimaryButton = styled(NormalButton, {
const PrimaryButton = styled(NormalButton)({
color: 'red'
})

Expand Down
3 changes: 2 additions & 1 deletion src/createStyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const createStyled = (jss: Function) => (baseStyles: BaseStylesType = {}): Style
}

return Object.assign((
tagNameOrStyledElement: TagNameOrStyledElementType,
tagNameOrStyledElement: TagNameOrStyledElementType
) => (
ownStyle: ComponentStyleType
): StyledElementType => {
const {tagName, style} = getStyledArgs(tagNameOrStyledElement)
Expand Down
18 changes: 11 additions & 7 deletions src/tests/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@ import React from 'react'
import type {StyledType} from '../types'

export default (styled: StyledType) => {
const App = styled('div', {
const App = styled('div')({
margin: 50,
})

const Header = styled('header', {
const Header = styled('header')({
padding: 10,
})

const Section = styled('section', {
// curried
const section = styled('section')

const Section = section({
color: 'red',
})

const AnotherSection = styled(Section, {
// composition
const AnotherSection = styled(Section)({
color: 'yellow',
})

const Title = styled('h1', {
const Title = styled('h1')({
color: 'red',
})

const Button = styled('button', {
// function value
const Button = styled('button')({
margin: ({margin = 0}) => margin,
})


return () => (
<App>
<Header>
Expand Down