GithubHelp home page GithubHelp logo

dparker2 / vue-emotion Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 733 KB

Use emotion with Vue.js

License: MIT License

HTML 3.10% Vue 24.19% JavaScript 69.58% Shell 3.13%
vuejs vuejs2 emotion emotionjs vue-plugin css-in-js styled styled-components

vue-emotion's Introduction

vue-emotion

npm version Build Status Coverage Status

Use dynamic styling powered by emotion with Vue.js components.

Demo Link

https://codesandbox.io/s/github/ParkerD559/vue-emotion-plugin/tree/master

Styled

Installation

npm install -D @vue-emotion/styled

Style Components

const StyledButton = styled(MyButton)`
  border: 1px solid ${color('red')};
  padding: 10px;
  height: ${props => props.height}px;
  width: ${props => props.width}px;
  color: ${props => props.color};
  background-color: ${props => props.backgroundColor};
`

Style HTML elements

const StyledAnchor = styled.a`
  text-decoration: none;
`

Target styled components

import StyledButton from './somewhere'

const StyledWrapper = styled.section`
  div > ${StyledButton} {
    color: #123123;
  }
`

Note: Doesn't work with object styles

Object styles

const StyledButton = styled(MyButton)({
    color: '#0000ff',
    flex: 1
})

Reuse styles using withComponent

const StyledButton = styled(MyButton)`
    height: 100px;
    width: 200px;
`
const StyledAnchor = StyledButton.withComponent('a');
// => StyledButton and StyledAnchor have same styles

Bugs/Features

Please feel free to post any issues or feature requests: https://github.com/ParkerD559/vue-emotion/issues

vue-emotion's People

Contributors

aaron-pool avatar dparker2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bichikim

vue-emotion's Issues

Scoped styles

I've been using the (now archived) version of vue-emotion by egoist for a while now. The three things that would really make me switch to this library would be:

  1. an invisible implementation of targeting a child emotion component (but you already created an issue for that, so that's good ๐Ÿ‘ )
  2. Some sort of implementation that mimics scoped styles of vue style blocks. Because, at the point I am able to target emotion children components, I have to worry about styles leaking down through my component tree.
  3. Switching to the styled wrapper component to be a functional component. I use these everywhere, so, the lighter the better.

Overwriting classes instead of merging.

Hey!

Finally got around to playing around with this library, but some issues came up when I tried it as a drop in replacement for legacy vue-emotion, the biggest of which is that you're not taking into account existing classes that might exist on a VNode.

Checkout this line from wrapper.js:

    // Add the target class if need be
    const classes = this.$_targetClass
        ? [emotionClass, this.$_targetClass]
        : [emotionClass]

    return createElement(
        this.$_styledFrom,  // Base component even if styled multiple times
        { ...context.data, class: classes },
        context.children
    );

See? You're taking into account a targetClass for selector targeting, but when the root node of the component being styled already has a class attribute, it's getting wiped out.

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.