GithubHelp home page GithubHelp logo

itsjonq / styled-providers Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 1.7 MB

✨ Handy Providers for Emotion / Styled Components

License: MIT License

JavaScript 97.53% Shell 2.47%
styled-components styled emotion react providers

styled-providers's Introduction

✨ Styled Providers

Build Status

Handy Providers for Emotion / Styled Components

Installation

npm install --save styled-providers

Requirements

Usage

Emotion and Styled Components are supported.

Emotion

import React from "react";
import styled from "@emotion/styled";
import { ScopeProvider } from "styled-providers/emotion";

const View = styled.div`
	background: blue;
`;

const App = () => {
	return (
		<div id="#app">
			<ScopeProvider scope="#app">
				<View />
			</ScopeProvider>
		</div>
	);
};

Styled Components

import React from "react";
import styled from "styled-components";
import { ScopeProvider } from "styled-providers/styled-components";

const View = styled.div`
	background: blue;
`;

const App = () => {
	return (
		<div id="#app">
			<ScopeProvider scope="#app">
				<View />
			</ScopeProvider>
		</div>
	);
};

Components

FrameProvider

Provides the correct document.head to mount the <style> tag for either Emotion or Styled Components. This is necessary when rendering CSS-in-JS generated styles within elements like iFrames on runtime.

Example
import React from "react";
import styled from "@emotion/styled";
import { FrameProvider } from "styled-providers/emotion";
import Frame from "react-frame-component";

const View = styled.div`
	background: blue;
`;

const App = () => {
	return (
		<Frame>
			<FrameProvider>
				<View />
			</FrameProvider>
		</Frame>
	);
};

ScopeProvider

Provides a scope to prefix before generated classNames for either Emotion or Styled Components. Prefixing increases specificity, allowing for smoother integrations with pre-existing CSS rules.

Example
import React from "react";
import styled from "@emotion/styled";
import { ScopeProvider } from "styled-providers/emotion";

const View = styled.div`
	background: blue;
`;

const App = () => {
	return (
		<div id="#app">
			<ScopeProvider scope="html #app">
				<View />
			</ScopeProvider>
		</div>
	);
};

In the above example, rendered selectors (e.g. .css-123jda) will be prefixed with html #app, resulting in selectors like html #app .css-123jda)

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.