-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
113 additions
and
20 deletions.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import StyleSheet from '../models/StyleSheet' | ||
|
||
export default (sheet: StyleSheet) => { | ||
const bulmaTemplate = (tags: BulmaTag[]) => { | ||
sheet.injectTags(tags) | ||
|
||
return tags | ||
} | ||
|
||
return bulmaTemplate | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
export default () => '' | ||
import interleave from '../utils/interleave' | ||
|
||
export default <bulmaTemplate, props>( | ||
bulmaTemplate: bulmaTemplate, | ||
props: props, | ||
) => { | ||
const templateEvaluation = ( | ||
style: Style, | ||
...tags: TemplateTag[] | ||
): BulmaTag[] => { | ||
const reducedTags = tags.map(tag => { | ||
if (typeof tag === 'function') { | ||
return tag(bulmaTemplate, props) | ||
} else { | ||
return tag | ||
} | ||
}) | ||
|
||
return interleave(style, reducedTags) | ||
} | ||
|
||
return templateEvaluation | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
import React, { Component } from 'react' | ||
import React, { Component, Context } from 'react' | ||
|
||
export default constructor => { | ||
class BulmaComponent extends Component<any, any> {} | ||
interface Props<context> { | ||
sheet: context & { injectTags: (tags: string[]) => void } | ||
[key: string]: any | ||
} | ||
|
||
export default function<context>(BulmaContext: Context<context>) { | ||
const withBulma = ComposedComponent => props => ( | ||
<BulmaContext.Consumer> | ||
{sheet => <ComposedComponent sheet={sheet} {...props} />} | ||
</BulmaContext.Consumer> | ||
) | ||
|
||
const createBulmaComponent = ( | ||
ComposedComponent: typeof Component, | ||
options: object, | ||
tags: BulmaTag[], | ||
) => { | ||
class StyledComponent extends Component<Props<context>, any, any> { | ||
componentWillMount() { | ||
const { sheet } = this.props | ||
|
||
sheet.injectTags(tags) | ||
} | ||
|
||
render() { | ||
return <ComposedComponent classNames={tags} {...options} /> | ||
} | ||
} | ||
|
||
return withBulma(StyledComponent) | ||
} | ||
|
||
return BulmaComponent | ||
return createBulmaComponent | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type Style = string[] | ||
|
||
type BulmaTag = string | ||
|
||
type TemplateTag = <bulma, props>(bulma: bulma, props: props) => BulmaTag |
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,8 @@ | ||
export default function interleave<T, U>(base: T[], elements: U[]): (T | U)[] { | ||
return elements.reduce( | ||
(array, element, index) => { | ||
return [...array, element, base[index + 1]] | ||
}, | ||
[base[0]], | ||
) | ||
} |