diff --git a/.env.example b/.env.example index 4c437f704..ee464187c 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,9 @@ DESCOPE_TENANT_ID= # Your Descope Tenant ID DESCOPE_FLOW_ID="sign-up-or-in" # Your Descope flow ID DESCOPE_STYLE_ID= # Your Descope Style ID DESCOPE_FLOW_DEBUG= # Set to true in case you want to debug your flow +DESCOPE_BG= # Optional page background color or https:// image URL +DESCOPE_FLOW_LOADING= # Set to true to show a loading spinner while the flow initializes +DESCOPE_LOADING_COLOR= # Optional loading spinner color (defaults to bg color, then #0082b5) REACT_APP_DESCOPE_BASE_URL= # Descope API base URL REACT_APP_USE_ORIGIN_BASE_URL= # Set in case you want to use the origin as REACT_APP_FAVICON_URL= # Set in case you want to use a custom favicon diff --git a/README.md b/README.md index 938ffbc90..8e0475542 100644 --- a/README.md +++ b/README.md @@ -55,20 +55,25 @@ These are the different query parameters you can use: 5. `bg` query parameter is optional. If you wish to use a different background color or URL, you can use this parameter. - **Color name**: You can use a [web color](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value), e.g. `bg=red`, `bg=%23ff0000`. Note that some symbols such as `#` will have to be URL encoded. - **Image URL**: You can specify a URL to an image such as `https://example.com/background.png`. This image will be sized to cover the screen. + - When `bg` is a color, the flow loading spinner uses the same color by default. -6. `wide` query parameter is optional. If wide mode is nedded use `wide=true`. This will widen the flow component that is rendered, which is used for large forms made with Flow screens. +6. `loading` query parameter is optional. By default, no loading spinner is shown. Set `loading=true` to show a spinner while the flow initializes and during redirect steps (for example, when the first step is SSO). -7. `theme` query parameter is optional. The default value is `light`, but otherwise it will override the theme for your flows rendered with the SDK. +7. `loading_color` query parameter is optional. Sets the loading spinner color using the same formats as `bg` (including bare hex, e.g. `loading_color=ffffff`). Only applies when `loading=true`. If omitted, the spinner uses `bg` when it is a color; otherwise it defaults to `#0082b5`. -8. `style` query parameter is optional. The default style in your project will be used if not defined, but this allows you to override the `style` for the flows rendered with the SDK. +8. `wide` query parameter is optional. If wide mode is nedded use `wide=true`. This will widen the flow component that is rendered, which is used for large forms made with Flow screens. -9. `store_last_auth_user` query parameter is optional. Pass this parameter to ensure the last authenticated user is not saved when the flow ends. For example, append `store_last_auth_user=false` to the URL to disable saving the last user. +9. `theme` query parameter is optional. The default value is `light`, but otherwise it will override the theme for your flows rendered with the SDK. -10. Additional query parameters prefixed with `client.` are passed to the `Descope` component as its `client` prop. For example: `client.k1=v1&client.k2=v2` becomes `{ k1: 'v1', k2: 'v2' }`. +10. `style` query parameter is optional. The default style in your project will be used if not defined, but this allows you to override the `style` for the flows rendered with the SDK. -11. `width` & `height` are optional query parameters, controlling the sizing of the flow screen in either pixels or a percentage of the viewport (e.g. `50%`, `1200px`). Any value larger than the screen is clamped down. +11. `store_last_auth_user` query parameter is optional. Pass this parameter to ensure the last authenticated user is not saved when the flow ends. For example, append `store_last_auth_user=false` to the URL to disable saving the last user. -12. `title` query parameter is optional. If provided, it sets the browser tab/document title (e.g. `title=Sign%20in`). +12. Additional query parameters prefixed with `client.` are passed to the `Descope` component as its `client` prop. For example: `client.k1=v1&client.k2=v2` becomes `{ k1: 'v1', k2: 'v2' }`. + +13. `width` & `height` are optional query parameters, controlling the sizing of the flow screen in either pixels or a percentage of the viewport (e.g. `50%`, `1200px`). Any value larger than the screen is clamped down. + +14. `title` query parameter is optional. If provided, it sets the browser tab/document title (e.g. `title=Sign%20in`). **Using .env** diff --git a/src/App.css b/src/App.css index f1d326c5e..1de681c78 100644 --- a/src/App.css +++ b/src/App.css @@ -87,6 +87,33 @@ body, display: inline-block; } +.flow-loading-overlay { + position: fixed; + inset: 0; + z-index: 1000; + display: flex; + align-items: center; + justify-content: center; + background: rgba(255, 255, 255, 0.88); + backdrop-filter: blur(2px); +} + +.flow-loading-spinner { + width: 44px; + height: 44px; + border-radius: 50%; + border: 3px solid + color-mix(in srgb, var(--flow-loading-color, #0082b5) 20%, transparent); + border-top-color: var(--flow-loading-color, #0082b5); + animation: flow-loading-spin 0.8s linear infinite; +} + +@keyframes flow-loading-spin { + to { + transform: rotate(360deg); + } +} + h1 { margin: 0px; font-weight: 800; diff --git a/src/App.test.tsx b/src/App.test.tsx index 432a2c71f..390a5c0e4 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -18,8 +18,16 @@ const mockAuthProvider = jest.fn(); jest.mock('@descope/react-sdk', () => ({ ...jest.requireActual('@descope/react-sdk'), - Descope: ({ onSuccess, ...props }: { onSuccess: () => void }) => { + Descope: ({ + onSuccess, + onReady = () => {}, + ...props + }: { + onSuccess: () => void; + onReady: () => void; + }) => { mockDescope(props); + setTimeout(onReady, 0); return (