-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7373d5
commit 8b4dbac
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.btn { | ||
--bs-btn-padding-x: 0; | ||
--bs-btn-padding-y: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import styles from '!!raw-loader!./Clickable.css'; | ||
import varStyles from '!!raw-loader!../../../shared/variables.css'; | ||
import bootstrapStyles from '!!raw-loader!../../../shared/themed-bootstrap.css'; | ||
|
||
const template = document.createElement('template'); | ||
|
||
// A space for some clickable content. | ||
template.innerHTML = ` | ||
<slot></slot> | ||
`; | ||
|
||
export default class Clickable extends HTMLElement { | ||
constructor() { | ||
// Always call super constructor. | ||
super(); | ||
|
||
// Create a shadow root. | ||
this.attachShadow({ mode: 'open' }); | ||
} | ||
|
||
connectedCallback() { | ||
this.shadowRoot.addEventListener('slotchange', (ev) => { | ||
const elements = ev.target.assignedElements(); | ||
elements.forEach((element) => { | ||
if (typeof element.setIsClickable === 'function') { | ||
const btnColor = this.getAttribute('data-btn-color'); | ||
element.setIsClickable(true, btnColor); | ||
} | ||
}); | ||
this.clickable.append(...elements); | ||
}); | ||
|
||
// Create component. | ||
this.clickable = document.createElement('a'); | ||
|
||
// Add styles. | ||
const bootStyles = document.createElement('style'); | ||
bootStyles.textContent = bootstrapStyles; | ||
const variableStyles = document.createElement('style'); | ||
variableStyles.textContent = varStyles; | ||
const itemStyles = document.createElement('style'); | ||
itemStyles.textContent = styles; | ||
this.shadowRoot.appendChild(bootStyles); | ||
this.shadowRoot.appendChild(variableStyles); | ||
this.shadowRoot.appendChild(itemStyles); | ||
|
||
// Set attributes on node. | ||
const href = this.getAttribute('href'); | ||
this.clickable.setAttribute('href', href); | ||
const target = this.getAttribute('target'); | ||
this.clickable.setAttribute('target', target); | ||
|
||
// Set bootstrap classes. | ||
const btnColor = this.getAttribute('data-btn-color'); | ||
this.clickable.classList.add('btn', btnColor); | ||
|
||
// Add slot to clickable area. | ||
this.clickable.appendChild(template.content.cloneNode(true)); | ||
this.shadowRoot.appendChild(this.clickable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Clickable from './Clickable'; | ||
|
||
customElements.define('cod-clickable', Clickable); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { html } from 'lit-html'; | ||
import '../components/atoms/Clickable/cod-clickable'; | ||
import '../components/organisms/Card/cod-card'; | ||
import '../components/atoms/CardIconContainer/cod-card-icon-container'; | ||
import '../components/atoms/Icon/cod-icon'; | ||
import '../components/atoms/CardBody/cod-card-body'; | ||
|
||
export default { | ||
title: 'Components/Atoms/Clickable', | ||
}; | ||
|
||
export const ActionButton = () => html` | ||
<cod-clickable href="https://example.com" target="_blank" data-btn-color="btn-primary"> | ||
<cod-card | ||
data-id="card-as-action-button" | ||
data-width="18em" | ||
> | ||
<cod-card-icon-container> | ||
<cod-icon data-icon="house" data-size="x-large" /> | ||
</cod-card-icon-container> | ||
<cod-card-body> | ||
<h5 class="card-title">Do Something</h5> | ||
<p class="card-text">Like click on this card.</p> | ||
</cod-card-body> | ||
</cod-card> | ||
</clickable> | ||
`; | ||
|
||
export const ActionButtonSuccess = () => html` | ||
<cod-clickable href="https://example.com" target="_blank" data-btn-color="btn-success"> | ||
<cod-card | ||
data-id="card-as-action-button" | ||
data-width="18em" | ||
> | ||
<cod-card-icon-container> | ||
<cod-icon data-icon="house" data-size="x-large" /> | ||
</cod-card-icon-container> | ||
<cod-card-body> | ||
<h5 class="card-title">Do Something</h5> | ||
<p class="card-text">Like click on this card.</p> | ||
</cod-card-body> | ||
</cod-card> | ||
</clickable> | ||
`; |