Skip to content
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

Friendlier configuration API #14

Open
andywer opened this issue Jun 15, 2018 · 3 comments
Open

Friendlier configuration API #14

andywer opened this issue Jun 15, 2018 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@andywer
Copy link
Member

andywer commented Jun 15, 2018

It's not quite intuitive how to reference custom stylesheets, customize the layout, etc. right now.

Let's come up with something better.

@andywer andywer added enhancement New feature or request help wanted Extra attention is needed labels Jun 15, 2018
@andywer
Copy link
Member Author

andywer commented Jun 15, 2018

Idea:

import createReactShutter from '@shutter/react'
import { addToBody, addToHead, reactProvider, setViewport, useLayout } from '@shutter/react/config'

const shutter = createReactShutter(__dirname, [
  useLayout(myLayout),
  addToHead('<link rel="stylesheet" href="..." />'),
  addToBody('<script></script>'),
  setViewport('1920x1080'),
  reactProvider((element: React.ReactElement<any>) => (
    <SomeContextProvider>
      {element}
    </SomeContextProvider>
  ))
])

Also change the signature of layout functions from

type Layout = (content: HTMLString) => HTMLString

to

type Layout = (bodyContent: HTMLString, headContent?: HTMLString) => HTMLString

Under the hood (implementation details):

typeof addToHead = <Config extends CoreConfig>(html: string) => <Config>ConfigExtender
type ConfigExtender = <Config extends CoreConfig>(config: Config) => Config

// the <Config extends CoreConfig> generic allows it to be used with ReactConfig (extends CoreConfig) as well

interface CoreConfig {
  layout: Layout,
  bodyContent: HTMLString,
  headContent: HTMLString,
  viewport?: [number, number]
}

interface ReactConfig extends CoreConfig {
  wrapElement: (element: ReactElement<any>) => ReactElement<any>
}

@andywer
Copy link
Member Author

andywer commented Jun 15, 2018

@ulrich-merkel Thoughts? :)

@andywer
Copy link
Member Author

andywer commented Jun 15, 2018

Side note: reactProvider might be called decorate or similar.

It should be clear that it's React-specific when looking at the import. Thought of "decorate" when seeing that react-storybook calls it decorators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant