Code Monkey home page Code Monkey logo

Comments (6)

falkoschindler avatar falkoschindler commented on June 11, 2024 1

I just closed PR #2301, because we're no longer convinced that it is a good idea to add additional layers to ui.card to fix a layout inconsistency between NiceGUI and Quasar. Instead, I propose the following:

  1. Change ui.card to mimic QCard more closely. It won't add padding and gaps anymore, and requires to use ui.card_section where padding is required. This is like the old ui.card().tight(). For convenience, we can add QCard's style props as parameters:

    ui.card(*, square: bool = False, flat: bool = False, bordered: bool = False)
  2. Introduce a new ui.box element which behaves like the old ui.card. But instead of using QCard, it is simply a ui.column with optional shadow, border and/or rounded corners. Like the old ui.column and ui.card it adds padding and gaps. Replicating QCard's style props the signature might look like this:

    ui.box(*, square: bool = False, flat: bool = False, bordered: bool = False)

    Or we use more independent and maybe more intuitive parameter names like this:

    ui.box(*, rounded: bool = True, shadow: bool = True, border: bool = False)

Even though this requires all users to change ui.card to ui.box when migrating to NiceGUI 2.0.0, this is a much cleaner solution with less caveats compared to the old ui.card, which almost behaves like QCard, but leads to strange results when nesting bordered elements.

from nicegui.

falkoschindler avatar falkoschindler commented on June 11, 2024

Hi @ghbm-itk, this is an unfortunate consequence of how NiceGUI adds default padding to ui.card, which Quasar doesn't. It has been discussed in #726 and #1295 (comment) and is documented here.

from nicegui.

ghbm-itk avatar ghbm-itk commented on June 11, 2024

Since the problem is so easily fixed by simply wrapping the element in another element, it seems like something should be possible to fix. I don't understand the backend of NiceGui well enough yet, but I will look into it at some point.

Could a simple hotfix be something like: "If parent is a card wrap this element." ?

from nicegui.

falkoschindler avatar falkoschindler commented on June 11, 2024

@ghbm-itk I don't think it's a good idea to automatically change the element hierarchy, because it would break certain assumptions (see #2040 for a discussion about a similar case).

I tried once again to undo Quasar's CSS magic - without success. But I found a way to wrap the card content in a separate div, so that it isn't affected by the Quasar's CSS; see PR #2301. What do you think?

from nicegui.

ghbm-itk avatar ghbm-itk commented on June 11, 2024

@falkoschindler Isn't that just q-card-section reinvented? When looking at the examples on quasar.dev it seems that all content in cards is wrapped in card sections:

<q-card>
  <q-card-section>
    <div class="text-h6">Our Changing Planet</div>
    <div class="text-subtitle2">by John Doe</div>
  </q-card-section>
</q-card>

from nicegui.

falkoschindler avatar falkoschindler commented on June 11, 2024

@ghbm-itk Sorry for the late reply. I think it's a bit different:

  • QCards usually don't have any padding. But you can add padding with QCardSections:

    with ui.element('q-card'):
        ui.label('No padding.').classes('border')
    
    with ui.element('q-card'):
        with ui.element('q-card-section'):
            ui.label('Padding.').classes('border')
    Screenshot 2024-02-10 at 23 22 18
  • ui.card comes with padding by default. But in order for Quasar not removing borders of nested elements, adding another container layer helps:

    with ui.card():
        ui.label('Padding.').classes('border')
    
    with ui.card():
        with ui.element():
            ui.label('Padding.').classes('border')
    Screenshot 2024-02-10 at 23 22 56

from nicegui.

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.