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(Card): add textAlign prop to Card subcomponents #2038

Merged
merged 7 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions src/views/Card/CardContent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export interface CardContentProps {

/** Shorthand for CardMeta. */
meta?: SemanticShorthandItem<CardMetaProps>;

/** A card content can adjust its text alignment. */
textAlign?: 'center' | 'left' | 'right';
}

declare const CardContent: React.StatelessComponent<CardContentProps>;
Expand Down
8 changes: 8 additions & 0 deletions src/views/Card/CardContent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cx from 'classnames'
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

Expand All @@ -9,7 +10,9 @@ import {
getElementType,
getUnhandledProps,
META,
SUI,
useKeyOnly,
useTextAlignProp,
} from '../../lib'
import CardDescription from './CardDescription'
import CardHeader from './CardHeader'
Expand All @@ -26,11 +29,13 @@ function CardContent(props) {
extra,
header,
meta,
textAlign,
} = props

const classes = cx(
className,
useKeyOnly(extra, 'extra'),
useTextAlignProp(textAlign),
'content',
)
Copy link
Member

Choose a reason for hiding this comment

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

As we update almost all Card components, lets also move className to end, it's one of our style rules. I overlooked this on initial review.

cx(
  useKeyOnly(extra, 'extra'),
  useTextAlignProp(textAlign),
   'content',
  className,
)	

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should i first write 'ui', then functions, then other literals and then className?

const rest = getUnhandledProps(CardContent, props)
Expand Down Expand Up @@ -76,6 +81,9 @@ CardContent.propTypes = {

/** Shorthand for CardMeta. */
meta: customPropTypes.itemShorthand,

/** A card content can adjust its text alignment. */
textAlign: PropTypes.oneOf(_.without(SUI.TEXT_ALIGNMENTS, 'justified')),
}

export default CardContent
3 changes: 3 additions & 0 deletions src/views/Card/CardDescription.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface CardDescriptionProps {

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** A card description can adjust its text alignment. */
textAlign?: 'center' | 'left' | 'right';
}

declare const CardDescription: React.StatelessComponent<CardDescriptionProps>;
Expand Down
14 changes: 12 additions & 2 deletions src/views/Card/CardDescription.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cx from 'classnames'
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

Expand All @@ -8,14 +9,20 @@ import {
getElementType,
getUnhandledProps,
META,
SUI,
useTextAlignProp,
} from '../../lib'

/**
* A card can contain a description with one or more paragraphs.
*/
function CardDescription(props) {
const { children, className, content } = props
const classes = cx(className, 'description')
const { children, className, content, textAlign } = props
const classes = cx(
className,
useTextAlignProp(textAlign),
'description',
)
const rest = getUnhandledProps(CardDescription, props)
const ElementType = getElementType(CardDescription, props)

Expand Down Expand Up @@ -44,6 +51,9 @@ CardDescription.propTypes = {

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** A card content can adjust its text alignment. */
textAlign: PropTypes.oneOf(_.without(SUI.TEXT_ALIGNMENTS, 'justified')),
}

export default CardDescription
3 changes: 3 additions & 0 deletions src/views/Card/CardGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface CardGroupProps {

/** A group of cards can automatically stack rows to a single columns on mobile devices. */
stackable?: boolean;

/** A card group can adjust its text alignment. */
textAlign?: 'center' | 'left' | 'right';
}

declare const CardGroup: React.StatelessComponent<CardGroupProps>;
Expand Down
11 changes: 9 additions & 2 deletions src/views/Card/CardGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
META,
SUI,
useKeyOnly,
useTextAlignProp,
useWidthProp,
} from '../../lib'
import Card from './Card'
Expand All @@ -26,13 +27,16 @@ function CardGroup(props) {
items,
itemsPerRow,
stackable,
textAlign,
} = props

const classes = cx('ui',
const classes = cx(
'ui',
className,
useKeyOnly(doubling, 'doubling'),
useKeyOnly(stackable, 'stackable'),
useTextAlignProp(textAlign),
useWidthProp(itemsPerRow),
className,
'cards',
)
const rest = getUnhandledProps(CardGroup, props)
Expand Down Expand Up @@ -77,6 +81,9 @@ CardGroup.propTypes = {

/** A group of cards can automatically stack rows to a single columns on mobile devices. */
stackable: PropTypes.bool,

/** A card group can adjust its text alignment. */
textAlign: PropTypes.oneOf(_.without(SUI.TEXT_ALIGNMENTS, 'justified')),
}

export default CardGroup
3 changes: 3 additions & 0 deletions src/views/Card/CardHeader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface CardHeaderProps {

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** A card header can adjust its text alignment. */
textAlign?: 'center' | 'left' | 'right';
}

declare const CardHeader: React.StatelessComponent<CardHeaderProps>;
Expand Down
14 changes: 12 additions & 2 deletions src/views/Card/CardHeader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cx from 'classnames'
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

Expand All @@ -8,14 +9,20 @@ import {
getElementType,
getUnhandledProps,
META,
SUI,
useTextAlignProp,
} from '../../lib'

/**
* A card can contain a header.
*/
function CardHeader(props) {
const { children, className, content } = props
const classes = cx(className, 'header')
const { children, className, content, textAlign } = props
const classes = cx(
className,
useTextAlignProp(textAlign),
'header',
)
const rest = getUnhandledProps(CardHeader, props)
const ElementType = getElementType(CardHeader, props)

Expand Down Expand Up @@ -44,6 +51,9 @@ CardHeader.propTypes = {

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** A card header can adjust its text alignment. */
textAlign: PropTypes.oneOf(_.without(SUI.TEXT_ALIGNMENTS, 'justified')),
}

export default CardHeader
3 changes: 3 additions & 0 deletions src/views/Card/CardMeta.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface CardMetaProps {

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** A card meta can adjust its text alignment. */
textAlign?: 'center' | 'left' | 'right';
}

declare const CardMeta: React.StatelessComponent<CardMetaProps>;
Expand Down
14 changes: 12 additions & 2 deletions src/views/Card/CardMeta.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cx from 'classnames'
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

Expand All @@ -8,14 +9,20 @@ import {
getElementType,
getUnhandledProps,
META,
SUI,
useTextAlignProp,
} from '../../lib'

/**
* A card can contain content metadata.
*/
function CardMeta(props) {
const { children, className, content } = props
const classes = cx(className, 'meta')
const { children, className, content, textAlign } = props
const classes = cx(
className,
useTextAlignProp(textAlign),
'meta',
)
const rest = getUnhandledProps(CardMeta, props)
const ElementType = getElementType(CardMeta, props)

Expand Down Expand Up @@ -44,6 +51,9 @@ CardMeta.propTypes = {

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** A card meta can adjust its text alignment. */
textAlign: PropTypes.oneOf(_.without(SUI.TEXT_ALIGNMENTS, 'justified')),
}

export default CardMeta
4 changes: 4 additions & 0 deletions test/specs/views/Card/CardContent-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import _ from 'lodash';
Copy link
Member

Choose a reason for hiding this comment

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

Heads up, tests are failing due to lint:

/home/ubuntu/Semantic-UI-React/test/specs/views/Card/CardContent-test.js
  1:23  error  Extra semicolon  semi

You can run npm run lint:fix to fix most errors and then push. Note that you can ignore warnings.


import { SUI } from 'src/lib'
import CardContent from 'src/views/Card/CardContent'
import CardDescription from 'src/views/Card/CardDescription'
import CardHeader from 'src/views/Card/CardHeader'
Expand All @@ -24,5 +27,6 @@ describe('CardContent', () => {
mapValueToProps: val => ({ content: val }),
})

common.implementsTextAlignProp(CardContent, _.without(SUI.TEXT_ALIGNMENTS, 'justified'))
common.propKeyOnlyToClassName(CardContent, 'extra')
})
3 changes: 3 additions & 0 deletions test/specs/views/Card/CardDescription-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import faker from 'faker'
import _ from 'lodash'
import React from 'react'

import { SUI } from 'src/lib'
import CardDescription from 'src/views/Card/CardDescription'
import * as common from 'test/specs/commonTests'

describe('CardDescription', () => {
common.isConformant(CardDescription)
common.rendersChildren(CardDescription)
common.implementsTextAlignProp(CardDescription, _.without(SUI.TEXT_ALIGNMENTS, 'justified'))

describe('description prop', () => {
it('renders child text', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/specs/views/Card/CardGroup-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import faker from 'faker'
import _ from 'lodash'
import React from 'react'

import { SUI } from 'src/lib'
Expand All @@ -10,6 +11,7 @@ describe('CardGroup', () => {
common.hasUIClassName(CardGroup)
common.rendersChildren(CardGroup)

common.implementsTextAlignProp(CardGroup, _.without(SUI.TEXT_ALIGNMENTS, 'justified'))
common.implementsWidthProp(CardGroup, SUI.WIDTHS, { propKey: 'itemsPerRow', canEqual: false })

common.propKeyOnlyToClassName(CardGroup, 'doubling')
Expand Down
4 changes: 4 additions & 0 deletions test/specs/views/Card/CardHeader-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import faker from 'faker'
import _ from 'lodash'
import React from 'react'

import { SUI } from 'src/lib'
import CardHeader from 'src/views/Card/CardHeader'
import * as common from 'test/specs/commonTests'

describe('CardHeader', () => {
common.isConformant(CardHeader)
common.rendersChildren(CardHeader)

common.implementsTextAlignProp(CardHeader, _.without(SUI.TEXT_ALIGNMENTS, 'justified'))

describe('description prop', () => {
it('renders child text', () => {
const text = faker.hacker.phrase()
Expand Down
4 changes: 4 additions & 0 deletions test/specs/views/Card/CardMeta-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import faker from 'faker'
import _ from 'lodash'
import React from 'react'

import { SUI } from 'src/lib'
import CardMeta from 'src/views/Card/CardMeta'
import * as common from 'test/specs/commonTests'

describe('CardMeta', () => {
common.isConformant(CardMeta)
common.rendersChildren(CardMeta)

common.implementsTextAlignProp(CardMeta, _.without(SUI.TEXT_ALIGNMENTS, 'justified'))

describe('description prop', () => {
it('renders child text', () => {
const text = faker.hacker.phrase()
Expand Down