-
Notifications
You must be signed in to change notification settings - Fork 1
Increase specificity for hybrid ui #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| registry=https://nexus1.ci.quickbaserocks.com/nexus/content/repositories/qb-npm-all/ | ||
| [email protected] | ||
| always-auth=true | ||
| _auth=ZGV2ZWxvcGVyOmlkMnViVjhtaUVWaFh0R2Q= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,25 +2,42 @@ | |
| import type { Interpolation, Target } from '../types' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no semi-colons! those bastards!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. I have a really hard time reading this code. |
||
|
|
||
| export default (css: Function) => { | ||
| const constructWithOptions = (componentConstructor: Function, | ||
| tag: Target, | ||
| options: Object = {}) => { | ||
| const constructWithOptions = ( | ||
| componentConstructor: Function, | ||
| tag: Target, | ||
| options: Object = {}, | ||
| ) => { | ||
| if (typeof tag !== 'string' && typeof tag !== 'function') { | ||
| // $FlowInvalidInputTest | ||
| throw new Error(`Cannot create styled-component for component: ${tag}`) | ||
| } | ||
|
|
||
| /* This is callable directly as a template function */ | ||
| const templateFunction = | ||
| (strings: Array<string>, ...interpolations: Array<Interpolation>) => | ||
| componentConstructor(tag, options, css(strings, ...interpolations)) | ||
| const templateFunction = (strings: Array<string>, ...interpolations: Array<Interpolation>) => { | ||
| const cssWrapperStart = '.hybridUI & { ' | ||
| const cssWrapperEnd = ' }' | ||
|
|
||
| // We wrap the provided css string with our own specificity class (.hybridUI) | ||
| const updatedStrings = [...strings] | ||
| updatedStrings[0] = `${cssWrapperStart}${updatedStrings[0]}` | ||
| updatedStrings[updatedStrings.length - 1] = `${updatedStrings[ | ||
| updatedStrings.length - 1 | ||
| ]}${cssWrapperEnd}` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. I’ll try. I was having a lot of issues working with that strings array. I’m not sure if it’s typescript or what. |
||
|
|
||
| return componentConstructor(tag, options, css(updatedStrings, ...interpolations)) | ||
| } | ||
|
|
||
| /* If config methods are called, wrap up a new template function and merge options */ | ||
| templateFunction.withConfig = config => | ||
| constructWithOptions(componentConstructor, tag, { ...options, ...config }) | ||
| constructWithOptions(componentConstructor, tag, { | ||
| ...options, | ||
| ...config, | ||
| }) | ||
| templateFunction.attrs = attrs => | ||
| constructWithOptions(componentConstructor, tag, { ...options, | ||
| attrs: { ...(options.attrs || {}), ...attrs } }) | ||
| constructWithOptions(componentConstructor, tag, { | ||
| ...options, | ||
| attrs: { ...(options.attrs || {}), ...attrs }, | ||
| }) | ||
|
|
||
| return templateFunction | ||
| } | ||
|
|
||
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.
wow they're using rollup