@ory/elements-react 1.2.0-rc.0 → 1.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,30 +1,84 @@
1
- import { UiNodeInputAttributes, UiNode, UiNodeAnchorAttributes, UiNodeTextAttributes, UiNodeImageAttributes, UiText, FlowType, LoginFlow, RegistrationFlow, RecoveryFlow, VerificationFlow, SettingsFlow, UiContainer, OAuth2ConsentRequest, Session, FlowError, ConfigurationParameters, AccountExperienceConfiguration, UpdateLoginFlowBody, UpdateRegistrationFlowBody, UpdateVerificationFlowBody, UpdateRecoveryFlowBody, UpdateSettingsFlowBody, OnRedirectHandler, UiNodeGroupEnum, FrontendApi } from '@ory/client-fetch';
2
- import { ComponentPropsWithoutRef, PropsWithChildren, FormEventHandler, MouseEventHandler, ComponentType, Dispatch } from 'react';
3
- import * as class_variance_authority_types from 'class-variance-authority/types';
4
- import { VariantProps } from 'class-variance-authority';
1
+ import { UiNode, UiNodeInputAttributes, UiNodeTextAttributes, UiNodeImageAttributes, UiNodeAnchorAttributes, UiNodeScriptAttributes, UiNodeDivisionAttributes, UiText, FlowType, LoginFlow, RegistrationFlow, RecoveryFlow, VerificationFlow, SettingsFlow, UiContainer, OAuth2ConsentRequest, Session, FlowError, ConfigurationParameters, AccountExperienceConfiguration, UpdateLoginFlowBody, UpdateRegistrationFlowBody, UpdateVerificationFlowBody, UpdateRecoveryFlowBody, UpdateSettingsFlowBody, OnRedirectHandler, UiNodeGroupEnum, FrontendApi } from '@ory/client-fetch';
2
+ import { ComponentPropsWithoutRef, PropsWithChildren, FormEventHandler, MouseEventHandler, ComponentType, ReactNode, Dispatch } from 'react';
5
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import { IntlShape } from 'react-intl';
4
+ import { IntlShape, useIntl } from 'react-intl';
7
5
 
8
- declare const buttonStyles: (props?: ({
9
- intent?: "primary" | "secondary" | null | undefined;
10
- } & class_variance_authority_types.ClassProp) | undefined) => string;
11
- type ButtonVariants = VariantProps<typeof buttonStyles>;
6
+ type UiNodeInput = UiNode & {
7
+ type: "input";
8
+ attributes: UiNodeInputAttributes;
9
+ };
10
+ declare function isUiNodeInput(node: UiNode): node is UiNodeInput;
11
+ type UiNodeImage = UiNode & {
12
+ type: "img";
13
+ attributes: UiNodeImageAttributes;
14
+ };
15
+ declare function isUiNodeImage(node: UiNode): node is UiNodeImage;
16
+ type UiNodeAnchor = UiNode & {
17
+ type: "a";
18
+ attributes: UiNodeAnchorAttributes;
19
+ };
20
+ declare function isUiNodeAnchor(node: UiNode): node is UiNodeAnchor;
21
+ type UiNodeText = UiNode & {
22
+ type: "text";
23
+ attributes: UiNodeTextAttributes;
24
+ };
25
+ declare function isUiNodeText(node: UiNode): node is UiNodeText;
26
+ type UiNodeScript = UiNode & {
27
+ type: "script";
28
+ attributes: UiNodeScriptAttributes;
29
+ };
30
+ declare function isUiNodeScript(node: UiNode): node is UiNodeScript;
31
+ type UiNodeDiv = UiNode & {
32
+ type: "div";
33
+ attributes: UiNodeDivisionAttributes;
34
+ };
35
+ declare function isUiNodeDiv(node: UiNode): node is UiNodeDiv;
36
+ type UiNodeFixed = UiNodeInput | UiNodeImage | UiNodeAnchor | UiNodeText | UiNodeScript | UiNodeDiv;
12
37
 
38
+ type OryNodeButtonButtonProps = {
39
+ type: "button" | "submit" | "reset";
40
+ name: string;
41
+ value: string | number | readonly string[] | undefined;
42
+ onClick: (event: any) => void;
43
+ disabled?: boolean;
44
+ };
13
45
  type OryNodeButtonProps = {
46
+ /** @deprecated Use node.attributes instead. */
14
47
  attributes: UiNodeInputAttributes;
15
- node: UiNode;
16
- } & Omit<ComponentPropsWithoutRef<"button">, "children"> & ButtonVariants;
48
+ node: UiNodeInput;
49
+ /**
50
+ * Indicates whether the form is currently being submitted via this button.
51
+ */
52
+ isSubmitting: boolean;
53
+ buttonProps: OryNodeButtonButtonProps;
54
+ };
55
+ /**
56
+ * Props for the OryNodeSsoButton component.
57
+ */
58
+ type OryNodeSsoButtonProps = {
59
+ node: UiNodeInput;
60
+ /** @deprecated Use node.attributes instead. */
61
+ attributes: UiNodeInputAttributes;
62
+ provider: string;
63
+ isSubmitting: boolean;
64
+ buttonProps: OryNodeButtonButtonProps;
65
+ };
17
66
  type OryNodeAnchorProps = {
18
67
  attributes: UiNodeAnchorAttributes;
19
68
  node: UiNode;
20
69
  } & Omit<ComponentPropsWithoutRef<"a">, "children">;
21
70
  type OryNodeLabelProps = {
71
+ /** @deprecated Use node.attributes instead. */
22
72
  attributes: UiNodeInputAttributes;
23
- node: UiNode;
24
- } & ComponentPropsWithoutRef<"label">;
73
+ node: UiNodeInput;
74
+ fieldError?: object;
75
+ } & PropsWithChildren;
25
76
  type OryNodeTextProps = {
77
+ node: UiNodeText;
78
+ /**
79
+ * @deprecated Use node.attributes instead.
80
+ */
26
81
  attributes: UiNodeTextAttributes;
27
- node: UiNode;
28
82
  };
29
83
  type OryCardLogoProps = Record<string, never>;
30
84
  type OryNodeCaptchaProps = {
@@ -45,10 +99,12 @@ type OryCardAuthMethodListItemProps = {
45
99
  id: string;
46
100
  values?: Record<string, string>;
47
101
  };
102
+ disabled?: boolean;
48
103
  };
49
104
  type OryNodeImageProps = {
105
+ /** @deprecated Use node.attributes instead. */
50
106
  attributes: UiNodeImageAttributes;
51
- node: UiNode;
107
+ node: UiNodeImage;
52
108
  };
53
109
  /**
54
110
  * A generic type for the form values.
@@ -60,15 +116,54 @@ type FormValues = Record<string, string | boolean | number | undefined>;
60
116
  type OryFormRootProps = ComponentPropsWithoutRef<"form"> & {
61
117
  onSubmit: FormEventHandler<HTMLFormElement>;
62
118
  };
119
+ type OryNodeCheckboxInputProps = {
120
+ name: string;
121
+ onChange: (event: any) => void;
122
+ disabled?: boolean;
123
+ type: "checkbox";
124
+ checked: boolean;
125
+ value: string | number | readonly string[] | undefined;
126
+ ref: (instance: any) => void;
127
+ };
128
+ type OryNodeCheckboxProps = {
129
+ /** @deprecated - use node.attributes */
130
+ attributes: UiNodeInputAttributes;
131
+ node: UiNodeInput;
132
+ /** @deprecated - use inputProps.onClick */
133
+ onClick: MouseEventHandler;
134
+ inputProps: OryNodeCheckboxInputProps;
135
+ };
136
+ type OryNodeInputInputProps = {
137
+ name: string;
138
+ value: string | number | readonly string[] | undefined;
139
+ onClick: MouseEventHandler;
140
+ onChange: (event: any) => void;
141
+ onBlur: () => void;
142
+ ref: (instance: any) => void;
143
+ disabled?: boolean;
144
+ type: string;
145
+ autoComplete?: string;
146
+ maxLength?: number;
147
+ placeholder: string;
148
+ };
63
149
  type OryNodeInputProps = {
150
+ /** @deprecated - use node.attributes */
64
151
  attributes: UiNodeInputAttributes;
65
- node: UiNode;
152
+ node: UiNodeInput;
153
+ /** @deprecated - use inputProps.onClick */
66
154
  onClick?: MouseEventHandler;
155
+ inputProps: OryNodeInputInputProps;
67
156
  };
68
157
  type OryNodeConsentScopeCheckboxProps = {
69
158
  attributes: UiNodeInputAttributes;
70
159
  node: UiNode;
71
160
  onCheckedChange: (checked: boolean) => void;
161
+ inputProps: {
162
+ name: string;
163
+ disabled?: boolean;
164
+ checked: boolean;
165
+ value: string;
166
+ };
72
167
  };
73
168
  type OryFormSectionContentProps = PropsWithChildren<{
74
169
  title?: string;
@@ -205,42 +300,43 @@ declare function OrySettingsCard(): react_jsx_runtime.JSX.Element;
205
300
 
206
301
  type OrySettingsRecoveryCodesProps = {
207
302
  codes: string[];
208
- regnerateButton: UiNode | undefined;
209
- revealButton: UiNode | undefined;
303
+ regenerateButton: UiNodeInput | undefined;
304
+ revealButton: UiNodeInput | undefined;
210
305
  onRegenerate: () => void;
211
306
  onReveal: () => void;
307
+ isSubmitting: boolean;
212
308
  };
213
309
  type OrySettingsTotpProps = {
214
- totpImage: UiNode | undefined;
215
- totpSecret: UiNode | undefined;
216
- totpInput: UiNode | undefined;
217
- totpUnlink: UiNode | undefined;
310
+ totpImage: UiNodeImage | undefined;
311
+ totpSecret: UiNodeText | undefined;
312
+ totpInput: UiNodeInput | undefined;
313
+ totpUnlink: UiNodeInput | undefined;
218
314
  onUnlink: () => void;
315
+ isSubmitting: boolean;
219
316
  };
317
+ /**
318
+ * Props for a button used in the settings flow
319
+ */
320
+ type OryNodeSettingsButton = {
321
+ /** @deprecated - use buttonProps.onClick */
322
+ onClick: () => void;
323
+ buttonProps: OryNodeButtonButtonProps;
324
+ } & UiNodeInput;
220
325
  type OrySettingsSsoProps = {
221
- linkButtons: (UiNode & {
222
- onClick: () => void;
223
- })[];
224
- unlinkButtons: (UiNode & {
225
- onClick: () => void;
226
- })[];
326
+ linkButtons: OryNodeSettingsButton[];
327
+ unlinkButtons: OryNodeSettingsButton[];
328
+ isSubmitting: boolean;
227
329
  };
228
330
  type OrySettingsWebauthnProps = {
229
- nameInput: UiNode;
230
- triggerButton: UiNode & {
231
- onClick: () => void;
232
- };
233
- removeButtons: (UiNode & {
234
- onClick: () => void;
235
- })[];
331
+ nameInput: UiNodeInput;
332
+ triggerButton: OryNodeSettingsButton;
333
+ removeButtons: OryNodeSettingsButton[];
334
+ isSubmitting: boolean;
236
335
  };
237
336
  type OrySettingsPasskeyProps = {
238
- triggerButton: UiNode & {
239
- onClick: () => void;
240
- };
241
- removeButtons: (UiNode & {
242
- onClick: () => void;
243
- })[];
337
+ triggerButton: OryNodeSettingsButton;
338
+ removeButtons: OryNodeSettingsButton[];
339
+ isSubmitting: boolean;
244
340
  };
245
341
 
246
342
  /**
@@ -319,14 +415,6 @@ declare function OrySettingsFormSection({ children, nodes, ...rest }: OryFormSec
319
415
  type OryFormSsoRootProps = PropsWithChildren<{
320
416
  nodes: UiNode[];
321
417
  }>;
322
- /**
323
- * Props for the OryNodeSsoButton component.
324
- */
325
- type OryNodeSsoButtonProps = {
326
- node: UiNode;
327
- attributes: UiNodeInputAttributes;
328
- onClick?: () => void;
329
- };
330
418
  /**
331
419
  * Renders the flow's OIDC buttons.
332
420
  *
@@ -384,7 +472,7 @@ type OryFlowComponents = {
384
472
  /**
385
473
  * The Checkbox component is rendered whenever an input node with of boolean type is encountered.
386
474
  */
387
- Checkbox: ComponentType<OryNodeInputProps>;
475
+ Checkbox: ComponentType<OryNodeCheckboxProps>;
388
476
  /**
389
477
  * The Text component is rendered whenever a "text" node is encountered.
390
478
  */
@@ -549,6 +637,95 @@ interface OryFormProps extends PropsWithChildren {
549
637
  */
550
638
  declare function OryForm({ children, onAfterSubmit }: OryFormProps): react_jsx_runtime.JSX.Element;
551
639
 
640
+ type TextRendererProps = {
641
+ node: UiNodeText;
642
+ };
643
+ declare function TextRenderer({ node }: TextRendererProps): react_jsx_runtime.JSX.Element;
644
+
645
+ type ImageRendererProps = {
646
+ node: UiNodeImage;
647
+ };
648
+ declare function ImageRenderer({ node }: ImageRendererProps): react_jsx_runtime.JSX.Element;
649
+
650
+ type CheckboxRendererProps = {
651
+ node: UiNodeInput;
652
+ };
653
+ declare function CheckboxRenderer({ node }: CheckboxRendererProps): react_jsx_runtime.JSX.Element;
654
+
655
+ type TextBasedInputProps = {
656
+ node: UiNodeInput;
657
+ };
658
+ declare function InputRenderer({ node }: TextBasedInputProps): react_jsx_runtime.JSX.Element;
659
+
660
+ declare function ConsentCheckboxRenderer({ node }: {
661
+ node: UiNodeInput;
662
+ }): react_jsx_runtime.JSX.Element;
663
+
664
+ type SsoButtonProps = {
665
+ node: UiNodeInput;
666
+ };
667
+ declare function SSOButtonRenderer({ node }: SsoButtonProps): react_jsx_runtime.JSX.Element;
668
+
669
+ type ButtonRendererProps = {
670
+ node: UiNodeInput;
671
+ };
672
+ declare function ButtonRenderer({ node }: ButtonRendererProps): react_jsx_runtime.JSX.Element;
673
+ /**
674
+ * Renders the component passed for button nodes.
675
+ *
676
+ * @param props - The properties of the button node to render.
677
+ * @returns A React element representing the button node.
678
+ */
679
+ type ButtonRenderer = typeof ButtonRenderer;
680
+
681
+ type NodeProps = {
682
+ node: UiNode;
683
+ };
684
+ /**
685
+ * Use this component to render any UiNode. It will automatically pick the correct sub-component based on the node type and use any custom components provided via the ComponentsContext.
686
+ *
687
+ * Make sure to use this component instead of the custom component directly, to make sure it's integrated properly with the form system.
688
+ *
689
+ * @param props - NodeProps containing the UiNode to render
690
+ * @returns A ReactNode rendering the appropriate component for the given UiNode
691
+ * @group Components
692
+ */
693
+ declare const Node: (({ node }: NodeProps) => ReactNode) & {
694
+ Button: typeof ButtonRenderer;
695
+ SsoButton: typeof SSOButtonRenderer;
696
+ ConsentCheckbox: typeof ConsentCheckboxRenderer;
697
+ Input: typeof InputRenderer;
698
+ Checkbox: typeof CheckboxRenderer;
699
+ Image: typeof ImageRenderer;
700
+ Text: typeof TextRenderer;
701
+ };
702
+
703
+ /**
704
+ * useResendCode provides a callback to trigger a code resend in the current flow.
705
+ *
706
+ * You may use this hook to implement a "Resend Code" button in your forms.
707
+ *
708
+ * If the current flow does not support code resending, `resendCodeNode` will be `undefined` and `resendCode` will be a no-op.
709
+ *
710
+ * Example:
711
+ * ```tsx
712
+ * const { resendCode, resendCodeNode } = useResendCode();
713
+ *
714
+ * return (
715
+ * {resendCodeNode && (
716
+ * <button onClick={resendCode}>Resend Code</button>
717
+ * )}
718
+ * )
719
+ * ```
720
+ *
721
+ * @returns the callback to trigger a code resend
722
+ * @group Hooks
723
+ */
724
+ declare function useResendCode(): {
725
+ resendCode: () => void;
726
+ resendCodeNode: UiNode | undefined;
727
+ };
728
+
552
729
  /**
553
730
  * The `useComponents` hook provides access to the Ory Flow components provided in the `OryComponentProvider`.
554
731
  *
@@ -785,6 +962,7 @@ interface OryClientConfiguration {
785
962
  * @group Utilities
786
963
  */
787
964
  declare const uiTextToFormattedMessage: ({ id, context, text }: Omit<UiText, "type">, intl: IntlShape) => string;
965
+ declare function resolvePlaceholder(text: UiText, intl: ReturnType<typeof useIntl>): string;
788
966
 
789
967
  /**
790
968
  * Props for the submit handler
@@ -1060,4 +1238,4 @@ interface OryConfigurationProviderProps extends PropsWithChildren {
1060
1238
  */
1061
1239
  declare function OryConfigurationProvider({ children, sdk: initialConfig, project, }: OryConfigurationProviderProps): react_jsx_runtime.JSX.Element;
1062
1240
 
1063
- export { type ConsentFlow, type ConsentFlowContainer, type ErrorFlowContainer, type FlowContainerSetter, type FlowContextValue, type FormState, type FormStateAction, type FormStateMethodActive, type FormStateProvideIdentifier, type FormStateSelectMethod, type FormValues, type IntlConfig, type LoginFlowContainer, type OnSubmitHandlerProps, OryCard, type OryCardAuthMethodListItemProps, OryCardContent, type OryCardContentProps, type OryCardDividerProps, OryCardFooter, type OryCardFooterProps, OryCardHeader, type OryCardHeaderProps, type OryCardLogoProps, type OryCardRootProps as OryCardProps, type OryCardSettingsSectionProps, OryCardValidationMessages, type OryCardValidationMessagesProps, type OryClientConfiguration, OryConfigurationProvider, OryConsentCard, type OryElementsConfiguration, type OryFlowComponentOverrides, type OryFlowComponents, type OryFlowContainer, OryForm, OryFormGroupDivider, type OryFormGroupProps, type OryFormProps, type OryFormRootProps, type OryFormSectionContentProps, type OryFormSectionFooterProps, type OryFormSectionProps, OryFormSsoButtons, OryFormSsoForm, type OryFormSsoRootProps, OryLocales, type OryMessageContentProps, type OryMessageRootProps, type OryNodeAnchorProps, type OryNodeButtonProps, type OryNodeCaptchaProps, type OryNodeConsentScopeCheckboxProps, type OryNodeImageProps, type OryNodeInputProps, type OryNodeLabelProps, type OryNodeSsoButtonProps, type OryNodeTextProps, OryPageHeader, type OryPageHeaderProps, OryProvider, type OryProviderProps, OrySelfServiceFlowCard, OrySettingsCard, type OrySettingsFormProps, OrySettingsFormSection, type OrySettingsPasskeyProps, type OrySettingsRecoveryCodesProps, type OrySettingsSsoProps, type OrySettingsTotpProps, type OrySettingsWebauthnProps, type OryToastProps, type RecoveryFlowContainer, type RegistrationFlowContainer, type SettingsFlowContainer, type VerificationFlowContainer, messageTestId, uiTextToFormattedMessage, useComponents, useNodeSorter, useOryConfiguration, useOryFlow };
1241
+ export { type ConsentFlow, type ConsentFlowContainer, type ErrorFlowContainer, type FlowContainerSetter, type FlowContextValue, type FormState, type FormStateAction, type FormStateMethodActive, type FormStateProvideIdentifier, type FormStateSelectMethod, type FormValues, type IntlConfig, type LoginFlowContainer, Node, type NodeProps, type OnSubmitHandlerProps, OryCard, type OryCardAuthMethodListItemProps, OryCardContent, type OryCardContentProps, type OryCardDividerProps, OryCardFooter, type OryCardFooterProps, OryCardHeader, type OryCardHeaderProps, type OryCardLogoProps, type OryCardRootProps as OryCardProps, type OryCardSettingsSectionProps, OryCardValidationMessages, type OryCardValidationMessagesProps, type OryClientConfiguration, OryConfigurationProvider, OryConsentCard, type OryElementsConfiguration, type OryFlowComponentOverrides, type OryFlowComponents, type OryFlowContainer, OryForm, OryFormGroupDivider, type OryFormGroupProps, type OryFormProps, type OryFormRootProps, type OryFormSectionContentProps, type OryFormSectionFooterProps, type OryFormSectionProps, OryFormSsoButtons, OryFormSsoForm, type OryFormSsoRootProps, OryLocales, type OryMessageContentProps, type OryMessageRootProps, type OryNodeAnchorProps, type OryNodeButtonButtonProps, type OryNodeButtonProps, type OryNodeCaptchaProps, type OryNodeCheckboxInputProps, type OryNodeCheckboxProps, type OryNodeConsentScopeCheckboxProps, type OryNodeImageProps, type OryNodeInputInputProps, type OryNodeInputProps, type OryNodeLabelProps, type OryNodeSettingsButton, type OryNodeSsoButtonProps, type OryNodeTextProps, OryPageHeader, type OryPageHeaderProps, OryProvider, type OryProviderProps, OrySelfServiceFlowCard, OrySettingsCard, type OrySettingsFormProps, OrySettingsFormSection, type OrySettingsPasskeyProps, type OrySettingsRecoveryCodesProps, type OrySettingsSsoProps, type OrySettingsTotpProps, type OrySettingsWebauthnProps, type OryToastProps, type RecoveryFlowContainer, type RegistrationFlowContainer, type SettingsFlowContainer, type UiNodeAnchor, type UiNodeDiv, type UiNodeFixed, type UiNodeImage, type UiNodeInput, type UiNodeScript, type UiNodeText, type VerificationFlowContainer, isUiNodeAnchor, isUiNodeDiv, isUiNodeImage, isUiNodeInput, isUiNodeScript, isUiNodeText, messageTestId, resolvePlaceholder, uiTextToFormattedMessage, useComponents, useNodeSorter, useOryConfiguration, useOryFlow, useResendCode };