-
Notifications
You must be signed in to change notification settings - Fork 930
feat(components): add ui field in items
#4060
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
Conversation
commit: |
|
I agree this is a nice addition! However, this change should be applied to all components with an |
|
@benjamincanac I can work on this. Should I bunch it up into a one big PR or should I create separate PR for each instance? |
|
Great! No you can do this in this PR π |
iconClass field in items
|
Quick checklist to track the progress on this (I will validate it as I go through it):
|
|
@benjamincanac Just one more idea, what if we added a i.e. for the Accordion each item could have a <AccordionItem
v-for="(item, index) in props.items"
v-slot="{ open }"
:key="index"
:value="item.value || String(index)"
:disabled="item.disabled"
:class="ui.item({ class: [props.ui?.item, item.ui?.item] })"
>
<AccordionHeader as="div" :class="ui.header({ class: [props.ui?.header, item.ui?.header] })">
<AccordionTrigger :class="ui.trigger({ class: [props.ui?.trigger, item.ui?.trigger], disabled: item.disabled })">
<slot name="leading" :item="item" :index="index" :open="open">
<UIcon v-if="item.icon" :name="item.icon" :class="ui.leadingIcon({ class: [props.ui?.leadingIcon, item?.ui?.leadingIcon] })" />
</slot>
<span v-if="get(item, props.labelKey as string) || !!slots.default" :class="ui.label({ class: [props.ui?.label, item.ui?.label] })">
<slot :item="item" :index="index" :open="open">{{ get(item, props.labelKey as string) }}</slot>
</span>
<slot name="trailing" :item="item" :index="index" :open="open">
<UIcon :name="item.trailingIcon || trailingIcon || appConfig.ui.icons.chevronDown" :class="ui.trailingIcon({ class: [props.ui?.trailingIcon, item.ui?.trailingIcon] })" />
</slot>
</AccordionTrigger>
</AccordionHeader>
<AccordionContent v-if="item.content || !!slots.content || (item.slot && !!slots[item.slot as keyof AccordionSlots<T>]) || !!slots.body || (item.slot && !!slots[`${item.slot}-body` as keyof AccordionSlots<T>])" :class="ui.content({ class: [props.ui?.content, item.ui?.content] })">
<slot :name="((item.slot || 'content') as keyof AccordionSlots<T>)" :item="(item as Extract<T, { slot: string; }>)" :index="index" :open="open">
<div :class="ui.body({ class: [props.ui?.body, item.ui?.body] })">
<slot :name="((item.slot ? `${item.slot}-body`: 'body') as keyof AccordionSlots<T>)" :item="(item as Extract<T, { slot: string; }>)" :index="index" :open="open">
{{ item.content }}
</slot>
</div>
</slot>
</AccordionContent>
</AccordionItem>I feel like it would be more future proof as everyone might have different needs of per item customization, of course this is more involved solution but I think it might be worth it. |
|
We could uniformize this as well indeed, I did it in very specific places where I needed to make an example only at the moment: https://github.com/nuxt/ui/blob/v3/src/runtime/components/Select.vue#L243 |
|
@benjamincanac Here is a quick commit for the accordion component, if you could quickly have a look if I'm going in the right direction with this. |
Maybe I'm being too specific with this? The use can see it in detail in the props section.
iconClass field in itemsui field in items
β¦ek/ui into feat/stepper-icon-class
|
My mistake, you got a sharp eyes! Thanks for your reviews btw. Fixed in feb7ca7 |
|
@J-Michalek I've pushed a few fixes, let me know what you think! Is there a reason you ommitted the CommandPalette component? |
test/components/Accordion.spec.ts
Outdated
| ['with body slot', { props: { ...props, modelValue: '1' }, slots: { body: () => 'Body slot' } }], | ||
| ['with custom slot', { props: { ...props, modelValue: '5' }, slots: { custom: () => 'Custom slot' } }], | ||
| ['with custom body slot', { props: { ...props, modelValue: '5' }, slots: { 'custom-body': () => 'Custom body slot' } }] | ||
| ['with custom body slot', { props: { ...props, modelValue: '5' }, slots: { 'custom-body': () => 'Custom body slot' } }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it's a good idea to test everything item.ui here, it's a lot and will be a pain to maintain π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was unsure if I should add test cases for it, I guess we can remove it it is easily the largest block of test code for all of the affected component.
It would be annoying to maintain these.
It was under groups by mistake.
|
Thanks for the fixes, seems I was pretty sloppy π I've implemented |
|
Not at all! You did an amazing job, thanks a lot π |
|
@J-Michalek I've made a mistake regarding #4060 (comment) and reverted it here: 0905b2b. My argument was that for consistency the Let me know if I forgot some other places. |
|
Looks good, I checked my commits that made the original breaking changes and they only affected the |
π Linked issue
Resolves: #4059
β Type of change
π Description
I have added the
uifield initemsarray - this affects all components that currently use anitemsprop.This will simplify cases where the user wants to use a specific classes for different parts of an item but does not want to affect other items at the same time.
π Checklist