Skip to content

Commit

Permalink
THEMES-760: Identity Blocks | Login links block (#1713)
Browse files Browse the repository at this point in the history
THEMES-760: added login links block, corrected single column layout, updated localization text.
  • Loading branch information
vgalatro authored Aug 8, 2023
1 parent d66758f commit f86ef43
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 38 deletions.
5 changes: 5 additions & 0 deletions blocks/identity-block/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
@include scss.block-properties("login-form");
}

.b-login-links {
@include scss.block-components("login-links");
@include scss.block-properties("login-links");
}

.b-sign-up {
&__tos-container {
a {
Expand Down
83 changes: 83 additions & 0 deletions blocks/identity-block/features/login-links/default.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from "react";
import PropTypes from "@arc-fusion/prop-types";
import { useFusionContext } from "fusion:context";
import getTranslatedPhrases from "fusion:intl";
import { Link, Stack } from "@wpmedia/arc-themes-components";

const BLOCK_CLASS_NAME = "b-login-links";
const defaultLoginURL = "/account/login/";
const defaultForgotURL = "/account/forgot-password/";
const defaultSignUpURL = "/account/signup/";

const LoginLinks = ({ customFields }) => {
const {
showLogin = false,
loginURL = defaultLoginURL,
showForgot = false,
forgotURL = defaultForgotURL,
showSignUp = false,
signUpURL = defaultSignUpURL,
} = customFields;
const { siteProperties } = useFusionContext();
const { locale } = siteProperties;
const phrases = getTranslatedPhrases(locale);

if (!showLogin && !showForgot && !showSignUp) {
return null;
}

return (
<Stack as="div" className={BLOCK_CLASS_NAME}>
{showLogin ? (
<Link href={loginURL}>{phrases.t("identity-block.login-links-login")}</Link>
) : null}
{showForgot ? (
<Link href={forgotURL}>{phrases.t("identity-block.login-links-forgot")}</Link>
) : null}
{showSignUp ? (
<Link href={signUpURL}>{phrases.t("identity-block.login-links-signup")}</Link>
) : null}
</Stack>
);
};

LoginLinks.label = "Identity Login Links - Arc Block";

LoginLinks.icon = "laptop-help-message";

LoginLinks.propTypes = {
customFields: PropTypes.shape({
showLogin: PropTypes.bool.tag({
name: "Show Login link",
defaultValue: false,
group: "Login",
}),
loginURL: PropTypes.string.tag({
name: "Login URL",
defaultValue: defaultLoginURL,
group: "Login",
}),
showForgot: PropTypes.bool.tag({
name: "Show Forgot Password link",
defaultValue: false,
group: "Forgot Password",
}),
forgotURL: PropTypes.string.tag({
name: "Forgot Password URL",
defaultValue: defaultForgotURL,
group: "Forgot Password",
}),
showSignUp: PropTypes.bool.tag({
name: "Show Sign up link",
defaultValue: false,
group: "Sign Up",
}),
signUpURL: PropTypes.string.tag({
name: "Sign Up URL",
defaultValue: defaultSignUpURL,
group: "Sign Up",
}),
}),
};

export default LoginLinks;
56 changes: 56 additions & 0 deletions blocks/identity-block/features/login-links/default.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import { useFusionContext } from "fusion:context";
import LoginLinks from "./default";

useFusionContext.mockImplementation(
jest.fn(() => ({
siteProperties: {
locale: "en",
},
}))
);

describe("LoginLinks", () => {
it("renders nothing by default", () => {
render(<LoginLinks customFields={{}} />);
expect(screen.queryAllByRole("link")).toEqual([]);
});

it("renders login and sign up links", () => {
render(<LoginLinks customFields={{ showLogin: true, showSignUp: true }} />);
expect(screen.getAllByRole("link")).toHaveLength(2);
});

it("renders only login link", () => {
render(<LoginLinks customFields={{ showLogin: true }} />);
expect(screen.getByRole("link")).toHaveAttribute("href", "/account/login/");
});

it("renders only sign up link", () => {
render(<LoginLinks customFields={{ showSignUp: true }} />);
expect(screen.getByRole("link")).toHaveAttribute("href", "/account/signup/");
});

it("renders only forgot password link", () => {
render(<LoginLinks customFields={{ showForgot: true }} />);
expect(screen.getByRole("link")).toHaveAttribute("href", "/account/forgot-password/");
});

it("renders custom link URLs", () => {
const customFields = {
showLogin: true,
showSignUp: true,
showForgot: true,
loginURL: "custom-login",
forgotURL: "custom-forgot",
signUpURL: "custom-signup",
};
render(<LoginLinks customFields={customFields} />);
const links = screen.getAllByRole("link");
expect(links[0]).toHaveAttribute("href", customFields.loginURL);
expect(links[1]).toHaveAttribute("href", customFields.forgotURL);
expect(links[2]).toHaveAttribute("href", customFields.signUpURL);
});
});
17 changes: 17 additions & 0 deletions blocks/identity-block/features/login-links/index.story-ignore.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import LoginLinks from "./default";

export default {
title: "Blocks/Identity/Blocks/Login Links",
parameters: {
chromatic: { viewports: [320, 1200] },
},
};

export const LoginLink = () => <LoginLinks customFields={{ showLogin: true }} />;

export const SignUpLink = () => <LoginLinks customFields={{ showSignUp: true }} />;

export const loginAndSignUpLink = () => (
<LoginLinks customFields={{ showLogin: true, showSignUp: true }} />
);
6 changes: 3 additions & 3 deletions blocks/identity-block/intl.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
},
"identity-block.login-links-forgot": {
"de": "Forgot Password?",
"en": "Forgot Password?",
"en": "Forgot your password?",
"es": "Forgot Password?",
"fr": "Forgot Password?",
"ja": "Forgot Password?",
Expand All @@ -265,7 +265,7 @@
},
"identity-block.login-links-login": {
"de": "Already have an account? Log in.",
"en": "Already have an account? Log in.",
"en": "Already have an account? Log in",
"es": "Already have an account? Log in.",
"fr": "Already have an account? Log in.",
"ja": "Already have an account? Log in.",
Expand All @@ -276,7 +276,7 @@
},
"identity-block.login-links-signup": {
"de": "Sign up for an account.",
"en": "Sign up for an account.",
"en": "Don't have an account? Sign up",
"es": "Sign up for an account.",
"fr": "Sign up for an account.",
"ja": "Sign up for an account.",
Expand Down
23 changes: 15 additions & 8 deletions blocks/identity-block/themes/news.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@
"login-form": {
"styles": {
"default": {
"inline-size": "calc(100% - var(--global-spacing-6))",
"margin": "auto",
"font-family": "var(--font-family-primary)",
"max-inline-size": "none",
"components": {
"button": {
"font-size": "var(--global-font-size-4)"
Expand Down Expand Up @@ -122,7 +119,6 @@
}
},
"desktop": {
"max-inline-size": "37rem",
"components": {
"heading": {
"font-size": "var(--global-font-size-12)",
Expand All @@ -132,13 +128,25 @@
}
}
},
"login-links": {
"styles": {
"default": {
"components": {
"link": {
"text-align": "center"
},
"link-hover": {
"color": "var(--text-color-subtle)"
}
}
},
"desktop": {}
}
},
"sign-up": {
"styles": {
"default": {
"inline-size": "calc(100% - var(--global-spacing-6))",
"margin": "auto",
"font-family": "var(--font-family-primary)",
"max-inline-size": "none",
"components": {
"button": {
"font-size": "var(--global-font-size-4)"
Expand Down Expand Up @@ -175,7 +183,6 @@
}
},
"desktop": {
"max-inline-size": "37rem",
"components": {
"heading": {
"font-size": "var(--global-font-size-12)",
Expand Down
36 changes: 23 additions & 13 deletions blocks/single-column-layout-block/themes/commerce.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
{
"single-column-regular-main": {
"single-column-regular-body": {
"styles": {
"default": {
"components": {
"stack": {
"gap": "var(--global-spacing-11)"
}
}
"inline-size": "calc(100% - var(--global-spacing-6))",
"margin": "auto",
"max-inline-size": "none"
},
"desktop": {
"max-inline-size": "37rem"
}
}
},
"single-column-regular-main": {
"styles": {
"default": {
"components": {
"heading": {
"font-size": "var(--heading-level-3-font-size)",
"font-weight": "var(--heading-level-3-font-weight)",
"line-height": "var(--heading-level-3-line-height)"
},
"stack": {
"gap": "var(--global-spacing-16)"
"gap": "var(--global-spacing-5)"
}
}
}
},
"desktop": {}
}
},
"single-column-regular-body": {
"single-column-regular-footer": {
"styles": {
"default": {
"padding": "var(--global-spacing-5)",
"gap": "var(--global-spacing-5)",
"max-width": "39.875rem"
}
"width": "100%"
},
"desktop": {}
}
}
}
22 changes: 14 additions & 8 deletions blocks/single-column-layout-block/themes/news.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"single-column-regular-body": {
"styles": {
"default": {
"inline-size": "calc(100% - var(--global-spacing-6))",
"margin": "auto",
"max-inline-size": "none"
},
"desktop": {
"max-inline-size": "37rem"
}
}
},
"single-column-regular-main": {
"styles": {
"default": {
Expand All @@ -9,17 +21,11 @@
"line-height": "var(--heading-level-3-line-height)"
},
"stack": {
"gap": "var(--global-spacing-11)"
"gap": "var(--global-spacing-5)"
}
}
},
"desktop": {
"components": {
"stack": {
"gap": "var(--global-spacing-16)"
}
}
}
"desktop": {}
}
},
"single-column-regular-footer": {
Expand Down
6 changes: 3 additions & 3 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@
"identity-block.log-in": "Log In",
"identity-block.log-out": "Log Out",
"identity-block.login-form-error": "There's been an error logging you in",
"identity-block.login-links-forgot": "Forgot Password?",
"identity-block.login-links-login": "Already have an account? Log in.",
"identity-block.login-links-signup": "Sign up for an account.",
"identity-block.login-links-forgot": "Forgot your password?",
"identity-block.login-links-login": "Already have an account? Log in",
"identity-block.login-links-signup": "Don't have an account? Sign up",
"identity-block.login-options": "Log in options",
"identity-block.manage-account": "Manage Your Account",
"identity-block.new-password": "New Password",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f86ef43

Please sign in to comment.