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

can it notify the child component that is hovered if wrapped with styled component? #6

Open
OnlyRefat opened this issue Jun 26, 2018 · 0 comments

Comments

@OnlyRefat
Copy link

OnlyRefat commented Jun 26, 2018

  • question

Hi,

Thanks for the good work. I am using it on my projects heavily.

Does it support https://github.com/styled-components/styled-components ? I am using the following code

import React from 'react';
import ReactHoverObserver from 'react-hover-observer';
import { FieldBlock, FieldBoundaries } from './block.style';

export default ({ children, admin }) => (
  <FieldBlock className="hello">
    <ReactHoverObserver>
      {admin && <div className="drag-me">Drag Here</div>}
      <div>
        <FieldBoundaries>{children}</FieldBoundaries>
      </div>
    </ReactHoverObserver>
  </FieldBlock>
);

where the block.style.js is

import styled from 'styled-components';
import { palette } from 'styled-theme';

const FieldBlock = styled.div`
  ${'' /* background-color: #f4f4f5; */}
  background-color: ${palette('grey', 0)}; 
  padding: 30px;
`;

const FieldBoundaries = styled.div`
  background-color: #ffffff;
  border: 2px dashed #e9ebf3;
  padding: 30px 20px;
  border-radius: 3px;
`;

export { FieldBlock, FieldBoundaries };



if I remove the styled component and put a div aroung children property it does not work.

import React from 'react';
import ReactHoverObserver from 'react-hover-observer';
import { FieldBlock, FieldBoundaries } from './block.style';

export default ({ children, admin }) => (
  <FieldBlock className="hello">
    <ReactHoverObserver>
      {admin && <div className="drag-me">Drag Here</div>}
       <div> {children}</div>
    </ReactHoverObserver>
  </FieldBlock>
);

It works when I remove the styled component wrapper around children property.

import React from 'react';
import ReactHoverObserver from 'react-hover-observer';
import { FieldBlock, FieldBoundaries } from './block.style';

export default ({ children, admin }) => (
  <FieldBlock className="hello">
    <ReactHoverObserver>
      {admin && <div className="drag-me">Drag Here</div>}
        {children}
    </ReactHoverObserver>
  </FieldBlock>
);

Am I missing something or it does not have support for styled component?

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

No branches or pull requests

1 participant