diff --git a/client/components/SampleCode.tsx b/client/components/SampleCode.tsx index a108a8d..01835e6 100644 --- a/client/components/SampleCode.tsx +++ b/client/components/SampleCode.tsx @@ -3,7 +3,7 @@ * (c) 2019 - 2020 Nguyen Huu Phuoc */ -import React from 'react'; +import * as React from 'react'; import highlight from '../helpers/highlight'; @@ -18,8 +18,11 @@ const SampleCode: React.FC = ({ code, fullHeight = false, lang ? <> : (
+ */
+
+type Tuple = [number, T[]];
+
+function randomItems(arr: T[], count: number): T[] {
+    const result = arr.concat().reduce(
+        (p, _, __, arr) => {
+            const [a, b] = p;
+            return (a < count)
+                    ? [a + 1, b.concat(arr.splice(Math.random() * arr.length | 0, 1))]
+                    : p;
+        },
+        [0, []] as Tuple
+    );
+    return (result as Tuple)[1];
+};
+
+export default randomItems;
diff --git a/client/index.css b/client/index.css
index ccfe438..6b12e69 100644
--- a/client/index.css
+++ b/client/index.css
@@ -18,8 +18,8 @@ a {
     text-decoration: none;
 }
 
-code {
-    font-family: 'Source Code Pro', monospace;
+pre[class*="language-"] {
+   
 }
 
 /* Layout */
diff --git a/client/layouts/DetailsLayout.tsx b/client/layouts/DetailsLayout.tsx
index 0075205..ac4b935 100644
--- a/client/layouts/DetailsLayout.tsx
+++ b/client/layouts/DetailsLayout.tsx
@@ -3,14 +3,14 @@
  * (c) 2019 - 2020 Nguyen Huu Phuoc 
  */
 
-import React from 'react';
+import * as React from 'react';
 
 import Ad from '../components/Ad';
 import useDocumentTitle from '../hooks/useDocumentTitle';
 import Layout from './Layout';
 import Product from '../components/Product';
 import { ProductList } from '../constants/ProductList';
-import randomFromArray from '../helpers/randomFromArray';
+import randomItems from '../helpers/randomIterms';
 
 interface DetailsLayoutProps {
     title: string;
@@ -19,7 +19,7 @@ interface DetailsLayoutProps {
 const DetailsLayout: React.FC = ({ title, children }) => {
     useDocumentTitle(`CSS Layout ∙ ${title}`);
 
-    const product = randomFromArray(ProductList);
+    const products = randomItems(ProductList, 3);
 
     return (
         
@@ -36,7 +36,9 @@ const DetailsLayout: React.FC = ({ title, children }) => {
                     
- + { + products.map(product => ) + }
diff --git a/client/placeholders/BrowserFrame.tsx b/client/placeholders/BrowserFrame.tsx index 2fec018..af88283 100644 --- a/client/placeholders/BrowserFrame.tsx +++ b/client/placeholders/BrowserFrame.tsx @@ -3,9 +3,10 @@ * (c) 2019 - 2020 Nguyen Huu Phuoc */ -import React, { useState } from 'react'; +import * as React from 'react'; import SampleCode from '../components/SampleCode'; +import './browserFrame.css'; interface BrowserFrameProps { content: React.ReactNode; @@ -13,113 +14,13 @@ interface BrowserFrameProps { } const BrowserFrame: React.FC = ({ content, source }) => { - const [isContentActive, setContentActive] = useState(true); - const flip = () => setContentActive((isActive) => !isActive); - return ( -
-
-
-
-
- {source && ( -
- -
- )} +
+
+ {source && }
-
-
- {content} -
- {source && ( -
- -
- )} +
+ {content}
); diff --git a/client/placeholders/browserFrame.css b/client/placeholders/browserFrame.css new file mode 100644 index 0000000..6e79e86 --- /dev/null +++ b/client/placeholders/browserFrame.css @@ -0,0 +1,13 @@ +/** + * A collection of popular layouts and patterns made with CSS (https://csslayout.io) + * (c) 2019 - 2020 Nguyen Huu Phuoc + */ + +.demo { + border: 1px solid rgba(0, 0, 0, 0.2); + border-radius: 0.25rem; +} +.demo__source, +.demo__live { + height: 32rem; +}