Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@daun
Copy link
Contributor

@daun daun commented Nov 7, 2025

Wrap the widget component's header in a named slot to allow components without headers or with custom headers.

Example

Use case: we have a map widget that doesn't need – and looks better without – a header. Rendering an empty slot requires passing in an empty span or div. Just an empty template tag won't do, that's a limitation of Vue I think.

<ui-widget>
    <template v-slot:header><span></span></template>
    <div id="map"></div>
    <script type="module">
        const map = new mapboxgl.Map({ container: 'map', center: [2.2940, 48.8598] });
    </script>
</ui-widget>
Screenshot 2025-11-07 at 10 08 58

Note

Widget.vue now shows the header only if title, icon, or actions slot exist; props updated and icon/title rendered conditionally.

  • UI: resources/js/components/ui/Widget.vue
    • Conditional header: Introduces hasHeader (via useSlots/computed) to render <header> only when title, icon, or actions slot is present.
    • Conditional content: Renders Icon and title only if corresponding props are provided.
    • Props update: Replaces loose defineProps with typed props; removes default icon and href requirement.

Written by Cursor Bugbot for commit 737dadc. This will update automatically on new commits. Configure here.

@jasonvarga
Copy link
Member

Great idea but needing to pass an empty span feels a bit hacky. Maybe we can have a header="false" prop instead?

@daun
Copy link
Contributor Author

daun commented Nov 10, 2025

@jasonvarga True. I could change it to check for the existence of the slot, and hide it if it's defined but empty?

@jasonvarga
Copy link
Member

I mean forget a slot. Just have a header boolean prop and don't show the header if it's false.

@daun
Copy link
Contributor Author

daun commented Nov 10, 2025

I see. I was going to say it's still useful to have the slot to render custom headers/actions, but hiding the header and rendering whatever actions inside the default slot would work just as well. I'll turn it into a prop :)

@jackmcdade
Copy link
Member

I don't love having to set a prop to hide something if possible. I swapped this around so now if you have a title and/or icon it works the way it does now, otherwise you can push into the slot and override it. Looks cleaner to me.

@jasonvarga
Copy link
Member

jasonvarga commented Nov 10, 2025

Do we even need the header slot now? Omit the props and you can put your header in the default slot anyway.

@jackmcdade
Copy link
Member

Do we even need the header slot now? Omit the props and you can put your header in the default slot anyway.

Yeah I guess not!

@jasonvarga jasonvarga merged commit 49fe748 into statamic:master Nov 10, 2025
20 checks passed
@jasonvarga jasonvarga changed the title [6.x] Wrap widget header in a slot [6.x] Widget headers are optional Nov 10, 2025
@daun daun deleted the feature/widget-header-slot branch November 10, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants