Skip to content

Commit

Permalink
Working save
Browse files Browse the repository at this point in the history
  • Loading branch information
srm985 committed Oct 19, 2023
1 parent c3f3fb0 commit 61b1431
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 92 deletions.
45 changes: 29 additions & 16 deletions src/components/CodeBlockComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,58 @@ import './styles.scss';

function CodeBlockComponent(props) {
const {
children,
className,
language,
value
inline: isInline,
language
} = props;

const fieldValue = children[0];

const {
displayName
} = CodeBlockComponent;

const componentClassNames = classNames(
displayName,
className
className,
{
[`${displayName}--inline`]: isInline
}
);

return (
<SyntaxHighlighter
className={componentClassNames}
language={language}
showLineNumbers
style={vscDarkPlus}
wrapLines
>
{value}
</SyntaxHighlighter>
isInline ? (
<code className={componentClassNames}>{fieldValue}</code>
) : (
<SyntaxHighlighter
className={componentClassNames}
language={language}
showLineNumbers
style={vscDarkPlus}
wrapLines
>
{fieldValue}
</SyntaxHighlighter>
)
);
}

CodeBlockComponent.displayName = 'CodeBlockComponent';

CodeBlockComponent.propTypes = {
children: PropTypes.arrayOf(PropTypes.string),
className: PropTypes.string,
language: PropTypes.string,
value: PropTypes.string
// eslint-disable-next-line react/boolean-prop-naming
inline: PropTypes.bool,
language: PropTypes.string
};

CodeBlockComponent.defaultProps = {
children: [],
className: '',
language: '',
value: ''
inline: false,
language: ''
};

export default CodeBlockComponent;
6 changes: 6 additions & 0 deletions src/components/CodeBlockComponent/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ $code-block-font-size: 16px !important;
* {
font-size: $code-block-font-size;
}

&--inline {
padding: calc($planck-length / 2) $planck-length;

background-color: rgba($color-orange, 0.1);
}
}
6 changes: 3 additions & 3 deletions src/components/FooterComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ function FooterComponent(props) {
);
});

console.log(renderLinkButtons());

return (
<footer className={displayName}>
<p className={`${displayName}__copy`}>{footerCopy}</p>
<div className={`${displayName}__links`} />
<div className={`${displayName}__links`}>
{renderLinkButtons()}
</div>
</footer>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/LayoutComponent/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React, {
Children, cloneElement
cloneElement
} from 'react';

import Footer from '../FooterComponent';
Expand Down Expand Up @@ -69,12 +69,12 @@ function LayoutComponent(props) {
}
<main className={mainContentClassNames}>
{
Children.map(children, (child) => cloneElement(child, {
cloneElement(children, {
content: {
...content,
...extractedContent
}
}))
})
}
</main>
{
Expand Down
9 changes: 1 addition & 8 deletions src/components/LayoutComponent/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
} from 'gatsby';
import PropTypes from 'prop-types';
import React, {
Children,
cloneElement
} from 'react';

Expand Down Expand Up @@ -57,13 +56,7 @@ function Query(props) {
}
`
}
render={(data) => (
<>
{
Children.map(children, (child) => cloneElement(child, data))
}
</>
)}
render={(data) => cloneElement(children, data)}
/>
);
}
Expand Down
84 changes: 42 additions & 42 deletions src/components/ListComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ function ListComponent(props) {
displayName
} = ListComponent;

const renderListItems = (listItemsList) => listItemsList.map((listItemDetails) => {
console.log(props);

const renderListItems = (childList) => childList.map((childDetails) => {
const {
children: nestedChildren,
key,
props: nestedProps,
props: {
children: nestedChildren,
node: {
ordered: isOrderedList,
type: nodeType
} = {}
},
type: functionalType
} = listItemDetails;

const isList = nodeType === 'list';
const isListItem = nodeType === 'listItem';

const isTypeFunction = functionalType !== undefined && typeof functionalType === 'function';
tagName: elementType,
value
} = childDetails;

if (value === '\n') {
return undefined;
}

const isList = elementType === 'ul' || elementType === 'ol';

// console.log({
// childDetails
// });

if (isList) {
const isShortList = nestedChildren.length <= 10;
const isOrderedList = elementType === 'ol';
const isShortList = nestedChildren.length <= 14;

const componentClassNames = classNames(
displayName,
Expand All @@ -46,57 +48,55 @@ function ListComponent(props) {
<ol
className={componentClassNames}
key={key}
>
{renderListItems(nestedChildren)}
>{renderListItems(nestedChildren)}
</ol>
) : (
<ul
className={componentClassNames}
key={key}
>
{renderListItems(nestedChildren)}
>{renderListItems(nestedChildren)}
</ul>
)
);
}

if (isListItem) {
if (value) {
if (value === '.') {
console.log({
childDetails
});
}
return (
<li key={key}>
{renderListItems(nestedChildren)}
</li>
<li>{value}</li>
);
}

return isTypeFunction ? functionalType(nestedProps) : renderListItems(nestedChildren);
});
return renderListItems(nestedChildren);
}).filter((listItem) => listItem);

return renderListItems([
{
props
}
props.node
]);
}

ListComponent.displayName = 'ListComponent';

ListComponent.propTypes = {
children: PropTypes.arrayOf(PropTypes.shape({
key: PropTypes.string,
props: PropTypes.shape({
node: PropTypes.shape({
children: PropTypes.arrayOf(PropTypes.shape({
children: PropTypes.arrayOf(PropTypes.shape({
props: PropTypes.shape({
value: PropTypes.string
})
}))
})
})),
isOrderedList: PropTypes.bool
type: PropTypes.string,
value: PropTypes.string
})),
tagName: PropTypes.string
})),
key: PropTypes.string,
tagName: PropTypes.string
})
};

ListComponent.defaultProps = {
children: [],
isOrderedList: false
node: {}
};

export default ListComponent;
9 changes: 1 addition & 8 deletions src/components/SEOComponent/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
} from 'gatsby';
import PropTypes from 'prop-types';
import React, {
Children,
cloneElement
} from 'react';

Expand Down Expand Up @@ -33,13 +32,7 @@ function Query(props) {
}
`
}
render={(data) => (
<>
{
Children.map(children, (child) => cloneElement(child, data))
}
</>
)}
render={(data) => cloneElement(children, data)}
/>
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/SectionComponent/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/jsx-no-useless-fragment */
import PropTypes from 'prop-types';
import React from 'react';

Expand Down Expand Up @@ -33,9 +34,7 @@ function SectionComponent(props) {

return (
<section className={componentClassNames}>
{
children
}
<>{children}</>
</section>
);
}
Expand Down
18 changes: 9 additions & 9 deletions src/components/TextBlockComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ class TextBlockComponent extends React.Component {
);

// Hooking markdown components into React components.
const renderers = {
break: renderHardBreak,
const components = {
a: renderLink,
br: renderHardBreak,
code: CodeBlock,
image: Image,
link: renderLink,
list: List
img: Image,
ol: List,
ul: List
};

const componentClassNames = classNames(
Expand All @@ -93,10 +94,9 @@ class TextBlockComponent extends React.Component {
return (
<VisibilityChecker handleChange={this.handleVisibilityChange}>
<div className={componentClassNames}>
<ReactMarkdown
renderers={renderers}
source={text}
/>
<ReactMarkdown components={components}>
{text}
</ReactMarkdown>
</div>
</VisibilityChecker>
);
Expand Down

0 comments on commit 61b1431

Please sign in to comment.