@molecule/app-auth-shell-react 1.0.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/LICENSE +115 -0
- package/dist/AuthFormStateProvider.d.ts +44 -0
- package/dist/AuthFormStateProvider.d.ts.map +1 -0
- package/dist/AuthFormStateProvider.js +41 -0
- package/dist/AuthShell.d.ts +217 -0
- package/dist/AuthShell.d.ts.map +1 -0
- package/dist/AuthShell.js +96 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/useAuthFormState.d.ts +80 -0
- package/dist/useAuthFormState.d.ts.map +1 -0
- package/dist/useAuthFormState.js +111 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React context wiring for {@link useAuthFormState}.
|
|
3
|
+
*
|
|
4
|
+
* `<AuthShell>` wraps its content in `<AuthFormStateProvider>` so any
|
|
5
|
+
* auth form rendered inside inherits cross-view email persistence — call
|
|
6
|
+
* `useAuthFormStateContext()` from the form to bind the shared `email`
|
|
7
|
+
* (and other shared fields) and to `clear()` on successful auth. Apps
|
|
8
|
+
* that compose the lower-level AuthShell primitives (instead of the
|
|
9
|
+
* `AuthShell` preset) can wrap manually with `<AuthFormStateProvider>`.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { type JSX, type ReactNode } from 'react';
|
|
14
|
+
import type { StorageProvider } from '@molecule/app-storage';
|
|
15
|
+
import { type AuthFormFields, type AuthFormState } from './useAuthFormState.js';
|
|
16
|
+
/**
|
|
17
|
+
* Props for {@link AuthFormStateProvider}.
|
|
18
|
+
*/
|
|
19
|
+
export interface AuthFormStateProviderProps {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
/** Storage provider backing persistence (defaults to a shared in-memory provider). */
|
|
22
|
+
storage?: StorageProvider;
|
|
23
|
+
/** Storage key for the persisted fields. */
|
|
24
|
+
storageKey?: string;
|
|
25
|
+
/** Seed values used before hydration / when storage is empty. */
|
|
26
|
+
initialFields?: AuthFormFields;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Provides a single {@link useAuthFormState} instance to all descendants
|
|
30
|
+
* via React context, so sibling/child auth forms share the same email.
|
|
31
|
+
*
|
|
32
|
+
* @param props - Children plus optional storage provider, key, and seed fields.
|
|
33
|
+
* @returns The provider element.
|
|
34
|
+
*/
|
|
35
|
+
export declare function AuthFormStateProvider({ children, storage, storageKey, initialFields, }: AuthFormStateProviderProps): JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* Reads the shared auth form state from the nearest
|
|
38
|
+
* {@link AuthFormStateProvider} (which `<AuthShell>` renders by default).
|
|
39
|
+
*
|
|
40
|
+
* @returns The shared {@link AuthFormState}.
|
|
41
|
+
* @throws {Error} If called outside an `<AuthFormStateProvider>`/`<AuthShell>`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useAuthFormStateContext(): AuthFormState;
|
|
44
|
+
//# sourceMappingURL=AuthFormStateProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthFormStateProvider.d.ts","sourceRoot":"","sources":["../src/AuthFormStateProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAiB,KAAK,GAAG,EAAE,KAAK,SAAS,EAAc,MAAM,OAAO,CAAA;AAE3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAoB,MAAM,uBAAuB,CAAA;AAIjG;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,SAAS,CAAA;IACnB,sFAAsF;IACtF,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iEAAiE;IACjE,aAAa,CAAC,EAAE,cAAc,CAAA;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,OAAO,EACP,UAAU,EACV,aAAa,GACd,EAAE,0BAA0B,GAAG,GAAG,CAAC,OAAO,CAG1C;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,aAAa,CAQvD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* React context wiring for {@link useAuthFormState}.
|
|
4
|
+
*
|
|
5
|
+
* `<AuthShell>` wraps its content in `<AuthFormStateProvider>` so any
|
|
6
|
+
* auth form rendered inside inherits cross-view email persistence — call
|
|
7
|
+
* `useAuthFormStateContext()` from the form to bind the shared `email`
|
|
8
|
+
* (and other shared fields) and to `clear()` on successful auth. Apps
|
|
9
|
+
* that compose the lower-level AuthShell primitives (instead of the
|
|
10
|
+
* `AuthShell` preset) can wrap manually with `<AuthFormStateProvider>`.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { createContext, useContext } from 'react';
|
|
15
|
+
import { useAuthFormState } from './useAuthFormState.js';
|
|
16
|
+
const AuthFormStateContext = createContext(null);
|
|
17
|
+
/**
|
|
18
|
+
* Provides a single {@link useAuthFormState} instance to all descendants
|
|
19
|
+
* via React context, so sibling/child auth forms share the same email.
|
|
20
|
+
*
|
|
21
|
+
* @param props - Children plus optional storage provider, key, and seed fields.
|
|
22
|
+
* @returns The provider element.
|
|
23
|
+
*/
|
|
24
|
+
export function AuthFormStateProvider({ children, storage, storageKey, initialFields, }) {
|
|
25
|
+
const state = useAuthFormState({ storage, storageKey, initialFields });
|
|
26
|
+
return _jsx(AuthFormStateContext.Provider, { value: state, children: children });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reads the shared auth form state from the nearest
|
|
30
|
+
* {@link AuthFormStateProvider} (which `<AuthShell>` renders by default).
|
|
31
|
+
*
|
|
32
|
+
* @returns The shared {@link AuthFormState}.
|
|
33
|
+
* @throws {Error} If called outside an `<AuthFormStateProvider>`/`<AuthShell>`.
|
|
34
|
+
*/
|
|
35
|
+
export function useAuthFormStateContext() {
|
|
36
|
+
const ctx = useContext(AuthFormStateContext);
|
|
37
|
+
if (!ctx) {
|
|
38
|
+
throw new Error('useAuthFormStateContext must be used within an <AuthFormStateProvider> (or <AuthShell>, which renders one).');
|
|
39
|
+
}
|
|
40
|
+
return ctx;
|
|
41
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { CSSProperties, HTMLAttributes, JSX, ReactNode } from 'react';
|
|
2
|
+
import type { StorageProvider } from '@molecule/app-storage';
|
|
3
|
+
/**
|
|
4
|
+
* Outer full-screen container — centered Flex, padded, with optional
|
|
5
|
+
* absolute-positioned background decoration child.
|
|
6
|
+
*
|
|
7
|
+
* Compose with `<AuthShellCard>` (and friends) inside.
|
|
8
|
+
*/
|
|
9
|
+
export interface AuthShellContainerProps {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** Optional CSS background applied to the container. */
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
/** Optional extra className appended after defaults. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Layout direction. Defaults to centered-Flex; pass `'column'` for a vertical stack (top-bar / main / footer). */
|
|
16
|
+
layout?: 'centered' | 'column';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Full-screen container with centered-flex or column layout and optional background decoration support.
|
|
20
|
+
*/
|
|
21
|
+
export declare function AuthShellContainer({ children, style, className, layout, }: AuthShellContainerProps): JSX.Element;
|
|
22
|
+
/**
|
|
23
|
+
* Absolute-positioned background decoration layer — orbs, mesh gradients,
|
|
24
|
+
* radial glows. Children render inside a `pointer-events-none absolute
|
|
25
|
+
* inset-0 -z-10 overflow-hidden` wrapper.
|
|
26
|
+
*/
|
|
27
|
+
export declare function AuthShellDecoration({ children }: {
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
}): JSX.Element;
|
|
30
|
+
/**
|
|
31
|
+
* The centered glassmorphic card surface. Layout (flex column + padding)
|
|
32
|
+
* is fixed; the visible surface (rounded / bg / border / shadow) is the
|
|
33
|
+
* default glass treatment, replaceable per-app via `surfaceClassName`.
|
|
34
|
+
*
|
|
35
|
+
* Pass `outerClassName` to override the outer `<main>` width / max-width
|
|
36
|
+
* constraint (default `max-w-md`).
|
|
37
|
+
*/
|
|
38
|
+
export interface AuthShellCardProps {
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
/** Override the default glass surface (rounded + bg + border + shadow). */
|
|
41
|
+
surfaceClassName?: string;
|
|
42
|
+
/** Extra layout classes to append (after flex/padding defaults). */
|
|
43
|
+
className?: string;
|
|
44
|
+
/** Override the outer `<main>` wrapper classes (defaults to `cm.w('full') max-w-md relative z-10`). */
|
|
45
|
+
outerClassName?: string;
|
|
46
|
+
/** data-mol-id pass-through for E2E selectors. */
|
|
47
|
+
dataMolId?: string;
|
|
48
|
+
style?: CSSProperties;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Centered glassmorphic card surface with fixed flex-column layout and configurable surface treatment.
|
|
52
|
+
*/
|
|
53
|
+
export declare function AuthShellCard({ children, surfaceClassName, className, outerClassName, dataMolId, style, }: AuthShellCardProps): JSX.Element;
|
|
54
|
+
/**
|
|
55
|
+
* Heading block — optional eyebrow + h1 + optional subheading. All centered.
|
|
56
|
+
*/
|
|
57
|
+
export interface AuthShellHeadingProps {
|
|
58
|
+
heading: string;
|
|
59
|
+
subheading?: string;
|
|
60
|
+
/** Optional small uppercase tag rendered above the heading. */
|
|
61
|
+
eyebrow?: string;
|
|
62
|
+
/** Optional override for the h1 className (e.g. custom font-family). */
|
|
63
|
+
headingClassName?: string;
|
|
64
|
+
/** Optional override for the h1 style. */
|
|
65
|
+
headingStyle?: CSSProperties;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Centered heading block with optional eyebrow tag, h1 title, and subheading paragraph.
|
|
69
|
+
*/
|
|
70
|
+
export declare function AuthShellHeading({ heading, subheading, eyebrow, headingClassName, headingStyle, }: AuthShellHeadingProps): JSX.Element;
|
|
71
|
+
/**
|
|
72
|
+
* Footer inside the card — small text with a top border.
|
|
73
|
+
*/
|
|
74
|
+
export declare function AuthShellFooter({ children }: {
|
|
75
|
+
children: ReactNode;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
/**
|
|
78
|
+
* "Back to home" link (or custom destination) rendered below the card.
|
|
79
|
+
*/
|
|
80
|
+
export interface AuthShellBackLinkProps {
|
|
81
|
+
to?: string;
|
|
82
|
+
/** Translated label override; falls back to `auth.backHome` → "Back to home". */
|
|
83
|
+
label?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Back-navigation link rendered below the card, defaulting to "Back to home" via i18n.
|
|
87
|
+
*/
|
|
88
|
+
export declare function AuthShellBackLink({ to, label }: AuthShellBackLinkProps): JSX.Element;
|
|
89
|
+
/**
|
|
90
|
+
* Outer frame for the two-column "decorated brand panel + card" auth
|
|
91
|
+
* layout — the dominant shape across the fleet's polished auth pages.
|
|
92
|
+
*
|
|
93
|
+
* A `min-h-screen` vertical stack: compose an `<AuthShellSplitRow>` (the
|
|
94
|
+
* brand-panel + card-column row) as a child, and optionally a site
|
|
95
|
+
* `<Footer />` after it. The row flexes to fill, so the footer sits at
|
|
96
|
+
* the bottom.
|
|
97
|
+
*
|
|
98
|
+
* Provides only the structural concern (`flex-col` + `min-h-screen`).
|
|
99
|
+
* Background, text color, and font are per-app — pass them via
|
|
100
|
+
* `className`.
|
|
101
|
+
*/
|
|
102
|
+
export interface AuthShellSplitProps extends HTMLAttributes<HTMLDivElement> {
|
|
103
|
+
children: ReactNode;
|
|
104
|
+
/** Cosmetic classes (background, text color, font) for the outer container. */
|
|
105
|
+
className?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Outer min-h-screen flex-col frame for the two-column brand-panel + card auth layout.
|
|
109
|
+
*/
|
|
110
|
+
export declare function AuthShellSplit({ children, className, ...rest }: AuthShellSplitProps): JSX.Element;
|
|
111
|
+
/**
|
|
112
|
+
* The vertically-flexed two-column row inside `<AuthShellSplit>` —
|
|
113
|
+
* compose `<AuthShellPanel>` and `<AuthShellCardColumn>` as its
|
|
114
|
+
* children. Split out from `<AuthShellSplit>` so a site `<Footer />`
|
|
115
|
+
* can sit below the row as a sibling child rather than a slot prop.
|
|
116
|
+
*
|
|
117
|
+
* Provides only the `flex-1` vertical fill (so the row stretches and
|
|
118
|
+
* any sibling footer sits at the bottom). The two-column layout itself
|
|
119
|
+
* is the caller's choice — pass `className` with `cm.flex({})` for a
|
|
120
|
+
* flex row or `cm.grid({ cols: 2 })` (or a custom grid template) so the
|
|
121
|
+
* primitive never fights a grid-based shell.
|
|
122
|
+
*/
|
|
123
|
+
export interface AuthShellSplitRowProps extends HTMLAttributes<HTMLElement> {
|
|
124
|
+
children: ReactNode;
|
|
125
|
+
/**
|
|
126
|
+
* Layout classes for the row — typically `cm.flex({})` or
|
|
127
|
+
* `cm.grid({ cols: 2 })`. Appended after the `flex-1` vertical fill.
|
|
128
|
+
*/
|
|
129
|
+
className?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Vertically-filling flex-1 row inside AuthShellSplit that holds the brand panel and card column.
|
|
133
|
+
*/
|
|
134
|
+
export declare function AuthShellSplitRow({ children, className, ...rest }: AuthShellSplitRowProps): JSX.Element;
|
|
135
|
+
/**
|
|
136
|
+
* A decorative `<aside>` that collapses on mobile (`hidden lg:flex`, the
|
|
137
|
+
* one universally-shared concern) — the brand-panel half of
|
|
138
|
+
* `<AuthShellSplit>`, or the decorative column of any grid-based auth
|
|
139
|
+
* layout. Fill it with the app's bespoke decoration, wordmark, social
|
|
140
|
+
* proof, etc. Pass `className` for width ratio, padding, gradient, and
|
|
141
|
+
* positioning; extra props (`style`, `aria-*`, `data-*`) pass through to
|
|
142
|
+
* the `<aside>`.
|
|
143
|
+
*/
|
|
144
|
+
export interface AuthShellPanelProps extends HTMLAttributes<HTMLElement> {
|
|
145
|
+
children: ReactNode;
|
|
146
|
+
/** Cosmetic classes — width ratio, padding, gradient, positioning. */
|
|
147
|
+
className?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Decorative aside that collapses on mobile (hidden lg:flex) for the brand-panel half of a split auth layout.
|
|
151
|
+
*/
|
|
152
|
+
export declare function AuthShellPanel({ children, className, ...rest }: AuthShellPanelProps): JSX.Element;
|
|
153
|
+
/**
|
|
154
|
+
* A `<section>` (or `<main>`, via `as`) that centers its children on
|
|
155
|
+
* both axes — the form-card half of `<AuthShellSplit>`, or the centered
|
|
156
|
+
* content column of a header / main / footer stacked auth layout.
|
|
157
|
+
* Provides only the `flex` centering; pass `className` for width ratio,
|
|
158
|
+
* padding, and `flex-1`.
|
|
159
|
+
*/
|
|
160
|
+
export interface AuthShellCardColumnProps extends HTMLAttributes<HTMLElement> {
|
|
161
|
+
children: ReactNode;
|
|
162
|
+
/** Cosmetic classes — width ratio, padding. */
|
|
163
|
+
className?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Element to render. Defaults to `'section'`; pass `'main'` when the
|
|
166
|
+
* card column is the auth page's primary content landmark — i.e. the
|
|
167
|
+
* shell is not already wrapped in `<AuthShellSplitRow>` (which is
|
|
168
|
+
* itself a `<main>`, so nesting another would be invalid).
|
|
169
|
+
*/
|
|
170
|
+
as?: 'section' | 'main';
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Centered-flex section or main column for the form-card half of a split or stacked auth layout.
|
|
174
|
+
*/
|
|
175
|
+
export declare function AuthShellCardColumn({ children, className, as, ...rest }: AuthShellCardColumnProps): JSX.Element;
|
|
176
|
+
/**
|
|
177
|
+
* Convenience preset for the most common layout: centered glass card
|
|
178
|
+
* with optional decoration, brand panel, heading, body, footer, and a
|
|
179
|
+
* "Back to home" link below the card. Equivalent to manually composing
|
|
180
|
+
* `<AuthShellContainer>` + `<AuthShellDecoration>` + `<AuthShellCard>`
|
|
181
|
+
* + `<AuthShellHeading>` + `<AuthShellFooter>` + `<AuthShellBackLink>`.
|
|
182
|
+
*
|
|
183
|
+
* For the two-column "brand panel + card" shape, use `<AuthShellSplit>`
|
|
184
|
+
* + `<AuthShellPanel>` + `<AuthShellCardColumn>` instead.
|
|
185
|
+
*/
|
|
186
|
+
export interface AuthShellProps {
|
|
187
|
+
heading: string;
|
|
188
|
+
subheading: string;
|
|
189
|
+
children: ReactNode;
|
|
190
|
+
footer?: ReactNode;
|
|
191
|
+
brand?: ReactNode;
|
|
192
|
+
decoration?: ReactNode;
|
|
193
|
+
backTo?: string;
|
|
194
|
+
showBackLink?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Storage provider backing the cross-view auth form persistence
|
|
197
|
+
* (email shared across Login/Signup/Forgot/Reset, cleared on success).
|
|
198
|
+
* Defaults to a process-shared in-memory store; inject
|
|
199
|
+
* `createSessionStorageProvider()` from
|
|
200
|
+
* `@molecule/app-storage-localstorage` for tab-scoped persistence. The
|
|
201
|
+
* shell renders an `<AuthFormStateProvider>`, so forms inside read it
|
|
202
|
+
* via `useAuthFormStateContext()`.
|
|
203
|
+
*/
|
|
204
|
+
formStateStorage?: StorageProvider;
|
|
205
|
+
/** Storage key for the persisted auth form state. */
|
|
206
|
+
formStateKey?: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Convenience preset composing container, decoration, card, heading, footer, and back-link into a single component.
|
|
210
|
+
*
|
|
211
|
+
* Wraps its content in an `<AuthFormStateProvider>` so every form
|
|
212
|
+
* rendered inside inherits cross-view email persistence via
|
|
213
|
+
* `useAuthFormStateContext()`.
|
|
214
|
+
*/
|
|
215
|
+
export declare function AuthShell({ heading, subheading, children, footer, brand, decoration, backTo, showBackLink, formStateStorage, formStateKey, }: AuthShellProps): JSX.Element;
|
|
216
|
+
export default AuthShell;
|
|
217
|
+
//# sourceMappingURL=AuthShell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthShell.d.ts","sourceRoot":"","sources":["../src/AuthShell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAe,cAAc,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIvF,OAAO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,GACb,EAAE,cAAc,GAAG,GAAG,CAAC,OAAO,CAiB9B;AAED,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Link } from 'react-router';
|
|
3
|
+
import { useTranslation } from '@molecule/app-react';
|
|
4
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
5
|
+
import { AuthFormStateProvider } from './AuthFormStateProvider.js';
|
|
6
|
+
/**
|
|
7
|
+
* Full-screen container with centered-flex or column layout and optional background decoration support.
|
|
8
|
+
*/
|
|
9
|
+
export function AuthShellContainer({ children, style, className, layout = 'centered', }) {
|
|
10
|
+
const cm = getClassMap();
|
|
11
|
+
const base = layout === 'column'
|
|
12
|
+
? cm.cn(cm.flex({ direction: 'col' }), cm.minH('screen'), 'relative overflow-hidden bg-background text-on-surface')
|
|
13
|
+
: cm.cn(cm.flex({ align: 'center', justify: 'center' }), cm.minH('screen'), cm.sp('p', 6), 'relative overflow-hidden bg-background text-on-surface');
|
|
14
|
+
return (_jsx("div", { className: cm.cn(base, className), style: style, children: children }));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Absolute-positioned background decoration layer — orbs, mesh gradients,
|
|
18
|
+
* radial glows. Children render inside a `pointer-events-none absolute
|
|
19
|
+
* inset-0 -z-10 overflow-hidden` wrapper.
|
|
20
|
+
*/
|
|
21
|
+
export function AuthShellDecoration({ children }) {
|
|
22
|
+
const cm = getClassMap();
|
|
23
|
+
return (_jsx("div", { className: cm.cn('pointer-events-none absolute inset-0 -z-10 overflow-hidden'), children: children }));
|
|
24
|
+
}
|
|
25
|
+
const DEFAULT_SURFACE_CLASSES = 'rounded-3xl border border-white/40 bg-surface-container-lowest/80 backdrop-blur-2xl shadow-[0_30px_80px_-20px_rgba(116,47,229,0.30)]';
|
|
26
|
+
/**
|
|
27
|
+
* Centered glassmorphic card surface with fixed flex-column layout and configurable surface treatment.
|
|
28
|
+
*/
|
|
29
|
+
export function AuthShellCard({ children, surfaceClassName, className, outerClassName, dataMolId, style, }) {
|
|
30
|
+
const cm = getClassMap();
|
|
31
|
+
const outer = outerClassName ?? cm.cn(cm.w('full'), 'max-w-md relative z-10');
|
|
32
|
+
return (_jsx("main", { className: outer, children: _jsx("div", { className: cm.cn(cm.flex({ direction: 'col', gap: 'lg' }), cm.sp('p', 8), surfaceClassName ?? DEFAULT_SURFACE_CLASSES, className), style: style, "data-mol-id": dataMolId, children: children }) }));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Centered heading block with optional eyebrow tag, h1 title, and subheading paragraph.
|
|
36
|
+
*/
|
|
37
|
+
export function AuthShellHeading({ heading, subheading, eyebrow, headingClassName, headingStyle, }) {
|
|
38
|
+
const cm = getClassMap();
|
|
39
|
+
return (_jsxs("header", { className: cm.flex({ direction: 'col', align: 'center', gap: 'xs' }), children: [eyebrow ? (_jsx("span", { className: cm.cn(cm.textSize('xs'), cm.fontWeight('bold'), 'uppercase tracking-widest text-on-surface-variant'), children: eyebrow })) : null, _jsx("h1", { className: cm.cn(cm.textSize('2xl'), cm.fontWeight('bold'), 'tracking-tight text-on-surface text-center', headingClassName), style: headingStyle, children: heading }), subheading ? (_jsx("p", { className: cm.cn(cm.textSize('sm'), 'text-on-surface-variant text-center max-w-sm'), children: subheading })) : null] }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Footer inside the card — small text with a top border.
|
|
43
|
+
*/
|
|
44
|
+
export function AuthShellFooter({ children }) {
|
|
45
|
+
const cm = getClassMap();
|
|
46
|
+
return (_jsx("footer", { className: cm.cn(cm.textCenter, cm.textSize('sm'), 'text-on-surface-variant border-t border-outline-variant/10 pt-6'), children: children }));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Back-navigation link rendered below the card, defaulting to "Back to home" via i18n.
|
|
50
|
+
*/
|
|
51
|
+
export function AuthShellBackLink({ to = '/', label }) {
|
|
52
|
+
const cm = getClassMap();
|
|
53
|
+
const { t } = useTranslation();
|
|
54
|
+
return (_jsx("p", { className: cm.cn(cm.textCenter, cm.textSize('xs'), cm.sp('mt', 6), 'text-on-surface-variant'), children: _jsxs(Link, { to: to, className: cm.cn(cm.flex({ align: 'center', gap: 'xs' }), 'hover:text-primary transition-colors'), children: [_jsx("span", { className: cm.cn('material-symbols-outlined'), style: { fontSize: 14 }, children: "arrow_back" }), label ?? t('auth.backHome', undefined, { defaultValue: 'Back to home' })] }) }));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Outer min-h-screen flex-col frame for the two-column brand-panel + card auth layout.
|
|
58
|
+
*/
|
|
59
|
+
export function AuthShellSplit({ children, className, ...rest }) {
|
|
60
|
+
const cm = getClassMap();
|
|
61
|
+
return (_jsx("div", { className: cm.cn(cm.flex({ direction: 'col' }), cm.minH('screen'), className), ...rest, children: children }));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Vertically-filling flex-1 row inside AuthShellSplit that holds the brand panel and card column.
|
|
65
|
+
*/
|
|
66
|
+
export function AuthShellSplitRow({ children, className, ...rest }) {
|
|
67
|
+
const cm = getClassMap();
|
|
68
|
+
// `<main>` — the row is the auth page's primary content landmark.
|
|
69
|
+
return (_jsx("main", { className: cm.cn(cm.flex1, className), ...rest, children: children }));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Decorative aside that collapses on mobile (hidden lg:flex) for the brand-panel half of a split auth layout.
|
|
73
|
+
*/
|
|
74
|
+
export function AuthShellPanel({ children, className, ...rest }) {
|
|
75
|
+
const cm = getClassMap();
|
|
76
|
+
return (_jsx("aside", { className: cm.cn('hidden lg:flex', className), ...rest, children: children }));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Centered-flex section or main column for the form-card half of a split or stacked auth layout.
|
|
80
|
+
*/
|
|
81
|
+
export function AuthShellCardColumn({ children, className, as = 'section', ...rest }) {
|
|
82
|
+
const cm = getClassMap();
|
|
83
|
+
const Tag = as;
|
|
84
|
+
return (_jsx(Tag, { className: cm.cn(cm.flex({ direction: 'col', align: 'center', justify: 'center' }), className), ...rest, children: children }));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Convenience preset composing container, decoration, card, heading, footer, and back-link into a single component.
|
|
88
|
+
*
|
|
89
|
+
* Wraps its content in an `<AuthFormStateProvider>` so every form
|
|
90
|
+
* rendered inside inherits cross-view email persistence via
|
|
91
|
+
* `useAuthFormStateContext()`.
|
|
92
|
+
*/
|
|
93
|
+
export function AuthShell({ heading, subheading, children, footer, brand, decoration, backTo = '/', showBackLink = true, formStateStorage, formStateKey, }) {
|
|
94
|
+
return (_jsx(AuthFormStateProvider, { storage: formStateStorage, storageKey: formStateKey, children: _jsxs(AuthShellContainer, { children: [decoration ? _jsx(AuthShellDecoration, { children: decoration }) : null, _jsxs("div", { children: [_jsxs(AuthShellCard, { children: [brand, _jsx(AuthShellHeading, { heading: heading, subheading: subheading }), children, footer ? _jsx(AuthShellFooter, { children: footer }) : null] }), showBackLink ? _jsx(AuthShellBackLink, { to: backTo }) : null] })] }) }));
|
|
95
|
+
}
|
|
96
|
+
export default AuthShell;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-auth-shell-react` — centered glassmorphic shell for
|
|
3
|
+
* auth pages (Login, Signup, ForgotPassword, ResetPassword).
|
|
4
|
+
*
|
|
5
|
+
* Apps pass per-app `decoration` (orbs, gradient backdrop) and
|
|
6
|
+
* `brand` (logo + tagline) as ReactNode props. The shell handles
|
|
7
|
+
* layout, the glass card, heading/subheading, body slot, footer,
|
|
8
|
+
* and the "Back to home" link.
|
|
9
|
+
*
|
|
10
|
+
* The shell also wraps its content in an `<AuthFormStateProvider>`, so
|
|
11
|
+
* any form rendered inside inherits cross-view email persistence — the
|
|
12
|
+
* email typed on one auth view (Login/Signup/Forgot/Reset) is carried to
|
|
13
|
+
* the next and cleared on successful auth. Forms read it via
|
|
14
|
+
* `useAuthFormStateContext()`; the underlying `useAuthFormState` hook is
|
|
15
|
+
* also exported for standalone use. Persistence flows through the
|
|
16
|
+
* `@molecule/app-storage` `StorageProvider` abstraction (never raw
|
|
17
|
+
* `sessionStorage`), defaulting to a process-shared in-memory store.
|
|
18
|
+
*
|
|
19
|
+
* Besides the `AuthShell` preset, the package exports the composable
|
|
20
|
+
* primitives it is built from — `AuthShellContainer`, `AuthShellDecoration`,
|
|
21
|
+
* `AuthShellCard`, `AuthShellHeading`, `AuthShellFooter`, `AuthShellBackLink` —
|
|
22
|
+
* plus a two-column family for the "brand panel + form card" split layout:
|
|
23
|
+
* `AuthShellSplit` > `AuthShellSplitRow` > (`AuthShellPanel` + `AuthShellCardColumn`).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { AuthShell, useAuthFormStateContext } from '@molecule/app-auth-shell-react'
|
|
28
|
+
* import { createSessionStorageProvider } from '@molecule/app-storage-localstorage'
|
|
29
|
+
* import { AuthBrandHeader } from './AuthBrandHeader.js'
|
|
30
|
+
* import { Orbs } from './Orbs.js'
|
|
31
|
+
*
|
|
32
|
+
* const sessionStore = createSessionStorageProvider({ prefix: 'auth_' })
|
|
33
|
+
*
|
|
34
|
+
* function LoginForm() {
|
|
35
|
+
* const { fields, setField, clear } = useAuthFormStateContext()
|
|
36
|
+
* // bind <input value={fields.email} onChange={(e) => setField('email', e.target.value)} />
|
|
37
|
+
* // call clear() after a successful sign-in
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* export function Login() {
|
|
41
|
+
* return (
|
|
42
|
+
* <AuthShell
|
|
43
|
+
* heading="Sign in"
|
|
44
|
+
* subheading="Welcome back."
|
|
45
|
+
* brand={<AuthBrandHeader />}
|
|
46
|
+
* decoration={<Orbs />}
|
|
47
|
+
* formStateStorage={sessionStore}
|
|
48
|
+
* footer={<p>No account? <Link to="/signup">Sign up</Link></p>}
|
|
49
|
+
* >
|
|
50
|
+
* <LoginForm />
|
|
51
|
+
* </AuthShell>
|
|
52
|
+
* )
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* `AuthShell` renders a react-router `<Link>` ("Back to home") by default,
|
|
58
|
+
* so it MUST be rendered inside a `<Router>`; pass `showBackLink={false}`
|
|
59
|
+
* in router-less setups. The back link's arrow uses the Material Symbols
|
|
60
|
+
* icon font — load it, or the glyph renders as text. The default glass
|
|
61
|
+
* card treatment (`rounded-3xl`, translucent surface, backdrop blur) and
|
|
62
|
+
* the panel's `hidden lg:flex` collapse are Tailwind classes resolved by
|
|
63
|
+
* the wired ClassMap bond's theme tokens — on a non-Tailwind ClassMap,
|
|
64
|
+
* override via `surfaceClassName` / `className`. Form-state persistence
|
|
65
|
+
* defaults to a process-shared in-memory store (survives route swaps, not
|
|
66
|
+
* reloads) — inject `createSessionStorageProvider()` for reload-safe,
|
|
67
|
+
* tab-scoped persistence. Translations come from the companion
|
|
68
|
+
* `@molecule/app-locales-auth-shell` locale bond.
|
|
69
|
+
*
|
|
70
|
+
* @module
|
|
71
|
+
*/
|
|
72
|
+
export * from './AuthFormStateProvider.js';
|
|
73
|
+
export * from './AuthShell.js';
|
|
74
|
+
export * from './useAuthFormState.js';
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-auth-shell-react` — centered glassmorphic shell for
|
|
3
|
+
* auth pages (Login, Signup, ForgotPassword, ResetPassword).
|
|
4
|
+
*
|
|
5
|
+
* Apps pass per-app `decoration` (orbs, gradient backdrop) and
|
|
6
|
+
* `brand` (logo + tagline) as ReactNode props. The shell handles
|
|
7
|
+
* layout, the glass card, heading/subheading, body slot, footer,
|
|
8
|
+
* and the "Back to home" link.
|
|
9
|
+
*
|
|
10
|
+
* The shell also wraps its content in an `<AuthFormStateProvider>`, so
|
|
11
|
+
* any form rendered inside inherits cross-view email persistence — the
|
|
12
|
+
* email typed on one auth view (Login/Signup/Forgot/Reset) is carried to
|
|
13
|
+
* the next and cleared on successful auth. Forms read it via
|
|
14
|
+
* `useAuthFormStateContext()`; the underlying `useAuthFormState` hook is
|
|
15
|
+
* also exported for standalone use. Persistence flows through the
|
|
16
|
+
* `@molecule/app-storage` `StorageProvider` abstraction (never raw
|
|
17
|
+
* `sessionStorage`), defaulting to a process-shared in-memory store.
|
|
18
|
+
*
|
|
19
|
+
* Besides the `AuthShell` preset, the package exports the composable
|
|
20
|
+
* primitives it is built from — `AuthShellContainer`, `AuthShellDecoration`,
|
|
21
|
+
* `AuthShellCard`, `AuthShellHeading`, `AuthShellFooter`, `AuthShellBackLink` —
|
|
22
|
+
* plus a two-column family for the "brand panel + form card" split layout:
|
|
23
|
+
* `AuthShellSplit` > `AuthShellSplitRow` > (`AuthShellPanel` + `AuthShellCardColumn`).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { AuthShell, useAuthFormStateContext } from '@molecule/app-auth-shell-react'
|
|
28
|
+
* import { createSessionStorageProvider } from '@molecule/app-storage-localstorage'
|
|
29
|
+
* import { AuthBrandHeader } from './AuthBrandHeader.js'
|
|
30
|
+
* import { Orbs } from './Orbs.js'
|
|
31
|
+
*
|
|
32
|
+
* const sessionStore = createSessionStorageProvider({ prefix: 'auth_' })
|
|
33
|
+
*
|
|
34
|
+
* function LoginForm() {
|
|
35
|
+
* const { fields, setField, clear } = useAuthFormStateContext()
|
|
36
|
+
* // bind <input value={fields.email} onChange={(e) => setField('email', e.target.value)} />
|
|
37
|
+
* // call clear() after a successful sign-in
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* export function Login() {
|
|
41
|
+
* return (
|
|
42
|
+
* <AuthShell
|
|
43
|
+
* heading="Sign in"
|
|
44
|
+
* subheading="Welcome back."
|
|
45
|
+
* brand={<AuthBrandHeader />}
|
|
46
|
+
* decoration={<Orbs />}
|
|
47
|
+
* formStateStorage={sessionStore}
|
|
48
|
+
* footer={<p>No account? <Link to="/signup">Sign up</Link></p>}
|
|
49
|
+
* >
|
|
50
|
+
* <LoginForm />
|
|
51
|
+
* </AuthShell>
|
|
52
|
+
* )
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* `AuthShell` renders a react-router `<Link>` ("Back to home") by default,
|
|
58
|
+
* so it MUST be rendered inside a `<Router>`; pass `showBackLink={false}`
|
|
59
|
+
* in router-less setups. The back link's arrow uses the Material Symbols
|
|
60
|
+
* icon font — load it, or the glyph renders as text. The default glass
|
|
61
|
+
* card treatment (`rounded-3xl`, translucent surface, backdrop blur) and
|
|
62
|
+
* the panel's `hidden lg:flex` collapse are Tailwind classes resolved by
|
|
63
|
+
* the wired ClassMap bond's theme tokens — on a non-Tailwind ClassMap,
|
|
64
|
+
* override via `surfaceClassName` / `className`. Form-state persistence
|
|
65
|
+
* defaults to a process-shared in-memory store (survives route swaps, not
|
|
66
|
+
* reloads) — inject `createSessionStorageProvider()` for reload-safe,
|
|
67
|
+
* tab-scoped persistence. Translations come from the companion
|
|
68
|
+
* `@molecule/app-locales-auth-shell` locale bond.
|
|
69
|
+
*
|
|
70
|
+
* @module
|
|
71
|
+
*/
|
|
72
|
+
export * from './AuthFormStateProvider.js';
|
|
73
|
+
export * from './AuthShell.js';
|
|
74
|
+
export * from './useAuthFormState.js';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useAuthFormState` — cross-view auth form persistence.
|
|
3
|
+
*
|
|
4
|
+
* Holds the email (and any other shared auth fields) so a value typed on
|
|
5
|
+
* one auth view (Login / Signup / ForgotPassword / ResetPassword) is
|
|
6
|
+
* carried over when the user navigates to another. Backed by the
|
|
7
|
+
* `@molecule/app-storage` `StorageProvider` abstraction (NEVER raw
|
|
8
|
+
* `sessionStorage`/`localStorage`), so persistence survives the
|
|
9
|
+
* unmount/remount that happens when the router swaps one auth view for
|
|
10
|
+
* another within a single SPA session.
|
|
11
|
+
*
|
|
12
|
+
* The state is CLEARED on successful auth (call `clear()` from the
|
|
13
|
+
* success handler) so credentials do not linger.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import { type StorageProvider } from '@molecule/app-storage';
|
|
18
|
+
/**
|
|
19
|
+
* Shared auth form field values. `email` is the canonical cross-view
|
|
20
|
+
* field; additional string fields (e.g. a name carried from Signup) may
|
|
21
|
+
* be stored alongside it.
|
|
22
|
+
*/
|
|
23
|
+
export interface AuthFormFields {
|
|
24
|
+
/** Email address, shared across all auth views. */
|
|
25
|
+
email?: string;
|
|
26
|
+
/** Any other shared string field (e.g. `name`). */
|
|
27
|
+
[field: string]: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for {@link useAuthFormState}.
|
|
31
|
+
*/
|
|
32
|
+
export interface UseAuthFormStateOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Storage provider backing persistence. Defaults to a process-shared
|
|
35
|
+
* in-memory provider (per the no-raw-storage rule), which still gives
|
|
36
|
+
* cross-view persistence within a single SPA session. Inject
|
|
37
|
+
* `createSessionStorageProvider()` from
|
|
38
|
+
* `@molecule/app-storage-localstorage` for tab-scoped persistence that
|
|
39
|
+
* also survives a full reload.
|
|
40
|
+
*/
|
|
41
|
+
storage?: StorageProvider;
|
|
42
|
+
/** Storage key for the persisted fields. Defaults to `molecule.auth.form-state`. */
|
|
43
|
+
storageKey?: string;
|
|
44
|
+
/** Seed values used before hydration completes / when storage is empty. */
|
|
45
|
+
initialFields?: AuthFormFields;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The value returned by {@link useAuthFormState} (and provided through
|
|
49
|
+
* the AuthShell form-state context).
|
|
50
|
+
*/
|
|
51
|
+
export interface AuthFormState {
|
|
52
|
+
/** Current field values (email + any shared fields). */
|
|
53
|
+
fields: AuthFormFields;
|
|
54
|
+
/**
|
|
55
|
+
* `true` once the initial read from storage has completed. Useful for
|
|
56
|
+
* deferring autofocus/validation until persisted values are loaded.
|
|
57
|
+
*/
|
|
58
|
+
hydrated: boolean;
|
|
59
|
+
/** Sets a single field and persists the new state. */
|
|
60
|
+
setField: (name: string, value: string) => void;
|
|
61
|
+
/** Merges a patch of fields and persists the new state. */
|
|
62
|
+
setFields: (patch: AuthFormFields) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Clears all persisted auth form state and removes the storage key.
|
|
65
|
+
* Call this from the successful-auth handler.
|
|
66
|
+
*/
|
|
67
|
+
clear: () => void;
|
|
68
|
+
}
|
|
69
|
+
/** Default storage key for persisted auth form fields. */
|
|
70
|
+
export declare const DEFAULT_AUTH_FORM_STATE_KEY = "molecule.auth.form-state";
|
|
71
|
+
/**
|
|
72
|
+
* React hook holding email + shared auth fields, persisted across auth
|
|
73
|
+
* views via an injectable `StorageProvider` and cleared on successful
|
|
74
|
+
* auth.
|
|
75
|
+
*
|
|
76
|
+
* @param options - Optional storage provider, storage key, and seed fields.
|
|
77
|
+
* @returns The current fields plus `setField`/`setFields`/`clear` and a `hydrated` flag.
|
|
78
|
+
*/
|
|
79
|
+
export declare function useAuthFormState(options?: UseAuthFormStateOptions): AuthFormState;
|
|
80
|
+
//# sourceMappingURL=useAuthFormState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthFormState.d.ts","sourceRoot":"","sources":["../src/useAuthFormState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,EAA+B,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEzF;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,mDAAmD;IACnD,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB,oFAAoF;IACpF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2EAA2E;IAC3E,aAAa,CAAC,EAAE,cAAc,CAAA;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,MAAM,EAAE,cAAc,CAAA;IACtB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAA;IACjB,sDAAsD;IACtD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/C,2DAA2D;IAC3D,SAAS,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAA;IAC1C;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED,0DAA0D;AAC1D,eAAO,MAAM,2BAA2B,6BAA6B,CAAA;AAoBrE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,aAAa,CA8EjF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useAuthFormState` — cross-view auth form persistence.
|
|
3
|
+
*
|
|
4
|
+
* Holds the email (and any other shared auth fields) so a value typed on
|
|
5
|
+
* one auth view (Login / Signup / ForgotPassword / ResetPassword) is
|
|
6
|
+
* carried over when the user navigates to another. Backed by the
|
|
7
|
+
* `@molecule/app-storage` `StorageProvider` abstraction (NEVER raw
|
|
8
|
+
* `sessionStorage`/`localStorage`), so persistence survives the
|
|
9
|
+
* unmount/remount that happens when the router swaps one auth view for
|
|
10
|
+
* another within a single SPA session.
|
|
11
|
+
*
|
|
12
|
+
* The state is CLEARED on successful auth (call `clear()` from the
|
|
13
|
+
* success handler) so credentials do not linger.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
18
|
+
import { getLogger } from '@molecule/app-logger';
|
|
19
|
+
import { createMemoryStorageProvider } from '@molecule/app-storage';
|
|
20
|
+
/** Default storage key for persisted auth form fields. */
|
|
21
|
+
export const DEFAULT_AUTH_FORM_STATE_KEY = 'molecule.auth.form-state';
|
|
22
|
+
/**
|
|
23
|
+
* Process-shared in-memory provider used as the default backing store.
|
|
24
|
+
* Shared (not per-call) so the email survives the unmount/remount of an
|
|
25
|
+
* auth view within one SPA session even without an injected provider.
|
|
26
|
+
*/
|
|
27
|
+
let defaultStorage;
|
|
28
|
+
/**
|
|
29
|
+
* Lazily creates (once) and returns the process-shared in-memory storage
|
|
30
|
+
* provider used as the default backing store.
|
|
31
|
+
*
|
|
32
|
+
* @returns The shared in-memory `StorageProvider`.
|
|
33
|
+
*/
|
|
34
|
+
const getDefaultStorage = () => {
|
|
35
|
+
defaultStorage ??= createMemoryStorageProvider();
|
|
36
|
+
return defaultStorage;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* React hook holding email + shared auth fields, persisted across auth
|
|
40
|
+
* views via an injectable `StorageProvider` and cleared on successful
|
|
41
|
+
* auth.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Optional storage provider, storage key, and seed fields.
|
|
44
|
+
* @returns The current fields plus `setField`/`setFields`/`clear` and a `hydrated` flag.
|
|
45
|
+
*/
|
|
46
|
+
export function useAuthFormState(options) {
|
|
47
|
+
const logger = useMemo(() => getLogger('auth-form-state'), []);
|
|
48
|
+
const storage = useMemo(() => options?.storage ?? getDefaultStorage(), [options?.storage]);
|
|
49
|
+
const storageKey = options?.storageKey ?? DEFAULT_AUTH_FORM_STATE_KEY;
|
|
50
|
+
const [fields, setFieldsState] = useState(() => ({
|
|
51
|
+
...(options?.initialFields ?? {}),
|
|
52
|
+
}));
|
|
53
|
+
const [hydrated, setHydrated] = useState(false);
|
|
54
|
+
// Mirror the latest fields in a ref so setters can compute the next
|
|
55
|
+
// value synchronously (handling rapid successive calls in one tick)
|
|
56
|
+
// without an impure functional-updater side effect.
|
|
57
|
+
const fieldsRef = useRef(fields);
|
|
58
|
+
fieldsRef.current = fields;
|
|
59
|
+
const persist = useCallback((next) => {
|
|
60
|
+
storage.set(storageKey, next).catch((error) => {
|
|
61
|
+
logger.warn('Failed to persist auth form state', { error, storageKey });
|
|
62
|
+
});
|
|
63
|
+
}, [logger, storage, storageKey]);
|
|
64
|
+
// Hydrate from storage on mount (and when the backing store/key change).
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
let cancelled = false;
|
|
67
|
+
void (async () => {
|
|
68
|
+
try {
|
|
69
|
+
const stored = await storage.get(storageKey);
|
|
70
|
+
if (cancelled)
|
|
71
|
+
return;
|
|
72
|
+
if (stored && typeof stored === 'object') {
|
|
73
|
+
// Values the user already typed (in fieldsRef) win over stored.
|
|
74
|
+
const merged = { ...stored, ...fieldsRef.current };
|
|
75
|
+
fieldsRef.current = merged;
|
|
76
|
+
setFieldsState(merged);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
logger.warn('Failed to read persisted auth form state', { error, storageKey });
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
if (!cancelled)
|
|
84
|
+
setHydrated(true);
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
return () => {
|
|
88
|
+
cancelled = true;
|
|
89
|
+
};
|
|
90
|
+
}, [logger, storage, storageKey]);
|
|
91
|
+
const setField = useCallback((name, value) => {
|
|
92
|
+
const next = { ...fieldsRef.current, [name]: value };
|
|
93
|
+
fieldsRef.current = next;
|
|
94
|
+
setFieldsState(next);
|
|
95
|
+
persist(next);
|
|
96
|
+
}, [persist]);
|
|
97
|
+
const setFields = useCallback((patch) => {
|
|
98
|
+
const next = { ...fieldsRef.current, ...patch };
|
|
99
|
+
fieldsRef.current = next;
|
|
100
|
+
setFieldsState(next);
|
|
101
|
+
persist(next);
|
|
102
|
+
}, [persist]);
|
|
103
|
+
const clear = useCallback(() => {
|
|
104
|
+
fieldsRef.current = {};
|
|
105
|
+
setFieldsState({});
|
|
106
|
+
storage.remove(storageKey).catch((error) => {
|
|
107
|
+
logger.warn('Failed to clear persisted auth form state', { error, storageKey });
|
|
108
|
+
});
|
|
109
|
+
}, [logger, storage, storageKey]);
|
|
110
|
+
return { fields, hydrated, setField, setFields, clear };
|
|
111
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-auth-shell-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Auth-page layout shell — centered card with heading/subheading/form/footer + back-link below. Composable children for per-app decorative background + brand mark.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"auth",
|
|
25
|
+
"shell",
|
|
26
|
+
"layout",
|
|
27
|
+
"react"
|
|
28
|
+
],
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@molecule/app-logger": "^1.0.0",
|
|
32
|
+
"@molecule/app-react": "^1.0.0",
|
|
33
|
+
"@molecule/app-storage": "^1.0.0",
|
|
34
|
+
"@molecule/app-ui": "^1.0.0",
|
|
35
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
36
|
+
"react-router": "^7.0.0 || ^8.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@molecule/app-logger": "1.0.0",
|
|
40
|
+
"@molecule/app-react": "1.0.0",
|
|
41
|
+
"@molecule/app-storage": "1.0.0",
|
|
42
|
+
"@molecule/app-ui": "1.0.0",
|
|
43
|
+
"@testing-library/react": "16.3.2",
|
|
44
|
+
"@types/node": "26.1.2",
|
|
45
|
+
"@types/react": "19.2.17",
|
|
46
|
+
"@types/react-dom": "19.2.3",
|
|
47
|
+
"jsdom": "30.0.1",
|
|
48
|
+
"react": "19.2.8",
|
|
49
|
+
"react-dom": "19.2.8",
|
|
50
|
+
"react-router": "8.3.0",
|
|
51
|
+
"typescript": "6.0.3",
|
|
52
|
+
"vitest": "4.1.10"
|
|
53
|
+
}
|
|
54
|
+
}
|