Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Add blog template for SnippetCard organism
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed Jan 13, 2020
1 parent 60cacd5 commit 230bbe6
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 1 deletion.
1 change: 1 addition & 0 deletions content/sources/30csharp
Submodule 30csharp added at 86a805
3 changes: 2 additions & 1 deletion src/organisms/snippetCard/_index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import './standardSnippetCard';
@import './cssSnippetCard';
@import './cssSnippetCard';
@import './blogSnippetCard';
59 changes: 59 additions & 0 deletions src/organisms/snippetCard/blogSnippetCard/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@import '../../../atoms/card/mixins';

.snippet-card {

.card-meta-info {
font-size: 0.875rem;
margin-top: 0;
margin-bottom: 1.25rem;
color: var(--card-fore-color-light);
a {
&, &:link, &:visited {
color: var(--card-fore-color-light);
}
}
}

.card-cover-image {
@include card-full-width-section;
margin-top: 0.375rem;
min-width: calc(100% + 2rem);
object-fit: cover;
margin-bottom: 1rem;
min-height: calc(240px / var(--cover-aspect-ratio));
max-height: calc(640px / var(--cover-aspect-ratio));
}

ol {
list-style: none;
counter-reset: list-item-counter;

li {
counter-increment: list-item-counter;
position: relative;

&:before {
content: counter(list-item-counter) ". ";
position: absolute;
top: 0;
left: -1.5rem;
width: 1.5rem;
line-height: 1.5rem;
text-align: right;
}
}

.blog-list-item {
margin-bottom: 1.5rem;

&:before {
font-weight: 600;
}

> p:first-child:not(:last-child) {
font-weight: 600;
}
}
}

}
79 changes: 79 additions & 0 deletions src/organisms/snippetCard/blogSnippetCard/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import Card from 'atoms/card';
import TagList from 'molecules/tagList';
import CodeBlock from 'atoms/codeBlock';
import { CopyButton, CodepenButton } from 'atoms/button';
import Toast from 'atoms/toast';
import { Snippet as SnippetPropType } from 'typedefs';
import { trimWhiteSpace } from 'functions/utils';
import { Anchor } from 'atoms/anchor';
import { JSX_SNIPPET_PRESETS } from 'shared';
import _ from 'lang';
const _l = _('en');

const SnippetCard = ({
snippet,
className,
toastContainer,
...rest
}) => (
<Card className={ trimWhiteSpace`snippet-card ${className}` } { ...rest } >
<h4 className='card-title'>{ snippet.title }</h4>
{ /* TODO: Handle this properly, with classes etc. - Also handle the authors field in the PropType */ }
<p className="card-meta-info">
{ snippet.authors.map((a, i, arr) => (
<>
<Anchor link={ {
internal: false,
url: a.profile,
rel: 'noopener noreferrer nofollow',
target: '_blank',
} }>
{ a.name }
</Anchor>
{ i !== arr.length - 1 ? ', ' : '' }
</>
)) }
{ ' · ' }
{
new Date(snippet.firstSeen).toLocaleDateString('en-US', {
day: 'numeric', month: 'short', year: 'numeric',
})
}
</p>
<TagList tags={ [ ...snippet.tags.all] } />
{ /* TODO: Extract an atom from this */ }
{ /* { snippet.coverSrc ?
<div
className='card-cover-image'
style={ { backgroundImage: `url("${encodeURI(snippet.coverSrc)}")` } }
/>
: null } */ }
{ snippet.cover && snippet.cover.src ?
<img
className='card-cover-image'
style={ {'--cover-aspect-ratio': snippet.cover.aspectRatio} }
src={ snippet.cover.src }
/>
: null }
<div
className='card-description'
dangerouslySetInnerHTML={ { __html: `${snippet.html.fullDescription}` } }
/>
</Card>
);

SnippetCard.propTypes = {
/** Snippet data for the card */
snippet: SnippetPropType,
/** Additional classes for the card */
className: PropTypes.string,
/** The id of a DOM node used to render the toast when copying the snippet */
toastContainer: PropTypes.node,
/** Any other arguments to be passed to the card */
rest: PropTypes.any,
};

export default SnippetCard;
8 changes: 8 additions & 0 deletions src/organisms/snippetCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ import PropTypes from 'prop-types';

import StandardSnippetCard from './standardSnippetCard';
import CssSnippetCard from './cssSnippetCard';
import BlogSnippetCard from './blogSnippetCard';

export {
StandardSnippetCard,
CssSnippetCard,
BlogSnippetCard,
};

const SnippetCard = ({
cardTemplate,
...rest
}) => {
switch (cardTemplate) {
case 'blog':
return (
<BlogSnippetCard
{ ...rest }
/>
);
case 'css':
return (
<CssSnippetCard
Expand Down

0 comments on commit 230bbe6

Please sign in to comment.