@spectrum-web-components/base 0.5.1 → 0.5.2-express.41
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.
- package/package.json +2 -2
- package/src/sizedMixin.d.ts +1 -0
- package/src/sizedMixin.js +9 -0
- package/src/sizedMixin.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/base",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2-express.41+5d9e2a2ca",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"types": "./src/index.d.ts",
|
|
57
57
|
"customElements": "custom-elements.json",
|
|
58
58
|
"sideEffects": false,
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "5d9e2a2ca93deff51e4b2c7b8354f1127009a4e3"
|
|
60
60
|
}
|
package/src/sizedMixin.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare type Constructor<T = Record<string, unknown>> = {
|
|
|
4
4
|
prototype: T;
|
|
5
5
|
};
|
|
6
6
|
export declare type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';
|
|
7
|
+
export declare const ElementSizes: Record<string, ElementSize>;
|
|
7
8
|
export declare type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;
|
|
8
9
|
export interface SizedElementInterface {
|
|
9
10
|
size: ElementSize;
|
package/src/sizedMixin.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { property } from 'lit/decorators.js';
|
|
3
|
+
export const ElementSizes = {
|
|
4
|
+
xxs: 'xxs',
|
|
5
|
+
xs: 'xs',
|
|
6
|
+
s: 's',
|
|
7
|
+
m: 'm',
|
|
8
|
+
l: 'l',
|
|
9
|
+
xl: 'xl',
|
|
10
|
+
xxl: 'xxl',
|
|
11
|
+
};
|
|
3
12
|
export function SizedMixin(constructor, { validSizes = ['s', 'm', 'l', 'xl'], noDefaultSize, defaultSize = 'm', } = {}) {
|
|
4
13
|
class SizedElement extends constructor {
|
|
5
14
|
constructor() {
|
package/src/sizedMixin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAS7C,MAAM,CAAC,MAAM,YAAY,GAAgC;IACrD,GAAG,EAAE,KAAK;IACV,EAAE,EAAE,IAAI;IACR,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;CACb,CAAC;AAOF,MAAM,UAAU,UAAU,CACtB,WAAc,EACd,EACI,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAClC,aAAa,EACb,WAAW,GAAG,GAAG,MAKjB,EAAE;IAEN,MAAM,YAAa,SAAQ,WAAW;QAAtC;;YAyBY,UAAK,GAAuB,WAAW,CAAC;QAQpD,CAAC;QA/BG,IAAW,IAAI;YACX,OAAO,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC;QACrC,CAAC;QAED,IAAW,IAAI,CAAC,KAAkB;YAC9B,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;YACxD,MAAM,IAAI,GAAG,CACT,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,KAAK,CAC7B,CAAC;YACjB,MAAM,SAAS,GAAG,CACd,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CACnC,CAAC;YACjB,IAAI,SAAS,EAAE;gBACX,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;aACxC;YACD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC1B,OAAO;aACV;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAIS,YAAY,CAAC,OAAuB;YAC1C,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE;gBAC9C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aACxC;QACL,CAAC;KACJ;IA/BG;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CAGzC;IA8BL,OAAO,YAAY,CAAC;AACxB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';\nexport const ElementSizes: Record<string, ElementSize> = {\n xxs: 'xxs',\n xs: 'xs',\n s: 's',\n m: 'm',\n l: 'l',\n xl: 'xl',\n xxl: 'xxl',\n};\nexport type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = ['s', 'm', 'l', 'xl'],\n noDefaultSize,\n defaultSize = 'm',\n }: {\n validSizes?: ElementSize[];\n noDefaultSize?: boolean;\n defaultSize?: ElementSize;\n } = {}\n): T & Constructor<SizedElementInterface> {\n class SizedElement extends constructor {\n @property({ type: String, reflect: true })\n public get size(): ElementSize {\n return this._size || defaultSize;\n }\n\n public set size(value: ElementSize) {\n const fallbackSize = noDefaultSize ? null : defaultSize;\n const size = (\n value ? value.toLocaleLowerCase() : value\n ) as ElementSize;\n const validSize = (\n validSizes.includes(size) ? size : fallbackSize\n ) as ElementSize;\n if (validSize) {\n this.setAttribute('size', validSize);\n }\n if (this._size === validSize) {\n return;\n }\n const oldSize = this._size;\n this._size = validSize;\n this.requestUpdate('size', oldSize);\n }\n\n private _size: ElementSize | null = defaultSize;\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('size') && !noDefaultSize) {\n this.setAttribute('size', this.size);\n }\n }\n }\n return SizedElement;\n}\n"]}
|