Skip to content

Commit

Permalink
feat(content-cta)!: convert to CSS modules (#306)
Browse files Browse the repository at this point in the history
* refactor(content-cta)!: convert to CSS modules

* feat(content-cta): support className prop, add changeset
  • Loading branch information
zchsh committed Sep 7, 2021
1 parent 740f35b commit 1eceec6
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 156 deletions.
7 changes: 7 additions & 0 deletions .changeset/selfish-pigs-agree.md
@@ -0,0 +1,7 @@
---
'@hashicorp/react-content-cta': major
---

- 💥✨ BREAKING CHANGE: Converts to CSS modules.
- Consumers will need to remove any `@hashicorp/react-content-cta/style.css` imports.
- To support overrides in projects, consumers can use the `className` prop.
20 changes: 14 additions & 6 deletions packages/content-cta/index.js
@@ -1,12 +1,14 @@
import useProductMeta from '@hashicorp/platform-product-meta'
import classNames from 'classnames'
import Button from '@hashicorp/react-button'
import s from './style.module.css'

export default function ContentCta({
heading,
content,
product = 'hashicorp',
links,
className,
}) {
if (!heading || !content) {
throw new Error('<ContentCTA /> requires heading & content props')
Expand All @@ -21,26 +23,32 @@ export default function ContentCta({

return (
<div
className={classNames('g-content-cta', themeClass, {
hasTheme: themeClass,
})}
className={classNames(
s.root,
themeClass,
{
[s.hasTheme]: themeClass,
},
className
)}
>
<h4 data-testid="heading" className="g-type-display-4">
<h4 data-testid="heading" className={s.heading}>
{heading}
</h4>

{isContentString ? (
<p data-testid="content" className="g-type-body">
<p data-testid="content" className={s.content}>
{content}
</p>
) : isContentRenderProp ? (
content()
) : null}
{hasLinks && (
<div data-testid="links" className="links">
<div data-testid="links" className={s.links}>
{links.map(({ title, url }, i) => (
<Button
key={title}
className={i === 0 ? s.firstLink : ''}
title={title}
url={url}
theme={{
Expand Down
9 changes: 6 additions & 3 deletions packages/content-cta/index.test.js
Expand Up @@ -19,11 +19,14 @@ const baseProps = {
}

describe('<ContentCta />', () => {
it('should render a `.g-content-cta` <div> root element', () => {
const { container } = render(<ContentCta {...baseProps} />)
it('should add a provided className to the root element', () => {
const className = 'my-content-cta'
const { container } = render(
<ContentCta {...baseProps} className={className} />
)
const rootElem = container.firstChild
expect(rootElem.tagName).toBe('DIV')
expect(rootElem).toHaveClass('g-content-cta')
expect(rootElem).toHaveClass(className)
})

it('should display simple heading and content strings and links', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/content-cta/props.js
Expand Up @@ -12,6 +12,10 @@ module.exports = {
product: {
...baseProps.product,
},
className: {
type: 'string',
description: 'Optional className to add to the root element',
},
links: {
type: 'array',
properties: [
Expand Down
Empty file.
51 changes: 0 additions & 51 deletions packages/content-cta/stories/examples.stories.js

This file was deleted.

58 changes: 0 additions & 58 deletions packages/content-cta/stories/with-knobs.stories.js

This file was deleted.

37 changes: 0 additions & 37 deletions packages/content-cta/style.css

This file was deleted.

44 changes: 44 additions & 0 deletions packages/content-cta/style.module.css
@@ -0,0 +1,44 @@
.root {
padding: 28px;

&.hasTheme {
--link-color: var(--brand-link);

background: var(--brand-secondary);
}
}

.heading {
composes: g-type-display-4 from global;
margin-top: 0;
margin-bottom: 16px;
}

.content {
composes: g-type-body from global;

& p {
margin: 0;
max-width: 30em;
color: var(--gray-2);

& a {
color: var(--link-color);
&:hover {
text-decoration: underline;
}
}
}
}

.links {
margin-top: 28px;
}

.firstLink {
margin-right: 16px;

@media (max-width: 468px) {
margin-bottom: 16px;
}
}
1 change: 0 additions & 1 deletion pages/global.css
Expand Up @@ -8,7 +8,6 @@
@import '../packages/call-to-action/style.css';
@import '../packages/product-features-list/style.css';
@import '../packages/enterprise-alert/style.css';
@import '../packages/content-cta/style.css';
@import '../packages/toggle/style.css';
@import '../packages/text-input/style.css';
@import '../packages/logo-grid/style.css';
Expand Down

1 comment on commit 1eceec6

@vercel
Copy link

@vercel vercel bot commented on 1eceec6 Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.