Skip to content

Commit

Permalink
Improve content-image custom styling
Browse files Browse the repository at this point in the history
  • Loading branch information
neillrobson committed Jun 10, 2024
1 parent 7393e41 commit 94b5a4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ const components = {
// <p parentname="blockquote">...</p>
return this.$slots.default;
}
}),
// shallow-copy props because MDXProvider shares the instance to parents
img: ({ ...props }) => ({
render() {
// Pull everything except `attrs` into a child object, domProps
const { attrs, ...domProps } = props;
const data = { attrs, domProps };
const elProps = { class: 'mdx-img', ...props, ...data };

return <img {...elProps} />;
}
})
};

Expand Down
18 changes: 7 additions & 11 deletions src/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ h6 {
margin: 1.5em 0;
}

/* TODO: Find a way to customize this selector to something more semantically relevant */
[parentname='blockquote'] {
font-size: 18px;
}
Expand All @@ -63,16 +64,11 @@ h6 {
margin: 0.2em 0;
}
}
}

/*
* Targeting specifically images within the main MDX body.
* There's certainly a better way to do this by passing MDX components,
* something to research in the future.
*/
[mdxtype='MDXLayout'] > p > img {
max-width: 95%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
margin: 0 auto;
display: block;
.mdx-img {
max-width: 95%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
margin: 0 auto;
display: block;
}
}

0 comments on commit 94b5a4a

Please sign in to comment.