-
Notifications
You must be signed in to change notification settings - Fork 96
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
Naresh jupalle
committed
Jun 21, 2024
1 parent
492a901
commit 320d251
Showing
9 changed files
with
163 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
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,11 @@ | ||
# Checkbox | ||
Add a description of the component here. | ||
|
||
## Usage | ||
Describe how best to use this web component along with best practices. | ||
|
||
```html | ||
<pf-checkbox> | ||
|
||
</pf-checkbox> | ||
``` |
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 @@ | ||
pf-checkbox { | ||
/* insert demo styles */ | ||
} |
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,6 @@ | ||
<link rel="stylesheet" href="demo.css"> | ||
<script type="module"> | ||
import '@patternfly/elements/pf-checkbox/pf-checkbox.js'; | ||
</script> | ||
|
||
<pf-checkbox></pf-checkbox> |
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,17 @@ | ||
{% renderOverview %} | ||
<pf-checkbox></pf-checkbox> | ||
{% endrenderOverview %} | ||
|
||
{% band header="Usage" %}{% endband %} | ||
|
||
{% renderSlots %}{% endrenderSlots %} | ||
|
||
{% renderAttributes %}{% endrenderAttributes %} | ||
|
||
{% renderMethods %}{% endrenderMethods %} | ||
|
||
{% renderEvents %}{% endrenderEvents %} | ||
|
||
{% renderCssCustomProperties %}{% endrenderCssCustomProperties %} | ||
|
||
{% renderCssParts %}{% endrenderCssParts %} |
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,21 @@ | ||
.container { | ||
/* padding: 12px 8px; */ | ||
margin: 48px; | ||
} | ||
|
||
.container .heading { | ||
margin:0 0 12px 0; | ||
font-size: 16px; | ||
font-weight: 600; | ||
color:#514646; | ||
} | ||
|
||
.container .pf-c-check { | ||
padding-left: 16px; | ||
} | ||
|
||
.container .heading__controlled { | ||
margin-top: 8px; | ||
margin-bottom: 0px; | ||
} | ||
|
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,71 @@ | ||
import { LitElement, html } from 'lit'; | ||
import { customElement } from 'lit/decorators/custom-element.js'; | ||
|
||
import styles from './pf-checkbox.css'; | ||
|
||
/** | ||
* Checkbox | ||
* @slot - Place element content here | ||
*/ | ||
@customElement('pf-checkbox') | ||
export class PfCheckbox extends LitElement { | ||
static readonly styles = [styles]; | ||
|
||
#getElement() { | ||
const checkbox = document.querySelector('pf-checkbox'); | ||
const checkbasic = checkbox!.shadowRoot!.getElementById('check-basic') as HTMLInputElement; | ||
return checkbasic; | ||
} | ||
|
||
keydown(event: KeyboardEvent) { | ||
const checkbox = this.#getElement(); | ||
if (event.code === 'Enter' || event.code === 'Space') { | ||
event.preventDefault(); | ||
checkbox.checked = !checkbox.checked; | ||
// Optionally, you can also update aria-checked attribute for screen readers | ||
checkbox.setAttribute('aria-checked', checkbox.checked ? 'true' : 'false'); | ||
} | ||
} | ||
|
||
click() { | ||
const checkbox = this.#getElement(); | ||
checkbox.setAttribute('aria-checked', checkbox.checked ? 'true' : 'false'); | ||
} | ||
|
||
render() { | ||
return html` | ||
<slot> | ||
<div class="container"> | ||
<h1 class="heading">Uncontrolled </h1> | ||
<div class="pf-c-check"> | ||
<input | ||
class="pf-c-check__input" | ||
type="checkbox" | ||
id="check-basic" | ||
name="check-basic" | ||
@keydown=${this.keydown} | ||
@click=${this.click} | ||
/> | ||
<label class="pf-c-check__label" for="check-basic">Uncontrolled CheckBox </label> | ||
</div> | ||
</div> | ||
</slot> | ||
`; | ||
} | ||
} | ||
|
||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'pf-checkbox': PfCheckbox; | ||
} | ||
} | ||
|
||
// | ||
|
||
// checkbox.addEventListener('click', function(event) { | ||
// // Update aria-checked attribute for screen readers | ||
// checkbox.setAttribute('aria-checked', checkbox.checked ? 'true' : 'false'); | ||
// }); | ||
|
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,12 @@ | ||
import { test } from '@playwright/test'; | ||
import { PfeDemoPage } from '@patternfly/pfe-tools/test/playwright/PfeDemoPage.js'; | ||
|
||
const tagName = 'pf-checkbox'; | ||
|
||
test.describe(tagName, () => { | ||
test('snapshot', async ({ page }) => { | ||
const componentPage = new PfeDemoPage(page, tagName); | ||
await componentPage.navigate(); | ||
await componentPage.snapshot(); | ||
}); | ||
}); |
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,21 @@ | ||
import { expect, html } from '@open-wc/testing'; | ||
import { createFixture } from '@patternfly/pfe-tools/test/create-fixture.js'; | ||
import { PfCheckbox } from '@patternfly/elements/pf-checkbox/pf-checkbox.js'; | ||
|
||
describe('<pf-checkbox>', function() { | ||
describe('simply instantiating', function() { | ||
let element: PfCheckbox; | ||
it('imperatively instantiates', function() { | ||
expect(document.createElement('pf-checkbox')).to.be.an.instanceof(PfCheckbox); | ||
}); | ||
|
||
it('should upgrade', async function() { | ||
element = await createFixture<PfCheckbox>(html`<pf-checkbox></pf-checkbox>`); | ||
const klass = customElements.get('pf-checkbox'); | ||
expect(element) | ||
.to.be.an.instanceOf(klass) | ||
.and | ||
.to.be.an.instanceOf(PfCheckbox); | ||
}); | ||
}); | ||
}); |