Skip to content

Commit

Permalink
feat: collapsible tab card
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloBar1 committed Jan 29, 2024
1 parent 2f96ac2 commit f0421d6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"./next/*": "./src/next/*"
},
"dependencies": {
"@neovici/cosmoz-collapse": "^1.3.0",
"@neovici/cosmoz-router": "^11.0.0",
"@neovici/cosmoz-utils": "^6.0.0",
"@pionjs/pion": "^2.0.0",
Expand Down
28 changes: 20 additions & 8 deletions src/cosmoz-tab-card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @license Copyright (C) 2015 Neovici AB - Apache 2 License
import { html, component } from '@pionjs/pion';

import '@neovici/cosmoz-collapse';
import { useState } from 'haunted';

Check failure on line 4 in src/cosmoz-tab-card.js

View workflow job for this annotation

GitHub Actions / build / build

Unable to resolve path to module 'haunted'
/**
@demo demo/card.html
Expand All @@ -19,8 +20,11 @@ Custom property | Description | Default
`--cosmoz-tab-card-content-line-height` | Card content line height | `initial`
`--cosmoz-tab-card-content-padding` | Card content padding | `initial`
*/
const CosmozTabCard = ({ heading }) =>
html` <style>

const CosmozTabCard = ({ heading, canCollapse }) => {
const [collapsed, setCollapsed] = useState(false);

return html` <style>
:host {
display: block;
position: relative;
Expand Down Expand Up @@ -60,19 +64,27 @@ const CosmozTabCard = ({ heading }) =>
</style>
<div id="header" part="header">
<h1 class="heading" part="heading">
<h1
class="heading"
part="heading"
@click=${() => setCollapsed((c) => !c)}
>
${heading}<slot name="after-title"></slot>
</h1>
<slot name="card-actions"></slot>
</div>
<div id="content" part="content">
<slot></slot>
${canCollapse
? html`<cosmoz-collapse ?opened=${collapsed}
><slot></slot
></cosmoz-collapse>`
: html`<slot></slot>`}
</div>`;

};
customElements.define(
'cosmoz-tab-card',
component(CosmozTabCard, {
observedAttributes: ['heading'],
}),
observedAttributes: ['heading', 'can-collapse'],
})
);
2 changes: 1 addition & 1 deletion stories/cosmoz-tab-card.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const basics = () => html`
</cosmoz-tab-card>
</cosmoz-tab>
<cosmoz-tab heading="Tab2" name="tab2">
<cosmoz-tab-card heading="Card2">
<cosmoz-tab-card can-collapse heading="Card2">
<p>
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce non libero eget lorem interdum lacinia.
Vivamus eu libero lacus. Vestibulum blandit ornare orci non imperdiet. Aliquam condimentum lacus mauris, id aliquet lectus faucibus vel.
Expand Down

0 comments on commit f0421d6

Please sign in to comment.