Skip to content

Commit

Permalink
feat: migrates Alert to css modules (#231)
Browse files Browse the repository at this point in the history
* migrates alert to css modules

* update test

* remove usage of g-alert

* migrate to TS

* updates props file

* adds graphql type declaration

* remove unnecessary file
  • Loading branch information
Bryce Kalow committed Aug 16, 2021
1 parent 57720a9 commit 32cf9e3
Show file tree
Hide file tree
Showing 72 changed files with 9,596 additions and 9,471 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
}
},
"lint-staged": {
"*.+(js|jsx|ts|tsx)": [
"next-hashicorp format",
"next-hashicorp lint"
]
"*.+(js|jsx|ts|tsx)": ["next-hashicorp format", "next-hashicorp lint"]
}
}
4 changes: 1 addition & 3 deletions packages/accordion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"description": "A block that displays a set of title + content items, with content collapsed by default, but expandable to view. Also includes an optional heading for the block.",
"version": "2.0.2",
"author": "HashiCorp",
"contributors": [
"Zach Shilton"
],
"contributors": ["Zach Shilton"],
"dependencies": {
"@hashicorp/react-inline-svg": "^1.0.2"
},
Expand Down
168 changes: 84 additions & 84 deletions packages/alert-banner/package-lock.json

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

6 changes: 1 addition & 5 deletions packages/alert-banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"version": "6.2.0",
"author": "HashiCorp",
"bugs": "https://github.com/hashicorp/react-components/issues?q=is:issue+%22alert-banner%22",
"contributors": [
"Zach Shilton",
"Jeff Escalante",
"Kendall Strautman"
],
"contributors": ["Zach Shilton", "Jeff Escalante", "Kendall Strautman"],
"dependencies": {
"@hashicorp/platform-product-meta": "^0.1.0",
"@hashicorp/react-inline-svg": "^6.0.2",
Expand Down
7 changes: 6 additions & 1 deletion packages/alert/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ describe('<Alert />', () => {
test('renders correctly', () => {
const { container } = render(<Alert {...defaultProps} />)
const rootElem = container.firstChild
expect(rootElem).toHaveClass('g-alert')
expect(rootElem).toHaveClass(defaultProps.product)
expect(rootElem).toHaveClass(defaultProps.textColor)
expect(rootElem).toHaveAttribute('href', defaultProps.url)
expect(screen.getByTestId('tag')).toHaveTextContent(defaultProps.tag)
expect(screen.getByTestId('text')).toHaveTextContent(defaultProps.text)
})

test('accepts a className prop', () => {
const { container } = render(<Alert {...defaultProps} className="alert" />)
const rootElem = container.firstChild
expect(rootElem).toHaveClass('alert')
})
})
31 changes: 28 additions & 3 deletions packages/alert/index.js → packages/alert/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import classNames from 'classnames'
import useProductMeta from '@hashicorp/platform-product-meta'
import useProductMeta, { Products } from '@hashicorp/platform-product-meta'
import fragment from './fragment.graphql'
import s from './style.module.css'

function Alert({ product, url, tag, text, state, textColor }) {
function Alert({
product,
url,
tag,
text,
state,
textColor,
className,
}: AlertProps): React.ReactElement {
const { themeClass } = useProductMeta(product)
return (
<a
href={url}
className={classNames('g-alert', themeClass, state, textColor)}
className={classNames(
s.alertRoot,
themeClass,
state ? s[state] : false,
textColor ? s[textColor] : false,
className
)}
>
<span className="g-type-tag-label" data-testid="tag">
{tag}
Expand Down Expand Up @@ -48,3 +63,13 @@ function ArrowIcon() {
Alert.fragmentSpec = { fragment }

export default Alert

interface AlertProps {
product: Products
url: string
tag: string
text: string
state: 'success' | 'warning' | 'error'
textColor: 'dark' | 'light'
className?: string
}
4 changes: 1 addition & 3 deletions packages/alert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"version": "5.0.1",
"author": "HashiCorp",
"bugs": "https://github.com/hashicorp/react-components/issues?q=is:issue+%22alert%22",
"contributors": [
"Jeff Escalante"
],
"contributors": ["Jeff Escalante"],
"homepage": "https://github.com/hashicorp/react-components/tree/master/packages/alert",
"license": "MPL-2.0",
"main": "index.jsx",
Expand Down
5 changes: 5 additions & 0 deletions packages/alert/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ module.exports = {
options: ['dark', 'light'],
testValue: 'dark',
},
className: {
description: 'class to apply to the root element',
control: { type: 'text' },
type: 'string',
},
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.g-alert {
.alertRoot {
display: inline-flex;
align-items: flex-start;

Expand Down
4 changes: 1 addition & 3 deletions packages/button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"description": "A clickable text box that allows a user to take an action.",
"version": "5.3.0",
"author": "HashiCorp",
"contributors": [
"Jeff Escalante"
],
"contributors": ["Jeff Escalante"],
"dependencies": {
"@hashicorp/platform-product-meta": "^0.1.0",
"@hashicorp/react-inline-svg": "^1.0.0",
Expand Down
50 changes: 25 additions & 25 deletions packages/call-to-action/package-lock.json

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

10 changes: 2 additions & 8 deletions packages/call-to-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
"description": "Display a title, content, and links in a call-to-action format",
"version": "3.1.3",
"author": "HashiCorp",
"contributors": [
"Zach Shilton"
],
"contributors": ["Zach Shilton"],
"dependencies": {
"@hashicorp/react-button": "^5.3.0"
},
"peerDependencies": {
"@hashicorp/mktg-global-styles": ">=3.x"
},
"keywords": [
"call to action",
"component",
"react"
],
"keywords": ["call to action", "component", "react"],
"license": "MPL-2.0",
"publishConfig": {
"access": "public"
Expand Down
4 changes: 1 addition & 3 deletions packages/callouts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"description": "Display a set of items, each with a title, description, option links, and an optional icon.",
"version": "7.1.3",
"author": "HashiCorp",
"contributors": [
"Zach Shilton"
],
"contributors": ["Zach Shilton"],
"dependencies": {
"@hashicorp/platform-product-meta": "^0.1.0",
"@hashicorp/react-button": "^5.3.0",
Expand Down

1 comment on commit 32cf9e3

@vercel
Copy link

@vercel vercel bot commented on 32cf9e3 Aug 16, 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.