Code Monkey home page Code Monkey logo

styled-stencils's Introduction

๐Ÿ’… โ€“ Styled Stencils โ€“ A library for your web components

A Styled Components like library for StencilJS


Build Status Maintainability npm version

Intro

This project is meant to handle fast production and easy maintenance, this is not an overall solution is a way for us for fasten our work and grant quality during all the development project.

Contributions and feedbacks are welcome.

What it does

Basically it gives you the flexibility of CSS in the power engine of JS. Helps keep clean your code and avoid spaghetti code and css files long like script rolls.

Install

yarn add styled-stencils

or if you have time to spare

npm install styled-stencil

Example

Use your styled components in JSX as you would have done with normal components

import {Component} from '@stencil/core';
import styled from 'styled-stencil';

const Background = styled.section`
  padding: 4em;
  background: papayawhip;
`;

const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: ${(props) => props.color};
`;

@Component({
  tag: 'my-component'
})
export class MyComponent {
  render() {
    return (
      <Background>
        <Title color="palevioletred">Hello World, this is my first styled component!</Title>
      </Background>
    );
  }
}

And here the result you'll se on page. Same as styled-components ๐Ÿ˜‰

Requirements

  • Node >= 10.1

Author

Acknowledgments

styled-stencils's People

Contributors

dependabot[bot] avatar wanbinkimoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mehmetsuci

styled-stencils's Issues

Cannot pass props to styled component

While trying to create a button, I discovered that the following code won't render props to the styled component.

Stripped back code:

const Button = styled.button`
...
`

@Component({
	tag: 'my-button'
})

export class MyButton {
   @Prop() isDisabled?: boolean;
   
   render () {
      return (
         <Button disabled={this.isDisabled}></Button>
      )}
}

<my-button is-disabled></my-button>

When rendering the component, the attribute disabled isn't rendered on the element. On the host the is-disabled prop is visible.

Information: apply display flex

I'm using display: flex and appear not apply on elements.

Code example

const StyledIcon = styled.span`
  display: flex;
`;

Using div or span whethever, the result is the same.

My component

    return (
      <Host>
        <StyledIcon>
          <div>Column 1</div>
          <div>Column 2</div>
        </StyledIcon>
      </Host>
    );

Preview

image

For tests, adding display: flex; on dynamic created element

image

`as` Prop doesn't work

Hi! I'm trying to use as Prop -> documentation here <- but it doesn't work.

I have this StyledComponent:

export const Text = styled.div`
    color: #333333;
    font-size: 1.5rem;
`;
export class TheText {
	@Prop() text: string;
	@Prop() taghtml: string;

	render() {
		return (
			<Host>
				<Text as={this.taghtml}>{this.text}</Text>
			</Host>
		);
	}
}

I use TheText component:

<the-text text="Hi! I'm a text" taghtml="p"/>

And the DOM always show the tag: div

<the-text text="Hi! I'm a text" taghtml="p">
	<div>Hi! I'm a text</div>
</the-text>

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.