-
Notifications
You must be signed in to change notification settings - Fork 72
PD-309: Card Component #102
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
53f83e5
chore: renamed packages
bruugey ec228d8
Merge branch 'master' of github.com:mongodb/leafygreen-ui
bruugey dec6c31
Merge branch 'master' of github.com:mongodb/leafygreen-ui
bruugey bd117db
Merge branch 'master' of github.com:mongodb/leafygreen-ui
bruugey dd18a4d
feat(card): implement card component
bruugey bda33c4
fix(card): respondign to PR feedback
bruugey 8dd715b
fix(card): render in section html element
bruugey c2ce17c
feat: addded border-radius
bruugey 80f2ac8
chore: merge w master
bruugey 8bc7057
feat: added yarn error log to gitignore
bruugey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -14,3 +14,6 @@ storybook/public/ | |
|
|
||
| # JUnit report files | ||
| reports | ||
|
|
||
| # Yarn Error Log | ||
| yarn-error.log | ||
This file contains hidden or 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,50 @@ | ||
| # Card | ||
|
|
||
|  | ||
|
|
||
| ## Example | ||
|
|
||
| ```Javascript | ||
| import Card from '@leafygreen-ui/card'; | ||
|
|
||
| <Card | ||
| as='div' | ||
| className='card-styles' | ||
| > | ||
| This is my card component | ||
| </Card> | ||
| ``` | ||
|
|
||
| **Output HTML** | ||
|
|
||
| ```HTML | ||
| <div class="leafygreen-ui-1xf4bcx">This is a card component</div> | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| ### className | ||
|
|
||
| **Type:** `string` | ||
|
|
||
| **Default:** `''` | ||
|
|
||
| Adds a className to the class attribute. | ||
|
|
||
| ### children | ||
|
|
||
| **Type:** `node` | ||
|
|
||
| **Default:** `null` | ||
|
|
||
| The children of the rendered `Card` component. | ||
|
|
||
| ### as | ||
|
|
||
| **Type:** `HTML Tag` or `React Element` | ||
|
|
||
| **Default:** `section` | ||
|
|
||
| Determines the root element. For example, `Link` or `a` tags can be supplied to replace `div` from being the DOM element that wraps the component. | ||
|
|
||
| #### Any other properties will be spread on the input element. |
This file contains hidden or 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,20 @@ | ||
| { | ||
| "name": "@leafygreen-ui/card", | ||
| "version": "0.9.0", | ||
| "description": "leafyGreen UI Kit Card", | ||
| "main": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "scripts": { | ||
| "build": "../../node_modules/.bin/webpack --config ../../webpack.config.js", | ||
| "ts:emit": "tsc --project ./tsconfig.json" | ||
| }, | ||
| "license": "Apache-2.0", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@leafygreen-ui/lib": "^3.0.0", | ||
| "@leafygreen-ui/palette": "^1.0.0" | ||
| }, | ||
| "gitHead": "53385cfed5ecf3101d098d26dedc6a40b27c402a" | ||
| } |
This file contains hidden or 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,43 @@ | ||
| import React from 'react'; | ||
| import { render, cleanup } from '@testing-library/react'; | ||
| import Card from './Card'; | ||
|
|
||
| afterAll(cleanup); | ||
|
|
||
| describe('packages/Card', () => { | ||
| const className = 'card-className'; | ||
| const children = 'this is my card component'; | ||
| const cardId = 'cardID'; | ||
|
|
||
| const { getByTestId } = render( | ||
| <Card data-testid={cardId} className={className}> | ||
| {children} | ||
| </Card>, | ||
| ); | ||
|
|
||
| const renderedCard = getByTestId(cardId); | ||
|
|
||
| test(`renders "${className}" in the cards's classList`, () => { | ||
| expect(renderedCard.classList.contains(className)).toBe(true); | ||
| }); | ||
|
|
||
| test(`renders "${children}" as the cards's textContent`, () => { | ||
| expect(renderedCard.textContent).toBe(children); | ||
| }); | ||
|
|
||
| test(`renders inside of a section tag by default`, () => { | ||
| expect(renderedCard.tagName.toLowerCase()).toBe('section'); | ||
| }); | ||
|
|
||
| test(`renders component inside of a React Element/HTML tag based on as prop`, () => { | ||
| const newCardId = 'newCardID'; | ||
| const { getByTestId } = render( | ||
| <Card data-testid={newCardId} as="section"> | ||
| Card! | ||
| </Card>, | ||
| ); | ||
| const cardComponent = getByTestId(newCardId); | ||
|
|
||
| expect(cardComponent.tagName.toLowerCase()).toBe('section'); | ||
| }); | ||
| }); |
This file contains hidden or 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,19 @@ | ||
| import React from 'react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
| import { css } from '@leafygreen-ui/emotion'; | ||
| import Card from './Card'; | ||
|
|
||
| const containerStyle = css` | ||
| padding: 10px; | ||
| height: 70px; | ||
| width: 140px; | ||
| display: flex; | ||
| align-items: center; | ||
| text-align: center; | ||
| `; | ||
|
|
||
| storiesOf('Card', module).add('Default', () => ( | ||
| <Card as="div" className={containerStyle}> | ||
| This is a card component | ||
| </Card> | ||
| )); |
This file contains hidden or 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,43 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { css, cx } from '@leafygreen-ui/emotion'; | ||
| import { uiColors } from '@leafygreen-ui/palette'; | ||
|
|
||
| const containerStyle = css` | ||
| background-color: white; | ||
| border: 1px solid ${uiColors.gray.light2}; | ||
| border-radius: 4px; | ||
| box-shadow: 0px 4px 10px -4px ${uiColors.gray.light1}; | ||
| transition: border 300ms ease-in-out, box-shadow 300ms ease-in-out; | ||
|
|
||
| &:hover { | ||
| border: 1px solid ${uiColors.gray.light2}; | ||
| box-shadow: 0px 3px 6px -2px ${uiColors.gray.base}; | ||
| } | ||
| `; | ||
|
|
||
| interface CardProps { | ||
| children: React.ReactNode; | ||
| as?: React.ElementType<any>; | ||
hswolff marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| className?: string; | ||
| } | ||
|
|
||
| function Card({ children, as = 'section', className, ...rest }: CardProps) { | ||
| const Root = as; | ||
|
|
||
| return ( | ||
DesignerDave marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Root {...rest} className={cx(containerStyle, className)}> | ||
| {children} | ||
| </Root> | ||
| ); | ||
| } | ||
|
|
||
| Card.displayName = 'Card'; | ||
|
|
||
| Card.propTypes = { | ||
| children: PropTypes.node, | ||
| as: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | ||
| className: PropTypes.string, | ||
| }; | ||
|
|
||
| export default Card; | ||
This file contains hidden or 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,2 @@ | ||
| import Card from './Card'; | ||
| export default Card; |
This file contains hidden or 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,7 @@ | ||
| { | ||
| "extends": "../../package.tsconfig.json", | ||
| "compilerOptions": { | ||
| "declarationDir": "dist" | ||
| }, | ||
| "include": ["src/**/*"] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could ya add a transition to the border and box-shadow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what kind of transition?