Skip to content

Commit 693f7af

Browse files
committed
chore: added radio button component
1 parent fe349ea commit 693f7af

File tree

8 files changed

+136
-0
lines changed

8 files changed

+136
-0
lines changed

elements/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"./pf-jump-links/pf-jump-links-list.js": "./pf-jump-links/pf-jump-links-list.js",
3737
"./pf-jump-links/pf-jump-links.js": "./pf-jump-links/pf-jump-links.js",
3838
"./pf-label/pf-label.js": "./pf-label/pf-label.js",
39+
"./pf-radio/pf-radio.js": "./pf-radio/pf-radio.js",
3940
"./pf-select/pf-select.js": "./pf-select/pf-select.js",
4041
"./pf-select/pf-listbox.js": "./pf-select/pf-listbox.js",
4142
"./pf-select/pf-option-group.js": "./pf-select/pf-option-group.js",

elements/pf-radio/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Radio
2+
Add a description of the component here.
3+
4+
## Usage
5+
Describe how best to use this web component along with best practices.
6+
7+
```html
8+
<pf-radio>
9+
10+
</pf-radio>
11+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<pf-radio></pf-radio>
2+
3+
<script type="module">
4+
import '@patternfly/elements/pf-radio/pf-radio.js';
5+
</script>
6+
7+
<style>
8+
pf-radio {
9+
/* insert demo styles */
10+
}
11+
</style>
12+

elements/pf-radio/docs/pf-radio.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% renderOverview %}
2+
<pf-radio></pf-radio>
3+
{% endrenderOverview %}
4+
5+
{% band header="Usage" %}{% endband %}
6+
7+
{% renderSlots %}{% endrenderSlots %}
8+
9+
{% renderAttributes %}{% endrenderAttributes %}
10+
11+
{% renderMethods %}{% endrenderMethods %}
12+
13+
{% renderEvents %}{% endrenderEvents %}
14+
15+
{% renderCssCustomProperties %}{% endrenderCssCustomProperties %}
16+
17+
{% renderCssParts %}{% endrenderCssParts %}

elements/pf-radio/pf-radio.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:host {
2+
display: block;
3+
}

elements/pf-radio/pf-radio.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { LitElement, html, type TemplateResult } from 'lit';
2+
import { customElement } from 'lit/decorators/custom-element.js';
3+
4+
import styles from './pf-radio.css';
5+
import { property } from 'lit/decorators/property.js';
6+
7+
/**
8+
* Radio
9+
* @slot - Place element content here
10+
*/
11+
@customElement('pf-radio')
12+
export class PfRadio extends LitElement {
13+
static readonly styles: CSSStyleSheet[] = [styles];
14+
@property() checked = false;
15+
@property({ reflect: true }) name = 'radio-test';
16+
@property({ reflect: true }) label?: string;
17+
// #input:any
18+
19+
constructor() {
20+
super();
21+
}
22+
23+
connectedCallback(): void {
24+
super.connectedCallback();
25+
26+
const root = this.getRootNode();
27+
if (root instanceof Document || root instanceof ShadowRoot) {
28+
const group = root.querySelectorAll(`pf-radio`);
29+
// console.log("------------- the group is", group);
30+
}
31+
}
32+
33+
34+
render(): TemplateResult<1> {
35+
return html`
36+
<label for=input>${this.label}</label>
37+
<input id=input class="pf-radio" .name=${this.name} type="radio" .checked="${this.checked}">
38+
`;
39+
}
40+
}
41+
42+
declare global {
43+
interface HTMLElementTagNameMap {
44+
'pf-radio': PfRadio;
45+
}
46+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { test } from '@playwright/test';
2+
import { PfeDemoPage } from '@patternfly/pfe-tools/test/playwright/PfeDemoPage.js';
3+
import { SSRPage } from '@patternfly/pfe-tools/test/playwright/SSRPage.js';
4+
5+
const tagName = 'pf-radio';
6+
7+
test.describe(tagName, () => {
8+
test('snapshot', async ({ page }) => {
9+
const componentPage = new PfeDemoPage(page, tagName);
10+
await componentPage.navigate();
11+
await componentPage.snapshot();
12+
});
13+
14+
test('ssr', async ({ browser }) => {
15+
const fixture = new SSRPage({
16+
tagName,
17+
browser,
18+
demoDir: new URL('../demo/', import.meta.url),
19+
importSpecifiers: [
20+
`@patternfly/elements/${tagName}/${tagName}.js`,
21+
],
22+
});
23+
await fixture.snapshots();
24+
});
25+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, html } from '@open-wc/testing';
2+
import { createFixture } from '@patternfly/pfe-tools/test/create-fixture.js';
3+
import { PfRadio } from '@patternfly/elements/pf-radio/pf-radio.js';
4+
5+
describe('<pf-radio>', function() {
6+
describe('simply instantiating', function() {
7+
let element: PfRadio;
8+
it('imperatively instantiates', function() {
9+
expect(document.createElement('pf-radio')).to.be.an.instanceof(PfRadio);
10+
});
11+
12+
it('should upgrade', async function() {
13+
element = await createFixture<PfRadio>(html`<pf-radio></pf-radio>`);
14+
const klass = customElements.get('pf-radio');
15+
expect(element)
16+
.to.be.an.instanceOf(klass)
17+
.and
18+
.to.be.an.instanceOf(PfRadio);
19+
});
20+
});
21+
});

0 commit comments

Comments
 (0)