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

Proposal: Presets #65

Open
Idered opened this issue Nov 7, 2019 · 0 comments
Open

Proposal: Presets #65

Idered opened this issue Nov 7, 2019 · 0 comments

Comments

@Idered
Copy link
Contributor

Idered commented Nov 7, 2019

Define component presets:

const presets = {
  button: {
    save: {
      children: 'Save [ICON]',
      appearance: 'primary',
      intent: 'success'
    },
    cancel: {
      children: 'Cancel',
      appearance: 'minimal'
    }
  }
}

const App = () => (
  <SmashingPresetProvider value={presets}>
    <Page/>
  </SmashingPresetProvider>
)

Bind preset group to component:

const Button = (props) => {
  const presetProps = usePreset('button', props)

  return <button {...presetProps} />
}
//or
const Button withPreset('button', (props) => {
  return <button {...props} />
})

Use preset:

const Page = () => (
  <>
    <Button preset="save" />
    <Button preset="cancel" appearance="subtle" /> 
  </>
)

This will render two buttons with props taken from presets. Preset can be overwritten with a prop: cancel button has appearance overwritten.

@Idered Idered pinned this issue Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant