Giter VIP home page Giter VIP logo

Comments (8)

yysun avatar yysun commented on May 12, 2024 1

from apprun.

yysun avatar yysun commented on May 12, 2024 1

Changed in 1.18.2.

from apprun.

yysun avatar yysun commented on May 12, 2024

You can define the class or CSS in the view function of your components.

class MyClass extends Component {

  view = state => <div class='myClass' styles={{ 'color': 'red' }}>
  </div>

}

from apprun.

bo-kh avatar bo-kh commented on May 12, 2024

I will explain my thoughts with a simplified example. Let's pretend I have a useful stateful component Stars.tsx that I would like to re-use in my application several times:

Stars.tsx

import app, {Component} from 'apprun';

export default class Stars extends Component
{
  view = state => <div class="stars">
    <span>Here should be stars...</span>
  </div>
}

In my main.tsx (for example) I would like to re-use this component this way:

import app from 'apprun';

import Stars from './Stars';

const view = state => <div className="container">
  <h2>Stars app</h2>
  <Stars id="star1" className="stars-new" />
  <Stars id="star2" className="stars-new" />
</div>;

app.start('main', {}, view, {});

After I have run this example I will see the next situation in devTool:
image

Here are two wrapping divs with Ids "star1" and "star2" that Component adds (not me :))

So, the question is: could I suppress creating wrapping divs "star1" and "star2" within stateful components or could you add at least an ability to handle className property in this wrapping div that a developer could apply CSS rules by class name (in my example "stars-new")? It's not good to define these divs' CSS rules by id every time I use Stars component.

from apprun.

yysun avatar yysun commented on May 12, 2024

I have pushed a fix 7ca2764. It sets props to the div wrapper.

  it("should set props to child component's div wrapper", () => {
    class Child extends Component {
    }
    class Main extends Component {
      view = _ => <>
        <Child class="c1" id="c1" />
        <Child className="c2" />
        <Child style={{ 'color': 'red' }} />
        <Child data-a='a' />
      </>;
    }
    const element = document.createElement('div');
    app.render(element, <Main />);
    const main = element.children[0];
    expect(main.children[0].id).toBe("c1");
    expect(main.children[0].className).toBe("c1");
    expect(main.children[1].className).toBe("c2");
    expect((main.children[2] as HTMLDivElement).style.color).toBe("red");
    expect((main.children[3] as HTMLDivElement).dataset.a).toBe("a");
  });

from apprun.

bo-kh avatar bo-kh commented on May 12, 2024

Thank you! The fix looks good and simple. So far I like this small but very powerful library.

from apprun.

yysun avatar yysun commented on May 12, 2024

@bo-kh, I am thinking to change the component wrapper element from div to section. Will this change break your code?

from apprun.

bo-kh avatar bo-kh commented on May 12, 2024

@yysun, No, this change doesn't affect my code much. Semantically section suits better for the component wrapper purpose

from apprun.

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.