Skip to content

Create JSS-styled prototype#1

Merged
kof merged 11 commits intomasterfrom
feature/prototype
Apr 21, 2017
Merged

Create JSS-styled prototype#1
kof merged 11 commits intomasterfrom
feature/prototype

Conversation

@lttb
Copy link
Copy Markdown
Member

@lttb lttb commented Apr 19, 2017

Implement base jss-styled realisation

TODO:

  • We increase amount of styles rendered to css in the head. so we should use just one global sheet?
  • Make is-native-prop as a separate package. Created is-react-prop

@kof

@lttb lttb force-pushed the feature/prototype branch from cab7cef to 6a80dd8 Compare April 19, 2017 17:11
Comment thread package.json Outdated
"jss": "^6.5.0",
"jss-preset-default": "^1.3.1",
"react": "^15.4.2",
"react-jss": "^5.4.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

both jss and react-jss are old, also if you have react-jss, you don't need jss and jss-preset-default

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

right, thanks!

Comment thread package.json Outdated
"recompose": "^0.23.1"
},
"devDependencies": {
"@lttb/eslint-config-default": "github:lttb/configs#js",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in case we are going to move this repo to the cssinjs org, we should use https://github.com/cssinjs/eslint-config-jss

Comment thread src/index.jsx Outdated

const elementStyles = { ...inheritStyles, ...styles }

const StyledElement = pure(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure shallowEqual should be implemented by default, does styled-components has it ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if yes, instead of the library, we could use PureComponent from react, its some lines more but at the end way smaller build

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it should, otherwise it may cause some effects with dom-elements like focus-lost on input in rerender

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please check what styled does out of curiosity

Comment thread src/index.jsx Outdated

const StyledElement = pure(
injectSheet({ [Tag]: elementStyles, ...baseStyles })(({ classes, children }) =>
<Tag className={classes[Tag]}>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think styled supports className prop, so if user passes a className it should not override, it should be added

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

agree

Comment thread src/index.jsx Outdated
const elementStyles = { ...inheritStyles, ...styles }

const StyledElement = pure(
injectSheet({ [Tag]: elementStyles, ...baseStyles })(({ classes, children }) =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure its a good idea to have a separate style tag for each styled element, that would be a lot of tags.

Comment thread package.json
},
"homepage": "https://github.com/lttb/jss-styled#readme",
"dependencies": {
"react": "^15.5.4",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread src/index.jsx Outdated
const elementStyles = { ...inheritStyles, ...styles }

const Primitive = ({ classes, children, className }: PrimitiveProps) =>
<Tag className={classes[Tag].concat(className ? ` ${className}` : '')}>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how is it possible that you use Tag as a component and as a class name at the same time?

Comment thread src/index.jsx Outdated
styles?: Object
} = typeof Element === 'string' ? { Tag: Element } : Element

const elementStyles = { ...inheritStyles, ...styles }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In this case we increase amount of styles rendered to css, we should think how to leverage jss-compose for this.

Comment thread src/index.jsx Outdated

export const styled = prepareStyled()

export const setStyledCreator = (styledFunction: Function = styled) =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

name setStyledCreator is bad, this function doesn't set anything, its a get or a create

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

createStyledCreator is a better name

Comment thread src/index.jsx Outdated
}


export const prepareStyled = (injectSheet?: Function = injectSheetDefault) =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

createStyled is a better name

Comment thread src/index.jsx Outdated
return Object.assign(StyledPrimitive, { Tag, styles: elementStyles })
}

export const styled = prepareStyled()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion for the naming conflict fix

const defaultStyled = createStyled()

export {defaultStyled as styled}

export const createStyledCreator = (styled: Function = defaultStyled) =>

Comment thread src/index.jsx Outdated

export const prepareStyled = (injectSheet?: Function = injectSheetDefault) =>
(
Element: string | StyledElementType,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am using in such cases this convention: TagNameOrStyledElement

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

later on you can do the delegation and name the variable differently.

Comment thread src/tests/App.jsx Outdated

export default (styled: Function) => {
const App = styled('div', {
margin: '50px',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please rely in all examples on jss-preset-default, in this case it allows you to use numbers

Comment thread src/tests/App.jsx Outdated
})

const Button = styled('button', {
margin: ({ margin = 0 }) => `${margin}px`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here, you can use numbers in the latest jss version

Comment thread src/tests/App.jsx Outdated

<Section data-name="content">
<Button>primitive test</Button>
<Button _margin={10}>dynamic primitive test</Button>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

forgot to update?

@lttb lttb force-pushed the feature/prototype branch 2 times, most recently from 4edbac4 to 6e1b3fe Compare April 20, 2017 15:58
@lttb lttb force-pushed the feature/prototype branch from 6e1b3fe to f8a7e59 Compare April 20, 2017 16:01
@lttb lttb force-pushed the feature/prototype branch from f036f28 to 682aee9 Compare April 20, 2017 17:04
Comment thread src/index.jsx Outdated
@@ -0,0 +1,133 @@
import React, {PureComponent} from 'react'

import {create as createJSS, getDynamicStyles} from 'jss'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I use strict camel case: createJss, it looks strange sometimes but its a better way.

Comment thread src/index.jsx Outdated

const JSS = createJSS(preset())

type StyledElementAttrsT = { Tag: string, styles: Object }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do types conflict with vars? Asking because of "T" suffix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, they can't have the same names

Comment thread src/index.jsx Outdated
import filterProps from './utils/filter-props'


const JSS = createJSS(preset())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I use jss small for the Jss instance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread src/index.jsx Outdated
let sheet
let dynamicSheet

let currentId = 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

its more like a counter I think

@lttb lttb force-pushed the feature/prototype branch from 7eb58c1 to 0e45a63 Compare April 20, 2017 23:56
Comment thread README.md
import injectSheet from 'react-jss'

// Base styles, like a regular jss object.
const styled = Styled({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be a second separate example, because user will think he needs to do that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would try to make clear that the API is mostly compatible with styled

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And this feature is on top of it.

Comment thread README.md

const NormalButton = styled('button', {
composes: '$baseButton',
border: '1px solid grey'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lets leverage jss-default-unit? border: [1, 'solid', 'grey']

@kof kof merged commit 7e7a507 into master Apr 21, 2017
@lttb lttb deleted the feature/prototype branch April 21, 2017 10:43
lttb added a commit that referenced this pull request Apr 28, 2017
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.

2 participants