diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 0ed460471..e918c3ee5 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -201,7 +201,17 @@ module.exports = { 'no-restricted-imports': [ 'warn', { + patterns: [ + { + group: ['../*'], + message: 'Usage of relative parent imports is not allowed.' + } + ], paths: [ + { + name: '.', + message: 'Usage of local index imports is not allowed.' + }, { name: './index', message: 'Import from the source file instead.' @@ -214,6 +224,16 @@ module.exports = { 'warn', { groups: ['builtin', 'external', 'internal', 'unknown', 'parent', 'sibling', 'index', 'object', 'type'], + pathGroups: [ + { + pattern: '~/**', + group: 'internal' + }, + { + pattern: 'dist/**', + group: 'external' + } + ], alphabetize: { order: 'asc', caseInsensitive: true diff --git a/cspell.json b/cspell.json index 1e52dd4a2..0f6de2b33 100644 --- a/cspell.json +++ b/cspell.json @@ -108,6 +108,7 @@ "textareas", "transitionend", "Triaging", + "ttsc", "turbolinks", "unbundles", "unbundling", diff --git a/docs/components/checkbox.md b/docs/components/checkbox.md index 1a40415ed..dbb67e377 100644 --- a/docs/components/checkbox.md +++ b/docs/components/checkbox.md @@ -60,73 +60,4 @@ import { SlCheckbox } from '@shoelace-style/shoelace/dist/react'; const App = () => Disabled; ``` -### Custom Validity - -Use the `setCustomValidity()` method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string. - -```html preview -
- Check me -
- Submit -
- - -``` - -```jsx react -import { useEffect, useRef } from 'react'; -import { SlButton, SlCheckbox } from '@shoelace-style/shoelace/dist/react'; - -const App = () => { - const checkbox = useRef(null); - const errorMessage = `Don't forget to check me!`; - - function handleChange() { - checkbox.current.setCustomValidity(checkbox.current.checked ? '' : errorMessage); - } - - function handleSubmit(event) { - event.preventDefault(); - alert('All fields are valid!'); - } - - useEffect(() => { - checkbox.current.setCustomValidity(errorMessage); - }, []); - - return ( -
- - Check me - -
- - Submit - -
- ); -}; -``` - [component-metadata:sl-checkbox] diff --git a/docs/components/radio-button.md b/docs/components/radio-button.md index 7f745b187..a21d138f5 100644 --- a/docs/components/radio-button.md +++ b/docs/components/radio-button.md @@ -414,90 +414,4 @@ const App = () => ( ); ``` -### Custom Validity - -Use the `setCustomValidity()` method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string. - -```html preview -
- - Not me - Me neither - Choose me - - -
- - Submit -
- - -``` - -```jsx react -import { useEffect, useRef } from 'react'; -import { SlButton, SlIcon, SlRadioButton, SlRadioGroup } from '@shoelace-style/shoelace/dist/react'; - -const App = () => { - const radio = useRef(null); - const errorMessage = 'You must choose this option'; - - function handleChange(event) { - radio.current.setCustomValidity(radio.current.checked ? '' : errorMessage); - } - - function handleSubmit(event) { - event.preventDefault(); - alert('All fields are valid!'); - } - - useEffect(() => { - radio.current.setCustomValidity(errorMessage); - }, []); - - return ( -
- - - Not me - - - Me neither - - - Choose me - - - -
- - - Submit - -
- ); -}; -``` - [component-metadata:sl-radio-button] diff --git a/docs/components/radio.md b/docs/components/radio.md index c6368374d..4c271e972 100644 --- a/docs/components/radio.md +++ b/docs/components/radio.md @@ -96,90 +96,4 @@ const App = () => ( ); ``` -### Custom Validity - -Use the `setCustomValidity()` method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string. - -```html preview -
- - Not me - Me neither - Choose me - - -
- - Submit -
- - -``` - -```jsx react -import { useEffect, useRef } from 'react'; -import { SlButton, SlIcon, SlRadio, SlRadioGroup } from '@shoelace-style/shoelace/dist/react'; - -const App = () => { - const radio = useRef(null); - const errorMessage = 'You must choose this option'; - - function handleChange(event) { - radio.current.setCustomValidity(radio.current.checked ? '' : errorMessage); - } - - function handleSubmit(event) { - event.preventDefault(); - alert('All fields are valid!'); - } - - useEffect(() => { - radio.current.setCustomValidity(errorMessage); - }, []); - - return ( -
- - - Not me - - - Me neither - - - Choose me - - - -
- - - Submit - -
- ); -}; -``` - [component-metadata:sl-radio] diff --git a/docs/getting-started/form-controls.md b/docs/getting-started/form-controls.md index b4c1584ad..472be6962 100644 --- a/docs/getting-started/form-controls.md +++ b/docs/getting-started/form-controls.md @@ -194,7 +194,7 @@ const App = () => { ### Custom Validation -To create a custom validation error, pass a non-empty string to the `setCustomValidity()` method. This will override any existing validation constraints. The form will not be submitted when a custom validity is set and the browser will show a validation error when the containing form is submitted. To make the input valid again, call `setCustomValidity()` again with an empty string. +To create a custom validation error, use the `setCustomValidity` method. The form will not be submitted when this method is called with anything other than an empty string, and its message will be shown by the browser as the validation error. To make the input valid again, call the method a second time with an empty string as the argument. ```html preview
@@ -257,8 +257,6 @@ const App = () => { }; ``` -?> Custom validation can be applied to any form control that supports the `setCustomValidity()` method. It is not limited to inputs and textareas. - ### Custom Validation Styles The `invalid` attribute reflects the form control's validity, so you can style invalid fields using the `[invalid]` selector. The example below demonstrates how you can give erroneous fields a different appearance. Type something other than "shoelace" to demonstrate this. diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index a59b4c739..495686221 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -6,15 +6,6 @@ Components with the Experimental bad _During the beta period, these restrictions may be relaxed in the event of a mission-critical bug._ 🐛 -## 2.0.0-beta.73 - -- Added `button` part to `` -- Added custom validity examples and tests to ``, ``, and `` -- Fixed a bug that prevented a number of properties, methods, etc. from being documented in `` and `` -- Fixed a bug that prevented `setCustomValidity()` from working with `` -- Fixed a bug where the right border of a checked `` was the wrong color -- Once again removed path aliasing because it doesn't work with Web Test Runner's esbuild plugin - ## 2.0.0-beta.72 - 🚨 BREAKING: refactored parts in ``, ``, ``, and `` to allow you to customize the label and help text position diff --git a/package-lock.json b/package-lock.json index 8676b52de..311fb2e92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,7 +62,9 @@ "sinon": "^13.0.1", "strip-css-comments": "^5.0.0", "tslib": "^2.3.1", - "typescript": "4.5.5" + "ttypescript": "^1.5.13", + "typescript": "4.5.5", + "typescript-transform-paths": "^3.3.1" }, "engines": { "node": ">=14.17.0" @@ -505,6 +507,29 @@ "integrity": "sha512-/MB0RS0Gn01s4pgmjy0FvsLfr3RRMrRphEuvTRserNcM8XVtoIVAtrjig/Gg0DPwDrN8Clm0L1j7iQay6S8D0g==", "dev": true }, + "node_modules/@cspotcode/source-map-consumer": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", + "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", + "dev": true, + "peer": true, + "engines": { + "node": ">= 12" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", + "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", + "dev": true, + "peer": true, + "dependencies": { + "@cspotcode/source-map-consumer": "0.8.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@custom-elements-manifest/analyzer": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@custom-elements-manifest/analyzer/-/analyzer-0.5.7.tgz", @@ -996,6 +1021,34 @@ "node": ">= 6" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", + "integrity": "sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==", + "dev": true, + "peer": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.9.tgz", + "integrity": "sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==", + "dev": true, + "peer": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.1.tgz", + "integrity": "sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==", + "dev": true, + "peer": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz", + "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", + "dev": true, + "peer": true + }, "node_modules/@types/accepts": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz", @@ -2027,6 +2080,16 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true, + "peer": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/after": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", @@ -2250,6 +2313,13 @@ "node": ">= 6" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "peer": true + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -3727,6 +3797,13 @@ "node": ">=10" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "peer": true + }, "node_modules/cross-fetch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", @@ -9081,6 +9158,13 @@ "semver": "bin/semver.js" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, + "peer": true + }, "node_modules/make-fetch-happen": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz", @@ -13150,6 +13234,59 @@ "node": ">=0.8.0" } }, + "node_modules/ts-node": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.6.0.tgz", + "integrity": "sha512-CJen6+dfOXolxudBQXnVjRVvYTmTWbyz7cn+xq2XTsvnaXbHqr4gXSCNbS2Jj8yTZMuGwUoBESLaOkLascVVvg==", + "dev": true, + "peer": true, + "dependencies": { + "@cspotcode/source-map-support": "0.7.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.0", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/ts-node/node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "peer": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/tsconfig-paths": { "version": "3.12.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.12.0.tgz", @@ -13210,6 +13347,23 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, + "node_modules/ttypescript": { + "version": "1.5.13", + "resolved": "https://registry.npmjs.org/ttypescript/-/ttypescript-1.5.13.tgz", + "integrity": "sha512-KT/RBfGGlVJFqEI8cVvI3nMsmYcFvPSZh8bU0qX+pAwbi7/ABmYkzn7l/K8skw0xmYjVCoyaV6WLsBQxdadybQ==", + "dev": true, + "dependencies": { + "resolve": ">=1.9.0" + }, + "bin": { + "ttsc": "bin/tsc", + "ttsserver": "bin/tsserver" + }, + "peerDependencies": { + "ts-node": ">=8.0.2", + "typescript": ">=3.2.2" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -13278,6 +13432,18 @@ "node": ">=4.2.0" } }, + "node_modules/typescript-transform-paths": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/typescript-transform-paths/-/typescript-transform-paths-3.3.1.tgz", + "integrity": "sha512-c+8Cqd2rsRtTU68rJI0NX/OtqgBDddNs1fIxm1nCNyhn0WpoyqtpUxc1w9Ke5c5kgE4/OT5xYbKf2cf694RYEg==", + "dev": true, + "dependencies": { + "minimatch": "^3.0.4" + }, + "peerDependencies": { + "typescript": ">=3.6.5" + } + }, "node_modules/typical": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", @@ -13566,6 +13732,13 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz", + "integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==", + "dev": true, + "peer": true + }, "node_modules/v8-to-istanbul": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-8.1.1.tgz", @@ -14113,6 +14286,16 @@ "node": ">= 4.0.0" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "peer": true, + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -14523,6 +14706,23 @@ "integrity": "sha512-/MB0RS0Gn01s4pgmjy0FvsLfr3RRMrRphEuvTRserNcM8XVtoIVAtrjig/Gg0DPwDrN8Clm0L1j7iQay6S8D0g==", "dev": true }, + "@cspotcode/source-map-consumer": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", + "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", + "dev": true, + "peer": true + }, + "@cspotcode/source-map-support": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", + "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", + "dev": true, + "peer": true, + "requires": { + "@cspotcode/source-map-consumer": "0.8.0" + } + }, "@custom-elements-manifest/analyzer": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@custom-elements-manifest/analyzer/-/analyzer-0.5.7.tgz", @@ -14939,6 +15139,34 @@ "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", "dev": true }, + "@tsconfig/node10": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", + "integrity": "sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==", + "dev": true, + "peer": true + }, + "@tsconfig/node12": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.9.tgz", + "integrity": "sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==", + "dev": true, + "peer": true + }, + "@tsconfig/node14": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.1.tgz", + "integrity": "sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==", + "dev": true, + "peer": true + }, + "@tsconfig/node16": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz", + "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", + "dev": true, + "peer": true + }, "@types/accepts": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz", @@ -15798,6 +16026,13 @@ "dev": true, "requires": {} }, + "acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true, + "peer": true + }, "after": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", @@ -15973,6 +16208,13 @@ } } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "peer": true + }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -17119,6 +17361,13 @@ "yaml": "^1.10.0" } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "peer": true + }, "cross-fetch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", @@ -21122,6 +21371,13 @@ } } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, + "peer": true + }, "make-fetch-happen": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz", @@ -24284,6 +24540,37 @@ } } }, + "ts-node": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.6.0.tgz", + "integrity": "sha512-CJen6+dfOXolxudBQXnVjRVvYTmTWbyz7cn+xq2XTsvnaXbHqr4gXSCNbS2Jj8yTZMuGwUoBESLaOkLascVVvg==", + "dev": true, + "peer": true, + "requires": { + "@cspotcode/source-map-support": "0.7.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.0", + "yn": "3.1.1" + }, + "dependencies": { + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "peer": true + } + } + }, "tsconfig-paths": { "version": "3.12.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.12.0.tgz", @@ -24336,6 +24623,15 @@ } } }, + "ttypescript": { + "version": "1.5.13", + "resolved": "https://registry.npmjs.org/ttypescript/-/ttypescript-1.5.13.tgz", + "integrity": "sha512-KT/RBfGGlVJFqEI8cVvI3nMsmYcFvPSZh8bU0qX+pAwbi7/ABmYkzn7l/K8skw0xmYjVCoyaV6WLsBQxdadybQ==", + "dev": true, + "requires": { + "resolve": ">=1.9.0" + } + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -24382,6 +24678,15 @@ "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", "dev": true }, + "typescript-transform-paths": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/typescript-transform-paths/-/typescript-transform-paths-3.3.1.tgz", + "integrity": "sha512-c+8Cqd2rsRtTU68rJI0NX/OtqgBDddNs1fIxm1nCNyhn0WpoyqtpUxc1w9Ke5c5kgE4/OT5xYbKf2cf694RYEg==", + "dev": true, + "requires": { + "minimatch": "^3.0.4" + } + }, "typical": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", @@ -24592,6 +24897,13 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, + "v8-compile-cache-lib": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz", + "integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==", + "dev": true, + "peer": true + }, "v8-to-istanbul": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-8.1.1.tgz", @@ -25023,6 +25335,13 @@ "integrity": "sha512-faQrqNMzcPCHGVC2aaOINk13K+aaBDUPjGWl0teOXywElLjyVAB6Oe2jj62jHYtwsU49jXhScYbvPENK+6zAvQ==", "dev": true }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "peer": true + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index e175e00d1..6ea27d84a 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,9 @@ "sinon": "^13.0.1", "strip-css-comments": "^5.0.0", "tslib": "^2.3.1", - "typescript": "4.5.5" + "ttypescript": "^1.5.13", + "typescript": "4.5.5", + "typescript-transform-paths": "^3.3.1" }, "lint-staged": { "*.{ts,js}": [ diff --git a/scripts/build.js b/scripts/build.js index fb8967592..a8a7638ff 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -34,7 +34,7 @@ fs.mkdirSync(outdir, { recursive: true }); execSync(`node scripts/make-icons.js --outdir "${outdir}"`, { stdio: 'inherit' }); if (types) { console.log('Running the TypeScript compiler...'); - execSync(`tsc --project ./tsconfig.json --outdir "${outdir}"`, { stdio: 'inherit' }); + execSync(`ttsc --project ./tsconfig.prod.json --outdir "${outdir}"`, { stdio: 'inherit' }); } } catch (err) { console.error(chalk.red(err)); diff --git a/scripts/plop/templates/component/component.hbs b/scripts/plop/templates/component/component.hbs index 5f0d7e8cb..306c316df 100644 --- a/scripts/plop/templates/component/component.hbs +++ b/scripts/plop/templates/component/component.hbs @@ -1,7 +1,7 @@ import { LitElement, html } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { emit } from '../../internal/event'; -import { watch } from '../../internal/watch'; +import { emit } from '~/internal/event'; +import { watch } from '~/internal/watch'; import styles from './{{ tagWithoutPrefix tag }}.styles'; /** diff --git a/scripts/plop/templates/component/styles.hbs b/scripts/plop/templates/component/styles.hbs index a4aafbb97..fd001391b 100644 --- a/scripts/plop/templates/component/styles.hbs +++ b/scripts/plop/templates/component/styles.hbs @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/alert/alert.styles.ts b/src/components/alert/alert.styles.ts index 30b8b4b76..7a05bf177 100644 --- a/src/components/alert/alert.styles.ts +++ b/src/components/alert/alert.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/alert/alert.ts b/src/components/alert/alert.ts index 37bcd34b8..4af1ac8bd 100644 --- a/src/components/alert/alert.ts +++ b/src/components/alert/alert.ts @@ -1,12 +1,12 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import '../../components/icon-button/icon-button'; -import { animateTo, stopAnimations } from '../../internal/animate'; -import { emit, waitForEvent } from '../../internal/event'; -import { HasSlotController } from '../../internal/slot'; -import { watch } from '../../internal/watch'; -import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry'; +import '~/components/icon-button/icon-button'; +import { animateTo, stopAnimations } from '~/internal/animate'; +import { emit, waitForEvent } from '~/internal/event'; +import { HasSlotController } from '~/internal/slot'; +import { watch } from '~/internal/watch'; +import { getAnimation, setDefaultAnimation } from '~/utilities/animation-registry'; import styles from './alert.styles'; const toastStack = Object.assign(document.createElement('div'), { className: 'sl-toast-stack' }); diff --git a/src/components/animated-image/animated-image.styles.ts b/src/components/animated-image/animated-image.styles.ts index 72685544c..b4d529b3e 100644 --- a/src/components/animated-image/animated-image.styles.ts +++ b/src/components/animated-image/animated-image.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/animated-image/animated-image.ts b/src/components/animated-image/animated-image.ts index 22cedbf0d..3e5b72806 100644 --- a/src/components/animated-image/animated-image.ts +++ b/src/components/animated-image/animated-image.ts @@ -1,8 +1,8 @@ import { html, LitElement } from 'lit'; import { customElement, property, query, state } from 'lit/decorators.js'; -import '../../components/icon/icon'; -import { emit } from '../../internal/event'; -import { watch } from '../../internal/watch'; +import '~/components/icon/icon'; +import { emit } from '~/internal/event'; +import { watch } from '~/internal/watch'; import styles from './animated-image.styles'; /** diff --git a/src/components/animation/animation.styles.ts b/src/components/animation/animation.styles.ts index cb10fcc60..707b58af8 100644 --- a/src/components/animation/animation.styles.ts +++ b/src/components/animation/animation.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/animation/animation.ts b/src/components/animation/animation.ts index 7f647c6ef..960c0a7cc 100644 --- a/src/components/animation/animation.ts +++ b/src/components/animation/animation.ts @@ -1,7 +1,7 @@ import { html, LitElement } from 'lit'; import { customElement, property, queryAsync } from 'lit/decorators.js'; -import { emit } from '../../internal/event'; -import { watch } from '../../internal/watch'; +import { emit } from '~/internal/event'; +import { watch } from '~/internal/watch'; import styles from './animation.styles'; import { animations } from './animations'; diff --git a/src/components/avatar/avatar.styles.ts b/src/components/avatar/avatar.styles.ts index 307d3b05f..7bc8f598a 100644 --- a/src/components/avatar/avatar.styles.ts +++ b/src/components/avatar/avatar.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/avatar/avatar.ts b/src/components/avatar/avatar.ts index 334567ed5..293843e08 100644 --- a/src/components/avatar/avatar.ts +++ b/src/components/avatar/avatar.ts @@ -1,7 +1,7 @@ import { html, LitElement } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import '../../components/icon/icon'; +import '~/components/icon/icon'; import styles from './avatar.styles'; /** diff --git a/src/components/badge/badge.styles.ts b/src/components/badge/badge.styles.ts index 9279e6ff0..e1e2e26f9 100644 --- a/src/components/badge/badge.styles.ts +++ b/src/components/badge/badge.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/breadcrumb-item/breadcrumb-item.styles.ts b/src/components/breadcrumb-item/breadcrumb-item.styles.ts index 077cb2915..ae174294b 100644 --- a/src/components/breadcrumb-item/breadcrumb-item.styles.ts +++ b/src/components/breadcrumb-item/breadcrumb-item.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/breadcrumb-item/breadcrumb-item.ts b/src/components/breadcrumb-item/breadcrumb-item.ts index db7532611..0c354ae0f 100644 --- a/src/components/breadcrumb-item/breadcrumb-item.ts +++ b/src/components/breadcrumb-item/breadcrumb-item.ts @@ -2,7 +2,7 @@ import { html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; -import { HasSlotController } from '../../internal/slot'; +import { HasSlotController } from '~/internal/slot'; import styles from './breadcrumb-item.styles'; /** diff --git a/src/components/breadcrumb/breadcrumb.styles.ts b/src/components/breadcrumb/breadcrumb.styles.ts index 281a00f50..c6adb7372 100644 --- a/src/components/breadcrumb/breadcrumb.styles.ts +++ b/src/components/breadcrumb/breadcrumb.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/breadcrumb/breadcrumb.ts b/src/components/breadcrumb/breadcrumb.ts index 99ceae143..ca8e3a133 100644 --- a/src/components/breadcrumb/breadcrumb.ts +++ b/src/components/breadcrumb/breadcrumb.ts @@ -1,13 +1,13 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; -import '../../components/icon/icon'; +import type SlBreadcrumbItem from '~/components/breadcrumb-item/breadcrumb-item'; +import '~/components/icon/icon'; import styles from './breadcrumb.styles'; -import type SlBreadcrumbItem from '../../components/breadcrumb-item/breadcrumb-item'; /** * @since 2.0 - * * @status stable + * * @slot - One or more breadcrumb items to display. * @slot separator - The separator to use between breadcrumb items. * diff --git a/src/components/button-group/button-group.styles.ts b/src/components/button-group/button-group.styles.ts index 03cbf62e8..4fb79e51c 100644 --- a/src/components/button-group/button-group.styles.ts +++ b/src/components/button-group/button-group.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/button/button.styles.ts b/src/components/button/button.styles.ts index 181fa2b82..aa7c46875 100644 --- a/src/components/button/button.styles.ts +++ b/src/components/button/button.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} @@ -632,13 +632,12 @@ export default css` mix-blend-mode: multiply; } - /* Bump hovered, focused, and checked buttons up so their focus ring isn't clipped */ + /* Bump focused buttons up so their focus ring isn't clipped */ :host(.sl-button-group__button--hover) { z-index: 1; } - :host(.sl-button-group__button--focus), - :host(.sl-button-group__button[checked]) { + :host(.sl-button-group__button--focus) { z-index: 2; } `; diff --git a/src/components/button/button.test.ts b/src/components/button/button.test.ts index 01b71b292..1846f5420 100644 --- a/src/components/button/button.test.ts +++ b/src/components/button/button.test.ts @@ -2,19 +2,13 @@ import { expect, fixture, html } from '@open-wc/testing'; import sinon from 'sinon'; import type SlButton from './button'; -const variants = ['default', 'primary', 'success', 'neutral', 'warning', 'danger']; - describe('', () => { - describe('accessibility tests', () => { - variants.forEach(variant => { - it(`is should be accessible when variant is "${variant}"`, async () => { - const el = await fixture(html` Button Label `); - await expect(el).to.be.accessible(); - }); - }); - }); - describe('when provided no parameters', () => { + it('passes accessibility test', async () => { + const el = await fixture(html` Button Label `); + await expect(el).to.be.accessible(); + }); + it('default values are set correctly', async () => { const el = await fixture(html` Button Label `); diff --git a/src/components/button/button.ts b/src/components/button/button.ts index 58ebe3bbc..1b84c2d1c 100644 --- a/src/components/button/button.ts +++ b/src/components/button/button.ts @@ -3,10 +3,10 @@ import { customElement, property, query, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { html, literal } from 'lit/static-html.js'; -import '../../components/spinner/spinner'; -import { emit } from '../../internal/event'; -import { FormSubmitController } from '../../internal/form'; -import { HasSlotController } from '../../internal/slot'; +import '~/components/spinner/spinner'; +import { emit } from '~/internal/event'; +import { FormSubmitController } from '~/internal/form'; +import { HasSlotController } from '~/internal/slot'; import styles from './button.styles'; /** diff --git a/src/components/card/card.styles.ts b/src/components/card/card.styles.ts index 817ca597b..2f3d1bb64 100644 --- a/src/components/card/card.styles.ts +++ b/src/components/card/card.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/card/card.ts b/src/components/card/card.ts index 4fd597e7a..07d76ec23 100644 --- a/src/components/card/card.ts +++ b/src/components/card/card.ts @@ -1,7 +1,7 @@ import { html, LitElement } from 'lit'; import { customElement } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import { HasSlotController } from '../../internal/slot'; +import { HasSlotController } from '~/internal/slot'; import styles from './card.styles'; /** diff --git a/src/components/checkbox/checkbox.styles.ts b/src/components/checkbox/checkbox.styles.ts index e84d07b03..5ce6fdcdc 100644 --- a/src/components/checkbox/checkbox.styles.ts +++ b/src/components/checkbox/checkbox.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/checkbox/checkbox.test.ts b/src/components/checkbox/checkbox.test.ts index 73c8ee8a8..12c5454b6 100644 --- a/src/components/checkbox/checkbox.test.ts +++ b/src/components/checkbox/checkbox.test.ts @@ -1,6 +1,5 @@ -import { aTimeout, expect, fixture, html, oneEvent, waitUntil } from '@open-wc/testing'; +import { expect, fixture, html, oneEvent } from '@open-wc/testing'; import { sendKeys } from '@web/test-runner-commands'; -import sinon from 'sinon'; import type SlCheckbox from './checkbox'; describe('', () => { @@ -43,49 +42,4 @@ describe('', () => { el.checked = false; await el.updateComplete; }); - - describe('when submitting a form', () => { - it('should submit the correct value', async () => { - const form = await fixture(html` - - - Submit - - `); - const button = form.querySelector('sl-button')!; - const submitHandler = sinon.spy((event: SubmitEvent) => { - formData = new FormData(form); - event.preventDefault(); - }); - let formData: FormData; - - form.addEventListener('submit', submitHandler); - button.click(); - - await waitUntil(() => submitHandler.calledOnce); - - expect(formData!.get('a')).to.equal('1'); - }); - - it('should show a constraint validation error when setCustomValidity() is called', async () => { - const form = await fixture(html` -
- - Submit -
- `); - const button = form.querySelector('sl-button')!; - const checkbox = form.querySelector('sl-checkbox')!; - const submitHandler = sinon.spy((event: SubmitEvent) => event.preventDefault()); - - // Submitting the form after setting custom validity should not trigger the handler - checkbox.setCustomValidity('Invalid selection'); - form.addEventListener('submit', submitHandler); - button.click(); - - await aTimeout(100); - - expect(submitHandler).to.not.have.been.called; - }); - }); }); diff --git a/src/components/checkbox/checkbox.ts b/src/components/checkbox/checkbox.ts index 0a7f68fef..1d49e384d 100644 --- a/src/components/checkbox/checkbox.ts +++ b/src/components/checkbox/checkbox.ts @@ -3,9 +3,9 @@ import { customElement, property, query, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { live } from 'lit/directives/live.js'; -import { emit } from '../../internal/event'; -import { FormSubmitController } from '../../internal/form'; -import { watch } from '../../internal/watch'; +import { emit } from '~/internal/event'; +import { FormSubmitController } from '~/internal/form'; +import { watch } from '~/internal/watch'; import styles from './checkbox.styles'; /** diff --git a/src/components/color-picker/color-picker.styles.ts b/src/components/color-picker/color-picker.styles.ts index 75ad1862f..039d0f371 100644 --- a/src/components/color-picker/color-picker.styles.ts +++ b/src/components/color-picker/color-picker.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/color-picker/color-picker.ts b/src/components/color-picker/color-picker.ts index 992841357..2fa047859 100644 --- a/src/components/color-picker/color-picker.ts +++ b/src/components/color-picker/color-picker.ts @@ -5,21 +5,21 @@ import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { live } from 'lit/directives/live.js'; import { styleMap } from 'lit/directives/style-map.js'; -import '../../components/button-group/button-group'; -import '../../components/button/button'; -import '../../components/dropdown/dropdown'; -import '../../components/icon/icon'; -import '../../components/input/input'; -import '../../components/visually-hidden/visually-hidden'; -import { drag } from '../../internal/drag'; -import { emit } from '../../internal/event'; -import { FormSubmitController } from '../../internal/form'; -import { clamp } from '../../internal/math'; -import { watch } from '../../internal/watch'; -import { LocalizeController } from '../../utilities/localize'; +import '~/components/button-group/button-group'; +import '~/components/button/button'; +import '~/components/dropdown/dropdown'; +import type SlDropdown from '~/components/dropdown/dropdown'; +import '~/components/icon/icon'; +import '~/components/input/input'; +import type SlInput from '~/components/input/input'; +import '~/components/visually-hidden/visually-hidden'; +import { drag } from '~/internal/drag'; +import { emit } from '~/internal/event'; +import { FormSubmitController } from '~/internal/form'; +import { clamp } from '~/internal/math'; +import { watch } from '~/internal/watch'; +import { LocalizeController } from '~/utilities/localize'; import styles from './color-picker.styles'; -import type SlDropdown from '../../components/dropdown/dropdown'; -import type SlInput from '../../components/input/input'; const hasEyeDropper = 'EyeDropper' in window; diff --git a/src/components/details/details.styles.ts b/src/components/details/details.styles.ts index e42646ef9..f8f18abb3 100644 --- a/src/components/details/details.styles.ts +++ b/src/components/details/details.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/details/details.ts b/src/components/details/details.ts index e694cecba..1be5f3221 100644 --- a/src/components/details/details.ts +++ b/src/components/details/details.ts @@ -1,11 +1,11 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import '../../components/icon/icon'; -import { animateTo, shimKeyframesHeightAuto, stopAnimations } from '../../internal/animate'; -import { emit, waitForEvent } from '../../internal/event'; -import { watch } from '../../internal/watch'; -import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry'; +import '~/components/icon/icon'; +import { animateTo, shimKeyframesHeightAuto, stopAnimations } from '~/internal/animate'; +import { emit, waitForEvent } from '~/internal/event'; +import { watch } from '~/internal/watch'; +import { getAnimation, setDefaultAnimation } from '~/utilities/animation-registry'; import styles from './details.styles'; /** diff --git a/src/components/dialog/dialog.styles.ts b/src/components/dialog/dialog.styles.ts index b2857bc3f..dbf14bfad 100644 --- a/src/components/dialog/dialog.styles.ts +++ b/src/components/dialog/dialog.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/dialog/dialog.ts b/src/components/dialog/dialog.ts index c92d1cabb..cbc7d3cf0 100644 --- a/src/components/dialog/dialog.ts +++ b/src/components/dialog/dialog.ts @@ -2,15 +2,15 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; -import '../../components/icon-button/icon-button'; -import { animateTo, stopAnimations } from '../../internal/animate'; -import { emit, waitForEvent } from '../../internal/event'; -import Modal from '../../internal/modal'; -import { lockBodyScrolling, unlockBodyScrolling } from '../../internal/scroll'; -import { HasSlotController } from '../../internal/slot'; -import { watch } from '../../internal/watch'; -import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry'; -import { LocalizeController } from '../../utilities/localize'; +import '~/components/icon-button/icon-button'; +import { animateTo, stopAnimations } from '~/internal/animate'; +import { emit, waitForEvent } from '~/internal/event'; +import Modal from '~/internal/modal'; +import { lockBodyScrolling, unlockBodyScrolling } from '~/internal/scroll'; +import { HasSlotController } from '~/internal/slot'; +import { watch } from '~/internal/watch'; +import { getAnimation, setDefaultAnimation } from '~/utilities/animation-registry'; +import { LocalizeController } from '~/utilities/localize'; import styles from './dialog.styles'; /** diff --git a/src/components/divider/divider.styles.ts b/src/components/divider/divider.styles.ts index f7d102469..1d99a9be3 100644 --- a/src/components/divider/divider.styles.ts +++ b/src/components/divider/divider.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/divider/divider.ts b/src/components/divider/divider.ts index 13288ca0a..b029df1b0 100644 --- a/src/components/divider/divider.ts +++ b/src/components/divider/divider.ts @@ -1,6 +1,6 @@ import { LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { watch } from '../../internal/watch'; +import { watch } from '~/internal/watch'; import styles from './divider.styles'; /** diff --git a/src/components/drawer/drawer.styles.ts b/src/components/drawer/drawer.styles.ts index 7499ae353..a7e07cf02 100644 --- a/src/components/drawer/drawer.styles.ts +++ b/src/components/drawer/drawer.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/drawer/drawer.ts b/src/components/drawer/drawer.ts index 002fb88fb..8f7fbbcd1 100644 --- a/src/components/drawer/drawer.ts +++ b/src/components/drawer/drawer.ts @@ -2,16 +2,16 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; -import '../../components/icon-button/icon-button'; -import { animateTo, stopAnimations } from '../../internal/animate'; -import { emit, waitForEvent } from '../../internal/event'; -import Modal from '../../internal/modal'; -import { lockBodyScrolling, unlockBodyScrolling } from '../../internal/scroll'; -import { HasSlotController } from '../../internal/slot'; -import { uppercaseFirstLetter } from '../../internal/string'; -import { watch } from '../../internal/watch'; -import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry'; -import { LocalizeController } from '../../utilities/localize'; +import '~/components/icon-button/icon-button'; +import { animateTo, stopAnimations } from '~/internal/animate'; +import { emit, waitForEvent } from '~/internal/event'; +import Modal from '~/internal/modal'; +import { lockBodyScrolling, unlockBodyScrolling } from '~/internal/scroll'; +import { HasSlotController } from '~/internal/slot'; +import { uppercaseFirstLetter } from '~/internal/string'; +import { watch } from '~/internal/watch'; +import { getAnimation, setDefaultAnimation } from '~/utilities/animation-registry'; +import { LocalizeController } from '~/utilities/localize'; import styles from './drawer.styles'; /** diff --git a/src/components/dropdown/dropdown.styles.ts b/src/components/dropdown/dropdown.styles.ts index be0d8b902..0087a5f53 100644 --- a/src/components/dropdown/dropdown.styles.ts +++ b/src/components/dropdown/dropdown.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/dropdown/dropdown.ts b/src/components/dropdown/dropdown.ts index 461062ea1..6d5d07482 100644 --- a/src/components/dropdown/dropdown.ts +++ b/src/components/dropdown/dropdown.ts @@ -2,17 +2,17 @@ import { autoUpdate, computePosition, flip, offset, shift, size } from '@floatin import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import { animateTo, stopAnimations } from '../../internal/animate'; -import { emit, waitForEvent } from '../../internal/event'; -import { scrollIntoView } from '../../internal/scroll'; -import { getTabbableBoundary } from '../../internal/tabbable'; -import { watch } from '../../internal/watch'; -import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry'; +import type SlButton from '~/components/button/button'; +import type SlIconButton from '~/components/icon-button/icon-button'; +import type SlMenuItem from '~/components/menu-item/menu-item'; +import type SlMenu from '~/components/menu/menu'; +import { animateTo, stopAnimations } from '~/internal/animate'; +import { emit, waitForEvent } from '~/internal/event'; +import { scrollIntoView } from '~/internal/scroll'; +import { getTabbableBoundary } from '~/internal/tabbable'; +import { watch } from '~/internal/watch'; +import { getAnimation, setDefaultAnimation } from '~/utilities/animation-registry'; import styles from './dropdown.styles'; -import type SlButton from '../../components/button/button'; -import type SlIconButton from '../../components/icon-button/icon-button'; -import type SlMenuItem from '../../components/menu-item/menu-item'; -import type SlMenu from '../../components/menu/menu'; /** * @since 2.0 diff --git a/src/components/format-bytes/format-bytes.ts b/src/components/format-bytes/format-bytes.ts index 07fd6c391..9bdbb6497 100644 --- a/src/components/format-bytes/format-bytes.ts +++ b/src/components/format-bytes/format-bytes.ts @@ -1,6 +1,6 @@ import { LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { LocalizeController } from '../../utilities/localize'; +import { LocalizeController } from '~/utilities/localize'; /** diff --git a/src/components/format-date/format-date.ts b/src/components/format-date/format-date.ts index 9690ddf84..b94263063 100644 --- a/src/components/format-date/format-date.ts +++ b/src/components/format-date/format-date.ts @@ -1,6 +1,6 @@ import { html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { LocalizeController } from '../../utilities/localize'; +import { LocalizeController } from '~/utilities/localize'; /** * @since 2.0 diff --git a/src/components/format-number/format-number.ts b/src/components/format-number/format-number.ts index a22876013..db46a3c02 100644 --- a/src/components/format-number/format-number.ts +++ b/src/components/format-number/format-number.ts @@ -1,6 +1,6 @@ import { LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { LocalizeController } from '../../utilities/localize'; +import { LocalizeController } from '~/utilities/localize'; /** * @since 2.0 diff --git a/src/components/icon-button/icon-button.styles.ts b/src/components/icon-button/icon-button.styles.ts index 9500feb69..4fa968c72 100644 --- a/src/components/icon-button/icon-button.styles.ts +++ b/src/components/icon-button/icon-button.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/icon-button/icon-button.ts b/src/components/icon-button/icon-button.ts index 3faf81223..3d224747b 100644 --- a/src/components/icon-button/icon-button.ts +++ b/src/components/icon-button/icon-button.ts @@ -2,7 +2,7 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; -import '../../components/icon/icon'; +import '~/components/icon/icon'; import styles from './icon-button.styles'; /** diff --git a/src/components/icon/icon.styles.ts b/src/components/icon/icon.styles.ts index eea476906..1740bb460 100644 --- a/src/components/icon/icon.styles.ts +++ b/src/components/icon/icon.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/icon/icon.test.ts b/src/components/icon/icon.test.ts index 57ba58c18..d5b5e4150 100644 --- a/src/components/icon/icon.test.ts +++ b/src/components/icon/icon.test.ts @@ -1,4 +1,6 @@ +/* eslint-disable no-restricted-imports */ import { elementUpdated, expect, fixture, html, oneEvent } from '@open-wc/testing'; +/* @ts-expect-error - TODO - switch to path aliases when Web Test Runner's esbuild plugin allows it */ import { registerIconLibrary } from '../../../dist/shoelace.js'; import type SlIcon from './icon'; diff --git a/src/components/icon/icon.ts b/src/components/icon/icon.ts index 3abd65a70..617747cbf 100644 --- a/src/components/icon/icon.ts +++ b/src/components/icon/icon.ts @@ -2,8 +2,8 @@ import { html, LitElement } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { unsafeSVG } from 'lit/directives/unsafe-svg.js'; -import { emit } from '../../internal/event'; -import { watch } from '../../internal/watch'; +import { emit } from '~/internal/event'; +import { watch } from '~/internal/watch'; import styles from './icon.styles'; import { getIconLibrary, unwatchIcon, watchIcon } from './library'; import { requestIcon } from './request'; diff --git a/src/components/icon/library.default.ts b/src/components/icon/library.default.ts index 28f3672c5..d59766ec2 100644 --- a/src/components/icon/library.default.ts +++ b/src/components/icon/library.default.ts @@ -1,4 +1,4 @@ -import { getBasePath } from '../../utilities/base-path'; +import { getBasePath } from '~/utilities/base-path'; import type { IconLibrary } from './library'; const library: IconLibrary = { diff --git a/src/components/icon/library.ts b/src/components/icon/library.ts index 2e9713490..a0133d88d 100644 --- a/src/components/icon/library.ts +++ b/src/components/icon/library.ts @@ -1,6 +1,6 @@ +import type SlIcon from '~/components/icon/icon'; import defaultLibrary from './library.default'; import systemLibrary from './library.system'; -import type SlIcon from '../../components/icon/icon'; export type IconLibraryResolver = (name: string) => string; export type IconLibraryMutator = (svg: SVGElement) => void; diff --git a/src/components/icon/request.ts b/src/components/icon/request.ts index 61571eb1e..a78629fd3 100644 --- a/src/components/icon/request.ts +++ b/src/components/icon/request.ts @@ -1,4 +1,4 @@ -import { requestInclude } from '../../components/include/request'; +import { requestInclude } from '~/components/include/request'; type IconFile = | { diff --git a/src/components/image-comparer/image-comparer.styles.ts b/src/components/image-comparer/image-comparer.styles.ts index b3fd29f81..132fb0ffd 100644 --- a/src/components/image-comparer/image-comparer.styles.ts +++ b/src/components/image-comparer/image-comparer.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/image-comparer/image-comparer.ts b/src/components/image-comparer/image-comparer.ts index b9b2739e9..69bf04ff7 100644 --- a/src/components/image-comparer/image-comparer.ts +++ b/src/components/image-comparer/image-comparer.ts @@ -1,11 +1,11 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { styleMap } from 'lit/directives/style-map.js'; -import '../../components/icon/icon'; -import { drag } from '../../internal/drag'; -import { emit } from '../../internal/event'; -import { clamp } from '../../internal/math'; -import { watch } from '../../internal/watch'; +import '~/components/icon/icon'; +import { drag } from '~/internal/drag'; +import { emit } from '~/internal/event'; +import { clamp } from '~/internal/math'; +import { watch } from '~/internal/watch'; import styles from './image-comparer.styles'; /** diff --git a/src/components/include/include.styles.ts b/src/components/include/include.styles.ts index a4aafbb97..fd001391b 100644 --- a/src/components/include/include.styles.ts +++ b/src/components/include/include.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/include/include.ts b/src/components/include/include.ts index 345275888..d49e26e7e 100644 --- a/src/components/include/include.ts +++ b/src/components/include/include.ts @@ -1,7 +1,7 @@ import { html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { emit } from '../../internal/event'; -import { watch } from '../../internal/watch'; +import { emit } from '~/internal/event'; +import { watch } from '~/internal/watch'; import styles from './include.styles'; import { requestInclude } from './request'; diff --git a/src/components/input/input.styles.ts b/src/components/input/input.styles.ts index 4729f33bd..a8ede2833 100644 --- a/src/components/input/input.styles.ts +++ b/src/components/input/input.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; -import formControlStyles from '../../styles/form-control.styles'; +import componentStyles from '~/styles/component.styles'; +import formControlStyles from '~/styles/form-control.styles'; export default css` ${componentStyles} diff --git a/src/components/input/input.test.ts b/src/components/input/input.test.ts index ea947eb43..53b8358eb 100644 --- a/src/components/input/input.test.ts +++ b/src/components/input/input.test.ts @@ -1,6 +1,7 @@ import { expect, fixture, html, waitUntil } from '@open-wc/testing'; import { sendKeys } from '@web/test-runner-commands'; import sinon from 'sinon'; +// eslint-disable-next-line no-restricted-imports import { serialize } from '../../utilities/form'; import type SlInput from './input'; diff --git a/src/components/input/input.ts b/src/components/input/input.ts index 9b8041f93..d3f23c164 100644 --- a/src/components/input/input.ts +++ b/src/components/input/input.ts @@ -3,11 +3,11 @@ import { customElement, property, query, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { live } from 'lit/directives/live.js'; -import '../../components/icon/icon'; -import { emit } from '../../internal/event'; -import { FormSubmitController } from '../../internal/form'; -import { HasSlotController } from '../../internal/slot'; -import { watch } from '../../internal/watch'; +import '~/components/icon/icon'; +import { emit } from '~/internal/event'; +import { FormSubmitController } from '~/internal/form'; +import { HasSlotController } from '~/internal/slot'; +import { watch } from '~/internal/watch'; import styles from './input.styles'; /** diff --git a/src/components/menu-item/menu-item.styles.ts b/src/components/menu-item/menu-item.styles.ts index b1bd3cd46..5471c144c 100644 --- a/src/components/menu-item/menu-item.styles.ts +++ b/src/components/menu-item/menu-item.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/menu-item/menu-item.ts b/src/components/menu-item/menu-item.ts index 8ae68dbd1..8401c91e3 100644 --- a/src/components/menu-item/menu-item.ts +++ b/src/components/menu-item/menu-item.ts @@ -1,8 +1,8 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import '../../components/icon/icon'; -import { watch } from '../../internal/watch'; +import '~/components/icon/icon'; +import { watch } from '~/internal/watch'; import styles from './menu-item.styles'; /** diff --git a/src/components/menu-label/menu-label.styles.ts b/src/components/menu-label/menu-label.styles.ts index 69ec644da..02c4458a8 100644 --- a/src/components/menu-label/menu-label.styles.ts +++ b/src/components/menu-label/menu-label.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/menu/menu.styles.ts b/src/components/menu/menu.styles.ts index 5eef4bd31..c4c004ce8 100644 --- a/src/components/menu/menu.styles.ts +++ b/src/components/menu/menu.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/menu/menu.ts b/src/components/menu/menu.ts index 1fa95b670..7fedf4d84 100644 --- a/src/components/menu/menu.ts +++ b/src/components/menu/menu.ts @@ -1,10 +1,10 @@ import { html, LitElement } from 'lit'; import { customElement, query } from 'lit/decorators.js'; -import { emit } from '../../internal/event'; -import { hasFocusVisible } from '../../internal/focus-visible'; -import { getTextContent } from '../../internal/slot'; +import type SlMenuItem from '~/components/menu-item/menu-item'; +import { emit } from '~/internal/event'; +import { hasFocusVisible } from '~/internal/focus-visible'; +import { getTextContent } from '~/internal/slot'; import styles from './menu.styles'; -import type SlMenuItem from '../../components/menu-item/menu-item'; export interface MenuSelectEventDetail { item: SlMenuItem; } diff --git a/src/components/mutation-observer/mutation-observer.styles.ts b/src/components/mutation-observer/mutation-observer.styles.ts index cb10fcc60..707b58af8 100644 --- a/src/components/mutation-observer/mutation-observer.styles.ts +++ b/src/components/mutation-observer/mutation-observer.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/mutation-observer/mutation-observer.ts b/src/components/mutation-observer/mutation-observer.ts index c6604b1d2..71d57687a 100644 --- a/src/components/mutation-observer/mutation-observer.ts +++ b/src/components/mutation-observer/mutation-observer.ts @@ -1,7 +1,7 @@ import { html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { emit } from '../../internal/event'; -import { watch } from '../../internal/watch'; +import { emit } from '~/internal/event'; +import { watch } from '~/internal/watch'; import styles from './mutation-observer.styles'; /** diff --git a/src/components/progress-bar/progress-bar.styles.ts b/src/components/progress-bar/progress-bar.styles.ts index f0957d1fb..72bf9f636 100644 --- a/src/components/progress-bar/progress-bar.styles.ts +++ b/src/components/progress-bar/progress-bar.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/progress-bar/progress-bar.ts b/src/components/progress-bar/progress-bar.ts index c18e14d5b..4178b8d37 100644 --- a/src/components/progress-bar/progress-bar.ts +++ b/src/components/progress-bar/progress-bar.ts @@ -3,7 +3,7 @@ import { customElement, property } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { styleMap } from 'lit/directives/style-map.js'; -import { LocalizeController } from '../../utilities/localize'; +import { LocalizeController } from '~/utilities/localize'; import styles from './progress-bar.styles'; /** diff --git a/src/components/progress-ring/progress-ring.styles.ts b/src/components/progress-ring/progress-ring.styles.ts index b8c83ca6e..07cc8c0cb 100644 --- a/src/components/progress-ring/progress-ring.styles.ts +++ b/src/components/progress-ring/progress-ring.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/progress-ring/progress-ring.ts b/src/components/progress-ring/progress-ring.ts index 9209fa712..8edc16ace 100644 --- a/src/components/progress-ring/progress-ring.ts +++ b/src/components/progress-ring/progress-ring.ts @@ -1,6 +1,6 @@ import { html, LitElement } from 'lit'; import { customElement, property, query, state } from 'lit/decorators.js'; -import { LocalizeController } from '../../utilities/localize'; +import { LocalizeController } from '~/utilities/localize'; import styles from './progress-ring.styles'; /** diff --git a/src/components/qr-code/qr-code.styles.ts b/src/components/qr-code/qr-code.styles.ts index 99a10c060..ab8d589d9 100644 --- a/src/components/qr-code/qr-code.styles.ts +++ b/src/components/qr-code/qr-code.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/qr-code/qr-code.ts b/src/components/qr-code/qr-code.ts index b46a04dfe..bdf4cffb4 100644 --- a/src/components/qr-code/qr-code.ts +++ b/src/components/qr-code/qr-code.ts @@ -2,7 +2,7 @@ import { html, LitElement } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; import { styleMap } from 'lit/directives/style-map.js'; import QrCreator from 'qr-creator'; -import { watch } from '../../internal/watch'; +import { watch } from '~/internal/watch'; import styles from './qr-code.styles'; /** diff --git a/src/components/radio-button/radio-button.styles.ts b/src/components/radio-button/radio-button.styles.ts deleted file mode 100644 index 21e552330..000000000 --- a/src/components/radio-button/radio-button.styles.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { css } from 'lit'; -import buttonStyles from '../button/button.styles'; - -export default css` - ${buttonStyles} - - label { - display: inline-block; - position: relative; - } - - /* We use a hidden input so constraint validation errors work, since they don't appear to show when used with buttons. - We can't actually hide it, though, otherwise the messages will be suppressed by the browser. */ - .hidden-input { - all: unset; - position: absolute; - top: 0; - left: 0; - bottom: 0; - right: 0; - outline: dotted 1px red; - opacity: 0; - z-index: -1; - } -`; diff --git a/src/components/radio-button/radio-button.test.ts b/src/components/radio-button/radio-button.test.ts index 1b188c7c1..5c580aeb3 100644 --- a/src/components/radio-button/radio-button.test.ts +++ b/src/components/radio-button/radio-button.test.ts @@ -1,7 +1,7 @@ -import { aTimeout, expect, fixture, html, oneEvent, waitUntil } from '@open-wc/testing'; +import { expect, fixture, html, oneEvent, waitUntil } from '@open-wc/testing'; import { sendKeys } from '@web/test-runner-commands'; import sinon from 'sinon'; -import type SlRadioGroup from '../../components/radio-group/radio-group'; +import type SlRadioGroup from '~/components/radio-group/radio-group'; import type SlRadioButton from './radio-button'; describe('', () => { @@ -74,7 +74,7 @@ describe('', () => { - + Submit @@ -95,29 +95,5 @@ describe('', () => { expect(formData!.get('a')).to.equal('2'); }); - - it('should show a constraint validation error when setCustomValidity() is called', async () => { - const form = await fixture(html` -
- - - - - Submit -
- `); - const button = form.querySelector('sl-button')!; - const radio = form.querySelectorAll('sl-radio-button')[1]!; - const submitHandler = sinon.spy((event: SubmitEvent) => event.preventDefault()); - - // Submitting the form after setting custom validity should not trigger the handler - radio.setCustomValidity('Invalid selection'); - form.addEventListener('submit', submitHandler); - button.click(); - - await aTimeout(100); - - expect(submitHandler).to.not.have.been.called; - }); }); }); diff --git a/src/components/radio-button/radio-button.ts b/src/components/radio-button/radio-button.ts index 3acd6bf59..e32078dd7 100644 --- a/src/components/radio-button/radio-button.ts +++ b/src/components/radio-button/radio-button.ts @@ -1,13 +1,10 @@ -import { LitElement } from 'lit'; -import { customElement, property, query, state } from 'lit/decorators.js'; +import { customElement, property } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { html } from 'lit/static-html.js'; -import { emit } from '../../internal/event'; -import { FormSubmitController } from '../../internal/form'; -import { HasSlotController } from '../../internal/slot'; -import { watch } from '../../internal/watch'; -import styles from './radio-button.styles'; +import styles from '~/components/button/button.styles'; +import RadioBase from '~/internal/radio'; +import { HasSlotController } from '~/internal/slot'; /** * @since 2.0 @@ -24,109 +21,16 @@ import styles from './radio-button.styles'; * @slot suffix - Used to append an icon or similar element to the button. * * @csspart base - The component's internal wrapper. - * @csspart button - The internal button element. * @csspart prefix - The prefix slot's container. * @csspart label - The button's label. * @csspart suffix - The suffix slot's container. */ @customElement('sl-radio-button') -export default class SlRadioButton extends LitElement { +export default class SlRadioButton extends RadioBase { static styles = styles; - @query('.button') input: HTMLInputElement; - @query('.hidden-input') hiddenInput: HTMLInputElement; - - protected readonly formSubmitController = new FormSubmitController(this, { - value: (control: SlRadioButton) => (control.checked ? control.value : undefined) - }); private readonly hasSlotController = new HasSlotController(this, '[default]', 'prefix', 'suffix'); - @state() protected hasFocus = false; - - /** The radio's name attribute. */ - @property() name: string; - - /** The radio's value attribute. */ - @property() value: string; - - /** Disables the radio. */ - @property({ type: Boolean, reflect: true }) disabled = false; - - /** Draws the radio in a checked state. */ - @property({ type: Boolean, reflect: true }) checked = false; - - /** - * This will be true when the control is in an invalid state. Validity in radios is determined by the message provided - * by the `setCustomValidity` method. - */ - @property({ type: Boolean, reflect: true }) invalid = false; - - connectedCallback(): void { - super.connectedCallback(); - this.setAttribute('role', 'radio'); - } - - /** Simulates a click on the radio. */ - click() { - this.input.click(); - } - - /** Sets focus on the radio. */ - focus(options?: FocusOptions) { - this.input.focus(options); - } - - /** Removes focus from the radio. */ - blur() { - this.input.blur(); - } - - /** Checks for validity and shows the browser's validation message if the control is invalid. */ - reportValidity() { - return this.hiddenInput.reportValidity(); - } - - /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */ - setCustomValidity(message: string) { - this.hiddenInput.setCustomValidity(message); - } - - handleBlur() { - this.hasFocus = false; - emit(this, 'sl-blur'); - } - - handleClick() { - if (!this.disabled) { - this.checked = true; - } - } - - handleFocus() { - this.hasFocus = true; - emit(this, 'sl-focus'); - } - - @watch('checked') - handleCheckedChange() { - this.setAttribute('aria-checked', this.checked ? 'true' : 'false'); - - if (this.hasUpdated) { - emit(this, 'sl-change'); - } - } - - @watch('disabled', { waitUntilFirstUpdate: true }) - handleDisabledChange() { - this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false'); - - // Disabled form controls are always valid, so we need to recheck validity when the state changes - if (this.hasUpdated) { - this.input.disabled = this.disabled; - this.invalid = !this.input.checkValidity(); - } - } - /** The button's variant. */ @property({ reflect: true }) variant: 'default' | 'primary' | 'success' | 'neutral' | 'warning' | 'danger' = 'default'; @@ -134,54 +38,57 @@ export default class SlRadioButton extends LitElement { /** The button's size. */ @property({ reflect: true }) size: 'small' | 'medium' | 'large' = 'medium'; + /** + * This will be true when the control is in an invalid state. Validity in radio buttons is determined by the message + * provided by the `setCustomValidity` method. + */ + @property({ type: Boolean, reflect: true }) invalid = false; + /** Draws a pill-style button with rounded edges. */ @property({ type: Boolean, reflect: true }) pill = false; render() { return html` -
- - -
+ `; } } diff --git a/src/components/radio-group/radio-group.styles.ts b/src/components/radio-group/radio-group.styles.ts index ffad5702c..d6d7b5799 100644 --- a/src/components/radio-group/radio-group.styles.ts +++ b/src/components/radio-group/radio-group.styles.ts @@ -1,5 +1,5 @@ import { css } from 'lit'; -import componentStyles from '../../styles/component.styles'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/radio-group/radio-group.ts b/src/components/radio-group/radio-group.ts index dada60c1b..7431f24dc 100644 --- a/src/components/radio-group/radio-group.ts +++ b/src/components/radio-group/radio-group.ts @@ -1,9 +1,9 @@ import { html, LitElement } from 'lit'; import { customElement, property, query, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import '../../components/button-group/button-group'; +import '~/components/button-group/button-group'; +import type SlRadio from '~/components/radio/radio'; import styles from './radio-group.styles'; -import type SlRadio from '../../components/radio/radio'; const RADIO_CHILDREN = ['sl-radio', 'sl-radio-button']; diff --git a/src/components/radio/radio.styles.ts b/src/components/radio/radio.styles.ts index cc5bf5f13..190313e22 100644 --- a/src/components/radio/radio.styles.ts +++ b/src/components/radio/radio.styles.ts @@ -1,6 +1,6 @@ import { css } from 'lit'; -import { focusVisibleSelector } from '../../internal/focus-visible'; -import componentStyles from '../../styles/component.styles'; +import { focusVisibleSelector } from '~/internal/focus-visible'; +import componentStyles from '~/styles/component.styles'; export default css` ${componentStyles} diff --git a/src/components/radio/radio.test.ts b/src/components/radio/radio.test.ts index 0654efbde..12c86e634 100644 --- a/src/components/radio/radio.test.ts +++ b/src/components/radio/radio.test.ts @@ -1,7 +1,7 @@ -import { aTimeout, expect, fixture, html, oneEvent, waitUntil } from '@open-wc/testing'; +import { expect, fixture, html, oneEvent, waitUntil } from '@open-wc/testing'; import { sendKeys } from '@web/test-runner-commands'; import sinon from 'sinon'; -import type SlRadioGroup from '../../components/radio-group/radio-group'; +import type SlRadioGroup from '~/components/radio-group/radio-group'; import type SlRadio from './radio'; describe('', () => { @@ -75,7 +75,7 @@ describe('', () => { - + Submit @@ -96,29 +96,5 @@ describe('', () => { expect(formData!.get('a')).to.equal('2'); }); - - it('should show a constraint validation error when setCustomValidity() is called', async () => { - const form = await fixture(html` -
- - - - - Submit -
- `); - const button = form.querySelector('sl-button')!; - const radio = form.querySelectorAll('sl-radio')[1]!; - const submitHandler = sinon.spy((event: SubmitEvent) => event.preventDefault()); - - // Submitting the form after setting custom validity should not trigger the handler - radio.setCustomValidity('Invalid selection'); - form.addEventListener('submit', submitHandler); - button.click(); - - await aTimeout(100); - - expect(submitHandler).to.not.have.been.called; - }); }); }); diff --git a/src/components/radio/radio.ts b/src/components/radio/radio.ts index 26eecd38e..6387da42e 100644 --- a/src/components/radio/radio.ts +++ b/src/components/radio/radio.ts @@ -1,11 +1,9 @@ -import { html, LitElement } from 'lit'; -import { customElement, property, query, state } from 'lit/decorators.js'; +import { html } from 'lit'; +import { customElement } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { live } from 'lit/directives/live.js'; -import { emit } from '../../internal/event'; -import { FormSubmitController } from '../../internal/form'; -import { watch } from '../../internal/watch'; +import RadioBase from '~/internal/radio'; import styles from './radio.styles'; /** @@ -24,102 +22,9 @@ import styles from './radio.styles'; * @csspart label - The radio label. */ @customElement('sl-radio') -export default class SlRadio extends LitElement { +export default class SlRadio extends RadioBase { static styles = styles; - @query('.radio__input') input: HTMLInputElement; - - protected readonly formSubmitController = new FormSubmitController(this, { - value: (control: HTMLInputElement) => (control.checked ? control.value : undefined) - }); - - @state() protected hasFocus = false; - - /** The radio's name attribute. */ - @property() name: string; - - /** The radio's value attribute. */ - @property() value: string; - - /** Disables the radio. */ - @property({ type: Boolean, reflect: true }) disabled = false; - - /** Draws the radio in a checked state. */ - @property({ type: Boolean, reflect: true }) checked = false; - - /** - * This will be true when the control is in an invalid state. Validity in radios is determined by the message provided - * by the `setCustomValidity` method. - */ - @property({ type: Boolean, reflect: true }) invalid = false; - - connectedCallback(): void { - super.connectedCallback(); - this.setAttribute('role', 'radio'); - } - - /** Simulates a click on the radio. */ - click() { - this.input.click(); - } - - /** Sets focus on the radio. */ - focus(options?: FocusOptions) { - this.input.focus(options); - } - - /** Removes focus from the radio. */ - blur() { - this.input.blur(); - } - - /** Checks for validity and shows the browser's validation message if the control is invalid. */ - reportValidity() { - return this.input.reportValidity(); - } - - /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */ - setCustomValidity(message: string) { - this.input.setCustomValidity(message); - this.invalid = !this.input.checkValidity(); - } - - handleBlur() { - this.hasFocus = false; - emit(this, 'sl-blur'); - } - - handleClick() { - if (!this.disabled) { - this.checked = true; - } - } - - handleFocus() { - this.hasFocus = true; - emit(this, 'sl-focus'); - } - - @watch('checked') - handleCheckedChange() { - this.setAttribute('aria-checked', this.checked ? 'true' : 'false'); - - if (this.hasUpdated) { - emit(this, 'sl-change'); - } - } - - @watch('disabled', { waitUntilFirstUpdate: true }) - handleDisabledChange() { - this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false'); - - // Disabled form controls are always valid, so we need to recheck validity when the state changes - if (this.hasUpdated) { - this.input.disabled = this.disabled; - this.invalid = !this.input.checkValidity(); - } - } - render() { return html`