Skip to content

Commit

Permalink
Fix admonition style
Browse files Browse the repository at this point in the history
  • Loading branch information
kazk committed Apr 15, 2021
1 parent c1f313b commit 6d5748f
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 28 deletions.
50 changes: 50 additions & 0 deletions content/meta/docs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Writing Codewars Docs
---

The Codewars Docs is built with [Docusaurus][docusaurus]. You can write docs using Markdown. Docusaurus provides some [extensions][markdown-features] to make writing docs easier, and we can also use [MDX][mdx] to extend Markdown with React components.

This page summarizes the features and also used to test the styling.

See [Docusaurus Docs][docusaurus-docs] for more details.

## Admonitions

Use the following syntax to add admonitions:

```markdown
:::type title?

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

:::
```

`type` is required. `title` is optional and defaults to uppercased `type`.

### Types

:::note
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.
:::

:::tip
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.
:::

:::info
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.
:::

:::warning
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.
:::

:::caution
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.
:::

[docusaurus]: https://docusaurus.io/
[docusaurus-docs]: https://docusaurus.io/docs
[mdx]: https://mdxjs.com/
[markdown-features]: https://docusaurus.io/docs/markdown-features
1 change: 1 addition & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = {
sidebarPath: require.resolve("./sidebars.js"),
editUrl: "https://github.com/codewars/docs/edit/master/",
},
blog: false,
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
]
},
"devDependencies": {
"prettier": "^2.2.1"
"autoprefixer": "^10.2.5",
"postcss": "^8.2.10",
"postcss-nested": "^5.0.5",
"postcss-preset-env": "^6.7.0",
"prettier": "^2.2.1",
"tailwindcss": "^2.1.1"
}
}
5 changes: 5 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,10 @@ module.exports = {
],
},
"glossary",
{
type: "category",
label: "Meta",
items: ["meta/docs"],
},
],
};
18 changes: 17 additions & 1 deletion sitePlugin.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
const path = require("path");

// Make `@components/` resolve to `src/components`.
module.exports = () => {
return {
name: "site-plugin",

// Make `@components/` resolve to `src/components`.
configureWebpack: (_config, _isServer) => ({
resolve: {
alias: {
"@components": path.resolve(__dirname, "src/components/"),
},
},
}),

// Append new PostCSS plugins.
configurePostCss: (postcssOptions) => {
postcssOptions.plugins.push(
require("tailwindcss"),
require("postcss-nested"),
require("postcss-preset-env")({
autoprefixer: {
flexbox: "no-2009",
},
stage: 4,
})
);
return postcssOptions;
},
};
};
2 changes: 1 addition & 1 deletion src/components/Anchored.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";

const Anchored = ({ id, children }) => {
return (
<div id={`.${id}`} class="anchored">
<div id={`.${id}`} class="anchored inline relative">
<a class="anchor-link" href={`#.${id}`} aria-hidden="true"></a>
{children}
</div>
Expand Down
95 changes: 83 additions & 12 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* bundles Infima by default. Infima is a CSS framework designed to
* work well for content-centric websites.
*/
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--ifm-color-primary: #b1361e;
Expand Down Expand Up @@ -47,10 +50,6 @@ html[data-theme="dark"] .header-github-link:before {
no-repeat;
}

.anchored {
display: inline;
position: relative;
}
.anchored:target {
background-color: var(--cw-anchored-target-bg);
}
Expand All @@ -59,13 +58,85 @@ html[data-theme="dark"] .header-github-link:before {
}
.anchored > .anchor-link::before {
content: "*";
/* -ml-2 pr-2 absolute inset-y-0 opacity-0 float-left text-primary */
margin-left: -0.5rem;
padding-right: 0.5rem;
@apply -ml-2 pr-2 absolute inset-y-0 opacity-0 float-left;
color: var(--ifm-color-primary);
position: absolute;
top: 0;
bottom: 0;
opacity: 0;
float: left;
}

/* Remove .alert styles from Docusaurus */
.admonition.alert {
border-radius: 0;
border-width: 0;
}

.admonition {
@apply mb-4 py-4 pr-8 pl-4;

& .admonition-heading h5 {
@apply flex items-center m-0 mb-2 uppercase text-lg;
}

& .admonition-icon {
@apply inline-block align-middle mr-1 mt-1.5;

& svg {
@apply inline-block w-5 h-5;
@apply fill-current stroke-current;
}
}
}

.admonition.admonition-note {
@apply bg-note bg-opacity-10 border-solid border-l-8 border-note;

& .admonition-heading {
@apply text-note;
}
& .admonition-content {
@apply text-note-content;
}
}

.admonition.admonition-tip {
@apply bg-tip bg-opacity-10 border-solid border-l-8 border-tip;

& .admonition-heading {
@apply text-tip;
}
& .admonition-content {
@apply text-tip-content;
}
}

.admonition.admonition-info {
@apply bg-info bg-opacity-10 border-solid border-l-8 border-info;

& .admonition-heading {
@apply text-info;
}
& .admonition-content {
@apply text-info-content;
}
}

.admonition.admonition-warning {
@apply bg-warning bg-opacity-10 border-solid border-l-8 border-warning;

& .admonition-heading {
@apply text-warning;
}
& .admonition-content {
@apply text-warning-content;
}
}

.admonition.admonition-caution,
.admonition.admonition-danger {
@apply bg-caution bg-opacity-10 border-solid border-l-8 border-caution;

& .admonition-heading {
@apply text-caution;
}
& .admonition-content {
@apply text-caution-content;
}
}
48 changes: 48 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const colors = require("tailwindcss/colors");
const plugin = require("tailwindcss/plugin");

module.exports = {
mode: "jit",
purge: ["./src/**/*.{js,jsx,ts,tsx}", "./content/**/*.mdx"],
corePlugins: {
preflight: false,
},
// Using custom dark variant `html[data-theme="dark"]` to match Docusaurus.
darkMode: false,
theme: {
extend: {
colors: {
brand: "#b1361e",
// Admonitions colors
note: colors.coolGray[600],
"note-content": colors.coolGray[500],
tip: colors.emerald[600],
"tip-content": colors.emerald[600],
info: colors.lightBlue[500],
"info-content": colors.lightBlue[700],
warning: colors.orange[500],
"warning-content": colors.orange[700],
caution: colors.red[600],
"caution-content": colors.red[500],
},
},
},
variants: {
extend: {
backgroundColor: ["dark"],
textColor: ["dark"],
display: ["dark"],
},
},
plugins: [
plugin(({ addVariant, e }) => {
addVariant("dark", ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `html[data-theme="dark"] .${e(
`dark${separator}${className}`
)}`;
});
});
}),
],
};
Loading

0 comments on commit 6d5748f

Please sign in to comment.