Skip to content

Commit

Permalink
update mixin for web components
Browse files Browse the repository at this point in the history
  • Loading branch information
Bars92 committed Jul 24, 2024
1 parent f6fba2f commit 25316d9
Show file tree
Hide file tree
Showing 9 changed files with 1,840 additions and 358 deletions.
4 changes: 2 additions & 2 deletions packages/libs/sdk-mixins/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
declare global {
interface HTMLElement {
attributeChangedCallback(
attributeChangedCallback?(
attrName: string,
oldValue: string | null,
newValue: string | null,
): void;
connectedCallback(): void;
connectedCallback?(): void;
}
}

Expand Down
11 changes: 8 additions & 3 deletions packages/libs/sdk-mixins/src/mixins/themeMixin/themeMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ export const themeMixin = createSingletonMixin(
return theme || 'light';
}

get styleName(): string {
return this.getAttribute('style-name') || THEME_DEFAULT_NAME;
get styleId(): string {
return this.getAttribute('style-id') || THEME_DEFAULT_NAME;
}

#_themeResource: Promise<void | Record<string, any>>;

async #fetchTheme() {
try {
const { body: fetchedTheme } = await this.fetchStaticResource(
`${this.styleName}.json`,
`${this.styleId}.json`,
'json',
);

Expand Down Expand Up @@ -174,6 +174,11 @@ export const themeMixin = createSingletonMixin(
this.#loadFonts();
this.#applyTheme();
});

this.observeAttributes(['style-id'], () => {
this.#_themeResource = null;
this.#loadComponentsStyle();
});
}
};
},
Expand Down
2 changes: 2 additions & 0 deletions packages/sdks/web-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
},
"dependencies": {
"tslib": "2.6.3",
"@descope/sdk-helpers": "workspace:*",
"@descope/sdk-mixins": "workspace:*",
"@descope/web-js-sdk": "workspace:*"
},
"overrides": {
Expand Down
Loading

0 comments on commit 25316d9

Please sign in to comment.