@brightspace-ui/core 3.116.6 → 3.118.0

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,148 +0,0 @@
1
- import { css, html, LitElement } from 'lit';
2
- import { findFormElements, getFormElementData, isCustomFormElement, isNativeFormElement } from './form-helper.js';
3
- import { FormMixin } from './form-mixin.js';
4
- import { getUniqueId } from '../../helpers/uniqueId.js';
5
-
6
- /**
7
- * A component that can be used to build sections containing interactive controls that are validated and submitted as a group.
8
- * These interactive controls are submitted using a native HTML form submission.
9
- * @slot - The native and custom form elements that participate in validation and submission
10
- * @fires submit - Dispatched when the form is submitted. Cancelling this event will prevent form submission.
11
- */
12
- class FormNative extends FormMixin(LitElement) {
13
-
14
- static get properties() {
15
- return {
16
- /**
17
- * The URL that processes the form submission.
18
- * @type {string}
19
- */
20
- action: { type: String },
21
- /**
22
- * If the value of the method attribute is post, enctype is the MIME type of the form submission.
23
- * @type {'application/x-www-form-urlencoded'|'multipart/form-data'|'text/plain'}
24
- */
25
- enctype: { type: String },
26
- /**
27
- * The HTTP method to submit the form with.
28
- * @type {'get'|'post'}
29
- */
30
- method: { type: String },
31
- /**
32
- * Indicates where to display the response after submitting the form.
33
- * @type {'_self '|'_blank'|'_parent'|'_top'}
34
- */
35
- target: { type: String },
36
- };
37
- }
38
-
39
- static get styles() {
40
- return css`
41
- :host {
42
- display: block;
43
- }
44
- :host([hidden]) {
45
- display: none;
46
- }
47
- `;
48
- }
49
-
50
- constructor() {
51
- super();
52
- this.action = '';
53
- this.enctype = 'application/x-www-form-urlencoded';
54
- this.method = 'get';
55
- this.target = '_self';
56
- }
57
-
58
- render() {
59
- const errors = [...this._errors]
60
- .filter(([, eleErrors]) => eleErrors.length > 0)
61
- .map(([ele, eleErrors]) => ({ href: `#${ele.id}`, message: eleErrors[0], onClick: () => ele.focus() }));
62
- return html`
63
- <d2l-form-error-summary .errors=${errors}></d2l-form-error-summary>
64
- <slot></slot>
65
- `;
66
- }
67
-
68
- shouldUpdate(changedProperties) {
69
- if (!super.shouldUpdate(changedProperties)) {
70
- return false;
71
- }
72
- const ignoredProps = new Set(['action', 'enctype', 'method', 'target']);
73
- return [...changedProperties].filter(([prop]) => !ignoredProps.has(prop)).length > 0;
74
- }
75
-
76
- async requestSubmit(submitter) {
77
- const errors = await this.validate();
78
- if (errors.size > 0) {
79
- return;
80
- }
81
- this._dirty = false;
82
-
83
- const form = document.createElement('form');
84
- form.addEventListener('formdata', this._onFormData);
85
- form.id = getUniqueId();
86
- form.action = this.action;
87
- form.enctype = this.enctype;
88
- form.method = this.method;
89
- form.target = this.target;
90
- this.appendChild(form);
91
-
92
- let customFormData = {};
93
- const formElements = findFormElements(this);
94
- for (const ele of formElements) {
95
- const eleData = getFormElementData(ele, submitter);
96
- const isCustom = isCustomFormElement(ele);
97
- if (isCustom || ele === submitter) {
98
- customFormData = { ...customFormData, ...eleData };
99
- }
100
- if (!isCustom && isNativeFormElement(ele)) {
101
- ele.setAttribute('form', form.id);
102
- }
103
- }
104
- for (const entry of Object.entries(customFormData)) {
105
- const input = document.createElement('input');
106
- input.type = 'hidden';
107
- input.name = entry[0];
108
- input.value = entry[1];
109
- form.appendChild(input);
110
- }
111
- const submit = this.dispatchEvent(new CustomEvent('submit', { bubbles: true, cancelable: true }));
112
- /** Dispatched after the entry list representing the form's data is constructed. This happens when the form is submitted just prior to submission. The form data can be obtained from the `detail`'s `formData` property. */
113
- this.dispatchEvent(new CustomEvent('formdata', { detail: { formData: new FormData(form) } }));
114
- if (submit) {
115
- form.submit();
116
- }
117
- form.remove();
118
- }
119
-
120
- async submit() {
121
- return this.requestSubmit(null);
122
- }
123
-
124
- async validate() {
125
- let errors = [];
126
- const errorMap = new Map();
127
- const formElements = findFormElements(this);
128
- for (const ele of formElements) {
129
- const eleErrors = await this._validateFormElement(ele, true);
130
- if (eleErrors.length > 0) {
131
- errors = [...errors, ...eleErrors];
132
- errorMap.set(ele, eleErrors);
133
- }
134
- }
135
- this._errors = errorMap;
136
- if (this.shadowRoot && errorMap.size > 0) {
137
- const errorSummary = this.shadowRoot.querySelector('d2l-form-error-summary');
138
- this.updateComplete.then(() => errorSummary.focus());
139
- }
140
- return errorMap;
141
- }
142
-
143
- _onFormData(e) {
144
- e.stopPropagation();
145
- }
146
-
147
- }
148
- customElements.define('d2l-form-native', FormNative);
@@ -1,25 +0,0 @@
1
- import { html, LitElement } from 'lit';
2
- import { radioStyles } from '../input-radio-styles.js';
3
- import { RtlMixin } from '../../../mixins/rtl/rtl-mixin.js';
4
-
5
- class TestInputRadioLabelSimple extends RtlMixin(LitElement) {
6
-
7
- static get styles() {
8
- return [ radioStyles ];
9
- }
10
-
11
- render() {
12
- return html`
13
- <label class="d2l-input-radio-label">
14
- <input type="radio" name="myGroup" value="first" checked>
15
- Option 1
16
- </label>
17
- <label class="d2l-input-radio-label">
18
- <input type="radio" name="myGroup" value="second">
19
- Option 2
20
- </label>
21
- `;
22
- }
23
-
24
- }
25
- customElements.define('d2l-test-input-radio-label-simple', TestInputRadioLabelSimple);
@@ -1,42 +0,0 @@
1
- import '../input-radio-spacer.js';
2
- import { html, LitElement } from 'lit';
3
- import { inlineHelpStyles } from '../input-inline-help.js';
4
- import { radioStyles } from '../input-radio-styles.js';
5
-
6
- class TestInputRadioSpacer extends LitElement {
7
-
8
- static get styles() {
9
- return [ radioStyles, inlineHelpStyles ];
10
- }
11
-
12
- render() {
13
- return html`
14
- <div>
15
- <label class="d2l-input-radio-label">
16
- <input type="radio" aria-describedby="desc1" name="myGroup" value="normal">
17
- Option 1
18
- </label>
19
- <d2l-input-radio-spacer id="desc1" class="d2l-input-inline-help">
20
- Additional content can go here and will line up nicely with the edge of the radio.
21
- </d2l-input-radio-spacer>
22
- </div>
23
- <div>
24
- <label class="d2l-input-radio-label">
25
- <input type="radio" aria-describedby="desc2" name="myGroup" value="normal">
26
- Option 1 (Deadlights jack lad schooner scallywag dance the hempen jig carouser broadside cable strike colors. Bring a spring upon her cable holystone blow the man down spanker.)
27
- </label>
28
- <d2l-input-radio-spacer id="desc2" class="d2l-input-inline-help">
29
- Trysail Sail ho Corsair red ensign hulk smartly boom jib rum gangway. Case shot Shiver me timbers gangplank crack Jennys tea cup ballast Blimey lee snow crow's nest rutters. Fluke jib scourge of the seven seas boatswain schooner gaff booty Jack Tar transom spirits.
30
- </d2l-input-radio-spacer>
31
- </div>
32
- `;
33
- }
34
-
35
- focus() {
36
- const elem = this.shadowRoot && this.shadowRoot.querySelector('input');
37
- if (elem) elem.focus();
38
- }
39
-
40
- }
41
-
42
- customElements.define('d2l-test-input-radio-spacer', TestInputRadioSpacer);