Skip to content

Commit f137892

Browse files
committed
Merge branch 'dev' into feature/formControlMixin-adapt-native-validation
2 parents a8f720b + 760d8bb commit f137892

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+15530
-5993
lines changed

package-lock.json

Lines changed: 15044 additions & 5657 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uui-avatar-group/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"custom-elements.json"
3131
],
3232
"dependencies": {
33-
"@umbraco-ui/uui-base": "0.0.17"
33+
"@umbraco-ui/uui-base": "0.0.17",
34+
"@umbraco-ui/uui-avatar": "0.0.19"
3435
},
3536
"scripts": {
3637
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",

packages/uui-avatar-group/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"references": [
1313
{
1414
"path": "../uui-base"
15+
},
16+
{
17+
"path": "../uui-avatar"
1518
}
1619
]
1720
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import '.';
2+
3+
import { Story } from '@storybook/web-components';
4+
import { html } from 'lit-html';
5+
6+
export default {
7+
id: 'FormControlMixin',
8+
title: 'Inputs/Form/FormControlMixin',
9+
};
10+
11+
export const AAAOverview: Story = () =>
12+
html`
13+
<p>FormControlMixin can be used to make a web component part of a form.</p>
14+
`;
15+
AAAOverview.storyName = 'Overview';

packages/uui-base/lib/mixins/FormControlMixin.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,22 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
172172
});
173173
}
174174

175+
/**
176+
* Determn wether this FormControl has a value.
177+
* @method hasValue
178+
* @returns {boolean}
179+
*/
175180
public hasValue(): boolean {
176181
return this.value !== '';
177182
}
178183

184+
/**
185+
* Get internal form element.
186+
* This has to be implemented to provide a FormControl Element of choice for the given context. The element is used as anchor for validation-messages.
187+
* @abstract
188+
* @method getFormElement
189+
* @returns {HTMLElement | undefined}
190+
*/
179191
protected abstract getFormElement(): HTMLElement | undefined;
180192

181193
disconnectedCallback(): void {
@@ -188,6 +200,21 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
188200
}
189201
}
190202

203+
/**
204+
* Add validator, to validate this Form Control.
205+
* See https://developer.mozilla.org/en-US/docs/Web/API/ValidityState for available Validator FlagTypes.
206+
*
207+
* @example
208+
* this.addValidator(
209+
* 'tooLong',
210+
* () => 'This input contains too many characters',
211+
* () => this._value.length > 10
212+
* );
213+
* @method hasValue
214+
* @param {FlagTypes} flagKey the type of validation.
215+
* @param {method} getMessage method to retrieve relevant message. Is executed every time the validator is re-executed.
216+
* @param {method} checkMethod method to determine if this validator should invalidate this form control. Return true if this should prevent submission.
217+
*/
191218
protected addValidator(
192219
flagKey: FlagTypes,
193220
getMessageMethod: () => String,
@@ -285,8 +312,8 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
285312
this._removeFormListeners();
286313
this._form = this._internals.form;
287314
if (this._form) {
288-
// This relies on the form begin a child of uui-form:
289-
if (this._form.hasAttribute('invalid-submit')) {
315+
// This relies on the form begin a 'uui-form':
316+
if (this._form.hasAttribute('submit-invalid')) {
290317
this.pristine = false;
291318
}
292319
this._form.addEventListener('submit', this._onFormSubmit);

packages/uui-base/lib/registration/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ export function defineElement(
2121

2222
const existingElement = window.customElements.get(name);
2323

24-
if (existingElement) {
25-
console.warn(`${name} is already defined`, existingElement); // TODO: Remove this in production
26-
} else {
24+
if (!existingElement) {
2725
window.customElements.define(name, constructor, options);
2826
}
2927
};

packages/uui-button-group/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"custom-elements.json"
3232
],
3333
"dependencies": {
34-
"@umbraco-ui/uui-base": "0.0.17",
35-
"@umbraco-ui/uui-icon-registry-essential": "0.0.3"
34+
"@umbraco-ui/uui-base": "0.0.17"
3635
},
3736
"scripts": {
3837
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",

packages/uui-button-group/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
"references": [
1313
{
1414
"path": "../uui-base"
15-
},
16-
{
17-
"path": "../uui-icon-registry-essential"
1815
}
1916
]
2017
}

packages/uui-button/lib/uui-button.element.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import '@umbraco-ui/uui-icon/lib';
2-
31
import {
42
UUIHorizontalShakeAnimationValue,
53
UUIHorizontalShakeKeyframes,
64
} from '@umbraco-ui/uui-base/lib/animations';
5+
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
76
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
87
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
98
import {
@@ -167,6 +166,9 @@ export class UUIButtonElement extends LabelMixin('', LitElement) {
167166
#loader {
168167
font-size: 1.5em;
169168
}
169+
:host([look]:not([look=''])) #loader {
170+
color: inherit;
171+
}
170172
171173
/* ANIMATIONS */
172174
@keyframes fadeIn {
@@ -609,19 +611,17 @@ export class UUIButtonElement extends LabelMixin('', LitElement) {
609611
let element = html``;
610612
switch (this.state) {
611613
case 'waiting':
612-
if (!customElements.get('uui-loader-circle')) {
613-
console.warn(
614-
'To properly render the waiting state, the uui-loader-circle element has to be registered'
615-
);
616-
}
614+
demandCustomElement(this, 'uui-loader-circle');
617615
element = html`<uui-loader-circle id="loader"></uui-loader-circle>`;
618616
break;
619617
case 'success':
618+
demandCustomElement(this, 'uui-icon');
620619
element = html`<uui-icon
621620
name="check"
622621
.fallback=${iconCheck.strings[0]}></uui-icon>`;
623622
break;
624623
case 'failed':
624+
demandCustomElement(this, 'uui-icon');
625625
element = html`<uui-icon
626626
name="wrong"
627627
.fallback=${iconWrong.strings[0]}></uui-icon>`;

packages/uui-button/lib/uui-button.story.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default {
1818
look: '',
1919
type: '',
2020
label: 'Button',
21+
state: '',
2122
},
2223
argTypes: {
2324
look: {
@@ -270,11 +271,8 @@ WithIcon.parameters = {
270271
},
271272
};
272273

273-
export const WaitingState = () => html`
274-
<uui-button state="waiting" label="A11Y proper label">
275-
Loading button
276-
</uui-button>
277-
`;
274+
export const WaitingState = Template.bind({});
275+
WaitingState.args = { state: 'waiting' };
278276
WaitingState.parameters = {
279277
docs: {
280278
source: {

0 commit comments

Comments
 (0)