Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit d8c8dea

Browse files
committed
fix(Card): Apply alignment as text-alignment and allow text color to be set
1 parent b5a29a2 commit d8c8dea

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

src/cards/Card.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ class Card extends React.Component<CardProps> {
3333
};
3434

3535
public render() {
36-
const { backgroundColor, children, headerColor, onClick, overlayContent, title } = this.props;
36+
const {
37+
backgroundColor,
38+
children,
39+
headerColor,
40+
onClick,
41+
overlayContent,
42+
textColor,
43+
title,
44+
} = this.props;
3745

3846
const actionOpen = (e: React.MouseEvent<HTMLElement>) => {
3947
e.stopPropagation();
@@ -72,6 +80,7 @@ class Card extends React.Component<CardProps> {
7280
<BaseCard
7381
role={onClick !== undefined ? 'button' : ''}
7482
backgroundColor={backgroundColor}
83+
textColor={textColor}
7584
onClick={onClick}
7685
>
7786
{overlayContent !== undefined ? renderOverlay : null}

src/cards/docs/DocsCardPreview.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ const DocsCardOnClick = () => {
5050

5151
const DocsCardHeroText = () => {
5252
return (
53-
<Card active backgroundColor={({ theme }) => theme.color.Disabled}>
53+
<Card
54+
active
55+
backgroundColor={({ theme }) => theme.color.Disabled}
56+
textColor={({ theme }) => theme.color.DisabledText}
57+
>
5458
<CardHeroText>
5559
<H2
56-
textColor={({ theme }) => theme.color.DisabledText}
5760
size={Size.Large}
5861
alignment={Align.Center}
5962
>

src/cards/docs/DocsCardProps.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export default () => {
1414
<TableCell>False</TableCell>
1515
<TableCell>Use for when a Card needs to be shown as active/selected</TableCell>
1616
</TableRow>
17+
<TableRow>
18+
<TableCell>textColor</TableCell>
19+
<TableCell>string | theme</TableCell>
20+
<TableCell>Undefined</TableCell>
21+
<TableCell>Sets the text color of the card</TableCell>
22+
</TableRow>
1723
<TableRow>
1824
<TableCell>backgroundColor</TableCell>
1925
<TableCell>string | theme</TableCell>

src/cards/utils/BaseCard.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const BaseCard = styled.div<CardProps>`
88
box-shadow: ${({ onClick, theme }) =>
99
onClick !== undefined ? theme.shadow.Medium : theme.shadow.Small};
1010
box-sizing: border-box;
11-
color: ${({ backgroundColor, theme }) => {
11+
color: ${({ backgroundColor, textColor, theme }) => {
12+
if (textColor !== undefined) {
13+
return textColor;
14+
}
1215
if (backgroundColor === undefined) {
1316
return theme.color.BodyText;
1417
}

src/cards/utils/CardProps.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export default interface CardProps {
88
// Sets the background color of the card
99
readonly backgroundColor?: ((props: { readonly theme: ThemeProvider }) => string) | string;
1010

11+
// Sets the main text color of the card
12+
readonly textColor?: ((props: { readonly theme: ThemeProvider }) => string) | string;
13+
1114
// Set background color of header/title
1215
readonly headerColor?: ((props: { readonly theme: ThemeProvider }) => string) | string;
1316

src/text/utils/textStyles.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css } from '../../utils/mural-styled-components';
22

33
import ThemeProvider from '../../themes/themeProps';
4-
import { Align } from '../../utils/AlignmentProps';
4+
import { Align, getTextAlignment } from '../../utils/AlignmentProps';
55
import { getSize, Size } from '../../utils/sizes';
66

77
export interface TextProps {
@@ -15,11 +15,12 @@ export interface TextProps {
1515
}
1616

1717
const textStyle = css<TextProps>`
18-
color: ${(props) => props.textColor !== undefined ? props.textColor : props.theme.color.BodyText};
18+
color: ${(props) => props.textColor !== undefined ? props.textColor : 'inherit'};
1919
font-style: ${(props) => props.italic !== undefined ? 'italic' : 'normal'};
2020
font-weight: ${(props) => props.bold !== undefined ? '700' : '300'};
2121
margin: 0 0 ${(props) => getSize(props.spacing, Size.Default)};
2222
width: 100%;
23+
${(props) => props.alignment !== undefined ? getTextAlignment(props.alignment) : null}
2324
`;
2425

2526
export default textStyle;

src/utils/AlignmentProps.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,17 @@ export enum Align {
77
export default interface AlignmentProps {
88
readonly alignment?: Align;
99
}
10+
11+
export const getTextAlignment = (align: Align) => {
12+
switch (align) {
13+
case Align.Left:
14+
default:
15+
return 'text-align: left';
16+
17+
case Align.Center:
18+
return 'text-align: center';
19+
20+
case Align.Right:
21+
return 'text-align: right';
22+
}
23+
};

0 commit comments

Comments
 (0)