Skip to content

Commit

Permalink
chore: add style id to react sdk (#782)
Browse files Browse the repository at this point in the history
## Related Issues
related descope/etc#4875

## Related PRs
#744

## Description
- add styleId to react sdk
- add test
- add readme details

## Must

- [ ] Tests
- [ ] Documentation (if applicable)

---------

Signed-off-by: Bar Saar <[email protected]>
Co-authored-by: nirgur <[email protected]>
  • Loading branch information
Bars92 and nirgur authored Aug 22, 2024
1 parent 2ed965e commit 64034a2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions packages/sdks/react-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ const App = () => {
// ...
// logger={logger}
// ...


// Use a custom style name or keep empty to use the default style.
// styleId="my-awesome-style"

/>
)
}
Expand Down
16 changes: 10 additions & 6 deletions packages/sdks/react-sdk/src/components/Descope.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ const DescopeWC = lazy(async () => {
redirectUrl,
client,
form,
styleId,
autoFocus,
validateOnBlur,
}) => (
<descope-wc
<descope-wc
project-id={projectId}
flow-id={flowId}
base-url={baseUrl}
Expand All @@ -65,6 +66,7 @@ const DescopeWC = lazy(async () => {
debug={debug}
client={client}
form={form}
style-id={styleId}
redirect-url={redirectUrl}
auto-focus={autoFocus}
validate-on-blur={validateOnBlur}
Expand Down Expand Up @@ -92,6 +94,7 @@ const Descope = React.forwardRef<HTMLElement, DescopeProps>(
autoFocus,
validateOnBlur,
errorTransformer,
styleId,
},
ref,
) => {
Expand Down Expand Up @@ -193,9 +196,9 @@ const Descope = React.forwardRef<HTMLElement, DescopeProps>(
* it can be removed once this issue will be solved
* https://bugs.chromium.org/p/chromium/issues/detail?id=1404106#c2
*/
<form>
<Suspense fallback={null}>
<DescopeWC
<form>
<Suspense fallback={null}>
<DescopeWC
projectId={projectId}
flowId={flowId}
baseUrl={baseUrl}
Expand All @@ -210,14 +213,15 @@ const Descope = React.forwardRef<HTMLElement, DescopeProps>(
telemetryKey={telemetryKey}
redirectUrl={redirectUrl}
autoFocus={autoFocus}
styleId={styleId}
validateOnBlur={validateOnBlur}
storeLastAuthenticatedUser={storeLastAuthenticatedUser}
keepLastAuthenticatedUserAfterLogout={
keepLastAuthenticatedUserAfterLogout
}
/>
</Suspense>
</form>
</Suspense>
</form>
);
},
);
Expand Down
2 changes: 2 additions & 0 deletions packages/sdks/react-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface IContext {
isSessionFetched: boolean;
projectId: string;
baseUrl?: string;
styleId?: string;
baseStaticUrl?: string;
storeLastAuthenticatedUser?: boolean;
keepLastAuthenticatedUserAfterLogout?: boolean;
Expand Down Expand Up @@ -117,6 +118,7 @@ export type DescopeProps = {
form?: Record<string, any>;
// use to override client context in flow execution
client?: Record<string, any>;
styleId?: string;
};

export type UserManagementProps = WidgetProps;
Expand Down
10 changes: 10 additions & 0 deletions packages/sdks/react-sdk/test/components/Descope.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,14 @@ describe('Descope', () => {
);
});
});

it('should render web-component with style id when provided', async () => {
renderWithProvider(<Descope flowId="flow-1" styleId="test" />);
await waitFor(() => {
expect(document.querySelector('descope-wc')).toHaveAttribute(
'style-id',
'test',
);
});
});
});
2 changes: 1 addition & 1 deletion packages/sdks/web-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ NOTE: This package is a part of a monorepo. so if you make changes in a dependen
| storage-prefix | **String** - A prefix to add to the key of the local storage when persisting tokens | **""** |
| store-last-authenticated-user | **"true"** - Stores last-authenticated user details in local storage when flow is completed</br>**"false"** - Do not store last-auth user details. Disabling this flag may cause last-authenticated user features to not function properly | **"true"** |
| keep-last-authenticated-user-after-logout | **"true"** - Do not clear the last authenticated user details from the browser storage after logout</br>**"false"** - Clear the last authenticated user details from the browser storage after logout | **"false"** |
| | | |
| style-id | **"String"** - Set a specific style to load rather then the default style | **""** |

## Optional Properties

Expand Down

0 comments on commit 64034a2

Please sign in to comment.