Skip to content

Commit

Permalink
Adjust login/signup layout (#329)
Browse files Browse the repository at this point in the history
* Adjust login/signup layout

* Fix clear button in input field
  • Loading branch information
JunichiSugiura authored May 31, 2024
1 parent 0eca54e commit 5d7b83c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 48 deletions.
10 changes: 6 additions & 4 deletions packages/keychain/src/components/Auth/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field } from "@cartridge/ui";
import { Field, FingerprintIcon } from "@cartridge/ui";
import { VStack, Button } from "@chakra-ui/react";
import { Container } from "../Container";
import { Form as FormikForm, Field as FormikField, Formik } from "formik";
Expand Down Expand Up @@ -85,7 +85,7 @@ export function Login({
);

return (
<Container chainId={chainId} overflowY="auto">
<Container chainId={chainId} overflowY={error ? "auto" : undefined}>
<Formik
initialValues={{ username: prefilledName }}
onSubmit={onSubmit}
Expand All @@ -103,13 +103,13 @@ export function Login({
description="Enter your Controller username"
/>

<VStack align="stretch" pb={PORTAL_FOOTER_MIN_HEIGHT}>
<VStack align="stretch" pb={error ? PORTAL_FOOTER_MIN_HEIGHT : undefined}>
<FormikField
name="username"
placeholder="Username"
validate={validateUsernameFor("login")}
>
{({ field, meta }) => (
{({ field, meta, form }) => (
<Field
{...field}
autoFocus
Expand All @@ -118,6 +118,7 @@ export function Login({
error={meta.error}
isLoading={props.isValidating}
isDisabled={isLoading}
onClear={() => form.setFieldValue(field.name, "")}
/>
)}
</FormikField>
Expand All @@ -134,6 +135,7 @@ export function Login({
type="submit"
colorScheme="colorful"
isLoading={isLoading}
leftIcon={<FingerprintIcon fontSize="2xl" />}
>
Log in
</Button>
Expand Down
11 changes: 4 additions & 7 deletions packages/keychain/src/components/Auth/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { client } from "utils/graphql";
import { PopupCenter } from "utils/url";
import { FormValues, SignupProps } from "./types";
import { isIframe, validateUsernameFor } from "./utils";
import { useClearField } from "./hooks";
import { RegistrationLink } from "./RegistrationLink";
import { doSignup } from "hooks/account";
import { useControllerTheme } from "hooks/theme";
Expand Down Expand Up @@ -68,7 +67,7 @@ export function Signup({

return (
<>
<Container>
<Container overflowY={error ? "auto" : undefined}>
<Formik
initialValues={{ username: prefilledName }}
onSubmit={onSubmit}
Expand Down Expand Up @@ -171,8 +170,6 @@ function Form({
},
);

const onClearUsername = useClearField("username");

const onLogin = useCallback(() => {
onLoginProp(values.username);
}, [values.username, onLoginProp]);
Expand All @@ -188,20 +185,20 @@ function Form({
description="Create your Cartridge Controller"
/>

<VStack align="stretch" pb={PORTAL_FOOTER_MIN_HEIGHT}>
<VStack align="stretch" pb={error ? PORTAL_FOOTER_MIN_HEIGHT : undefined}>
<FormikField
name="username"
placeholder="Username"
validate={validateUsernameFor("signup")}
>
{({ field, meta }) => (
{({ field, meta, form }) => (
<Field
{...field}
autoFocus
placeholder="Username"
touched={meta.touched}
error={meta.error}
onClear={onClearUsername}
onClear={() => form.setFieldValue(field.name, "")}
isLoading={isValidating}
/>
)}
Expand Down
6 changes: 3 additions & 3 deletions packages/keychain/src/components/Container/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export function Header({
right={0}
>
<Flex
bg="darkGray.800"
bg="darkGray.700"
borderRadius="lg"
h={`${ICON_SIZE}px`}
w={`${ICON_SIZE}px`}
justify="center"
alignItems="center"
borderWidth={4}
borderColor={colorMode === "dark" ? "solid.bg" : "blueGray.100"}
borderColor="solid.bg"
>
<Image
src={theme.icon}
Expand Down Expand Up @@ -143,4 +143,4 @@ function Container({
export const BANNER_HEIGHT = 150;
export const ICON_IMAGE_SIZE = 64;
export const ICON_SIZE = 80;
export const ICON_OFFSET = 16;
export const ICON_OFFSET = 32;
7 changes: 4 additions & 3 deletions packages/keychain/src/components/Container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function Container({
w="full"
h="full"
p={4}
pt={12}
overflowY="auto"
css={{
"::-webkit-scrollbar": {
Expand All @@ -50,6 +51,8 @@ export function Container({
alignItems="center"
justify="center"
minH={FOOTER_HEIGHT / 4}
bottom={0}
position="fixed"
>
<CartridgeIcon fontSize="sm" />
<Text fontSize="xs" color="currentColor">
Expand All @@ -69,7 +72,6 @@ function Wrapper({ children }: React.PropsWithChildren) {
<Show below="md">
<ChakraContainer
w="100vw"
h="100vh"
bg="solid.bg"
p={0}
as={motion.div}
Expand All @@ -83,10 +85,9 @@ function Wrapper({ children }: React.PropsWithChildren) {

{/** Show as modal */}
<Show above="md">
<Flex w="100vw" h="100vh" m={0} p={0} alignItems="center">
<Flex w="100vw" m={0} p={0} alignItems="center">
<ChakraContainer
w="432px"
h="600px"
bg="solid.bg"
p={0}
as={motion.div}
Expand Down
39 changes: 19 additions & 20 deletions packages/keychain/src/components/PortalBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@ export function PortalBanner({
description?: string | React.ReactElement;
}) {
return (
<VStack w="full" mb={4} p={3}>
<VStack pt={6} px={8}>
{!!Icon && (
<Circle size={12} mb={4} bg="solid.primary">
<Icon boxSize={8} />
</Circle>
)}
<VStack pb={6}>
{!!Icon && (
<Circle size={12} mb={4} bg="solid.primary">
<Icon boxSize={8} />
</Circle>
)}

{!!icon && (
<Circle size={12} mb={4} bg="solid.primary">
{icon}
</Circle>
)}
{!!icon && (
<Circle size={12} mb={4} bg="solid.primary">
{icon}
</Circle>
)}

<Text fontSize="lg" fontWeight="semibold" whiteSpace="nowrap">
{title}
<Text fontSize="lg" fontWeight="semibold" whiteSpace="nowrap">
{title}
</Text>

{description && (
<Text fontSize="sm" color="text.secondary" align="center">
{description}
</Text>
{description && (
<Text fontSize="sm" color="text.secondary" align="center">
{description}
</Text>
)}
</VStack>
)}
</VStack>
);
}
13 changes: 6 additions & 7 deletions packages/keychain/src/components/PortalFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ export function PortalFooter({
const height = useMemo(
() =>
isOpen
? `${
window.document.body.scrollHeight -
BANNER_HEIGHT -
FOOTER_HEIGHT +
ICON_SIZE / 2 -
ICON_OFFSET
}px`
? `${window.innerHeight -
BANNER_HEIGHT -
FOOTER_HEIGHT +
ICON_SIZE / 2 -
ICON_OFFSET
}px`
: "auto",
[isOpen],
);
Expand Down
2 changes: 1 addition & 1 deletion packages/keychain/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function Keychain({ Component, pageProps }: AppProps) {
}
body {
background: var(--chakra-colors-translucent-lg);
background: var(--chakra-colors-solid-bg);
}
`}</style>

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export function Field({
cursor={isActive ? "pointer" : "default"}
opacity={isActive ? 100 : 0} // workaround for onBlur handler triggeres before onClear
>
<TimesCircleIcon color="text.secondary" boxSize={5} />
<TimesCircleIcon color="text.secondary" boxSize={6} />
</InputRightElement>
)
)}
</InputGroup>

{error && touched && (
<HStack marginY={3}>
<AlertIcon color="text.error" />
<AlertIcon fontSize="xl" color="text.error" />
<Text color="text.error" fontSize="sm">
{error}
</Text>
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/theme/components/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const Button: ComponentStyleConfig = defineStyleConfig({
},
lineHeight: "none",
textTransform: "uppercase",
letterSpacing: "widest",
_disabled: {
pointerEvents: "none",
},
Expand Down

0 comments on commit 5d7b83c

Please sign in to comment.