-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
THEMES-760: Identity Blocks | Login links block (#1713)
THEMES-760: added login links block, corrected single column layout, updated localization text.
- Loading branch information
Showing
10 changed files
with
222 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
blocks/identity-block/features/login-links/default.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
blocks/identity-block/features/login-links/index.story-ignore.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} /> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.