@@ -4,19 +4,17 @@ import ZincElement from '../../internal/zinc-element';
44
55import styles from './panel.scss' ;
66import { classMap } from "lit/directives/class-map.js" ;
7+ import { HasSlotController } from "../../internal/slot" ;
78
89/**
910 * @summary Short summary of the component's intended use.
1011 * @documentation https://zinc.style/components/panel
1112 * @status experimental
1213 * @since 1.0
1314 *
14- * @dependency zn-example
15- *
16- * @event zn-event-name - Emitted as an example.
17- *
1815 * @slot - The default slot.
19- * @slot example - An example slot.
16+ * @slot actions - The actions slot.
17+ * @slot footer - The footer slot.
2018 *
2119 * @csspart base - The component's base wrapper.
2220 *
@@ -25,17 +23,26 @@ import {classMap} from "lit/directives/class-map.js";
2523export default class ZnPanel extends ZincElement {
2624 static styles : CSSResultGroup = unsafeCSS ( styles ) ;
2725
28- @property ( { attribute : 'basis-px' , type : Number , reflect : true } ) basis : number ;
29- @property ( { attribute : 'caption' , type : String , reflect : true } ) caption : string ;
30- @property ( { attribute : 'rows' , type : Number , reflect : true } ) rows : number ;
31- @property ( { attribute : 'tabbed' , type : Boolean , reflect : true } ) tabbed : boolean ;
26+ private readonly hasSlotController = new HasSlotController ( this , '[default]' , 'actions' , 'footer' ) ;
27+
28+ @property ( { type : Number } ) basis : number ;
29+
30+ @property ( ) caption : string ;
31+
32+ @property ( { type : Boolean } ) tabbed : boolean ;
33+
3234 @property ( { type : Boolean } ) flush : boolean ;
3335
3436
3537 protected firstUpdated ( _changedProperties : PropertyValues ) {
3638 super . firstUpdated ( _changedProperties ) ;
39+
40+ if ( this . basis ) {
41+ this . style . setProperty ( '--zn-panel-basis' , this . basis . toString ( ) ) ;
42+ }
43+
3744 if ( ! this . tabbed ) {
38- const tabs = this . querySelector ( 'zn-tabs' ) ;
45+ const tabs = this . querySelector ( 'zn-tabs' ) ! ;
3946 if ( tabs ) {
4047 tabs . setAttribute ( 'flush-x' , '' ) ;
4148 const body = this . shadowRoot ?. querySelector ( '.body' ) ;
@@ -46,48 +53,37 @@ export default class ZnPanel extends ZincElement {
4653 }
4754 }
4855
49- protected render ( ) : unknown {
50- if ( this . basis > 0 ) {
51- this . style . flexBasis = this . basis + 'px' ;
52- }
53-
54- const footerItems = this . querySelectorAll ( '[slot="footer"]' ) . length > 0 ;
55- const actionItems = this . querySelectorAll ( '[slot="actions"]' ) . length > 0 ;
56-
57- if ( this . rows > 0 ) {
58- this . style . setProperty ( '--row-count' , this . rows . toString ( ) ) ;
59- }
60-
61- let header ;
62- if ( actionItems || this . caption || this . firstChild ?. nodeName == 'ZN-TABS' ) {
63- // zn-tabs uses the header as top-padding
64- header = html `
65- < div class ="header ">
66- < span > ${ this . caption } </ span >
67- < slot name ="actions " class ="header__actions "> </ slot >
68- </ div >
69- ` ;
70- }
7156
72- let footer ;
73- if ( footerItems ) {
74- footer = html `
75- < div class ="footer ">
76- < slot name ="footer "> </ slot >
77- </ div > ` ;
78- }
57+ protected render ( ) : unknown {
58+ const hasActionSlot = this . hasSlotController . test ( 'actions' ) ;
59+ const hasFooterSlot = this . hasSlotController . test ( 'footer' ) ;
60+ const hasHeader = this . caption || hasActionSlot ;
7961
8062 return html `
81- < div class =${ classMap ( {
63+ < div part =" base " class =${ classMap ( {
8264 panel : true ,
83- 'panel--flush' : this . flush || this . tabbed
65+ 'panel--flush' : this . flush || this . tabbed ,
66+ 'panel--tabbed' : this . tabbed ,
67+ 'panel--has-actions' : hasActionSlot ,
68+ 'panel--has-footer' : hasFooterSlot ,
69+ 'panel--has-header' : hasHeader ,
8470 } ) } >
85- < div > ${ header }
86- < div class ="panel__body body ">
87- < slot > </ slot >
71+
72+ ${ hasHeader ? html `
73+ < div class ="panel__header ">
74+ < span class ="panel__caption "> ${ this . caption } </ span >
75+ ${ hasActionSlot ? html `
76+ < slot name ="actions " class ="panel__header__actions "> </ slot >
77+ ` : null }
8878 </ div >
89- ${ footer }
79+ ` : null }
80+
81+ < div class ="panel__body ">
82+ < slot > </ slot >
9083 </ div >
84+
85+ ${ hasFooterSlot ? html `
86+ < slot name ="footer " class ="panel__footer "> </ slot > ` : null }
9187 </ div > ` ;
9288 }
9389}
0 commit comments