@outbook/webcomponents-clip-flag 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_lib/constants.js +4 -0
- package/_style/clip-flag.style.js +4 -0
- package/clip-flag.js +15 -9
- package/package.json +1 -1
- package/_lib/_clip-flag.style.js +0 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { css } from 'lit';
|
|
3
|
+
|
|
4
|
+
export default css`:host([size=XS]){--clip-flag--width: 1.375rem}:host([size=S]){--clip-flag--width: 2rem}:host([size=M]){--clip-flag--width: 3.5rem}:host([size=L]){--clip-flag--width: 5rem}:host([size=XL]){--clip-flag--width: 8rem}:host([ratio=square]){--clip-flag--ratio: 1 / 1}:host{color-scheme:inherit;display:inline-block;aspect-ratio:var(--clip-flag--ratio, 4/3);width:var(--clip-flag--width, 100%)}.flag,.flag__svg{display:block;width:inherit;height:100%}.flag__svg{position:relative;overflow:hidden}svg,.flag__placeholder{display:block;min-height:100%;position:absolute;height:100%;left:50%;top:50%;transform:translate(-50%, -50%)}.flag__placeholder{display:flex;align-items:center;justify-content:center;width:100%;background:light-dark(oklch(92.2% 0 0deg), oklch(37.1% 0 0deg));color:light-dark(oklch(44.4% 0.177 26.899deg), oklch(88.5% 0.062 18.334deg));font-weight:500;text-align:center}`;
|
package/clip-flag.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { html, LitElement } from 'lit';
|
|
2
2
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
3
|
import { flags } from './_lib/list-flags.js';
|
|
4
|
-
import styleComponent from './
|
|
4
|
+
import styleComponent from './_style/clip-flag.style.js';
|
|
5
|
+
import { RATIO_DEFAULT, SIZE_DEFAULT } from './_lib/constants.js';
|
|
5
6
|
|
|
6
7
|
const LIST_FLAGS = { ...flags, en: flags.gb };
|
|
7
8
|
|
|
8
9
|
class ComponentClipFlag extends LitElement {
|
|
9
10
|
static get properties() {
|
|
10
11
|
return {
|
|
11
|
-
code: { type: String },
|
|
12
|
-
|
|
12
|
+
code: { type: String },
|
|
13
|
+
size: { type: String, reflect: true },
|
|
14
|
+
ratio: { type: String, reflect: true },
|
|
15
|
+
_svgContent: { state: true }
|
|
13
16
|
};
|
|
14
17
|
}
|
|
15
18
|
|
|
@@ -18,6 +21,8 @@ class ComponentClipFlag extends LitElement {
|
|
|
18
21
|
constructor() {
|
|
19
22
|
super();
|
|
20
23
|
this.code = '';
|
|
24
|
+
this.size = SIZE_DEFAULT;
|
|
25
|
+
this.ratio = RATIO_DEFAULT;
|
|
21
26
|
this._svgContent = '';
|
|
22
27
|
}
|
|
23
28
|
|
|
@@ -29,7 +34,6 @@ class ComponentClipFlag extends LitElement {
|
|
|
29
34
|
|
|
30
35
|
_fetchFlag(code) {
|
|
31
36
|
const safeCode = code.toLowerCase().trim();
|
|
32
|
-
|
|
33
37
|
if (LIST_FLAGS[safeCode]) {
|
|
34
38
|
this._svgContent = LIST_FLAGS[safeCode];
|
|
35
39
|
} else {
|
|
@@ -41,9 +45,9 @@ class ComponentClipFlag extends LitElement {
|
|
|
41
45
|
render() {
|
|
42
46
|
return html`
|
|
43
47
|
<span class="flag" aria-hidden="true">
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
<span class="flag__svg">
|
|
49
|
+
${this._svgContent || html`<span class="flag__placeholder">?</span>`}
|
|
50
|
+
</span>
|
|
47
51
|
</span>
|
|
48
52
|
`;
|
|
49
53
|
}
|
|
@@ -56,14 +60,16 @@ if (!customElements.get('outbook-clip-flag')) {
|
|
|
56
60
|
/**
|
|
57
61
|
* Wrapper function
|
|
58
62
|
*
|
|
59
|
-
* @param {{code: *, extraClasses: string}} props
|
|
63
|
+
* @param {{code: *, extraClasses: string, ratio: string}} props
|
|
60
64
|
* @param {string} [props.extraClasses] - Classes to add to the host element
|
|
61
65
|
*/
|
|
62
66
|
export function ClipFlag(props) {
|
|
63
|
-
const { code, extraClasses } = props;
|
|
67
|
+
const { code, ratio = 'natural', size = SIZE_DEFAULT, extraClasses } = props;
|
|
64
68
|
|
|
65
69
|
return html`<outbook-clip-flag
|
|
66
70
|
code="${code}"
|
|
71
|
+
ratio="${ratio}"
|
|
72
|
+
size="${size}"
|
|
67
73
|
class="${ifDefined(extraClasses || undefined)}"
|
|
68
74
|
></outbook-clip-flag>`;
|
|
69
75
|
}
|
package/package.json
CHANGED
package/_lib/_clip-flag.style.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
import { css } from 'lit';
|
|
3
|
-
|
|
4
|
-
export default css`:host{color-scheme:inherit;display:inline-block;aspect-ratio:4/3;width:2rem;overflow:hidden}.flag__svg,svg{width:100%;height:100%;display:block}.flag__placeholder{display:flex;align-items:center;justify-content:center;width:100%;height:100%;background:light-dark(oklch(92.2% 0 0deg), oklch(37.1% 0 0deg));color:light-dark(oklch(44.4% 0.177 26.899deg), oklch(88.5% 0.062 18.334deg));font-weight:bold}`;
|