-
-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use slots with props #501
Comments
This is using the example for the Quasar website: qtable.js
qtable.py
test_table.py
|
Hi @Allen-Taylor ! Thanks for your brillant demo. I had figured that out indeed, but this is a very user specific example here. I am not sure if I am able to explain that properly here: I am looking at a way to render a slot with props agnostically of what is inside so that this becomes an API of nicegui. |
Wouldn't you have to pass props you want to the Tr, Th and Td classes? The classes just set the tags as they currently stand. class Tr(Element):
def __init__(self) -> None:
super().__init__('q-tr')
class Th(Element):
def __init__(self) -> None:
super().__init__('q-th')
class Td(Element):
def __init__(self, key: str = '') -> None:
super().__init__('q-td')
if key:
self._props['key'] = key |
What I would like to, following the PR and it's example, is something this kind : with ui.table(title='Foo', rows=rows, columns=columns) as table:
with table.add_slot('body') as slot:
with ui.tr():
with ui.td(key='name'):
ui.label(slot.props.row.name).classes('text-center') Hence from the slot, retrieving the props injected by the vue component and use it within in the python code. |
Very interesting, @dclause! But I've also been struggling to really understand the idea, since I'm not that familiar with Vue and its advanced concepts. I think this is related to #167. But QTree has "ScopedSlots" and QTable doesn't. So maybe it is not the same... I don't know. Let me summarize: You want to control how a table row ("body" slot) or a cell ("body-cell" slot) is rendered. Because these elements are generated dynamically by Quasar, these slots don't exist in the Python world (yet). This is in contrast to slots like "top-row" which are uniquely named and can be created in Python to fill them with child elements. Currently I really don't know how to tackle the implementation of such dynamic (scoped?) slots. Do we need to introduce something like a template element in Python that is synced to the client? But how to inject the prop values? I think this is not an easy task and we shouldn't let the QTable component #500 depend on this. |
Hi @falkoschindler ! Scoped slot would be a nice to have in order to be able to create tables where a cell is an icon, of with action buttons in for instance. |
I guess this issue duplicates discussion at #167 and therefore can be closed. |
Currently writting a table component using QTable, I wish I could use slots where props is needed to be injected.
As you can check in PR https://github.com/zauberzeug/nicegui/pull/500/files,
I am able to use components slots for slots that are named but do not inject props.
I wish to use the component for use-cases like body-slot: https://quasar.dev/vue-components/table#body-slots where the slot exposes props.
How can we use props in the slots currently (ie how could I use the body slot in the PR's example above) ?
If not possible currently, could this be added as a feature in the roadmap and eventually, could you point at some directly on how to do it: I may be able to succeed to create a PR for it if guided.
Thanks for this amazing project and your help.
The text was updated successfully, but these errors were encountered: