Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

docs(examples): show only relevant styling variables #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kuzhelov
Copy link
Collaborator

@kuzhelov kuzhelov commented Jul 12, 2018

Provided functionality is working, thorough description with visual examples is about to come.

Issues

  • description is not provided
  • naming (suggestions are warmly welcome:). Specifically, it is about making names of all the introduced agents being succinct and consistent

@levithomason
Copy link
Member

levithomason commented Jul 12, 2018

PR title check is wanting docs: ...message or something like docs(examples): ...message.

@kuzhelov kuzhelov changed the title Show only relevant styling variables in Docs docs(examples): show only relevant styling variables Jul 12, 2018
<Provider
componentVariables={this.state.componentVariables}
rtl={this.state.showRtl}
variableSpies={variableSpies}
Copy link
Member

@levithomason levithomason Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to not have this part of the public API at present. One thought is to first consume the theme in the tree, clone it and observe it at that point, then provide the observed version down stream.

This could be wrapped up in a new component something like this (assumes some observe() deep clone exists):

import Provider from 'src/components/Provider'

const ProviderObserver = (props) => (
  <Provider.Consumer
    render={context => {
      const observed = observe(context)
      observed.onGet(props.onGet)

      return (
        <Provider {...observed}>
          {props.children}
        </Provider>
      )
    }}
  />
)

export default ProviderObserver

Now, anywhere we'd like to observe context in the tree we can use it like so:

// ComponentExample.js

  handleContextGet(context: object, path: string[]) {
    // assuming componentVariables.Button.backgroundColor was accessed:
    // 
    // context === { siteVariables: { ... }, componentVariables: { ... }, ... }
    // path === ['componentVariables', 'Button', 'backgroundColor']
  }

  renderWithProvider() {
    const { componentVariables, showRtl } = this.state
    return (
      <Provider componentVariables={componentVariables} rtl={showRtl}>
        <ProviderObserver onGet={this.handleContextGet}>
          <ExampleComponent knobs={this.getKnobsValue()} />
        </ProviderObserver>
      </Provider>
    )
  }

Now, any rules rendered down stream of our ProviderObserver that access the variables should result in firing the onGet callback. Here, we can track those variables.

What's also neat about this is that we can now also tell any part of the theme is accessed. Including listing out any other components that may be at play in the example.

Let's see if we can get an implementation working that does not require changes to any existing:

  1. Rules file
  2. Variables file
  3. Component file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your feedback - agree, will look into that

@levithomason
Copy link
Member

Bump, anything I can do to help here?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants