Skip to content

Commit

Permalink
chore: updating typpings
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodek committed Sep 27, 2020
1 parent cb9f565 commit 12855c7
Show file tree
Hide file tree
Showing 13 changed files with 2,218 additions and 1,782 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,7 @@
{
"cSpell.words": [
"describedby",
"labelledby",
"radiogroup"
]
}
381 changes: 381 additions & 0 deletions custom-elements.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion demo/index.js
Expand Up @@ -16,6 +16,8 @@ class ComponentDemo extends ArcDemoPage {
]);
this.componentName = 'anypoint-radio-button';
this.demoStates = ['Normal'];
this.darkThemeActive = false;
this.demoDisabled = false;
this._toggleMainOption = this._toggleMainOption.bind(this);
}

Expand Down Expand Up @@ -74,4 +76,3 @@ class ComponentDemo extends ArcDemoPage {
}
const instance = new ComponentDemo();
instance.render();
window.demo = instance;
1 change: 1 addition & 0 deletions demo/templateIntroduction.js
@@ -1,4 +1,5 @@
import { html } from 'lit-html';

export default html`
<section class="documentation-section">
<h3>Introduction</h3>
Expand Down
1 change: 1 addition & 0 deletions demo/templateUsage.js
@@ -1,4 +1,5 @@
import { html } from 'lit-html';

export default html`
<section class="documentation-section">
<h2>Usage</h2>
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
@@ -0,0 +1,2 @@
export { AnypointRadioGroupElement } from './src/AnypointRadioGroupElement';
export { AnypointRadioButtonElement } from './src/AnypointRadioButtonElement';
2 changes: 2 additions & 0 deletions index.js
@@ -0,0 +1,2 @@
export { AnypointRadioGroupElement } from './src/AnypointRadioGroupElement.js';
export { AnypointRadioButtonElement } from './src/AnypointRadioButtonElement.js';
3,342 changes: 1,583 additions & 1,759 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "@anypoint-web-components/anypoint-radio-button",
"description": "Anypoint styled radio button",
"version": "0.1.5",
"version": "0.1.6",
"license": "Apache-2.0",
"main": "anypoint-radio-button.js",
"keywords": [
Expand All @@ -28,28 +28,28 @@
"email": "arc@mulesoft.com"
},
"dependencies": {
"@anypoint-web-components/anypoint-form-mixins": "^1.2.0",
"@anypoint-web-components/anypoint-menu-mixin": "^1.1.6",
"@anypoint-web-components/anypoint-form-mixins": "^1.2.1",
"@anypoint-web-components/anypoint-menu-mixin": "^1.1.7",
"@anypoint-web-components/anypoint-styles": "^1.0.1",
"lit-element": "^2.3.1"
"lit-element": "^2.4.0"
},
"devDependencies": {
"@advanced-rest-client/arc-demo-helper": "^1.0.17",
"@advanced-rest-client/testing-karma-sl": "^1.3.1",
"@advanced-rest-client/testing-karma-sl": "^1.4.2",
"@anypoint-web-components/anypoint-checkbox": "^1.1.2",
"@open-wc/eslint-config": "^2.0.0",
"@open-wc/testing": "^2.5.19",
"@open-wc/testing-karma": "^3.4.7",
"@open-wc/eslint-config": "^3.0.0",
"@open-wc/testing": "^2.5.27",
"@open-wc/testing-karma": "^4.0.6",
"@polymer/iron-test-helpers": "^3.0.1",
"deepmerge": "^4.2.2",
"es-dev-server": "^1.56.1",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5",
"sinon": "^9.0.2",
"typescript": "^3.9.6",
"es-dev-server": "^1.57.5",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"husky": "^4.3.0",
"lint-staged": "^10.4.0",
"prettier": "^2.1.2",
"sinon": "^9.0.3",
"typescript": "^4.0.3",
"typescript-lit-html-plugin": "^0.9.0"
},
"scripts": {
Expand All @@ -63,7 +63,8 @@
"format": "npm run format:eslint && npm run format:prettier",
"test": "karma start --coverage",
"test:watch": "karma start --auto-watch=true --single-run=false",
"test:sl": "karma start karma.sl.config.js --compatibility auto --coverage"
"test:sl": "karma start karma.sl.config.js --compatibility auto --coverage",
"gen:wc": "wca analyze \"*.js\" --outFile custom-elements.json"
},
"eslintConfig": {
"extends": [
Expand Down
100 changes: 100 additions & 0 deletions src/AnypointRadioButtonElement.d.ts
@@ -0,0 +1,100 @@
import { LitElement, TemplateResult, CSSResult } from 'lit-element';
import { CheckedElementMixin } from '@anypoint-web-components/anypoint-form-mixins';


export declare interface AnypointRadioButtonElement extends CheckedElementMixin, LitElement {
onchange: EventListener;
}

/**
* `anypoint-radio-button`
*
* Anypoint styled radio button.
*
* ## Usage
*
* Install element:
*
* ```
* npm i --save @anypoint-components/anypoint-radio-button
* ```
*
* Import into your app:
*
* ```html
* <script type="module" src="node_modules/@anypoint-components/anypoint-radio-button.js"></script>
* ```
*
* Or into another component
*
* ```javascript
* import '@anypoint-components/anypoint-radio-button.js';
* ```
*
* Use it:
*
* ```html
* <paper-radio-group selectable="anypoint-radio-button">
* <anypoint-radio-button name="a">Apple</anypoint-radio-button>
* <anypoint-radio-button name="b">Banana</anypoint-radio-button>
* <anypoint-radio-button name="c">Orange</anypoint-radio-button>
* </paper-radio-group>
* ```
*
* ### Styling
*
* `<anypoint-radio-button>` provides the following custom properties and mixins for styling:
*
* Custom property | Description | Default
* ----------------|-------------|----------
* `--anypoint-radio-button-radio-container` | A mixin applied to the internal radio container | `{}`
* `--anypoint-radio-button-unchecked-color` | Border color of unchecked button | `--anypoint-color-aluminum5`
* `--anypoint-radio-button-unchecked-background-color` | Unchecked button background color | `transparent`
* `--anypoint-radio-button-checked-color` | Checked button selection color | `--anypoint-color-coreBlue3`
* `--anypoint-radio-button-checked-inner-background-color` | Checked button inner circle background color | `#fff`
* `--anypoint-radio-button-label-spacing` | Spacing between the label and the button | `5px`
* `--anypoint-radio-button-label-color` | Label color | `--primary-text-color`
* `--anypoint-radio-button-label` | A mixin applied to the internal label | `{}`
*/
export declare class AnypointRadioButtonElement {
readonly styles: CSSResult;

render(): TemplateResult;
/**
* Controls whether this button is in checked state.
* @attribute
*/
checked: boolean;
/**
* Controls whether this button is in disabled state.
* @attribute
*/
disabled: boolean;

connectedCallback(): void;

disconnectedCallback(): void;

_updateCheckedAria(checked?: boolean): void;

/**
* Handler for keyboard down event
*/
_keyDownHandler(e: KeyboardEvent): void;

/**
* Handler for pointer click event
*/
_clickHandler(): void;

/**
* Performs a click operation in next macro-task.
*/
_asyncClick(): void;

/**
* Handles `disable` property state change and manages `aria-disabled`
* and `tabindex` attributes
*/
_disabledChanged(disabled: boolean): void;
}
4 changes: 2 additions & 2 deletions src/AnypointRadioButtonElement.js
Expand Up @@ -49,7 +49,7 @@ import radioStyles from './radio.styles.js';
* `--anypoint-radio-button-unchecked-color` | Border color of unchecked button | `--anypoint-color-aluminum5`
* `--anypoint-radio-button-unchecked-background-color` | Unchecked button background color | `transparent`
* `--anypoint-radio-button-checked-color` | Checked button selection color | `--anypoint-color-coreBlue3`
* `--anypoint-radio-button-checked-inner-background-color` | Checked button inner cicrcle background color | `#fff`
* `--anypoint-radio-button-checked-inner-background-color` | Checked button inner circle background color | `#fff`
* `--anypoint-radio-button-label-spacing` | Spacing between the label and the button | `5px`
* `--anypoint-radio-button-label-color` | Label color | `--primary-text-color`
* `--anypoint-radio-button-label` | A mixin applied to the internal label | `{}`
Expand Down Expand Up @@ -154,7 +154,7 @@ export class AnypointRadioButtonElement extends CheckedElementMixin(LitElement)
}

/**
* Performs a click operation in next macrotask.
* Performs a click operation in next macro-task.
*/
_asyncClick() {
if (this.disabled) {
Expand Down
116 changes: 116 additions & 0 deletions src/AnypointRadioGroupElement.d.ts
@@ -0,0 +1,116 @@
import { LitElement, TemplateResult, CSSResult } from 'lit-element';
import { AnypointMenuMixin } from '@anypoint-web-components/anypoint-menu-mixin';

export declare interface AnypointRadioGroupElement extends AnypointMenuMixin, LitElement {
onselect: EventListener;
}

/**
* A web component that groups custom radio buttons and handles selection inside
* the group.
*
* Requirements for children:
* - must have role="radio" attribute
* - must have name attribute
* - radio state change must be notified via `change` event.
*
* Radio buttons with the same name inside their group will have single selection.
* This means when selecting a radio button any other currently selected button
* will be deselected.
*
* Also. when initializing the component, only last selected component keeps the
* selection.
* When new checked radio button is inserted into the group the selection is passed to the newly
* arriving element.
*
* This behavior is consistent with native DOM API.
*
* The group element exposes `selected` property that holds a reference to
* currently selected radio button.
*
* Example
*
* ```
* <anypoint-radio-group>
* <anypoint-radio-button name="option"></anypoint-radio-button>
* <other-control role="button" name="option" checked></other-control>
* </anypoint-radio-group>
* ```
*/
export declare class AnypointRadioGroupElement {
createRenderRoot(): AnypointRadioGroupElement;

/**
* List of radio button nodes.
*/
readonly elements: NodeList;

connectedCallback(): void;

/**
* Function that manages attribute change.
* If the changed attribute is `role` with value `radio` then the node is processed
* as a button and is added or removed from collection.
* @param {MutationRecord} record A MutationRecord received from MutationObserver
* callback.
*/
_processNodeAttributeChange(record): void;

/**
* Adds `change` event listener to detected radio buttons.
* A button is considered as a radio button when its `role` is `radio`.
*
* @param nodes List of nodes to process.
*/
_processAddedNodes(nodes: HTMLElement[]): void;

/**
* Removes event listeners and possibly clears `selected` when removing nodes from
* light DOM.
* @param nodes Nodes to process
*/
_processRemovedNodes(nodes: NodeList): void;

/**
* A function to be called when a node from the light DOM has been removed.
* It clears previously attached listeners and selection if passed node is
* currently selected node.
* @param node Removed node
*/
_nodeRemoved(node: Node): void;

/**
* Overrides `AnypointMenuMixin._onKeydown`. Adds right / left arrows support.
*/
_onKeydown(e: KeyboardEvent): void;

/**
* Overrides `AnypointSelectableMixin._applySelection` to manage item's checked
* state.
* @param item Selected / deselected item.
* @param isSelected True if the item is selected
*/
_applySelection(item: HTMLElement, isSelected: boolean): void;

/**
* Ensures that the last child element is checked in the group.
*/
_ensureSingleSelection(): void;

/**
* Overrides `AnypointSelectableMixin._mutationHandler`.
* Processes dynamically added nodes and updates selection if needed.
* @params mutationsList A list of changes record
*/
_mutationHandler(mutationsList: MutationRecord[]): void;

/**
* Overrides `AnypointSelectableMixin._observeItems` to include subtree.
*/
_observeItems(): MutationObserver;

/**
* Disables children when disabled state changes
*/
_disabledChanged(disabled: boolean): void;
}
6 changes: 3 additions & 3 deletions src/AnypointRadioGroupElement.js
Expand Up @@ -74,7 +74,7 @@ export class AnypointRadioGroupElement extends AnypointMenuMixin(LitElement) {
/**
* Function that manages attribute change.
* If the changed attribute is `role` with value `radio` then the node is processed
* as a button and is added or removed from tollection.
* as a button and is added or removed from collection.
* @param {MutationRecord} record A MutationRecord received from MutationObserver
* callback.
*/
Expand Down Expand Up @@ -110,7 +110,7 @@ export class AnypointRadioGroupElement extends AnypointMenuMixin(LitElement) {
}

/**
* Removes event listenensers and possibly clears `selected` when removing nodes from
* Removes event listeners and possibly clears `selected` when removing nodes from
* light DOM.
* @param {NodeList} nodes Nodes to process
*/
Expand All @@ -126,7 +126,7 @@ export class AnypointRadioGroupElement extends AnypointMenuMixin(LitElement) {

/**
* A function to be called when a node from the light DOM has been removed.
* It clears previosly attached listeners and selection if passed node is
* It clears previously attached listeners and selection if passed node is
* currently selected node.
* @param {Node} node Removed node
*/
Expand Down

0 comments on commit 12855c7

Please sign in to comment.