Skip to content

Commit 16ff75a

Browse files
committed
chore(swingset): Add profile permutations exploration page
1 parent cd21ebe commit 16ff75a

5 files changed

Lines changed: 375 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

‎packages/swingset/src/components/DocsViewer.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { PlaygroundProvider } from './PlaygroundContext';
1111
const docModules: Record<string, Record<string, React.ComponentType>> = {
1212
'user-button': {
1313
'user-button': dynamic(() => import('../stories/user-button.mdx')),
14+
'profile-permutations': dynamic(() => import('../stories/profile-permutations.mdx')),
1415
},
1516
'user-profile': {
1617
'user-profile': dynamic(() => import('../stories/user-profile.mdx')),

‎packages/swingset/src/lib/registry.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ import {
226226
meta as profileComponentMeta,
227227
Transitions as ProfileTransitions,
228228
} from '../stories/profile.component.stories';
229+
import { meta as profilePermutationsMeta } from '../stories/profile-permutations.stories';
229230
import {
230231
Default as RadioDefault,
231232
Descriptions as RadioDescriptions,
@@ -1013,6 +1014,7 @@ const organizationProfileMembersPanelModule: StoryModule = {
10131014
export const registry: StoryModule[] = [
10141015
// User Button
10151016
userButtonModule,
1017+
{ meta: profilePermutationsMeta },
10161018
// User Profile
10171019
userProfileModule,
10181020
// User Profile · Panels
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import * as Stories from './profile-permutations.stories';
2+
3+
# Profile permutations
4+
5+
Exploration page: every pairing of switchers and profile shape, running on fixtures. Each example shares
6+
one account and organization across its triggers, so switching in one updates the other and the profile.
7+
8+
Today `mode` on `UserButton` sets both the menu and the profile. `OrganizationSwitcher` always opens the
9+
standalone organization profile.
10+
11+
The snippets show the proposed API, which is not implemented. `combined` defaults to `true` in two places:
12+
on `UserButton` it decides what the menu lists, and on `MosaicProvider`'s `profile` it decides what the
13+
profile shows.
14+
15+
| # | Switchers | Profile | With the modal today | Proposed config |
16+
| --- | ---------------------------------------------- | -------- | --------------------------------------------- | ---------------------- |
17+
| 1 | `UserButton` combined | Combined | Yes (the default) | None |
18+
| 2 | `UserButton` combined | Separate | No | Profile opt-out |
19+
| 3 | `UserButton` user | Account | Yes | Menu + profile opt-out |
20+
| 4 | `UserButton` user | Combined | No | Menu opt-out |
21+
| 5 | `UserButton` user + `OrganizationSwitcher` | Separate | Yes | Menu + profile opt-out |
22+
| 6 | `UserButton` user + `OrganizationSwitcher` | Combined | No | Menu opt-out |
23+
| 7 | `OrganizationSwitcher` | Org | Yes | Profile opt-out |
24+
| 8 | `OrganizationSwitcher` | Combined | No | None |
25+
| 9 | `UserButton` combined + `OrganizationSwitcher` | Combined | No: the switcher opens the standalone profile | None |
26+
27+
The `No` rows can be approximated by routing with `userProfileUrl` and `organizationProfileUrl` to pages
28+
that mount `<UserProfile />`.
29+
30+
## 1. Combined button, combined profile
31+
32+
Settings opens one profile.
33+
34+
```tsx
35+
<UserButton />
36+
```
37+
38+
<Story
39+
name='CombinedButtonCombinedProfile'
40+
storyModule={Stories}
41+
/>
42+
43+
## 2. Combined button, separate profiles
44+
45+
Settings offers the account and the organization as two targets.
46+
47+
```tsx
48+
<MosaicProvider profile={{ combined: false }}>
49+
<UserButton />
50+
</MosaicProvider>
51+
```
52+
53+
<Story
54+
name='CombinedButtonSeparateProfiles'
55+
storyModule={Stories}
56+
/>
57+
58+
## 3. User button, account profile
59+
60+
```tsx
61+
<MosaicProvider profile={{ combined: false }}>
62+
<UserButton combined={false} />
63+
</MosaicProvider>
64+
```
65+
66+
<Story
67+
name='UserButtonAccountProfile'
68+
storyModule={Stories}
69+
/>
70+
71+
## 4. User button, combined profile
72+
73+
No organization rows in the menu, but the profile carries the active organization's pages.
74+
75+
```tsx
76+
<UserButton combined={false} />
77+
```
78+
79+
<Story
80+
name='UserButtonCombinedProfile'
81+
storyModule={Stories}
82+
/>
83+
84+
## 5. User button and switcher, separate profiles
85+
86+
```tsx
87+
<MosaicProvider profile={{ combined: false }}>
88+
<OrganizationSwitcher />
89+
<UserButton combined={false} />
90+
</MosaicProvider>
91+
```
92+
93+
<Story
94+
name='UserButtonAndSwitcherSeparateProfiles'
95+
storyModule={Stories}
96+
/>
97+
98+
## 6. User button and switcher, combined profile
99+
100+
Both triggers open the same profile. The button lands on the account's pages and the switcher on the
101+
organization's. Switch to the personal account and the organization group leaves the profile.
102+
103+
```tsx
104+
<OrganizationSwitcher />
105+
<UserButton combined={false} />
106+
```
107+
108+
<Story
109+
name='UserButtonAndSwitcherCombinedProfile'
110+
storyModule={Stories}
111+
/>
112+
113+
## 7. Switcher, organization profile
114+
115+
```tsx
116+
<MosaicProvider profile={{ combined: false }}>
117+
<OrganizationSwitcher />
118+
</MosaicProvider>
119+
```
120+
121+
<Story
122+
name='SwitcherOrganizationProfile'
123+
storyModule={Stories}
124+
/>
125+
126+
## 8. Switcher, combined profile
127+
128+
```tsx
129+
<OrganizationSwitcher />
130+
```
131+
132+
<Story
133+
name='SwitcherCombinedProfile'
134+
storyModule={Stories}
135+
/>
136+
137+
## 9. Combined button and switcher
138+
139+
Both menus list the organizations, and both open the combined profile.
140+
141+
```tsx
142+
<OrganizationSwitcher />
143+
<UserButton />
144+
```
145+
146+
<Story
147+
name='CombinedButtonAndSwitcher'
148+
storyModule={Stories}
149+
/>
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
import type {
2+
OrganizationProfileModalContentProps,
3+
OrganizationProfileModalOptions,
4+
} from '@clerk/mosaic/features/organization-profile/organization-profile.modal.types';
5+
import { OrganizationProfileView } from '@clerk/mosaic/features/organization-profile/organization-profile.view';
6+
import type { SwitcherViewProps } from '@clerk/mosaic/features/switcher/switcher.view';
7+
import { SwitcherView } from '@clerk/mosaic/features/switcher/switcher.view';
8+
import type { UserButtonMode } from '@clerk/mosaic/features/user-button/user-button';
9+
import type {
10+
UserProfileModalContentProps,
11+
UserProfileModalOptions,
12+
} from '@clerk/mosaic/features/user-profile/user-profile.modal.types';
13+
import { UserProfileView } from '@clerk/mosaic/features/user-profile/user-profile.view';
14+
import { defineModalSurface } from '@clerk/mosaic/modals/define-modal-surface';
15+
import type { ModalSurfaces } from '@clerk/mosaic/modals/modal.types';
16+
import { ModalHost } from '@clerk/mosaic/modals/modal-host';
17+
import { useModal } from '@clerk/mosaic/modals/use-modal';
18+
import { useState } from 'react';
19+
20+
import type { StoryMeta } from '@/lib/types';
21+
22+
import { useOrganizationProfileFixture } from './fixtures/organization-profile';
23+
import { usePrototype } from './fixtures/switcher';
24+
import { useUserProfileFixture } from './fixtures/user-profile';
25+
26+
export const meta: StoryMeta = {
27+
group: 'User Button',
28+
title: 'ProfilePermutations',
29+
label: 'Profile permutations',
30+
status: 'wip',
31+
source: 'packages/swingset/src/stories/profile-permutations.stories.tsx',
32+
};
33+
34+
export function CombinedButtonCombinedProfile(_args: Record<string, unknown>) {
35+
return (
36+
<Permutation
37+
userButton='combined'
38+
profile='combined'
39+
/>
40+
);
41+
}
42+
43+
export function CombinedButtonSeparateProfiles(_args: Record<string, unknown>) {
44+
return (
45+
<Permutation
46+
userButton='combined'
47+
profile='separate'
48+
/>
49+
);
50+
}
51+
52+
export function UserButtonAccountProfile(_args: Record<string, unknown>) {
53+
return (
54+
<Permutation
55+
userButton='user'
56+
profile='separate'
57+
/>
58+
);
59+
}
60+
61+
export function UserButtonCombinedProfile(_args: Record<string, unknown>) {
62+
return (
63+
<Permutation
64+
userButton='user'
65+
profile='combined'
66+
/>
67+
);
68+
}
69+
70+
export function UserButtonAndSwitcherSeparateProfiles(_args: Record<string, unknown>) {
71+
return (
72+
<Permutation
73+
userButton='user'
74+
organizationSwitcher
75+
profile='separate'
76+
/>
77+
);
78+
}
79+
80+
export function UserButtonAndSwitcherCombinedProfile(_args: Record<string, unknown>) {
81+
return (
82+
<Permutation
83+
userButton='user'
84+
organizationSwitcher
85+
profile='combined'
86+
/>
87+
);
88+
}
89+
90+
export function SwitcherOrganizationProfile(_args: Record<string, unknown>) {
91+
return (
92+
<Permutation
93+
organizationSwitcher
94+
profile='separate'
95+
/>
96+
);
97+
}
98+
99+
export function SwitcherCombinedProfile(_args: Record<string, unknown>) {
100+
return (
101+
<Permutation
102+
organizationSwitcher
103+
profile='combined'
104+
/>
105+
);
106+
}
107+
108+
export function CombinedButtonAndSwitcher(_args: Record<string, unknown>) {
109+
return (
110+
<Permutation
111+
userButton='combined'
112+
organizationSwitcher
113+
profile='combined'
114+
/>
115+
);
116+
}
117+
118+
interface PermutationProps {
119+
userButton?: UserButtonMode;
120+
organizationSwitcher?: boolean;
121+
profile: 'combined' | 'separate';
122+
}
123+
124+
function Permutation(props: PermutationProps) {
125+
return (
126+
<ModalHost surfaces={surfaces}>
127+
<Triggers {...props} />
128+
</ModalHost>
129+
);
130+
}
131+
132+
function Triggers({ userButton, organizationSwitcher = false, profile }: PermutationProps) {
133+
const prototype = usePrototype();
134+
const [openSurface, setOpenSurface] = useState<'userButton' | 'organizationSwitcher'>('userButton');
135+
const userProfile = useModal(fixtureUserProfileModal);
136+
const organizationProfile = useModal(fixtureOrganizationProfileModal);
137+
const combined = profile === 'combined' && prototype.activeOrganization ? 'combined' : 'user';
138+
139+
const manageAccount = () => {
140+
prototype.onManageAccount?.();
141+
userProfile.open({ mode: combined });
142+
};
143+
const manageOrganization = () => {
144+
prototype.onManageOrganization?.();
145+
if (profile === 'combined') {
146+
userProfile.open({ mode: combined, page: 'organization/general' });
147+
} else {
148+
organizationProfile.open();
149+
}
150+
};
151+
const surfaceProps = (surface: typeof openSurface): Omit<SwitcherViewProps, 'mode'> => ({
152+
...prototype,
153+
open: prototype.open && openSurface === surface,
154+
onOpenChange: open => {
155+
setOpenSurface(surface);
156+
prototype.onOpenChange?.(open);
157+
},
158+
onManageAccount: manageAccount,
159+
onManageOrganization: manageOrganization,
160+
});
161+
162+
return (
163+
<div className='flex flex-wrap items-center gap-4'>
164+
{organizationSwitcher ? (
165+
<SwitcherView
166+
{...surfaceProps('organizationSwitcher')}
167+
mode='organization'
168+
/>
169+
) : null}
170+
{userButton ? (
171+
<SwitcherView
172+
{...surfaceProps('userButton')}
173+
mode={userButton}
174+
triggerVariant={userButton === 'combined' ? 'full' : 'condensed'}
175+
onManageOrganization={userButton === 'combined' && profile === 'combined' ? undefined : manageOrganization}
176+
/>
177+
) : null}
178+
</div>
179+
);
180+
}
181+
182+
const fixtureUserProfileModal = defineModalSurface<UserProfileModalOptions>({
183+
id: 'permutationUserProfile',
184+
variant: 'profile',
185+
load: () => Promise.resolve({ default: FixtureUserProfile }),
186+
});
187+
188+
const fixtureOrganizationProfileModal = defineModalSurface<OrganizationProfileModalOptions>({
189+
id: 'permutationOrganizationProfile',
190+
variant: 'profile',
191+
load: () => Promise.resolve({ default: FixtureOrganizationProfile }),
192+
});
193+
194+
const surfaces: ModalSurfaces = [fixtureUserProfileModal, fixtureOrganizationProfileModal];
195+
196+
function FixtureUserProfile({ options }: UserProfileModalContentProps) {
197+
const { pages } = useUserProfileFixture();
198+
const organization = useOrganizationProfileFixture();
199+
const [activePage, setActivePage] = useState(options?.page ?? 'account');
200+
201+
return (
202+
<UserProfileView
203+
activePage={activePage}
204+
pages={pages}
205+
organization={options?.mode === 'combined' ? { pages: organization.pages } : undefined}
206+
onPageChange={setActivePage}
207+
/>
208+
);
209+
}
210+
211+
function FixtureOrganizationProfile(_props: OrganizationProfileModalContentProps) {
212+
const { activePage, setActivePage, pages } = useOrganizationProfileFixture();
213+
214+
return (
215+
<OrganizationProfileView
216+
activePage={activePage}
217+
pages={pages}
218+
onPageChange={setActivePage}
219+
/>
220+
);
221+
}

0 commit comments

Comments
 (0)