Skip to content

Commit c12c6b3

Browse files
committed
fixed patterns and maybe hover states
1 parent 9487596 commit c12c6b3

File tree

6 files changed

+142
-63
lines changed

6 files changed

+142
-63
lines changed

packages/gamut/src/Card/elements.tsx

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { Background ,
33
Colors,
44
} from '@codecademy/gamut-styles';
55
import styled from '@emotion/styled';
6+
import { useEffect, useState } from 'react';
67

78
import { Anchor } from '../Anchor';
89
import { Box } from '../Box';
9-
import { cardAnchorVariants, cardVariants, hoverState, shadowVariants } from './styles';
10+
import { cardAnchorVariants, cardVariants, hoverState, patternHoverState, shadowVariants } from './styles';
1011
import { CardAnchorProps, CardWrapperProps } from './types';
1112

1213
export const AnchorWrapper = styled(Anchor)<CardAnchorProps>(
@@ -25,39 +26,57 @@ export const StaticCardWrapper = styled(Background)<CardWrapperProps>(
2526
hoverState
2627
);
2728

29+
export const PatternWrapper = styled(Box)(
30+
patternHoverState
31+
)
32+
2833
export const CardWrapper: React.FC<CardWrapperProps> = ({
2934
children,
3035
variant='default',
3136
shadow ='none',
3237
isInteractive=false,
3338
pattern: Pattern = CheckerDense,
39+
// isHovering,
3440
...rest
3541
}) => {
36-
console.log('pattern is', Pattern);
37-
console.log('shadow is', shadow);
3842
const CardWrapper = variant === 'default' ? DynamicCardWrapper : StaticCardWrapper;
43+
44+
const [isHovering, setIsHovering] = useState(false);
45+
const handleMouseOver = () => {
46+
setTimeout(() => {
47+
setIsHovering(true);
48+
}, 100);
49+
}
50+
const handleMouseLeave = () => {
51+
setTimeout(() => {
52+
setIsHovering(false);
53+
}, 100);
54+
}
55+
56+
const hasPattern = shadow === 'patternLeft' || shadow === 'patternRight'
57+
const showPattern = hasPattern && (isInteractive && !isHovering);
3958
return (
40-
<CardWrapper
41-
bg={variant !== 'default' ? variant as Colors : 'white'}
42-
variant={variant}
43-
shadow={shadow}
44-
isInteractive={isInteractive}
45-
position='relative'
46-
zIndex={1}
47-
{...rest}
48-
>
49-
{ (shadow === 'patternLeft' || shadow === 'patternRight') &&
59+
<Box dimensions={1} position='relative' onMouseOver={handleMouseOver}
60+
onMouseLeave={handleMouseLeave}>
61+
{ showPattern &&
5062
<Pattern
5163
dimensions={1}
5264
position="absolute"
5365
top=".5rem"
5466
left={shadow === 'patternLeft' ? '-0.5rem' : undefined}
5567
right={shadow === 'patternRight' ? '-0.5rem' : undefined}
56-
// zIndex={-1}
5768
/>
5869
}
59-
{children}
60-
</CardWrapper>
70+
<CardWrapper
71+
bg={variant !== 'default' ? variant as Colors : 'white'}
72+
variant={variant}
73+
shadow={shadow}
74+
isInteractive={isInteractive}
75+
{...rest}
76+
>
77+
{children}
78+
</CardWrapper>
79+
</Box>
6180
);
6281
};
6382

packages/gamut/src/Card/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22

33
import { AnchorWrapper, CardWrapper } from './elements';
44
import { CardProps } from './types';
5-
import { CheckerDense } from '@codecademy/gamut-patterns';
65

76
// export interface CardProps {
87
// variant?: 'navy' | 'white' | 'hyper' | 'yellow' | 'beige';
@@ -16,11 +15,8 @@ export const Card: React.FC<CardProps> = ({
1615
shadow ='none',
1716
pattern,
1817
}) => {
19-
// const CardContent = <CardWrapper variant={variant} shadow={shadow} isInteractive={Boolean(href)} pattern={Pattern} >
20-
// {children}
21-
// </CardWrapper>
22-
console.log(shadow)
2318
const isInteractive = Boolean(href);
19+
2420
if(isInteractive) {
2521
return (
2622
<AnchorWrapper
@@ -29,7 +25,7 @@ export const Card: React.FC<CardProps> = ({
2925
onClick={onClick}
3026
hoverState={shadow === 'patternRight' ? 'hoverRight' : 'default'}
3127
>
32-
<CardWrapper variant={variant} shadow={shadow} isInteractive={isInteractive} pattern={pattern}>
28+
<CardWrapper variant={variant} shadow={shadow} isInteractive={isInteractive} pattern={pattern} >
3329
{children}
3430
</CardWrapper>
3531
</AnchorWrapper>

packages/gamut/src/Card/styles.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ export const shadowVariants = variant({
5151
export const hoverState = states({
5252
isInteractive: {
5353
'&:hover': {
54-
transition: 'box-shadow 200ms ease, ',
55-
boxShadow: `0px 0px 0px ${theme.colors['shadow-primary']}`,
54+
transition: 'box-shadow 200ms ease',
55+
boxShadow: `0px 0px ${theme.colors['shadow-primary']}`,
5656
},
5757
},
5858
})
5959

60+
export const patternHoverState = states({
61+
hidePattern: {
62+
[ButtonSelectors.HOVER]: {
63+
display: 'none'
64+
}
65+
}
66+
})
67+
6068
export const cardAnchorVariants = variant({
6169
prop: 'hoverState',
6270
base: {
@@ -74,7 +82,7 @@ export const cardAnchorVariants = variant({
7482
},
7583
hoverRight: {
7684
[ButtonSelectors.HOVER]: {
77-
transform: 'translate(4px, 4px)',
85+
transform: 'translate(-4px, -4px)',
7886
boxShadow: `8px 8px 0 ${theme.colors['shadow-primary']}`,
7987
transition: 'box-shadow 200ms ease, transform 200ms ease',
8088
},

packages/gamut/src/Card/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface CardWrapperProps
1010
StyleProps<typeof hoverState>,
1111
WithChildrenProp {
1212
pattern?: React.ComponentType<PatternProps>;
13+
isHovering?: boolean;
1314
}
1415

1516
export interface CardProps extends CardWrapperProps {

packages/styleguide/src/lib/Atoms/Card/Card.mdx

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ export const parameters = {
2323

2424
<ComponentHeader {...parameters} />
2525

26-
#### PatternLeft
27-
Setting `shadow = "patternLeft"` will apply a pattern bottom and left sides of the Card. By default, the pattern used is `CheckerDense`, but you can pass in a different pattern using the `pattern` prop.
28-
29-
<Canvas of={CardStories.ShadowPatternLeft} />
30-
3126
## Usage
3227

3328
Use Card to present different types of information in a visually appealing way.
@@ -37,7 +32,7 @@ Use Card to present different types of information in a visually appealing way.
3732
### Backgrounds
3833

3934
#### Default
40-
When a Card is not provided a `variant`, i.e. it uses the `'default'` variant and it will use the `'background'` color token — this color token is <LinkTo id="Foundations/ColorMode">ColorMode</LinkTo> responsive.
35+
When a Card's `variant` prop isn't set, or it's set to `'default'` it will use the `'background'` color token — this color token is <LinkTo id="Foundations/ColorMode">ColorMode</LinkTo> responsive.
4136

4237
<Canvas of={CardStories.Dynamic} />
4338

@@ -65,46 +60,22 @@ Setting `shadow = "outline"` will apply a shadow to the bottom and left sides of
6560

6661
<Canvas of={CardStories.ShadowOutline} />
6762

63+
#### PatternLeft
64+
Setting `shadow = "patternLeft"` will apply a pattern bottom and left sides of the Card. By default, the pattern used is `CheckerDense`, but you can pass in a different pattern using the `pattern` prop.
6865

66+
<Canvas of={CardStories.ShadowPatternLeft} />
6967

7068
#### PatternRight
69+
Setting `shadow = "patternRight"` works like `"patternLeft"` but applies the pattern to the bottom and right sides of the Card. You may also change the `pattern` used.
7170

72-
<Canvas of={CardStories.Navy} />
73-
74-
### Hyper
75-
76-
<Canvas of={CardStories.Hyper} />
77-
78-
### Beige
71+
<Canvas of={CardStories.ShadowPatternRight} />
7972

80-
<Canvas of={CardStories.Beige} />
73+
### As a link
74+
Cards can be used as links by providing an `href` prop. These Cards can also accept an `onClick` prop that accepts a function. Stylistically, these Cards will have a hover effect that adds a shadow to the card.
8175

82-
## Shadow variants
8376

84-
### Small
77+
<Canvas of={CardStories.CardLink} />
8578

86-
<Canvas of={CardStories.PatternLeftShadow} />
87-
88-
### Medium
89-
90-
<Canvas of={CardStories.PatternRightShadow} />
91-
92-
### Outline
93-
94-
The outline color will inherit the color of the card.
95-
96-
<Canvas of={CardStories.OutlineShadow} />
97-
<Canvas of={CardStories.OutlineShadowColor} />
98-
99-
## As link
100-
101-
<Canvas of={CardStories.Link} />
102-
103-
## ColorMode as default
104-
105-
Card elements respond to the current <LinkTo id="Foundations/ColorMode">ColorMode</LinkTo> they are used in. Note that their background color will match the background of their context and secondary colors are used for their hover effect. As these are not the typical inverse effects we utilize in color mode, please check with your design team before use.
106-
107-
<Canvas of={CardStories.Dynamic} />
10879

10980
## Playground
11081

packages/styleguide/src/lib/Atoms/Card/Card.stories.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,90 @@ export const ShadowPatternLeft: Story = {
195195
),
196196
}
197197

198+
export const ShadowPatternRight: Story = {
199+
render: () => (
200+
<FlexBox column>
201+
<FlexBox p={24} border={1}>
202+
<Box flexGrow={1}>
203+
<Card shadow="patternRight">
204+
Default with patternRight
205+
</Card>
206+
</Box>
207+
</FlexBox>
208+
<FlexBox row gap={16} p={24} border={1}>
209+
<Box flexGrow={1}>
210+
<Card variant="white" shadow="patternRight">
211+
White with patternRight
212+
</Card>
213+
</Box>
214+
<Box flexGrow={1}>
215+
<Card variant="yellow" shadow="patternRight">
216+
Yellow with patternRight
217+
</Card>
218+
</Box>
219+
<Box flexGrow={1}>
220+
<Card variant="beige" shadow="patternRight">
221+
Beige with patternRight
222+
</Card>
223+
</Box>
224+
</FlexBox>
225+
<Background bg="navy">
226+
<FlexBox row gap={16} p={24} border={1}>
227+
<Box flexGrow={1}>
228+
<Card variant="navy" shadow="patternRight">
229+
Navy with patternRight
230+
</Card>
231+
</Box>
232+
<Box flexGrow={1}>
233+
<Card variant="hyper" shadow="patternRight">
234+
Hyper with patternRight
235+
</Card>
236+
</Box>
237+
</FlexBox>
238+
</Background>
239+
</FlexBox>
240+
),
241+
}
242+
243+
export const CardLink: Story = {
244+
render: () => (
245+
<FlexBox column>
246+
<FlexBox row gap={16} p={24} border={1}>
247+
<Box flexGrow={1}>
248+
<Card variant="white" shadow="none" href="/">
249+
White with patternRight
250+
</Card>
251+
</Box>
252+
<Box flexGrow={1}>
253+
<Card variant="yellow" shadow="patternLeft" href="/">
254+
Yellow with patternRight
255+
</Card>
256+
</Box>
257+
<Box flexGrow={1}>
258+
<Card variant="beige" shadow="outline" href="/">
259+
Beige with patternRight
260+
</Card>
261+
</Box>
262+
</FlexBox>
263+
<Background bg="navy">
264+
<FlexBox row gap={16} p={24} border={1}>
265+
<Box flexGrow={1}>
266+
<Card variant="navy" shadow="patternLeft" href="/">
267+
Navy with patternRight
268+
</Card>
269+
</Box>
270+
<Box flexGrow={1}>
271+
<Card variant="hyper" shadow="patternRight" href="/">
272+
Hyper with patternRight
273+
</Card>
274+
</Box>
275+
</FlexBox>
276+
</Background>
277+
</FlexBox>
278+
),
279+
}
280+
281+
198282
export const Yellow: Story = {
199283
args: {
200284
variant: 'yellow',

0 commit comments

Comments
 (0)