Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support multi style and style prop #744

Merged
merged 40 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e622305
support multi style and style parameter in flow web component
Bars92 Jul 18, 2024
484eb8b
Merge branch 'main' into multi-style-project
Bars92 Jul 22, 2024
3ebbedf
update style name and add test
Bars92 Jul 22, 2024
9a085fe
Merge branch 'main' into multi-style-project
nirgur Jul 23, 2024
f6fba2f
Merge branch 'main' into multi-style-project
nirgur Jul 24, 2024
25316d9
update mixin for web components
Bars92 Jul 24, 2024
f44a2f4
update package
Bars92 Jul 24, 2024
172b478
remove unused const
Bars92 Jul 24, 2024
fe503b8
CR fixes
nirgur Jul 24, 2024
f01eaf2
remove unused
Bars92 Jul 24, 2024
a068dda
fix nx config
nirgur Jul 24, 2024
0f3a68e
fix nx config
nirgur Jul 24, 2024
b1747e9
fix types
nirgur Jul 24, 2024
8f0ffb5
fixes
nirgur Jul 24, 2024
a5ec4be
fix lint and remove skip
Bars92 Jul 25, 2024
e735ef5
fix lint
Bars92 Jul 25, 2024
8e426e3
fix lint
Bars92 Jul 25, 2024
83c7d9b
fix lint
Bars92 Jul 25, 2024
cf8ef19
fix tests
Bars92 Jul 25, 2024
ec8d3ff
remove skip
Bars92 Jul 28, 2024
4da0cce
merge from main
Bars92 Jul 28, 2024
9625660
merge from main
Bars92 Jul 28, 2024
fc9bb0f
merge from main
Bars92 Jul 28, 2024
f04cb01
fix tests and init
Bars92 Jul 28, 2024
308d36b
fix lint
Bars92 Jul 28, 2024
3650efc
Merge branch 'main' into multi-style-project
nirgur Jul 28, 2024
0861ab3
fix cov
Bars92 Jul 28, 2024
f7c04dd
lint
Bars92 Jul 28, 2024
a99a791
Merge branch 'multi-style-project' of github.com:descope/descope-js i…
Bars92 Jul 28, 2024
c05c2b8
merge with main
nirgur Jul 28, 2024
83bfd6c
merge with main
nirgur Jul 28, 2024
57d8a78
Merge branch 'main' of github.com:descope/descope-js into multi-style…
Bars92 Aug 5, 2024
33b20e4
lint
Bars92 Aug 5, 2024
af65886
Merge branch 'main' into multi-style-project
Bars92 Aug 6, 2024
0a6539d
Merge branch 'main' into multi-style-project
Bars92 Aug 7, 2024
d9d24de
fix logger
Bars92 Aug 8, 2024
a641877
fix lint
Bars92 Aug 8, 2024
529e04a
Merge branch 'main' into multi-style-project
Bars92 Aug 9, 2024
40867b8
Merge branch 'main' into multi-style-project
Bars92 Aug 11, 2024
537cea2
fix pnpm lock
Bars92 Aug 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"postversion:ci": "pnpm run build:ci",
"print-affected:ci": "nx print-affected --base=$(sh ./tools/scripts/latestTag.sh) --select=projects",
"format": "nx format:write",
"format:ci": "nx format:check"
"format:ci": "nx format:check",
"postinstall": "pnpm update @descope/web-components-ui"
},
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Those files are saved on a new folder to prevent breaking changes
export const THEME_FILENAME = 'theme.json';
export const DEFAULT_STYLE_ID = 'theme';
export const CONFIG_FILENAME = 'config.json';
48 changes: 39 additions & 9 deletions packages/libs/sdk-mixins/src/mixins/themeMixin/themeMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { descopeUiMixin } from '../descopeUiMixin';
import { initElementMixin } from '../initElementMixin';
import { initLifecycleMixin } from '../initLifecycleMixin';
import { staticResourcesMixin } from '../staticResourcesMixin';
import { THEME_FILENAME } from './constants';
import { DEFAULT_STYLE_ID } from './constants';
import { loadDevTheme, loadFont } from './helpers';
import { observeAttributesMixin } from '../observeAttributesMixin';
import { UI_COMPONENTS_URL_KEY } from '../descopeUiMixin/constants';
Expand All @@ -32,6 +32,8 @@ export const themeMixin = createSingletonMixin(
)(superclass);

return class ThemeMixinClass extends BaseClass {
#globalStyleTag: HTMLStyleElement;

get theme(): ThemeOptions {
const theme = this.getAttribute('theme') as ThemeOptions | null;

Expand All @@ -46,12 +48,16 @@ export const themeMixin = createSingletonMixin(
return theme || 'light';
}

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

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

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

Expand Down Expand Up @@ -116,11 +122,14 @@ export const themeMixin = createSingletonMixin(
const theme = await this.#themeResource;
if (!theme) return;

const styleEle = document.createElement('style');
styleEle.innerText =
(theme?.light?.globals || '') + (theme?.dark?.globals || '');
if (!this.#globalStyleTag) {
this.#globalStyleTag = document.createElement('style');
this.#globalStyleTag.id = 'global-style';
this.shadowRoot!.appendChild(this.#globalStyleTag);
}

this.shadowRoot!.appendChild(styleEle);
this.#globalStyleTag.innerText =
(theme?.light?.globals || '') + (theme?.dark?.globals || '');
}

async #loadComponentsStyle() {
Expand All @@ -136,17 +145,31 @@ export const themeMixin = createSingletonMixin(
}
}

async #loadFonts() {
const { projectConfig } = await this.config;
async #getFontsConfig() {
const { projectConfig } = (await this.config) || {};

const newConfig = projectConfig?.styles?.[this.styleId];
const oldConfig = projectConfig?.cssTemplate;

const config = newConfig || oldConfig;

const fonts: Record<string, { url?: string }> | undefined =
projectConfig?.cssTemplate?.[this.theme]?.fonts;
config?.[this.theme]?.fonts;

return fonts;
}

async #loadFonts() {
const fonts = await this.#getFontsConfig();
if (fonts) {
Object.values(fonts).forEach((font) => {
if (font.url) {
this.logger.debug(`Loading font from URL "${font.url}"`);
loadFont(font.url);
}
});
} else {
this.logger.debug('No fonts to load');
}
}

Expand All @@ -170,6 +193,13 @@ export const themeMixin = createSingletonMixin(
this.#loadFonts();
this.#applyTheme();
});

this.observeAttributes(['style-id'], () => {
this.#_themeResource = null;
this.#loadFonts();
this.#loadGlobalStyle();
this.#loadComponentsStyle();
Bars92 marked this conversation as resolved.
Show resolved Hide resolved
});
}
};
},
Expand Down
12 changes: 7 additions & 5 deletions packages/sdks/nextjs-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,26 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/s

### Dependency Updates

* `react-sdk` updated to version `2.0.63`
- `react-sdk` updated to version `2.0.63`

## [0.0.20](https://github.com/descope/descope-js/compare/nextjs-sdk-0.0.19...nextjs-sdk-0.0.20) (2024-08-03)

### Dependency Updates

* `react-sdk` updated to version `2.0.62`
* `web-component` updated to version `3.22.0`
- `react-sdk` updated to version `2.0.62`
- `web-component` updated to version `3.22.0`

## [0.0.19](https://github.com/descope/descope-js/compare/nextjs-sdk-0.0.18...nextjs-sdk-0.0.19) (2024-08-01)

## [0.0.18](https://github.com/descope/descope-js/compare/nextjs-sdk-0.0.17...nextjs-sdk-0.0.18) (2024-07-31)

### Dependency Updates

* `react-sdk` updated to version `2.0.61`
- `react-sdk` updated to version `2.0.61`

### Bug Fixes

* issue 7219 RELEASE ([#765](https://github.com/descope/descope-js/issues/765)) ([eec8843](https://github.com/descope/descope-js/commit/eec88439177d57dd19665c96bd57dc206ca3b4f4))
- issue 7219 RELEASE ([#765](https://github.com/descope/descope-js/issues/765)) ([eec8843](https://github.com/descope/descope-js/commit/eec88439177d57dd19665c96bd57dc206ca3b4f4))

## [0.0.17](https://github.com/descope/descope-js/compare/nextjs-sdk-0.0.16...nextjs-sdk-0.0.17) (2024-07-28)

Expand Down
6 changes: 3 additions & 3 deletions packages/sdks/web-component/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module.exports = {
coverageThreshold: {
global: {
branches: 81,
functions: 89,
lines: 93,
statements: 93,
functions: 87,
lines: 89,
statements: 89,
},
},
globals: {
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:*",
"@fingerprintjs/fingerprintjs-pro": "3.9.9"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/sdks/web-component/src/lib/constants/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ export const BASE_CONTENT_URL = 'https://static.descope.com/pages';
export const ASSETS_FOLDER = 'v2-beta';
export const PREV_VER_ASSETS_FOLDER = 'v2-alpha';

// Those files are saved on a new folder to prevent breaking changes
export const THEME_FILENAME = 'theme.json';
export const CONFIG_FILENAME = 'config.json';
Loading
Loading