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

Add hoverable effect to shared styles #223

Merged
merged 2 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 35 additions & 0 deletions src/components/SharedStyles.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import styled from 'styled-components';
import { pageMargins, hoverEffect } from './shared/styles';

export default {
title: 'Design System/SharedStyles',
};

const BlockWithMargin = styled.div`
${pageMargins};
height: 300px;
background-color: #333;
`;

export const PageMargins = () => (
<div>
<p>
The box below has <code>pageMargins</code> styles applied to it which controls the horizontal
padding and margin
</p>
<BlockWithMargin />
</div>
);

const BlockWithHoverEffect = styled.div`
${hoverEffect};
display: block;
height: 300px;
`;

export const HoverEffectRest = () => <BlockWithHoverEffect />;

export const HoverEffectHover = () => <BlockWithHoverEffect className="__hover" />;

export const HoverEffectActive = () => <BlockWithHoverEffect className="__active" />;
21 changes: 21 additions & 0 deletions src/components/shared/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { css } from 'styled-components';
import { rgba } from 'polished';

// Global style variables
export const background = {
Expand Down Expand Up @@ -96,3 +97,23 @@ export const pageMargins = css`
margin: 0 ${pageMargin * 4}%;
}
`;

export const hoverEffect = css`
border: 1px solid ${color.border};
border-radius: ${spacing.borderRadius.small}px;
transition: background 150ms ease-out, border 150ms ease-out,
transform 150ms ease-out;

&:hover,
&.__hover {
Copy link
Member

Choose a reason for hiding this comment

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

Nice 💪

border-color: ${rgba(color.secondary, 0.5)};
transform: translate3d(0, -3px, 0);
box-shadow: rgba(0, 0, 0, 0.08) 0 3px 10px 0;
}

&:active,
&.__active {
border-color: ${rgba(color.secondary, 1)};
transform: translate3d(0, 0, 0);
}
`;