Skip to content

Commit

Permalink
Rename method and return injectPreflight
Browse files Browse the repository at this point in the history
  • Loading branch information
cdonohue committed Aug 18, 2019
1 parent a59af74 commit b3f1f0f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/benefit/config/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import variants from "./variants"

export default {
prefix: "",

theme,
utilities,
variants,
Expand Down
23 changes: 13 additions & 10 deletions packages/benefit/createBenefit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import parseDeclarations from "./util/parseDeclarations"
import getProcessedRules from "./util/getProcessedRules"
import createStyleTag from "./util/createStyleTag"
import createHash from "./util/createHash"
import { global } from "./util/css"
import { injectGlobal } from "./util/css"
import isBrowser from "./util/isBrowser"
import getPreflightStyles from "./util/getPreflightStyles"
import createCache from "./util/createCache"
import initializeContainers from "./util/initializeContainers"

interface Options {
prefix?: string
preflight?: boolean
theme?: { [key: string]: any }
normalize?: (theme?: { [key: string]: any }) => { [key: string]: any }
utilities?: Array<(theme?: { [key: string]: any }) => { [key: string]: any }>
Expand All @@ -23,13 +23,11 @@ interface Options {
export default function createBenefit(
configFn: (defaultConfig?: Options) => Options = () => defaultConfig
) {
const isBrowser = typeof window !== "undefined"
// const isDevMode = process.env.NODE_ENV === "development"
const config = configFn(defaultConfig)

const {
prefix = "",
preflight = true,
theme = {},
utilities = [],
variants = [],
Expand Down Expand Up @@ -71,12 +69,6 @@ export default function createBenefit(
if (isBrowser) {
initializeContainers()

if (preflight) {
global`
${getPreflightStyles()}
`
}

// const preloadedUtilities =
// process.env.NODE_ENV === "development"
// ? Object.keys(utilityClasses).map((className) => {
Expand Down Expand Up @@ -151,6 +143,16 @@ export default function createBenefit(
}
}

const injectPreflight = () => {
if (isBrowser()) {
initializeContainers()

injectGlobal`
${getPreflightStyles()}
`
}
}

const styleWith = (
classNames: string = "",
isImportant: boolean = false
Expand Down Expand Up @@ -197,6 +199,7 @@ export default function createBenefit(
return {
config,
cssForUtility,
injectPreflight,
getDeclarationsForClasses,
styleWith,
utilities: utilityClasses,
Expand Down
2 changes: 1 addition & 1 deletion packages/benefit/util/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ function createCss(isGlobal: boolean = false, isKeyframes: boolean = false) {

export const css = createCss()

export const global = createCss(true)
export const injectGlobal = createCss(true)

export const keyframes = createCss(false, true)

0 comments on commit b3f1f0f

Please sign in to comment.