@ttoss/react-auth 1.5.0 → 1.6.0

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/esm/index.js CHANGED
@@ -76,12 +76,12 @@ var useAuth = () => {
76
76
  };
77
77
 
78
78
  // src/Auth.tsx
79
- import * as React3 from "react";
79
+ import * as React4 from "react";
80
80
  import { Auth as AmplifyAuth } from "aws-amplify";
81
81
 
82
82
  // src/AuthCard.tsx
83
83
  import * as React2 from "react";
84
- import { Box, Button, Flex, Link, Text } from "@ttoss/ui";
84
+ import { Box, Button, Flex, Heading } from "@ttoss/ui";
85
85
  import { useNotifications } from "@ttoss/react-notifications";
86
86
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
87
87
  var LogoContext = /*#__PURE__*/React2.createContext({});
@@ -98,7 +98,8 @@ var AuthCard = ({
98
98
  children,
99
99
  title,
100
100
  buttonLabel,
101
- links = []
101
+ extraButton,
102
+ isValidForm
102
103
  }) => {
103
104
  const {
104
105
  logo
@@ -106,59 +107,54 @@ var AuthCard = ({
106
107
  const {
107
108
  isLoading
108
109
  } = useNotifications();
109
- return /* @__PURE__ */jsx2(Box, {
110
+ return /* @__PURE__ */jsxs(Box, {
110
111
  sx: {
111
- maxWidth: "564px"
112
+ maxWidth: "390px",
113
+ border: "default",
114
+ borderColor: "primary",
115
+ paddingX: "2xl",
116
+ paddingY: "3xl",
117
+ backgroundColor: "surface"
112
118
  },
113
- children: /* @__PURE__ */jsxs(Flex, {
119
+ children: [logo && /* @__PURE__ */jsx2(Flex, {
114
120
  sx: {
115
- flexDirection: "column",
116
- gap: "md"
121
+ width: "100%",
122
+ maxHeight: "90px",
123
+ justifyContent: "center",
124
+ marginBottom: "2xl"
117
125
  },
118
- children: [logo && /* @__PURE__ */jsx2(Flex, {
119
- sx: {
120
- width: "100%",
121
- justifyContent: "center"
122
- },
123
- children: logo
124
- }), /* @__PURE__ */jsx2(Text, {
126
+ children: logo
127
+ }), /* @__PURE__ */jsxs(Flex, {
128
+ sx: {
129
+ flexDirection: "column"
130
+ },
131
+ children: [/* @__PURE__ */jsx2(Heading, {
132
+ as: "h2",
133
+ variant: "h2",
125
134
  sx: {
126
- alignSelf: "center",
127
- marginY: "md",
128
- fontSize: "xl"
135
+ marginBottom: "2xl"
129
136
  },
130
137
  children: title
131
- }), children, /* @__PURE__ */jsx2(Flex, {
138
+ }), children, /* @__PURE__ */jsxs(Flex, {
132
139
  sx: {
133
- justifyContent: "space-between",
134
- marginTop: "md"
140
+ flexDirection: "column",
141
+ width: "100%",
142
+ gap: "xl",
143
+ marginTop: "2xl"
135
144
  },
136
- children: /* @__PURE__ */jsx2(Button, {
145
+ children: [/* @__PURE__ */jsx2(Button, {
137
146
  type: "submit",
138
- "aria-label": "submit-login",
139
- variant: "cta",
140
- disabled: isLoading,
147
+ "aria-label": "submit-button",
148
+ variant: "accent",
149
+ disabled: isLoading || !isValidForm,
141
150
  sx: {
142
- width: "100%"
151
+ textAlign: "center",
152
+ display: "initial"
143
153
  },
144
154
  children: buttonLabel
145
- })
146
- }), /* @__PURE__ */jsx2(Flex, {
147
- sx: {
148
- justifyContent: "space-between",
149
- flexDirection: "column",
150
- gap: "sm",
151
- marginTop: "md",
152
- color: "text"
153
- },
154
- children: links.map(link => {
155
- return link && /* @__PURE__ */jsx2(Link, {
156
- onClick: link.onClick,
157
- children: link.label
158
- }, link.label);
159
- })
155
+ }), extraButton]
160
156
  })]
161
- })
157
+ })]
162
158
  });
163
159
  };
164
160
 
@@ -217,6 +213,7 @@ var AuthConfirmSignUp = ({
217
213
  "value": "Confirm"
218
214
  }]
219
215
  }),
216
+ isValidForm: formMethods.formState.isValid,
220
217
  title: intl.formatMessage({
221
218
  id: "cGR2eI",
222
219
  defaultMessage: [{
@@ -260,6 +257,7 @@ var AuthFullScreen = ({
260
257
  };
261
258
 
262
259
  // src/AuthSignIn.tsx
260
+ import { Button as Button2, Flex as Flex3, Link, Text } from "@ttoss/ui";
263
261
  import { Form as Form2, FormFieldInput as FormFieldInput2, useForm as useForm2, yup as yup2, yupResolver as yupResolver2 } from "@ttoss/forms";
264
262
 
265
263
  // ../cloud-auth/dist/esm/index.js
@@ -505,17 +503,48 @@ createAuthTemplate.CognitoUserPoolLogicalId = CognitoUserPoolLogicalId;
505
503
  createAuthTemplate.CognitoUserPoolClientLogicalId = CognitoUserPoolClientLogicalId;
506
504
  createAuthTemplate.CognitoIdentityPoolLogicalId = CognitoIdentityPoolLogicalId;
507
505
 
506
+ // src/useHidePassInput.ts
507
+ import * as React3 from "react";
508
+ var useHidePassInput = (defaultValue = true) => {
509
+ const [hidePass, setHidePass] = React3.useState(Boolean(defaultValue));
510
+ const {
511
+ icon,
512
+ inputType
513
+ } = React3.useMemo(() => {
514
+ return {
515
+ icon: hidePass ? "view-off" : "view-on",
516
+ inputType: hidePass ? "password" : "text"
517
+ };
518
+ }, [hidePass]);
519
+ const handleClick = () => {
520
+ setHidePass(prev => {
521
+ return !prev;
522
+ });
523
+ };
524
+ return {
525
+ handleClick,
526
+ icon,
527
+ inputType
528
+ };
529
+ };
530
+
508
531
  // src/AuthSignIn.tsx
509
532
  import { useI18n as useI18n2 } from "@ttoss/react-i18n";
510
533
  import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
511
534
  var AuthSignIn = ({
512
535
  onSignIn,
513
536
  onSignUp,
514
- defaultValues
537
+ defaultValues,
538
+ onForgotPassword
515
539
  }) => {
516
540
  const {
517
541
  intl
518
542
  } = useI18n2();
543
+ const {
544
+ handleClick,
545
+ icon,
546
+ inputType
547
+ } = useHidePassInput();
519
548
  const schema = yup2.object().shape({
520
549
  email: yup2.string().required(intl.formatMessage({
521
550
  id: "r+QgO+",
@@ -551,7 +580,9 @@ var AuthSignIn = ({
551
580
  }, {
552
581
  value: PASSWORD_MINIMUM_LENGTH
553
582
  })).trim()
583
+ // remember: yup.boolean(),
554
584
  });
585
+
555
586
  const formMethods = useForm2({
556
587
  defaultValues,
557
588
  resolver: yupResolver2(schema)
@@ -564,55 +595,79 @@ var AuthSignIn = ({
564
595
  onSubmit: onSubmitForm,
565
596
  children: /* @__PURE__ */jsxs2(AuthCard, {
566
597
  title: intl.formatMessage({
567
- id: "R1rFNQ",
598
+ id: "F2iS37",
568
599
  defaultMessage: [{
569
600
  "type": 0,
570
- "value": "Login"
601
+ "value": "Log in"
571
602
  }]
572
603
  }),
573
604
  buttonLabel: intl.formatMessage({
574
- id: "0cVgsc",
605
+ id: "/J+02x",
575
606
  defaultMessage: [{
576
607
  "type": 0,
577
- "value": "Login"
608
+ "value": "Log in"
578
609
  }]
579
610
  }),
580
- links: [{
581
- onClick: onSignUp,
582
- label: intl.formatMessage({
583
- id: "z5s0vm",
584
- defaultMessage: [{
585
- "type": 0,
586
- "value": "Do you forgot your password?"
587
- }]
588
- })
589
- }, {
611
+ isValidForm: formMethods.formState.isValid,
612
+ extraButton: /* @__PURE__ */jsx5(Button2, {
613
+ type: "button",
614
+ variant: "secondary",
615
+ sx: {
616
+ textAlign: "center",
617
+ display: "initial"
618
+ },
590
619
  onClick: onSignUp,
591
- label: intl.formatMessage({
592
- id: "XC1w2U",
620
+ "aria-label": "sign-up",
621
+ children: intl.formatMessage({
622
+ id: "EZ3YF2",
593
623
  defaultMessage: [{
594
624
  "type": 0,
595
- "value": "Don't have an account? Sign up"
625
+ "value": "Sign up"
596
626
  }]
597
627
  })
598
- }],
599
- children: [/* @__PURE__ */jsx5(FormFieldInput2, {
600
- name: "email",
601
- label: intl.formatMessage({
602
- id: "5E12mO",
603
- defaultMessage: [{
604
- "type": 0,
605
- "value": "Email"
606
- }]
607
- })
608
- }), /* @__PURE__ */jsx5(FormFieldInput2, {
609
- name: "password",
610
- label: intl.formatMessage({
611
- id: "PylVqx",
612
- defaultMessage: [{
613
- "type": 0,
614
- "value": "Password"
615
- }]
628
+ }),
629
+ children: [/* @__PURE__ */jsxs2(Flex3, {
630
+ sx: {
631
+ flexDirection: "column",
632
+ gap: "xl"
633
+ },
634
+ children: [/* @__PURE__ */jsx5(FormFieldInput2, {
635
+ name: "email",
636
+ label: intl.formatMessage({
637
+ id: "5E12mO",
638
+ defaultMessage: [{
639
+ "type": 0,
640
+ "value": "Email"
641
+ }]
642
+ })
643
+ }), /* @__PURE__ */jsx5(FormFieldInput2, {
644
+ name: "password",
645
+ trailingIcon: icon,
646
+ onTrailingIconClick: handleClick,
647
+ type: inputType,
648
+ label: intl.formatMessage({
649
+ id: "PylVqx",
650
+ defaultMessage: [{
651
+ "type": 0,
652
+ "value": "Password"
653
+ }]
654
+ })
655
+ })]
656
+ }), /* @__PURE__ */jsx5(Flex3, {
657
+ sx: {
658
+ justifyContent: "space-between",
659
+ marginTop: "lg"
660
+ },
661
+ children: /* @__PURE__ */jsx5(Text, {
662
+ as: Link,
663
+ onClick: onForgotPassword,
664
+ children: intl.formatMessage({
665
+ id: "BtK6KR",
666
+ defaultMessage: [{
667
+ "type": 0,
668
+ "value": "Forgot password?"
669
+ }]
670
+ })
616
671
  })
617
672
  })]
618
673
  })
@@ -621,6 +676,7 @@ var AuthSignIn = ({
621
676
 
622
677
  // src/AuthSignUp.tsx
623
678
  import { Form as Form3, FormFieldInput as FormFieldInput3, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
679
+ import { Link as Link2, Text as Text2 } from "@ttoss/ui";
624
680
  import { useI18n as useI18n3 } from "@ttoss/react-i18n";
625
681
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
626
682
  var AuthSignUp = ({
@@ -690,16 +746,18 @@ var AuthSignUp = ({
690
746
  "value": "Register"
691
747
  }]
692
748
  }),
693
- links: [{
694
- label: intl.formatMessage({
749
+ isValidForm: formMethods.formState.isValid,
750
+ extraButton: /* @__PURE__ */jsx6(Text2, {
751
+ onClick: onReturnToSignIn,
752
+ as: Link2,
753
+ children: intl.formatMessage({
695
754
  id: "LU2ddR",
696
755
  defaultMessage: [{
697
756
  "type": 0,
698
757
  "value": "Do you already have an account? Sign in"
699
758
  }]
700
- }),
701
- onClick: onReturnToSignIn
702
- }],
759
+ })
760
+ }),
703
761
  children: [/* @__PURE__ */jsx6(FormFieldInput3, {
704
762
  name: "email",
705
763
  label: intl.formatMessage({
@@ -711,6 +769,7 @@ var AuthSignUp = ({
711
769
  })
712
770
  }), /* @__PURE__ */jsx6(FormFieldInput3, {
713
771
  name: "password",
772
+ type: "password",
714
773
  label: intl.formatMessage({
715
774
  id: "PylVqx",
716
775
  defaultMessage: [{
@@ -780,7 +839,7 @@ var AuthLogic = () => {
780
839
  const {
781
840
  setLoading
782
841
  } = useNotifications2();
783
- const onSignIn = React3.useCallback(async ({
842
+ const onSignIn = React4.useCallback(async ({
784
843
  email,
785
844
  password
786
845
  }) => {
@@ -802,7 +861,7 @@ var AuthLogic = () => {
802
861
  setLoading(false);
803
862
  }
804
863
  }, [send, setLoading]);
805
- const onSignUp = React3.useCallback(async ({
864
+ const onSignUp = React4.useCallback(async ({
806
865
  email,
807
866
  password
808
867
  }) => {
@@ -823,7 +882,7 @@ var AuthLogic = () => {
823
882
  setLoading(false);
824
883
  }
825
884
  }, [send, setLoading]);
826
- const onConfirmSignUp = React3.useCallback(async ({
885
+ const onConfirmSignUp = React4.useCallback(async ({
827
886
  email,
828
887
  code
829
888
  }) => {
@@ -838,7 +897,7 @@ var AuthLogic = () => {
838
897
  setLoading(false);
839
898
  }
840
899
  }, [send, setLoading]);
841
- const onReturnToSignIn = React3.useCallback(() => {
900
+ const onReturnToSignIn = React4.useCallback(() => {
842
901
  send({
843
902
  type: "RETURN_TO_SIGN_IN"
844
903
  });
@@ -872,7 +931,7 @@ var Auth2 = ({
872
931
  logo,
873
932
  fullScreen = true
874
933
  }) => {
875
- const withLogoNode = React3.useMemo(() => {
934
+ const withLogoNode = React4.useMemo(() => {
876
935
  return /* @__PURE__ */jsx7(LogoProvider, {
877
936
  logo,
878
937
  children: /* @__PURE__ */jsx7(AuthLogic, {})