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
Feature/dynamic elements #462
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- "6" | ||
- "8" | ||
- "10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 45 additions & 39 deletions
84
test/fixtures/attribute-generation-classname-rewriting.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,45 @@ | ||
export default () => ( | ||
<div> | ||
<div className="test" {...test.test} /> | ||
<div className="test" {...test.test.test} /> | ||
<div className="test" {...this.test.test} /> | ||
<div data-test="test" /> | ||
<div className="test" /> | ||
<div className={'test'} /> | ||
<div className={`test`} /> | ||
<div className={`test${true ? ' test2' : ''}`} /> | ||
<div className={'test ' + test} /> | ||
<div className={['test', 'test2'].join(' ')} /> | ||
<div className={true && 'test'} /> | ||
<div className={test ? 'test' : null} /> | ||
<div className={test} /> | ||
<div className={test && 'test'} /> | ||
<div className={test && test('test')} /> | ||
<div className={undefined} /> | ||
<div className={null} /> | ||
<div className={false} /> | ||
<div className={'test'} data-test /> | ||
<div data-test className={'test'} /> | ||
<div className={'test'} data-test="test" /> | ||
<div className={'test'} {...props} /> | ||
<div className={'test'} {...props} {...rest} /> | ||
<div className={`test ${test ? 'test' : ''}`} {...props} /> | ||
<div className={test && test('test')} {...props} /> | ||
<div className={test && test('test') && 'test'} {...props} /> | ||
<div className={test && test('test') && test2('test')} {...props} /> | ||
<div {...props} className={'test'} /> | ||
<div {...props} {...rest} className={'test'} /> | ||
<div {...props} className={'test'} {...rest} /> | ||
<div {...props} /> | ||
<div {...props} {...rest} /> | ||
<div {...props} data-foo {...rest} /> | ||
<div {...props} className={'test'} data-foo {...rest} /> | ||
<style jsx>{'div { color: red }'}</style> | ||
</div> | ||
) | ||
export default () => { | ||
const Element = 'div' | ||
return ( | ||
<div> | ||
<div className="test" {...test.test} /> | ||
<div className="test" {...test.test.test} /> | ||
<div className="test" {...this.test.test} /> | ||
<div data-test="test" /> | ||
<div className="test" /> | ||
<div className={'test'} /> | ||
<div className={`test`} /> | ||
<div className={`test${true ? ' test2' : ''}`} /> | ||
<div className={'test ' + test} /> | ||
<div className={['test', 'test2'].join(' ')} /> | ||
<div className={true && 'test'} /> | ||
<div className={test ? 'test' : null} /> | ||
<div className={test} /> | ||
<div className={test && 'test'} /> | ||
<div className={test && test('test')} /> | ||
<div className={undefined} /> | ||
<div className={null} /> | ||
<div className={false} /> | ||
<div className={'test'} data-test /> | ||
<div data-test className={'test'} /> | ||
<div className={'test'} data-test="test" /> | ||
<div className={'test'} {...props} /> | ||
<div className={'test'} {...props} {...rest} /> | ||
<div className={`test ${test ? 'test' : ''}`} {...props} /> | ||
<div className={test && test('test')} {...props} /> | ||
<div className={test && test('test') && 'test'} {...props} /> | ||
<div className={test && test('test') && test2('test')} {...props} /> | ||
<div {...props} className={'test'} /> | ||
<div {...props} {...rest} className={'test'} /> | ||
<div {...props} className={'test'} {...rest} /> | ||
<div {...props} /> | ||
<div {...props} {...rest} /> | ||
<div {...props} data-foo {...rest} /> | ||
<div {...props} className={'test'} data-foo {...rest} /> | ||
<Element /> | ||
<Element className="test" /> | ||
<Element {...props} /> | ||
<style jsx>{'div { color: red }'}</style> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export default class { | ||
render() { | ||
const Element = 'div' | ||
|
||
return ( | ||
<Element className="root"> | ||
<p>dynamic element</p> | ||
<style jsx>{` | ||
.root { | ||
background: red; | ||
} | ||
`}</style> | ||
</Element> | ||
) | ||
} | ||
} | ||
|
||
const Element2 = 'div' | ||
export const Test2 = class { | ||
render() { | ||
return ( | ||
<Element2 className="root"> | ||
<p>dynamic element</p> | ||
<style jsx>{` | ||
.root { | ||
background: red; | ||
} | ||
`}</style> | ||
</Element2> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import styles from './styles2' | ||
|
||
export default ({ level = 1 }) => { | ||
const Element = `h${level}` | ||
|
||
return ( | ||
<Element className="root"> | ||
<p>dynamic element</p> | ||
<style jsx>{styles}</style> | ||
</Element> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export default ({ level = 1 }) => { | ||
const Element = `h${level}` | ||
|
||
return ( | ||
<Element className="root"> | ||
<p>dynamic element</p> | ||
<style jsx>{` | ||
.root { | ||
background: red; | ||
} | ||
`}</style> | ||
</Element> | ||
) | ||
} | ||
|
||
export const TestLowerCase = ({ level = 1 }) => { | ||
const element = `h${level}` | ||
|
||
return ( | ||
<element className="root"> | ||
<p>dynamic element</p> | ||
<style jsx>{` | ||
.root { | ||
background: red; | ||
} | ||
`}</style> | ||
</element> | ||
) | ||
} | ||
|
||
const Element2 = 'div' | ||
export const Test2 = () => { | ||
return ( | ||
<Element2 className="root"> | ||
<p>dynamic element</p> | ||
<style jsx>{` | ||
.root { | ||
background: red; | ||
} | ||
`}</style> | ||
</Element2> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome can you add a few more tests cases? i.e. a few more combinations to where
Element
is defined outside of the component, and maybe when it is lowercase too (any edge case you can think of). Also can you add a class component too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Im missing something, but I dont think it will work if Element is defined outside of the component. ( Thats why I added the styled-jsx option )
I´ll add the testcases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, it won't work (it won't add the className) and we want a snapshot of that! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍