@outbook/webcomponents-clip-flag 1.0.0 → 1.0.2

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.
@@ -0,0 +1,4 @@
1
+ export const RATIOS = ['natural', 'square'];
2
+ export const RATIO_DEFAULT = 'natural';
3
+ export const SIZES = ['CUSTOM', 'XS', 'S', 'M', 'L', 'XL'];
4
+ export const SIZE_DEFAULT = 'CUSTOM';
@@ -1,5 +1,10 @@
1
1
  import { svg } from 'lit';
2
2
 
3
+ const vn = svg`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 85.333 512 341.333">
4
+ <path fill="#d80027" d="M196.641 85.337H0v341.326h512V85.337z"/>
5
+ <path fill="#ffda44" d="m256 157.279 22.663 69.747H352l-59.332 43.106 22.664 69.749L256 296.774l-59.332 43.107 22.664-69.749L160 227.026h73.337z"/>
6
+ </svg>`;
7
+
3
8
  export const flags = {
4
9
  es: svg`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22.5 15">
5
10
  <path fill="#d03433" d="M0 0h22.5v4H0zm0 11h22.5v4H0z"/>
@@ -16,8 +21,6 @@ export const flags = {
16
21
  <path d="M311.7 230 513 341.3v-31.5L369.3 230zm-168 0L0 309.9v31.5L200.3 230zm56.6-118.7L0 0v31.5l143.7 79.8zm168 0L513 31.5V0L311.7 111.3z"/>
17
22
  </g>
18
23
  </svg>`,
19
- vn: svg`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 85.333 512 341.333">
20
- <path fill="#d80027" d="M196.641 85.337H0v341.326h512V85.337z"/>
21
- <path fill="#ffda44" d="m256 157.279 22.663 69.747H352l-59.332 43.106 22.664 69.749L256 296.774l-59.332 43.107 22.664-69.749L160 227.026h73.337z"/>
22
- </svg>`
23
- };
24
+ vi: vn,
25
+ vn
26
+ };
@@ -0,0 +1,4 @@
1
+ /* eslint-disable */
2
+ import { css } from 'lit';
3
+
4
+ export default css`:host([size=XS]){--_width: 1.375rem}:host([size=S]){--_width: 2rem}:host([size=M]){--_width: 3.5rem}:host([size=L]){--_width: 5rem}:host([size=XL]){--_width: 8rem}:host([ratio=square]){--_ratio: 1 / 1}:host{color-scheme:inherit;display:inline-block;aspect-ratio:var(--_ratio, 4/3);width:var(--_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 './_lib/_clip-flag.style.js';
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 }, // public attr
12
- _svgContent: { state: true } // internal state
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
- ${this._svgContent
45
- ? html`<span class="flag__svg">${this._svgContent}</span>`
46
- : html`<span class="flag__placeholder">?</span>`}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outbook/webcomponents-clip-flag",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "clip-flag.js",
5
5
  "type": "module",
6
6
  "private": false,
@@ -22,7 +22,7 @@
22
22
  "description": "Web components clip-flag",
23
23
  "devDependencies": {
24
24
  "@outbook/colorful": ">=1.1.2",
25
- "@outbook/design-decisions": ">=1.1.2"
25
+ "@outbook/design-decisions": ">=1.1.4"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "sass": "^1.97.2",
@@ -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}`;