diff --git a/.markdownlint.json b/.markdownlint.json index d4e6b0ad7..80622a6af 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -1,6 +1,7 @@ { "MD003": {"style": "atx"}, "MD007": {"indent": 2}, + "MD026": {"punctuation": ".,;!。,;:!"}, "default": true, "line-length": false, "no-duplicate-heading": false, diff --git a/components/atoms/Columns/Columns.js b/components/atoms/Columns/Columns.js index 46721c4bb..9bd78e84a 100644 --- a/components/atoms/Columns/Columns.js +++ b/components/atoms/Columns/Columns.js @@ -6,24 +6,55 @@ import styles from './Columns.module.css' /** * Render the Columns component. * - * @param {object} props Container component props. - * @param {string} props.id Optional ID/Anchor. - * @param {string} props.className Optional className. - * @param {string} props.columnCount Total number of columns. - * @param {object} props.children React children. - * @return {Element} The Columns component. + * @param {object} props Container component props. + * @param {string} props.id Optional ID/Anchor. + * @param {string} props.className Optional className. + * @param {string} props.columnCount Total number of columns. + * @param {object} props.children React children. + * @param {object} props.style Custom columns styles. + * @param {string} props.verticalAlignment Vertical alignment of columns. + * @return {Element} The Columns component. */ -export default function Columns({id, className, columnCount, children}) { +export default function Columns({ + id, + className, + columnCount, + children, + style, + verticalAlignment +}) { return (
{!!innerBlocks?.length && (
- {innerBlocks.map((block, index) => {
+ {innerBlocks.map(({attributes, innerBlocks}, index) => {
+ const columnStyle = getBlockStyles({
+ backgroundColorHex: attributes?.backgroundColorHex,
+ gradientHex: attributes?.gradientHex,
+ textColorHex: attributes?.textColorHex,
+ style: attributes?.style
+ })
+
return (
- {!!block?.innerBlocks?.length && (
-
- )}
+ {!!innerBlocks?.length && }
)
})}
@@ -44,12 +70,17 @@ export default function BlockColumns({columns, innerBlocks}) {
BlockColumns.propTypes = {
columns: PropTypes.shape({
anchor: PropTypes.string,
- className: PropTypes.string
+ backgroundColorHex: PropTypes.string,
+ className: PropTypes.string,
+ gradientHex: PropTypes.string,
+ style: PropTypes.object,
+ textColorHex: PropTypes.string,
+ verticalAlignment: PropTypes.string
}),
innerBlocks: PropTypes.arrayOf(
PropTypes.shape({
- name: PropTypes.string,
- attributes: PropTypes.object
+ block: PropTypes.object,
+ index: PropTypes.number
})
)
}
diff --git a/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js b/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js
index 5b75496bc..74b9f97bc 100644
--- a/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js
+++ b/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js
@@ -1,5 +1,6 @@
import Blocks from '@/components/molecules/Blocks'
import MediaText from '@/components/organisms/MediaText'
+import getBlockStyles from '@/functions/wordpress/blocks/getBlockStyles'
import PropTypes from 'prop-types'
/**
@@ -40,22 +41,17 @@ export default function BlockMediaText({innerBlocks, media}) {
verticalAlignment
} = media
/* eslint-enable no-unused-vars */
+ const mediaTextStyle = getBlockStyles({
+ backgroundColorHex,
+ gradientHex,
+ textColorHex,
+ style
+ })
- // Determine background and text colors, using stylelint-accepted const names.
- const backgroundcolor =
- backgroundColorHex || style?.color?.background || 'inherit'
- const textcolor = textColorHex || style?.color?.text || 'inherit'
- const background = gradientHex || style?.color?.gradient || 'inherit'
+ // Add additional styles.
const gridtemplatecolumns =
mediaPosition === 'left' ? `${mediaWidth}% 1fr` : `1fr ${mediaWidth}%`
-
- // Create style object for button.
- const mediaTextStyle = {
- background: background,
- backgroundColor: backgroundcolor,
- color: textcolor,
- gridTemplateColumns: gridtemplatecolumns
- }
+ mediaTextStyle.gridTemplateColumns = gridtemplatecolumns
const newFocalPoint = {}
diff --git a/components/blocks/Gutenberg/BlockParagraph/BlockParagraph.js b/components/blocks/Gutenberg/BlockParagraph/BlockParagraph.js
index de4294149..a86f6fd6f 100644
--- a/components/blocks/Gutenberg/BlockParagraph/BlockParagraph.js
+++ b/components/blocks/Gutenberg/BlockParagraph/BlockParagraph.js
@@ -1,4 +1,5 @@
import RichText from '@/components/atoms/RichText'
+import getBlockStyles from '@/functions/wordpress/blocks/getBlockStyles'
import cn from 'classnames'
import PropTypes from 'prop-types'
@@ -30,15 +31,20 @@ export default function BlockParagraph({
textColorHex
}) {
const alignment = !align ? 'left' : align
+
+ const paragraphStyle = getBlockStyles({
+ backgroundColorHex,
+ textColorHex,
+ style
+ })
+
return (
{content}
diff --git a/functions/wordpress/blocks/getBlockStyles.js b/functions/wordpress/blocks/getBlockStyles.js
new file mode 100644
index 000000000..cd7f6ac64
--- /dev/null
+++ b/functions/wordpress/blocks/getBlockStyles.js
@@ -0,0 +1,50 @@
+/**
+ * Get formatted block styles.
+ *
+ * @author WebDevStudios
+ * @param {object} styles Various block custom and preset styles.
+ * @param {string} styles.backgroundColorHex The background color hex value.
+ * @param {string} styles.gradientHex The background gradient hex value.
+ * @param {string} styles.textColorHex The text color hex value.
+ * @param {number} styles.width The width in percent.
+ * @param {object} styles.style The style attributes.
+ * @return {object} The formatted style object.
+ */
+export default function getBlockStyles({
+ backgroundColorHex,
+ gradientHex,
+ textColorHex,
+ width,
+ style
+}) {
+ const blockStyle = {}
+
+ // Determine styles, using stylelint-accepted const names.
+ const background = gradientHex || style?.color?.gradient
+ const backgroundcolor = backgroundColorHex || style?.color?.background
+ const fontsize = style?.typography?.fontSize
+ const textcolor = textColorHex || style?.color?.text
+
+ // Only add styles if set.
+ if (background) {
+ blockStyle.background = background
+ }
+
+ if (fontsize) {
+ blockStyle.fontSize = fontsize
+ }
+
+ if (backgroundcolor) {
+ blockStyle.backgroundColor = backgroundcolor
+ }
+
+ if (textcolor) {
+ blockStyle.color = textcolor
+ }
+
+ if (width) {
+ blockStyle.width = width ? `${width}%` : 'auto'
+ }
+
+ return blockStyle
+}