Skip to content

Commit

Permalink
refactor: move combobox component to components package
Browse files Browse the repository at this point in the history
  • Loading branch information
tams sokari committed Nov 26, 2023
1 parent 2147702 commit 07b5b3a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 34 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ class ComboboxTrigger extends HTMLElement {
this.innerHTML = `${
this.type === "text"
? `
<div>
<input ${this.value ? `value="${this.value}" ` : ""}${
<div>
<input ${this.value ? `value="${this.value}" ` : ""}${
this.disabled ? " disabled " : ""
}type="text" placeholder="${this.label}" />
<button ${this.disabled ? "disabled " : ""}tabindex='-1' type='button'>
<span class="visually-hidden">Toggle</span>
</button>
</div>
`
<button ${this.disabled ? "disabled " : ""}tabindex='-1' type='button'>
<span class="visually-hidden">Toggle</span>
</button>
</div>
`
: `<button ${this.disabled ? "disabled " : ""}type="button">${
this.value || this.label
}</button>`
Expand Down Expand Up @@ -335,10 +335,10 @@ class ComboboxListbox extends HTMLElement {

get emptyState() {
return `
<p id='empty-state' style="text-align: center;">
${this.emptyLabel || "No items"}
</p>
`;
<p id='empty-state' style="text-align: center;">
${this.emptyLabel || "No items"}
</p>
`;
}

connectedCallback() {
Expand Down Expand Up @@ -571,9 +571,21 @@ class ComboboxOption extends HTMLElement {
}
}

export default {
Root: ComboboxRoot,
Trigger: ComboboxTrigger,
List: ComboboxListbox,
Option: ComboboxOption,
const Root = ComboboxRoot;
const Trigger = ComboboxTrigger;
const List = ComboboxListbox;
const Option = ComboboxOption;

if ("customElements" in window) {
window.customElements.define('smileid-combobox', Root);
window.customElements.define('smileid-combobox-trigger', Trigger);
window.customElements.define('smileid-combobox-listbox', List);
window.customElements.define('smileid-combobox-option', Option);
}

export {
Root,
Trigger,
List,
Option,
};
6 changes: 6 additions & 0 deletions packages/components/combobox/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export {
Root,
Trigger,
List,
Option,
} from './Combobox';
12 changes: 12 additions & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@smileid/components",
"version": "1.0.0",
"private": "true",
"exports": {
".": "./index.js",
"./combobox": "./combobox/src/index.js"
},
"description": "A collection of Web Components used by SmileID",
"keywords": [ "Web Components" ],
"author": "SmileID <[email protected]> (https://usesmileid.com)"
}
7 changes: 1 addition & 6 deletions packages/embed/src/js/basic-kyc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import validate from "validate.js";
import "@smileid/components/combobox";
import ConsentScreen from "./components/ConsentScreen";
import TotpBasedConsent from "./components/TotpConsentApp";
import Combobox from "./components/Combobox";
import { version as sdkVersion } from "../../package.json";

(function basicKyc() {
Expand All @@ -22,11 +22,6 @@ import { version as sdkVersion } from "../../package.json";
window.customElements.define("end-user-consent", ConsentScreen);
window.customElements.define("totp-consent-app", TotpBasedConsent);

window.customElements.define("smileid-combobox", Combobox.Root);
window.customElements.define("smileid-combobox-trigger", Combobox.Trigger);
window.customElements.define("smileid-combobox-listbox", Combobox.List);
window.customElements.define("smileid-combobox-option", Combobox.Option);

const pages = [];
let activeScreen;
let config;
Expand Down
7 changes: 1 addition & 6 deletions packages/embed/src/js/doc-verification.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@smile_identity/smart-camera-web";
import "@smileid/components/combobox";
import JSZip from "jszip";
import { version as sdkVersion } from "../../package.json";
import Combobox from "./components/Combobox";

(function documentVerification() {
"use strict";
Expand All @@ -17,11 +17,6 @@ import Combobox from "./components/Combobox";
const referenceWindow = window.parent;
referenceWindow.postMessage("SmileIdentity::ChildPageReady", "*");

window.customElements.define("smileid-combobox", Combobox.Root);
window.customElements.define("smileid-combobox-trigger", Combobox.Trigger);
window.customElements.define("smileid-combobox-listbox", Combobox.List);
window.customElements.define("smileid-combobox-option", Combobox.Option);

let config;
let activeScreen;
let id_info;
Expand Down
7 changes: 1 addition & 6 deletions packages/embed/src/js/ekyc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import validate from "validate.js";
import "@smileid/components/combobox";
import ConsentScreen from "./components/ConsentScreen";
import TotpBasedConsent from "./components/TotpConsentApp";
import Combobox from "./components/Combobox";
import { version as sdkVersion } from "../../package.json";

(function eKYC() {
Expand All @@ -21,11 +21,6 @@ import { version as sdkVersion } from "../../package.json";
window.customElements.define("end-user-consent", ConsentScreen);
window.customElements.define("totp-consent-app", TotpBasedConsent);

window.customElements.define("smileid-combobox", Combobox.Root);
window.customElements.define("smileid-combobox-trigger", Combobox.Trigger);
window.customElements.define("smileid-combobox-listbox", Combobox.List);
window.customElements.define("smileid-combobox-option", Combobox.Option);

const pages = [];
let activeScreen;
let config;
Expand Down

0 comments on commit 07b5b3a

Please sign in to comment.