Skip to content

Commit 9edcaab

Browse files
committed
feat(Panel): accept custom css classes for internal containers
1 parent fd7a211 commit 9edcaab

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/components/Dialog.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
import AButton from './Button.vue'
1010
import APanel from './Panel.vue'
1111
12+
type ClassValue = string | string[] | Record<string, boolean>
13+
1214
export default defineComponent({
1315
name: 'ADialog',
1416
components: { HlDialog, HlDialogPanel, HlDialogTitle, AButton, APanel },
@@ -36,6 +38,20 @@ export default defineComponent({
3638
position: {
3739
type: String as PropType<'top' | 'center' | 'bottom'>,
3840
default: 'top'
41+
},
42+
/**
43+
* Custom classes for internal panel containers. Passed through to APanel.
44+
* - `title`: merged with panel title defaults
45+
* - `body`: merged with panel body defaults
46+
* - `actions`: merged with panel actions defaults
47+
*/
48+
classes: {
49+
type: Object as PropType<{
50+
title?: ClassValue
51+
body?: ClassValue
52+
actions?: ClassValue
53+
}>,
54+
default: () => ({})
3955
}
4056
},
4157
emits: ['close'],
@@ -70,7 +86,7 @@ export default defineComponent({
7086
<slot></slot>
7187
</HlDialogPanel>
7288
<HlDialogPanel v-else class="contents">
73-
<APanel class="m-[5rem] min-w-[20rem] overflow-auto">
89+
<APanel class="m-[5rem] min-w-[20rem] overflow-auto" :classes="classes">
7490
<!-- this snippet passes up all the wrapper component's slots -->
7591
<template v-for="(_, slot) in $slots" #[slot]="scope">
7692
<slot :name="slot" v-bind="scope || {}" />

src/components/Panel.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
22
import { defineComponent, PropType, Component } from 'vue'
33
4+
type ClassValue = string | string[] | Record<string, boolean>
5+
46
export default defineComponent({
57
name: 'APanel',
68
props: {
@@ -15,13 +17,27 @@ export default defineComponent({
1517
as: {
1618
type: [Object, String] as PropType<Component | keyof HTMLElementTagNameMap>,
1719
default: 'div'
20+
},
21+
/**
22+
* Custom classes for internal containers. Merged with default classes.
23+
* - `title`: merged with (min-h-10 px-6 pt-2 heading-sm)
24+
* - `body`: merged with (overflow-auto px-6 py-4 body-md)
25+
* - `actions`: merged with (mt-auto flex h-16 items-center gap-2 rounded-b border-t border-gray bg-athens px-6 py-3)
26+
*/
27+
classes: {
28+
type: Object as PropType<{
29+
title?: ClassValue
30+
body?: ClassValue
31+
actions?: ClassValue
32+
}>,
33+
default: () => ({})
1834
}
1935
}
2036
})
2137
</script>
2238
<template>
2339
<div class="a-panel-lg flex flex-col whitespace-pre-line rounded bg-white">
24-
<div v-if="$slots.title || title" class="min-h-10 px-6 pt-2 heading-sm">
40+
<div v-if="$slots.title || title" class="min-h-10 px-6 pt-2 heading-sm" :class="classes.title">
2541
<!--
2642
@slot #title
2743
For simple strings, use the `title` prop.
@@ -31,7 +47,7 @@ export default defineComponent({
3147
{{ title }}
3248
</slot>
3349
</div>
34-
<div class="overflow-auto px-6 py-4 body-md">
50+
<div class="overflow-auto px-6 py-4 body-md" :class="classes.body">
3551
<!--
3652
@slot #body
3753
This is a padded container with typography styles
@@ -40,7 +56,8 @@ export default defineComponent({
4056
</div>
4157
<div
4258
v-if="$slots.actions"
43-
class="mt-auto flex h-16 items-center gap-2 rounded-b border-t border-gray bg-athens px-6 py-3">
59+
class="mt-auto flex h-16 items-center gap-2 rounded-b border-t border-gray bg-athens px-6 py-3"
60+
:class="classes.actions">
4461
<!--
4562
@slot #actions
4663
Use the slot to provide buttons for user actions.

0 commit comments

Comments
 (0)