@fluid-topics/ft-radio 2.0.38 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,7 @@
1
1
  import { FtRadio } from "./ft-radio";
2
- import { FtdsRadio } from "./ftds-radio";
3
2
  import { FtRadioGroup } from "./ft-radio-group";
4
- import { FtdsRadioGroup } from "./ftds-radio-group";
5
3
  declare const _default: {
6
4
  "ft-radio": typeof FtRadio;
7
- "ftds-radio": typeof FtdsRadio;
8
5
  "ft-radio-group": typeof FtRadioGroup;
9
- "ftds-radio-group": typeof FtdsRadioGroup;
10
6
  };
11
7
  export default _default;
@@ -1,10 +1,6 @@
1
1
  import { FtRadio } from "./ft-radio";
2
- import { FtdsRadio } from "./ftds-radio";
3
2
  import { FtRadioGroup } from "./ft-radio-group";
4
- import { FtdsRadioGroup } from "./ftds-radio-group";
5
3
  export default {
6
4
  "ft-radio": FtRadio,
7
- "ftds-radio": FtdsRadio,
8
5
  "ft-radio-group": FtRadioGroup,
9
- "ftds-radio-group": FtdsRadioGroup,
10
6
  };
@@ -1,5 +1,24 @@
1
- import { FtBaseRadioGroup, FtBaseRadioGroupProperties } from "./ft-base-radio-group";
2
- export * from "./ft-base-radio-group";
3
- export declare class FtRadioGroup extends FtBaseRadioGroup implements FtBaseRadioGroupProperties {
1
+ import { FtLitElement } from "@fluid-topics/ft-wc-utils";
2
+ import { PropertyValues } from "lit";
3
+ import { FtRadio } from "./ft-radio";
4
+ import { FtRadioGroupProperties } from "./ft-radio-group.properties";
5
+ export declare class FtRadioGroup extends FtLitElement implements FtRadioGroupProperties {
6
+ static elementDefinitions: {};
4
7
  static styles: import("lit").CSSResult;
8
+ name: string;
9
+ role: string;
10
+ ariaLabelledBy: string;
11
+ assignedElements?: Array<Element>;
12
+ get radioButtons(): Array<FtRadio>;
13
+ currentSelectedIndex: number;
14
+ protected render(): import("lit-html").TemplateResult<1>;
15
+ connectedCallback(): void;
16
+ disconnectedCallback(): void;
17
+ private onSlotChange;
18
+ protected contentAvailableCallback(props: PropertyValues): void;
19
+ private onFocus;
20
+ private onChange;
21
+ private onKeyDown;
22
+ private resolveCurrentSelectedIndex;
23
+ private focusCurrentChecked;
5
24
  }
@@ -1,6 +1,117 @@
1
- import { FtBaseRadioGroup } from "./ft-base-radio-group";
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { FtLitElement } from "@fluid-topics/ft-wc-utils";
8
+ import { property, queryAssignedElements, state, } from "lit/decorators.js";
9
+ import { html, } from "lit";
2
10
  import { groupStyles } from "./ft-radio-group.styles";
3
- export * from "./ft-base-radio-group";
4
- export class FtRadioGroup extends FtBaseRadioGroup {
11
+ export class FtRadioGroup extends FtLitElement {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.name = "";
15
+ this.role = "radiogroup";
16
+ this.ariaLabelledBy = "";
17
+ this.currentSelectedIndex = 0;
18
+ this.onFocus = () => {
19
+ setTimeout(() => this.focusCurrentChecked(), 100);
20
+ };
21
+ }
22
+ get radioButtons() {
23
+ var _a, _b;
24
+ return (_b = (_a = this.assignedElements) === null || _a === void 0 ? void 0 : _a.flatMap((e) => e.matches("ft-radio,ftds-radio")
25
+ ? [e]
26
+ : [...e.querySelectorAll("ft-radio,ftds-radio")])) !== null && _b !== void 0 ? _b : [];
27
+ }
28
+ render() {
29
+ return html `
30
+ <slot @slotchange=${this.onSlotChange}
31
+ @change=${this.onChange}
32
+ @keydown=${this.onKeyDown}
33
+ ></slot>
34
+ `;
35
+ }
36
+ connectedCallback() {
37
+ super.connectedCallback();
38
+ this.addEventListener("focus", this.onFocus);
39
+ }
40
+ disconnectedCallback() {
41
+ super.disconnectedCallback();
42
+ this.removeEventListener("focus", this.onFocus);
43
+ }
44
+ onSlotChange() {
45
+ this.radioButtons.forEach((rb) => rb.name = this.name);
46
+ }
47
+ contentAvailableCallback(props) {
48
+ super.contentAvailableCallback(props);
49
+ this.radioButtons.forEach((rb) => rb.setInputTabIndex(-1)); // RadioButton is no more selectable alone
50
+ this.resolveCurrentSelectedIndex();
51
+ }
52
+ onChange(event) {
53
+ event.stopPropagation();
54
+ this.radioButtons.forEach((rb) => rb.checked = event.detail.value === rb.value);
55
+ this.dispatchEvent(new CustomEvent("change", { detail: event.detail.value }));
56
+ this.resolveCurrentSelectedIndex();
57
+ }
58
+ onKeyDown(event) {
59
+ let blockUnwhishedReaction = false;
60
+ switch (event.key) {
61
+ case "ArrowUp":
62
+ case "ArrowLeft": {
63
+ blockUnwhishedReaction = true;
64
+ const indexToFocus = this.currentSelectedIndex - 1;
65
+ this.radioButtons[indexToFocus < 0 ? this.radioButtons.length - 1 : indexToFocus].select();
66
+ this.radioButtons[indexToFocus < 0 ? this.radioButtons.length - 1 : indexToFocus].focus();
67
+ break;
68
+ }
69
+ case "ArrowDown":
70
+ case "ArrowRight": {
71
+ blockUnwhishedReaction = true;
72
+ const indexToFocus = this.currentSelectedIndex + 1;
73
+ this.radioButtons[indexToFocus > this.radioButtons.length - 1 ? 0 : indexToFocus].select();
74
+ this.radioButtons[indexToFocus > this.radioButtons.length - 1 ? 0 : indexToFocus].focus();
75
+ break;
76
+ }
77
+ case "Enter": {
78
+ this.radioButtons[this.currentSelectedIndex].select();
79
+ }
80
+ }
81
+ if (blockUnwhishedReaction) {
82
+ event.stopPropagation();
83
+ event.preventDefault();
84
+ }
85
+ }
86
+ resolveCurrentSelectedIndex() {
87
+ const checkedButtonIndex = this.radioButtons.findIndex((rb) => rb.checked);
88
+ if (checkedButtonIndex == -1) {
89
+ this.currentSelectedIndex = 0;
90
+ this.radioButtons[0].select();
91
+ }
92
+ else {
93
+ this.currentSelectedIndex = checkedButtonIndex;
94
+ }
95
+ this.radioButtons[this.currentSelectedIndex].setInputTabIndex(0);
96
+ }
97
+ focusCurrentChecked() {
98
+ this.radioButtons[this.currentSelectedIndex].focus();
99
+ }
5
100
  }
101
+ FtRadioGroup.elementDefinitions = {};
6
102
  FtRadioGroup.styles = groupStyles;
103
+ __decorate([
104
+ property()
105
+ ], FtRadioGroup.prototype, "name", void 0);
106
+ __decorate([
107
+ property({ reflect: true, attribute: "role" })
108
+ ], FtRadioGroup.prototype, "role", void 0);
109
+ __decorate([
110
+ property({ reflect: true, attribute: "aria-labelledby" })
111
+ ], FtRadioGroup.prototype, "ariaLabelledBy", void 0);
112
+ __decorate([
113
+ queryAssignedElements()
114
+ ], FtRadioGroup.prototype, "assignedElements", void 0);
115
+ __decorate([
116
+ state()
117
+ ], FtRadioGroup.prototype, "currentSelectedIndex", void 0);
@@ -0,0 +1,5 @@
1
+ export interface FtRadioGroupProperties {
2
+ name?: string;
3
+ role?: string;
4
+ ariaLabelledBy?: string;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,31 @@
1
- import { FtBaseRadio, FtBaseRadioProperties } from "./ft-base-radio";
2
- import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
- export * from "./ft-base-radio";
4
- export declare class FtRadio extends FtBaseRadio implements FtBaseRadioProperties {
1
+ import { PropertyValues } from "lit";
2
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
3
+ import { ClassInfo } from "lit/directives/class-map.js";
4
+ import { FtRadioProperties } from "./ft-radio.properties";
5
+ export declare class FtRadioChangeEvent extends CustomEvent<{
6
+ value: string;
7
+ checked: boolean;
8
+ }> {
9
+ constructor(value: string, checked: boolean);
10
+ }
11
+ export declare class FtRadio extends FtLitElement implements FtRadioProperties {
5
12
  static elementDefinitions: ElementDefinitionsMap;
6
13
  static styles: import("lit").CSSResult;
7
- get typographyVariant(): string;
14
+ name: string;
15
+ value: string;
16
+ checked: boolean;
17
+ ariaChecked: string;
18
+ disabled: boolean;
19
+ private container?;
20
+ private ripple?;
21
+ private input?;
22
+ get radioClasses(): ClassInfo;
23
+ protected render(): import("lit-html").TemplateResult<1>;
24
+ protected willUpdate(changedProperties: PropertyValues): void;
25
+ private onChange;
26
+ protected contentAvailableCallback(props: PropertyValues): void;
27
+ select(): void;
28
+ setInputTabIndex(index: number): void;
29
+ focus(): void;
30
+ onClick(e: Event): void;
8
31
  }
package/build/ft-radio.js CHANGED
@@ -1,15 +1,134 @@
1
- import { FtBaseRadio } from "./ft-base-radio";
2
- import { classicStyles } from "./ft-radio.styles";
3
- import { FtTypographyVariants } from "@fluid-topics/ft-typography/build/ft-typography.properties";
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, } from "lit";
8
+ import { property, query, } from "lit/decorators.js";
9
+ import { FtLitElement, } from "@fluid-topics/ft-wc-utils";
10
+ import { classMap, } from "lit/directives/class-map.js";
11
+ import { FtRipple } from "@fluid-topics/ft-ripple";
4
12
  import { FtTypography } from "@fluid-topics/ft-typography";
5
- export * from "./ft-base-radio";
6
- export class FtRadio extends FtBaseRadio {
7
- get typographyVariant() {
8
- return FtTypographyVariants.body2;
13
+ import { FtTypographyVariants } from "@fluid-topics/ft-typography/build/ft-typography.properties";
14
+ import { classicStyles } from "./ft-radio.styles";
15
+ export class FtRadioChangeEvent extends CustomEvent {
16
+ constructor(value, checked) {
17
+ super("change", { detail: { value: value, checked: checked }, bubbles: true, composed: true });
18
+ }
19
+ }
20
+ export class FtRadio extends FtLitElement {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.name = "";
24
+ this.value = "";
25
+ this.checked = false;
26
+ this.ariaChecked = "false";
27
+ this.disabled = false;
28
+ }
29
+ get radioClasses() {
30
+ return {
31
+ "ft-radio": true,
32
+ "ft-radio--checked": this.checked,
33
+ "ft-radio--disabled": this.disabled,
34
+ };
35
+ }
36
+ render() {
37
+ // We use inert on the input to prevent the "radio" role to be present twice in the aria tree
38
+ return html `
39
+ <div class="${classMap(this.radioClasses)}"
40
+ @click=${this.onClick}>
41
+ <div class="ft-radio--box-container">
42
+ <ft-ripple
43
+ ?disabled=${this.disabled}
44
+ ?primary=${this.checked}
45
+ unbounded>
46
+ </ft-ripple>
47
+ <div class="ft-radio--box">
48
+ </div>
49
+ <input id="radio-button"
50
+ type="radio"
51
+ name="${this.name}"
52
+ value="${this.value}"
53
+ .checked=${this.checked}
54
+ .disabled=${this.disabled}
55
+ @change=${this.onChange}
56
+ >
57
+ </div>
58
+ <label for="radio-button" inert>
59
+ <ft-typography variant="${FtTypographyVariants.body2}">
60
+ <slot></slot>
61
+ </ft-typography>
62
+ </label>
63
+ </div>
64
+ `;
65
+ }
66
+ willUpdate(changedProperties) {
67
+ super.willUpdate(changedProperties);
68
+ if (changedProperties.has("checked")) {
69
+ this.ariaChecked = this.checked ? "true" : "false";
70
+ }
71
+ }
72
+ onChange(event) {
73
+ event.stopPropagation();
74
+ this.checked = event.target.checked;
75
+ this.dispatchEvent(new FtRadioChangeEvent(this.value, this.checked));
76
+ }
77
+ contentAvailableCallback(props) {
78
+ var _a;
79
+ super.contentAvailableCallback(props);
80
+ (_a = this.ripple) === null || _a === void 0 ? void 0 : _a.setupFor(this.container);
81
+ }
82
+ select() {
83
+ this.checked = true;
84
+ this.dispatchEvent(new FtRadioChangeEvent(this.value, this.checked));
85
+ }
86
+ setInputTabIndex(index) {
87
+ if (this.input) {
88
+ this.input.tabIndex = index;
89
+ }
90
+ }
91
+ focus() {
92
+ var _a;
93
+ (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus();
94
+ setTimeout(() => { var _a; return (_a = this.ripple) === null || _a === void 0 ? void 0 : _a.forceFocusUpdate(); }, 0);
95
+ }
96
+ onClick(e) {
97
+ var _a;
98
+ if (e.target === this.input) {
99
+ return;
100
+ }
101
+ e.stopPropagation();
102
+ e.preventDefault();
103
+ (_a = this.input) === null || _a === void 0 ? void 0 : _a.click();
9
104
  }
10
105
  }
11
106
  FtRadio.elementDefinitions = {
12
- ...FtBaseRadio.elementDefinitions,
13
- "ft-or-ftds-typography": FtTypography,
107
+ "ft-ripple": FtRipple,
108
+ "ft-typography": FtTypography,
14
109
  };
15
110
  FtRadio.styles = classicStyles;
111
+ __decorate([
112
+ property()
113
+ ], FtRadio.prototype, "name", void 0);
114
+ __decorate([
115
+ property()
116
+ ], FtRadio.prototype, "value", void 0);
117
+ __decorate([
118
+ property({ type: Boolean, reflect: true })
119
+ ], FtRadio.prototype, "checked", void 0);
120
+ __decorate([
121
+ property({ attribute: "aria-checked", reflect: true })
122
+ ], FtRadio.prototype, "ariaChecked", void 0);
123
+ __decorate([
124
+ property({ type: Boolean })
125
+ ], FtRadio.prototype, "disabled", void 0);
126
+ __decorate([
127
+ query(".ft-radio")
128
+ ], FtRadio.prototype, "container", void 0);
129
+ __decorate([
130
+ query("ft-ripple")
131
+ ], FtRadio.prototype, "ripple", void 0);
132
+ __decorate([
133
+ query("input")
134
+ ], FtRadio.prototype, "input", void 0);