Skip to content

Commit

Permalink
Merge pull request #165 from web3ui/feature/icon-onClick
Browse files Browse the repository at this point in the history
feat:
-onClick as Icon prop
-CreditCard onPress/onRemove - delete Icon
-RGBToHex -> rgbToHex
  • Loading branch information
locothedev authored Feb 28, 2022
2 parents 20958a9 + ae6660d commit d833000
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 88 deletions.
10 changes: 5 additions & 5 deletions src/components/BannerStrip/BannerStrip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { composeStories } from '@storybook/testing-react';
import * as stories from './BannerStrip.stories';
import 'jest-styled-components';
import color from '../../styles/colors';
import RGBToHex from '../../utils/rgbToHex';
import rgbToHex from '../../utils/rgbToHex';

const { Standard, StandardWithButton, Warning, Error, Success } =
composeStories(stories);
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Banner Strip - Standard', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.blue);
});
});
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('Banner Strip - Warning', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.yellow);
});
});
Expand All @@ -120,7 +120,7 @@ describe('Banner Strip - Error', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.red);
});
});
Expand All @@ -147,7 +147,7 @@ describe('Banner Strip - Success', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.green);
});
});
40 changes: 20 additions & 20 deletions src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fireEvent } from '@testing-library/react';
import { composeStories } from '@storybook/testing-react';
import * as stories from './Button.stories';
import color from '../../styles/colors';
import RGBToHex from '../../utils/rgbToHex';
import rgbToHex from '../../utils/rgbToHex';

const {
Primary,
Expand Down Expand Up @@ -59,9 +59,9 @@ describe('Button - Primary', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.green);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.white);
});

Expand Down Expand Up @@ -90,10 +90,10 @@ describe('Button - Primary Large', () => {
`[data-testid="${buttonTestId}"]`,
);
const styles = element && getComputedStyle(element);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.white);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.green);
expect(styles?.borderWidth).toBe('4px');
expect(styles?.fontSize).toBe('16px');
Expand All @@ -117,10 +117,10 @@ describe('Button - Primary Small', () => {
`[data-testid="${buttonTestId}"]`,
);
const styles = element && getComputedStyle(element);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.white);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.green);
expect(styles?.fontSize).toBe('13px');
expect(styles?.padding).toBe('2px 12px');
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('Button - Primary with icon', () => {
});
it('renders icon correctly', () => {
const iconElement = container.querySelector(
`[data-testid="${buttonTestId}"] > svg`,
`[data-testid="${buttonTestId}"] > div > svg`,
);
expect(iconElement).not.toBeNull();
});
Expand Down Expand Up @@ -275,9 +275,9 @@ describe('Button - Secondary', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.blueLight);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.blue);
});

Expand Down Expand Up @@ -321,9 +321,9 @@ describe('Button - Outline', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.white);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.blue);
});
it('returns the normal onClick event', () => {
Expand Down Expand Up @@ -366,9 +366,9 @@ describe('Button - ColoredRed', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.red);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.red);
});
it('returns the normal onClick event', () => {
Expand Down Expand Up @@ -411,9 +411,9 @@ describe('Button - ColoredBlue', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.blue);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.blue);
});
it('returns the normal onClick event', () => {
Expand Down Expand Up @@ -456,9 +456,9 @@ describe('Button - ColoredGreen', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.green);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.green);
});
it('returns the normal onClick event', () => {
Expand Down Expand Up @@ -501,9 +501,9 @@ describe('Button - ColoredYellow', () => {
);
const styles = element && getComputedStyle(element);
const bgColorHex =
styles && RGBToHex(styles.backgroundColor).toUpperCase();
styles && rgbToHex(styles.backgroundColor).toUpperCase();
expect(bgColorHex).toBe(color.yellow);
const colorHex = styles && RGBToHex(styles.color).toUpperCase();
const colorHex = styles && rgbToHex(styles.color).toUpperCase();
expect(colorHex).toBe(color.yellow);
});
it('returns the normal onClick event', () => {
Expand Down
70 changes: 70 additions & 0 deletions src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { ComponentStory, ComponentMeta } from '@storybook/react';
import Card from './Card';
import React from 'react';
import getModuleAnimation from './Animations/animations';
import { Icon, iconTypes } from '../Icon';
import colors from '../../styles/colors';
import { Button } from '../Button';

export default {
title: '4.UI/Card',
Expand Down Expand Up @@ -94,3 +97,70 @@ ComingSoon.args = {
description: 'Coming Soon',
isDisabled: true,
};

export const ProPlan = Template.bind({});
ProPlan.args = {
children: [
<div key={'0'}>
<p>Pro Plan</p>
<div style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
<span style={{ fontWeight: 600, color: colors.black }}>
$18
</span>
<span>per month</span>
</div>
<span>Everything in Starter, plus</span>
<div
style={{
display: 'flex',
fontSize: '12px',
color: colors.grey,
}}
>
<Icon svg={iconTypes.checkmark} fill="green" />
Servers never Sleep
</div>
<div
style={{
display: 'flex',
fontSize: '12px',
color: colors.grey,
}}
>
<Icon svg={iconTypes.checkmark} fill="green" />
More requests
</div>
<div
style={{
display: 'flex',
fontSize: '12px',
color: colors.grey,
}}
>
<Icon svg={iconTypes.checkmark} fill="green" />
Higher limits
</div>
<div
style={{
display: 'flex',
fontSize: '12px',
color: colors.grey,
}}
>
<Icon svg={iconTypes.checkmark} fill="green" />
Request auto scaling
</div>
<div
style={{
display: 'flex',
fontSize: '12px',
color: colors.grey,
}}
>
<Icon svg={iconTypes.checkmark} fill="green" />
Email support
</div>
<Button text="Upgrade" theme="primary" isFullWidth />
</div>,
],
};
2 changes: 1 addition & 1 deletion src/components/Card/Card.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const DivStyled = styled.div<Pick<CardProps, 'selected' | 'isDisabled'>>`
padding: 15px;
position: relative;
width: 100%;
${(p) => p.isDisabled && `opacity:70%;`}
${(p) => p.isDisabled && 'opacity:70%;'}
${(p) => (p.selected ? selected : !p.isDisabled && hoverNotSelected)}
`;

Expand Down
16 changes: 9 additions & 7 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Card: React.FC<CardProps> = ({
svg={iconTypes.checkmark}
/>
)}
{!isDisabled && (
{!isDisabled && tooltipText && (
<Tooltip
position={'bottom'}
children={[
Expand All @@ -66,12 +66,14 @@ const Card: React.FC<CardProps> = ({
)}
</HeaderStyled>
<div>{children}</div>
<FooterStyled>
{title && <p data-testid={'title-test-id'}>{title}</p>}
{description && (
<span data-testid={'desc-test-id'}>{description}</span>
)}
</FooterStyled>
{(title || description) && (
<FooterStyled>
{title && <p data-testid={'title-test-id'}>{title}</p>}
{description && (
<span data-testid={'desc-test-id'}>{description}</span>
)}
</FooterStyled>
)}
</DivStyled>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Card/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface CardProps {
/**
* set text inside tooltip
*/
tooltipText: string;
tooltipText?: string;

/**
* Set the state disabled state of the cart
Expand Down
3 changes: 1 addition & 2 deletions src/components/CreditCard/CreditCard.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const DivStyledFlex = styled.div`
export const DivStyledFlexText = styled.div`
color: white;
display: flex;
gap: 15px;
`;

export const DivStyledRemove = styled.div`
Expand All @@ -73,7 +72,7 @@ export const PStyledText = styled.p`
color: ${colors.white};
font-size: 12px;
line-height: 16px;
margin: 0;
margin: 0 0 0 5px;
`;

const expiredStyles = css`
Expand Down
19 changes: 12 additions & 7 deletions src/components/CreditCard/CreditCard.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import React, { useState } from 'react';
import React from 'react';
import { Radios } from '../Radios';
import { Logo } from '../Logo';
import { CreditCardProps } from './types';
import {
DivStyledCreditCard,
DivStyledFlex,
DivStyledFlexText,
DivStyledRemove,
PStyledDigits,
PStyledText,
} from './CreditCard.styles';
import { Icon, iconTypes } from '../Icon';
import colors from '../../styles/colors';

const CreditCard: React.FC<CreditCardProps> = ({
expiresAt,
id,
isExpired,
lastDigits,
name,
onPressed,
onRemove,
pressed,
brand,
}: CreditCardProps) => {
const [pressed, setPressed] = useState<boolean>(false);

return (
<DivStyledCreditCard
isExpired={isExpired}
onClick={() => setPressed(!pressed)}
onClick={onPressed}
brand={brand}
pressed={pressed}
>
Expand All @@ -34,9 +35,13 @@ const CreditCard: React.FC<CreditCardProps> = ({
checked={pressed}
id={id || 'radio-credit-card'}
items={['']}
onChange={() => setPressed(!pressed)}
onChange={() => {}}
/>
<Icon
svg={iconTypes.bin}
fill={colors.red}
onClick={onRemove}
/>
<DivStyledRemove onClick={onRemove} />
</DivStyledFlex>
<PStyledDigits>{`•••• ${lastDigits}`}</PStyledDigits>
<DivStyledFlex>
Expand Down
5 changes: 5 additions & 0 deletions src/components/CreditCard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface CreditCardProps {
*/
name: string;

/**
* run function when creditcard is clicked
*/
onPressed?: () => void;

/**
* run function when remove icon is clicked
*/
Expand Down
Loading

0 comments on commit d833000

Please sign in to comment.