Skip to content

React Style To Css ??? #6

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

Closed
xyzdata opened this issue Jun 28, 2017 · 8 comments
Closed

React Style To Css ??? #6

xyzdata opened this issue Jun 28, 2017 · 8 comments

Comments

@xyzdata
Copy link

xyzdata commented Jun 28, 2017

Css To React

CssToReact

http://staxmanade.com/CssToReact/

how to fixed this bug ???

.sidebar-btn::after {
    color: #0f0;
    background: #000;
    width: 20px;
    margin: auto 5px;
    height: 50px;
    content: 'B';
    position: absolute;
    left: 240px;
    top: 35%;
    cursor: pointer;
}
{
  "sidebar_btn__after": {
    "color": "#0f0",
    "background": "#000",
    "width": "20px",
    "margin": "auto 5px",
    "height": "50px",
    "content": "'B'",
    "position": "absolute",
    "left": "240px",
    "top": "35%",
    "cursor": "pointer"
  }
}

React To Css

???

http://reactcss.com/

@xyzdata
Copy link
Author

xyzdata commented Jun 28, 2017

how to add an event listener to a CSS Pseudo-element ???

stackoverflow

https://stackoverflow.com/q/9395858/8202629

https://stackoverflow.com/questions/5598675/javascript-find-pseudo-elements

getComputedStyle

$('*').filter(function(){return getComputedStyle(this, ':before').length != 0});

getComputedStyle & getDefaultComputedStyle

let style = window.getComputedStyle(element, [pseudoElt]);

https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle

http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSview-getComputedStyle

https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getDefaultComputedStyle

https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getDefaultComputedStyle

https://developer.mozilla.org/zh-CN/docs/Web/CSS/computed_value

computed_value

let elem1 = document.getElementById("elemId");
let style = window.getComputedStyle(elem1, null);

// 它等价于
// let style = document.defaultView.getComputedStyle(elem1, null);
<style>
    #elem-container{
        position: absolute;
        left:     100px;
        top:      200px;
        height:   100px;
    }
</style>

<div id="elem-container">dummy</div>
<div id="output"></div>  

<script>
    function getTheStyle(){
        let elem = document.getElementById("elem-container");
        let theCSSprop = window.getComputedStyle(elem,null).getPropertyValue("height");
        document.getElementById("output").innerHTML = theCSSprop;
    }
    getTheStyle();
</script>

event delegation

https://javascript.info/event-delegation

https://developer.mozilla.org/zh-CN/docs/Web/API/Event/target

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events

jquery

https://learn.jquery.com/events/event-delegation/

@xyzdata
Copy link
Author

xyzdata commented Jun 28, 2017

https://stackoverflow.com/questions/5598675/javascript-find-pseudo-elements

Pseudo-element & getComputedStyle

https://stackoverflow.com/questions/44342065/how-to-get-a-dom-elements-before-content-with-javscript

let v_dom = document.querySelector(".javascript"), ":before").getPropertyValue("background-image");

getComputedStyle(v_dom);

@staxmanade
Copy link
Owner

@xgqfrms-gildata - not quite following what the issue/ask is for this item? Can you elaborate a bit more?

@yanckst
Copy link

yanckst commented Mar 11, 2019

@staxmanade I think the original issue is...

This is your CSS class :

.sidebar-btn::after {
    color: #0f0;
    background: #000;
    width: 20px;
    margin: auto 5px;
    height: 50px;
    content: 'B';
    position: absolute;
    left: 240px;
    top: 35%;
    cursor: pointer;
}

This is the output from your conversion:

"sidebar_btn__after": {
    "color": "#0f0",
    "background": "#000",
    "width": "20px",
    "margin": "auto 5px",
    "height": "50px",
    "content": "'B'",
    "position": "absolute",
    "left": "240px",
    "top": "35%",
    "cursor": "pointer"
  }

Correct me if I'm wrong, but I think it should be something like :

"sidebar_btn": {
    //Some Style,

    "&:after": {
        "color": "#0f0",
        "background": "#000",
        "width": "20px",
        "margin": "auto 5px",
        "height": "50px",
        "content": "'B'",
        "position": "absolute",
        "left": "240px",
        "top": "35%",
        "cursor": "pointer"
    }
  }

I'm not an expect, but I know if you have a JSSProperty, you can put a string containing an additional rule. For example, a container that will have a CSS on hover

container: {
    //Some style...

    "&:hover": {
        //Some other style
    }

I think the conversion is wrong, because it doesn't nest rules such as hover, after, etc inside the object itself, but creates a class name with this rule. There's a big difference.

@xyzdata
Copy link
Author

xyzdata commented Mar 14, 2019

@xgqfrms-gildata - not quite following what the issue/ask is for this item? Can you elaborate a bit more?

Sorry for that confused description.

wanted

just keep the :: Pseudo-elements selector

https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors#Pseudo-elements

.sidebar-btn::after => .sidebar-btn::after

error result

.sidebar-btn::after => .sidebar_btn__after

@xyzdata
Copy link
Author

xyzdata commented Mar 14, 2019

image

@staxmanade
Copy link
Owner

Can you explain why/how this is used in a react app? It's my understanding that pseudo selectors are not supported at the element level so I'm not sure I understand what this change would mean if we did make it...

@xyzdata xyzdata closed this as completed Mar 18, 2019
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

3 participants