GithubHelp home page GithubHelp logo

Port to React about css-doodle HOT 12 CLOSED

css-doodle avatar css-doodle commented on May 21, 2024 19
Port to React

from css-doodle.

Comments (12)

Mizumaki avatar Mizumaki commented on May 21, 2024 8

@papan01

Does this support tsx?

I don't know the support means, but I use <css-doodle> in Doodle.tsx, and it works.

First, you need to extend JSX.IntrinsicElements interface.

declare namespace JSX {
  interface IntrinsicElements {
    'css-doodle': {}
  }
}

And then, you can use <css-doodle>. (Unfortunately, it seems that there is no type definition yet.)

import React from 'react';
import 'css-doodle';

const Doodle: React.FunctionComponent = () => {
  // code is referenced from https://alligator.io/css/patterns-css-doodle/
  return (
    <css-doodle>
      {`
      :doodle {
        @grid: 5x8 / 100% 15rem;
      }
      :after {
        content: "@index()"
      }
      background: pink;
      margin: .5rem;
    `}
    </css-doodle>
  );
};

export default Doodle;

hmm.
Really nice πŸ₯°

from css-doodle.

simonmarton avatar simonmarton commented on May 21, 2024 7

I think a template string helper would be nice too, similar to styled-components.
Something like this:

/* doodle.js */

import React from 'react';
import 'css-doodle';

export default ([ rule = '' ]) => () => (
  <css-doodle>{ rule }</css-doodle>
);
/* example.js */

import Doodle from './doodle';

const FancyDoodle = Doodle`
  :doodle {
    @grid: 2 / 200px;
    grid-gap: 1px;
  }
  background: @pick(red, pink);
`;

...

<FancyDoodle />

from css-doodle.

hiteshsahu avatar hiteshsahu commented on May 21, 2024 3

Sample https://codesandbox.io/s/vjjq6686y0

from css-doodle.

yuanchuan avatar yuanchuan commented on May 21, 2024 3

No need to wrap around. Just use it directly!

import 'css-doodle';

function App() {
  return (
    <css-doodle>{`
      :doodle {
        @grid: 2 / 200px;
        grid: 1px;
      }
      background: @pick(red, pink);
    `}</css-doodle>
  );
}

from css-doodle.

yuanchuan avatar yuanchuan commented on May 21, 2024

@hiteshsahu Thank you :D

from css-doodle.

yuanchuan avatar yuanchuan commented on May 21, 2024

@simonmarton Nice!

from css-doodle.

papan01 avatar papan01 commented on May 21, 2024

Does this support tsx?

from css-doodle.

yuanchuan avatar yuanchuan commented on May 21, 2024

@papan01 Nope

from css-doodle.

papan01 avatar papan01 commented on May 21, 2024

@Mizumaki That’s right! Thank you πŸ™‡

from css-doodle.

Alfxjx avatar Alfxjx commented on May 21, 2024
import React from "react";

const Doodle = (rule) => () => {
	React.useEffect(() => {
		const script = document.createElement("script");
		script.src = "https://unpkg.com/[email protected]/css-doodle.min.js";
		document.body.appendChild(script);
	}, []);
	return <css-doodle>{rule}</css-doodle>;
};

export { Doodle };

use next.js and css-doodles

from css-doodle.

vitpankin avatar vitpankin commented on May 21, 2024

For Typescript I had to add

declare global {
   declare namespace JSX {
      interface IntrinsicElements {
      'css-doodle': {}
    }
  }
}

from css-doodle.

surajsharma avatar surajsharma commented on May 21, 2024

anyone tried this with react-native?

from css-doodle.

Related Issues (20)

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.