diff --git a/elements/package.json b/elements/package.json index 261eb04fcb..03d9b5d07f 100644 --- a/elements/package.json +++ b/elements/package.json @@ -27,6 +27,7 @@ "./pf-button/pf-button.js": "./pf-button/pf-button.js", "./pf-card/BaseCard.js": "./pf-card/BaseCard.js", "./pf-card/pf-card.js": "./pf-card/pf-card.js", + "./pf-checkbox/pf-checkbox.js": "./pf-checkbox/pf-checkbox.js", "./pf-chip/pf-chip.js": "./pf-chip/pf-chip.js", "./pf-chip/pf-chip-group.js": "./pf-chip/pf-chip-group.js", "./pf-clipboard-copy/BaseClipboardCopy.js": "./pf-clipboard-copy/BaseClipboardCopy.js", diff --git a/elements/pf-checkbox/README.md b/elements/pf-checkbox/README.md new file mode 100644 index 0000000000..d243c8c140 --- /dev/null +++ b/elements/pf-checkbox/README.md @@ -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 + + + +``` diff --git a/elements/pf-checkbox/demo/demo.css b/elements/pf-checkbox/demo/demo.css new file mode 100644 index 0000000000..a8b9094be6 --- /dev/null +++ b/elements/pf-checkbox/demo/demo.css @@ -0,0 +1,3 @@ +pf-checkbox { + /* insert demo styles */ +} diff --git a/elements/pf-checkbox/demo/pf-checkbox.html b/elements/pf-checkbox/demo/pf-checkbox.html new file mode 100644 index 0000000000..8f905a156c --- /dev/null +++ b/elements/pf-checkbox/demo/pf-checkbox.html @@ -0,0 +1,6 @@ + + + + diff --git a/elements/pf-checkbox/docs/pf-checkbox.md b/elements/pf-checkbox/docs/pf-checkbox.md new file mode 100644 index 0000000000..06c8517ca1 --- /dev/null +++ b/elements/pf-checkbox/docs/pf-checkbox.md @@ -0,0 +1,17 @@ +{% renderOverview %} + +{% endrenderOverview %} + +{% band header="Usage" %}{% endband %} + +{% renderSlots %}{% endrenderSlots %} + +{% renderAttributes %}{% endrenderAttributes %} + +{% renderMethods %}{% endrenderMethods %} + +{% renderEvents %}{% endrenderEvents %} + +{% renderCssCustomProperties %}{% endrenderCssCustomProperties %} + +{% renderCssParts %}{% endrenderCssParts %} diff --git a/elements/pf-checkbox/pf-checkbox.css b/elements/pf-checkbox/pf-checkbox.css new file mode 100644 index 0000000000..e1f4103c9e --- /dev/null +++ b/elements/pf-checkbox/pf-checkbox.css @@ -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; +} + diff --git a/elements/pf-checkbox/pf-checkbox.ts b/elements/pf-checkbox/pf-checkbox.ts new file mode 100644 index 0000000000..002db1cc80 --- /dev/null +++ b/elements/pf-checkbox/pf-checkbox.ts @@ -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` + +
+

Uncontrolled

+
+ + +
+
+
+ `; + } +} + + +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'); +// }); + diff --git a/elements/pf-checkbox/test/pf-checkbox.e2e.ts b/elements/pf-checkbox/test/pf-checkbox.e2e.ts new file mode 100644 index 0000000000..eabfb4ee2a --- /dev/null +++ b/elements/pf-checkbox/test/pf-checkbox.e2e.ts @@ -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(); + }); +}); diff --git a/elements/pf-checkbox/test/pf-checkbox.spec.ts b/elements/pf-checkbox/test/pf-checkbox.spec.ts new file mode 100644 index 0000000000..a2c142ae2c --- /dev/null +++ b/elements/pf-checkbox/test/pf-checkbox.spec.ts @@ -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('', 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(html``); + const klass = customElements.get('pf-checkbox'); + expect(element) + .to.be.an.instanceOf(klass) + .and + .to.be.an.instanceOf(PfCheckbox); + }); + }); +});