Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implemented Call to Action Component (#371) #409

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/components/PageContent/CallToAction/CallToAction.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (C) 2018 The Trustees of Indiana University
SPDX-License-Identifier: BSD-3-Clause
*/
import classNames from "classnames";
import * as PropTypes from "prop-types";
import * as React from "react";
import * as Rivet from "../../util/Rivet";
import { TestUtils } from "../../util/TestUtils";

const CallToAction = ({
children,
className,
testMode = false,
variant = "link",
...attrs
}) => {
const classNameArr = [
"rvt-cta",
variant === "button" ? "rvt-cta--button" : "",
className
]
return (
<a
className={classNames(classNameArr)}
{...(testMode && { "data-testid": TestUtils.CallToAction.link })}
{...attrs}
>
{children}
</a>
)
};

CallToAction.displayName = "CallToAction";
CallToAction.propTypes = {
/** [Developer] Adds data-testId attributes for component testing */
testMode: PropTypes.bool,
/* The variant determines the style of the call to action link */
variant: PropTypes.oneOf(["button", "link"]),
};

export default Rivet.rivetize(CallToAction);
17 changes: 17 additions & 0 deletions src/components/PageContent/CallToAction/CallToAction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Use the call to action component to add a link with extra visual emphasis to your page.

Calls to action are often used at the end of content sections to direct visitors to your site’s most interesting or actionable pages.
View the [Rivet documentation for Call to action](https://rivet.uits.iu.edu/components/call-to-action/).

### Call to Action Examples

<!-- prettier-ignore-start -->
```jsx
<div className="rvt-m-bottom-md">
<CallToAction href="#">Standard Link</CallToAction>
</div>
<div>
<CallToAction href="#" variant="button">Button Style Link</CallToAction>
</div>
```
<!-- prettier-ignore-end -->
42 changes: 42 additions & 0 deletions src/components/PageContent/CallToAction/CallToAction.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import React from "react";
import CallToAction from "./CallToAction";
import { TestUtils } from "../../util/TestUtils";

const testIds = TestUtils.CallToAction
const content = "test link"
const href = "#"

describe("<CallToAction />", () => {
describe("Rendering", () => {
it("should render without throwing an error", () => {
render(
<CallToAction href={href} testMode>
{content}
</CallToAction>
);
renderCheck()
});

it("should render without throwing an error", () => {
render(
<CallToAction href={href} testMode variant="button">
{content}
</CallToAction>
);
renderCheck()
const link = screen.getByTestId(testIds.link);
expect(link).toHaveClass("rvt-cta--button");
});
});
});

const renderCheck = () => {
const link = screen.getByTestId(testIds.link);
expect(link).toBeVisible();
expect(link.nodeName).toBe("A")
expect(link).toHaveClass("rvt-cta");
expect(link).toHaveAttribute("href", href)
expect(link.innerHTML).toBe(content)
}
1 change: 1 addition & 0 deletions src/components/PageContent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Copyright (C) 2018 The Trustees of Indiana University
SPDX-License-Identifier: BSD-3-Clause
*/
export { default as Badge } from "./Badge/Badge";
export { default as CallToAction } from "./CallToAction/CallToAction";
export { default as Disclosure } from "./Disclosure/Disclosure";
3 changes: 3 additions & 0 deletions src/components/util/TestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Copyright (C) 2018 The Trustees of Indiana University
SPDX-License-Identifier: BSD-3-Clause
*/
export const TestUtils = {
CallToAction: {
link: "cta-link"
},
ButtonGroup: { testId: "buttonGroup_testId" },
SegmentedButton: { testId: "segmentedButton_testId" },
RivetIcons: { testId: "rivetIcon_testId" },
Expand Down