Code Monkey home page Code Monkey logo

Comments (6)

James-E-Adams avatar James-E-Adams commented on May 14, 2024

Probably want to have a single driver instance for the app/page.

Potential solution could be to create a HOC called withDriver, and wrap a component high up in the tree, which will pass down a driver instance as a prop.

withDriver(Root)

Then, when you use the DriverWrapper, you pass a reference to the driver instance which can be passed through the props down the tree.

from driver.js.

kamranahmedse avatar kamranahmedse commented on May 14, 2024

Hey, while this looks good, I was thinking about a little different implementation to keep it simple and more generic for any use-case. We export a single component with which user provides all the options and then we subscribe to the lifecycle hooks of the component and manipulate the driver:

Below is the example to give you a better idea

import Driver from 'react-driver';

export class App extends React.Component {
  render: function () {
    return (
      <div className="app">
          <Driver
             ref="driver"
             start={true} // boolean for when you want to start it
             steps={[arrayOfSteps]} // this would be the array of step definitions
             highlight={element} // or you can pass this to highlight single element
             animate={true}
             opacity={0.75}
             ...
        />
        <YourComponents .../>
      </div>
    );
  }
}

from driver.js.

James-E-Adams avatar James-E-Adams commented on May 14, 2024

Hmmm. How would you envision accessing the elements for the highlight/steps? For the highlight, It may be better to pass a reference to the driver down the tree to wherever you want to highlight - or even something like highlight: (element) => this.driver.highlight(element). We could even make it smarter and allow the wrapper's highlight to accept a component as the argument, and use ReactDOM.findDomNode() to get a reference to the DOM element.

Additionally, I'm not sure how you would come up with an array of steps here without deeply knowing how the tree looks further into <YourComponents...> which kind of breaks the idea of encapsulation, unless I'm misunderstanding your suggestion.

BTW string refs are considered legacy, https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs, so I'd avoid using them.

from driver.js.

kamranahmedse avatar kamranahmedse commented on May 14, 2024

How would you envision accessing the elements for the highlight/steps?

We don't need to access them in the wrapper, Driver would do that for us; you just need to pass the query selectors. I was thinking that the wrapper won't have anything reactish, it will just be a super simple single component using Driver behind the scenes the same way that we use it normally; except instead of initializing the Driver directly etc, we will do it through the wrapper. The component will just expose the options as attributes and proxy them over to the instance of Driver that it will create internally.

What do you think?

from driver.js.

James-E-Adams avatar James-E-Adams commented on May 14, 2024

Using the query selectors isn't a very react-y way of doing this - But I'm still not sure on the best way to do steps without it. It's hard because the very concept of steps breaks encapsulation in any case. I might write up a quick wrapper that only supports highlight for now, and you can see what you think. Will post it here when I'm done.

from driver.js.

James-E-Adams avatar James-E-Adams commented on May 14, 2024

https://github.com/James-E-Adams/react-driver.js

I still need to solve an issue with parcel/how I'm exporting the module though...

from driver.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.