Skip to content

Commit 5a6730a

Browse files
feat(clerk-js): Last authentication strategy badge (#6732)
1 parent 3f62cc7 commit 5a6730a

File tree

3 files changed

+52
-43
lines changed

3 files changed

+52
-43
lines changed
Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,38 @@
1-
import { Badge, descriptors, localizationKeys } from '../customizables';
2-
import type { InternalTheme, PropsOfComponent, ThemableCssProp } from '../styledSystem';
1+
import { descriptors, localizationKeys, Span } from '../customizables';
2+
import { common, type PropsOfComponent } from '../styledSystem';
33

4-
const overlayStyles = (t: InternalTheme): ThemableCssProp => [
5-
{
6-
background: `linear-gradient(${t.colors.$borderAlpha25}, ${t.colors.$borderAlpha25}),${t.colors.$colorBackground}`,
7-
borderColor: t.colors.$colorForeground,
8-
boxShadow: 'none',
9-
outline: `${t.space.$px} solid ${t.colors.$colorBackground}`,
10-
pointerEvents: 'none',
11-
position: 'absolute',
12-
right: `calc(${t.space.$2x5} * -1)`,
13-
top: '-35%',
14-
':after': {
15-
border: `${t.space.$px} solid ${t.colors.$borderAlpha150}`,
16-
borderRadius: t.radii.$lg,
17-
content: '""',
18-
display: 'block',
19-
height: '100%',
20-
inset: 0,
21-
padding: t.space.$px,
22-
position: 'absolute',
23-
width: '100%',
24-
},
25-
},
26-
];
27-
28-
export type LastAuthenticationStrategyBadgeProps = PropsOfComponent<typeof Badge> & { overlay?: boolean };
4+
export type LastAuthenticationStrategyBadgeProps = PropsOfComponent<typeof Span> & { overlay?: boolean };
295
export const LastAuthenticationStrategyBadge = ({
306
sx,
317
overlay,
328
...props
33-
}: LastAuthenticationStrategyBadgeProps): JSX.Element => (
34-
<Badge
35-
{...props}
36-
elementDescriptor={descriptors.lastAuthenticationStrategyBadge}
37-
localizationKey={localizationKeys('lastAuthenticationStrategy')}
38-
sx={[
39-
t => ({
40-
background: t.colors.$borderAlpha25,
41-
borderRadius: t.radii.$lg,
42-
}),
43-
overlay && overlayStyles,
44-
...(Array.isArray(sx) ? sx : sx ? [sx] : []),
45-
]}
46-
/>
47-
);
9+
}: LastAuthenticationStrategyBadgeProps): JSX.Element => {
10+
return (
11+
<Span
12+
{...props}
13+
elementDescriptor={descriptors.lastAuthenticationStrategyBadge}
14+
localizationKey={localizationKeys('lastAuthenticationStrategy')}
15+
sx={[
16+
t => ({
17+
...common.textVariants(t).caption,
18+
background: `linear-gradient(${t.colors.$borderAlpha25}, transparent), ${t.colors.$colorBackground}`,
19+
border: `${t.space.$px} solid ${t.colors.$borderAlpha150}`,
20+
borderRadius: t.radii.$lg,
21+
color: t.colors.$colorMutedForeground,
22+
height: t.space.$4x5,
23+
paddingInline: t.space.$1x5,
24+
whiteSpace: 'nowrap',
25+
boxShadow: `0 0 0 1px ${t.colors.$colorBackground}`,
26+
...(overlay && {
27+
position: 'absolute',
28+
right: -1,
29+
top: -1,
30+
transform: `translate(${t.space.$2x5}, -50%)`,
31+
pointerEvents: 'none',
32+
}),
33+
}),
34+
sx,
35+
]}
36+
/>
37+
);
38+
};

packages/clerk-js/src/ui/elements/Form.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ const CommonInputWrapper = (props: PropsWithChildren<CommonInputProps>) => {
151151
onClick={onActionClicked}
152152
/>
153153
)}
154-
{isLastAuthenticationStrategy && !actionLabel && !isOptional && <LastAuthenticationStrategyBadge />}
154+
{isLastAuthenticationStrategy && !actionLabel && !isOptional && (
155+
<LastAuthenticationStrategyBadgeWithFormState />
156+
)}
155157
<Field.Action />
156158
</Field.LabelRow>
157159

@@ -164,6 +166,20 @@ const CommonInputWrapper = (props: PropsWithChildren<CommonInputProps>) => {
164166
);
165167
};
166168

169+
const LastAuthenticationStrategyBadgeWithFormState = (
170+
props: PropsOfComponent<typeof LastAuthenticationStrategyBadge>,
171+
) => {
172+
const { isLoading, isDisabled } = useFormState();
173+
return (
174+
<LastAuthenticationStrategyBadge
175+
{...props}
176+
sx={t => ({
177+
opacity: isDisabled || isLoading ? t.opacity.$disabled : 1,
178+
})}
179+
/>
180+
);
181+
};
182+
167183
const PlainInput = (props: CommonInputProps) => {
168184
return (
169185
<CommonInputWrapper {...props}>

packages/clerk-js/src/ui/foundations/sizes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const spacingScale = Object.freeze({
2525
'3x5': { rem: '0.875rem', multiplier: 3.5 },
2626
'4': { rem: '1rem', multiplier: 4 },
2727
'4x25': { rem: '1.0625rem', multiplier: 4.25 },
28+
'4x5': { rem: '1.125rem', multiplier: 4.5 },
2829
'5': { rem: '1.25rem', multiplier: 5 },
2930
'5x5': { rem: '1.375rem', multiplier: 5.5 },
3031
'6': { rem: '1.5rem', multiplier: 6 },
@@ -102,6 +103,7 @@ const spaceUnits = Object.freeze({
102103
'3x5': spacingScale['3x5'].rem,
103104
'4': spacingScale['4'].rem,
104105
'4x25': spacingScale['4x25'].rem,
106+
'4x5': spacingScale['4x5'].rem,
105107
'5': spacingScale['5'].rem,
106108
'5x5': spacingScale['5x5'].rem,
107109
'6': spacingScale['6'].rem,

0 commit comments

Comments
 (0)