From 0bb3c031864be4e4b5c1feeb3958c0b05a65cec4 Mon Sep 17 00:00:00 2001
From: Angelos Chalaris
Date: Sat, 24 Aug 2019 10:43:07 +0300
Subject: [PATCH] Update list, search and index to show demos and browser
support
---
src/docs/components/SnippetCard.js | 50 +++++++++++-------------------
src/docs/pages/index.js | 18 +++++++----
src/docs/pages/list.js | 20 +++++++-----
src/docs/pages/search.js | 18 +++++++----
src/docs/styles/_card.scss | 16 +++++-----
5 files changed, 63 insertions(+), 59 deletions(-)
diff --git a/src/docs/components/SnippetCard.js b/src/docs/components/SnippetCard.js
index 8cc019542..3720d31ca 100644
--- a/src/docs/components/SnippetCard.js
+++ b/src/docs/components/SnippetCard.js
@@ -128,14 +128,8 @@ const FullCard = ({ snippetData, isDarkMode }) => {
// ===================================================
const ShortCard = ({
snippetData,
- withCode = false,
isDarkMode
}) => {
- let cardCodeHtml;
- if (withCode)
- cardCodeHtml = `${optimizeAllNodes(
- getCodeBlocks(snippetData.html).code,
- )}`;
return (
@@ -153,32 +147,24 @@ const ShortCard = ({
__html: `${getTextualContent(snippetData.html)}`,
}}
/>
- {withCode ?
-
{
- let tst = document.createElement('div');
- tst.classList = 'toast';
- tst.innerHTML = 'Snippet copied to clipboard!';
- document.body.appendChild(tst);
- setTimeout(function() {
- tst.style.opacity = 0;
- setTimeout(function() {
- document.body.removeChild(tst);
- }, 300);
- }, 1700);
- }}
- >
-
-
-
-
: '' }
+
+
Demo
+
+
+
+ {
+ snippetData.code.js &&
+
+ }
+
+
+
Browser support
+
{snippetData.supportPercentage}%
+
);
};
diff --git a/src/docs/pages/index.js b/src/docs/pages/index.js
index 5e8d7daf2..5733f1bf9 100644
--- a/src/docs/pages/index.js
+++ b/src/docs/pages/index.js
@@ -22,11 +22,8 @@ const IndexPage = props => {
tags: snippet.attributes.tags,
text: snippet.attributes.text,
id: snippet.id,
- code: getCodeBlocks(
- props.data.allMarkdownRemark.edges.find(
- v => v.node.frontmatter.title === snippet.title,
- ).node.rawMarkdownBody,
- ).code,
+ code: snippet.attributes.codeBlocks,
+ supportPercentage: snippet.attributes.browserSupport.supportPercentage,
}));
const [searchQuery, setSearchQuery] = React.useState(props.searchQuery);
@@ -125,13 +122,22 @@ export const indexPageQuery = graphql`
}
}
}
- snippetDataJson(meta: { type: { eq: "snippetListingArray" } }) {
+ snippetDataJson(meta: { type: { eq: "snippetArray" } }) {
data {
id
title
attributes {
tags
text
+ codeBlocks {
+ html
+ css
+ js
+ scopedCss
+ }
+ browserSupport {
+ supportPercentage
+ }
}
}
}
diff --git a/src/docs/pages/list.js b/src/docs/pages/list.js
index e3e52d798..62a62b7d1 100644
--- a/src/docs/pages/list.js
+++ b/src/docs/pages/list.js
@@ -24,11 +24,8 @@ const ListPage = props => {
tags: snippet.attributes.tags,
text: snippet.attributes.text,
id: snippet.id,
- code: getCodeBlocks(
- props.data.allMarkdownRemark.edges.find(
- v => v.node.frontmatter.title === snippet.title,
- ).node.rawMarkdownBody,
- ).code,
+ code: snippet.attributes.codeBlocks,
+ supportPercentage: snippet.attributes.browserSupport.supportPercentage,
}));
const tags = snippets.reduce((acc, snippet) => {
if (!snippet.tags) return acc;
@@ -57,7 +54,7 @@ const ListPage = props => {
Click on a snippet’s name to view its code or a tag name to view all
snippets in that category.
- {tags.map(tag => (
+ {tags.sort((a,b) => a.localeCompare(b)).map(tag => (
<>
{
tags: snippet.attributes.tags,
text: snippet.attributes.text,
id: snippet.id,
- code: getCodeBlocks(
- props.data.allMarkdownRemark.edges.find(
- v => v.node.frontmatter.title === snippet.title,
- ).node.rawMarkdownBody,
- ).code,
+ code: snippet.attributes.codeBlocks,
+ supportPercentage: snippet.attributes.browserSupport.supportPercentage,
}));
const [searchQuery, setSearchQuery] = React.useState(props.searchQuery);
@@ -110,13 +107,22 @@ export default connect(
export const searchPageQuery = graphql`
query searchSnippetList {
- snippetDataJson(meta: { type: { eq: "snippetListingArray" } }) {
+ snippetDataJson(meta: { type: { eq: "snippetArray" } }) {
data {
id
title
attributes {
tags
text
+ codeBlocks {
+ html
+ css
+ js
+ scopedCss
+ }
+ browserSupport {
+ supportPercentage
+ }
}
}
}
diff --git a/src/docs/styles/_card.scss b/src/docs/styles/_card.scss
index 0acbcfe7f..3cc184b42 100644
--- a/src/docs/styles/_card.scss
+++ b/src/docs/styles/_card.scss
@@ -69,14 +69,14 @@
background: var(--button-example-toggler-fore-color);
}
}
- &.short {
- .card-bottom {
- display: none;
- @media screen and (min-width: $layout-large-breakpoint) {
- display: block;
- }
- }
- }
+ // &.short {
+ // .card-bottom {
+ // display: none;
+ // @media screen and (min-width: $layout-large-breakpoint) {
+ // display: block;
+ // }
+ // }
+ // }
}
// Card sections