diff --git a/contents/_includes/patterns/tree-diagram.njk b/contents/_includes/patterns/tree-diagram.njk new file mode 100644 index 0000000..e52d7fe --- /dev/null +++ b/contents/_includes/patterns/tree-diagram.njk @@ -0,0 +1,28 @@ +
+ +
\ No newline at end of file diff --git a/contents/index.njk b/contents/index.njk index 71f7b41..cf2bf3e 100644 --- a/contents/index.njk +++ b/contents/index.njk @@ -277,6 +277,12 @@ eleventyExcludeFromCollections: true
Timeline
+
+ +
{% include "patterns/tree-diagram.njk" %}
+
Tree diagram
+
+
{% include "patterns/video-background.njk" %}
diff --git a/contents/tree-diagram.md b/contents/tree-diagram.md new file mode 100644 index 0000000..ec99f30 --- /dev/null +++ b/contents/tree-diagram.md @@ -0,0 +1,132 @@ +--- +layout: layouts/post.njk +title: Tree diagram +description: Create a tree diagram with CSS +keywords: css sitemap, css tree diagram +--- + +## HTML + +```html +
+
    +
  • + + ... + + +
      +
    • + + ... + + +
        +
      • ...
      • +
      • ...
      • + ... +
      +
    • +
    • ...
    • + ... +
    +
  • + + + ... +
+
+``` + +## CSS + +```css +.tree-diagram ul { + display: flex; + position: relative; + + /* Reset */ + list-style-type: none; + margin: 0; + padding: 1rem 0.5rem 0rem 0.5rem; +} + +.tree-diagram ul ul::before { + border-right: 1px solid #d1d5db; + content: ''; + + /* Position */ + position: absolute; + top: 0; + right: 50%; + + /* Size */ + height: 1rem; + width: 50%; +} + +.tree-diagram li { + padding: 1rem 0.5rem 0rem 0.5rem; + position: relative; + + /* Center the content */ + align-items: center; + display: flex; + flex-direction: column; +} + +.tree-diagram li::before { + border-right: 1px solid #d1d5db; + border-top: 1px solid #d1d5db; + content: ''; + + /* Position */ + position: absolute; + top: 0; + right: 50%; + + /* Size */ + height: 1rem; + width: 50%; +} + +.tree-diagram li::after { + border-top: 1px solid #d1d5db; + content: ''; + + /* Position */ + position: absolute; + top: 0; + right: 0; + + /* Size */ + width: 50%; +} + +.tree-diagram li:first-child::before, +.tree-diagram li:last-child::after { + /* Remove the top of border from the first and last items */ + border-top: none; +} + +/* Add a root item if you want */ +li.tree-diagram__root::before { + border-right: none; +} +``` + +You can add a root item to the tree: + +```html +
+
    +
  • + ... +
  • +
+
+``` + +{% demo %} +{% include "patterns/tree-diagram.njk" %} +{% enddemo %} diff --git a/pages/tree-diagram/index.tsx b/pages/tree-diagram/index.tsx deleted file mode 100644 index b4a549e..0000000 --- a/pages/tree-diagram/index.tsx +++ /dev/null @@ -1,197 +0,0 @@ -import * as React from 'react'; -import Head from 'next/head'; -import { Spacer } from '@1milligram/design'; - -import { RelatedPatterns } from '../../components/RelatedPatterns'; -import { Pattern } from '../../constants/Pattern'; -import { PatternLayout } from '../../layouts/PatternLayout'; -import BrowserFrame from '../../placeholders/BrowserFrame'; -import Square from '../../placeholders/Square'; - -const Details: React.FC<{}> = () => { - return ( - - - - - - - - -
    -
  • - - ... - - -
      -
    • - - ... - - -
        -
      • ...
      • -
      • ...
      • - ... -
      -
    • -
    • ...
    • - ... -
    -
  • - - - ... -
-
-`} - css={` - .tree-diagram ul { - display: flex; - position: relative; - - /* Reset */ - list-style-type: none; - margin: 0; - padding: 1rem 0.5rem 0rem 0.5rem; - } - - .tree-diagram ul ul::before { - border-right: 1px solid rgba(0, 0, 0, 0.3); - content: ''; - - /* Position */ - position: absolute; - top: 0; - right: 50%; - - /* Size */ - height: 1rem; - width: 50%; - } - - .tree-diagram li { - padding: 1rem 0.5rem 0rem 0.5rem; - position: relative; - - /* Center the content */ - align-items: center; - display: flex; - flex-direction: column; - } - - .tree-diagram li::before { - border-right: 1px solid rgba(0, 0, 0, 0.3); - border-top: 1px solid rgba(0, 0, 0, 0.3); - content: ''; - - /* Position */ - position: absolute; - top: 0; - right: 50%; - - /* Size */ - height: 1rem; - width: 50%; - } - - .tree-diagram li::after { - border-top: 1px solid rgba(0, 0, 0, 0.3); - content: ''; - - /* Position */ - position: absolute; - top: 0; - right: 0; - - /* Size */ - width: 50%; - } - - .tree-diagram li:first-child::before, - .tree-diagram li:last-child::after { - /* Remove the top of border from the first and last items */ - border-top: none; - } - - /* Add a root item if you want */ - li.tree-diagram__root::before { - border-right: none; - } - `} - > -
-
-
    -
  • - -
      -
    • - -
        -
      • - -
      • -
      -
    • -
    • - -
        -
      • - -
          -
        • - -
        • -
        • - -
        • -
        • - -
        • -
        -
      • -
      • - -
      • -
      • - -
          -
        • - -
        • -
        • - -
        • -
        -
      • -
      -
    • -
    • - -
    • -
    -
  • -
-
-
- - - - - - ); -}; - -export default Details; diff --git a/patterns/tree-diagram/Cover.tsx b/patterns/tree-diagram/Cover.tsx deleted file mode 100644 index b1e8725..0000000 --- a/patterns/tree-diagram/Cover.tsx +++ /dev/null @@ -1,129 +0,0 @@ -import * as React from 'react'; - -import Frame from '../../placeholders/Frame'; -import Square from '../../placeholders/Square'; - -const Cover: React.FC<{}> = () => { - return ( - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - ); -}; - -export default Cover; diff --git a/styles/index.scss b/styles/index.scss index d540dc6..5508f8d 100644 --- a/styles/index.scss +++ b/styles/index.scss @@ -55,6 +55,7 @@ @import './patterns/teardrop'; @import './patterns/three-dimensions-card'; @import './patterns/timeline'; +@import './patterns/tree-diagram'; @import './patterns/triangle-buttons'; @import './patterns/video-background'; @import './patterns/voting'; diff --git a/styles/patterns/_tree-diagram.scss b/styles/patterns/_tree-diagram.scss new file mode 100644 index 0000000..02960f4 --- /dev/null +++ b/styles/patterns/_tree-diagram.scss @@ -0,0 +1,72 @@ +.tree-diagram ul { + display: flex; + position: relative; + + /* Reset */ + list-style-type: none; + margin: 0; + padding: 1rem 0.5rem 0rem 0.5rem; +} + +.tree-diagram ul ul::before { + border-right: 1px solid #d1d5db; + content: ''; + + /* Position */ + position: absolute; + top: 0; + right: 50%; + + /* Size */ + height: 1rem; + width: 50%; +} + +.tree-diagram li { + padding: 1rem 0.5rem 0rem 0.5rem; + position: relative; + + /* Center the content */ + align-items: center; + display: flex; + flex-direction: column; +} + +.tree-diagram li::before { + border-right: 1px solid #d1d5db; + border-top: 1px solid #d1d5db; + content: ''; + + /* Position */ + position: absolute; + top: 0; + right: 50%; + + /* Size */ + height: 1rem; + width: 50%; +} + +.tree-diagram li::after { + border-top: 1px solid #d1d5db; + content: ''; + + /* Position */ + position: absolute; + top: 0; + right: 0; + + /* Size */ + width: 50%; +} + +.tree-diagram li:first-child::before, +.tree-diagram li:last-child::after { + /* Remove the top of border from the first and last items */ + border-top: none; +} + +/* Add a root item if you want */ +li.tree-diagram__root::before { + border-right: none; +} \ No newline at end of file diff --git a/styles/placeholders/_circle.scss b/styles/placeholders/_circle.scss index e1c194b..fa4f3c0 100644 --- a/styles/placeholders/_circle.scss +++ b/styles/placeholders/_circle.scss @@ -1,5 +1,5 @@ .circle { - background: rgba(0, 0, 0, .3); + background: #d1d5db; border-radius: 9999px; height: var(--circle-size); width: var(--circle-size); diff --git a/styles/placeholders/_line.scss b/styles/placeholders/_line.scss index b0e080b..5d5eefe 100644 --- a/styles/placeholders/_line.scss +++ b/styles/placeholders/_line.scss @@ -1,5 +1,5 @@ .line { - background: rgba(0, 0, 0, 0.3); + background: #d1d5db; } .line--hor { height: 1px; diff --git a/styles/placeholders/_rectangle.scss b/styles/placeholders/_rectangle.scss index 8118a35..32b88ba 100644 --- a/styles/placeholders/_rectangle.scss +++ b/styles/placeholders/_rectangle.scss @@ -1,5 +1,5 @@ .rectangle { - background: rgba(0, 0, 0, .3); + background: #d1d5db; border-radius: 0.25rem; } .rectangle--hor { diff --git a/styles/placeholders/_square.scss b/styles/placeholders/_square.scss index 6d8252b..b079d9e 100644 --- a/styles/placeholders/_square.scss +++ b/styles/placeholders/_square.scss @@ -1,6 +1,5 @@ .square { - background: rgba(0, 0, 0, 0.3); - border-radius: 0.25rem; + background: #d1d5db; height: var(--square-size); width: var(--square-size); } diff --git a/styles/placeholders/_triangle.scss b/styles/placeholders/_triangle.scss index 24a7615..179a6b0 100644 --- a/styles/placeholders/_triangle.scss +++ b/styles/placeholders/_triangle.scss @@ -4,35 +4,35 @@ width: 0; } .triangle--t { - border-color: transparent transparent rgba(0, 0, 0, .3) transparent; + border-color: transparent transparent #d1d5db transparent; border-width: 0 var(--triangle-size) var(--triangle-size) var(--triangle-size); } .triangle--r { - border-color: transparent transparent transparent rgba(0, 0, 0, .3); + border-color: transparent transparent transparent #d1d5db; border-width: var(--triangle-size) 0 var(--triangle-size) 1rem; } .triangle--b { - border-color: rgba(0, 0, 0, .3) transparent transparent transparent; + border-color: #d1d5db transparent transparent transparent; border-width: var(--triangle-size) var(--triangle-size) 0 var(--triangle-size); } .triangle--l { - border-color: transparent rgba(0, 0, 0, .3) transparent transparent; + border-color: transparent #d1d5db transparent transparent; border-width: var(--triangle-size) 1rem var(--triangle-size) 0; } .triangle--tr { - border-color: transparent rgba(0, 0, 0, .3) transparent transparent; + border-color: transparent #d1d5db transparent transparent; border-width: 0 var(--triangle-size) var(--triangle-size) 0; } .triangle--br { - border-color: transparent transparent rgba(0, 0, 0, .3) transparent; + border-color: transparent transparent #d1d5db transparent; border-width: 0 0 var(--triangle-size) var(--triangle-size); } .triangle--bl { - border-color: transparent transparent transparent rgba(0, 0, 0, .3); + border-color: transparent transparent transparent #d1d5db; border-width: var(--triangle-size) 0 0 var(--triangle-size); } .triangle--tl { - border-color: rgba(0, 0, 0, .3) transparent transparent transparent; + border-color: #d1d5db transparent transparent transparent; border-width: var(--triangle-size) var(--triangle-size) 0 0; } .triangle--sm {