Conversation
| "jss": "^6.5.0", | ||
| "jss-preset-default": "^1.3.1", | ||
| "react": "^15.4.2", | ||
| "react-jss": "^5.4.0", |
There was a problem hiding this comment.
both jss and react-jss are old, also if you have react-jss, you don't need jss and jss-preset-default
| "recompose": "^0.23.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@lttb/eslint-config-default": "github:lttb/configs#js", |
There was a problem hiding this comment.
in case we are going to move this repo to the cssinjs org, we should use https://github.com/cssinjs/eslint-config-jss
|
|
||
| const elementStyles = { ...inheritStyles, ...styles } | ||
|
|
||
| const StyledElement = pure( |
There was a problem hiding this comment.
not sure shallowEqual should be implemented by default, does styled-components has it ?
There was a problem hiding this comment.
if yes, instead of the library, we could use PureComponent from react, its some lines more but at the end way smaller build
There was a problem hiding this comment.
I think it should, otherwise it may cause some effects with dom-elements like focus-lost on input in rerender
There was a problem hiding this comment.
Please check what styled does out of curiosity
|
|
||
| const StyledElement = pure( | ||
| injectSheet({ [Tag]: elementStyles, ...baseStyles })(({ classes, children }) => | ||
| <Tag className={classes[Tag]}> |
There was a problem hiding this comment.
I think styled supports className prop, so if user passes a className it should not override, it should be added
| const elementStyles = { ...inheritStyles, ...styles } | ||
|
|
||
| const StyledElement = pure( | ||
| injectSheet({ [Tag]: elementStyles, ...baseStyles })(({ classes, children }) => |
There was a problem hiding this comment.
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.
| }, | ||
| "homepage": "https://github.com/lttb/jss-styled#readme", | ||
| "dependencies": { | ||
| "react": "^15.5.4", |
There was a problem hiding this comment.
react should be in peerDependencies https://github.com/styled-components/styled-components/blob/master/package.json#L118
| const elementStyles = { ...inheritStyles, ...styles } | ||
|
|
||
| const Primitive = ({ classes, children, className }: PrimitiveProps) => | ||
| <Tag className={classes[Tag].concat(className ? ` ${className}` : '')}> |
There was a problem hiding this comment.
how is it possible that you use Tag as a component and as a class name at the same time?
| styles?: Object | ||
| } = typeof Element === 'string' ? { Tag: Element } : Element | ||
|
|
||
| const elementStyles = { ...inheritStyles, ...styles } |
There was a problem hiding this comment.
In this case we increase amount of styles rendered to css, we should think how to leverage jss-compose for this.
|
|
||
| export const styled = prepareStyled() | ||
|
|
||
| export const setStyledCreator = (styledFunction: Function = styled) => |
There was a problem hiding this comment.
name setStyledCreator is bad, this function doesn't set anything, its a get or a create
There was a problem hiding this comment.
createStyledCreator is a better name
| } | ||
|
|
||
|
|
||
| export const prepareStyled = (injectSheet?: Function = injectSheetDefault) => |
| return Object.assign(StyledPrimitive, { Tag, styles: elementStyles }) | ||
| } | ||
|
|
||
| export const styled = prepareStyled() |
There was a problem hiding this comment.
suggestion for the naming conflict fix
const defaultStyled = createStyled()
export {defaultStyled as styled}
export const createStyledCreator = (styled: Function = defaultStyled) =>
|
|
||
| export const prepareStyled = (injectSheet?: Function = injectSheetDefault) => | ||
| ( | ||
| Element: string | StyledElementType, |
There was a problem hiding this comment.
I am using in such cases this convention: TagNameOrStyledElement
There was a problem hiding this comment.
later on you can do the delegation and name the variable differently.
|
|
||
| export default (styled: Function) => { | ||
| const App = styled('div', { | ||
| margin: '50px', |
There was a problem hiding this comment.
please rely in all examples on jss-preset-default, in this case it allows you to use numbers
| }) | ||
|
|
||
| const Button = styled('button', { | ||
| margin: ({ margin = 0 }) => `${margin}px`, |
There was a problem hiding this comment.
same here, you can use numbers in the latest jss version
|
|
||
| <Section data-name="content"> | ||
| <Button>primitive test</Button> | ||
| <Button _margin={10}>dynamic primitive test</Button> |
4edbac4 to
6e1b3fe
Compare
| @@ -0,0 +1,133 @@ | |||
| import React, {PureComponent} from 'react' | |||
|
|
|||
| import {create as createJSS, getDynamicStyles} from 'jss' | |||
There was a problem hiding this comment.
I use strict camel case: createJss, it looks strange sometimes but its a better way.
|
|
||
| const JSS = createJSS(preset()) | ||
|
|
||
| type StyledElementAttrsT = { Tag: string, styles: Object } |
There was a problem hiding this comment.
do types conflict with vars? Asking because of "T" suffix.
There was a problem hiding this comment.
yes, they can't have the same names
| import filterProps from './utils/filter-props' | ||
|
|
||
|
|
||
| const JSS = createJSS(preset()) |
There was a problem hiding this comment.
I use jss small for the Jss instance.
There was a problem hiding this comment.
yep, fix it here 7eb58c1#diff-73642d587163f2eb4d72f0fa6ebfba02R9
| let sheet | ||
| let dynamicSheet | ||
|
|
||
| let currentId = 0 |
| import injectSheet from 'react-jss' | ||
|
|
||
| // Base styles, like a regular jss object. | ||
| const styled = Styled({ |
There was a problem hiding this comment.
I think this should be a second separate example, because user will think he needs to do that.
There was a problem hiding this comment.
I would try to make clear that the API is mostly compatible with styled
|
|
||
| const NormalButton = styled('button', { | ||
| composes: '$baseButton', | ||
| border: '1px solid grey' |
There was a problem hiding this comment.
Lets leverage jss-default-unit? border: [1, 'solid', 'grey']
Implement base jss-styled realisation
TODO:
sheet?is-native-propas a separate package. Created is-react-prop@kof